1 /* 2 * OpenRISC Machine 3 * 4 * Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com> 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 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 "qemu-common.h" 22 #include "cpu.h" 23 #include "hw/hw.h" 24 #include "hw/boards.h" 25 #include "migration/cpu.h" 26 27 static int get_sr(QEMUFile *f, void *opaque, size_t size, VMStateField *field) 28 { 29 CPUOpenRISCState *env = opaque; 30 cpu_set_sr(env, qemu_get_be32(f)); 31 return 0; 32 } 33 34 static int put_sr(QEMUFile *f, void *opaque, size_t size, 35 VMStateField *field, QJSON *vmdesc) 36 { 37 CPUOpenRISCState *env = opaque; 38 qemu_put_be32(f, cpu_get_sr(env)); 39 return 0; 40 } 41 42 static const VMStateInfo vmstate_sr = { 43 .name = "sr", 44 .get = get_sr, 45 .put = put_sr, 46 }; 47 48 static const VMStateDescription vmstate_env = { 49 .name = "env", 50 .version_id = 3, 51 .minimum_version_id = 3, 52 .fields = (VMStateField[]) { 53 VMSTATE_UINTTL_ARRAY(gpr, CPUOpenRISCState, 32), 54 VMSTATE_UINTTL(pc, CPUOpenRISCState), 55 VMSTATE_UINTTL(npc, CPUOpenRISCState), 56 VMSTATE_UINTTL(ppc, CPUOpenRISCState), 57 VMSTATE_UINTTL(jmp_pc, CPUOpenRISCState), 58 VMSTATE_UINTTL(lock_addr, CPUOpenRISCState), 59 VMSTATE_UINTTL(lock_value, CPUOpenRISCState), 60 VMSTATE_UINTTL(epcr, CPUOpenRISCState), 61 VMSTATE_UINTTL(eear, CPUOpenRISCState), 62 63 /* Save the architecture value of the SR, not the internally 64 expanded version. Since this architecture value does not 65 exist in memory to be stored, this requires a but of hoop 66 jumping. We want OFFSET=0 so that we effectively pass ENV 67 to the helper functions, and we need to fill in the name by 68 hand since there's no field of that name. */ 69 { 70 .name = "sr", 71 .version_id = 0, 72 .size = sizeof(uint32_t), 73 .info = &vmstate_sr, 74 .flags = VMS_SINGLE, 75 .offset = 0 76 }, 77 78 VMSTATE_UINT32(vr, CPUOpenRISCState), 79 VMSTATE_UINT32(upr, CPUOpenRISCState), 80 VMSTATE_UINT32(cpucfgr, CPUOpenRISCState), 81 VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState), 82 VMSTATE_UINT32(immucfgr, CPUOpenRISCState), 83 VMSTATE_UINT32(esr, CPUOpenRISCState), 84 VMSTATE_UINT32(fpcsr, CPUOpenRISCState), 85 VMSTATE_UINT64(mac, CPUOpenRISCState), 86 VMSTATE_END_OF_LIST() 87 } 88 }; 89 90 const VMStateDescription vmstate_openrisc_cpu = { 91 .name = "cpu", 92 .version_id = 1, 93 .minimum_version_id = 1, 94 .fields = (VMStateField[]) { 95 VMSTATE_CPU(), 96 VMSTATE_STRUCT(env, OpenRISCCPU, 1, vmstate_env, CPUOpenRISCState), 97 VMSTATE_END_OF_LIST() 98 } 99 }; 100