4 * Copyright (c) 2003 Fabrice Bellard
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.1 of the License, or (at your option) any later version.
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.
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/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
23 #include "exec/exec-all.h"
24 #include "helper-tcg.h"
27 * NOTE: the translator must set DisasContext.cc_op to CC_OP_EFLAGS
28 * after generating a call to a helper that uses this.
30 void cpu_load_eflags(CPUX86State
*env
, int eflags
, int update_mask
)
32 CC_SRC
= eflags
& (CC_O
| CC_S
| CC_Z
| CC_A
| CC_P
| CC_C
);
34 env
->df
= 1 - (2 * ((eflags
>> 10) & 1));
35 env
->eflags
= (env
->eflags
& ~update_mask
) |
36 (eflags
& update_mask
) | 0x2;
39 void helper_into(CPUX86State
*env
, int next_eip_addend
)
43 eflags
= cpu_cc_compute_all(env
, CC_OP
);
45 raise_interrupt(env
, EXCP04_INTO
, 1, 0, next_eip_addend
);
49 void helper_cpuid(CPUX86State
*env
)
51 uint32_t eax
, ebx
, ecx
, edx
;
53 cpu_svm_check_intercept_param(env
, SVM_EXIT_CPUID
, 0, GETPC());
55 cpu_x86_cpuid(env
, (uint32_t)env
->regs
[R_EAX
], (uint32_t)env
->regs
[R_ECX
],
56 &eax
, &ebx
, &ecx
, &edx
);
57 env
->regs
[R_EAX
] = eax
;
58 env
->regs
[R_EBX
] = ebx
;
59 env
->regs
[R_ECX
] = ecx
;
60 env
->regs
[R_EDX
] = edx
;
63 void helper_rdtsc(CPUX86State
*env
)
67 if ((env
->cr
[4] & CR4_TSD_MASK
) && ((env
->hflags
& HF_CPL_MASK
) != 0)) {
68 raise_exception_ra(env
, EXCP0D_GPF
, GETPC());
70 cpu_svm_check_intercept_param(env
, SVM_EXIT_RDTSC
, 0, GETPC());
72 val
= cpu_get_tsc(env
) + env
->tsc_offset
;
73 env
->regs
[R_EAX
] = (uint32_t)(val
);
74 env
->regs
[R_EDX
] = (uint32_t)(val
>> 32);
77 void helper_rdtscp(CPUX86State
*env
)
80 env
->regs
[R_ECX
] = (uint32_t)(env
->tsc_aux
);
83 void QEMU_NORETURN
helper_rdpmc(CPUX86State
*env
)
85 if (((env
->cr
[4] & CR4_PCE_MASK
) == 0 ) &&
86 ((env
->hflags
& HF_CPL_MASK
) != 0)) {
87 raise_exception_ra(env
, EXCP0D_GPF
, GETPC());
89 cpu_svm_check_intercept_param(env
, SVM_EXIT_RDPMC
, 0, GETPC());
91 /* currently unimplemented */
92 qemu_log_mask(LOG_UNIMP
, "x86: unimplemented rdpmc\n");
93 raise_exception_err(env
, EXCP06_ILLOP
, 0);
96 void QEMU_NORETURN
do_pause(CPUX86State
*env
)
98 CPUState
*cs
= env_cpu(env
);
100 /* Just let another CPU run. */
101 cs
->exception_index
= EXCP_INTERRUPT
;
105 void QEMU_NORETURN
helper_pause(CPUX86State
*env
, int next_eip_addend
)
107 cpu_svm_check_intercept_param(env
, SVM_EXIT_PAUSE
, 0, GETPC());
108 env
->eip
+= next_eip_addend
;
113 void QEMU_NORETURN
helper_debug(CPUX86State
*env
)
115 CPUState
*cs
= env_cpu(env
);
117 cs
->exception_index
= EXCP_DEBUG
;
121 uint64_t helper_rdpkru(CPUX86State
*env
, uint32_t ecx
)
123 if ((env
->cr
[4] & CR4_PKE_MASK
) == 0) {
124 raise_exception_err_ra(env
, EXCP06_ILLOP
, 0, GETPC());
127 raise_exception_err_ra(env
, EXCP0D_GPF
, 0, GETPC());
133 void helper_wrpkru(CPUX86State
*env
, uint32_t ecx
, uint64_t val
)
135 CPUState
*cs
= env_cpu(env
);
137 if ((env
->cr
[4] & CR4_PKE_MASK
) == 0) {
138 raise_exception_err_ra(env
, EXCP06_ILLOP
, 0, GETPC());
140 if (ecx
!= 0 || (val
& 0xFFFFFFFF00000000ull
)) {
141 raise_exception_err_ra(env
, EXCP0D_GPF
, 0, GETPC());