1 #include "qemu/osdep.h"
3 #include "qemu/error-report.h"
4 #include "sysemu/kvm.h"
5 #include "sysemu/tcg.h"
8 #include "cpu-features.h"
9 #include "migration/cpu.h"
10 #include "target/arm/gtimer.h"
12 static bool vfp_needed(void *opaque
)
16 return (arm_feature(&cpu
->env
, ARM_FEATURE_AARCH64
)
17 ? cpu_isar_feature(aa64_fp_simd
, cpu
)
18 : cpu_isar_feature(aa32_vfp_simd
, cpu
));
21 static int get_fpscr(QEMUFile
*f
, void *opaque
, size_t size
,
22 const VMStateField
*field
)
25 CPUARMState
*env
= &cpu
->env
;
26 uint32_t val
= qemu_get_be32(f
);
28 vfp_set_fpscr(env
, val
);
32 static int put_fpscr(QEMUFile
*f
, void *opaque
, size_t size
,
33 const VMStateField
*field
, JSONWriter
*vmdesc
)
36 CPUARMState
*env
= &cpu
->env
;
38 qemu_put_be32(f
, vfp_get_fpscr(env
));
42 static const VMStateInfo vmstate_fpscr
= {
48 static const VMStateDescription vmstate_vfp
= {
51 .minimum_version_id
= 3,
53 .fields
= (const VMStateField
[]) {
54 /* For compatibility, store Qn out of Zn here. */
55 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[0].d
, ARMCPU
, 0, 2),
56 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[1].d
, ARMCPU
, 0, 2),
57 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[2].d
, ARMCPU
, 0, 2),
58 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[3].d
, ARMCPU
, 0, 2),
59 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[4].d
, ARMCPU
, 0, 2),
60 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[5].d
, ARMCPU
, 0, 2),
61 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[6].d
, ARMCPU
, 0, 2),
62 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[7].d
, ARMCPU
, 0, 2),
63 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[8].d
, ARMCPU
, 0, 2),
64 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[9].d
, ARMCPU
, 0, 2),
65 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[10].d
, ARMCPU
, 0, 2),
66 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[11].d
, ARMCPU
, 0, 2),
67 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[12].d
, ARMCPU
, 0, 2),
68 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[13].d
, ARMCPU
, 0, 2),
69 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[14].d
, ARMCPU
, 0, 2),
70 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[15].d
, ARMCPU
, 0, 2),
71 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[16].d
, ARMCPU
, 0, 2),
72 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[17].d
, ARMCPU
, 0, 2),
73 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[18].d
, ARMCPU
, 0, 2),
74 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[19].d
, ARMCPU
, 0, 2),
75 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[20].d
, ARMCPU
, 0, 2),
76 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[21].d
, ARMCPU
, 0, 2),
77 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[22].d
, ARMCPU
, 0, 2),
78 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[23].d
, ARMCPU
, 0, 2),
79 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[24].d
, ARMCPU
, 0, 2),
80 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[25].d
, ARMCPU
, 0, 2),
81 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[26].d
, ARMCPU
, 0, 2),
82 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[27].d
, ARMCPU
, 0, 2),
83 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[28].d
, ARMCPU
, 0, 2),
84 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[29].d
, ARMCPU
, 0, 2),
85 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[30].d
, ARMCPU
, 0, 2),
86 VMSTATE_UINT64_SUB_ARRAY(env
.vfp
.zregs
[31].d
, ARMCPU
, 0, 2),
88 /* The xregs array is a little awkward because element 1 (FPSCR)
89 * requires a specific accessor, so we have to split it up in
92 VMSTATE_UINT32(env
.vfp
.xregs
[0], ARMCPU
),
93 VMSTATE_UINT32_SUB_ARRAY(env
.vfp
.xregs
, ARMCPU
, 2, 14),
97 .size
= sizeof(uint32_t),
98 .info
= &vmstate_fpscr
,
102 VMSTATE_END_OF_LIST()
106 static bool iwmmxt_needed(void *opaque
)
108 ARMCPU
*cpu
= opaque
;
109 CPUARMState
*env
= &cpu
->env
;
111 return arm_feature(env
, ARM_FEATURE_IWMMXT
);
114 static const VMStateDescription vmstate_iwmmxt
= {
115 .name
= "cpu/iwmmxt",
117 .minimum_version_id
= 1,
118 .needed
= iwmmxt_needed
,
119 .fields
= (const VMStateField
[]) {
120 VMSTATE_UINT64_ARRAY(env
.iwmmxt
.regs
, ARMCPU
, 16),
121 VMSTATE_UINT32_ARRAY(env
.iwmmxt
.cregs
, ARMCPU
, 16),
122 VMSTATE_END_OF_LIST()
126 #ifdef TARGET_AARCH64
127 /* The expression ARM_MAX_VQ - 2 is 0 for pure AArch32 build,
128 * and ARMPredicateReg is actively empty. This triggers errors
129 * in the expansion of the VMSTATE macros.
132 static bool sve_needed(void *opaque
)
134 ARMCPU
*cpu
= opaque
;
136 return cpu_isar_feature(aa64_sve
, cpu
);
139 /* The first two words of each Zreg is stored in VFP state. */
140 static const VMStateDescription vmstate_zreg_hi_reg
= {
141 .name
= "cpu/sve/zreg_hi",
143 .minimum_version_id
= 1,
144 .fields
= (const VMStateField
[]) {
145 VMSTATE_UINT64_SUB_ARRAY(d
, ARMVectorReg
, 2, ARM_MAX_VQ
- 2),
146 VMSTATE_END_OF_LIST()
150 static const VMStateDescription vmstate_preg_reg
= {
151 .name
= "cpu/sve/preg",
153 .minimum_version_id
= 1,
154 .fields
= (const VMStateField
[]) {
155 VMSTATE_UINT64_ARRAY(p
, ARMPredicateReg
, 2 * ARM_MAX_VQ
/ 8),
156 VMSTATE_END_OF_LIST()
160 static const VMStateDescription vmstate_sve
= {
163 .minimum_version_id
= 1,
164 .needed
= sve_needed
,
165 .fields
= (const VMStateField
[]) {
166 VMSTATE_STRUCT_ARRAY(env
.vfp
.zregs
, ARMCPU
, 32, 0,
167 vmstate_zreg_hi_reg
, ARMVectorReg
),
168 VMSTATE_STRUCT_ARRAY(env
.vfp
.pregs
, ARMCPU
, 17, 0,
169 vmstate_preg_reg
, ARMPredicateReg
),
170 VMSTATE_END_OF_LIST()
174 static const VMStateDescription vmstate_vreg
= {
177 .minimum_version_id
= 1,
178 .fields
= (const VMStateField
[]) {
179 VMSTATE_UINT64_ARRAY(d
, ARMVectorReg
, ARM_MAX_VQ
* 2),
180 VMSTATE_END_OF_LIST()
184 static bool za_needed(void *opaque
)
186 ARMCPU
*cpu
= opaque
;
189 * When ZA storage is disabled, its contents are discarded.
190 * It will be zeroed when ZA storage is re-enabled.
192 return FIELD_EX64(cpu
->env
.svcr
, SVCR
, ZA
);
195 static const VMStateDescription vmstate_za
= {
198 .minimum_version_id
= 1,
200 .fields
= (const VMStateField
[]) {
201 VMSTATE_STRUCT_ARRAY(env
.zarray
, ARMCPU
, ARM_MAX_VQ
* 16, 0,
202 vmstate_vreg
, ARMVectorReg
),
203 VMSTATE_END_OF_LIST()
208 static bool serror_needed(void *opaque
)
210 ARMCPU
*cpu
= opaque
;
211 CPUARMState
*env
= &cpu
->env
;
213 return env
->serror
.pending
!= 0;
216 static const VMStateDescription vmstate_serror
= {
217 .name
= "cpu/serror",
219 .minimum_version_id
= 1,
220 .needed
= serror_needed
,
221 .fields
= (const VMStateField
[]) {
222 VMSTATE_UINT8(env
.serror
.pending
, ARMCPU
),
223 VMSTATE_UINT8(env
.serror
.has_esr
, ARMCPU
),
224 VMSTATE_UINT64(env
.serror
.esr
, ARMCPU
),
225 VMSTATE_END_OF_LIST()
229 static bool irq_line_state_needed(void *opaque
)
234 static const VMStateDescription vmstate_irq_line_state
= {
235 .name
= "cpu/irq-line-state",
237 .minimum_version_id
= 1,
238 .needed
= irq_line_state_needed
,
239 .fields
= (const VMStateField
[]) {
240 VMSTATE_UINT32(env
.irq_line_state
, ARMCPU
),
241 VMSTATE_END_OF_LIST()
245 static bool m_needed(void *opaque
)
247 ARMCPU
*cpu
= opaque
;
248 CPUARMState
*env
= &cpu
->env
;
250 return arm_feature(env
, ARM_FEATURE_M
);
253 static const VMStateDescription vmstate_m_faultmask_primask
= {
254 .name
= "cpu/m/faultmask-primask",
256 .minimum_version_id
= 1,
258 .fields
= (const VMStateField
[]) {
259 VMSTATE_UINT32(env
.v7m
.faultmask
[M_REG_NS
], ARMCPU
),
260 VMSTATE_UINT32(env
.v7m
.primask
[M_REG_NS
], ARMCPU
),
261 VMSTATE_END_OF_LIST()
265 /* CSSELR is in a subsection because we didn't implement it previously.
266 * Migration from an old implementation will leave it at zero, which
267 * is OK since the only CPUs in the old implementation make the
269 * Since there was no version of QEMU which implemented the CSSELR for
270 * just non-secure, we transfer both banks here rather than putting
271 * the secure banked version in the m-security subsection.
273 static bool csselr_vmstate_validate(void *opaque
, int version_id
)
275 ARMCPU
*cpu
= opaque
;
277 return cpu
->env
.v7m
.csselr
[M_REG_NS
] <= R_V7M_CSSELR_INDEX_MASK
278 && cpu
->env
.v7m
.csselr
[M_REG_S
] <= R_V7M_CSSELR_INDEX_MASK
;
281 static bool m_csselr_needed(void *opaque
)
283 ARMCPU
*cpu
= opaque
;
285 return !arm_v7m_csselr_razwi(cpu
);
288 static const VMStateDescription vmstate_m_csselr
= {
289 .name
= "cpu/m/csselr",
291 .minimum_version_id
= 1,
292 .needed
= m_csselr_needed
,
293 .fields
= (const VMStateField
[]) {
294 VMSTATE_UINT32_ARRAY(env
.v7m
.csselr
, ARMCPU
, M_REG_NUM_BANKS
),
295 VMSTATE_VALIDATE("CSSELR is valid", csselr_vmstate_validate
),
296 VMSTATE_END_OF_LIST()
300 static const VMStateDescription vmstate_m_scr
= {
303 .minimum_version_id
= 1,
305 .fields
= (const VMStateField
[]) {
306 VMSTATE_UINT32(env
.v7m
.scr
[M_REG_NS
], ARMCPU
),
307 VMSTATE_END_OF_LIST()
311 static const VMStateDescription vmstate_m_other_sp
= {
312 .name
= "cpu/m/other-sp",
314 .minimum_version_id
= 1,
316 .fields
= (const VMStateField
[]) {
317 VMSTATE_UINT32(env
.v7m
.other_sp
, ARMCPU
),
318 VMSTATE_END_OF_LIST()
322 static bool m_v8m_needed(void *opaque
)
324 ARMCPU
*cpu
= opaque
;
325 CPUARMState
*env
= &cpu
->env
;
327 return arm_feature(env
, ARM_FEATURE_M
) && arm_feature(env
, ARM_FEATURE_V8
);
330 static const VMStateDescription vmstate_m_v8m
= {
333 .minimum_version_id
= 1,
334 .needed
= m_v8m_needed
,
335 .fields
= (const VMStateField
[]) {
336 VMSTATE_UINT32_ARRAY(env
.v7m
.msplim
, ARMCPU
, M_REG_NUM_BANKS
),
337 VMSTATE_UINT32_ARRAY(env
.v7m
.psplim
, ARMCPU
, M_REG_NUM_BANKS
),
338 VMSTATE_END_OF_LIST()
342 static const VMStateDescription vmstate_m_fp
= {
345 .minimum_version_id
= 1,
346 .needed
= vfp_needed
,
347 .fields
= (const VMStateField
[]) {
348 VMSTATE_UINT32_ARRAY(env
.v7m
.fpcar
, ARMCPU
, M_REG_NUM_BANKS
),
349 VMSTATE_UINT32_ARRAY(env
.v7m
.fpccr
, ARMCPU
, M_REG_NUM_BANKS
),
350 VMSTATE_UINT32_ARRAY(env
.v7m
.fpdscr
, ARMCPU
, M_REG_NUM_BANKS
),
351 VMSTATE_UINT32_ARRAY(env
.v7m
.cpacr
, ARMCPU
, M_REG_NUM_BANKS
),
352 VMSTATE_UINT32(env
.v7m
.nsacr
, ARMCPU
),
353 VMSTATE_END_OF_LIST()
357 static bool mve_needed(void *opaque
)
359 ARMCPU
*cpu
= opaque
;
361 return cpu_isar_feature(aa32_mve
, cpu
);
364 static const VMStateDescription vmstate_m_mve
= {
367 .minimum_version_id
= 1,
368 .needed
= mve_needed
,
369 .fields
= (const VMStateField
[]) {
370 VMSTATE_UINT32(env
.v7m
.vpr
, ARMCPU
),
371 VMSTATE_UINT32(env
.v7m
.ltpsize
, ARMCPU
),
372 VMSTATE_END_OF_LIST()
376 static const VMStateDescription vmstate_m
= {
379 .minimum_version_id
= 4,
381 .fields
= (const VMStateField
[]) {
382 VMSTATE_UINT32(env
.v7m
.vecbase
[M_REG_NS
], ARMCPU
),
383 VMSTATE_UINT32(env
.v7m
.basepri
[M_REG_NS
], ARMCPU
),
384 VMSTATE_UINT32(env
.v7m
.control
[M_REG_NS
], ARMCPU
),
385 VMSTATE_UINT32(env
.v7m
.ccr
[M_REG_NS
], ARMCPU
),
386 VMSTATE_UINT32(env
.v7m
.cfsr
[M_REG_NS
], ARMCPU
),
387 VMSTATE_UINT32(env
.v7m
.hfsr
, ARMCPU
),
388 VMSTATE_UINT32(env
.v7m
.dfsr
, ARMCPU
),
389 VMSTATE_UINT32(env
.v7m
.mmfar
[M_REG_NS
], ARMCPU
),
390 VMSTATE_UINT32(env
.v7m
.bfar
, ARMCPU
),
391 VMSTATE_UINT32(env
.v7m
.mpu_ctrl
[M_REG_NS
], ARMCPU
),
392 VMSTATE_INT32(env
.v7m
.exception
, ARMCPU
),
393 VMSTATE_END_OF_LIST()
395 .subsections
= (const VMStateDescription
* const []) {
396 &vmstate_m_faultmask_primask
,
407 static bool thumb2ee_needed(void *opaque
)
409 ARMCPU
*cpu
= opaque
;
410 CPUARMState
*env
= &cpu
->env
;
412 return arm_feature(env
, ARM_FEATURE_THUMB2EE
);
415 static const VMStateDescription vmstate_thumb2ee
= {
416 .name
= "cpu/thumb2ee",
418 .minimum_version_id
= 1,
419 .needed
= thumb2ee_needed
,
420 .fields
= (const VMStateField
[]) {
421 VMSTATE_UINT32(env
.teecr
, ARMCPU
),
422 VMSTATE_UINT32(env
.teehbr
, ARMCPU
),
423 VMSTATE_END_OF_LIST()
427 static bool pmsav7_needed(void *opaque
)
429 ARMCPU
*cpu
= opaque
;
430 CPUARMState
*env
= &cpu
->env
;
432 return arm_feature(env
, ARM_FEATURE_PMSA
) &&
433 arm_feature(env
, ARM_FEATURE_V7
) &&
434 !arm_feature(env
, ARM_FEATURE_V8
);
437 static bool pmsav7_rgnr_vmstate_validate(void *opaque
, int version_id
)
439 ARMCPU
*cpu
= opaque
;
441 return cpu
->env
.pmsav7
.rnr
[M_REG_NS
] < cpu
->pmsav7_dregion
;
444 static const VMStateDescription vmstate_pmsav7
= {
445 .name
= "cpu/pmsav7",
447 .minimum_version_id
= 1,
448 .needed
= pmsav7_needed
,
449 .fields
= (const VMStateField
[]) {
450 VMSTATE_VARRAY_UINT32(env
.pmsav7
.drbar
, ARMCPU
, pmsav7_dregion
, 0,
451 vmstate_info_uint32
, uint32_t),
452 VMSTATE_VARRAY_UINT32(env
.pmsav7
.drsr
, ARMCPU
, pmsav7_dregion
, 0,
453 vmstate_info_uint32
, uint32_t),
454 VMSTATE_VARRAY_UINT32(env
.pmsav7
.dracr
, ARMCPU
, pmsav7_dregion
, 0,
455 vmstate_info_uint32
, uint32_t),
456 VMSTATE_VALIDATE("rgnr is valid", pmsav7_rgnr_vmstate_validate
),
457 VMSTATE_END_OF_LIST()
461 static bool pmsav7_rnr_needed(void *opaque
)
463 ARMCPU
*cpu
= opaque
;
464 CPUARMState
*env
= &cpu
->env
;
466 /* For R profile cores pmsav7.rnr is migrated via the cpreg
467 * "RGNR" definition in helper.h. For M profile we have to
468 * migrate it separately.
470 return arm_feature(env
, ARM_FEATURE_M
);
473 static const VMStateDescription vmstate_pmsav7_rnr
= {
474 .name
= "cpu/pmsav7-rnr",
476 .minimum_version_id
= 1,
477 .needed
= pmsav7_rnr_needed
,
478 .fields
= (const VMStateField
[]) {
479 VMSTATE_UINT32(env
.pmsav7
.rnr
[M_REG_NS
], ARMCPU
),
480 VMSTATE_END_OF_LIST()
484 static bool pmsav8_needed(void *opaque
)
486 ARMCPU
*cpu
= opaque
;
487 CPUARMState
*env
= &cpu
->env
;
489 return arm_feature(env
, ARM_FEATURE_PMSA
) &&
490 arm_feature(env
, ARM_FEATURE_V8
);
493 static bool pmsav8r_needed(void *opaque
)
495 ARMCPU
*cpu
= opaque
;
496 CPUARMState
*env
= &cpu
->env
;
498 return arm_feature(env
, ARM_FEATURE_PMSA
) &&
499 arm_feature(env
, ARM_FEATURE_V8
) &&
500 !arm_feature(env
, ARM_FEATURE_M
);
503 static const VMStateDescription vmstate_pmsav8r
= {
504 .name
= "cpu/pmsav8/pmsav8r",
506 .minimum_version_id
= 1,
507 .needed
= pmsav8r_needed
,
508 .fields
= (const VMStateField
[]) {
509 VMSTATE_VARRAY_UINT32(env
.pmsav8
.hprbar
, ARMCPU
,
510 pmsav8r_hdregion
, 0, vmstate_info_uint32
, uint32_t),
511 VMSTATE_VARRAY_UINT32(env
.pmsav8
.hprlar
, ARMCPU
,
512 pmsav8r_hdregion
, 0, vmstate_info_uint32
, uint32_t),
513 VMSTATE_END_OF_LIST()
517 static const VMStateDescription vmstate_pmsav8
= {
518 .name
= "cpu/pmsav8",
520 .minimum_version_id
= 1,
521 .needed
= pmsav8_needed
,
522 .fields
= (const VMStateField
[]) {
523 VMSTATE_VARRAY_UINT32(env
.pmsav8
.rbar
[M_REG_NS
], ARMCPU
, pmsav7_dregion
,
524 0, vmstate_info_uint32
, uint32_t),
525 VMSTATE_VARRAY_UINT32(env
.pmsav8
.rlar
[M_REG_NS
], ARMCPU
, pmsav7_dregion
,
526 0, vmstate_info_uint32
, uint32_t),
527 VMSTATE_UINT32(env
.pmsav8
.mair0
[M_REG_NS
], ARMCPU
),
528 VMSTATE_UINT32(env
.pmsav8
.mair1
[M_REG_NS
], ARMCPU
),
529 VMSTATE_END_OF_LIST()
531 .subsections
= (const VMStateDescription
* const []) {
537 static bool s_rnr_vmstate_validate(void *opaque
, int version_id
)
539 ARMCPU
*cpu
= opaque
;
541 return cpu
->env
.pmsav7
.rnr
[M_REG_S
] < cpu
->pmsav7_dregion
;
544 static bool sau_rnr_vmstate_validate(void *opaque
, int version_id
)
546 ARMCPU
*cpu
= opaque
;
548 return cpu
->env
.sau
.rnr
< cpu
->sau_sregion
;
551 static bool m_security_needed(void *opaque
)
553 ARMCPU
*cpu
= opaque
;
554 CPUARMState
*env
= &cpu
->env
;
556 return arm_feature(env
, ARM_FEATURE_M_SECURITY
);
559 static const VMStateDescription vmstate_m_security
= {
560 .name
= "cpu/m-security",
562 .minimum_version_id
= 1,
563 .needed
= m_security_needed
,
564 .fields
= (const VMStateField
[]) {
565 VMSTATE_UINT32(env
.v7m
.secure
, ARMCPU
),
566 VMSTATE_UINT32(env
.v7m
.other_ss_msp
, ARMCPU
),
567 VMSTATE_UINT32(env
.v7m
.other_ss_psp
, ARMCPU
),
568 VMSTATE_UINT32(env
.v7m
.basepri
[M_REG_S
], ARMCPU
),
569 VMSTATE_UINT32(env
.v7m
.primask
[M_REG_S
], ARMCPU
),
570 VMSTATE_UINT32(env
.v7m
.faultmask
[M_REG_S
], ARMCPU
),
571 VMSTATE_UINT32(env
.v7m
.control
[M_REG_S
], ARMCPU
),
572 VMSTATE_UINT32(env
.v7m
.vecbase
[M_REG_S
], ARMCPU
),
573 VMSTATE_UINT32(env
.pmsav8
.mair0
[M_REG_S
], ARMCPU
),
574 VMSTATE_UINT32(env
.pmsav8
.mair1
[M_REG_S
], ARMCPU
),
575 VMSTATE_VARRAY_UINT32(env
.pmsav8
.rbar
[M_REG_S
], ARMCPU
, pmsav7_dregion
,
576 0, vmstate_info_uint32
, uint32_t),
577 VMSTATE_VARRAY_UINT32(env
.pmsav8
.rlar
[M_REG_S
], ARMCPU
, pmsav7_dregion
,
578 0, vmstate_info_uint32
, uint32_t),
579 VMSTATE_UINT32(env
.pmsav7
.rnr
[M_REG_S
], ARMCPU
),
580 VMSTATE_VALIDATE("secure MPU_RNR is valid", s_rnr_vmstate_validate
),
581 VMSTATE_UINT32(env
.v7m
.mpu_ctrl
[M_REG_S
], ARMCPU
),
582 VMSTATE_UINT32(env
.v7m
.ccr
[M_REG_S
], ARMCPU
),
583 VMSTATE_UINT32(env
.v7m
.mmfar
[M_REG_S
], ARMCPU
),
584 VMSTATE_UINT32(env
.v7m
.cfsr
[M_REG_S
], ARMCPU
),
585 VMSTATE_UINT32(env
.v7m
.sfsr
, ARMCPU
),
586 VMSTATE_UINT32(env
.v7m
.sfar
, ARMCPU
),
587 VMSTATE_VARRAY_UINT32(env
.sau
.rbar
, ARMCPU
, sau_sregion
, 0,
588 vmstate_info_uint32
, uint32_t),
589 VMSTATE_VARRAY_UINT32(env
.sau
.rlar
, ARMCPU
, sau_sregion
, 0,
590 vmstate_info_uint32
, uint32_t),
591 VMSTATE_UINT32(env
.sau
.rnr
, ARMCPU
),
592 VMSTATE_VALIDATE("SAU_RNR is valid", sau_rnr_vmstate_validate
),
593 VMSTATE_UINT32(env
.sau
.ctrl
, ARMCPU
),
594 VMSTATE_UINT32(env
.v7m
.scr
[M_REG_S
], ARMCPU
),
595 /* AIRCR is not secure-only, but our implementation is R/O if the
596 * security extension is unimplemented, so we migrate it here.
598 VMSTATE_UINT32(env
.v7m
.aircr
, ARMCPU
),
599 VMSTATE_END_OF_LIST()
603 static int get_cpsr(QEMUFile
*f
, void *opaque
, size_t size
,
604 const VMStateField
*field
)
606 ARMCPU
*cpu
= opaque
;
607 CPUARMState
*env
= &cpu
->env
;
608 uint32_t val
= qemu_get_be32(f
);
610 if (arm_feature(env
, ARM_FEATURE_M
)) {
611 if (val
& XPSR_EXCP
) {
612 /* This is a CPSR format value from an older QEMU. (We can tell
613 * because values transferred in XPSR format always have zero
614 * for the EXCP field, and CPSR format will always have bit 4
615 * set in CPSR_M.) Rearrange it into XPSR format. The significant
616 * differences are that the T bit is not in the same place, the
617 * primask/faultmask info may be in the CPSR I and F bits, and
618 * we do not want the mode bits.
619 * We know that this cleanup happened before v8M, so there
620 * is no complication with banked primask/faultmask.
622 uint32_t newval
= val
;
624 assert(!arm_feature(env
, ARM_FEATURE_M_SECURITY
));
626 newval
&= (CPSR_NZCV
| CPSR_Q
| CPSR_IT
| CPSR_GE
);
630 /* If the I or F bits are set then this is a migration from
631 * an old QEMU which still stored the M profile FAULTMASK
632 * and PRIMASK in env->daif. For a new QEMU, the data is
633 * transferred using the vmstate_m_faultmask_primask subsection.
636 env
->v7m
.faultmask
[M_REG_NS
] = 1;
639 env
->v7m
.primask
[M_REG_NS
] = 1;
643 /* Ignore the low bits, they are handled by vmstate_m. */
644 xpsr_write(env
, val
, ~XPSR_EXCP
);
648 env
->aarch64
= ((val
& PSTATE_nRW
) == 0);
651 pstate_write(env
, val
);
655 cpsr_write(env
, val
, 0xffffffff, CPSRWriteRaw
);
659 static int put_cpsr(QEMUFile
*f
, void *opaque
, size_t size
,
660 const VMStateField
*field
, JSONWriter
*vmdesc
)
662 ARMCPU
*cpu
= opaque
;
663 CPUARMState
*env
= &cpu
->env
;
666 if (arm_feature(env
, ARM_FEATURE_M
)) {
667 /* The low 9 bits are v7m.exception, which is handled by vmstate_m. */
668 val
= xpsr_read(env
) & ~XPSR_EXCP
;
669 } else if (is_a64(env
)) {
670 val
= pstate_read(env
);
672 val
= cpsr_read(env
);
675 qemu_put_be32(f
, val
);
679 static const VMStateInfo vmstate_cpsr
= {
685 static int get_power(QEMUFile
*f
, void *opaque
, size_t size
,
686 const VMStateField
*field
)
688 ARMCPU
*cpu
= opaque
;
689 bool powered_off
= qemu_get_byte(f
);
690 cpu
->power_state
= powered_off
? PSCI_OFF
: PSCI_ON
;
694 static int put_power(QEMUFile
*f
, void *opaque
, size_t size
,
695 const VMStateField
*field
, JSONWriter
*vmdesc
)
697 ARMCPU
*cpu
= opaque
;
699 /* Migration should never happen while we transition power states */
701 if (cpu
->power_state
== PSCI_ON
||
702 cpu
->power_state
== PSCI_OFF
) {
703 bool powered_off
= (cpu
->power_state
== PSCI_OFF
) ? true : false;
704 qemu_put_byte(f
, powered_off
);
711 static const VMStateInfo vmstate_powered_off
= {
712 .name
= "powered_off",
717 static int cpu_pre_save(void *opaque
)
719 ARMCPU
*cpu
= opaque
;
721 if (!kvm_enabled()) {
722 pmu_op_start(&cpu
->env
);
726 if (!write_kvmstate_to_list(cpu
)) {
727 /* This should never fail */
728 g_assert_not_reached();
732 * kvm_arm_cpu_pre_save() must be called after
733 * write_kvmstate_to_list()
735 kvm_arm_cpu_pre_save(cpu
);
737 if (!write_cpustate_to_list(cpu
, false)) {
738 /* This should never fail. */
739 g_assert_not_reached();
743 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
744 memcpy(cpu
->cpreg_vmstate_indexes
, cpu
->cpreg_indexes
,
745 cpu
->cpreg_array_len
* sizeof(uint64_t));
746 memcpy(cpu
->cpreg_vmstate_values
, cpu
->cpreg_values
,
747 cpu
->cpreg_array_len
* sizeof(uint64_t));
752 static int cpu_post_save(void *opaque
)
754 ARMCPU
*cpu
= opaque
;
756 if (!kvm_enabled()) {
757 pmu_op_finish(&cpu
->env
);
763 static int cpu_pre_load(void *opaque
)
765 ARMCPU
*cpu
= opaque
;
766 CPUARMState
*env
= &cpu
->env
;
769 * Pre-initialize irq_line_state to a value that's never valid as
770 * real data, so cpu_post_load() can tell whether we've seen the
771 * irq-line-state subsection in the incoming migration state.
773 env
->irq_line_state
= UINT32_MAX
;
775 if (!kvm_enabled()) {
776 pmu_op_start(&cpu
->env
);
782 static int cpu_post_load(void *opaque
, int version_id
)
784 ARMCPU
*cpu
= opaque
;
785 CPUARMState
*env
= &cpu
->env
;
789 * Handle migration compatibility from old QEMU which didn't
790 * send the irq-line-state subsection. A QEMU without it did not
791 * implement the HCR_EL2.{VI,VF} bits as generating interrupts,
792 * so for TCG the line state matches the bits set in cs->interrupt_request.
793 * For KVM the line state is not stored in cs->interrupt_request
794 * and so this will leave irq_line_state as 0, but this is OK because
795 * we only need to care about it for TCG.
797 if (env
->irq_line_state
== UINT32_MAX
) {
798 CPUState
*cs
= CPU(cpu
);
800 env
->irq_line_state
= cs
->interrupt_request
&
801 (CPU_INTERRUPT_HARD
| CPU_INTERRUPT_FIQ
|
802 CPU_INTERRUPT_VIRQ
| CPU_INTERRUPT_VFIQ
);
805 /* Update the values list from the incoming migration data.
806 * Anything in the incoming data which we don't know about is
807 * a migration failure; anything we know about but the incoming
808 * data doesn't specify retains its current (reset) value.
809 * The indexes list remains untouched -- we only inspect the
810 * incoming migration index list so we can match the values array
811 * entries with the right slots in our own values array.
814 for (i
= 0, v
= 0; i
< cpu
->cpreg_array_len
815 && v
< cpu
->cpreg_vmstate_array_len
; i
++) {
816 if (cpu
->cpreg_vmstate_indexes
[v
] > cpu
->cpreg_indexes
[i
]) {
817 /* register in our list but not incoming : skip it */
820 if (cpu
->cpreg_vmstate_indexes
[v
] < cpu
->cpreg_indexes
[i
]) {
821 /* register in their list but not ours: fail migration */
824 /* matching register, copy the value over */
825 cpu
->cpreg_values
[i
] = cpu
->cpreg_vmstate_values
[v
];
830 if (!write_list_to_kvmstate(cpu
, KVM_PUT_FULL_STATE
)) {
833 /* Note that it's OK for the TCG side not to know about
834 * every register in the list; KVM is authoritative if
837 write_list_to_cpustate(cpu
);
838 kvm_arm_cpu_post_load(cpu
);
840 if (!write_list_to_cpustate(cpu
)) {
846 * Misaligned thumb pc is architecturally impossible. Fail the
847 * incoming migration. For TCG it would trigger the assert in
848 * thumb_tr_translate_insn().
850 if (!is_a64(env
) && env
->thumb
&& (env
->regs
[15] & 1)) {
855 hw_breakpoint_update_all(cpu
);
856 hw_watchpoint_update_all(cpu
);
860 * TCG gen_update_fp_context() relies on the invariant that
861 * FPDSCR.LTPSIZE is constant 4 for M-profile with the LOB extension;
862 * forbid bogus incoming data with some other value.
864 if (arm_feature(env
, ARM_FEATURE_M
) && cpu_isar_feature(aa32_lob
, cpu
)) {
865 if (extract32(env
->v7m
.fpdscr
[M_REG_NS
],
866 FPCR_LTPSIZE_SHIFT
, FPCR_LTPSIZE_LENGTH
) != 4 ||
867 extract32(env
->v7m
.fpdscr
[M_REG_S
],
868 FPCR_LTPSIZE_SHIFT
, FPCR_LTPSIZE_LENGTH
) != 4) {
873 if (!kvm_enabled()) {
874 pmu_op_finish(&cpu
->env
);
878 arm_rebuild_hflags(&cpu
->env
);
884 const VMStateDescription vmstate_arm_cpu
= {
887 .minimum_version_id
= 22,
888 .pre_save
= cpu_pre_save
,
889 .post_save
= cpu_post_save
,
890 .pre_load
= cpu_pre_load
,
891 .post_load
= cpu_post_load
,
892 .fields
= (const VMStateField
[]) {
893 VMSTATE_UINT32_ARRAY(env
.regs
, ARMCPU
, 16),
894 VMSTATE_UINT64_ARRAY(env
.xregs
, ARMCPU
, 32),
895 VMSTATE_UINT64(env
.pc
, ARMCPU
),
899 .size
= sizeof(uint32_t),
900 .info
= &vmstate_cpsr
,
904 VMSTATE_UINT32(env
.spsr
, ARMCPU
),
905 VMSTATE_UINT64_ARRAY(env
.banked_spsr
, ARMCPU
, 8),
906 VMSTATE_UINT32_ARRAY(env
.banked_r13
, ARMCPU
, 8),
907 VMSTATE_UINT32_ARRAY(env
.banked_r14
, ARMCPU
, 8),
908 VMSTATE_UINT32_ARRAY(env
.usr_regs
, ARMCPU
, 5),
909 VMSTATE_UINT32_ARRAY(env
.fiq_regs
, ARMCPU
, 5),
910 VMSTATE_UINT64_ARRAY(env
.elr_el
, ARMCPU
, 4),
911 VMSTATE_UINT64_ARRAY(env
.sp_el
, ARMCPU
, 4),
912 /* The length-check must come before the arrays to avoid
913 * incoming data possibly overflowing the array.
915 VMSTATE_INT32_POSITIVE_LE(cpreg_vmstate_array_len
, ARMCPU
),
916 VMSTATE_VARRAY_INT32(cpreg_vmstate_indexes
, ARMCPU
,
917 cpreg_vmstate_array_len
,
918 0, vmstate_info_uint64
, uint64_t),
919 VMSTATE_VARRAY_INT32(cpreg_vmstate_values
, ARMCPU
,
920 cpreg_vmstate_array_len
,
921 0, vmstate_info_uint64
, uint64_t),
922 VMSTATE_UINT64(env
.exclusive_addr
, ARMCPU
),
923 VMSTATE_UINT64(env
.exclusive_val
, ARMCPU
),
924 VMSTATE_UINT64(env
.exclusive_high
, ARMCPU
),
925 VMSTATE_UNUSED(sizeof(uint64_t)),
926 VMSTATE_UINT32(env
.exception
.syndrome
, ARMCPU
),
927 VMSTATE_UINT32(env
.exception
.fsr
, ARMCPU
),
928 VMSTATE_UINT64(env
.exception
.vaddress
, ARMCPU
),
929 VMSTATE_TIMER_PTR(gt_timer
[GTIMER_PHYS
], ARMCPU
),
930 VMSTATE_TIMER_PTR(gt_timer
[GTIMER_VIRT
], ARMCPU
),
932 .name
= "power_state",
934 .size
= sizeof(bool),
935 .info
= &vmstate_powered_off
,
939 VMSTATE_END_OF_LIST()
941 .subsections
= (const VMStateDescription
* const []) {
946 /* pmsav7_rnr must come before pmsav7 so that we have the
947 * region number before we test it in the VMSTATE_VALIDATE
954 #ifdef TARGET_AARCH64
959 &vmstate_irq_line_state
,