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