1 #include "qemu/osdep.h"
2 #include "qemu-common.h"
5 #include "migration/cpu.h"
7 static int cpu_post_load(void *opaque
, int version_id
)
10 CPUMIPSState
*env
= &cpu
->env
;
12 restore_fp_status(env
);
13 restore_msa_fp_status(env
);
22 static int get_fpr(QEMUFile
*f
, void *pv
, size_t size
, VMStateField
*field
)
26 /* Restore entire MSA vector register */
27 for (i
= 0; i
< MSA_WRLEN
/64; i
++) {
28 qemu_get_sbe64s(f
, &v
->wr
.d
[i
]);
33 static int put_fpr(QEMUFile
*f
, void *pv
, size_t size
, VMStateField
*field
,
38 /* Save entire MSA vector register */
39 for (i
= 0; i
< MSA_WRLEN
/64; i
++) {
40 qemu_put_sbe64s(f
, &v
->wr
.d
[i
]);
46 const VMStateInfo vmstate_info_fpr
= {
52 #define VMSTATE_FPR_ARRAY_V(_f, _s, _n, _v) \
53 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_fpr, fpr_t)
55 #define VMSTATE_FPR_ARRAY(_f, _s, _n) \
56 VMSTATE_FPR_ARRAY_V(_f, _s, _n, 0)
58 static VMStateField vmstate_fpu_fields
[] = {
59 VMSTATE_FPR_ARRAY(fpr
, CPUMIPSFPUContext
, 32),
60 VMSTATE_UINT32(fcr0
, CPUMIPSFPUContext
),
61 VMSTATE_UINT32(fcr31
, CPUMIPSFPUContext
),
65 const VMStateDescription vmstate_fpu
= {
68 .minimum_version_id
= 1,
69 .fields
= vmstate_fpu_fields
72 const VMStateDescription vmstate_inactive_fpu
= {
73 .name
= "cpu/inactive_fpu",
75 .minimum_version_id
= 1,
76 .fields
= vmstate_fpu_fields
81 static VMStateField vmstate_tc_fields
[] = {
82 VMSTATE_UINTTL_ARRAY(gpr
, TCState
, 32),
83 VMSTATE_UINTTL(PC
, TCState
),
84 VMSTATE_UINTTL_ARRAY(HI
, TCState
, MIPS_DSP_ACC
),
85 VMSTATE_UINTTL_ARRAY(LO
, TCState
, MIPS_DSP_ACC
),
86 VMSTATE_UINTTL_ARRAY(ACX
, TCState
, MIPS_DSP_ACC
),
87 VMSTATE_UINTTL(DSPControl
, TCState
),
88 VMSTATE_INT32(CP0_TCStatus
, TCState
),
89 VMSTATE_INT32(CP0_TCBind
, TCState
),
90 VMSTATE_UINTTL(CP0_TCHalt
, TCState
),
91 VMSTATE_UINTTL(CP0_TCContext
, TCState
),
92 VMSTATE_UINTTL(CP0_TCSchedule
, TCState
),
93 VMSTATE_UINTTL(CP0_TCScheFBack
, TCState
),
94 VMSTATE_INT32(CP0_Debug_tcstatus
, TCState
),
95 VMSTATE_UINTTL(CP0_UserLocal
, TCState
),
96 VMSTATE_INT32(msacsr
, TCState
),
100 const VMStateDescription vmstate_tc
= {
103 .minimum_version_id
= 1,
104 .fields
= vmstate_tc_fields
107 const VMStateDescription vmstate_inactive_tc
= {
108 .name
= "cpu/inactive_tc",
110 .minimum_version_id
= 1,
111 .fields
= vmstate_tc_fields
116 const VMStateDescription vmstate_mvp
= {
119 .minimum_version_id
= 1,
120 .fields
= (VMStateField
[]) {
121 VMSTATE_INT32(CP0_MVPControl
, CPUMIPSMVPContext
),
122 VMSTATE_INT32(CP0_MVPConf0
, CPUMIPSMVPContext
),
123 VMSTATE_INT32(CP0_MVPConf1
, CPUMIPSMVPContext
),
124 VMSTATE_END_OF_LIST()
130 static int get_tlb(QEMUFile
*f
, void *pv
, size_t size
, VMStateField
*field
)
135 qemu_get_betls(f
, &v
->VPN
);
136 qemu_get_be32s(f
, &v
->PageMask
);
137 qemu_get_be16s(f
, &v
->ASID
);
138 qemu_get_be16s(f
, &flags
);
139 v
->G
= (flags
>> 10) & 1;
140 v
->C0
= (flags
>> 7) & 3;
141 v
->C1
= (flags
>> 4) & 3;
142 v
->V0
= (flags
>> 3) & 1;
143 v
->V1
= (flags
>> 2) & 1;
144 v
->D0
= (flags
>> 1) & 1;
145 v
->D1
= (flags
>> 0) & 1;
146 v
->EHINV
= (flags
>> 15) & 1;
147 v
->RI1
= (flags
>> 14) & 1;
148 v
->RI0
= (flags
>> 13) & 1;
149 v
->XI1
= (flags
>> 12) & 1;
150 v
->XI0
= (flags
>> 11) & 1;
151 qemu_get_be64s(f
, &v
->PFN
[0]);
152 qemu_get_be64s(f
, &v
->PFN
[1]);
157 static int put_tlb(QEMUFile
*f
, void *pv
, size_t size
, VMStateField
*field
,
162 uint16_t asid
= v
->ASID
;
163 uint16_t flags
= ((v
->EHINV
<< 15) |
176 qemu_put_betls(f
, &v
->VPN
);
177 qemu_put_be32s(f
, &v
->PageMask
);
178 qemu_put_be16s(f
, &asid
);
179 qemu_put_be16s(f
, &flags
);
180 qemu_put_be64s(f
, &v
->PFN
[0]);
181 qemu_put_be64s(f
, &v
->PFN
[1]);
186 const VMStateInfo vmstate_info_tlb
= {
192 #define VMSTATE_TLB_ARRAY_V(_f, _s, _n, _v) \
193 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_tlb, r4k_tlb_t)
195 #define VMSTATE_TLB_ARRAY(_f, _s, _n) \
196 VMSTATE_TLB_ARRAY_V(_f, _s, _n, 0)
198 const VMStateDescription vmstate_tlb
= {
201 .minimum_version_id
= 2,
202 .fields
= (VMStateField
[]) {
203 VMSTATE_UINT32(nb_tlb
, CPUMIPSTLBContext
),
204 VMSTATE_UINT32(tlb_in_use
, CPUMIPSTLBContext
),
205 VMSTATE_TLB_ARRAY(mmu
.r4k
.tlb
, CPUMIPSTLBContext
, MIPS_TLB_MAX
),
206 VMSTATE_END_OF_LIST()
212 const VMStateDescription vmstate_mips_cpu
= {
215 .minimum_version_id
= 10,
216 .post_load
= cpu_post_load
,
217 .fields
= (VMStateField
[]) {
219 VMSTATE_STRUCT(env
.active_tc
, MIPSCPU
, 1, vmstate_tc
, TCState
),
222 VMSTATE_STRUCT(env
.active_fpu
, MIPSCPU
, 1, vmstate_fpu
,
226 VMSTATE_STRUCT_POINTER(env
.mvp
, MIPSCPU
, vmstate_mvp
,
230 VMSTATE_STRUCT_POINTER(env
.tlb
, MIPSCPU
, vmstate_tlb
,
234 VMSTATE_UINT32(env
.current_tc
, MIPSCPU
),
235 VMSTATE_UINT32(env
.current_fpu
, MIPSCPU
),
236 VMSTATE_INT32(env
.error_code
, MIPSCPU
),
237 VMSTATE_UINTTL(env
.btarget
, MIPSCPU
),
238 VMSTATE_UINTTL(env
.bcond
, MIPSCPU
),
240 /* Remaining CP0 registers */
241 VMSTATE_INT32(env
.CP0_Index
, MIPSCPU
),
242 VMSTATE_INT32(env
.CP0_Random
, MIPSCPU
),
243 VMSTATE_INT32(env
.CP0_VPEControl
, MIPSCPU
),
244 VMSTATE_INT32(env
.CP0_VPEConf0
, MIPSCPU
),
245 VMSTATE_INT32(env
.CP0_VPEConf1
, MIPSCPU
),
246 VMSTATE_UINTTL(env
.CP0_YQMask
, MIPSCPU
),
247 VMSTATE_UINTTL(env
.CP0_VPESchedule
, MIPSCPU
),
248 VMSTATE_UINTTL(env
.CP0_VPEScheFBack
, MIPSCPU
),
249 VMSTATE_INT32(env
.CP0_VPEOpt
, MIPSCPU
),
250 VMSTATE_UINT64(env
.CP0_EntryLo0
, MIPSCPU
),
251 VMSTATE_UINT64(env
.CP0_EntryLo1
, MIPSCPU
),
252 VMSTATE_UINTTL(env
.CP0_Context
, MIPSCPU
),
253 VMSTATE_INT32(env
.CP0_PageMask
, MIPSCPU
),
254 VMSTATE_INT32(env
.CP0_PageGrain
, MIPSCPU
),
255 VMSTATE_UINTTL(env
.CP0_SegCtl0
, MIPSCPU
),
256 VMSTATE_UINTTL(env
.CP0_SegCtl1
, MIPSCPU
),
257 VMSTATE_UINTTL(env
.CP0_SegCtl2
, MIPSCPU
),
258 VMSTATE_INT32(env
.CP0_Wired
, MIPSCPU
),
259 VMSTATE_INT32(env
.CP0_SRSConf0
, MIPSCPU
),
260 VMSTATE_INT32(env
.CP0_SRSConf1
, MIPSCPU
),
261 VMSTATE_INT32(env
.CP0_SRSConf2
, MIPSCPU
),
262 VMSTATE_INT32(env
.CP0_SRSConf3
, MIPSCPU
),
263 VMSTATE_INT32(env
.CP0_SRSConf4
, MIPSCPU
),
264 VMSTATE_INT32(env
.CP0_HWREna
, MIPSCPU
),
265 VMSTATE_UINTTL(env
.CP0_BadVAddr
, MIPSCPU
),
266 VMSTATE_UINT32(env
.CP0_BadInstr
, MIPSCPU
),
267 VMSTATE_UINT32(env
.CP0_BadInstrP
, MIPSCPU
),
268 VMSTATE_INT32(env
.CP0_Count
, MIPSCPU
),
269 VMSTATE_UINTTL(env
.CP0_EntryHi
, MIPSCPU
),
270 VMSTATE_INT32(env
.CP0_Compare
, MIPSCPU
),
271 VMSTATE_INT32(env
.CP0_Status
, MIPSCPU
),
272 VMSTATE_INT32(env
.CP0_IntCtl
, MIPSCPU
),
273 VMSTATE_INT32(env
.CP0_SRSCtl
, MIPSCPU
),
274 VMSTATE_INT32(env
.CP0_SRSMap
, MIPSCPU
),
275 VMSTATE_INT32(env
.CP0_Cause
, MIPSCPU
),
276 VMSTATE_UINTTL(env
.CP0_EPC
, MIPSCPU
),
277 VMSTATE_INT32(env
.CP0_PRid
, MIPSCPU
),
278 VMSTATE_UINTTL(env
.CP0_EBase
, MIPSCPU
),
279 VMSTATE_INT32(env
.CP0_Config0
, MIPSCPU
),
280 VMSTATE_INT32(env
.CP0_Config1
, MIPSCPU
),
281 VMSTATE_INT32(env
.CP0_Config2
, MIPSCPU
),
282 VMSTATE_INT32(env
.CP0_Config3
, MIPSCPU
),
283 VMSTATE_INT32(env
.CP0_Config6
, MIPSCPU
),
284 VMSTATE_INT32(env
.CP0_Config7
, MIPSCPU
),
285 VMSTATE_UINT64_ARRAY(env
.CP0_MAAR
, MIPSCPU
, MIPS_MAAR_MAX
),
286 VMSTATE_INT32(env
.CP0_MAARI
, MIPSCPU
),
287 VMSTATE_UINT64(env
.lladdr
, MIPSCPU
),
288 VMSTATE_UINTTL_ARRAY(env
.CP0_WatchLo
, MIPSCPU
, 8),
289 VMSTATE_INT32_ARRAY(env
.CP0_WatchHi
, MIPSCPU
, 8),
290 VMSTATE_UINTTL(env
.CP0_XContext
, MIPSCPU
),
291 VMSTATE_INT32(env
.CP0_Framemask
, MIPSCPU
),
292 VMSTATE_INT32(env
.CP0_Debug
, MIPSCPU
),
293 VMSTATE_UINTTL(env
.CP0_DEPC
, MIPSCPU
),
294 VMSTATE_INT32(env
.CP0_Performance0
, MIPSCPU
),
295 VMSTATE_UINT64(env
.CP0_TagLo
, MIPSCPU
),
296 VMSTATE_INT32(env
.CP0_DataLo
, MIPSCPU
),
297 VMSTATE_INT32(env
.CP0_TagHi
, MIPSCPU
),
298 VMSTATE_INT32(env
.CP0_DataHi
, MIPSCPU
),
299 VMSTATE_UINTTL(env
.CP0_ErrorEPC
, MIPSCPU
),
300 VMSTATE_INT32(env
.CP0_DESAVE
, MIPSCPU
),
301 VMSTATE_UINTTL_ARRAY(env
.CP0_KScratch
, MIPSCPU
, MIPS_KSCRATCH_NUM
),
304 VMSTATE_STRUCT_ARRAY(env
.tcs
, MIPSCPU
, MIPS_SHADOW_SET_MAX
, 1,
305 vmstate_inactive_tc
, TCState
),
306 VMSTATE_STRUCT_ARRAY(env
.fpus
, MIPSCPU
, MIPS_FPU_MAX
, 1,
307 vmstate_inactive_fpu
, CPUMIPSFPUContext
),
309 VMSTATE_END_OF_LIST()