| 1 | /* |
| 2 | * Microblaze VMState for qemu. |
| 3 | * |
| 4 | * Copyright (c) 2020 Linaro, Ltd. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "qemu/osdep.h" |
| 21 | #include "cpu.h" |
| 22 | #include "migration/qemu-file-types.h" |
| 23 | #include "migration/vmstate.h" |
| 24 | |
| 25 | |
| 26 | static const VMStateField vmstate_mmu_fields[] = { |
| 27 | VMSTATE_UINT64_2DARRAY(rams, MicroBlazeMMU, 2, TLB_ENTRIES), |
| 28 | VMSTATE_UINT8_ARRAY(tids, MicroBlazeMMU, TLB_ENTRIES), |
| 29 | VMSTATE_UINT32_ARRAY(regs, MicroBlazeMMU, 3), |
| 30 | VMSTATE_END_OF_LIST() |
| 31 | }; |
| 32 | |
| 33 | static const VMStateDescription vmstate_mmu = { |
| 34 | .name = "mmu", |
| 35 | .version_id = 0, |
| 36 | .minimum_version_id = 0, |
| 37 | .fields = vmstate_mmu_fields, |
| 38 | }; |
| 39 | |
| 40 | static int get_msr(QEMUFile *f, void *opaque, size_t size, |
| 41 | const VMStateField *field) |
| 42 | { |
| 43 | CPUMBState *env = container_of(opaque, CPUMBState, msr); |
| 44 | |
| 45 | mb_cpu_write_msr(env, qemu_get_be32(f)); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int put_msr(QEMUFile *f, void *opaque, size_t size, |
| 50 | const VMStateField *field, JSONWriter *vmdesc) |
| 51 | { |
| 52 | CPUMBState *env = container_of(opaque, CPUMBState, msr); |
| 53 | |
| 54 | qemu_put_be32(f, mb_cpu_read_msr(env)); |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static const VMStateInfo vmstate_msr = { |
| 59 | .name = "msr", |
| 60 | .get = get_msr, |
| 61 | .put = put_msr, |
| 62 | }; |
| 63 | |
| 64 | static const VMStateField vmstate_env_fields[] = { |
| 65 | VMSTATE_UINT32_ARRAY(regs, CPUMBState, 32), |
| 66 | |
| 67 | VMSTATE_UINT32(pc, CPUMBState), |
| 68 | VMSTATE_SINGLE(msr, CPUMBState, 0, vmstate_msr, uint32_t), |
| 69 | VMSTATE_UINT32(esr, CPUMBState), |
| 70 | VMSTATE_UINT32(fsr, CPUMBState), |
| 71 | VMSTATE_UINT32(btr, CPUMBState), |
| 72 | VMSTATE_UINT32(edr, CPUMBState), |
| 73 | VMSTATE_UINT32(slr, CPUMBState), |
| 74 | VMSTATE_UINT32(shr, CPUMBState), |
| 75 | VMSTATE_UINT64(ear, CPUMBState), |
| 76 | |
| 77 | VMSTATE_UINT32(btarget, CPUMBState), |
| 78 | VMSTATE_UINT32(imm, CPUMBState), |
| 79 | VMSTATE_UINT32(iflags, CPUMBState), |
| 80 | |
| 81 | VMSTATE_UINT32(res_val, CPUMBState), |
| 82 | VMSTATE_UINT32(res_addr, CPUMBState), |
| 83 | |
| 84 | VMSTATE_STRUCT(mmu, CPUMBState, 0, vmstate_mmu, MicroBlazeMMU), |
| 85 | |
| 86 | VMSTATE_END_OF_LIST() |
| 87 | }; |
| 88 | |
| 89 | static const VMStateDescription vmstate_env = { |
| 90 | .name = "env", |
| 91 | .version_id = 1, |
| 92 | .minimum_version_id = 1, |
| 93 | .fields = vmstate_env_fields, |
| 94 | }; |
| 95 | |
| 96 | static const VMStateField vmstate_cpu_fields[] = { |
| 97 | VMSTATE_STRUCT(parent_obj, MicroBlazeCPU, 0, vmstate_cpu_common, CPUState), |
| 98 | VMSTATE_STRUCT(env, MicroBlazeCPU, 1, vmstate_env, CPUMBState), |
| 99 | VMSTATE_END_OF_LIST() |
| 100 | }; |
| 101 | |
| 102 | const VMStateDescription vmstate_mb_cpu = { |
| 103 | .name = "cpu", |
| 104 | .version_id = 0, |
| 105 | .minimum_version_id = 0, |
| 106 | .fields = vmstate_cpu_fields, |
| 107 | }; |