| 1 | module AsmKernel; |
| 2 | (* A kernel's instructions in the assembler: each one's bytes, read |
| 3 | back from the procedure they are made in, since they can't run in |
| 4 | user mode. Each was checked against GNU as. *) |
| 5 | import Out; |
| 6 | import SYSTEM; |
| 7 | |
| 8 | const |
| 9 | Count = 45; |
| 10 | Names: [Count][]const U8 = ["cli", "sti", "iretq", "swapgs", |
| 11 | "rdmsr", "wrmsr", "wbinvd", "lgdt [rdi]", |
| 12 | "lidt [rsi + 8]", "invlpg [rax]", "invlpg [r12 + rcx * 8 + 400]", "xsave [rdi]", |
| 13 | "xrstor [r9]", "ltr ax", "ltr r10w", "mov cr0, rax", |
| 14 | "mov cr2, rdx", "mov cr3, r15", "mov cr4, rcx", "mov cr8, rax", |
| 15 | "mov cr8, r11", "mov rax, cr0", "mov r9, cr3", "mov rbx, cr8", |
| 16 | "in al, 60H", "in ax, 61H", "in eax, 0FFH", "in al, dx", |
| 17 | "in ax, dx", "in eax, dx", "out 80H, al", "out 80H, ax", |
| 18 | "out 0, eax", "out dx, al", "out dx, ax", "out dx, eax", |
| 19 | "push 0", "push 127", "push -128", "push 128", "push -129", |
| 20 | "push 7FFFFFFFH", "push -80000000H", "cld", "std"]; |
| 21 | Sizes: [Count]INT = [1, 1, 2, 3, 2, 2, 2, 3, 4, 3, 9, 3, |
| 22 | 4, 3, 4, 3, 3, 4, 3, 4, 4, 3, 4, 4, |
| 23 | 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, |
| 24 | 2, 2, 2, 5, 5, 5, 5, 1, 1]; |
| 25 | |
| 26 | proc kernel; |
| 27 | code |
| 28 | cli; |
| 29 | sti; |
| 30 | iretq; |
| 31 | swapgs; |
| 32 | rdmsr; |
| 33 | wrmsr; |
| 34 | wbinvd; |
| 35 | lgdt [rdi]; |
| 36 | lidt [rsi + 8]; |
| 37 | invlpg [rax]; |
| 38 | invlpg [r12 + rcx * 8 + 400]; |
| 39 | xsave [rdi]; |
| 40 | xrstor [r9]; |
| 41 | ltr ax; |
| 42 | ltr r10w; |
| 43 | mov cr0, rax; |
| 44 | mov cr2, rdx; |
| 45 | mov cr3, r15; |
| 46 | mov cr4, rcx; |
| 47 | mov cr8, rax; |
| 48 | mov cr8, r11; |
| 49 | mov rax, cr0; |
| 50 | mov r9, cr3; |
| 51 | mov rbx, cr8; |
| 52 | in al, 60H; |
| 53 | in ax, 61H; |
| 54 | in eax, 0FFH; |
| 55 | in al, dx; |
| 56 | in ax, dx; |
| 57 | in eax, dx; |
| 58 | out 80H, al; |
| 59 | out 80H, ax; |
| 60 | out 0, eax; |
| 61 | out dx, al; |
| 62 | out dx, ax; |
| 63 | out dx, eax; |
| 64 | push 0; |
| 65 | push 127; |
| 66 | push -128; |
| 67 | push 128; |
| 68 | push -129; |
| 69 | push 7FFFFFFFH; |
| 70 | push -80000000H; |
| 71 | cld; |
| 72 | std; |
| 73 | ret; |
| 74 | end kernel; |
| 75 | |
| 76 | proc main*; |
| 77 | var p: proc; b: ^U8; i, j, at: INT; |
| 78 | begin |
| 79 | p := kernel; |
| 80 | b := ^U8(p); |
| 81 | at := 0; |
| 82 | for i := 0 to Count - 1 do |
| 83 | Out.str(Names[i]); Out.str(":"); |
| 84 | for j := 0 to Sizes[i] - 1 do |
| 85 | Out.str(" "); Out.hex(U64(b[at + j]), 2); |
| 86 | end; |
| 87 | Out.ln; |
| 88 | at := at + Sizes[i]; |
| 89 | end; |
| 90 | end; |
| 91 | |
| 92 | end AsmKernel. |