1#include "qemu/osdep.h"
2#include "cpu.h"
3#include "exec/exec-all.h"
4#include "qemu/timer.h"
5
6#include "migration/cpu.h"
7
8#ifdef TARGET_SPARC64
9static const VMStateDescription vmstate_cpu_timer = {
10 .name = "cpu_timer",
11 .version_id = 1,
12 .minimum_version_id = 1,
13 .minimum_version_id_old = 1,
14 .fields = (VMStateField[]) {
15 VMSTATE_UINT32(frequency, CPUTimer),
16 VMSTATE_UINT32(disabled, CPUTimer),
17 VMSTATE_UINT64(disabled_mask, CPUTimer),
18 VMSTATE_UINT32(npt, CPUTimer),
19 VMSTATE_UINT64(npt_mask, CPUTimer),
20 VMSTATE_INT64(clock_offset, CPUTimer),
21 VMSTATE_TIMER_PTR(qtimer, CPUTimer),
22 VMSTATE_END_OF_LIST()
23 }
24};
25
26#define VMSTATE_CPU_TIMER(_f, _s) \
27 VMSTATE_STRUCT_POINTER(_f, _s, vmstate_cpu_timer, CPUTimer)
28
29static const VMStateDescription vmstate_trap_state = {
30 .name = "trap_state",
31 .version_id = 1,
32 .minimum_version_id = 1,
33 .minimum_version_id_old = 1,
34 .fields = (VMStateField[]) {
35 VMSTATE_UINT64(tpc, trap_state),
36 VMSTATE_UINT64(tnpc, trap_state),
37 VMSTATE_UINT64(tstate, trap_state),
38 VMSTATE_UINT32(tt, trap_state),
39 VMSTATE_END_OF_LIST()
40 }
41};
42
43static const VMStateDescription vmstate_tlb_entry = {
44 .name = "tlb_entry",
45 .version_id = 1,
46 .minimum_version_id = 1,
47 .minimum_version_id_old = 1,
48 .fields = (VMStateField[]) {
49 VMSTATE_UINT64(tag, SparcTLBEntry),
50 VMSTATE_UINT64(tte, SparcTLBEntry),
51 VMSTATE_END_OF_LIST()
52 }
53};
54#endif
55
56static int get_psr(QEMUFile *f, void *opaque, size_t size,
57 const VMStateField *field)
58{
59 SPARCCPU *cpu = opaque;
60 CPUSPARCState *env = &cpu->env;
61 uint32_t val = qemu_get_be32(f);
62
63
64 env->cwp = 0;
65 cpu_put_psr_raw(env, val);
66
67 return 0;
68}
69
70static int put_psr(QEMUFile *f, void *opaque, size_t size,
71 const VMStateField *field, QJSON *vmdesc)
72{
73 SPARCCPU *cpu = opaque;
74 CPUSPARCState *env = &cpu->env;
75 uint32_t val;
76
77 val = cpu_get_psr(env);
78
79 qemu_put_be32(f, val);
80 return 0;
81}
82
83static const VMStateInfo vmstate_psr = {
84 .name = "psr",
85 .get = get_psr,
86 .put = put_psr,
87};
88
89static int cpu_pre_save(void *opaque)
90{
91 SPARCCPU *cpu = opaque;
92 CPUSPARCState *env = &cpu->env;
93
94
95
96
97 cpu_set_cwp(env, env->cwp);
98
99 return 0;
100}
101
102
103
104
105
106#ifndef TARGET_SPARC64
107#define SPARC_VMSTATE_VER 7
108#else
109#define SPARC_VMSTATE_VER 9
110#endif
111
112const VMStateDescription vmstate_sparc_cpu = {
113 .name = "cpu",
114 .version_id = SPARC_VMSTATE_VER,
115 .minimum_version_id = SPARC_VMSTATE_VER,
116 .minimum_version_id_old = SPARC_VMSTATE_VER,
117 .pre_save = cpu_pre_save,
118 .fields = (VMStateField[]) {
119 VMSTATE_UINTTL_ARRAY(env.gregs, SPARCCPU, 8),
120 VMSTATE_UINT32(env.nwindows, SPARCCPU),
121 VMSTATE_VARRAY_MULTIPLY(env.regbase, SPARCCPU, env.nwindows, 16,
122 vmstate_info_uinttl, target_ulong),
123 VMSTATE_CPUDOUBLE_ARRAY(env.fpr, SPARCCPU, TARGET_DPREGS),
124 VMSTATE_UINTTL(env.pc, SPARCCPU),
125 VMSTATE_UINTTL(env.npc, SPARCCPU),
126 VMSTATE_UINTTL(env.y, SPARCCPU),
127 {
128
129 .name = "psr",
130 .version_id = 0,
131 .size = sizeof(uint32_t),
132 .info = &vmstate_psr,
133 .flags = VMS_SINGLE,
134 .offset = 0,
135 },
136 VMSTATE_UINTTL(env.fsr, SPARCCPU),
137 VMSTATE_UINTTL(env.tbr, SPARCCPU),
138 VMSTATE_INT32(env.interrupt_index, SPARCCPU),
139 VMSTATE_UINT32(env.pil_in, SPARCCPU),
140#ifndef TARGET_SPARC64
141
142 VMSTATE_UINT32(env.wim, SPARCCPU),
143 VMSTATE_UINT32_ARRAY(env.mmuregs, SPARCCPU, 32),
144 VMSTATE_UINT64_ARRAY(env.mxccdata, SPARCCPU, 4),
145 VMSTATE_UINT64_ARRAY(env.mxccregs, SPARCCPU, 8),
146 VMSTATE_UINT32(env.mmubpctrv, SPARCCPU),
147 VMSTATE_UINT32(env.mmubpctrc, SPARCCPU),
148 VMSTATE_UINT32(env.mmubpctrs, SPARCCPU),
149 VMSTATE_UINT64(env.mmubpaction, SPARCCPU),
150 VMSTATE_UINT64_ARRAY(env.mmubpregs, SPARCCPU, 4),
151#else
152 VMSTATE_UINT64(env.lsu, SPARCCPU),
153 VMSTATE_UINT64_ARRAY(env.immu.mmuregs, SPARCCPU, 16),
154 VMSTATE_UINT64_ARRAY(env.dmmu.mmuregs, SPARCCPU, 16),
155 VMSTATE_STRUCT_ARRAY(env.itlb, SPARCCPU, 64, 0,
156 vmstate_tlb_entry, SparcTLBEntry),
157 VMSTATE_STRUCT_ARRAY(env.dtlb, SPARCCPU, 64, 0,
158 vmstate_tlb_entry, SparcTLBEntry),
159 VMSTATE_UINT32(env.mmu_version, SPARCCPU),
160 VMSTATE_STRUCT_ARRAY(env.ts, SPARCCPU, MAXTL_MAX, 0,
161 vmstate_trap_state, trap_state),
162 VMSTATE_UINT32(env.xcc, SPARCCPU),
163 VMSTATE_UINT32(env.asi, SPARCCPU),
164 VMSTATE_UINT32(env.pstate, SPARCCPU),
165 VMSTATE_UINT32(env.tl, SPARCCPU),
166 VMSTATE_UINT32(env.cansave, SPARCCPU),
167 VMSTATE_UINT32(env.canrestore, SPARCCPU),
168 VMSTATE_UINT32(env.otherwin, SPARCCPU),
169 VMSTATE_UINT32(env.wstate, SPARCCPU),
170 VMSTATE_UINT32(env.cleanwin, SPARCCPU),
171 VMSTATE_UINT64_ARRAY(env.agregs, SPARCCPU, 8),
172 VMSTATE_UINT64_ARRAY(env.bgregs, SPARCCPU, 8),
173 VMSTATE_UINT64_ARRAY(env.igregs, SPARCCPU, 8),
174 VMSTATE_UINT64_ARRAY(env.mgregs, SPARCCPU, 8),
175 VMSTATE_UINT64(env.fprs, SPARCCPU),
176 VMSTATE_UINT64(env.tick_cmpr, SPARCCPU),
177 VMSTATE_UINT64(env.stick_cmpr, SPARCCPU),
178 VMSTATE_CPU_TIMER(env.tick, SPARCCPU),
179 VMSTATE_CPU_TIMER(env.stick, SPARCCPU),
180 VMSTATE_UINT64(env.gsr, SPARCCPU),
181 VMSTATE_UINT32(env.gl, SPARCCPU),
182 VMSTATE_UINT64(env.hpstate, SPARCCPU),
183 VMSTATE_UINT64_ARRAY(env.htstate, SPARCCPU, MAXTL_MAX),
184 VMSTATE_UINT64(env.hintp, SPARCCPU),
185 VMSTATE_UINT64(env.htba, SPARCCPU),
186 VMSTATE_UINT64(env.hver, SPARCCPU),
187 VMSTATE_UINT64(env.hstick_cmpr, SPARCCPU),
188 VMSTATE_UINT64(env.ssr, SPARCCPU),
189 VMSTATE_CPU_TIMER(env.hstick, SPARCCPU),
190
191 VMSTATE_UINT32(env.psrpil, SPARCCPU),
192 VMSTATE_UINT32(env.cwp, SPARCCPU),
193#endif
194 VMSTATE_END_OF_LIST()
195 },
196};
197