| ... | @@ -519,38 +519,21 @@ fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf { | ... | @@ -519,38 +519,21 @@ fn cpuid(leaf_id: u32, subid: u32) CpuidLeaf { |
| 519 | // Inline assembly in zig only supports one output, | 519 | // Inline assembly in zig only supports one output, |
| 520 | // so we pass a pointer to the struct. | 520 | // so we pass a pointer to the struct. |
| 521 | var cpuid_leaf = CpuidLeaf{ .eax = 0, .ebx = 0, .ecx = 0, .edx = 0 }; | 521 | var cpuid_leaf = CpuidLeaf{ .eax = 0, .ebx = 0, .ecx = 0, .edx = 0 }; |
| 522 | var leaf_ptr = &cpuid_leaf; | 522 | const leaf_ptr = &cpuid_leaf; |
| 523 | switch (Target.current.cpu.arch) { | 523 | |
| 524 | .i386 => { | 524 | // valid for both x86 and x86_64 |
| 525 | _ = asm volatile ( | 525 | asm volatile ( |
| 526 | \\ cpuid | 526 | \\ cpuid |
| 527 | \\ movl %%eax, (%%edi) | 527 | \\ movl %%eax, (%[leaf_ptr]) |
| 528 | \\ movl %%ebx, 4(%%edi) | 528 | \\ movl %%ebx, 4(%[leaf_ptr]) |
| 529 | \\ movl %%ecx, 8(%%edi) | 529 | \\ movl %%ecx, 8(%[leaf_ptr]) |
| 530 | \\ movl %%edx, 12(%%edi) | 530 | \\ movl %%edx, 12(%[leaf_ptr]) |
| 531 | : | 531 | : |
| 532 | : [leaf_id] "{eax}" (leaf_id), | 532 | : [leaf_id] "{eax}" (leaf_id), |
| 533 | [subid] "{ecx}" (subid), | 533 | [subid] "{ecx}" (subid), |
| 534 | [leaf_ptr] "{edi}" (leaf_ptr) | 534 | [leaf_ptr] "r" (leaf_ptr) |
| 535 | : "eax", "ebx", "ecx", "edx" | 535 | : "eax", "ebx", "ecx", "edx" |
| 536 | ); | 536 | ); |
| 537 | }, | | |
| 538 | .x86_64 => { | | |
| 539 | _ = asm volatile ( | | |
| 540 | \\ cpuid | | |
| 541 | \\ movl %%eax, (%%rdi) | | |
| 542 | \\ movl %%ebx, 4(%%rdi) | | |
| 543 | \\ movl %%ecx, 8(%%rdi) | | |
| 544 | \\ movl %%edx, 12(%%rdi) | | |
| 545 | : | | |
| 546 | : [leaf_id] "{eax}" (leaf_id), | | |
| 547 | [subid] "{ecx}" (subid), | | |
| 548 | [leaf_ptr] "{rdi}" (leaf_ptr) | | |
| 549 | : "eax", "ebx", "ecx", "edx" | | |
| 550 | ); | | |
| 551 | }, | | |
| 552 | else => unreachable, | | |
| 553 | } | | |
| 554 | return cpuid_leaf; | 537 | return cpuid_leaf; |
| 555 | } | 538 | } |
| 556 | | 539 | |