machine.c 17.8 KB
Newer Older
P
Peter Maydell 已提交
1
#include "qemu/osdep.h"
2 3
#include "qemu-common.h"
#include "cpu.h"
4
#include "exec/exec-all.h"
A
aurel32 已提交
5 6
#include "hw/hw.h"
#include "hw/boards.h"
7
#include "sysemu/kvm.h"
8
#include "helper_regs.h"
9
#include "mmu-hash64.h"
10
#include "migration/cpu.h"
A
aurel32 已提交
11

12
static int cpu_load_old(QEMUFile *f, void *opaque, int version_id)
A
aurel32 已提交
13
{
14 15
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;
B
blueswir1 已提交
16
    unsigned int i, j;
17
    target_ulong sdr1;
18
    uint32_t fpscr;
19
    target_ulong xer;
B
blueswir1 已提交
20 21 22 23 24 25 26 27 28 29 30

    for (i = 0; i < 32; i++)
        qemu_get_betls(f, &env->gpr[i]);
#if !defined(TARGET_PPC64)
    for (i = 0; i < 32; i++)
        qemu_get_betls(f, &env->gprh[i]);
#endif
    qemu_get_betls(f, &env->lr);
    qemu_get_betls(f, &env->ctr);
    for (i = 0; i < 8; i++)
        qemu_get_be32s(f, &env->crf[i]);
31 32
    qemu_get_betls(f, &xer);
    cpu_write_xer(env, xer);
33
    qemu_get_betls(f, &env->reserve_addr);
B
blueswir1 已提交
34 35 36 37 38 39 40 41 42 43 44
    qemu_get_betls(f, &env->msr);
    for (i = 0; i < 4; i++)
        qemu_get_betls(f, &env->tgpr[i]);
    for (i = 0; i < 32; i++) {
        union {
            float64 d;
            uint64_t l;
        } u;
        u.l = qemu_get_be64(f);
        env->fpr[i] = u.d;
    }
45 46
    qemu_get_be32s(f, &fpscr);
    env->fpscr = fpscr;
B
blueswir1 已提交
47 48
    qemu_get_sbe32s(f, &env->access_type);
#if defined(TARGET_PPC64)
49
    qemu_get_betls(f, &env->spr[SPR_ASR]);
B
blueswir1 已提交
50 51
    qemu_get_sbe32s(f, &env->slb_nr);
#endif
52
    qemu_get_betls(f, &sdr1);
B
blueswir1 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66
    for (i = 0; i < 32; i++)
        qemu_get_betls(f, &env->sr[i]);
    for (i = 0; i < 2; i++)
        for (j = 0; j < 8; j++)
            qemu_get_betls(f, &env->DBAT[i][j]);
    for (i = 0; i < 2; i++)
        for (j = 0; j < 8; j++)
            qemu_get_betls(f, &env->IBAT[i][j]);
    qemu_get_sbe32s(f, &env->nb_tlb);
    qemu_get_sbe32s(f, &env->tlb_per_way);
    qemu_get_sbe32s(f, &env->nb_ways);
    qemu_get_sbe32s(f, &env->last_way);
    qemu_get_sbe32s(f, &env->id_tlbs);
    qemu_get_sbe32s(f, &env->nb_pids);
67
    if (env->tlb.tlb6) {
B
blueswir1 已提交
68 69
        // XXX assumes 6xx
        for (i = 0; i < env->nb_tlb; i++) {
70 71 72
            qemu_get_betls(f, &env->tlb.tlb6[i].pte0);
            qemu_get_betls(f, &env->tlb.tlb6[i].pte1);
            qemu_get_betls(f, &env->tlb.tlb6[i].EPN);
B
blueswir1 已提交
73 74 75 76 77 78
        }
    }
    for (i = 0; i < 4; i++)
        qemu_get_betls(f, &env->pb[i]);
    for (i = 0; i < 1024; i++)
        qemu_get_betls(f, &env->spr[i]);
79 80 81
    if (!env->external_htab) {
        ppc_store_sdr1(env, sdr1);
    }
B
blueswir1 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    qemu_get_be32s(f, &env->vscr);
    qemu_get_be64s(f, &env->spe_acc);
    qemu_get_be32s(f, &env->spe_fscr);
    qemu_get_betls(f, &env->msr_mask);
    qemu_get_be32s(f, &env->flags);
    qemu_get_sbe32s(f, &env->error_code);
    qemu_get_be32s(f, &env->pending_interrupts);
    qemu_get_be32s(f, &env->irq_input_state);
    for (i = 0; i < POWERPC_EXCP_NB; i++)
        qemu_get_betls(f, &env->excp_vectors[i]);
    qemu_get_betls(f, &env->excp_prefix);
    qemu_get_betls(f, &env->ivor_mask);
    qemu_get_betls(f, &env->ivpr_mask);
    qemu_get_betls(f, &env->hreset_vector);
    qemu_get_betls(f, &env->nip);
    qemu_get_betls(f, &env->hflags);
    qemu_get_betls(f, &env->hflags_nmsr);
99
    qemu_get_sbe32(f); /* Discard unused mmu_idx */
100
    qemu_get_sbe32(f); /* Discard unused power_mode */
B
blueswir1 已提交
101

102 103 104
    /* Recompute mmu indices */
    hreg_compute_mem_idx(env);

A
aurel32 已提交
105 106
    return 0;
}
107

