Assembler: push of a constant, cld and std
| @@ -1175,7 +1175,7 @@ | ||
| 1175 | 1175 | `BitOps` the bit scans and counts: `bsf`, `bsr`, `tzcnt`, `lzcnt`, |
| 1176 | 1176 | `popcnt`). A kernel's instructions are there too, though the code |
| 1177 | 1177 | generator never makes them: `cli`, `sti`, `iretq`, `swapgs`, `rdmsr`, |
| 1178 | -`wrmsr` and `wbinvd` in `Plain`; `lgdt`, `lidt`, `invlpg`, `xsave` and | |
| 1178 | +`wrmsr`, `wbinvd`, `cld` and `std` in `Plain`; `push` of a constant (6A and a byte when it fits a signed byte, else 68 and four, sign-extended to 64 bits); `lgdt`, `lidt`, `invlpg`, `xsave` and | |
| 1179 | 1179 | `xrstor`, of one memory operand, in `MemOps`; `ltr` of a 16-bit |
| 1180 | 1180 | register; `mov` to and from `cr0`, `cr2`, `cr3`, `cr4` and `cr8` (an |
| 1181 | 1181 | operand of its own kind, `oCr`); and `in` and `out`, of `al`, `ax` or |
| @@ -1141,13 +1141,13 @@ | ||
| 1141 | 1141 | BitOps = " bsf bsr tzcnt lzcnt popcnt "; |
| 1142 | 1142 | BitPfx: [5]INT = [0, 0, 0F3H, 0F3H, 0F3H]; |
| 1143 | 1143 | BitCodes: [5]INT = [0BC0FH, 0BD0FH, 0BC0FH, 0BD0FH, 0B80FH]; |
| 1144 | - (* the instructions of no operands; the last seven are a kernel's *) | |
| 1145 | - Plain: [22][]const U8 = ["ret", "leave", "syscall", "cpuid", "rdtsc", | |
| 1144 | + (* the instructions of no operands; the last nine are a kernel's *) | |
| 1145 | + Plain: [24][]const U8 = ["ret", "leave", "syscall", "cpuid", "rdtsc", | |
| 1146 | 1146 | "pause", "nop", "ud2", "int3", "hlt", "cqo", "cdq", "mfence", "lfence", "sfence", |
| 1147 | - "cli", "sti", "iretq", "swapgs", "rdmsr", "wrmsr", "wbinvd"]; | |
| 1148 | - PlainOp: [22]INT = [0C3H, 0C9H, 050FH, 0A20FH, 310FH, | |
| 1147 | + "cli", "sti", "iretq", "swapgs", "rdmsr", "wrmsr", "wbinvd", "cld", "std"]; | |
| 1148 | + PlainOp: [24]INT = [0C3H, 0C9H, 050FH, 0A20FH, 310FH, | |
| 1149 | 1149 | 90F3H, 90H, 0B0FH, 0CCH, 0F4H, 9948H, 99H, 0F0AE0FH, 0E8AE0FH, 0F8AE0FH, |
| 1150 | - 0FAH, 0FBH, 0CF48H, 0F8010FH, 320FH, 300FH, 090FH]; | |
| 1150 | + 0FAH, 0FBH, 0CF48H, 0F8010FH, 320FH, 300FH, 090FH, 0FCH, 0FDH]; | |
| 1151 | 1151 | (* the privileged instructions of one memory operand, 0F 01 /digit |
| 1152 | 1152 | but for xsave and xrstor, 0F AE /digit *) |
| 1153 | 1153 | MemOps = " lgdt lidt invlpg xsave xrstor "; |
| @@ -1317,6 +1317,17 @@ | ||
| 1317 | 1317 | return bad(); |
| 1318 | 1318 | end; |
| 1319 | 1319 | elsif (aw = "push") or (aw = "pop") then |
| 1320 | + if (aw = "push") and (an = 1) and (ao[0].kind = oImm) then | |
| 1321 | + (* a constant, sign-extended to 64 bits: 6A and a byte if it fits | |
| 1322 | + one, else 68 and four bytes *) | |
| 1323 | + if (ao[0].v < -80000000H) or (ao[0].v > 7FFFFFFFH) then return bad(); end; | |
| 1324 | + if (ao[0].v >= -128) and (ao[0].v <= 127) then | |
| 1325 | + Chunk.put1(6AH); Chunk.put1(INT(ao[0].v & 0FFH)); | |
| 1326 | + else | |
| 1327 | + Chunk.put1(68H); Chunk.put4(INT(ao[0].v & 0FFFFFFFFH)); | |
| 1328 | + end; | |
| 1329 | + return nil; | |
| 1330 | + end; | |
| 1320 | 1331 | if (an # 1) or (ao[0].kind # oReg) or not awide then return bad(); end; |
| 1321 | 1332 | if aw = "push" then push(ao[0].r); else pop(ao[0].r); end; |
| 1322 | 1333 | elsif (aw = "call") or (aw = "jmp") then |
| @@ -34,3 +34,12 @@ | ||
| 34 | 34 | out dx, al: EE |
| 35 | 35 | out dx, ax: 66 EF |
| 36 | 36 | out dx, eax: EF |
| 37 | +push 0: 6A 00 | |
| 38 | +push 127: 6A 7F | |
| 39 | +push -128: 6A 80 | |
| 40 | +push 128: 68 80 00 00 00 | |
| 41 | +push -129: 68 7F FF FF FF | |
| 42 | +push 7FFFFFFFH: 68 FF FF FF 7F | |
| 43 | +push -80000000H: 68 00 00 00 80 | |
| 44 | +cld: FC | |
| 45 | +std: FD |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | import SYSTEM; |
| 7 | 7 | |
| 8 | 8 | const |
| 9 | - Count = 36; | |
| 9 | + Count = 45; | |
| 10 | 10 | Names: [Count][]const U8 = ["cli", "sti", "iretq", "swapgs", |
| 11 | 11 | "rdmsr", "wrmsr", "wbinvd", "lgdt [rdi]", |
| 12 | 12 | "lidt [rsi + 8]", "invlpg [rax]", "invlpg [r12 + rcx * 8 + 400]", "xsave [rdi]", |
| @@ -15,10 +15,13 @@ | ||
| 15 | 15 | "mov cr8, r11", "mov rax, cr0", "mov r9, cr3", "mov rbx, cr8", |
| 16 | 16 | "in al, 60H", "in ax, 61H", "in eax, 0FFH", "in al, dx", |
| 17 | 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"]; | |
| 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"]; | |
| 19 | 21 | Sizes: [Count]INT = [1, 1, 2, 3, 2, 2, 2, 3, 4, 3, 9, 3, |
| 20 | 22 | 4, 3, 4, 3, 3, 4, 3, 4, 4, 3, 4, 4, |
| 21 | - 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1]; | |
| 23 | + 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, | |
| 24 | + 2, 2, 2, 5, 5, 5, 5, 1, 1]; | |
| 22 | 25 | |
| 23 | 26 | proc kernel; |
| 24 | 27 | code |
| @@ -58,6 +61,15 @@ | ||
| 58 | 61 | out dx, al; |
| 59 | 62 | out dx, ax; |
| 60 | 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; | |
| 61 | 73 | ret; |
| 62 | 74 | end kernel; |
| 63 | 75 |