1 #include "qemu/osdep.h" 2 #include "qemu-common.h" 3 #include "cpu.h" 4 #include "exec/exec-all.h" 5 #include "hw/hw.h" 6 #include "hw/boards.h" 7 #include "qemu/timer.h" 8 9 #include "migration/cpu.h" 10 11 #ifdef TARGET_SPARC64 12 static const VMStateDescription vmstate_cpu_timer = { 13 .name = "cpu_timer", 14 .version_id = 1, 15 .minimum_version_id = 1, 16 .minimum_version_id_old = 1, 17 .fields = (VMStateField[]) { 18 VMSTATE_UINT32(frequency, CPUTimer), 19 VMSTATE_UINT32(disabled, CPUTimer), 20 VMSTATE_UINT64(disabled_mask, CPUTimer), 21 VMSTATE_UINT32(npt, CPUTimer), 22 VMSTATE_UINT64(npt_mask, CPUTimer), 23 VMSTATE_INT64(clock_offset, CPUTimer), 24 VMSTATE_TIMER_PTR(qtimer, CPUTimer), 25 VMSTATE_END_OF_LIST() 26 } 27 }; 28 29 #define VMSTATE_CPU_TIMER(_f, _s) \ 30 VMSTATE_STRUCT_POINTER(_f, _s, vmstate_cpu_timer, CPUTimer) 31 32 static const VMStateDescription vmstate_trap_state = { 33 .name = "trap_state", 34 .version_id = 1, 35 .minimum_version_id = 1, 36 .minimum_version_id_old = 1, 37 .fields = (VMStateField[]) { 38 VMSTATE_UINT64(tpc, trap_state), 39 VMSTATE_UINT64(tnpc, trap_state), 40 VMSTATE_UINT64(tstate, trap_state), 41 VMSTATE_UINT32(tt, trap_state), 42 VMSTATE_END_OF_LIST() 43 } 44 }; 45 46 static const VMStateDescription vmstate_tlb_entry = { 47 .name = "tlb_entry", 48 .version_id = 1, 49 .minimum_version_id = 1, 50 .minimum_version_id_old = 1, 51 .fields = (VMStateField[]) { 52 VMSTATE_UINT64(tag, SparcTLBEntry), 53 VMSTATE_UINT64(tte, SparcTLBEntry), 54 VMSTATE_END_OF_LIST() 55 } 56 }; 57 #endif 58 59 static int get_psr(QEMUFile *f, void *opaque, size_t size, 60 const VMStateField *field) 61 { 62 SPARCCPU *cpu = opaque; 63 CPUSPARCState *env = &cpu->env; 64 uint32_t val = qemu_get_be32(f); 65 66 /* needed to ensure that the wrapping registers are correctly updated */ 67 env->cwp = 0; 68 cpu_put_psr_raw(env, val); 69 70 return 0; 71 } 72 73 static int put_psr(QEMUFile *f, void *opaque, size_t size, 74 const VMStateField *field, QJSON *vmdesc) 75 { 76 SPARCCPU *cpu = opaque; 77 CPUSPARCState *env = &cpu->env; 78 uint32_t val; 79 80 val = cpu_get_psr(env); 81 82 qemu_put_be32(f, val); 83 return 0; 84 } 85 86 static const VMStateInfo vmstate_psr = { 87 .name = "psr", 88 .get = get_psr, 89 .put = put_psr, 90 }; 91 92 static int cpu_pre_save(void *opaque) 93 { 94 SPARCCPU *cpu = opaque; 95 CPUSPARCState *env = &cpu->env; 96 97 /* if env->cwp == env->nwindows - 1, this will set the ins of the last 98 * window as the outs of the first window 99 */ 100 cpu_set_cwp(env, env->cwp); 101 102 return 0; 103 } 104 105 /* 32-bit SPARC retains migration compatibility with older versions 106 * of QEMU; 64-bit SPARC has had a migration break since then, so the 107 * versions are different. 108 */ 109 #ifndef TARGET_SPARC64 110 #define SPARC_VMSTATE_VER 7 111 #else 112 #define SPARC_VMSTATE_VER 9 113 #endif 114 115 const VMStateDescription vmstate_sparc_cpu = { 116 .name = "cpu", 117 .version_id = SPARC_VMSTATE_VER, 118 .minimum_version_id = SPARC_VMSTATE_VER, 119 .minimum_version_id_old = SPARC_VMSTATE_VER, 120 .pre_save = cpu_pre_save, 121 .fields = (VMStateField[]) { 122 VMSTATE_UINTTL_ARRAY(env.gregs, SPARCCPU, 8), 123 VMSTATE_UINT32(env.nwindows, SPARCCPU), 124 VMSTATE_VARRAY_MULTIPLY(env.regbase, SPARCCPU, env.nwindows, 16, 125 vmstate_info_uinttl, target_ulong), 126 VMSTATE_CPUDOUBLE_ARRAY(env.fpr, SPARCCPU, TARGET_DPREGS), 127 VMSTATE_UINTTL(env.pc, SPARCCPU), 128 VMSTATE_UINTTL(env.npc, SPARCCPU), 129 VMSTATE_UINTTL(env.y, SPARCCPU), 130 { 131 132 .name = "psr", 133 .version_id = 0, 134 .size = sizeof(uint32_t), 135 .info = &vmstate_psr, 136 .flags = VMS_SINGLE, 137 .offset = 0, 138 }, 139 VMSTATE_UINTTL(env.fsr, SPARCCPU), 140 VMSTATE_UINTTL(env.tbr, SPARCCPU), 141 VMSTATE_INT32(env.interrupt_index, SPARCCPU), 142 VMSTATE_UINT32(env.pil_in, SPARCCPU), 143 #ifndef TARGET_SPARC64 144 /* MMU */ 145 VMSTATE_UINT32(env.wim, SPARCCPU), 146 VMSTATE_UINT32_ARRAY(env.mmuregs, SPARCCPU, 32), 147 VMSTATE_UINT64_ARRAY(env.mxccdata, SPARCCPU, 4), 148 VMSTATE_UINT64_ARRAY(env.mxccregs, SPARCCPU, 8), 149 VMSTATE_UINT32(env.mmubpctrv, SPARCCPU), 150 VMSTATE_UINT32(env.mmubpctrc, SPARCCPU), 151 VMSTATE_UINT32(env.mmubpctrs, SPARCCPU), 152 VMSTATE_UINT64(env.mmubpaction, SPARCCPU), 153 VMSTATE_UINT64_ARRAY(env.mmubpregs, SPARCCPU, 4), 154 #else 155 VMSTATE_UINT64(env.lsu, SPARCCPU), 156 VMSTATE_UINT64_ARRAY(env.immu.mmuregs, SPARCCPU, 16), 157 VMSTATE_UINT64_ARRAY(env.dmmu.mmuregs, SPARCCPU, 16), 158 VMSTATE_STRUCT_ARRAY(env.itlb, SPARCCPU, 64, 0, 159 vmstate_tlb_entry, SparcTLBEntry), 160 VMSTATE_STRUCT_ARRAY(env.dtlb, SPARCCPU, 64, 0, 161 vmstate_tlb_entry, SparcTLBEntry), 162 VMSTATE_UINT32(env.mmu_version, SPARCCPU), 163 VMSTATE_STRUCT_ARRAY(env.ts, SPARCCPU, MAXTL_MAX, 0, 164 vmstate_trap_state, trap_state), 165 VMSTATE_UINT32(env.xcc, SPARCCPU), 166 VMSTATE_UINT32(env.asi, SPARCCPU), 167 VMSTATE_UINT32(env.pstate, SPARCCPU), 168 VMSTATE_UINT32(env.tl, SPARCCPU), 169 VMSTATE_UINT32(env.cansave, SPARCCPU), 170 VMSTATE_UINT32(env.canrestore, SPARCCPU), 171 VMSTATE_UINT32(env.otherwin, SPARCCPU), 172 VMSTATE_UINT32(env.wstate, SPARCCPU), 173 VMSTATE_UINT32(env.cleanwin, SPARCCPU), 174 VMSTATE_UINT64_ARRAY(env.agregs, SPARCCPU, 8), 175 VMSTATE_UINT64_ARRAY(env.bgregs, SPARCCPU, 8), 176 VMSTATE_UINT64_ARRAY(env.igregs, SPARCCPU, 8), 177 VMSTATE_UINT64_ARRAY(env.mgregs, SPARCCPU, 8), 178 VMSTATE_UINT64(env.fprs, SPARCCPU), 179 VMSTATE_UINT64(env.tick_cmpr, SPARCCPU), 180 VMSTATE_UINT64(env.stick_cmpr, SPARCCPU), 181 VMSTATE_CPU_TIMER(env.tick, SPARCCPU), 182 VMSTATE_CPU_TIMER(env.stick, SPARCCPU), 183 VMSTATE_UINT64(env.gsr, SPARCCPU), 184 VMSTATE_UINT32(env.gl, SPARCCPU), 185 VMSTATE_UINT64(env.hpstate, SPARCCPU), 186 VMSTATE_UINT64_ARRAY(env.htstate, SPARCCPU, MAXTL_MAX), 187 VMSTATE_UINT64(env.hintp, SPARCCPU), 188 VMSTATE_UINT64(env.htba, SPARCCPU), 189 VMSTATE_UINT64(env.hver, SPARCCPU), 190 VMSTATE_UINT64(env.hstick_cmpr, SPARCCPU), 191 VMSTATE_UINT64(env.ssr, SPARCCPU), 192 VMSTATE_CPU_TIMER(env.hstick, SPARCCPU), 193 /* On SPARC32 env.psrpil and env.cwp are migrated as part of the PSR */ 194 VMSTATE_UINT32(env.psrpil, SPARCCPU), 195 VMSTATE_UINT32(env.cwp, SPARCCPU), 196 #endif 197 VMSTATE_END_OF_LIST() 198 }, 199 }; 200