J
Jianjun Duan 已提交
108
static int get_avr(QEMUFile *f, void *pv, size_t size, VMStateField *field)
109 110 111 112 113 114 115 116 117
{
    ppc_avr_t *v = pv;

    v->u64[0] = qemu_get_be64(f);
    v->u64[1] = qemu_get_be64(f);

    return 0;
}

J
Jianjun Duan 已提交
118 119
static int put_avr(QEMUFile *f, void *pv, size_t size, VMStateField *field,
                   QJSON *vmdesc)
120 121 122 123 124
{
    ppc_avr_t *v = pv;

    qemu_put_be64(f, v->u64[0]);
    qemu_put_be64(f, v->u64[1]);
J
Jianjun Duan 已提交
125
    return 0;
126 127
}

128
static const VMStateInfo vmstate_info_avr = {
129 130 131 132 133 134 135 136 137 138 139
    .name = "avr",
    .get  = get_avr,
    .put  = put_avr,
};

#define VMSTATE_AVR_ARRAY_V(_f, _s, _n, _v)                       \
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_avr, ppc_avr_t)

#define VMSTATE_AVR_ARRAY(_f, _s, _n)                             \
    VMSTATE_AVR_ARRAY_V(_f, _s, _n, 0)

140 141 142 143 144 145 146
static bool cpu_pre_2_8_migration(void *opaque, int version_id)
{
    PowerPCCPU *cpu = opaque;

    return cpu->pre_2_8_migration;
}

147 148 149 150 151
static void cpu_pre_save(void *opaque)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;
    int i;
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    uint64_t insns_compat_mask =
        PPC_INSNS_BASE | PPC_ISEL | PPC_STRING | PPC_MFTB
        | PPC_FLOAT | PPC_FLOAT_FSEL | PPC_FLOAT_FRES
        | PPC_FLOAT_FSQRT | PPC_FLOAT_FRSQRTE | PPC_FLOAT_FRSQRTES
        | PPC_FLOAT_STFIWX | PPC_FLOAT_EXT
        | PPC_CACHE | PPC_CACHE_ICBI | PPC_CACHE_DCBZ
        | PPC_MEM_SYNC | PPC_MEM_EIEIO | PPC_MEM_TLBIE | PPC_MEM_TLBSYNC
        | PPC_64B | PPC_64BX | PPC_ALTIVEC
        | PPC_SEGMENT_64B | PPC_SLBI | PPC_POPCNTB | PPC_POPCNTWD;
    uint64_t insns_compat_mask2 = PPC2_VSX | PPC2_VSX207 | PPC2_DFP | PPC2_DBRX
        | PPC2_PERM_ISA206 | PPC2_DIVE_ISA206
        | PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206
        | PPC2_FP_TST_ISA206 | PPC2_BCTAR_ISA207
        | PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207
        | PPC2_ISA205 | PPC2_ISA207S | PPC2_FP_CVT_S64 | PPC2_TM;
167 168 169

    env->spr[SPR_LR] = env->lr;
    env->spr[SPR_CTR] = env->ctr;
170
    env->spr[SPR_XER] = cpu_read_xer(env);
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
#if defined(TARGET_PPC64)
    env->spr[SPR_CFAR] = env->cfar;
