| 1 | (* A code procedure: machine code written as bytes, called like any |
| 2 | other procedure. cpuid's vendor string, from leaf 0. *) |
| 3 | module Cpu; |
| 4 | import Out; |
| 5 | import SYSTEM; |
| 6 | |
| 7 | (* cpuid leaf 0: puts the 12 bytes of the vendor in buf, rdi. *) |
| 8 | proc vendor(buf: ^U8); |
| 9 | code |
| 10 | push rbx; |
| 11 | mov r8, rdi; |
| 12 | xor eax, eax; |
| 13 | cpuid; |
| 14 | mov [r8], ebx; |
| 15 | mov [r8 + 4], edx; |
| 16 | mov [r8 + 8], ecx; |
| 17 | pop rbx; |
| 18 | ret; |
| 19 | end vendor; |
| 20 | |
| 21 | proc main*; |
| 22 | var buf: [12]U8; i: INT; ok: BOOL; |
| 23 | begin |
| 24 | vendor(SYSTEM.ADR(buf[0])); |
| 25 | ok := true; |
| 26 | for i := 0 to 11 do |
| 27 | if (buf[i] < ' ') or (buf[i] > '~') then ok := false; end; |
| 28 | end; |
| 29 | if ok then Out.str("vendor is printable\n"); end; |
| 30 | end; |
| 31 | |
| 32 | end Cpu. |