xref: /qemu/target/openrisc/machine.c (revision bf88c124)
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 = 4,
51     .minimum_version_id = 4,
52     .fields = (VMStateField[]) {
53         VMSTATE_UINTTL_ARRAY(gpr, CPUOpenRISCState, 32),
54         VMSTATE_UINTTL(pc, CPUOpenRISCState),
55         VMSTATE_UINTTL(ppc, CPUOpenRISCState),
56         VMSTATE_UINTTL(jmp_pc, CPUOpenRISCState),
57         VMSTATE_UINTTL(lock_addr, CPUOpenRISCState),
58         VMSTATE_UINTTL(lock_value, CPUOpenRISCState),
59         VMSTATE_UINTTL(epcr, CPUOpenRISCState),
60         VMSTATE_UINTTL(eear, CPUOpenRISCState),
61 
62         /* Save the architecture value of the SR, not the internally
63            expanded version.  Since this architecture value does not
64            exist in memory to be stored, this requires a but of hoop
65            jumping.  We want OFFSET=0 so that we effectively pass ENV
66            to the helper functions, and we need to fill in the name by
67            hand since there's no field of that name.  */
68         {
69             .name = "sr",
70             .version_id = 0,
71             .size = sizeof(uint32_t),
72             .info = &vmstate_sr,
73             .flags = VMS_SINGLE,
74             .offset = 0
75         },
76 
77         VMSTATE_UINT32(vr, CPUOpenRISCState),
78         VMSTATE_UINT32(upr, CPUOpenRISCState),
79         VMSTATE_UINT32(cpucfgr, CPUOpenRISCState),
80         VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState),
81         VMSTATE_UINT32(immucfgr, CPUOpenRISCState),
82         VMSTATE_UINT32(esr, CPUOpenRISCState),
83         VMSTATE_UINT32(fpcsr, CPUOpenRISCState),
84         VMSTATE_UINT64(mac, CPUOpenRISCState),
85         VMSTATE_END_OF_LIST()
86     }
87 };
88 
89 const VMStateDescription vmstate_openrisc_cpu = {
90     .name = "cpu",
91     .version_id = 1,
92     .minimum_version_id = 1,
93     .fields = (VMStateField[]) {
94         VMSTATE_CPU(),
95         VMSTATE_STRUCT(env, OpenRISCCPU, 1, vmstate_env, CPUOpenRISCState),
96         VMSTATE_END_OF_LIST()
97     }
98 };
99