#endif
    env->spr[SPR_BOOKE_SPEFSCR] = env->spe_fscr;

    for (i = 0; (i < 4) && (i < env->nb_BATs); i++) {
        env->spr[SPR_DBAT0U + 2*i] = env->DBAT[0][i];
        env->spr[SPR_DBAT0U + 2*i + 1] = env->DBAT[1][i];
        env->spr[SPR_IBAT0U + 2*i] = env->IBAT[0][i];
        env->spr[SPR_IBAT0U + 2*i + 1] = env->IBAT[1][i];
    }
    for (i = 0; (i < 4) && ((i+4) < env->nb_BATs); i++) {
        env->spr[SPR_DBAT4U + 2*i] = env->DBAT[0][i+4];
        env->spr[SPR_DBAT4U + 2*i + 1] = env->DBAT[1][i+4];
        env->spr[SPR_IBAT4U + 2*i] = env->IBAT[0][i+4];
        env->spr[SPR_IBAT4U + 2*i + 1] = env->IBAT[1][i+4];
    }
188 189

    /* Hacks for migration compatibility between 2.6, 2.7 & 2.8 */
190 191 192 193 194 195
    if (cpu->pre_2_8_migration) {
        cpu->mig_msr_mask = env->msr_mask;
        cpu->mig_insns_flags = env->insns_flags & insns_compat_mask;
        cpu->mig_insns_flags2 = env->insns_flags2 & insns_compat_mask2;
        cpu->mig_nb_BATs = env->nb_BATs;
    }
196 197 198 199 200 201 202
}

static int cpu_post_load(void *opaque, int version_id)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;
    int i;
203
    target_ulong msr;
204

205 206 207 208 209
    /*
     * We always ignore the source PVR. The user or management
     * software has to take care of running QEMU in a compatible mode.
     */
    env->spr[SPR_PVR] = env->spr_cb[SPR_PVR].default_value;
210 211
    env->lr = env->spr[SPR_LR];
    env->ctr = env->spr[SPR_CTR];
212
    cpu_write_xer(env, env->spr[SPR_XER]);
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
#if defined(TARGET_PPC64)
    env->cfar = env->spr[SPR_CFAR];
#endif
    env->spe_fscr = env->spr[SPR_BOOKE_SPEFSCR];

    for (i = 0; (i < 4) && (i < env->nb_BATs); i++) {
        env->DBAT[0][i] = env->spr[SPR_DBAT0U + 2*i];
        env->DBAT[1][i] = env->spr[SPR_DBAT0U + 2*i + 1];
        env->IBAT[0][i] = env->spr[SPR_IBAT0U + 2*i];
        env->IBAT[1][i] = env->spr[SPR_IBAT0U + 2*i + 1];
    }
    for (i = 0; (i < 4) && ((i+4) < env->nb_BATs); i++) {
        env->DBAT[0][i+4] = env->spr[SPR_DBAT4U + 2*i];
        env->DBAT[1][i+4] = env->spr[SPR_DBAT4U + 2*i + 1];
        env->IBAT[0][i+4] = env->spr[SPR_IBAT4U + 2*i];
        env->IBAT[1][i+4] = env->spr[SPR_IBAT4U + 2*i + 1];
    }

231 232 233 234
    if (!env->external_htab) {
        /* Restore htab_base and htab_mask variables */
        ppc_store_sdr1(env, env->spr[SPR_SDR1]);
    }
235

236
    /* Invalidate all msr bits except MSR_TGPR/MSR_HVB before restoring */
237
    msr = env->msr;
238
    env->msr ^= ~((1ULL << MSR_TGPR) | MSR_HVB);
239 240
    ppc_store_msr(env, msr);

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    hreg_compute_mem_idx(env);

    return 0;
}

static bool fpu_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;

    return (cpu->env.insns_flags & PPC_FLOAT);
}

static const VMStateDescription vmstate_fpu = {
    .name = "cpu/fpu",
    .version_id = 1,
    .minimum_version_id = 1,
257
    .needed = fpu_needed,
258
    .fields = (VMStateField[]) {
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        VMSTATE_FLOAT64_ARRAY(env.fpr, PowerPCCPU, 32),
        VMSTATE_UINTTL(env.fpscr, PowerPCCPU),
        VMSTATE_END_OF_LIST()
    },
};

static bool altivec_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;

    return (cpu->env.insns_flags & PPC_ALTIVEC);
}

