3 #include "sysemu/kvm.h"
7 static bool vfp_needed(void *opaque
)
10 CPUARMState
*env
= &cpu
->env
;
12 return arm_feature(env
, ARM_FEATURE_VFP
);
15 static int get_fpscr(QEMUFile
*f
, void *opaque
, size_t size
)
18 CPUARMState
*env
= &cpu
->env
;
19 uint32_t val
= qemu_get_be32(f
);
21 vfp_set_fpscr(env
, val
);
25 static void put_fpscr(QEMUFile
*f
, void *opaque
, size_t size
)
28 CPUARMState
*env
= &cpu
->env
;
30 qemu_put_be32(f
, vfp_get_fpscr(env
));
33 static const VMStateInfo vmstate_fpscr
= {
39 static const VMStateDescription vmstate_vfp
= {
42 .minimum_version_id
= 3,
44 .fields
= (VMStateField
[]) {
45 VMSTATE_FLOAT64_ARRAY(env
.vfp
.regs
, ARMCPU
, 64),
46 /* The xregs array is a little awkward because element 1 (FPSCR)
47 * requires a specific accessor, so we have to split it up in
50 VMSTATE_UINT32(env
.vfp
.xregs
[0], ARMCPU
),
51 VMSTATE_UINT32_SUB_ARRAY(env
.vfp
.xregs
, ARMCPU
, 2, 14),
55 .size
= sizeof(uint32_t),
56 .info
= &vmstate_fpscr
,
64 static bool iwmmxt_needed(void *opaque
)
67 CPUARMState
*env
= &cpu
->env
;
69 return arm_feature(env
, ARM_FEATURE_IWMMXT
);
72 static const VMStateDescription vmstate_iwmmxt
= {
75 .minimum_version_id
= 1,
76 .needed
= iwmmxt_needed
,
77 .fields
= (VMStateField
[]) {
78 VMSTATE_UINT64_ARRAY(env
.iwmmxt
.regs
, ARMCPU
, 16),
79 VMSTATE_UINT32_ARRAY(env
.iwmmxt
.cregs
, ARMCPU
, 16),
84 static bool m_needed(void *opaque
)
87 CPUARMState
*env
= &cpu
->env
;
89 return arm_feature(env
, ARM_FEATURE_M
);
92 static const VMStateDescription vmstate_m
= {
95 .minimum_version_id
= 1,
97 .fields
= (VMStateField
[]) {
98 VMSTATE_UINT32(env
.v7m
.other_sp
, ARMCPU
),
99 VMSTATE_UINT32(env
.v7m
.vecbase
, ARMCPU
),
100 VMSTATE_UINT32(env
.v7m
.basepri
, ARMCPU
),
101 VMSTATE_UINT32(env
.v7m
.control
, ARMCPU
),
102 VMSTATE_INT32(env
.v7m
.current_sp
, ARMCPU
),
103 VMSTATE_INT32(env
.v7m
.exception
, ARMCPU
),
104 VMSTATE_END_OF_LIST()
108 static bool thumb2ee_needed(void *opaque
)
110 ARMCPU
*cpu
= opaque
;
111 CPUARMState
*env
= &cpu
->env
;
113 return arm_feature(env
, ARM_FEATURE_THUMB2EE
);
116 static const VMStateDescription vmstate_thumb2ee
= {
117 .name
= "cpu/thumb2ee",
119 .minimum_version_id
= 1,
120 .needed
= thumb2ee_needed
,
121 .fields
= (VMStateField
[]) {
122 VMSTATE_UINT32(env
.teecr
, ARMCPU
),
123 VMSTATE_UINT32(env
.teehbr
, ARMCPU
),
124 VMSTATE_END_OF_LIST()
128 static int get_cpsr(QEMUFile
*f
, void *opaque
, size_t size
)
130 ARMCPU
*cpu
= opaque
;
131 CPUARMState
*env
= &cpu
->env
;
132 uint32_t val
= qemu_get_be32(f
);
134 env
->aarch64
= ((val
& PSTATE_nRW
) == 0);
137 pstate_write(env
, val
);
141 /* Avoid mode switch when restoring CPSR */
142 env
->uncached_cpsr
= val
& CPSR_M
;
143 cpsr_write(env
, val
, 0xffffffff);
147 static void put_cpsr(QEMUFile
*f
, void *opaque
, size_t size
)
149 ARMCPU
*cpu
= opaque
;
150 CPUARMState
*env
= &cpu
->env
;
154 val
= pstate_read(env
);
156 val
= cpsr_read(env
);
159 qemu_put_be32(f
, val
);
162 static const VMStateInfo vmstate_cpsr
= {
168 static void cpu_pre_save(void *opaque
)
170 ARMCPU
*cpu
= opaque
;
173 if (!write_kvmstate_to_list(cpu
)) {
174 /* This should never fail */
178 if (!write_cpustate_to_list(cpu
)) {
179 /* This should never fail. */
184 cpu
->cpreg_vmstate_array_len
= cpu
->cpreg_array_len
;
185 memcpy(cpu
->cpreg_vmstate_indexes
, cpu
->cpreg_indexes
,
186 cpu
->cpreg_array_len
* sizeof(uint64_t));
187 memcpy(cpu
->cpreg_vmstate_values
, cpu
->cpreg_values
,
188 cpu
->cpreg_array_len
* sizeof(uint64_t));
191 static int cpu_post_load(void *opaque
, int version_id
)
193 ARMCPU
*cpu
= opaque
;
196 /* Update the values list from the incoming migration data.
197 * Anything in the incoming data which we don't know about is
198 * a migration failure; anything we know about but the incoming
199 * data doesn't specify retains its current (reset) value.
200 * The indexes list remains untouched -- we only inspect the
201 * incoming migration index list so we can match the values array
202 * entries with the right slots in our own values array.
205 for (i
= 0, v
= 0; i
< cpu
->cpreg_array_len
206 && v
< cpu
->cpreg_vmstate_array_len
; i
++) {
207 if (cpu
->cpreg_vmstate_indexes
[v
] > cpu
->cpreg_indexes
[i
]) {
208 /* register in our list but not incoming : skip it */
211 if (cpu
->cpreg_vmstate_indexes
[v
] < cpu
->cpreg_indexes
[i
]) {
212 /* register in their list but not ours: fail migration */
215 /* matching register, copy the value over */
216 cpu
->cpreg_values
[i
] = cpu
->cpreg_vmstate_values
[v
];
221 if (!write_list_to_kvmstate(cpu
)) {
224 /* Note that it's OK for the TCG side not to know about
225 * every register in the list; KVM is authoritative if
228 write_list_to_cpustate(cpu
);
230 if (!write_list_to_cpustate(cpu
)) {
235 hw_breakpoint_update_all(cpu
);
236 hw_watchpoint_update_all(cpu
);
241 const VMStateDescription vmstate_arm_cpu
= {
244 .minimum_version_id
= 22,
245 .pre_save
= cpu_pre_save
,
246 .post_load
= cpu_post_load
,
247 .fields
= (VMStateField
[]) {
248 VMSTATE_UINT32_ARRAY(env
.regs
, ARMCPU
, 16),
249 VMSTATE_UINT64_ARRAY(env
.xregs
, ARMCPU
, 32),
250 VMSTATE_UINT64(env
.pc
, ARMCPU
),
254 .size
= sizeof(uint32_t),
255 .info
= &vmstate_cpsr
,
259 VMSTATE_UINT32(env
.spsr
, ARMCPU
),
260 VMSTATE_UINT64_ARRAY(env
.banked_spsr
, ARMCPU
, 8),
261 VMSTATE_UINT32_ARRAY(env
.banked_r13
, ARMCPU
, 8),
262 VMSTATE_UINT32_ARRAY(env
.banked_r14
, ARMCPU
, 8),
263 VMSTATE_UINT32_ARRAY(env
.usr_regs
, ARMCPU
, 5),
264 VMSTATE_UINT32_ARRAY(env
.fiq_regs
, ARMCPU
, 5),
265 VMSTATE_UINT64_ARRAY(env
.elr_el
, ARMCPU
, 4),
266 VMSTATE_UINT64_ARRAY(env
.sp_el
, ARMCPU
, 4),
267 /* The length-check must come before the arrays to avoid
268 * incoming data possibly overflowing the array.
270 VMSTATE_INT32_POSITIVE_LE(cpreg_vmstate_array_len
, ARMCPU
),
271 VMSTATE_VARRAY_INT32(cpreg_vmstate_indexes
, ARMCPU
,
272 cpreg_vmstate_array_len
,
273 0, vmstate_info_uint64
, uint64_t),
274 VMSTATE_VARRAY_INT32(cpreg_vmstate_values
, ARMCPU
,
275 cpreg_vmstate_array_len
,
276 0, vmstate_info_uint64
, uint64_t),
277 VMSTATE_UINT64(env
.exclusive_addr
, ARMCPU
),
278 VMSTATE_UINT64(env
.exclusive_val
, ARMCPU
),
279 VMSTATE_UINT64(env
.exclusive_high
, ARMCPU
),
280 VMSTATE_UINT64(env
.features
, ARMCPU
),
281 VMSTATE_UINT32(env
.exception
.syndrome
, ARMCPU
),
282 VMSTATE_UINT32(env
.exception
.fsr
, ARMCPU
),
283 VMSTATE_UINT64(env
.exception
.vaddress
, ARMCPU
),
284 VMSTATE_TIMER_PTR(gt_timer
[GTIMER_PHYS
], ARMCPU
),
285 VMSTATE_TIMER_PTR(gt_timer
[GTIMER_VIRT
], ARMCPU
),
286 VMSTATE_BOOL(powered_off
, ARMCPU
),
287 VMSTATE_END_OF_LIST()
289 .subsections
= (const VMStateDescription
*[]) {