Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-04-29' into staging
[qemu.git] / target-mips / machine.c
blob22bca1814534032463daefaf3ecb55d1e6aa8ec9
1 #include "qemu/osdep.h"
2 #include "hw/hw.h"
4 #include "cpu.h"
6 static int cpu_post_load(void *opaque, int version_id)
8 MIPSCPU *cpu = opaque;
9 CPUMIPSState *env = &cpu->env;
11 restore_fp_status(env);
12 restore_msa_fp_status(env);
13 compute_hflags(env);
14 restore_pamask(env);
16 return 0;
19 /* FPU state */
21 static int get_fpr(QEMUFile *f, void *pv, size_t size)
23 int i;
24 fpr_t *v = pv;
25 /* Restore entire MSA vector register */
26 for (i = 0; i < MSA_WRLEN/64; i++) {
27 qemu_get_sbe64s(f, &v->wr.d[i]);
29 return 0;
32 static void put_fpr(QEMUFile *f, void *pv, size_t size)
34 int i;
35 fpr_t *v = pv;
36 /* Save entire MSA vector register */
37 for (i = 0; i < MSA_WRLEN/64; i++) {
38 qemu_put_sbe64s(f, &v->wr.d[i]);
42 const VMStateInfo vmstate_info_fpr = {
43 .name = "fpr",
44 .get = get_fpr,
45 .put = put_fpr,
48 #define VMSTATE_FPR_ARRAY_V(_f, _s, _n, _v) \
49 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_fpr, fpr_t)
51 #define VMSTATE_FPR_ARRAY(_f, _s, _n) \
52 VMSTATE_FPR_ARRAY_V(_f, _s, _n, 0)
54 static VMStateField vmstate_fpu_fields[] = {
55 VMSTATE_FPR_ARRAY(fpr, CPUMIPSFPUContext, 32),
56 VMSTATE_UINT32(fcr0, CPUMIPSFPUContext),
57 VMSTATE_UINT32(fcr31, CPUMIPSFPUContext),
58 VMSTATE_END_OF_LIST()
61 const VMStateDescription vmstate_fpu = {
62 .name = "cpu/fpu",
63 .version_id = 1,
64 .minimum_version_id = 1,
65 .fields = vmstate_fpu_fields
68 const VMStateDescription vmstate_inactive_fpu = {
69 .name = "cpu/inactive_fpu",
70 .version_id = 1,
71 .minimum_version_id = 1,
72 .fields = vmstate_fpu_fields
75 /* TC state */
77 static VMStateField vmstate_tc_fields[] = {
78 VMSTATE_UINTTL_ARRAY(gpr, TCState, 32),
79 VMSTATE_UINTTL(PC, TCState),
80 VMSTATE_UINTTL_ARRAY(HI, TCState, MIPS_DSP_ACC),
81 VMSTATE_UINTTL_ARRAY(LO, TCState, MIPS_DSP_ACC),
82 VMSTATE_UINTTL_ARRAY(ACX, TCState, MIPS_DSP_ACC),
83 VMSTATE_UINTTL(DSPControl, TCState),
84 VMSTATE_INT32(CP0_TCStatus, TCState),
85 VMSTATE_INT32(CP0_TCBind, TCState),
86 VMSTATE_UINTTL(CP0_TCHalt, TCState),
87 VMSTATE_UINTTL(CP0_TCContext, TCState),
88 VMSTATE_UINTTL(CP0_TCSchedule, TCState),
89 VMSTATE_UINTTL(CP0_TCScheFBack, TCState),
90 VMSTATE_INT32(CP0_Debug_tcstatus, TCState),
91 VMSTATE_UINTTL(CP0_UserLocal, TCState),
92 VMSTATE_INT32(msacsr, TCState),
93 VMSTATE_END_OF_LIST()
96 const VMStateDescription vmstate_tc = {
97 .name = "cpu/tc",
98 .version_id = 1,
99 .minimum_version_id = 1,
100 .fields = vmstate_tc_fields
103 const VMStateDescription vmstate_inactive_tc = {
104 .name = "cpu/inactive_tc",
105 .version_id = 1,
106 .minimum_version_id = 1,
107 .fields = vmstate_tc_fields
110 /* MVP state */
112 const VMStateDescription vmstate_mvp = {
113 .name = "cpu/mvp",
114 .version_id = 1,
115 .minimum_version_id = 1,
116 .fields = (VMStateField[]) {
117 VMSTATE_INT32(CP0_MVPControl, CPUMIPSMVPContext),
118 VMSTATE_INT32(CP0_MVPConf0, CPUMIPSMVPContext),
119 VMSTATE_INT32(CP0_MVPConf1, CPUMIPSMVPContext),
120 VMSTATE_END_OF_LIST()
124 /* TLB state */
126 static int get_tlb(QEMUFile *f, void *pv, size_t size)
128 r4k_tlb_t *v = pv;
129 uint16_t flags;
131 qemu_get_betls(f, &v->VPN);
132 qemu_get_be32s(f, &v->PageMask);
133 qemu_get_8s(f, &v->ASID);
134 qemu_get_be16s(f, &flags);
135 v->G = (flags >> 10) & 1;
136 v->C0 = (flags >> 7) & 3;
137 v->C1 = (flags >> 4) & 3;
138 v->V0 = (flags >> 3) & 1;
139 v->V1 = (flags >> 2) & 1;
140 v->D0 = (flags >> 1) & 1;
141 v->D1 = (flags >> 0) & 1;
142 v->EHINV = (flags >> 15) & 1;
143 v->RI1 = (flags >> 14) & 1;
144 v->RI0 = (flags >> 13) & 1;
145 v->XI1 = (flags >> 12) & 1;
146 v->XI0 = (flags >> 11) & 1;
147 qemu_get_be64s(f, &v->PFN[0]);
148 qemu_get_be64s(f, &v->PFN[1]);
150 return 0;
153 static void put_tlb(QEMUFile *f, void *pv, size_t size)
155 r4k_tlb_t *v = pv;
157 uint8_t asid = v->ASID;
158 uint16_t flags = ((v->EHINV << 15) |
159 (v->RI1 << 14) |
160 (v->RI0 << 13) |
161 (v->XI1 << 12) |
162 (v->XI0 << 11) |
163 (v->G << 10) |
164 (v->C0 << 7) |
165 (v->C1 << 4) |
166 (v->V0 << 3) |
167 (v->V1 << 2) |
168 (v->D0 << 1) |
169 (v->D1 << 0));
171 qemu_put_betls(f, &v->VPN);
172 qemu_put_be32s(f, &v->PageMask);
173 qemu_put_8s(f, &asid);
174 qemu_put_be16s(f, &flags);
175 qemu_put_be64s(f, &v->PFN[0]);
176 qemu_put_be64s(f, &v->PFN[1]);
179 const VMStateInfo vmstate_info_tlb = {
180 .name = "tlb_entry",
181 .get = get_tlb,
182 .put = put_tlb,
185 #define VMSTATE_TLB_ARRAY_V(_f, _s, _n, _v) \
186 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_tlb, r4k_tlb_t)
188 #define VMSTATE_TLB_ARRAY(_f, _s, _n) \
189 VMSTATE_TLB_ARRAY_V(_f, _s, _n, 0)
191 const VMStateDescription vmstate_tlb = {
192 .name = "cpu/tlb",
193 .version_id = 1,
194 .minimum_version_id = 1,
195 .fields = (VMStateField[]) {
196 VMSTATE_UINT32(nb_tlb, CPUMIPSTLBContext),
197 VMSTATE_UINT32(tlb_in_use, CPUMIPSTLBContext),
198 VMSTATE_TLB_ARRAY(mmu.r4k.tlb, CPUMIPSTLBContext, MIPS_TLB_MAX),
199 VMSTATE_END_OF_LIST()
203 /* MIPS CPU state */
205 const VMStateDescription vmstate_mips_cpu = {
206 .name = "cpu",
207 .version_id = 8,
208 .minimum_version_id = 8,
209 .post_load = cpu_post_load,
210 .fields = (VMStateField[]) {
211 /* Active TC */
212 VMSTATE_STRUCT(env.active_tc, MIPSCPU, 1, vmstate_tc, TCState),
214 /* Active FPU */
215 VMSTATE_STRUCT(env.active_fpu, MIPSCPU, 1, vmstate_fpu,
216 CPUMIPSFPUContext),
218 /* MVP */
219 VMSTATE_STRUCT_POINTER(env.mvp, MIPSCPU, vmstate_mvp,
220 CPUMIPSMVPContext),
222 /* TLB */
223 VMSTATE_STRUCT_POINTER(env.tlb, MIPSCPU, vmstate_tlb,
224 CPUMIPSTLBContext),
226 /* CPU metastate */
227 VMSTATE_UINT32(env.current_tc, MIPSCPU),
228 VMSTATE_UINT32(env.current_fpu, MIPSCPU),
229 VMSTATE_INT32(env.error_code, MIPSCPU),
230 VMSTATE_UINTTL(env.btarget, MIPSCPU),
231 VMSTATE_UINTTL(env.bcond, MIPSCPU),
233 /* Remaining CP0 registers */
234 VMSTATE_INT32(env.CP0_Index, MIPSCPU),
235 VMSTATE_INT32(env.CP0_Random, MIPSCPU),
236 VMSTATE_INT32(env.CP0_VPEControl, MIPSCPU),
237 VMSTATE_INT32(env.CP0_VPEConf0, MIPSCPU),
238 VMSTATE_INT32(env.CP0_VPEConf1, MIPSCPU),
239 VMSTATE_UINTTL(env.CP0_YQMask, MIPSCPU),
240 VMSTATE_UINTTL(env.CP0_VPESchedule, MIPSCPU),
241 VMSTATE_UINTTL(env.CP0_VPEScheFBack, MIPSCPU),
242 VMSTATE_INT32(env.CP0_VPEOpt, MIPSCPU),
243 VMSTATE_UINT64(env.CP0_EntryLo0, MIPSCPU),
244 VMSTATE_UINT64(env.CP0_EntryLo1, MIPSCPU),
245 VMSTATE_UINTTL(env.CP0_Context, MIPSCPU),
246 VMSTATE_INT32(env.CP0_PageMask, MIPSCPU),
247 VMSTATE_INT32(env.CP0_PageGrain, MIPSCPU),
248 VMSTATE_INT32(env.CP0_Wired, MIPSCPU),
249 VMSTATE_INT32(env.CP0_SRSConf0, MIPSCPU),
250 VMSTATE_INT32(env.CP0_SRSConf1, MIPSCPU),
251 VMSTATE_INT32(env.CP0_SRSConf2, MIPSCPU),
252 VMSTATE_INT32(env.CP0_SRSConf3, MIPSCPU),
253 VMSTATE_INT32(env.CP0_SRSConf4, MIPSCPU),
254 VMSTATE_INT32(env.CP0_HWREna, MIPSCPU),
255 VMSTATE_UINTTL(env.CP0_BadVAddr, MIPSCPU),
256 VMSTATE_UINT32(env.CP0_BadInstr, MIPSCPU),
257 VMSTATE_UINT32(env.CP0_BadInstrP, MIPSCPU),
258 VMSTATE_INT32(env.CP0_Count, MIPSCPU),
259 VMSTATE_UINTTL(env.CP0_EntryHi, MIPSCPU),
260 VMSTATE_INT32(env.CP0_Compare, MIPSCPU),
261 VMSTATE_INT32(env.CP0_Status, MIPSCPU),
262 VMSTATE_INT32(env.CP0_IntCtl, MIPSCPU),
263 VMSTATE_INT32(env.CP0_SRSCtl, MIPSCPU),
264 VMSTATE_INT32(env.CP0_SRSMap, MIPSCPU),
265 VMSTATE_INT32(env.CP0_Cause, MIPSCPU),
266 VMSTATE_UINTTL(env.CP0_EPC, MIPSCPU),
267 VMSTATE_INT32(env.CP0_PRid, MIPSCPU),
268 VMSTATE_INT32(env.CP0_EBase, MIPSCPU),
269 VMSTATE_INT32(env.CP0_Config0, MIPSCPU),
270 VMSTATE_INT32(env.CP0_Config1, MIPSCPU),
271 VMSTATE_INT32(env.CP0_Config2, MIPSCPU),
272 VMSTATE_INT32(env.CP0_Config3, MIPSCPU),
273 VMSTATE_INT32(env.CP0_Config6, MIPSCPU),
274 VMSTATE_INT32(env.CP0_Config7, MIPSCPU),
275 VMSTATE_UINT64_ARRAY(env.CP0_MAAR, MIPSCPU, MIPS_MAAR_MAX),
276 VMSTATE_INT32(env.CP0_MAARI, MIPSCPU),
277 VMSTATE_UINT64(env.lladdr, MIPSCPU),
278 VMSTATE_UINTTL_ARRAY(env.CP0_WatchLo, MIPSCPU, 8),
279 VMSTATE_INT32_ARRAY(env.CP0_WatchHi, MIPSCPU, 8),
280 VMSTATE_UINTTL(env.CP0_XContext, MIPSCPU),
281 VMSTATE_INT32(env.CP0_Framemask, MIPSCPU),
282 VMSTATE_INT32(env.CP0_Debug, MIPSCPU),
283 VMSTATE_UINTTL(env.CP0_DEPC, MIPSCPU),
284 VMSTATE_INT32(env.CP0_Performance0, MIPSCPU),
285 VMSTATE_UINT64(env.CP0_TagLo, MIPSCPU),
286 VMSTATE_INT32(env.CP0_DataLo, MIPSCPU),
287 VMSTATE_INT32(env.CP0_TagHi, MIPSCPU),
288 VMSTATE_INT32(env.CP0_DataHi, MIPSCPU),
289 VMSTATE_UINTTL(env.CP0_ErrorEPC, MIPSCPU),
290 VMSTATE_INT32(env.CP0_DESAVE, MIPSCPU),
291 VMSTATE_UINTTL_ARRAY(env.CP0_KScratch, MIPSCPU, MIPS_KSCRATCH_NUM),
293 /* Inactive TC */
294 VMSTATE_STRUCT_ARRAY(env.tcs, MIPSCPU, MIPS_SHADOW_SET_MAX, 1,
295 vmstate_inactive_tc, TCState),
296 VMSTATE_STRUCT_ARRAY(env.fpus, MIPSCPU, MIPS_FPU_MAX, 1,
297 vmstate_inactive_fpu, CPUMIPSFPUContext),
299 VMSTATE_END_OF_LIST()