static const VMStateDescription vmstate_altivec = {
    .name = "cpu/altivec",
    .version_id = 1,
    .minimum_version_id = 1,
276
    .needed = altivec_needed,
277
    .fields = (VMStateField[]) {
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
        VMSTATE_AVR_ARRAY(env.avr, PowerPCCPU, 32),
        VMSTATE_UINT32(env.vscr, PowerPCCPU),
        VMSTATE_END_OF_LIST()
    },
};

static bool vsx_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;

    return (cpu->env.insns_flags2 & PPC2_VSX);
}

static const VMStateDescription vmstate_vsx = {
    .name = "cpu/vsx",
    .version_id = 1,
    .minimum_version_id = 1,
295
    .needed = vsx_needed,
296
    .fields = (VMStateField[]) {
297 298 299 300 301
        VMSTATE_UINT64_ARRAY(env.vsr, PowerPCCPU, 32),
        VMSTATE_END_OF_LIST()
    },
};

302 303 304 305 306 307 308 309 310 311 312 313 314 315
#ifdef TARGET_PPC64
/* Transactional memory state */
static bool tm_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;
    return msr_ts;
}

static const VMStateDescription vmstate_tm = {
    .name = "cpu/tm",
    .version_id = 1,
    .minimum_version_id = 1,
    .minimum_version_id_old = 1,
316
    .needed = tm_needed,
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
    .fields      = (VMStateField []) {
        VMSTATE_UINTTL_ARRAY(env.tm_gpr, PowerPCCPU, 32),
        VMSTATE_AVR_ARRAY(env.tm_vsr, PowerPCCPU, 64),
        VMSTATE_UINT64(env.tm_cr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_lr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_ctr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_fpscr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_amr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_ppr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_vrsave, PowerPCCPU),
        VMSTATE_UINT32(env.tm_vscr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_dscr, PowerPCCPU),
        VMSTATE_UINT64(env.tm_tar, PowerPCCPU),
        VMSTATE_END_OF_LIST()
    },
};
#endif

335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
static bool sr_needed(void *opaque)
{
#ifdef TARGET_PPC64
    PowerPCCPU *cpu = opaque;

    return !(cpu->env.mmu_model & POWERPC_MMU_64);
#else
    return true;
#endif
}

static const VMStateDescription vmstate_sr = {
    .name = "cpu/sr",
    .version_id = 1,
    .minimum_version_id = 1,
350
    .needed = sr_needed,
351
    .fields = (VMStateField[]) {
352 353 354 355 356 357
        VMSTATE_UINTTL_ARRAY(env.sr, PowerPCCPU, 32),
        VMSTATE_END_OF_LIST()
    },
};

#ifdef TARGET_PPC64
J
Jianjun Duan 已提交
358
static int get_slbe(QEMUFile *f, void *pv, size_t size, VMStateField *field)
359 360 361 362 363 364 365 366 367
{
    ppc_slb_t *v = pv;

    v->esid = qemu_get_be64(f);
    v->vsid = qemu_get_be64(f);

    return 0;
}

J
Jianjun Duan 已提交
368 369
static int put_slbe(QEMUFile *f, void *pv, size_t size, VMStateField *field,
                    QJSON *vmdesc)
370 371 372 373 374
{
    ppc_slb_t *v = pv;

    qemu_put_be64(f, v->esid);
    qemu_put_be64(f, v->vsid);
J
Jianjun Duan 已提交
375
    return 0;
376 377
}

378
static const VMStateInfo vmstate_info_slbe = {
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
    .name = "slbe",
    .get  = get_slbe,
    .put  = put_slbe,
};

#define VMSTATE_SLB_ARRAY_V(_f, _s, _n, _v)                       \
    VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_slbe, ppc_slb_t)

#define VMSTATE_SLB_ARRAY(_f, _s, _n)                             \
    VMSTATE_SLB_ARRAY_V(_f, _s, _n, 0)

static bool slb_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;

    /* We don't support any of the old segment table based 64-bit CPUs */
    return (cpu->env.mmu_model & POWERPC_MMU_64);
}

398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
static int slb_post_load(void *opaque, int version_id)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;
    int i;

    /* We've pulled in the raw esid and vsid values from the migration
     * stream, but we need to recompute the page size pointers */
    for (i = 0; i < env->slb_nr; i++) {
        if (ppc_store_slb(cpu, i, env->slb[i].esid, env->slb[i].vsid) < 0) {
            /* Migration source had bad values in its SLB */
            return -1;
        }
    }

    return 0;
}

