iotests: Make 136 less flaky
[qemu/ar7.git] / target / mips / machine.c
blob20100d5adb0ed366cf59e930b3a34b504c7b5a50
1 #include "qemu/osdep.h"
2 #include "qemu-common.h"
3 #include "cpu.h"
4 #include "internal.h"
5 #include "hw/hw.h"
6 #include "migration/cpu.h"
8 static int cpu_post_load(void *opaque, int version_id)
10 MIPSCPU *cpu = opaque;
11 CPUMIPSState *env = &cpu->env;
13 restore_fp_status(env);
14 restore_msa_fp_status(env);
15 compute_hflags(env);
16 restore_pamask(env);
18 return 0;
21 /* FPU state */
23 static int get_fpr(QEMUFile *f, void *pv, size_t size, VMStateField *field)
25 int i;
26 fpr_t *v = pv;
27 /* Restore entire MSA vector register */
28 for (i = 0; i < MSA_WRLEN/64; i++) {
29 qemu_get_sbe64s(f, &v->wr.d[i]);
31 return 0;
34 static int put_fpr(QEMUFile *f, void *pv, size_t size, VMStateField *field,
35 QJSON *vmdesc)
37 int i;
38 fpr_t *v = pv;
39 /* Save entire MSA vector register */
40 for (i = 0; i < MSA_WRLEN/64; i++) {
41 qemu_put_sbe64s(f, &v->wr.d[i]);
44 return 0;
47 const VMStateInfo vmstate_info_fpr = {
48 .name = "fpr",
49 .get = get_fpr,
50 .put = put_fpr,
53 #define VMSTATE_FPR_ARRAY_V(_f, _s, _n, _v) \
54 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_fpr, fpr_t)
56 #define VMSTATE_FPR_ARRAY(_f, _s, _n) \
57 VMSTATE_FPR_ARRAY_V(_f, _s, _n, 0)
59 static VMStateField vmstate_fpu_fields[] = {
60 VMSTATE_FPR_ARRAY(fpr, CPUMIPSFPUContext, 32),
61 VMSTATE_UINT32(fcr0, CPUMIPSFPUContext),
62 VMSTATE_UINT32(fcr31, CPUMIPSFPUContext),
63 VMSTATE_END_OF_LIST()
66 const VMStateDescription vmstate_fpu = {
67 .name = "cpu/fpu",
68 .version_id = 1,
69 .minimum_version_id = 1,
70 .fields = vmstate_fpu_fields
73 const VMStateDescription vmstate_inactive_fpu = {
74 .name = "cpu/inactive_fpu",
75 .version_id = 1,
76 .minimum_version_id = 1,
77 .fields = vmstate_fpu_fields
80 /* TC state */
82 static VMStateField vmstate_tc_fields[] = {
83 VMSTATE_UINTTL_ARRAY(gpr, TCState, 32),
84 VMSTATE_UINTTL(PC, TCState),
85 VMSTATE_UINTTL_ARRAY(HI, TCState, MIPS_DSP_ACC),
86 VMSTATE_UINTTL_ARRAY(LO, TCState, MIPS_DSP_ACC),
87 VMSTATE_UINTTL_ARRAY(ACX, TCState, MIPS_DSP_ACC),
88 VMSTATE_UINTTL(DSPControl, TCState),
89 VMSTATE_INT32(CP0_TCStatus, TCState),
90 VMSTATE_INT32(CP0_TCBind, TCState),
91 VMSTATE_UINTTL(CP0_TCHalt, TCState),
92 VMSTATE_UINTTL(CP0_TCContext, TCState),
93 VMSTATE_UINTTL(CP0_TCSchedule, TCState),
94 VMSTATE_UINTTL(CP0_TCScheFBack, TCState),
95 VMSTATE_INT32(CP0_Debug_tcstatus, TCState),
96 VMSTATE_UINTTL(CP0_UserLocal, TCState),
97 VMSTATE_INT32(msacsr, TCState),
98 VMSTATE_END_OF_LIST()
101 const VMStateDescription vmstate_tc = {
102 .name = "cpu/tc",
103 .version_id = 1,
104 .minimum_version_id = 1,
105 .fields = vmstate_tc_fields
108 const VMStateDescription vmstate_inactive_tc = {
109 .name = "cpu/inactive_tc",
110 .version_id = 1,
111 .minimum_version_id = 1,
112 .fields = vmstate_tc_fields
115 /* MVP state */
117 const VMStateDescription vmstate_mvp = {
118 .name = "cpu/mvp",
119 .version_id = 1,
120 .minimum_version_id = 1,
121 .fields = (VMStateField[]) {
122 VMSTATE_INT32(CP0_MVPControl, CPUMIPSMVPContext),
123 VMSTATE_INT32(CP0_MVPConf0, CPUMIPSMVPContext),
124 VMSTATE_INT32(CP0_MVPConf1, CPUMIPSMVPContext),
125 VMSTATE_END_OF_LIST()
129 /* TLB state */
131 static int get_tlb(QEMUFile *f, void *pv, size_t size, VMStateField *field)
133 r4k_tlb_t *v = pv;
134 uint16_t flags;
136 qemu_get_betls(f, &v->VPN);
137 qemu_get_be32s(f, &v->PageMask);
138 qemu_get_be16s(f, &v->ASID);
139 qemu_get_be16s(f, &flags);
140 v->G = (flags >> 10) & 1;
141 v->C0 = (flags >> 7) & 3;
142 v->C1 = (flags >> 4) & 3;
143 v->V0 = (flags >> 3) & 1;
144 v->V1 = (flags >> 2) & 1;
145 v->D0 = (flags >> 1) & 1;
146 v->D1 = (flags >> 0) & 1;
147 v->EHINV = (flags >> 15) & 1;
148 v->RI1 = (flags >> 14) & 1;
149 v->RI0 = (flags >> 13) & 1;
150 v->XI1 = (flags >> 12) & 1;
151 v->XI0 = (flags >> 11) & 1;
152 qemu_get_be64s(f, &v->PFN[0]);
153 qemu_get_be64s(f, &v->PFN[1]);
155 return 0;
158 static int put_tlb(QEMUFile *f, void *pv, size_t size, VMStateField *field,
159 QJSON *vmdesc)
161 r4k_tlb_t *v = pv;
163 uint16_t asid = v->ASID;
164 uint16_t flags = ((v->EHINV << 15) |
165 (v->RI1 << 14) |
166 (v->RI0 << 13) |
167 (v->XI1 << 12) |
168 (v->XI0 << 11) |
169 (v->G << 10) |
170 (v->C0 << 7) |
171 (v->C1 << 4) |
172 (v->V0 << 3) |
173 (v->V1 << 2) |
174 (v->D0 << 1) |
175 (v->D1 << 0));
177 qemu_put_betls(f, &v->VPN);
178 qemu_put_be32s(f, &v->PageMask);
179 qemu_put_be16s(f, &asid);
180 qemu_put_be16s(f, &flags);
181 qemu_put_be64s(f, &v->PFN[0]);
182 qemu_put_be64s(f, &v->PFN[1]);
184 return 0;
187 const VMStateInfo vmstate_info_tlb = {
188 .name = "tlb_entry",
189 .get = get_tlb,
190 .put = put_tlb,
193 #define VMSTATE_TLB_ARRAY_V(_f, _s, _n, _v) \
194 VMSTATE_ARRAY(_f, _s, _n, _v, vmstate_info_tlb, r4k_tlb_t)
196 #define VMSTATE_TLB_ARRAY(_f, _s, _n) \
197 VMSTATE_TLB_ARRAY_V(_f, _s, _n, 0)
199 const VMStateDescription vmstate_tlb = {
200 .name = "cpu/tlb",
201 .version_id = 2,
202 .minimum_version_id = 2,
203 .fields = (VMStateField[]) {
204 VMSTATE_UINT32(nb_tlb, CPUMIPSTLBContext),
205 VMSTATE_UINT32(tlb_in_use, CPUMIPSTLBContext),
206 VMSTATE_TLB_ARRAY(mmu.r4k.tlb, CPUMIPSTLBContext, MIPS_TLB_MAX),
207 VMSTATE_END_OF_LIST()
211 /* MIPS CPU state */
213 const VMStateDescription vmstate_mips_cpu = {
214 .name = "cpu",
215 .version_id = 10,
216 .minimum_version_id = 10,
217 .post_load = cpu_post_load,
218 .fields = (VMStateField[]) {
219 /* Active TC */
220 VMSTATE_STRUCT(env.active_tc, MIPSCPU, 1, vmstate_tc, TCState),
222 /* Active FPU */
223 VMSTATE_STRUCT(env.active_fpu, MIPSCPU, 1, vmstate_fpu,
224 CPUMIPSFPUContext),
226 /* MVP */
227 VMSTATE_STRUCT_POINTER(env.mvp, MIPSCPU, vmstate_mvp,
228 CPUMIPSMVPContext),
230 /* TLB */
231 VMSTATE_STRUCT_POINTER(env.tlb, MIPSCPU, vmstate_tlb,
232 CPUMIPSTLBContext),
234 /* CPU metastate */
235 VMSTATE_UINT32(env.current_tc, MIPSCPU),
236 VMSTATE_UINT32(env.current_fpu, MIPSCPU),
237 VMSTATE_INT32(env.error_code, MIPSCPU),
238 VMSTATE_UINTTL(env.btarget, MIPSCPU),
239 VMSTATE_UINTTL(env.bcond, MIPSCPU),
241 /* Remaining CP0 registers */
242 VMSTATE_INT32(env.CP0_Index, MIPSCPU),
243 VMSTATE_INT32(env.CP0_Random, MIPSCPU),
244 VMSTATE_INT32(env.CP0_VPEControl, MIPSCPU),
245 VMSTATE_INT32(env.CP0_VPEConf0, MIPSCPU),
246 VMSTATE_INT32(env.CP0_VPEConf1, MIPSCPU),
247 VMSTATE_UINTTL(env.CP0_YQMask, MIPSCPU),
248 VMSTATE_UINTTL(env.CP0_VPESchedule, MIPSCPU),
249 VMSTATE_UINTTL(env.CP0_VPEScheFBack, MIPSCPU),
250 VMSTATE_INT32(env.CP0_VPEOpt, MIPSCPU),
251 VMSTATE_UINT64(env.CP0_EntryLo0, MIPSCPU),
252 VMSTATE_UINT64(env.CP0_EntryLo1, MIPSCPU),
253 VMSTATE_UINTTL(env.CP0_Context, MIPSCPU),
254 VMSTATE_INT32(env.CP0_PageMask, MIPSCPU),
255 VMSTATE_INT32(env.CP0_PageGrain, MIPSCPU),
256 VMSTATE_UINTTL(env.CP0_SegCtl0, MIPSCPU),
257 VMSTATE_UINTTL(env.CP0_SegCtl1, MIPSCPU),
258 VMSTATE_UINTTL(env.CP0_SegCtl2, MIPSCPU),
259 VMSTATE_INT32(env.CP0_Wired, MIPSCPU),
260 VMSTATE_INT32(env.CP0_SRSConf0, MIPSCPU),
261 VMSTATE_INT32(env.CP0_SRSConf1, MIPSCPU),
262 VMSTATE_INT32(env.CP0_SRSConf2, MIPSCPU),
263 VMSTATE_INT32(env.CP0_SRSConf3, MIPSCPU),
264 VMSTATE_INT32(env.CP0_SRSConf4, MIPSCPU),
265 VMSTATE_INT32(env.CP0_HWREna, MIPSCPU),
266 VMSTATE_UINTTL(env.CP0_BadVAddr, MIPSCPU),
267 VMSTATE_UINT32(env.CP0_BadInstr, MIPSCPU),
268 VMSTATE_UINT32(env.CP0_BadInstrP, MIPSCPU),
269 VMSTATE_INT32(env.CP0_Count, MIPSCPU),
270 VMSTATE_UINTTL(env.CP0_EntryHi, MIPSCPU),
271 VMSTATE_INT32(env.CP0_Compare, MIPSCPU),
272 VMSTATE_INT32(env.CP0_Status, MIPSCPU),
273 VMSTATE_INT32(env.CP0_IntCtl, MIPSCPU),
274 VMSTATE_INT32(env.CP0_SRSCtl, MIPSCPU),
275 VMSTATE_INT32(env.CP0_SRSMap, MIPSCPU),
276 VMSTATE_INT32(env.CP0_Cause, MIPSCPU),
277 VMSTATE_UINTTL(env.CP0_EPC, MIPSCPU),
278 VMSTATE_INT32(env.CP0_PRid, MIPSCPU),
279 VMSTATE_UINTTL(env.CP0_EBase, MIPSCPU),
280 VMSTATE_INT32(env.CP0_Config0, MIPSCPU),
281 VMSTATE_INT32(env.CP0_Config1, MIPSCPU),
282 VMSTATE_INT32(env.CP0_Config2, MIPSCPU),
283 VMSTATE_INT32(env.CP0_Config3, MIPSCPU),
284 VMSTATE_INT32(env.CP0_Config6, MIPSCPU),
285 VMSTATE_INT32(env.CP0_Config7, MIPSCPU),
286 VMSTATE_UINT64_ARRAY(env.CP0_MAAR, MIPSCPU, MIPS_MAAR_MAX),
287 VMSTATE_INT32(env.CP0_MAARI, MIPSCPU),
288 VMSTATE_UINT64(env.lladdr, MIPSCPU),
289 VMSTATE_UINTTL_ARRAY(env.CP0_WatchLo, MIPSCPU, 8),
290 VMSTATE_INT32_ARRAY(env.CP0_WatchHi, MIPSCPU, 8),
291 VMSTATE_UINTTL(env.CP0_XContext, MIPSCPU),
292 VMSTATE_INT32(env.CP0_Framemask, MIPSCPU),
293 VMSTATE_INT32(env.CP0_Debug, MIPSCPU),
294 VMSTATE_UINTTL(env.CP0_DEPC, MIPSCPU),
295 VMSTATE_INT32(env.CP0_Performance0, MIPSCPU),
296 VMSTATE_UINT64(env.CP0_TagLo, MIPSCPU),
297 VMSTATE_INT32(env.CP0_DataLo, MIPSCPU),
298 VMSTATE_INT32(env.CP0_TagHi, MIPSCPU),
299 VMSTATE_INT32(env.CP0_DataHi, MIPSCPU),
300 VMSTATE_UINTTL(env.CP0_ErrorEPC, MIPSCPU),
301 VMSTATE_INT32(env.CP0_DESAVE, MIPSCPU),
302 VMSTATE_UINTTL_ARRAY(env.CP0_KScratch, MIPSCPU, MIPS_KSCRATCH_NUM),
304 /* Inactive TC */
305 VMSTATE_STRUCT_ARRAY(env.tcs, MIPSCPU, MIPS_SHADOW_SET_MAX, 1,
306 vmstate_inactive_tc, TCState),
307 VMSTATE_STRUCT_ARRAY(env.fpus, MIPSCPU, MIPS_FPU_MAX, 1,
308 vmstate_inactive_fpu, CPUMIPSFPUContext),
310 VMSTATE_END_OF_LIST()