9 void register_machines(void)
11 qemu_register_machine(&pc_machine
);
12 qemu_register_machine(&isapc_machine
);
15 static void cpu_put_seg(QEMUFile
*f
, SegmentCache
*dt
)
17 qemu_put_be32(f
, dt
->selector
);
18 qemu_put_betl(f
, dt
->base
);
19 qemu_put_be32(f
, dt
->limit
);
20 qemu_put_be32(f
, dt
->flags
);
23 static void cpu_get_seg(QEMUFile
*f
, SegmentCache
*dt
)
25 dt
->selector
= qemu_get_be32(f
);
26 dt
->base
= qemu_get_betl(f
);
27 dt
->limit
= qemu_get_be32(f
);
28 dt
->flags
= qemu_get_be32(f
);
31 void cpu_save(QEMUFile
*f
, void *opaque
)
33 CPUState
*env
= opaque
;
34 uint16_t fptag
, fpus
, fpuc
, fpregs_format
;
40 kvm_save_registers(env
);
41 kvm_save_mpstate(env
);
44 for(i
= 0; i
< CPU_NB_REGS
; i
++)
45 qemu_put_betls(f
, &env
->regs
[i
]);
46 qemu_put_betls(f
, &env
->eip
);
47 qemu_put_betls(f
, &env
->eflags
);
48 hflags
= env
->hflags
; /* XXX: suppress most of the redundant hflags */
49 qemu_put_be32s(f
, &hflags
);
53 fpus
= (env
->fpus
& ~0x3800) | (env
->fpstt
& 0x7) << 11;
55 for(i
= 0; i
< 8; i
++) {
56 fptag
|= ((!env
->fptags
[i
]) << i
);
59 qemu_put_be16s(f
, &fpuc
);
60 qemu_put_be16s(f
, &fpus
);
61 qemu_put_be16s(f
, &fptag
);
68 qemu_put_be16s(f
, &fpregs_format
);
70 for(i
= 0; i
< 8; i
++) {
75 /* we save the real CPU data (in case of MMX usage only 'mant'
76 contains the MMX register */
77 cpu_get_fp80(&mant
, &exp
, env
->fpregs
[i
].d
);
78 qemu_put_be64(f
, mant
);
79 qemu_put_be16(f
, exp
);
82 /* if we use doubles for float emulation, we save the doubles to
83 avoid losing information in case of MMX usage. It can give
84 problems if the image is restored on a CPU where long
85 doubles are used instead. */
86 qemu_put_be64(f
, env
->fpregs
[i
].mmx
.MMX_Q(0));
90 for(i
= 0; i
< 6; i
++)
91 cpu_put_seg(f
, &env
->segs
[i
]);
92 cpu_put_seg(f
, &env
->ldt
);
93 cpu_put_seg(f
, &env
->tr
);
94 cpu_put_seg(f
, &env
->gdt
);
95 cpu_put_seg(f
, &env
->idt
);
97 qemu_put_be32s(f
, &env
->sysenter_cs
);
98 qemu_put_be32s(f
, &env
->sysenter_esp
);
99 qemu_put_be32s(f
, &env
->sysenter_eip
);
101 qemu_put_betls(f
, &env
->cr
[0]);
102 qemu_put_betls(f
, &env
->cr
[2]);
103 qemu_put_betls(f
, &env
->cr
[3]);
104 qemu_put_betls(f
, &env
->cr
[4]);
106 for(i
= 0; i
< 8; i
++)
107 qemu_put_betls(f
, &env
->dr
[i
]);
110 a20_mask
= (int32_t) env
->a20_mask
;
111 qemu_put_be32s(f
, &a20_mask
);
114 qemu_put_be32s(f
, &env
->mxcsr
);
115 for(i
= 0; i
< CPU_NB_REGS
; i
++) {
116 qemu_put_be64s(f
, &env
->xmm_regs
[i
].XMM_Q(0));
117 qemu_put_be64s(f
, &env
->xmm_regs
[i
].XMM_Q(1));
121 qemu_put_be64s(f
, &env
->efer
);
122 qemu_put_be64s(f
, &env
->star
);
123 qemu_put_be64s(f
, &env
->lstar
);
124 qemu_put_be64s(f
, &env
->cstar
);
125 qemu_put_be64s(f
, &env
->fmask
);
126 qemu_put_be64s(f
, &env
->kernelgsbase
);
128 qemu_put_be32s(f
, &env
->smbase
);
131 for (i
= 0; i
< NR_IRQ_WORDS
; i
++) {
132 qemu_put_be32s(f
, &env
->kvm_interrupt_bitmap
[i
]);
134 qemu_put_be64s(f
, &env
->tsc
);
135 qemu_put_be32s(f
, &env
->mp_state
);
139 #ifdef USE_X86LDOUBLE
140 /* XXX: add that in a FPU generic layer */
141 union x86_longdouble
{
146 #define MANTD1(fp) (fp & ((1LL << 52) - 1))
147 #define EXPBIAS1 1023
148 #define EXPD1(fp) ((fp >> 52) & 0x7FF)
149 #define SIGND1(fp) ((fp >> 32) & 0x80000000)
151 static void fp64_to_fp80(union x86_longdouble
*p
, uint64_t temp
)
155 p
->mant
= (MANTD1(temp
) << 11) | (1LL << 63);
156 /* exponent + sign */
157 e
= EXPD1(temp
) - EXPBIAS1
+ 16383;
158 e
|= SIGND1(temp
) >> 16;
163 int cpu_load(QEMUFile
*f
, void *opaque
, int version_id
)
165 CPUState
*env
= opaque
;
168 uint16_t fpus
, fpuc
, fptag
, fpregs_format
;
171 if (version_id
< 3 || version_id
> 5)
173 for(i
= 0; i
< CPU_NB_REGS
; i
++)
174 qemu_get_betls(f
, &env
->regs
[i
]);
175 qemu_get_betls(f
, &env
->eip
);
176 qemu_get_betls(f
, &env
->eflags
);
177 qemu_get_be32s(f
, &hflags
);
179 qemu_get_be16s(f
, &fpuc
);
180 qemu_get_be16s(f
, &fpus
);
181 qemu_get_be16s(f
, &fptag
);
182 qemu_get_be16s(f
, &fpregs_format
);
184 /* NOTE: we cannot always restore the FPU state if the image come
185 from a host with a different 'USE_X86LDOUBLE' define. We guess
186 if we are in an MMX state to restore correctly in that case. */
187 guess_mmx
= ((fptag
== 0xff) && (fpus
& 0x3800) == 0);
188 for(i
= 0; i
< 8; i
++) {
192 switch(fpregs_format
) {
194 mant
= qemu_get_be64(f
);
195 exp
= qemu_get_be16(f
);
196 #ifdef USE_X86LDOUBLE
197 env
->fpregs
[i
].d
= cpu_set_fp80(mant
, exp
);
201 env
->fpregs
[i
].mmx
.MMX_Q(0) = mant
;
203 env
->fpregs
[i
].d
= cpu_set_fp80(mant
, exp
);
207 mant
= qemu_get_be64(f
);
208 #ifdef USE_X86LDOUBLE
210 union x86_longdouble
*p
;
212 p
= (void *)&env
->fpregs
[i
];
217 fp64_to_fp80(p
, mant
);
221 env
->fpregs
[i
].mmx
.MMX_Q(0) = mant
;
230 /* XXX: restore FPU round state */
231 env
->fpstt
= (fpus
>> 11) & 7;
232 env
->fpus
= fpus
& ~0x3800;
234 for(i
= 0; i
< 8; i
++) {
235 env
->fptags
[i
] = (fptag
>> i
) & 1;
238 for(i
= 0; i
< 6; i
++)
239 cpu_get_seg(f
, &env
->segs
[i
]);
240 cpu_get_seg(f
, &env
->ldt
);
241 cpu_get_seg(f
, &env
->tr
);
242 cpu_get_seg(f
, &env
->gdt
);
243 cpu_get_seg(f
, &env
->idt
);
245 qemu_get_be32s(f
, &env
->sysenter_cs
);
246 qemu_get_be32s(f
, &env
->sysenter_esp
);
247 qemu_get_be32s(f
, &env
->sysenter_eip
);
249 qemu_get_betls(f
, &env
->cr
[0]);
250 qemu_get_betls(f
, &env
->cr
[2]);
251 qemu_get_betls(f
, &env
->cr
[3]);
252 qemu_get_betls(f
, &env
->cr
[4]);
254 for(i
= 0; i
< 8; i
++)
255 qemu_get_betls(f
, &env
->dr
[i
]);
258 qemu_get_be32s(f
, &a20_mask
);
259 env
->a20_mask
= a20_mask
;
261 qemu_get_be32s(f
, &env
->mxcsr
);
262 for(i
= 0; i
< CPU_NB_REGS
; i
++) {
263 qemu_get_be64s(f
, &env
->xmm_regs
[i
].XMM_Q(0));
264 qemu_get_be64s(f
, &env
->xmm_regs
[i
].XMM_Q(1));
268 qemu_get_be64s(f
, &env
->efer
);
269 qemu_get_be64s(f
, &env
->star
);
270 qemu_get_be64s(f
, &env
->lstar
);
271 qemu_get_be64s(f
, &env
->cstar
);
272 qemu_get_be64s(f
, &env
->fmask
);
273 qemu_get_be64s(f
, &env
->kernelgsbase
);
276 qemu_get_be32s(f
, &env
->smbase
);
278 /* XXX: compute hflags from scratch, except for CPL and IIF */
279 env
->hflags
= hflags
;
282 /* when in-kernel irqchip is used, HF_HALTED_MASK causes deadlock
283 because no userspace IRQs will ever clear this flag */
284 env
->hflags
&= ~HF_HALTED_MASK
;
285 for (i
= 0; i
< NR_IRQ_WORDS
; i
++) {
286 qemu_get_be32s(f
, &env
->kvm_interrupt_bitmap
[i
]);
288 qemu_get_be64s(f
, &env
->tsc
);
289 kvm_load_registers(env
);
290 if (version_id
>= 5) {
291 qemu_get_be32s(f
, &env
->mp_state
);
292 kvm_load_mpstate(env
);