416 417 418 419
static const VMStateDescription vmstate_slb = {
    .name = "cpu/slb",
    .version_id = 1,
    .minimum_version_id = 1,
420
    .needed = slb_needed,
421
    .post_load = slb_post_load,
422
    .fields = (VMStateField[]) {
423
        VMSTATE_INT32_EQUAL(env.slb_nr, PowerPCCPU),
424
        VMSTATE_SLB_ARRAY(env.slb, PowerPCCPU, MAX_SLB_ENTRIES),
425 426 427 428 429 430 431 432 433
        VMSTATE_END_OF_LIST()
    }
};
#endif /* TARGET_PPC64 */

static const VMStateDescription vmstate_tlb6xx_entry = {
    .name = "cpu/tlb6xx_entry",
    .version_id = 1,
    .minimum_version_id = 1,
434
    .fields = (VMStateField[]) {
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
        VMSTATE_UINTTL(pte0, ppc6xx_tlb_t),
        VMSTATE_UINTTL(pte1, ppc6xx_tlb_t),
        VMSTATE_UINTTL(EPN, ppc6xx_tlb_t),
        VMSTATE_END_OF_LIST()
    },
};

static bool tlb6xx_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;

    return env->nb_tlb && (env->tlb_type == TLB_6XX);
}

static const VMStateDescription vmstate_tlb6xx = {
    .name = "cpu/tlb6xx",
    .version_id = 1,
    .minimum_version_id = 1,
454
    .needed = tlb6xx_needed,
455
    .fields = (VMStateField[]) {
456 457 458 459 460 461 462 463 464 465 466 467 468 469
        VMSTATE_INT32_EQUAL(env.nb_tlb, PowerPCCPU),
        VMSTATE_STRUCT_VARRAY_POINTER_INT32(env.tlb.tlb6, PowerPCCPU,
                                            env.nb_tlb,
                                            vmstate_tlb6xx_entry,
                                            ppc6xx_tlb_t),
        VMSTATE_UINTTL_ARRAY(env.tgpr, PowerPCCPU, 4),
        VMSTATE_END_OF_LIST()
    }
};

static const VMStateDescription vmstate_tlbemb_entry = {
    .name = "cpu/tlbemb_entry",
    .version_id = 1,
    .minimum_version_id = 1,
470
    .fields = (VMStateField[]) {
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
        VMSTATE_UINT64(RPN, ppcemb_tlb_t),
        VMSTATE_UINTTL(EPN, ppcemb_tlb_t),
        VMSTATE_UINTTL(PID, ppcemb_tlb_t),
        VMSTATE_UINTTL(size, ppcemb_tlb_t),
        VMSTATE_UINT32(prot, ppcemb_tlb_t),
        VMSTATE_UINT32(attr, ppcemb_tlb_t),
        VMSTATE_END_OF_LIST()
    },
};

static bool tlbemb_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;

    return env->nb_tlb && (env->tlb_type == TLB_EMB);
}

static bool pbr403_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;
    uint32_t pvr = cpu->env.spr[SPR_PVR];

    return (pvr & 0xffff0000) == 0x00200000;
}

static const VMStateDescription vmstate_pbr403 = {
    .name = "cpu/pbr403",
    .version_id = 1,
    .minimum_version_id = 1,
501
    .needed = pbr403_needed,
502
    .fields = (VMStateField[]) {
503 504 505 506 507 508 509 510 511
        VMSTATE_UINTTL_ARRAY(env.pb, PowerPCCPU, 4),
        VMSTATE_END_OF_LIST()
    },
};

static const VMStateDescription vmstate_tlbemb = {
    .name = "cpu/tlb6xx",
    .version_id = 1,
    .minimum_version_id = 1,
512
    .needed = tlbemb_needed,
513
    .fields = (VMStateField[]) {
514 515 516 517 518 519 520 521
        VMSTATE_INT32_EQUAL(env.nb_tlb, PowerPCCPU),
        VMSTATE_STRUCT_VARRAY_POINTER_INT32(env.tlb.tlbe, PowerPCCPU,
                                            env.nb_tlb,
                                            vmstate_tlbemb_entry,
                                            ppcemb_tlb_t),
        /* 403 protection registers */
        VMSTATE_END_OF_LIST()
    },
522 523 524
    .subsections = (const VMStateDescription*[]) {
        &vmstate_pbr403,
        NULL
525 526 527 528 529 530 531
    }
};

