xref: /openbmc/qemu/target/openrisc/machine.c (revision db725815985654007ade0fd53590d613fd657208)
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.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 "hw/boards.h"
23 #include "migration/cpu.h"
24 
25 static const VMStateDescription vmstate_tlb_entry = {
26     .name = "tlb_entry",
27     .version_id = 1,
28     .minimum_version_id = 1,
29     .minimum_version_id_old = 1,
30     .fields = (VMStateField[]) {
31         VMSTATE_UINTTL(mr, OpenRISCTLBEntry),
32         VMSTATE_UINTTL(tr, OpenRISCTLBEntry),
33         VMSTATE_END_OF_LIST()
34     }
35 };
36 
37 static const VMStateDescription vmstate_cpu_tlb = {
38     .name = "cpu_tlb",
39     .version_id = 2,
40     .minimum_version_id = 2,
41     .fields = (VMStateField[]) {
42         VMSTATE_STRUCT_ARRAY(itlb, CPUOpenRISCTLBContext, TLB_SIZE, 0,
43                              vmstate_tlb_entry, OpenRISCTLBEntry),
44         VMSTATE_STRUCT_ARRAY(dtlb, CPUOpenRISCTLBContext, TLB_SIZE, 0,
45                              vmstate_tlb_entry, OpenRISCTLBEntry),
46         VMSTATE_END_OF_LIST()
47     }
48 };
49 
50 static int get_sr(QEMUFile *f, void *opaque, size_t size,
51                   const VMStateField *field)
52 {
53     CPUOpenRISCState *env = opaque;
54     cpu_set_sr(env, qemu_get_be32(f));
55     return 0;
56 }
57 
58 static int put_sr(QEMUFile *f, void *opaque, size_t size,
59                   const VMStateField *field, QJSON *vmdesc)
60 {
61     CPUOpenRISCState *env = opaque;
62     qemu_put_be32(f, cpu_get_sr(env));
63     return 0;
64 }
65 
66 static const VMStateInfo vmstate_sr = {
67     .name = "sr",
68     .get = get_sr,
69     .put = put_sr,
70 };
71 
72 static const VMStateDescription vmstate_env = {
73     .name = "env",
74     .version_id = 6,
75     .minimum_version_id = 6,
76     .fields = (VMStateField[]) {
77         VMSTATE_UINTTL_2DARRAY(shadow_gpr, CPUOpenRISCState, 16, 32),
78         VMSTATE_UINTTL(pc, CPUOpenRISCState),
79         VMSTATE_UINTTL(ppc, CPUOpenRISCState),
80         VMSTATE_UINTTL(jmp_pc, CPUOpenRISCState),
81         VMSTATE_UINTTL(lock_addr, CPUOpenRISCState),
82         VMSTATE_UINTTL(lock_value, CPUOpenRISCState),
83         VMSTATE_UINTTL(epcr, CPUOpenRISCState),
84         VMSTATE_UINTTL(eear, CPUOpenRISCState),
85 
86         /* Save the architecture value of the SR, not the internally
87            expanded version.  Since this architecture value does not
88            exist in memory to be stored, this requires a but of hoop
89            jumping.  We want OFFSET=0 so that we effectively pass ENV
90            to the helper functions, and we need to fill in the name by
91            hand since there's no field of that name.  */
92         {
93             .name = "sr",
94             .version_id = 0,
95             .size = sizeof(uint32_t),
96             .info = &vmstate_sr,
97             .flags = VMS_SINGLE,
98             .offset = 0
99         },
100 
101         VMSTATE_UINT32(vr, CPUOpenRISCState),
102         VMSTATE_UINT32(upr, CPUOpenRISCState),
103         VMSTATE_UINT32(cpucfgr, CPUOpenRISCState),
104         VMSTATE_UINT32(dmmucfgr, CPUOpenRISCState),
105         VMSTATE_UINT32(immucfgr, CPUOpenRISCState),
106         VMSTATE_UINT32(evbar, CPUOpenRISCState),
107         VMSTATE_UINT32(pmr, CPUOpenRISCState),
108         VMSTATE_UINT32(esr, CPUOpenRISCState),
109         VMSTATE_UINT32(fpcsr, CPUOpenRISCState),
110         VMSTATE_UINT64(mac, CPUOpenRISCState),
111 
112         VMSTATE_STRUCT(tlb, CPUOpenRISCState, 1,
113                        vmstate_cpu_tlb, CPUOpenRISCTLBContext),
114 
115         VMSTATE_TIMER_PTR(timer, CPUOpenRISCState),
116         VMSTATE_UINT32(ttmr, CPUOpenRISCState),
117 
118         VMSTATE_UINT32(picmr, CPUOpenRISCState),
119         VMSTATE_UINT32(picsr, CPUOpenRISCState),
120 
121         VMSTATE_END_OF_LIST()
122     }
123 };
124 
125 const VMStateDescription vmstate_openrisc_cpu = {
126     .name = "cpu",
127     .version_id = 1,
128     .minimum_version_id = 1,
129     .fields = (VMStateField[]) {
130         VMSTATE_CPU(),
131         VMSTATE_STRUCT(env, OpenRISCCPU, 1, vmstate_env, CPUOpenRISCState),
132         VMSTATE_END_OF_LIST()
133     }
134 };
135