]> Git Repo - qemu.git/blame - target-i386/misc_helper.c
exec: extract exec/tb-context.h
[qemu.git] / target-i386 / misc_helper.c
CommitLineData
f7b2429f
BS
1/*
2 * x86 misc helpers
3 *
4 * Copyright (c) 2003 Fabrice Bellard
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 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
b6a0aa05 20#include "qemu/osdep.h"
f7b2429f 21#include "cpu.h"
2ef6175a 22#include "exec/helper-proto.h"
f08b6170 23#include "exec/cpu_ldst.h"
3f7d8464 24#include "exec/address-spaces.h"
92fc4b58 25
3f7d8464 26void helper_outb(CPUX86State *env, uint32_t port, uint32_t data)
f7b2429f 27{
3f7d8464
PB
28#ifdef CONFIG_USER_ONLY
29 fprintf(stderr, "outb: port=0x%04x, data=%02x\n", port, data);
30#else
31 address_space_stb(&address_space_io, port, data,
32 cpu_get_mem_attrs(env), NULL);
33#endif
f7b2429f
BS
34}
35
3f7d8464 36target_ulong helper_inb(CPUX86State *env, uint32_t port)
f7b2429f 37{
3f7d8464
PB
38#ifdef CONFIG_USER_ONLY
39 fprintf(stderr, "inb: port=0x%04x\n", port);
40 return 0;
41#else
42 return address_space_ldub(&address_space_io, port,
43 cpu_get_mem_attrs(env), NULL);
44#endif
f7b2429f
BS
45}
46
3f7d8464 47void helper_outw(CPUX86State *env, uint32_t port, uint32_t data)
f7b2429f 48{
3f7d8464
PB
49#ifdef CONFIG_USER_ONLY
50 fprintf(stderr, "outw: port=0x%04x, data=%04x\n", port, data);
51#else
52 address_space_stw(&address_space_io, port, data,
53 cpu_get_mem_attrs(env), NULL);
54#endif
f7b2429f
BS
55}
56
3f7d8464 57target_ulong helper_inw(CPUX86State *env, uint32_t port)
f7b2429f 58{
3f7d8464
PB
59#ifdef CONFIG_USER_ONLY
60 fprintf(stderr, "inw: port=0x%04x\n", port);
61 return 0;
62#else
63 return address_space_lduw(&address_space_io, port,
64 cpu_get_mem_attrs(env), NULL);
65#endif
f7b2429f
BS
66}
67
3f7d8464 68void helper_outl(CPUX86State *env, uint32_t port, uint32_t data)
f7b2429f 69{
3f7d8464
PB
70#ifdef CONFIG_USER_ONLY
71 fprintf(stderr, "outw: port=0x%04x, data=%08x\n", port, data);
72#else
73 address_space_stl(&address_space_io, port, data,
74 cpu_get_mem_attrs(env), NULL);
75#endif
f7b2429f
BS
76}
77
3f7d8464 78target_ulong helper_inl(CPUX86State *env, uint32_t port)
f7b2429f 79{
3f7d8464
PB
80#ifdef CONFIG_USER_ONLY
81 fprintf(stderr, "inl: port=0x%04x\n", port);
82 return 0;
83#else
84 return address_space_ldl(&address_space_io, port,
85 cpu_get_mem_attrs(env), NULL);
86#endif
f7b2429f
BS
87}
88
4a7443be 89void helper_into(CPUX86State *env, int next_eip_addend)
f7b2429f
BS
90{
91 int eflags;
92
f0967a1a 93 eflags = cpu_cc_compute_all(env, CC_OP);
f7b2429f
BS
94 if (eflags & CC_O) {
95 raise_interrupt(env, EXCP04_INTO, 1, 0, next_eip_addend);
96 }
97}
98
4a7443be 99void helper_cpuid(CPUX86State *env)
f7b2429f
BS
100{
101 uint32_t eax, ebx, ecx, edx;
102
103 cpu_svm_check_intercept_param(env, SVM_EXIT_CPUID, 0);
104
90a2541b
LG
105 cpu_x86_cpuid(env, (uint32_t)env->regs[R_EAX], (uint32_t)env->regs[R_ECX],
106 &eax, &ebx, &ecx, &edx);
4b34e3ad 107 env->regs[R_EAX] = eax;
70b51365 108 env->regs[R_EBX] = ebx;
a4165610 109 env->regs[R_ECX] = ecx;
00f5e6f2 110 env->regs[R_EDX] = edx;
f7b2429f
BS
111}
112
113#if defined(CONFIG_USER_ONLY)
4a7443be 114target_ulong helper_read_crN(CPUX86State *env, int reg)
f7b2429f
BS
115{
116 return 0;
117}
118
4a7443be 119void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)
f7b2429f
BS
120{
121}
f7b2429f 122#else
4a7443be 123target_ulong helper_read_crN(CPUX86State *env, int reg)
f7b2429f
BS
124{
125 target_ulong val;
126
127 cpu_svm_check_intercept_param(env, SVM_EXIT_READ_CR0 + reg, 0);
128 switch (reg) {
129 default:
130 val = env->cr[reg];
131 break;
132 case 8:
133 if (!(env->hflags2 & HF2_VINTR_MASK)) {
02e51483 134 val = cpu_get_apic_tpr(x86_env_get_cpu(env)->apic_state);
f7b2429f
BS
135 } else {
136 val = env->v_tpr;
137 }
138 break;
139 }
140 return val;
141}
142
4a7443be 143void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)
f7b2429f
BS
144{
145 cpu_svm_check_intercept_param(env, SVM_EXIT_WRITE_CR0 + reg, 0);
146 switch (reg) {
147 case 0:
148 cpu_x86_update_cr0(env, t0);
149 break;
150 case 3:
151 cpu_x86_update_cr3(env, t0);
152 break;
153 case 4:
154 cpu_x86_update_cr4(env, t0);
155 break;
156 case 8:
157 if (!(env->hflags2 & HF2_VINTR_MASK)) {
02e51483 158 cpu_set_apic_tpr(x86_env_get_cpu(env)->apic_state, t0);
f7b2429f
BS
159 }
160 env->v_tpr = t0 & 0x0f;
161 break;
162 default:
163 env->cr[reg] = t0;
164 break;
165 }
166}
f7b2429f
BS
167#endif
168
4a7443be 169void helper_lmsw(CPUX86State *env, target_ulong t0)
f7b2429f
BS
170{
171 /* only 4 lower bits of CR0 are modified. PE cannot be set to zero
172 if already set to one. */
173 t0 = (env->cr[0] & ~0xe) | (t0 & 0xf);
4a7443be 174 helper_write_crN(env, 0, t0);
f7b2429f
BS
175}
176
4a7443be 177void helper_invlpg(CPUX86State *env, target_ulong addr)
f7b2429f 178{
31b030d4
AF
179 X86CPU *cpu = x86_env_get_cpu(env);
180
f7b2429f 181 cpu_svm_check_intercept_param(env, SVM_EXIT_INVLPG, 0);
31b030d4 182 tlb_flush_page(CPU(cpu), addr);
f7b2429f
BS
183}
184
4a7443be 185void helper_rdtsc(CPUX86State *env)
f7b2429f
BS
186{
187 uint64_t val;
188
189 if ((env->cr[4] & CR4_TSD_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
4054cdec 190 raise_exception_ra(env, EXCP0D_GPF, GETPC());
f7b2429f
BS
191 }
192 cpu_svm_check_intercept_param(env, SVM_EXIT_RDTSC, 0);
193
194 val = cpu_get_tsc(env) + env->tsc_offset;
4b34e3ad 195 env->regs[R_EAX] = (uint32_t)(val);
00f5e6f2 196 env->regs[R_EDX] = (uint32_t)(val >> 32);
f7b2429f
BS
197}
198
4a7443be 199void helper_rdtscp(CPUX86State *env)
f7b2429f 200{
4a7443be 201 helper_rdtsc(env);
a4165610 202 env->regs[R_ECX] = (uint32_t)(env->tsc_aux);
f7b2429f
BS
203}
204
4a7443be 205void helper_rdpmc(CPUX86State *env)
f7b2429f
BS
206{
207 if ((env->cr[4] & CR4_PCE_MASK) && ((env->hflags & HF_CPL_MASK) != 0)) {
4054cdec 208 raise_exception_ra(env, EXCP0D_GPF, GETPC());
f7b2429f
BS
209 }
210 cpu_svm_check_intercept_param(env, SVM_EXIT_RDPMC, 0);
211
212 /* currently unimplemented */
213 qemu_log_mask(LOG_UNIMP, "x86: unimplemented rdpmc\n");
214 raise_exception_err(env, EXCP06_ILLOP, 0);
215}
216
217#if defined(CONFIG_USER_ONLY)
4a7443be 218void helper_wrmsr(CPUX86State *env)
f7b2429f
BS
219{
220}
221
4a7443be 222void helper_rdmsr(CPUX86State *env)
f7b2429f
BS
223{
224}
225#else
4a7443be 226void helper_wrmsr(CPUX86State *env)
f7b2429f
BS
227{
228 uint64_t val;
229
230 cpu_svm_check_intercept_param(env, SVM_EXIT_MSR, 1);
231
90a2541b
LG
232 val = ((uint32_t)env->regs[R_EAX]) |
233 ((uint64_t)((uint32_t)env->regs[R_EDX]) << 32);
f7b2429f 234
a4165610 235 switch ((uint32_t)env->regs[R_ECX]) {
f7b2429f
BS
236 case MSR_IA32_SYSENTER_CS:
237 env->sysenter_cs = val & 0xffff;
238 break;
239 case MSR_IA32_SYSENTER_ESP:
240 env->sysenter_esp = val;
241 break;
242 case MSR_IA32_SYSENTER_EIP:
243 env->sysenter_eip = val;
244 break;
245 case MSR_IA32_APICBASE:
02e51483 246 cpu_set_apic_base(x86_env_get_cpu(env)->apic_state, val);
f7b2429f
BS
247 break;
248 case MSR_EFER:
249 {
250 uint64_t update_mask;
251
252 update_mask = 0;
0514ef2f 253 if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_SYSCALL) {
f7b2429f
BS
254 update_mask |= MSR_EFER_SCE;
255 }
0514ef2f 256 if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) {
f7b2429f
BS
257 update_mask |= MSR_EFER_LME;
258 }
0514ef2f 259 if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_FFXSR) {
f7b2429f
BS
260 update_mask |= MSR_EFER_FFXSR;
261 }
0514ef2f 262 if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_NX) {
f7b2429f
BS
263 update_mask |= MSR_EFER_NXE;
264 }
0514ef2f 265 if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_SVM) {
f7b2429f
BS
266 update_mask |= MSR_EFER_SVME;
267 }
0514ef2f 268 if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_FFXSR) {
f7b2429f
BS
269 update_mask |= MSR_EFER_FFXSR;
270 }
271 cpu_load_efer(env, (env->efer & ~update_mask) |
272 (val & update_mask));
273 }
274 break;
275 case MSR_STAR:
276 env->star = val;
277 break;
278 case MSR_PAT:
279 env->pat = val;
280 break;
281 case MSR_VM_HSAVE_PA:
282 env->vm_hsave = val;
283 break;
284#ifdef TARGET_X86_64
285 case MSR_LSTAR:
286 env->lstar = val;
287 break;
288 case MSR_CSTAR:
289 env->cstar = val;
290 break;
291 case MSR_FMASK:
292 env->fmask = val;
293 break;
294 case MSR_FSBASE:
295 env->segs[R_FS].base = val;
296 break;
297 case MSR_GSBASE:
298 env->segs[R_GS].base = val;
299 break;
300 case MSR_KERNELGSBASE:
301 env->kernelgsbase = val;
302 break;
303#endif
304 case MSR_MTRRphysBase(0):
305 case MSR_MTRRphysBase(1):
306 case MSR_MTRRphysBase(2):
307 case MSR_MTRRphysBase(3):
308 case MSR_MTRRphysBase(4):
309 case MSR_MTRRphysBase(5):
310 case MSR_MTRRphysBase(6):
311 case MSR_MTRRphysBase(7):
90a2541b
LG
312 env->mtrr_var[((uint32_t)env->regs[R_ECX] -
313 MSR_MTRRphysBase(0)) / 2].base = val;
f7b2429f
BS
314 break;
315 case MSR_MTRRphysMask(0):
316 case MSR_MTRRphysMask(1):
317 case MSR_MTRRphysMask(2):
318 case MSR_MTRRphysMask(3):
319 case MSR_MTRRphysMask(4):
320 case MSR_MTRRphysMask(5):
321 case MSR_MTRRphysMask(6):
322 case MSR_MTRRphysMask(7):
90a2541b
LG
323 env->mtrr_var[((uint32_t)env->regs[R_ECX] -
324 MSR_MTRRphysMask(0)) / 2].mask = val;
f7b2429f
BS
325 break;
326 case MSR_MTRRfix64K_00000:
90a2541b
LG
327 env->mtrr_fixed[(uint32_t)env->regs[R_ECX] -
328 MSR_MTRRfix64K_00000] = val;
f7b2429f
BS
329 break;
330 case MSR_MTRRfix16K_80000:
331 case MSR_MTRRfix16K_A0000:
90a2541b
LG
332 env->mtrr_fixed[(uint32_t)env->regs[R_ECX] -
333 MSR_MTRRfix16K_80000 + 1] = val;
f7b2429f
BS
334 break;
335 case MSR_MTRRfix4K_C0000:
336 case MSR_MTRRfix4K_C8000:
337 case MSR_MTRRfix4K_D0000:
338 case MSR_MTRRfix4K_D8000:
339 case MSR_MTRRfix4K_E0000:
340 case MSR_MTRRfix4K_E8000:
341 case MSR_MTRRfix4K_F0000:
342 case MSR_MTRRfix4K_F8000:
90a2541b
LG
343 env->mtrr_fixed[(uint32_t)env->regs[R_ECX] -
344 MSR_MTRRfix4K_C0000 + 3] = val;
f7b2429f
BS
345 break;
346 case MSR_MTRRdefType:
347 env->mtrr_deftype = val;
348 break;
349 case MSR_MCG_STATUS:
350 env->mcg_status = val;
351 break;
352 case MSR_MCG_CTL:
353 if ((env->mcg_cap & MCG_CTL_P)
354 && (val == 0 || val == ~(uint64_t)0)) {
355 env->mcg_ctl = val;
356 }
357 break;
358 case MSR_TSC_AUX:
359 env->tsc_aux = val;
360 break;
361 case MSR_IA32_MISC_ENABLE:
362 env->msr_ia32_misc_enable = val;
363 break;
f4f1110e
RH
364 case MSR_IA32_BNDCFGS:
365 /* FIXME: #GP if reserved bits are set. */
366 /* FIXME: Extend highest implemented bit of linear address. */
367 env->msr_bndcfgs = val;
368 cpu_sync_bndcs_hflags(env);
369 break;
f7b2429f 370 default:
a4165610 371 if ((uint32_t)env->regs[R_ECX] >= MSR_MC0_CTL
90a2541b
LG
372 && (uint32_t)env->regs[R_ECX] < MSR_MC0_CTL +
373 (4 * env->mcg_cap & 0xff)) {
a4165610 374 uint32_t offset = (uint32_t)env->regs[R_ECX] - MSR_MC0_CTL;
f7b2429f
BS
375 if ((offset & 0x3) != 0
376 || (val == 0 || val == ~(uint64_t)0)) {
377 env->mce_banks[offset] = val;
378 }
379 break;
380 }
381 /* XXX: exception? */
382 break;
383 }
384}
385
4a7443be 386void helper_rdmsr(CPUX86State *env)
f7b2429f
BS
387{
388 uint64_t val;
389
390 cpu_svm_check_intercept_param(env, SVM_EXIT_MSR, 0);
391
a4165610 392 switch ((uint32_t)env->regs[R_ECX]) {
f7b2429f
BS
393 case MSR_IA32_SYSENTER_CS:
394 val = env->sysenter_cs;
395 break;
396 case MSR_IA32_SYSENTER_ESP:
397 val = env->sysenter_esp;
398 break;
399 case MSR_IA32_SYSENTER_EIP:
400 val = env->sysenter_eip;
401 break;
402 case MSR_IA32_APICBASE:
02e51483 403 val = cpu_get_apic_base(x86_env_get_cpu(env)->apic_state);
f7b2429f
BS
404 break;
405 case MSR_EFER:
406 val = env->efer;
407 break;
408 case MSR_STAR:
409 val = env->star;
410 break;
411 case MSR_PAT:
412 val = env->pat;
413 break;
414 case MSR_VM_HSAVE_PA:
415 val = env->vm_hsave;
416 break;
417 case MSR_IA32_PERF_STATUS:
418 /* tsc_increment_by_tick */
419 val = 1000ULL;
420 /* CPU multiplier */
421 val |= (((uint64_t)4ULL) << 40);
422 break;
423#ifdef TARGET_X86_64
424 case MSR_LSTAR:
425 val = env->lstar;
426 break;
427 case MSR_CSTAR:
428 val = env->cstar;
429 break;
430 case MSR_FMASK:
431 val = env->fmask;
432 break;
433 case MSR_FSBASE:
434 val = env->segs[R_FS].base;
435 break;
436 case MSR_GSBASE:
437 val = env->segs[R_GS].base;
438 break;
439 case MSR_KERNELGSBASE:
440 val = env->kernelgsbase;
441 break;
442 case MSR_TSC_AUX:
443 val = env->tsc_aux;
444 break;
445#endif
446 case MSR_MTRRphysBase(0):
447 case MSR_MTRRphysBase(1):
448 case MSR_MTRRphysBase(2):
449 case MSR_MTRRphysBase(3):
450 case MSR_MTRRphysBase(4):
451 case MSR_MTRRphysBase(5):
452 case MSR_MTRRphysBase(6):
453 case MSR_MTRRphysBase(7):
90a2541b
LG
454 val = env->mtrr_var[((uint32_t)env->regs[R_ECX] -
455 MSR_MTRRphysBase(0)) / 2].base;
f7b2429f
BS
456 break;
457 case MSR_MTRRphysMask(0):
458 case MSR_MTRRphysMask(1):
459 case MSR_MTRRphysMask(2):
460 case MSR_MTRRphysMask(3):
461 case MSR_MTRRphysMask(4):
462 case MSR_MTRRphysMask(5):
463 case MSR_MTRRphysMask(6):
464 case MSR_MTRRphysMask(7):
90a2541b
LG
465 val = env->mtrr_var[((uint32_t)env->regs[R_ECX] -
466 MSR_MTRRphysMask(0)) / 2].mask;
f7b2429f
BS
467 break;
468 case MSR_MTRRfix64K_00000:
469 val = env->mtrr_fixed[0];
470 break;
471 case MSR_MTRRfix16K_80000:
472 case MSR_MTRRfix16K_A0000:
90a2541b
LG
473 val = env->mtrr_fixed[(uint32_t)env->regs[R_ECX] -
474 MSR_MTRRfix16K_80000 + 1];
f7b2429f
BS
475 break;
476 case MSR_MTRRfix4K_C0000:
477 case MSR_MTRRfix4K_C8000:
478 case MSR_MTRRfix4K_D0000:
479 case MSR_MTRRfix4K_D8000:
480 case MSR_MTRRfix4K_E0000:
481 case MSR_MTRRfix4K_E8000:
482 case MSR_MTRRfix4K_F0000:
483 case MSR_MTRRfix4K_F8000:
90a2541b
LG
484 val = env->mtrr_fixed[(uint32_t)env->regs[R_ECX] -
485 MSR_MTRRfix4K_C0000 + 3];
f7b2429f
BS
486 break;
487 case MSR_MTRRdefType:
488 val = env->mtrr_deftype;
489 break;
490 case MSR_MTRRcap:
0514ef2f 491 if (env->features[FEAT_1_EDX] & CPUID_MTRR) {
f7b2429f
BS
492 val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT |
493 MSR_MTRRcap_WC_SUPPORTED;
494 } else {
495 /* XXX: exception? */
496 val = 0;
497 }
498 break;
499 case MSR_MCG_CAP:
500 val = env->mcg_cap;
501 break;
502 case MSR_MCG_CTL:
503 if (env->mcg_cap & MCG_CTL_P) {
504 val = env->mcg_ctl;
505 } else {
506 val = 0;
507 }
508 break;
509 case MSR_MCG_STATUS:
510 val = env->mcg_status;
511 break;
512 case MSR_IA32_MISC_ENABLE:
513 val = env->msr_ia32_misc_enable;
514 break;
f4f1110e
RH
515 case MSR_IA32_BNDCFGS:
516 val = env->msr_bndcfgs;
517 break;
f7b2429f 518 default:
a4165610 519 if ((uint32_t)env->regs[R_ECX] >= MSR_MC0_CTL
90a2541b
LG
520 && (uint32_t)env->regs[R_ECX] < MSR_MC0_CTL +
521 (4 * env->mcg_cap & 0xff)) {
a4165610 522 uint32_t offset = (uint32_t)env->regs[R_ECX] - MSR_MC0_CTL;
f7b2429f
BS
523 val = env->mce_banks[offset];
524 break;
525 }
526 /* XXX: exception? */
527 val = 0;
528 break;
529 }
4b34e3ad 530 env->regs[R_EAX] = (uint32_t)(val);
00f5e6f2 531 env->regs[R_EDX] = (uint32_t)(val >> 32);
f7b2429f
BS
532}
533#endif
534
81f3053b
PB
535static void do_pause(X86CPU *cpu)
536{
27103424 537 CPUState *cs = CPU(cpu);
81f3053b
PB
538
539 /* Just let another CPU run. */
27103424 540 cs->exception_index = EXCP_INTERRUPT;
5638d180 541 cpu_loop_exit(cs);
81f3053b
PB
542}
543
259186a7 544static void do_hlt(X86CPU *cpu)
f7b2429f 545{
259186a7
AF
546 CPUState *cs = CPU(cpu);
547 CPUX86State *env = &cpu->env;
548
f7b2429f 549 env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */
259186a7 550 cs->halted = 1;
27103424 551 cs->exception_index = EXCP_HLT;
5638d180 552 cpu_loop_exit(cs);
f7b2429f
BS
553}
554
4a7443be 555void helper_hlt(CPUX86State *env, int next_eip_addend)
f7b2429f 556{
259186a7
AF
557 X86CPU *cpu = x86_env_get_cpu(env);
558
f7b2429f 559 cpu_svm_check_intercept_param(env, SVM_EXIT_HLT, 0);
a78d0eab 560 env->eip += next_eip_addend;
f7b2429f 561
259186a7 562 do_hlt(cpu);
f7b2429f
BS
563}
564
4a7443be 565void helper_monitor(CPUX86State *env, target_ulong ptr)
f7b2429f 566{
a4165610 567 if ((uint32_t)env->regs[R_ECX] != 0) {
4054cdec 568 raise_exception_ra(env, EXCP0D_GPF, GETPC());
f7b2429f
BS
569 }
570 /* XXX: store address? */
571 cpu_svm_check_intercept_param(env, SVM_EXIT_MONITOR, 0);
572}
573
4a7443be 574void helper_mwait(CPUX86State *env, int next_eip_addend)
f7b2429f 575{
259186a7
AF
576 CPUState *cs;
577 X86CPU *cpu;
55e5c285 578
a4165610 579 if ((uint32_t)env->regs[R_ECX] != 0) {
4054cdec 580 raise_exception_ra(env, EXCP0D_GPF, GETPC());
f7b2429f
BS
581 }
582 cpu_svm_check_intercept_param(env, SVM_EXIT_MWAIT, 0);
a78d0eab 583 env->eip += next_eip_addend;
f7b2429f 584
259186a7
AF
585 cpu = x86_env_get_cpu(env);
586 cs = CPU(cpu);
f7b2429f 587 /* XXX: not complete but not completely erroneous */
bdc44640 588 if (cs->cpu_index != 0 || CPU_NEXT(cs) != NULL) {
81f3053b 589 do_pause(cpu);
f7b2429f 590 } else {
259186a7 591 do_hlt(cpu);
f7b2429f
BS
592 }
593}
594
81f3053b
PB
595void helper_pause(CPUX86State *env, int next_eip_addend)
596{
597 X86CPU *cpu = x86_env_get_cpu(env);
598
599 cpu_svm_check_intercept_param(env, SVM_EXIT_PAUSE, 0);
600 env->eip += next_eip_addend;
601
602 do_pause(cpu);
603}
604
4a7443be 605void helper_debug(CPUX86State *env)
f7b2429f 606{
27103424
AF
607 CPUState *cs = CPU(x86_env_get_cpu(env));
608
609 cs->exception_index = EXCP_DEBUG;
5638d180 610 cpu_loop_exit(cs);
f7b2429f 611}
0f70ed47
PB
612
613uint64_t helper_rdpkru(CPUX86State *env, uint32_t ecx)
614{
615 if ((env->cr[4] & CR4_PKE_MASK) == 0) {
616 raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
617 }
618 if (ecx != 0) {
619 raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC());
620 }
621
622 return env->pkru;
623}
624
625void helper_wrpkru(CPUX86State *env, uint32_t ecx, uint64_t val)
626{
627 CPUState *cs = CPU(x86_env_get_cpu(env));
628
629 if ((env->cr[4] & CR4_PKE_MASK) == 0) {
630 raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
631 }
632 if (ecx != 0 || (val & 0xFFFFFFFF00000000ull)) {
633 raise_exception_err_ra(env, EXCP0D_GPF, 0, GETPC());
634 }
635
636 env->pkru = val;
637 tlb_flush(cs, 1);
638}
This page took 0.353931 seconds and 4 git commands to generate.