static const VMStateDescription vmstate_tlbmas_entry = {
    .name = "cpu/tlbmas_entry",
    .version_id = 1,
    .minimum_version_id = 1,
532
    .fields = (VMStateField[]) {
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
        VMSTATE_UINT32(mas8, ppcmas_tlb_t),
        VMSTATE_UINT32(mas1, ppcmas_tlb_t),
        VMSTATE_UINT64(mas2, ppcmas_tlb_t),
        VMSTATE_UINT64(mas7_3, ppcmas_tlb_t),
        VMSTATE_END_OF_LIST()
    },
};

static bool tlbmas_needed(void *opaque)
{
    PowerPCCPU *cpu = opaque;
    CPUPPCState *env = &cpu->env;

    return env->nb_tlb && (env->tlb_type == TLB_MAS);
}

static const VMStateDescription vmstate_tlbmas = {
    .name = "cpu/tlbmas",
    .version_id = 1,
    .minimum_version_id = 1,
553
    .needed = tlbmas_needed,
554
    .fields = (VMStateField[]) {
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
        VMSTATE_INT32_EQUAL(env.nb_tlb, PowerPCCPU),
        VMSTATE_STRUCT_VARRAY_POINTER_INT32(env.tlb.tlbm, PowerPCCPU,
                                            env.nb_tlb,
                                            vmstate_tlbmas_entry,
                                            ppcmas_tlb_t),
        VMSTATE_END_OF_LIST()
    }
};

const VMStateDescription vmstate_ppc_cpu = {
    .name = "cpu",
    .version_id = 5,
    .minimum_version_id = 5,
    .minimum_version_id_old = 4,
    .load_state_old = cpu_load_old,
    .pre_save = cpu_pre_save,
    .post_load = cpu_post_load,
572
    .fields = (VMStateField[]) {
573
        VMSTATE_UNUSED(sizeof(target_ulong)), /* was _EQUAL(env.spr[SPR_PVR]) */
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597

        /* User mode architected state */
        VMSTATE_UINTTL_ARRAY(env.gpr, PowerPCCPU, 32),
#if !defined(TARGET_PPC64)
        VMSTATE_UINTTL_ARRAY(env.gprh, PowerPCCPU, 32),
#endif
        VMSTATE_UINT32_ARRAY(env.crf, PowerPCCPU, 8),
        VMSTATE_UINTTL(env.nip, PowerPCCPU),

        /* SPRs */
        VMSTATE_UINTTL_ARRAY(env.spr, PowerPCCPU, 1024),
        VMSTATE_UINT64(env.spe_acc, PowerPCCPU),

        /* Reservation */
        VMSTATE_UINTTL(env.reserve_addr, PowerPCCPU),

        /* Supervisor mode architected state */
        VMSTATE_UINTTL(env.msr, PowerPCCPU),

        /* Internal state */
        VMSTATE_UINTTL(env.hflags_nmsr, PowerPCCPU),
        /* FIXME: access_type? */

        /* Sanity checking */
598 599 600 601 602
        VMSTATE_UINTTL_TEST(mig_msr_mask, PowerPCCPU, cpu_pre_2_8_migration),
        VMSTATE_UINT64_TEST(mig_insns_flags, PowerPCCPU, cpu_pre_2_8_migration),
        VMSTATE_UINT64_TEST(mig_insns_flags2, PowerPCCPU,
                            cpu_pre_2_8_migration),
        VMSTATE_UINT32_TEST(mig_nb_BATs, PowerPCCPU, cpu_pre_2_8_migration),
603 604
        VMSTATE_END_OF_LIST()
    },
605 606 607 608 609
    .subsections = (const VMStateDescription*[]) {
        &vmstate_fpu,
        &vmstate_altivec,
        &vmstate_vsx,
        &vmstate_sr,
610
#ifdef TARGET_PPC64
611 612
        &vmstate_tm,
        &vmstate_slb,
613
#endif /* TARGET_PPC64 */
614 615 616 617
        &vmstate_tlb6xx,
        &vmstate_tlbemb,
        &vmstate_tlbmas,
        NULL
618 619
    }
};