Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit 296fa1d

Browse files
authored
Merge pull request #57 from kazumi007/preserve-rbx
Preserve rbx regsiter when cpuid is called.
2 parents 39593a7 + 15baf0b commit 296fa1d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/main.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323

2424
#include <mach-o/dyld.h>
2525

26+
static int
27+
get_cpuid_count (unsigned int leaf,
28+
unsigned int subleaf,
29+
unsigned int *eax, unsigned int *ebx,
30+
unsigned int *ecx, unsigned int *edx)
31+
{
32+
__cpuid_count(leaf, subleaf, *eax, *ebx, *ecx, *edx);
33+
return 1;
34+
}
35+
2636
static bool
2737
is_avx(int instlen, uint64_t rip)
2838
{
@@ -144,8 +154,8 @@ main_loop(int return_on_sigret)
144154
uint64_t xcr0;
145155
vmm_read_register(HV_X86_XCR0, &xcr0);
146156
if ((xcr0 & XCR0_AVX_STATE) == 0) {
147-
uint64_t eax;
148-
asm ("cpuid" : "=a" (eax) : "a" (0x0d), "c" (0));
157+
unsigned int eax, ebx, ecx, edx;
158+
get_cpuid_count(0x0d, 0x0, &eax, &ebx, &ecx, &edx);
149159
if (eax & XCR0_AVX_STATE) {
150160
vmm_write_register(HV_X86_XCR0, xcr0 | XCR0_AVX_STATE);
151161
continue;
@@ -330,8 +340,8 @@ init_regs()
330340
{
331341
/* set up cpu regs */
332342
vmm_write_register(HV_X86_RFLAGS, 0x2);
333-
uint64_t eax;
334-
asm ("cpuid" : "=a" (eax) : "a" (0x0d), "c" (0));
343+
unsigned int eax, ebx, ecx, edx;
344+
get_cpuid_count(0x0d, 0x0, &eax, &ebx, &ecx, &edx);
335345
if (eax & XCR0_SSE_STATE) {
336346
uint64_t xcr0;
337347
vmm_read_register(HV_X86_XCR0, &xcr0);

0 commit comments

Comments
 (0)