raz / commit 94283193

commit
942831934dfff9d4c8dd3d86a13fb454d7f2d09f
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
5d91876d
Assembler: push of a constant, cld and std

patch · log

4 files changed, +41 -9

doc/compiler.md (history) modified +1 -1

@@ -1175,7 +1175,7 @@
11751175 `BitOps` the bit scans and counts: `bsf`, `bsr`, `tzcnt`, `lzcnt`,
11761176 `popcnt`). A kernel's instructions are there too, though the code
11771177 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
11791179 `xrstor`, of one memory operand, in `MemOps`; `ltr` of a 16-bit
11801180 register; `mov` to and from `cr0`, `cr2`, `cr3`, `cr4` and `cr8` (an
11811181 operand of its own kind, `oCr`); and `in` and `out`, of `al`, `ax` or

src/X64.raz (history) modified +16 -5

@@ -1141,13 +1141,13 @@
11411141 BitOps = " bsf bsr tzcnt lzcnt popcnt ";
11421142 BitPfx: [5]INT = [0, 0, 0F3H, 0F3H, 0F3H];
11431143 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",
11461146 "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,
11491149 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];
11511151 (* the privileged instructions of one memory operand, 0F 01 /digit
11521152 but for xsave and xrstor, 0F AE /digit *)
11531153 MemOps = " lgdt lidt invlpg xsave xrstor ";
@@ -1317,6 +1317,17 @@
13171317 return bad();
13181318 end;
13191319 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;
13201331 if (an # 1) or (ao[0].kind # oReg) or not awide then return bad(); end;
13211332 if aw = "push" then push(ao[0].r); else pop(ao[0].r); end;
13221333 elsif (aw = "call") or (aw = "jmp") then

test/run/AsmKernel.expect (history) modified +9 -0

@@ -34,3 +34,12 @@
3434 out dx, al: EE
3535 out dx, ax: 66 EF
3636 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

test/run/AsmKernel.raz (history) modified +15 -3

@@ -6,7 +6,7 @@
66 import SYSTEM;
77
88 const
9- Count = 36;
9+ Count = 45;
1010 Names: [Count][]const U8 = ["cli", "sti", "iretq", "swapgs",
1111 "rdmsr", "wrmsr", "wbinvd", "lgdt [rdi]",
1212 "lidt [rsi + 8]", "invlpg [rax]", "invlpg [r12 + rcx * 8 + 400]", "xsave [rdi]",
@@ -15,10 +15,13 @@
1515 "mov cr8, r11", "mov rax, cr0", "mov r9, cr3", "mov rbx, cr8",
1616 "in al, 60H", "in ax, 61H", "in eax, 0FFH", "in al, dx",
1717 "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"];
1921 Sizes: [Count]INT = [1, 1, 2, 3, 2, 2, 2, 3, 4, 3, 9, 3,
2022 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];
2225
2326 proc kernel;
2427 code
@@ -58,6 +61,15 @@
5861 out dx, al;
5962 out dx, ax;
6063 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;
6173 ret;
6274 end kernel;
6375