1 #include "qemu/osdep.h"
2 #include "qemu-common.h"
4 #include "exec/exec-all.h"
7 #include "sysemu/kvm.h"
8 #include "helper_regs.h"
9 #include "mmu-hash64.h"
10 #include "migration/cpu.h"
11 #include "qapi/error.h"
14 static int cpu_load_old(QEMUFile
*f
, void *opaque
, int version_id
)
16 PowerPCCPU
*cpu
= opaque
;
17 CPUPPCState
*env
= &cpu
->env
;
21 #if defined(TARGET_PPC64)
26 for (i
= 0; i
< 32; i
++)
27 qemu_get_betls(f
, &env
->gpr
[i
]);
28 #if !defined(TARGET_PPC64)
29 for (i
= 0; i
< 32; i
++)
30 qemu_get_betls(f
, &env
->gprh
[i
]);
32 qemu_get_betls(f
, &env
->lr
);
33 qemu_get_betls(f
, &env
->ctr
);
34 for (i
= 0; i
< 8; i
++)
35 qemu_get_be32s(f
, &env
->crf
[i
]);
36 qemu_get_betls(f
, &xer
);
37 cpu_write_xer(env
, xer
);
38 qemu_get_betls(f
, &env
->reserve_addr
);
39 qemu_get_betls(f
, &env
->msr
);
40 for (i
= 0; i
< 4; i
++)
41 qemu_get_betls(f
, &env
->tgpr
[i
]);
42 for (i
= 0; i
< 32; i
++) {
47 u
.l
= qemu_get_be64(f
);
48 *cpu_fpr_ptr(env
, i
) = u
.d
;
50 qemu_get_be32s(f
, &fpscr
);
52 qemu_get_sbe32s(f
, &env
->access_type
);
53 #if defined(TARGET_PPC64)
54 qemu_get_betls(f
, &env
->spr
[SPR_ASR
]);
55 qemu_get_sbe32s(f
, &slb_nr
);
57 qemu_get_betls(f
, &sdr1
);
58 for (i
= 0; i
< 32; i
++)
59 qemu_get_betls(f
, &env
->sr
[i
]);
60 for (i
= 0; i
< 2; i
++)
61 for (j
= 0; j
< 8; j
++)
62 qemu_get_betls(f
, &env
->DBAT
[i
][j
]);
63 for (i
= 0; i
< 2; i
++)
64 for (j
= 0; j
< 8; j
++)
65 qemu_get_betls(f
, &env
->IBAT
[i
][j
]);
66 qemu_get_sbe32s(f
, &env
->nb_tlb
);
67 qemu_get_sbe32s(f
, &env
->tlb_per_way
);
68 qemu_get_sbe32s(f
, &env
->nb_ways
);
69 qemu_get_sbe32s(f
, &env
->last_way
);
70 qemu_get_sbe32s(f
, &env
->id_tlbs
);
71 qemu_get_sbe32s(f
, &env
->nb_pids
);
74 for (i
= 0; i
< env
->nb_tlb
; i
++) {
75 qemu_get_betls(f
, &env
->tlb
.tlb6
[i
].pte0
);
76 qemu_get_betls(f
, &env
->tlb
.tlb6
[i
].pte1
);
77 qemu_get_betls(f
, &env
->tlb
.tlb6
[i
].EPN
);
80 for (i
= 0; i
< 4; i
++)
81 qemu_get_betls(f
, &env
->pb
[i
]);
82 for (i
= 0; i
< 1024; i
++)
83 qemu_get_betls(f
, &env
->spr
[i
]);
85 ppc_store_sdr1(env
, sdr1
);
87 qemu_get_be32s(f
, &env
->vscr
);
88 qemu_get_be64s(f
, &env
->spe_acc
);
89 qemu_get_be32s(f
, &env
->spe_fscr
);
90 qemu_get_betls(f
, &env
->msr_mask
);
91 qemu_get_be32s(f
, &env
->flags
);
92 qemu_get_sbe32s(f
, &env
->error_code
);
93 qemu_get_be32s(f
, &env
->pending_interrupts
);
94 qemu_get_be32s(f
, &env
->irq_input_state
);
95 for (i
= 0; i
< POWERPC_EXCP_NB
; i
++)
96 qemu_get_betls(f
, &env
->excp_vectors
[i
]);
97 qemu_get_betls(f
, &env
->excp_prefix
);
98 qemu_get_betls(f
, &env
->ivor_mask
);
99 qemu_get_betls(f
, &env
->ivpr_mask
);
100 qemu_get_betls(f
, &env
->hreset_vector
);
101 qemu_get_betls(f
, &env
->nip
);
102 qemu_get_betls(f
, &env
->hflags
);
103 qemu_get_betls(f
, &env
->hflags_nmsr
);
104 qemu_get_sbe32(f
); /* Discard unused mmu_idx */
105 qemu_get_sbe32(f
); /* Discard unused power_mode */
107 /* Recompute mmu indices */
108 hreg_compute_mem_idx(env
);
113 static int get_avr(QEMUFile
*f
, void *pv
, size_t size
,
114 const VMStateField
*field
)
118 v
->u64
[0] = qemu_get_be64(f
);
119 v
->u64
[1] = qemu_get_be64(f
);
124 static int put_avr(QEMUFile
*f
, void *pv
, size_t size
,
125 const VMStateField
*field
, QJSON
*vmdesc
)
129 qemu_put_be64(f
, v
->u64
[0]);
130 qemu_put_be64(f
, v
->u64
[1]);
134 static const VMStateInfo vmstate_info_avr
= {
140 #define VMSTATE_AVR_ARRAY_V(_f, _s, _n, _v) \
141 VMSTATE_SUB_ARRAY(_f, _s, 32, _n, _v, vmstate_info_avr, ppc_avr_t)
143 #define VMSTATE_AVR_ARRAY(_f, _s, _n) \
144 VMSTATE_AVR_ARRAY_V(_f, _s, _n, 0)
146 static int get_fpr(QEMUFile
*f
, void *pv
, size_t size
,
147 const VMStateField
*field
)
151 v
->u64
[0] = qemu_get_be64(f
);
156 static int put_fpr(QEMUFile
*f
, void *pv
, size_t size
,
157 const VMStateField
*field
, QJSON
*vmdesc
)
161 qemu_put_be64(f
, v
->u64
[0]);
165 static const VMStateInfo vmstate_info_fpr
= {
171 #define VMSTATE_FPR_ARRAY_V(_f, _s, _n, _v) \
172 VMSTATE_SUB_ARRAY(_f, _s, 0, _n, _v, vmstate_info_fpr, ppc_vsr_t)
174 #define VMSTATE_FPR_ARRAY(_f, _s, _n) \
175 VMSTATE_FPR_ARRAY_V(_f, _s, _n, 0)
177 static int get_vsr(QEMUFile
*f
, void *pv
, size_t size
,
178 const VMStateField
*field
)
182 v
->u64
[1] = qemu_get_be64(f
);
187 static int put_vsr(QEMUFile
*f
, void *pv
, size_t size
,
188 const VMStateField
*field
, QJSON
*vmdesc
)
192 qemu_put_be64(f
, v
->u64
[1]);
196 static const VMStateInfo vmstate_info_vsr
= {
202 #define VMSTATE_VSR_ARRAY_V(_f, _s, _n, _v) \
203 VMSTATE_SUB_ARRAY(_f, _s, 0, _n, _v, vmstate_info_vsr, ppc_vsr_t)
205 #define VMSTATE_VSR_ARRAY(_f, _s, _n) \
206 VMSTATE_VSR_ARRAY_V(_f, _s, _n, 0)
208 static bool cpu_pre_2_8_migration(void *opaque
, int version_id
)
210 PowerPCCPU
*cpu
= opaque
;
212 return cpu
->pre_2_8_migration
;
215 #if defined(TARGET_PPC64)
216 static bool cpu_pre_3_0_migration(void *opaque
, int version_id
)
218 PowerPCCPU
*cpu
= opaque
;
220 return cpu
->pre_3_0_migration
;
224 static int cpu_pre_save(void *opaque
)
226 PowerPCCPU
*cpu
= opaque
;
227 CPUPPCState
*env
= &cpu
->env
;
229 uint64_t insns_compat_mask
=
230 PPC_INSNS_BASE
| PPC_ISEL
| PPC_STRING
| PPC_MFTB
231 | PPC_FLOAT
| PPC_FLOAT_FSEL
| PPC_FLOAT_FRES
232 | PPC_FLOAT_FSQRT
| PPC_FLOAT_FRSQRTE
| PPC_FLOAT_FRSQRTES
233 | PPC_FLOAT_STFIWX
| PPC_FLOAT_EXT
234 | PPC_CACHE
| PPC_CACHE_ICBI
| PPC_CACHE_DCBZ
235 | PPC_MEM_SYNC
| PPC_MEM_EIEIO
| PPC_MEM_TLBIE
| PPC_MEM_TLBSYNC
236 | PPC_64B
| PPC_64BX
| PPC_ALTIVEC
237 | PPC_SEGMENT_64B
| PPC_SLBI
| PPC_POPCNTB
| PPC_POPCNTWD
;
238 uint64_t insns_compat_mask2
= PPC2_VSX
| PPC2_VSX207
| PPC2_DFP
| PPC2_DBRX
239 | PPC2_PERM_ISA206
| PPC2_DIVE_ISA206
240 | PPC2_ATOMIC_ISA206
| PPC2_FP_CVT_ISA206
241 | PPC2_FP_TST_ISA206
| PPC2_BCTAR_ISA207
242 | PPC2_LSQ_ISA207
| PPC2_ALTIVEC_207
243 | PPC2_ISA205
| PPC2_ISA207S
| PPC2_FP_CVT_S64
| PPC2_TM
;
245 env
->spr
[SPR_LR
] = env
->lr
;
246 env
->spr
[SPR_CTR
] = env
->ctr
;
247 env
->spr
[SPR_XER
] = cpu_read_xer(env
);
248 #if defined(TARGET_PPC64)
249 env
->spr
[SPR_CFAR
] = env
->cfar
;
251 env
->spr
[SPR_BOOKE_SPEFSCR
] = env
->spe_fscr
;
253 for (i
= 0; (i
< 4) && (i
< env
->nb_BATs
); i
++) {
254 env
->spr
[SPR_DBAT0U
+ 2*i
] = env
->DBAT
[0][i
];
255 env
->spr
[SPR_DBAT0U
+ 2*i
+ 1] = env
->DBAT
[1][i
];
256 env
->spr
[SPR_IBAT0U
+ 2*i
] = env
->IBAT
[0][i
];
257 env
->spr
[SPR_IBAT0U
+ 2*i
+ 1] = env
->IBAT
[1][i
];
259 for (i
= 0; (i
< 4) && ((i
+4) < env
->nb_BATs
); i
++) {
260 env
->spr
[SPR_DBAT4U
+ 2*i
] = env
->DBAT
[0][i
+4];
261 env
->spr
[SPR_DBAT4U
+ 2*i
+ 1] = env
->DBAT
[1][i
+4];
262 env
->spr
[SPR_IBAT4U
+ 2*i
] = env
->IBAT
[0][i
+4];
263 env
->spr
[SPR_IBAT4U
+ 2*i
+ 1] = env
->IBAT
[1][i
+4];
266 /* Hacks for migration compatibility between 2.6, 2.7 & 2.8 */
267 if (cpu
->pre_2_8_migration
) {
268 /* Mask out bits that got added to msr_mask since the versions
269 * which stupidly included it in the migration stream. */
270 target_ulong metamask
= 0
271 #if defined(TARGET_PPC64)
276 cpu
->mig_msr_mask
= env
->msr_mask
& ~metamask
;
277 cpu
->mig_insns_flags
= env
->insns_flags
& insns_compat_mask
;
278 /* CPU models supported by old machines all have PPC_MEM_TLBIE,
279 * so we set it unconditionally to allow backward migration from
280 * a POWER9 host to a POWER8 host.
282 cpu
->mig_insns_flags
|= PPC_MEM_TLBIE
;
283 cpu
->mig_insns_flags2
= env
->insns_flags2
& insns_compat_mask2
;
284 cpu
->mig_nb_BATs
= env
->nb_BATs
;
286 if (cpu
->pre_3_0_migration
) {
287 if (cpu
->hash64_opts
) {
288 cpu
->mig_slb_nr
= cpu
->hash64_opts
->slb_size
;
296 * Determine if a given PVR is a "close enough" match to the CPU
297 * object. For TCG and KVM PR it would probably be sufficient to
298 * require an exact PVR match. However for KVM HV the user is
299 * restricted to a PVR exactly matching the host CPU. The correct way
300 * to handle this is to put the guest into an architected
301 * compatibility mode. However, to allow a more forgiving transition
302 * and migration from before this was widely done, we allow migration
303 * between sufficiently similar PVRs, as determined by the CPU class's
306 static bool pvr_match(PowerPCCPU
*cpu
, uint32_t pvr
)
308 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
310 if (pvr
== pcc
->pvr
) {
313 return pcc
->pvr_match(pcc
, pvr
);
316 static int cpu_post_load(void *opaque
, int version_id
)
318 PowerPCCPU
*cpu
= opaque
;
319 CPUPPCState
*env
= &cpu
->env
;
324 * If we're operating in compat mode, we should be ok as long as
325 * the destination supports the same compatiblity mode.
327 * Otherwise, however, we require that the destination has exactly
328 * the same CPU model as the source.
331 #if defined(TARGET_PPC64)
332 if (cpu
->compat_pvr
) {
333 uint32_t compat_pvr
= cpu
->compat_pvr
;
334 Error
*local_err
= NULL
;
337 ppc_set_compat(cpu
, compat_pvr
, &local_err
);
339 error_report_err(local_err
);
345 if (!pvr_match(cpu
, env
->spr
[SPR_PVR
])) {
351 * If we're running with KVM HV, there is a chance that the guest
352 * is running with KVM HV and its kernel does not have the
353 * capability of dealing with a different PVR other than this
354 * exact host PVR in KVM_SET_SREGS. If that happens, the
355 * guest freezes after migration.
357 * The function kvmppc_pvr_workaround_required does this verification
358 * by first checking if the kernel has the cap, returning true immediately
359 * if that is the case. Otherwise, it checks if we're running in KVM PR.
360 * If the guest kernel does not have the cap and we're not running KVM-PR
361 * (so, it is running KVM-HV), we need to ensure that KVM_SET_SREGS will
362 * receive the PVR it expects as a workaround.
365 #if defined(CONFIG_KVM)
366 if (kvmppc_pvr_workaround_required(cpu
)) {
367 env
->spr
[SPR_PVR
] = env
->spr_cb
[SPR_PVR
].default_value
;
371 env
->lr
= env
->spr
[SPR_LR
];
372 env
->ctr
= env
->spr
[SPR_CTR
];
373 cpu_write_xer(env
, env
->spr
[SPR_XER
]);
374 #if defined(TARGET_PPC64)
375 env
->cfar
= env
->spr
[SPR_CFAR
];
377 env
->spe_fscr
= env
->spr
[SPR_BOOKE_SPEFSCR
];
379 for (i
= 0; (i
< 4) && (i
< env
->nb_BATs
); i
++) {
380 env
->DBAT
[0][i
] = env
->spr
[SPR_DBAT0U
+ 2*i
];
381 env
->DBAT
[1][i
] = env
->spr
[SPR_DBAT0U
+ 2*i
+ 1];
382 env
->IBAT
[0][i
] = env
->spr
[SPR_IBAT0U
+ 2*i
];
383 env
->IBAT
[1][i
] = env
->spr
[SPR_IBAT0U
+ 2*i
+ 1];
385 for (i
= 0; (i
< 4) && ((i
+4) < env
->nb_BATs
); i
++) {
386 env
->DBAT
[0][i
+4] = env
->spr
[SPR_DBAT4U
+ 2*i
];
387 env
->DBAT
[1][i
+4] = env
->spr
[SPR_DBAT4U
+ 2*i
+ 1];
388 env
->IBAT
[0][i
+4] = env
->spr
[SPR_IBAT4U
+ 2*i
];
389 env
->IBAT
[1][i
+4] = env
->spr
[SPR_IBAT4U
+ 2*i
+ 1];
393 ppc_store_sdr1(env
, env
->spr
[SPR_SDR1
]);
396 /* Invalidate all supported msr bits except MSR_TGPR/MSR_HVB before restoring */
398 env
->msr
^= env
->msr_mask
& ~((1ULL << MSR_TGPR
) | MSR_HVB
);
399 ppc_store_msr(env
, msr
);
401 hreg_compute_mem_idx(env
);
406 static bool fpu_needed(void *opaque
)
408 PowerPCCPU
*cpu
= opaque
;
410 return (cpu
->env
.insns_flags
& PPC_FLOAT
);
413 static const VMStateDescription vmstate_fpu
= {
416 .minimum_version_id
= 1,
417 .needed
= fpu_needed
,
418 .fields
= (VMStateField
[]) {
419 VMSTATE_FPR_ARRAY(env
.vsr
, PowerPCCPU
, 32),
420 VMSTATE_UINTTL(env
.fpscr
, PowerPCCPU
),
421 VMSTATE_END_OF_LIST()
425 static bool altivec_needed(void *opaque
)
427 PowerPCCPU
*cpu
= opaque
;
429 return (cpu
->env
.insns_flags
& PPC_ALTIVEC
);
432 static const VMStateDescription vmstate_altivec
= {
433 .name
= "cpu/altivec",
435 .minimum_version_id
= 1,
436 .needed
= altivec_needed
,
437 .fields
= (VMStateField
[]) {
438 VMSTATE_AVR_ARRAY(env
.vsr
, PowerPCCPU
, 32),
439 VMSTATE_UINT32(env
.vscr
, PowerPCCPU
),
440 VMSTATE_END_OF_LIST()
444 static bool vsx_needed(void *opaque
)
446 PowerPCCPU
*cpu
= opaque
;
448 return (cpu
->env
.insns_flags2
& PPC2_VSX
);
451 static const VMStateDescription vmstate_vsx
= {
454 .minimum_version_id
= 1,
455 .needed
= vsx_needed
,
456 .fields
= (VMStateField
[]) {
457 VMSTATE_VSR_ARRAY(env
.vsr
, PowerPCCPU
, 32),
458 VMSTATE_END_OF_LIST()
463 /* Transactional memory state */
464 static bool tm_needed(void *opaque
)
466 PowerPCCPU
*cpu
= opaque
;
467 CPUPPCState
*env
= &cpu
->env
;
471 static const VMStateDescription vmstate_tm
= {
474 .minimum_version_id
= 1,
475 .minimum_version_id_old
= 1,
477 .fields
= (VMStateField
[]) {
478 VMSTATE_UINTTL_ARRAY(env
.tm_gpr
, PowerPCCPU
, 32),
479 VMSTATE_AVR_ARRAY(env
.tm_vsr
, PowerPCCPU
, 64),
480 VMSTATE_UINT64(env
.tm_cr
, PowerPCCPU
),
481 VMSTATE_UINT64(env
.tm_lr
, PowerPCCPU
),
482 VMSTATE_UINT64(env
.tm_ctr
, PowerPCCPU
),
483 VMSTATE_UINT64(env
.tm_fpscr
, PowerPCCPU
),
484 VMSTATE_UINT64(env
.tm_amr
, PowerPCCPU
),
485 VMSTATE_UINT64(env
.tm_ppr
, PowerPCCPU
),
486 VMSTATE_UINT64(env
.tm_vrsave
, PowerPCCPU
),
487 VMSTATE_UINT32(env
.tm_vscr
, PowerPCCPU
),
488 VMSTATE_UINT64(env
.tm_dscr
, PowerPCCPU
),
489 VMSTATE_UINT64(env
.tm_tar
, PowerPCCPU
),
490 VMSTATE_END_OF_LIST()
495 static bool sr_needed(void *opaque
)
498 PowerPCCPU
*cpu
= opaque
;
500 return !(cpu
->env
.mmu_model
& POWERPC_MMU_64
);
506 static const VMStateDescription vmstate_sr
= {
509 .minimum_version_id
= 1,
511 .fields
= (VMStateField
[]) {
512 VMSTATE_UINTTL_ARRAY(env
.sr
, PowerPCCPU
, 32),
513 VMSTATE_END_OF_LIST()
518 static int get_slbe(QEMUFile
*f
, void *pv
, size_t size
,
519 const VMStateField
*field
)
523 v
->esid
= qemu_get_be64(f
);
524 v
->vsid
= qemu_get_be64(f
);
529 static int put_slbe(QEMUFile
*f
, void *pv
, size_t size
,
530 const VMStateField
*field
, QJSON
*vmdesc
)
534 qemu_put_be64(f
, v
->esid
);
535 qemu_put_be64(f
, v
->vsid
);
539 static const VMStateInfo vmstate_info_slbe
= {
545 #define VMSTATE_SLB_ARRAY_V(_f, _s, _n, _v) \
546 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_slbe, ppc_slb_t)
548 #define VMSTATE_SLB_ARRAY(_f, _s, _n) \
549 VMSTATE_SLB_ARRAY_V(_f, _s, _n, 0)
551 static bool slb_needed(void *opaque
)
553 PowerPCCPU
*cpu
= opaque
;
555 /* We don't support any of the old segment table based 64-bit CPUs */
556 return (cpu
->env
.mmu_model
& POWERPC_MMU_64
);
559 static int slb_post_load(void *opaque
, int version_id
)
561 PowerPCCPU
*cpu
= opaque
;
562 CPUPPCState
*env
= &cpu
->env
;
565 /* We've pulled in the raw esid and vsid values from the migration
566 * stream, but we need to recompute the page size pointers */
567 for (i
= 0; i
< cpu
->hash64_opts
->slb_size
; i
++) {
568 if (ppc_store_slb(cpu
, i
, env
->slb
[i
].esid
, env
->slb
[i
].vsid
) < 0) {
569 /* Migration source had bad values in its SLB */
577 static const VMStateDescription vmstate_slb
= {
580 .minimum_version_id
= 1,
581 .needed
= slb_needed
,
582 .post_load
= slb_post_load
,
583 .fields
= (VMStateField
[]) {
584 VMSTATE_INT32_TEST(mig_slb_nr
, PowerPCCPU
, cpu_pre_3_0_migration
),
585 VMSTATE_SLB_ARRAY(env
.slb
, PowerPCCPU
, MAX_SLB_ENTRIES
),
586 VMSTATE_END_OF_LIST()
589 #endif /* TARGET_PPC64 */
591 static const VMStateDescription vmstate_tlb6xx_entry
= {
592 .name
= "cpu/tlb6xx_entry",
594 .minimum_version_id
= 1,
595 .fields
= (VMStateField
[]) {
596 VMSTATE_UINTTL(pte0
, ppc6xx_tlb_t
),
597 VMSTATE_UINTTL(pte1
, ppc6xx_tlb_t
),
598 VMSTATE_UINTTL(EPN
, ppc6xx_tlb_t
),
599 VMSTATE_END_OF_LIST()
603 static bool tlb6xx_needed(void *opaque
)
605 PowerPCCPU
*cpu
= opaque
;
606 CPUPPCState
*env
= &cpu
->env
;
608 return env
->nb_tlb
&& (env
->tlb_type
== TLB_6XX
);
611 static const VMStateDescription vmstate_tlb6xx
= {
612 .name
= "cpu/tlb6xx",
614 .minimum_version_id
= 1,
615 .needed
= tlb6xx_needed
,
616 .fields
= (VMStateField
[]) {
617 VMSTATE_INT32_EQUAL(env
.nb_tlb
, PowerPCCPU
, NULL
),
618 VMSTATE_STRUCT_VARRAY_POINTER_INT32(env
.tlb
.tlb6
, PowerPCCPU
,
620 vmstate_tlb6xx_entry
,
622 VMSTATE_UINTTL_ARRAY(env
.tgpr
, PowerPCCPU
, 4),
623 VMSTATE_END_OF_LIST()
627 static const VMStateDescription vmstate_tlbemb_entry
= {
628 .name
= "cpu/tlbemb_entry",
630 .minimum_version_id
= 1,
631 .fields
= (VMStateField
[]) {
632 VMSTATE_UINT64(RPN
, ppcemb_tlb_t
),
633 VMSTATE_UINTTL(EPN
, ppcemb_tlb_t
),
634 VMSTATE_UINTTL(PID
, ppcemb_tlb_t
),
635 VMSTATE_UINTTL(size
, ppcemb_tlb_t
),
636 VMSTATE_UINT32(prot
, ppcemb_tlb_t
),
637 VMSTATE_UINT32(attr
, ppcemb_tlb_t
),
638 VMSTATE_END_OF_LIST()
642 static bool tlbemb_needed(void *opaque
)
644 PowerPCCPU
*cpu
= opaque
;
645 CPUPPCState
*env
= &cpu
->env
;
647 return env
->nb_tlb
&& (env
->tlb_type
== TLB_EMB
);
650 static bool pbr403_needed(void *opaque
)
652 PowerPCCPU
*cpu
= opaque
;
653 uint32_t pvr
= cpu
->env
.spr
[SPR_PVR
];
655 return (pvr
& 0xffff0000) == 0x00200000;
658 static const VMStateDescription vmstate_pbr403
= {
659 .name
= "cpu/pbr403",
661 .minimum_version_id
= 1,
662 .needed
= pbr403_needed
,
663 .fields
= (VMStateField
[]) {
664 VMSTATE_UINTTL_ARRAY(env
.pb
, PowerPCCPU
, 4),
665 VMSTATE_END_OF_LIST()
669 static const VMStateDescription vmstate_tlbemb
= {
670 .name
= "cpu/tlb6xx",
672 .minimum_version_id
= 1,
673 .needed
= tlbemb_needed
,
674 .fields
= (VMStateField
[]) {
675 VMSTATE_INT32_EQUAL(env
.nb_tlb
, PowerPCCPU
, NULL
),
676 VMSTATE_STRUCT_VARRAY_POINTER_INT32(env
.tlb
.tlbe
, PowerPCCPU
,
678 vmstate_tlbemb_entry
,
680 /* 403 protection registers */
681 VMSTATE_END_OF_LIST()
683 .subsections
= (const VMStateDescription
*[]) {
689 static const VMStateDescription vmstate_tlbmas_entry
= {
690 .name
= "cpu/tlbmas_entry",
692 .minimum_version_id
= 1,
693 .fields
= (VMStateField
[]) {
694 VMSTATE_UINT32(mas8
, ppcmas_tlb_t
),
695 VMSTATE_UINT32(mas1
, ppcmas_tlb_t
),
696 VMSTATE_UINT64(mas2
, ppcmas_tlb_t
),
697 VMSTATE_UINT64(mas7_3
, ppcmas_tlb_t
),
698 VMSTATE_END_OF_LIST()
702 static bool tlbmas_needed(void *opaque
)
704 PowerPCCPU
*cpu
= opaque
;
705 CPUPPCState
*env
= &cpu
->env
;
707 return env
->nb_tlb
&& (env
->tlb_type
== TLB_MAS
);
710 static const VMStateDescription vmstate_tlbmas
= {
711 .name
= "cpu/tlbmas",
713 .minimum_version_id
= 1,
714 .needed
= tlbmas_needed
,
715 .fields
= (VMStateField
[]) {
716 VMSTATE_INT32_EQUAL(env
.nb_tlb
, PowerPCCPU
, NULL
),
717 VMSTATE_STRUCT_VARRAY_POINTER_INT32(env
.tlb
.tlbm
, PowerPCCPU
,
719 vmstate_tlbmas_entry
,
721 VMSTATE_END_OF_LIST()
725 static bool compat_needed(void *opaque
)
727 PowerPCCPU
*cpu
= opaque
;
729 assert(!(cpu
->compat_pvr
&& !cpu
->vhyp
));
730 return !cpu
->pre_2_10_migration
&& cpu
->compat_pvr
!= 0;
733 static const VMStateDescription vmstate_compat
= {
734 .name
= "cpu/compat",
736 .minimum_version_id
= 1,
737 .needed
= compat_needed
,
738 .fields
= (VMStateField
[]) {
739 VMSTATE_UINT32(compat_pvr
, PowerPCCPU
),
740 VMSTATE_END_OF_LIST()
744 const VMStateDescription vmstate_ppc_cpu
= {
747 .minimum_version_id
= 5,
748 .minimum_version_id_old
= 4,
749 .load_state_old
= cpu_load_old
,
750 .pre_save
= cpu_pre_save
,
751 .post_load
= cpu_post_load
,
752 .fields
= (VMStateField
[]) {
753 VMSTATE_UNUSED(sizeof(target_ulong
)), /* was _EQUAL(env.spr[SPR_PVR]) */
755 /* User mode architected state */
756 VMSTATE_UINTTL_ARRAY(env
.gpr
, PowerPCCPU
, 32),
757 #if !defined(TARGET_PPC64)
758 VMSTATE_UINTTL_ARRAY(env
.gprh
, PowerPCCPU
, 32),
760 VMSTATE_UINT32_ARRAY(env
.crf
, PowerPCCPU
, 8),
761 VMSTATE_UINTTL(env
.nip
, PowerPCCPU
),
764 VMSTATE_UINTTL_ARRAY(env
.spr
, PowerPCCPU
, 1024),
765 VMSTATE_UINT64(env
.spe_acc
, PowerPCCPU
),
768 VMSTATE_UINTTL(env
.reserve_addr
, PowerPCCPU
),
770 /* Supervisor mode architected state */
771 VMSTATE_UINTTL(env
.msr
, PowerPCCPU
),
774 VMSTATE_UINTTL(env
.hflags_nmsr
, PowerPCCPU
),
775 /* FIXME: access_type? */
777 /* Sanity checking */
778 VMSTATE_UINTTL_TEST(mig_msr_mask
, PowerPCCPU
, cpu_pre_2_8_migration
),
779 VMSTATE_UINT64_TEST(mig_insns_flags
, PowerPCCPU
, cpu_pre_2_8_migration
),
780 VMSTATE_UINT64_TEST(mig_insns_flags2
, PowerPCCPU
,
781 cpu_pre_2_8_migration
),
782 VMSTATE_UINT32_TEST(mig_nb_BATs
, PowerPCCPU
, cpu_pre_2_8_migration
),
783 VMSTATE_END_OF_LIST()
785 .subsections
= (const VMStateDescription
*[]) {
793 #endif /* TARGET_PPC64 */