2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
|
|
|
|
2023-01-21 15:34:25 +01:00
|
|
|
Copyright (c) 2018-2023, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE AMD64;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IMPORT IL, BIN, WR := WRITER, CHL := CHUNKLISTS, LISTS, PATHS, PROG, TARGETS,
|
2020-10-13 09:58:51 +02:00
|
|
|
REG, UTILS, S := STRINGS, PE32, ELF, X86, ERRORS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
rax = REG.R0;
|
|
|
|
r10 = REG.R10;
|
|
|
|
r11 = REG.R11;
|
|
|
|
|
|
|
|
rcx = REG.R1;
|
|
|
|
rdx = REG.R2;
|
2020-10-13 09:58:51 +02:00
|
|
|
r8 = REG.R8;
|
|
|
|
r9 = REG.R9;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
rsp = 4;
|
|
|
|
rbp = 5;
|
|
|
|
rsi = 6;
|
|
|
|
rdi = 7;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
MAX_XMM = 5;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
je = 84H; jne = 85H; jl = 8CH; jge = 8DH; jle = 8EH; jg = 8FH; jb = 82H;
|
|
|
|
|
|
|
|
sete = 94H; setne = 95H; setl = 9CH; setge = 9DH; setle = 9EH; setg = 9FH; setc = 92H; setnc = 93H;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
shl = IL.opLSL2; shr = IL.opLSR2; sar = IL.opASR2; ror = IL.opROR2;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
sCODE = BIN.PICCODE;
|
|
|
|
sDATA = BIN.PICDATA;
|
|
|
|
sBSS = BIN.PICBSS;
|
|
|
|
sIMP = BIN.PICIMP;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
FPR_ERR = 41;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
COMMAND = IL.COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
Number = POINTER TO RECORD (LISTS.ITEM) value: INTEGER END;
|
|
|
|
|
|
|
|
OPRR = PROCEDURE (reg1, reg2: INTEGER);
|
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
|
|
|
R: REG.REGS;
|
|
|
|
|
|
|
|
Numbers: LISTS.LIST;
|
|
|
|
Numbers_Count: INTEGER;
|
|
|
|
Numbers_Offs: INTEGER;
|
|
|
|
|
|
|
|
prog: BIN.PROGRAM;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
tcount: INTEGER;
|
|
|
|
|
|
|
|
dllret, sofinit: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
Win64RegPar: ARRAY 4 OF INTEGER;
|
|
|
|
SystemVRegPar: ARRAY 6 OF INTEGER;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
Xmm: ARRAY 1000 OF INTEGER;
|
|
|
|
|
|
|
|
fname: PATHS.PATH;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE OutByte (b: BYTE);
|
|
|
|
BEGIN
|
|
|
|
X86.OutByte(b)
|
|
|
|
END OutByte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutByte2 (a, b: BYTE);
|
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.OutByte(a);
|
|
|
|
X86.OutByte(b)
|
2019-03-11 09:59:55 +01:00
|
|
|
END OutByte2;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutByte3 (a, b, c: BYTE);
|
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.OutByte(a);
|
|
|
|
X86.OutByte(b);
|
|
|
|
X86.OutByte(c)
|
2019-03-11 09:59:55 +01:00
|
|
|
END OutByte3;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutInt (n: INTEGER);
|
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.OutByte(n MOD 256);
|
|
|
|
X86.OutByte(UTILS.Byte(n, 1));
|
|
|
|
X86.OutByte(UTILS.Byte(n, 2));
|
|
|
|
X86.OutByte(UTILS.Byte(n, 3))
|
2019-03-11 09:59:55 +01:00
|
|
|
END OutInt;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE short (n: INTEGER): INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN 2 * ORD(X86.isByte(n))
|
2019-03-11 09:59:55 +01:00
|
|
|
END short;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE long (n: INTEGER): INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN 40H * ORD(~X86.isByte(n))
|
2019-03-11 09:59:55 +01:00
|
|
|
END long;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutIntByte (n: INTEGER);
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF X86.isByte(n) THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(n MOD 256)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
OutInt(n)
|
|
|
|
END
|
|
|
|
END OutIntByte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isLong (n: INTEGER): BOOLEAN;
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN (n > UTILS.max32) OR (n < UTILS.min32)
|
2019-03-11 09:59:55 +01:00
|
|
|
END isLong;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE NewNumber (value: INTEGER);
|
|
|
|
VAR
|
|
|
|
number: Number;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
NEW(number);
|
|
|
|
number.value := value;
|
|
|
|
LISTS.push(Numbers, number);
|
|
|
|
INC(Numbers_Count)
|
|
|
|
END NewNumber;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE NewLabel (): INTEGER;
|
|
|
|
BEGIN
|
|
|
|
BIN.NewLabel(prog)
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN IL.NewLabel()
|
2019-03-11 09:59:55 +01:00
|
|
|
END NewLabel;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Rex (reg1, reg2: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
OutByte(48H + reg1 DIV 8 + 4 * (reg2 DIV 8))
|
|
|
|
END Rex;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE lea (reg, offset, section: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Rex(0, reg);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(8DH, 05H + 8 * (reg MOD 8)); (* lea reg, [rip + offset] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
X86.Reloc(section, offset)
|
|
|
|
END lea;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE oprr (op: BYTE; reg1, reg2: INTEGER); (* op reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
Rex(reg1, reg2);
|
|
|
|
OutByte2(op, 0C0H + 8 * (reg2 MOD 8) + reg1 MOD 8)
|
|
|
|
END oprr;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE oprr2 (op1, op2: BYTE; reg1, reg2: INTEGER); (* op reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
Rex(reg1, reg2);
|
|
|
|
OutByte3(op1, op2, 0C0H + 8 * (reg2 MOD 8) + reg1 MOD 8)
|
|
|
|
END oprr2;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE mov (reg1, reg2: INTEGER); (* mov reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(89H, reg1, reg2)
|
|
|
|
END mov;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE xor (reg1, reg2: INTEGER); (* xor reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(31H, reg1, reg2)
|
|
|
|
END xor;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE and (reg1, reg2: INTEGER); (* and reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(21H, reg1, reg2)
|
|
|
|
END and;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE _or (reg1, reg2: INTEGER); (* or reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(09H, reg1, reg2)
|
2020-10-13 09:58:51 +02:00
|
|
|
END _or;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE add (reg1, reg2: INTEGER); (* add reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(01H, reg1, reg2)
|
|
|
|
END add;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE sub (reg1, reg2: INTEGER); (* sub reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(29H, reg1, reg2)
|
|
|
|
END sub;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE xchg (reg1, reg2: INTEGER); (* xchg reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF rax IN {reg1, reg2} THEN
|
|
|
|
Rex(reg1 + reg2, 0);
|
|
|
|
OutByte(90H + (reg1 + reg2) MOD 8)
|
|
|
|
ELSE
|
|
|
|
oprr(87H, reg1, reg2)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END xchg;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE cmprr (reg1, reg2: INTEGER); (* cmp reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(39H, reg1, reg2)
|
|
|
|
END cmprr;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE pop (reg: INTEGER); (* pop reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte(58H + reg MOD 8)
|
|
|
|
END pop;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE push (reg: INTEGER); (* push reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte(50H + reg MOD 8)
|
|
|
|
END push;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE decr (reg: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 0C8H + reg MOD 8) (* dec reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END decr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE incr (reg: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 0C0H + reg MOD 8) (* inc reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END incr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE drop;
|
|
|
|
BEGIN
|
|
|
|
REG.Drop(R)
|
|
|
|
END drop;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE GetAnyReg (): INTEGER;
|
|
|
|
RETURN REG.GetAnyReg(R)
|
|
|
|
END GetAnyReg;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE callimp (label: INTEGER);
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte2(0FFH, 15H); (* call qword[rip + label + IMP] *)
|
|
|
|
X86.Reloc(sIMP, label)
|
2019-03-11 09:59:55 +01:00
|
|
|
END callimp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE pushDA (offs: INTEGER);
|
|
|
|
VAR
|
|
|
|
reg: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg, offs, sDATA);
|
|
|
|
push(reg);
|
|
|
|
drop
|
|
|
|
END pushDA;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE CallRTL (proc: INTEGER);
|
|
|
|
VAR
|
|
|
|
label: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
label := IL.codes.rtl[proc];
|
2019-03-11 09:59:55 +01:00
|
|
|
IF label < 0 THEN
|
|
|
|
callimp(-label)
|
|
|
|
ELSE
|
|
|
|
X86.call(label)
|
2021-06-15 19:33:16 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END CallRTL;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE UnOp (VAR reg: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
REG.UnOp(R, reg)
|
|
|
|
END UnOp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE BinOp (VAR reg1, reg2: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
REG.BinOp(R, reg1, reg2)
|
|
|
|
END BinOp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE PushAll (NumberOfParameters: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
REG.PushAll(R);
|
2019-09-26 22:23:06 +02:00
|
|
|
DEC(R.pushed, NumberOfParameters)
|
2019-03-11 09:59:55 +01:00
|
|
|
END PushAll;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movabs (reg, n: INTEGER);
|
|
|
|
VAR
|
|
|
|
i: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0B8H + reg MOD 8); (* movabs reg, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
FOR i := 0 TO 7 DO
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte(UTILS.Byte(n, i))
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END movabs;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movrc (reg, n: INTEGER); (* mov reg, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
IF isLong(n) THEN
|
|
|
|
movabs(reg, n)
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF n = 0 THEN
|
|
|
|
xor(reg, reg)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0C7H, 0C0H + reg MOD 8);
|
|
|
|
OutInt(n)
|
|
|
|
END
|
|
|
|
END movrc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE test (reg: INTEGER); (* test reg, reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprr(85H, reg, reg)
|
|
|
|
END test;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE oprlongc (reg, n: INTEGER; oprr: OPRR);
|
|
|
|
VAR
|
|
|
|
reg2: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2020-05-25 22:48:33 +02:00
|
|
|
ASSERT(reg2 # reg);
|
2019-03-11 09:59:55 +01:00
|
|
|
movabs(reg2, n);
|
|
|
|
oprr(reg, reg2);
|
|
|
|
drop
|
|
|
|
END oprlongc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE oprc (op, reg, n: INTEGER; oprr: OPRR);
|
|
|
|
BEGIN
|
|
|
|
IF isLong(n) THEN
|
|
|
|
oprlongc(reg, n, oprr)
|
|
|
|
ELSE
|
|
|
|
Rex(reg, 0);
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.oprc(op, reg, n)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END oprc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE cmprc (reg, n: INTEGER); (* cmp reg, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
IF n = 0 THEN
|
|
|
|
test(reg)
|
|
|
|
ELSE
|
|
|
|
oprc(0F8H, reg, n, cmprr)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END cmprc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE addrc (reg, n: INTEGER); (* add reg, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprc(0C0H, reg, n, add)
|
|
|
|
END addrc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE subrc (reg, n: INTEGER); (* sub reg, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprc(0E8H, reg, n, sub)
|
|
|
|
END subrc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE andrc (reg, n: INTEGER); (* and reg, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
oprc(0E0H, reg, n, and)
|
|
|
|
END andrc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE orrc (reg, n: INTEGER); (* or reg, n *)
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprc(0C8H, reg, n, _or)
|
2020-05-25 22:48:33 +02:00
|
|
|
END orrc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE xorrc (reg, n: INTEGER); (* xor reg, n *)
|
|
|
|
BEGIN
|
|
|
|
oprc(0F0H, reg, n, xor)
|
|
|
|
END xorrc;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE pushc (n: INTEGER);
|
|
|
|
VAR
|
|
|
|
reg2: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF isLong(n) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movabs(reg2, n);
|
|
|
|
push(reg2);
|
|
|
|
drop
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.pushc(n)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END pushc;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE not (reg: INTEGER); (* not reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0F7H, 0D0H + reg MOD 8)
|
|
|
|
END not;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE neg (reg: INTEGER); (* neg reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0F7H, 0D8H + reg MOD 8)
|
|
|
|
END neg;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movzx (reg1, reg2, offs: INTEGER; word: BOOLEAN); (* movzx reg1, byte/word[reg2 + offs] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
Rex(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.movzx(reg1, reg2, offs, word)
|
2019-03-11 09:59:55 +01:00
|
|
|
END movzx;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movmr32 (reg1, offs, reg2: INTEGER); (* mov dword[reg1+offs], reg2_32 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86._movrm(reg2, reg1, offs, 32, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END movmr32;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movrm32 (reg1, reg2, offs: INTEGER); (* mov reg1_32, dword[reg2+offs] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86._movrm(reg1, reg2, offs, 32, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END movrm32;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movmr (reg1, offs, reg2: INTEGER); (* mov qword[reg1+offs], reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86._movrm(reg2, reg1, offs, 64, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END movmr;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movrm (reg1, reg2, offs: INTEGER); (* mov reg1, qword[reg2+offs] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
X86._movrm(reg1, reg2, offs, 64, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END movrm;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE comisd (xmm1, xmm2: INTEGER); (* comisd xmm1, xmm2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
OutByte(66H);
|
|
|
|
IF (xmm1 >= 8) OR (xmm2 >= 8) THEN
|
|
|
|
OutByte(40H + (xmm1 DIV 8) * 4 + xmm2 DIV 8)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, 2FH, 0C0H + (xmm1 MOD 8) * 8 + xmm2 MOD 8)
|
|
|
|
END comisd;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE _movsdrm (xmm, reg, offs: INTEGER; mr: BOOLEAN);
|
|
|
|
VAR
|
|
|
|
b: BYTE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
OutByte(0F2H);
|
|
|
|
IF (xmm >= 8) OR (reg >= 8) THEN
|
|
|
|
OutByte(40H + (xmm DIV 8) * 4 + reg DIV 8)
|
|
|
|
END;
|
|
|
|
OutByte2(0FH, 10H + ORD(mr));
|
|
|
|
IF (offs = 0) & (reg # rbp) THEN
|
|
|
|
b := 0
|
|
|
|
ELSE
|
|
|
|
b := 40H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + (xmm MOD 8) * 8 + reg MOD 8);
|
|
|
|
IF reg = rsp THEN
|
|
|
|
OutByte(24H)
|
|
|
|
END;
|
|
|
|
IF b # 0 THEN
|
|
|
|
OutIntByte(offs)
|
|
|
|
END
|
|
|
|
END _movsdrm;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movsdrm (xmm, reg, offs: INTEGER); (* movsd xmm, qword[reg+offs] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
_movsdrm(xmm, reg, offs, FALSE)
|
|
|
|
END movsdrm;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE movsdmr (reg, offs, xmm: INTEGER); (* movsd qword[reg+offs], xmm *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
_movsdrm(xmm, reg, offs, TRUE)
|
|
|
|
END movsdmr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE opxx (op, xmm1, xmm2: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
OutByte(0F2H);
|
|
|
|
IF (xmm1 >= 8) OR (xmm2 >= 8) THEN
|
|
|
|
OutByte(40H + (xmm1 DIV 8) * 4 + xmm2 DIV 8)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, op, 0C0H + (xmm1 MOD 8) * 8 + xmm2 MOD 8)
|
|
|
|
END opxx;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE jcc (cc, label: INTEGER); (* jcc label *)
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
X86.jcc(cc, label)
|
|
|
|
END jcc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE shiftrc (op, reg, n: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
IF n = 1 THEN
|
|
|
|
OutByte(0D1H)
|
|
|
|
ELSE
|
|
|
|
OutByte(0C1H)
|
|
|
|
END;
|
|
|
|
X86.shift(op, reg MOD 8);
|
|
|
|
IF n # 1 THEN
|
|
|
|
OutByte(n)
|
|
|
|
END
|
|
|
|
END shiftrc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetRegA;
|
|
|
|
BEGIN
|
|
|
|
ASSERT(REG.GetReg(R, rax))
|
|
|
|
END GetRegA;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Win64Passing (params: INTEGER);
|
|
|
|
VAR
|
|
|
|
n, i: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
n := params MOD 32;
|
|
|
|
params := params DIV 32;
|
|
|
|
FOR i := 0 TO n - 1 DO
|
|
|
|
IF i IN BITS(params) THEN
|
|
|
|
movsdrm(i, rsp, i * 8)
|
|
|
|
ELSE
|
|
|
|
movrm(Win64RegPar[i], rsp, i * 8)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END Win64Passing;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE SysVPassing (params: INTEGER);
|
|
|
|
VAR
|
|
|
|
n, i, s, p, ofs: INTEGER;
|
|
|
|
i_count, f_count: INTEGER;
|
|
|
|
reg: BOOLEAN;
|
|
|
|
|
|
|
|
BEGIN
|
2021-06-15 19:33:16 +02:00
|
|
|
ASSERT(r11 IN R.regs);
|
2019-03-11 09:59:55 +01:00
|
|
|
n := params MOD 32;
|
|
|
|
params := params DIV 32;
|
|
|
|
s := 0;
|
|
|
|
|
|
|
|
i_count := 0;
|
|
|
|
f_count := 0;
|
|
|
|
FOR i := 0 TO n - 1 DO
|
|
|
|
IF i IN BITS(params) THEN
|
|
|
|
INC(f_count)
|
|
|
|
ELSE
|
|
|
|
INC(i_count)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
s := MAX(0, f_count - 8) + MAX(0, i_count - 6);
|
|
|
|
p := 0;
|
|
|
|
|
|
|
|
subrc(rsp, s * 8);
|
|
|
|
|
|
|
|
i_count := 0;
|
|
|
|
f_count := 0;
|
|
|
|
FOR i := 0 TO n - 1 DO
|
|
|
|
ofs := (i + s) * 8;
|
|
|
|
IF i IN BITS(params) THEN
|
|
|
|
reg := f_count <= 7;
|
|
|
|
IF reg THEN
|
|
|
|
movsdrm(f_count, rsp, ofs);
|
|
|
|
INC(f_count)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
reg := i_count <= 5;
|
|
|
|
IF reg THEN
|
|
|
|
movrm(SystemVRegPar[i_count], rsp, ofs);
|
|
|
|
INC(i_count)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF ~reg THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm(r11, rsp, ofs);
|
|
|
|
movmr(rsp, p, r11);
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(p, 8)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END SysVPassing;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE fcmp (op: INTEGER; xmm: INTEGER);
|
|
|
|
VAR
|
|
|
|
cc, reg: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
xor(reg, reg);
|
|
|
|
CASE op OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQF:
|
2019-03-11 09:59:55 +01:00
|
|
|
comisd(xmm - 1, xmm);
|
|
|
|
cc := sete
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opNEF:
|
2019-03-11 09:59:55 +01:00
|
|
|
comisd(xmm - 1, xmm);
|
|
|
|
cc := setne
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLTF:
|
2019-03-11 09:59:55 +01:00
|
|
|
comisd(xmm - 1, xmm);
|
|
|
|
cc := setc
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGTF:
|
2019-03-11 09:59:55 +01:00
|
|
|
comisd(xmm, xmm - 1);
|
|
|
|
cc := setc
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLEF:
|
2019-03-11 09:59:55 +01:00
|
|
|
comisd(xmm, xmm - 1);
|
|
|
|
cc := setnc
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGEF:
|
2019-03-11 09:59:55 +01:00
|
|
|
comisd(xmm - 1, xmm);
|
|
|
|
cc := setnc
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(7AH, 3 + reg DIV 8); (* jp L *)
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(cc, reg)
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END fcmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE translate (commands: LISTS.LIST; stroffs: INTEGER);
|
|
|
|
VAR
|
|
|
|
cmd, next: COMMAND;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
opcode, param1, param2, param3, a, b, c, n, label, L, i, cc: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
reg1, reg2, reg3, xmm: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
float: REAL;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
xmm := -1;
|
|
|
|
cmd := commands.first(COMMAND);
|
|
|
|
WHILE cmd # NIL DO
|
|
|
|
|
|
|
|
param1 := cmd.param1;
|
|
|
|
param2 := cmd.param2;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
opcode := cmd.opcode;
|
|
|
|
|
|
|
|
CASE opcode OF
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opJMP:
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.jmp(param1)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALL, IL.opWIN64CALL, IL.opSYSVCALL:
|
|
|
|
CASE opcode OF
|
|
|
|
|IL.opCALL:
|
|
|
|
|IL.opWIN64CALL: Win64Passing(param2)
|
|
|
|
|IL.opSYSVCALL: SysVPassing(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
X86.call(param1)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALLP, IL.opWIN64CALLP, IL.opSYSVCALLP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 # rax THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
mov(rax, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
drop;
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE opcode OF
|
|
|
|
|IL.opCALLP:
|
|
|
|
|IL.opWIN64CALLP: Win64Passing(param2)
|
|
|
|
|IL.opSYSVCALLP: SysVPassing(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 0D0H); (* call rax *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(R.top = -1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALLI, IL.opWIN64CALLI, IL.opSYSVCALLI:
|
|
|
|
CASE opcode OF
|
|
|
|
|IL.opCALLI:
|
|
|
|
|IL.opWIN64CALLI: Win64Passing(param2)
|
|
|
|
|IL.opSYSVCALLI: SysVPassing(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
callimp(param1)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLABEL:
|
|
|
|
X86.SetLabel(param1)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opERR:
|
|
|
|
CallRTL(IL._error)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opONERR:
|
|
|
|
pushc(param2);
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.jmp(param1)
|
2020-05-25 22:48:33 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHC:
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPRECALL:
|
2020-10-13 09:58:51 +02:00
|
|
|
PushAll(0);
|
|
|
|
IF (param2 # 0) & (xmm >= 0) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(rsp, 8)
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(Xmm[0]);
|
|
|
|
Xmm[Xmm[0]] := xmm + 1;
|
|
|
|
WHILE xmm >= 0 DO
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(rsp, 8);
|
|
|
|
movsdmr(rsp, 0, xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
DEC(xmm)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm = -1)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opWIN64ALIGN16:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(rax IN R.regs);
|
|
|
|
mov(rax, rsp);
|
|
|
|
andrc(rsp, -16);
|
|
|
|
push(rax);
|
|
|
|
subrc(rsp, (MAX(param2 - 4, 0) MOD 2 + MAX(4 - param2, 0) + 1) * 8)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSYSVALIGN16:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(rax IN R.regs);
|
|
|
|
mov(rax, rsp);
|
|
|
|
andrc(rsp, -16);
|
|
|
|
push(rax);
|
|
|
|
IF ~ODD(param2) THEN
|
|
|
|
push(rax)
|
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opRESF, IL.opRES:
|
|
|
|
ASSERT(R.top = -1);
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(xmm = -1);
|
2020-10-13 09:58:51 +02:00
|
|
|
n := Xmm[Xmm[0]]; DEC(Xmm[0]);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF opcode = IL.opRESF THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF n > 0 THEN
|
|
|
|
movsdmr(rsp, n * 8, 0);
|
|
|
|
DEC(xmm);
|
|
|
|
INC(n)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF xmm + n > MAX_XMM THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
GetRegA
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
WHILE n > 0 DO
|
|
|
|
INC(xmm);
|
|
|
|
movsdrm(xmm, rsp, 0);
|
|
|
|
addrc(rsp, 8);
|
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opENTER:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(R.top = -1);
|
|
|
|
|
|
|
|
X86.SetLabel(param1);
|
|
|
|
|
|
|
|
param3 := cmd.param3;
|
|
|
|
|
|
|
|
IF param3 > 0 THEN
|
|
|
|
push(rbp);
|
|
|
|
mov(rbp, rsp);
|
|
|
|
|
|
|
|
n := param3 MOD 32;
|
|
|
|
param3 := param3 DIV 32;
|
|
|
|
|
|
|
|
FOR i := 0 TO n - 1 DO
|
|
|
|
IF i IN BITS(param3) THEN
|
|
|
|
movsdmr(rbp, i * 8 + 16, i)
|
|
|
|
ELSE
|
|
|
|
movmr(rbp, i * 8 + 16, Win64RegPar[i])
|
|
|
|
END
|
|
|
|
END
|
|
|
|
ELSIF param3 < 0 THEN
|
|
|
|
param3 := -param3;
|
|
|
|
n := (param3 MOD 32) * 8;
|
|
|
|
param3 := param3 DIV 32;
|
2021-06-15 19:33:16 +02:00
|
|
|
pop(r11);
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(rsp, n);
|
2021-06-15 19:33:16 +02:00
|
|
|
push(r11);
|
2019-03-11 09:59:55 +01:00
|
|
|
push(rbp);
|
|
|
|
mov(rbp, rsp);
|
|
|
|
|
|
|
|
a := 0;
|
|
|
|
b := 0;
|
|
|
|
c := 0;
|
|
|
|
|
|
|
|
INC(n, 16);
|
|
|
|
|
|
|
|
FOR i := 16 TO n - 8 BY 8 DO
|
|
|
|
IF ODD(param3) THEN
|
|
|
|
IF b <= 7 THEN
|
|
|
|
movsdmr(rbp, i, b);
|
|
|
|
INC(b)
|
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm(r11, rbp, n + c);
|
|
|
|
movmr(rbp, i, r11);
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(c, 8)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF a <= 5 THEN
|
|
|
|
movmr(rbp, i, SystemVRegPar[a]);
|
|
|
|
INC(a)
|
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm(r11, rbp, n + c);
|
|
|
|
movmr(rbp, i, r11);
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(c, 8)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
param3 := param3 DIV 2
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
push(rbp);
|
|
|
|
mov(rbp, rsp)
|
|
|
|
END;
|
|
|
|
|
|
|
|
n := param2;
|
|
|
|
IF n > 4 THEN
|
|
|
|
movrc(rcx, n);
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0E2H, 0FCH) (* loop L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
WHILE n > 0 DO
|
|
|
|
pushc(0);
|
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLEAVE, IL.opLEAVER, IL.opLEAVEF:
|
|
|
|
IF opcode = IL.opLEAVER THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 # rax THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
mov(rax, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(R.top = -1);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opLEAVEF THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(xmm)
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(xmm = -1);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF param1 > 0 THEN
|
|
|
|
mov(rsp, rbp)
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(rbp);
|
|
|
|
IF param2 > 0 THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
OutByte3(0C2H, (param2 * 8) MOD 256, (param2 * 8) DIV 256) (* ret param2*8 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.ret
|
2021-06-15 19:33:16 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVES:
|
2019-10-06 19:55:12 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
REG.PushAll_1(R);
|
2019-03-11 09:59:55 +01:00
|
|
|
pushDA(stroffs + param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg1);
|
|
|
|
drop;
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param1);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._move)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSADR:
|
|
|
|
lea(GetAnyReg(), stroffs + param2, sDATA)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD8:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
movzx(reg1, reg1, 0, FALSE)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD16:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
movzx(reg1, reg1, 0, TRUE)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD32:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
movrm32(reg1, reg1, 0);
|
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD64:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
movrm(reg1, reg1, 0)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD64:
|
|
|
|
reg1 := GetAnyReg();
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm(reg1, rbp, param2 * 8)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD8,
|
|
|
|
IL.opLLOAD16:
|
|
|
|
reg1 := GetAnyReg();
|
2021-06-15 19:33:16 +02:00
|
|
|
movzx(reg1, rbp, param2 * 8, opcode = IL.opLLOAD16)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD32:
|
|
|
|
reg1 := GetAnyReg();
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm32(reg1, rbp, param2 * 8);
|
2020-10-13 09:58:51 +02:00
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD64:
|
|
|
|
reg1 := GetAnyReg();
|
2020-10-13 09:58:51 +02:00
|
|
|
Rex(0, reg1); (* mov reg1, qword[rip + param2 + BSS] *)
|
|
|
|
OutByte2(8BH, 05H + 8 * (reg1 MOD 8));
|
|
|
|
X86.Reloc(sBSS, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opGLOAD8, IL.opGLOAD16:
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2020-10-13 09:58:51 +02:00
|
|
|
Rex(0, reg1); (* movzx reg1, byte/word[rip + param2 + BSS] *)
|
|
|
|
OutByte3(0FH, 0B6H + ORD(opcode = IL.opGLOAD16), 05H + 8 * (reg1 MOD 8));
|
|
|
|
X86.Reloc(sBSS, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD32:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, param2, sBSS);
|
2020-10-13 09:58:51 +02:00
|
|
|
movrm32(reg1, reg1, 0);
|
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVLOAD64:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm(reg1, rbp, param2 * 8);
|
|
|
|
movrm(reg1, reg1, 0)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVLOAD8,
|
|
|
|
IL.opVLOAD16:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm(reg1, rbp, param2 * 8);
|
2019-09-26 22:23:06 +02:00
|
|
|
movzx(reg1, reg1, 0, opcode = IL.opVLOAD16)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVLOAD32:
|
|
|
|
reg1 := GetAnyReg();
|
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm(reg2, rbp, param2 * 8);
|
|
|
|
movrm32(reg1, reg2, 0);
|
2020-10-13 09:58:51 +02:00
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 8;
|
|
|
|
next := cmd.next(COMMAND);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF (next.opcode = IL.opSAVEF) OR (next.opcode = IL.opSAVEFI) THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
movsdmr(rbp, n, xmm);
|
|
|
|
DEC(xmm);
|
|
|
|
cmd := next
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF next.opcode = IL.opLOADF THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF xmm > MAX_XMM THEN
|
|
|
|
ERRORS.ErrorMsg(fname, next.param1, next.param2, FPR_ERR)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
movsdrm(xmm, rbp, n);
|
|
|
|
cmd := next
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (next.opcode = IL.opADDC) & ~isLong(n + next.param2) THEN
|
|
|
|
INC(n, next.param2);
|
|
|
|
cmd := next
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(0, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(8DH, 45H + long(n) + (reg1 MOD 8) * 8); (* lea reg1, qword[rbp+n] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGADR:
|
2020-10-13 09:58:51 +02:00
|
|
|
next := cmd.next(COMMAND);
|
|
|
|
IF (next.opcode = IL.opADDC) & ~isLong(param2 + next.param2) THEN
|
|
|
|
INC(param2, next.param2);
|
|
|
|
cmd := next
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
lea(GetAnyReg(), param2, sBSS)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVADR:
|
|
|
|
movrm(GetAnyReg(), rbp, param2 * 8)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE8C:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0C6H, reg1 MOD 8, param2); (* mov byte[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE16C:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
OutByte(66H);
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte2(0C7H, reg1 MOD 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(param2 MOD 256, param2 DIV 256); (* mov word[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF isLong(param2) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg2, param2);
|
|
|
|
movmr(reg1, 0, reg2);
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
Rex(reg1, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0C7H, reg1 MOD 8); (* mov qword[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutInt(param2)
|
|
|
|
END;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opRSET:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._set);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opRSETR:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(1);
|
|
|
|
pushc(param2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._set);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opRSETL:
|
2019-10-06 19:55:12 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
REG.PushAll_1(R);
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg1);
|
|
|
|
drop;
|
|
|
|
CallRTL(IL._set);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opRSET1:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(1);
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(IL._set1);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCL, IL.opEXCL:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprc(reg1, 64);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(73H, 04H); (* jnb L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0ABH + 8 * ORD(opcode = IL.opEXCL), 8 * (reg1 MOD 8) + reg2 MOD 8); (* bts/btr qword[reg2], reg1 *)
|
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCLC, IL.opEXCLC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
Rex(reg1, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FH, 0BAH); (* bts/btr qword[reg1], param2 *)
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(28H + 8 * ORD(opcode = IL.opEXCLC) + reg1 MOD 8, param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQS .. IL.opGES:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(4);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(opcode - IL.opEQS);
|
|
|
|
CallRTL(IL._strcmp);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQSW .. IL.opGESW:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(4);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(opcode - IL.opEQSW);
|
|
|
|
CallRTL(IL._strcmpw);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCONST:
|
|
|
|
movrc(GetAnyReg(), param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQ..IL.opGE,
|
|
|
|
IL.opEQC..IL.opGEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF (IL.opEQ <= opcode) & (opcode <= IL.opGE) THEN
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprr(reg1, reg2);
|
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
cmprc(reg1, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
2019-09-26 22:23:06 +02:00
|
|
|
cc := X86.cond(opcode);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
next := cmd.next(COMMAND);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF next.opcode = IL.opJNZ THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
jcc(cc, next.param1);
|
|
|
|
cmd := next
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF next.opcode = IL.opJZ THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
jcc(X86.inv0(cc), next.param1);
|
|
|
|
cmd := next
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(cc + 16, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
andrc(reg1, 1)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCODE:
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte(param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHIP:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, param2, sIMP);
|
|
|
|
movrm(reg1, reg1, 0)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPARAM:
|
2023-01-21 15:34:25 +01:00
|
|
|
IF param2 = 1 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
push(reg1);
|
|
|
|
drop
|
|
|
|
ELSE
|
2023-01-21 15:34:25 +01:00
|
|
|
ASSERT(R.top + 1 <= param2);
|
|
|
|
PushAll(param2)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opJNZ1:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(jne, param1)
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opJG:
|
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(jg, param1)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opJNZ:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(jne, param1);
|
|
|
|
drop
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opJZ:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(je, param1);
|
|
|
|
drop
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opIN, IL.opINR:
|
|
|
|
IF opcode = IL.opINR THEN
|
|
|
|
reg2 := GetAnyReg();
|
|
|
|
movrc(reg2, param2)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
label := NewLabel();
|
|
|
|
L := NewLabel();
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprc(reg1, 64);
|
|
|
|
jcc(jb, L);
|
|
|
|
xor(reg1, reg1);
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.jmp(label);
|
2019-03-11 09:59:55 +01:00
|
|
|
X86.SetLabel(L);
|
|
|
|
Rex(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0A3H, 0C0H + 8 * (reg1 MOD 8) + reg2 MOD 8); (* bt reg2, reg1 *)
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(setc, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
andrc(reg1, 1);
|
|
|
|
X86.SetLabel(label);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINL:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
Rex(reg1, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FH, 0BAH); (* bt reg1, param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte2(0E0H + reg1 MOD 8, param2);
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(setc, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
andrc(reg1, 1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opNOT:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(sete, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
andrc(reg1, 1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opORD:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(setne, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
andrc(reg1, 1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opABS:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(7DH, 03H); (* jge L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
neg(reg1)
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQB, IL.opNEB:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
drop;
|
|
|
|
test(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
label := NewLabel();
|
|
|
|
jcc(je, label);
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg1, 1);
|
2019-09-26 22:23:06 +02:00
|
|
|
X86.SetLabel(label);
|
2019-03-11 09:59:55 +01:00
|
|
|
test(reg2);
|
2019-09-26 22:23:06 +02:00
|
|
|
label := NewLabel();
|
|
|
|
jcc(je, label);
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg2, 1);
|
2019-09-26 22:23:06 +02:00
|
|
|
X86.SetLabel(label);
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprr(reg1, reg2);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opEQB THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(sete, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
X86.setcc(setne, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
andrc(reg1, 1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULSC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, param2)
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opDIVSC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
xorrc(reg1, param2)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opADDSC:
|
2020-05-25 22:48:33 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
orrc(reg1, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBSL:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
not(reg1);
|
|
|
|
andrc(reg1, param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBSR:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, ORD(-BITS(param2)))
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
and(reg1, reg2);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
xor(reg1, reg2);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opUMINS:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
not(reg1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCOPY:
|
2022-06-21 22:32:43 +02:00
|
|
|
IF (0 < param2) & (param2 <= 256) THEN
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
reg3 := GetAnyReg();
|
|
|
|
FOR n := 0 TO param2 - param2 MOD 8 - 1 BY 8 DO
|
|
|
|
movrm(reg3, reg1, n);
|
|
|
|
movmr(reg2, n, reg3)
|
|
|
|
END;
|
|
|
|
n := param2 - param2 MOD 8;
|
|
|
|
IF param2 MOD 8 >= 4 THEN
|
|
|
|
movrm32(reg3, reg1, n);
|
|
|
|
movmr32(reg2, n, reg3);
|
|
|
|
INC(n, 4);
|
|
|
|
DEC(param2, 4)
|
|
|
|
END;
|
|
|
|
IF param2 MOD 8 >= 2 THEN
|
|
|
|
X86.movrm16(reg3, reg1, n);
|
|
|
|
X86.movmr16(reg2, n, reg3);
|
|
|
|
INC(n, 2);
|
|
|
|
DEC(param2, 2)
|
|
|
|
END;
|
|
|
|
IF param2 MOD 8 = 1 THEN
|
|
|
|
X86.movrm8(reg3, reg1, n);
|
|
|
|
X86.movmr8(reg2, n, reg3);
|
|
|
|
END;
|
|
|
|
drop;
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
PushAll(2);
|
|
|
|
pushc(param2);
|
|
|
|
CallRTL(IL._move)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMOVE:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(3);
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(IL._move)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCOPYA:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(4);
|
|
|
|
pushc(param2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._arrcpy);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCOPYS:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(4);
|
|
|
|
pushc(param2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._strcpy)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opROT:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(0);
|
|
|
|
push(rsp);
|
|
|
|
pushc(param2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._rot)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opNEW:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(1);
|
2023-01-21 15:34:25 +01:00
|
|
|
n := param2 + 16;
|
|
|
|
ASSERT(UTILS.Align(n, 16));
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(n);
|
|
|
|
pushc(param1);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._new)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDISP:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(1);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._dispose)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHT:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm(GetAnyReg(), reg1, -8)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opISREC:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._isrec);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opIS:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(1);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._is);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opTYPEGR:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(1);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._guardrec);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opTYPEGP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
PushAll(0);
|
|
|
|
push(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._guard);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opTYPEGD:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
PushAll(0);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.pushm(reg1, -8);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._guardrec);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASET:
|
2021-06-15 19:33:16 +02:00
|
|
|
push(rcx);
|
|
|
|
push(rcx);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._guardrec);
|
2021-06-15 19:33:16 +02:00
|
|
|
pop(rcx);
|
2019-03-11 09:59:55 +01:00
|
|
|
test(rax);
|
|
|
|
jcc(jne, param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param2, sCODE);
|
|
|
|
movmr(reg1, 0, reg2);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHP:
|
|
|
|
lea(GetAnyReg(), param2, sCODE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINC, IL.opDEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
(* add/sub qword[reg2], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(reg2, reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(01H + 28H * ORD(opcode = IL.opDEC), reg2 MOD 8 + (reg1 MOD 8) * 8);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF isLong(param2) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg2, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
(* add qword[reg1], reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(reg1, reg2);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(01H, reg1 MOD 8 + (reg2 MOD 8) * 8);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF ABS(param2) = 1 THEN
|
|
|
|
Rex(reg1, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, reg1 MOD 8 + 8 * ORD(param2 = -1)) (* inc/dec qword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
(* add qword[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(reg1, 0);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(81H + short(param2), reg1 MOD 8);
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(param2)
|
|
|
|
END;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDROP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE, IL.opSAVE64:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
|
|
|
movmr(reg1, 0, reg2);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE8:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.movmr8(reg1, 0, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE16:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.movmr16(reg1, 0, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE32:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
|
|
|
movmr32(reg1, 0, reg2);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opMAX, IL.opMIN:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprr(reg1, reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(7DH + ORD(opcode = IL.opMIN), 3); (* jge/jle L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
mov(reg1, reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opMAXC, IL.opMINC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
cmprc(reg1, param2);
|
|
|
|
label := NewLabel();
|
2020-05-25 22:48:33 +02:00
|
|
|
IF opcode = IL.opMINC THEN
|
|
|
|
cc := jle
|
|
|
|
ELSE
|
|
|
|
cc := jge
|
|
|
|
END;
|
|
|
|
jcc(cc, label);
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg1, param2);
|
|
|
|
X86.SetLabel(label)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSBOOL:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
|
|
|
test(reg2);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 95H, reg1 MOD 8); (* setne byte[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSBOOLC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0C6H, reg1 MOD 8, ORD(param2 # 0)); (* mov byte[reg1], 0/1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opUMINUS:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
neg(reg1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opADD:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
add(reg1, reg2);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUB:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
sub(reg1, reg2);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBR, IL.opSUBL:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF param2 = 1 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
decr(reg1)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF param2 = -1 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
incr(reg1)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF param2 # 0 THEN
|
|
|
|
subrc(reg1, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opSUBL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
neg(reg1)
|
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opADDC:
|
2020-05-25 22:48:33 +02:00
|
|
|
IF (param2 # 0) & ~isLong(param2) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
next := cmd.next(COMMAND);
|
|
|
|
CASE next.opcode OF
|
|
|
|
|IL.opLOAD64:
|
|
|
|
movrm(reg1, reg1, param2);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD32:
|
|
|
|
movrm32(reg1, reg1, param2);
|
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD16:
|
|
|
|
movzx(reg1, reg1, param2, TRUE);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD8:
|
|
|
|
movzx(reg1, reg1, param2, FALSE);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD64_PARAM:
|
|
|
|
X86.pushm(reg1, param2);
|
|
|
|
drop;
|
|
|
|
cmd := next
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
IF param2 = 1 THEN
|
|
|
|
incr(reg1)
|
|
|
|
ELSIF param2 = -1 THEN
|
|
|
|
decr(reg1)
|
|
|
|
ELSE
|
|
|
|
addrc(reg1, param2)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF isLong(param2) THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
addrc(reg1, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIV:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(IL._divmod);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVR:
|
2020-05-25 22:48:33 +02:00
|
|
|
n := UTILS.Log2(param2);
|
|
|
|
IF n > 0 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
shiftrc(sar, reg1, n)
|
|
|
|
ELSIF n < 0 THEN
|
|
|
|
PushAll(1);
|
|
|
|
pushc(param2);
|
|
|
|
CallRTL(IL._divmod);
|
|
|
|
GetRegA
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVL:
|
2019-10-06 19:55:12 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
REG.PushAll_1(R);
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg1);
|
|
|
|
drop;
|
|
|
|
CallRTL(IL._divmod);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMOD:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(IL._divmod);
|
|
|
|
mov(rax, rdx);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMODR:
|
2020-05-25 22:48:33 +02:00
|
|
|
n := UTILS.Log2(param2);
|
|
|
|
IF n > 0 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, param2 - 1);
|
|
|
|
ELSIF n < 0 THEN
|
|
|
|
PushAll(1);
|
|
|
|
pushc(param2);
|
|
|
|
CallRTL(IL._divmod);
|
|
|
|
mov(rax, rdx);
|
|
|
|
GetRegA
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
UnOp(reg1);
|
|
|
|
xor(reg1, reg1)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMODL:
|
2019-10-06 19:55:12 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
REG.PushAll_1(R);
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg1);
|
|
|
|
drop;
|
|
|
|
CallRTL(IL._divmod);
|
|
|
|
mov(rax, rdx);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMUL:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
oprr2(0FH, 0AFH, reg2, reg1); (* imul reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULC:
|
2020-05-25 22:48:33 +02:00
|
|
|
IF (cmd.next(COMMAND).opcode = IL.opADD) & ((param2 = 2) OR (param2 = 4) OR (param2 = 8)) THEN
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
OutByte2(48H + 5 * (reg1 DIV 8) + 2 * (reg2 DIV 8), 8DH); (* lea reg1, [reg1 + reg2 * param2] *)
|
|
|
|
reg1 := reg1 MOD 8;
|
|
|
|
reg2 := reg2 MOD 8;
|
|
|
|
OutByte2(04H + reg1 * 8, reg1 + reg2 * 8 + 40H * UTILS.Log2(param2));
|
|
|
|
drop;
|
|
|
|
cmd := cmd.next(COMMAND)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
|
|
|
|
a := param2;
|
|
|
|
IF a > 1 THEN
|
|
|
|
n := UTILS.Log2(a)
|
|
|
|
ELSIF a < -1 THEN
|
|
|
|
n := UTILS.Log2(-a)
|
|
|
|
ELSE
|
|
|
|
n := -1
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF a = 1 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF a = -1 THEN
|
|
|
|
neg(reg1)
|
|
|
|
ELSIF a = 0 THEN
|
|
|
|
xor(reg1, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
IF n > 0 THEN
|
|
|
|
IF a < 0 THEN
|
|
|
|
neg(reg1)
|
|
|
|
END;
|
|
|
|
shiftrc(shl, reg1, n)
|
|
|
|
ELSE
|
|
|
|
IF isLong(a) THEN
|
|
|
|
reg2 := GetAnyReg();
|
|
|
|
movabs(reg2, a);
|
|
|
|
ASSERT(reg1 # reg2);
|
|
|
|
oprr2(0FH, 0AFH, reg2, reg1); (* imul reg1, reg2 *)
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
(* imul reg1, a *)
|
|
|
|
Rex(reg1, reg1);
|
|
|
|
OutByte2(69H + short(a), 0C0H + (reg1 MOD 8) * 9);
|
|
|
|
OutIntByte(a)
|
|
|
|
END
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opADDS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2020-10-13 09:58:51 +02:00
|
|
|
_or(reg1, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
not(reg2);
|
|
|
|
and(reg1, reg2);
|
|
|
|
drop
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opNOP, IL.opAND, IL.opOR:
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSWITCH:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF param2 = 0 THEN
|
|
|
|
reg2 := rax
|
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
reg2 := rcx
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
IF reg1 # reg2 THEN
|
|
|
|
ASSERT(REG.GetReg(R, reg2));
|
|
|
|
ASSERT(REG.Exchange(R, reg1, reg2));
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opENDSW:
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASEL:
|
2020-05-25 22:48:33 +02:00
|
|
|
GetRegA;
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(rax, param1);
|
2020-05-25 22:48:33 +02:00
|
|
|
jcc(jl, param2);
|
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASER:
|
2020-05-25 22:48:33 +02:00
|
|
|
GetRegA;
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(rax, param1);
|
2020-05-25 22:48:33 +02:00
|
|
|
jcc(jg, param2);
|
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASELR:
|
2020-05-25 22:48:33 +02:00
|
|
|
GetRegA;
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(rax, param1);
|
2021-06-15 19:33:16 +02:00
|
|
|
IF param2 = cmd.param3 THEN
|
|
|
|
jcc(jne, param2)
|
|
|
|
ELSE
|
|
|
|
jcc(jl, param2);
|
|
|
|
jcc(jg, cmd.param3)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR, IL.opROR, IL.opLSL, IL.opLSR:
|
2021-06-15 19:33:16 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 # rcx THEN
|
|
|
|
ASSERT(REG.GetReg(R, rcx));
|
|
|
|
ASSERT(REG.Exchange(R, reg1, rcx));
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2021-06-15 19:33:16 +02:00
|
|
|
ASSERT(reg2 = rcx);
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(reg1, 0);
|
|
|
|
OutByte(0D3H);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.shift(opcode, reg1 MOD 8); (* shift reg1, cl *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR1, IL.opROR1, IL.opLSL1, IL.opLSR1:
|
2021-06-15 19:33:16 +02:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 # rcx THEN
|
|
|
|
ASSERT(REG.GetReg(R, rcx));
|
|
|
|
ASSERT(REG.Exchange(R, reg1, rcx));
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg1, param2);
|
|
|
|
BinOp(reg1, reg2);
|
2021-06-15 19:33:16 +02:00
|
|
|
ASSERT(reg1 = rcx);
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(reg2, 0);
|
|
|
|
OutByte(0D3H);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.shift(opcode, reg2 MOD 8); (* shift reg2, cl *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop;
|
|
|
|
ASSERT(REG.GetReg(R, reg2))
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR2, IL.opROR2, IL.opLSL2, IL.opLSR2:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
shiftrc(opcode, reg1, param2 MOD 64)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGET, IL.opGETC:
|
|
|
|
IF opcode = IL.opGET THEN
|
|
|
|
BinOp(reg1, reg2)
|
|
|
|
ELSIF opcode = IL.opGETC THEN
|
|
|
|
UnOp(reg2);
|
|
|
|
reg1 := GetAnyReg();
|
|
|
|
movrc(reg1, param1)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop;
|
2020-05-25 22:48:33 +02:00
|
|
|
X86._movrm(reg1, reg1, 0, param2 * 8, FALSE);
|
|
|
|
X86._movrm(reg1, reg2, 0, param2 * 8, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCHKIDX:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
cmprc(reg1, param2);
|
|
|
|
jcc(jb, param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCHKIDX2:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
IF param2 # -1 THEN
|
|
|
|
cmprr(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
jcc(jb, param1);
|
|
|
|
END;
|
|
|
|
INCL(R.regs, reg1);
|
|
|
|
DEC(R.top);
|
|
|
|
R.stk[R.top] := reg2
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLENGTH:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._length);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLENGTHW:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._lengthw);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLEN:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2;
|
|
|
|
UnOp(reg1);
|
|
|
|
drop;
|
|
|
|
EXCL(R.regs, reg1);
|
|
|
|
|
|
|
|
WHILE n > 0 DO
|
|
|
|
UnOp(reg2);
|
|
|
|
drop;
|
|
|
|
DEC(n)
|
|
|
|
END;
|
|
|
|
|
|
|
|
INCL(R.regs, reg1);
|
|
|
|
ASSERT(REG.GetReg(R, reg1))
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQP, IL.opNEP, IL.opEQIP, IL.opNEIP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE opcode OF
|
|
|
|
|IL.opEQP, IL.opNEP:
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param1, sCODE)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQIP, IL.opNEIP:
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param1, sIMP);
|
|
|
|
movrm(reg2, reg2, 0)
|
|
|
|
END;
|
|
|
|
|
|
|
|
cmprr(reg1, reg2);
|
|
|
|
drop;
|
|
|
|
drop;
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE opcode OF
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opEQP, IL.opEQIP: X86.setcc(sete, reg1)
|
|
|
|
|IL.opNEP, IL.opNEIP: X86.setcc(setne, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
andrc(reg1, 1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCCB, IL.opDECCB:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(80H, 28H * ORD(opcode = IL.opDECCB) + reg1 MOD 8, param2 MOD 256); (* add/sub byte[reg1], param2 MOD 256 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCB, IL.opDECB:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
IF (reg1 >= 8) OR (reg2 >= 8) THEN
|
|
|
|
OutByte(40H + reg2 DIV 8 + 4 * (reg1 DIV 8))
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(28H * ORD(opcode = IL.opDECB), reg2 MOD 8 + 8 * (reg1 MOD 8)); (* add/sub byte[reg2], reg1_8 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEIP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param2, sIMP);
|
|
|
|
movrm(reg2, reg2, 0);
|
|
|
|
push(reg2);
|
|
|
|
drop;
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(8FH, reg1 MOD 8); (* pop qword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCLEANUP:
|
2020-10-13 09:58:51 +02:00
|
|
|
IF param2 # 0 THEN
|
|
|
|
addrc(rsp, param2 * 8)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPOPSP:
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(rsp)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOADF:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
INC(xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF xmm > MAX_XMM THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
movsdrm(xmm, reg1, 0);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(rsp, 8);
|
|
|
|
movsdmr(rsp, 0, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCONSTF:
|
2019-03-11 09:59:55 +01:00
|
|
|
float := cmd.float;
|
|
|
|
INC(xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF xmm > MAX_XMM THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
|
|
|
(* movsd xmm, qword ptr [rip + Numbers_Offs + Numbers_Count * 8 + DATA] *)
|
|
|
|
OutByte(0F2H);
|
|
|
|
IF xmm >= 8 THEN
|
|
|
|
OutByte(44H)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, 10H, 05H + 8 * (xmm MOD 8));
|
|
|
|
X86.Reloc(sDATA, Numbers_Offs + Numbers_Count * 8);
|
2019-03-11 09:59:55 +01:00
|
|
|
NewNumber(UTILS.splitf(float, a, b))
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opSAVEF, IL.opSAVEFI:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
movsdmr(reg1, 0, xmm);
|
|
|
|
DEC(xmm);
|
|
|
|
drop
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opADDF:
|
|
|
|
ASSERT(xmm >= 1);
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(58H, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 1);
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(5CH, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBFI:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 1);
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(5CH, xmm, xmm - 1);
|
|
|
|
opxx(10H, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 1);
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(59H, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 1);
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(5EH, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVFI:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 1);
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(5EH, xmm, xmm - 1);
|
|
|
|
opxx(10H, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opFABS, IL.opUMINF: (* andpd/xorpd xmm, xmmword[rip + Numbers_Offs + (16) + DATA] *)
|
|
|
|
ASSERT(xmm >= 0);
|
|
|
|
OutByte(66H);
|
|
|
|
IF xmm >= 8 THEN
|
|
|
|
OutByte(44H)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, 54H + 3 * ORD(opcode = IL.opUMINF), 05H + (xmm MOD 8) * 8);
|
|
|
|
X86.Reloc(sDATA, Numbers_Offs + 16 * ORD(opcode = IL.opFABS))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFLT:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
INC(xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF xmm > MAX_XMM THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0F2H); Rex(reg1, xmm); OutByte(0FH); (* cvtsi2sd xmm, reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte2(2AH, 0C0H + (xmm MOD 8) * 8 + reg1 MOD 8);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFLOOR:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 0);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(rsp, 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(00FH, 0AEH, 05CH); OutByte2(024H, 004H); (* stmxcsr dword[rsp+4]; *)
|
|
|
|
OutByte2(00FH, 0AEH); OutByte2(01CH, 024H); (* stmxcsr dword[rsp]; *)
|
|
|
|
OutByte3(081H, 024H, 024H); OutByte2(0FFH, 09FH); OutByte2(0FFH, 0FFH); (* and dword[rsp],11111111111111111001111111111111b; *)
|
|
|
|
OutByte3(081H, 00CH, 024H); OutByte2(000H, 020H); OutByte2(000H, 000H); (* or dword[rsp],00000000000000000010000000000000b; *)
|
|
|
|
OutByte2(00FH, 0AEH); OutByte2(014H, 024H); (* ldmxcsr dword[rsp]; *)
|
|
|
|
OutByte(0F2H); Rex(xmm, reg1); OutByte(0FH); (* cvtsd2si reg1, xmm *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte2(2DH, 0C0H + xmm MOD 8 + (reg1 MOD 8) * 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(00FH, 0AEH, 054H); OutByte2(024H, 004H); (* ldmxcsr dword[rsp+4]; *)
|
2019-03-11 09:59:55 +01:00
|
|
|
addrc(rsp, 8);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQF .. IL.opGEF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(xmm >= 1);
|
2019-09-26 22:23:06 +02:00
|
|
|
fcmp(opcode, xmm);
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(xmm, 2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINF:
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(xmm);
|
2020-10-13 09:58:51 +02:00
|
|
|
IF xmm > MAX_XMM THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
|
|
|
(* movsd xmm, qword ptr [rip + Numbers_Offs + 32 + DATA] *)
|
|
|
|
OutByte(0F2H);
|
|
|
|
IF xmm >= 8 THEN
|
|
|
|
OutByte(44H)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, 10H, 05H + 8 * (xmm MOD 8));
|
|
|
|
X86.Reloc(sDATA, Numbers_Offs + 32)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPACK, IL.opPACKC:
|
|
|
|
IF opcode = IL.opPACK THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2)
|
|
|
|
ELSE
|
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg2, param2)
|
|
|
|
END;
|
|
|
|
push(reg1);
|
|
|
|
movrm(reg1, reg1, 0);
|
|
|
|
shiftrc(shl, reg1, 1);
|
|
|
|
shiftrc(shr, reg1, 53);
|
|
|
|
add(reg1, reg2);
|
|
|
|
andrc(reg1, ORD({0..10}));
|
|
|
|
shiftrc(shl, reg1, 52);
|
|
|
|
movrm(reg2, rsp, 0);
|
|
|
|
movrm(reg2, reg2, 0);
|
|
|
|
|
|
|
|
push(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
lea(reg1, Numbers_Offs + 40, sDATA); (* {0..51, 63} *)
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm(reg1, reg1, 0);
|
|
|
|
and(reg2, reg1);
|
|
|
|
pop(reg1);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_or(reg2, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(reg1);
|
|
|
|
movmr(reg1, 0, reg2);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opUNPK, IL.opLADR_UNPK:
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opLADR_UNPK THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 8;
|
|
|
|
UnOp(reg1);
|
2021-06-15 19:33:16 +02:00
|
|
|
reg2 := GetAnyReg();
|
|
|
|
Rex(0, reg2);
|
|
|
|
OutByte2(8DH, 45H + long(n) + (reg2 MOD 8) * 8); (* lea reg2, qword[rbp+n] *)
|
|
|
|
OutIntByte(n)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
BinOp(reg1, reg2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
push(reg1);
|
|
|
|
movrm(reg1, reg1, 0);
|
|
|
|
shiftrc(shl, reg1, 1);
|
|
|
|
shiftrc(shr, reg1, 53);
|
|
|
|
subrc(reg1, 1023);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
movmr(reg2, 0, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
pop(reg2);
|
|
|
|
movrm(reg1, reg2, 0);
|
|
|
|
|
|
|
|
push(reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
lea(reg2, Numbers_Offs + 48, sDATA); (* {52..61} *)
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm(reg2, reg2, 0);
|
2020-10-13 09:58:51 +02:00
|
|
|
_or(reg1, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(reg2);
|
|
|
|
|
|
|
|
Rex(reg1, 0);
|
|
|
|
OutByte2(0FH, 0BAH);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0F0H + reg1 MOD 8, 3EH); (* btr reg1, 62 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
movmr(reg2, 0, reg1);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSADR_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
pushDA(stroffs + param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVADR_PARAM:
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.pushm(rbp, param2 * 8)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD64_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.pushm(reg1, 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD64_PARAM:
|
2021-06-15 19:33:16 +02:00
|
|
|
X86.pushm(rbp, param2 * 8)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD64_PARAM:
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte2(0FFH, 35H); (* push qword[rip + param2 + BSS] *)
|
|
|
|
X86.Reloc(sBSS, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCONST_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param2)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opGLOAD32_PARAM, IL.opLOAD32_PARAM:
|
|
|
|
IF opcode = IL.opGLOAD32_PARAM THEN
|
|
|
|
reg1 := GetAnyReg();
|
|
|
|
lea(reg1, param2, sBSS)
|
|
|
|
ELSE
|
|
|
|
UnOp(reg1)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm32(reg1, reg1, 0);
|
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32);
|
|
|
|
push(reg1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD32_PARAM:
|
|
|
|
reg1 := GetAnyReg();
|
2021-06-15 19:33:16 +02:00
|
|
|
movrm32(reg1, rbp, param2 * 8);
|
2020-10-13 09:58:51 +02:00
|
|
|
shiftrc(shl, reg1, 32);
|
|
|
|
shiftrc(shr, reg1, 32);
|
2019-03-11 09:59:55 +01:00
|
|
|
push(reg1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_SAVEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param1 * 8;
|
2021-06-15 19:33:16 +02:00
|
|
|
IF isLong(param2) THEN
|
|
|
|
reg2 := GetAnyReg();
|
|
|
|
movrc(reg2, param2);
|
|
|
|
movmr(rbp, n, reg2);
|
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
OutByte3(48H, 0C7H, 45H + long(n)); (* mov qword[rbp+n], param2 *)
|
|
|
|
OutIntByte(n);
|
|
|
|
OutInt(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGADR_SAVEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isLong(param2) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg1, param2);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param1, sBSS);
|
|
|
|
movmr(reg2, 0, reg1);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
(* mov qword[rip + param1 - 4 + BSS], param2 *)
|
|
|
|
OutByte3(48H, 0C7H, 05H);
|
|
|
|
X86.Reloc(sBSS, param1 - 4);
|
|
|
|
OutInt(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_SAVE:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2021-06-15 19:33:16 +02:00
|
|
|
movmr(rbp, param2 * 8, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCC:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF isLong(param2) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg2, param2);
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param1 * 8;
|
|
|
|
Rex(0, reg2);
|
|
|
|
OutByte2(01H, 45H + long(n) + (reg2 MOD 8) * 8);
|
|
|
|
OutIntByte(n); (* add qword[rbp+n], reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF ABS(param2) = 1 THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param1 * 8;
|
|
|
|
OutByte3(48H, 0FFH, 45H + 8 * ORD(param2 = -1) + long(n)); (* inc/dec qword[rbp+n] *)
|
|
|
|
OutIntByte(n)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param1 * 8;
|
|
|
|
OutByte3(48H, 81H + short(param2), 45H + long(n));
|
|
|
|
OutIntByte(n);
|
|
|
|
OutIntByte(param2) (* add qword[rbp+n], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCCB, IL.opLADR_DECCB:
|
2019-03-11 09:59:55 +01:00
|
|
|
param2 := param2 MOD 256;
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param1 * 8;
|
|
|
|
OutByte2(80H, 45H + long(n) + 28H * ORD(opcode = IL.opLADR_DECCB));
|
|
|
|
OutIntByte(n);
|
|
|
|
OutByte(param2) (* add/sub byte[rbp+n], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INC, IL.opLADR_DEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param2 * 8;
|
|
|
|
Rex(0, reg1);
|
|
|
|
OutByte2(01H + 28H * ORD(opcode = IL.opLADR_DEC), 45H + long(n) + (reg1 MOD 8) * 8);
|
|
|
|
OutIntByte(n); (* add/sub qword[rbp+n], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCB, IL.opLADR_DECB:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param2 * 8;
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(44H)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
OutByte2(28H * ORD(opcode = IL.opLADR_DECB), 45H + long(n) + 8 * (reg1 MOD 8));
|
|
|
|
OutIntByte(n); (* add/sub byte[rbp+n], reg1_8 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCL, IL.opLADR_EXCL:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
cmprc(reg1, 64);
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param2 * 8;
|
|
|
|
OutByte2(73H, 5 + 3 * ORD(~X86.isByte(n))); (* jnb L *)
|
|
|
|
Rex(0, reg1);
|
|
|
|
OutByte3(0FH, 0ABH + 8 * ORD(opcode = IL.opLADR_EXCL), 45H + long(n) + 8 * (reg1 MOD 8));
|
|
|
|
OutIntByte(n); (* bts/btr qword[rbp+n], reg1 *)
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCLC, IL.opLADR_EXCLC:
|
2021-06-15 19:33:16 +02:00
|
|
|
n := param1 * 8;
|
|
|
|
OutByte3(48H, 0FH, 0BAH); (* bts/btr qword[rbp+n], param2 *)
|
|
|
|
OutByte(6DH + long(n) + 8 * ORD(opcode = IL.opLADR_EXCLC));
|
|
|
|
OutIntByte(n);
|
|
|
|
OutByte(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opFNAME:
|
|
|
|
fname := cmd(IL.FNAMECMD).fname
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
cmd := cmd.next(COMMAND)
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(R.pushed = 0);
|
|
|
|
ASSERT(R.top = -1);
|
|
|
|
ASSERT(xmm = -1)
|
|
|
|
END translate;
|
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE prolog (modname: ARRAY OF CHAR; target, stack_size: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
ModName_Offs, entry, L: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-10-06 19:55:12 +02:00
|
|
|
ModName_Offs := tcount * 8 + CHL.Length(IL.codes.data);
|
2019-03-11 09:59:55 +01:00
|
|
|
Numbers_Offs := ModName_Offs + LENGTH(modname) + 1;
|
2019-09-26 22:23:06 +02:00
|
|
|
ASSERT(UTILS.Align(Numbers_Offs, 16));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
entry := NewLabel();
|
|
|
|
X86.SetLabel(entry);
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.Win64DLL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
dllret := NewLabel();
|
|
|
|
push(r8);
|
|
|
|
push(rdx);
|
|
|
|
push(rcx);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._dllentry);
|
2019-03-11 09:59:55 +01:00
|
|
|
test(rax);
|
2020-10-13 09:58:51 +02:00
|
|
|
jcc(je, dllret);
|
|
|
|
pushc(0)
|
|
|
|
ELSIF target = TARGETS.Linux64 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
push(rsp)
|
|
|
|
ELSE
|
|
|
|
pushc(0)
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(rax, entry, sCODE);
|
|
|
|
push(rax);
|
2020-05-25 22:48:33 +02:00
|
|
|
pushDA(0); (* TYPES *)
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(tcount);
|
2020-05-25 22:48:33 +02:00
|
|
|
pushDA(ModName_Offs); (* MODNAME *)
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._init);
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target IN {TARGETS.Win64C, TARGETS.Win64GUI, TARGETS.Linux64} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
L := NewLabel();
|
|
|
|
pushc(0);
|
|
|
|
push(rsp);
|
|
|
|
pushc(1024 * 1024 * stack_size);
|
|
|
|
pushc(0);
|
|
|
|
CallRTL(IL._new);
|
|
|
|
pop(rax);
|
|
|
|
test(rax);
|
|
|
|
jcc(je, L);
|
2020-05-25 22:48:33 +02:00
|
|
|
GetRegA;
|
2019-09-26 22:23:06 +02:00
|
|
|
addrc(rax, 1024 * 1024 * stack_size - 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
drop;
|
2019-09-26 22:23:06 +02:00
|
|
|
mov(rsp, rax);
|
|
|
|
X86.SetLabel(L)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END prolog;
|
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE epilog (modname: ARRAY OF CHAR; target: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
i, n: INTEGER;
|
|
|
|
number: Number;
|
2019-09-26 22:23:06 +02:00
|
|
|
exp: IL.EXPORT_PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE _import (imp: LISTS.LIST);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
lib: IL.IMPORT_LIB;
|
|
|
|
proc: IL.IMPORT_PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
lib := imp.first(IL.IMPORT_LIB);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE lib # NIL DO
|
|
|
|
BIN.Import(prog, lib.name, 0);
|
2019-09-26 22:23:06 +02:00
|
|
|
proc := lib.procs.first(IL.IMPORT_PROC);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE proc # NIL DO
|
|
|
|
BIN.Import(prog, proc.name, proc.label);
|
2019-09-26 22:23:06 +02:00
|
|
|
proc := proc.next(IL.IMPORT_PROC)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
lib := lib.next(IL.IMPORT_LIB)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
END _import;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.Win64DLL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
X86.SetLabel(dllret);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.ret
|
|
|
|
ELSIF target = TARGETS.Linux64SO THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
sofinit := NewLabel();
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.ret;
|
2019-09-26 22:23:06 +02:00
|
|
|
X86.SetLabel(sofinit);
|
|
|
|
CallRTL(IL._sofinit);
|
2020-05-25 22:48:33 +02:00
|
|
|
X86.ret
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
pushc(0);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._exit)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
X86.fixup;
|
|
|
|
|
|
|
|
i := 0;
|
2019-09-26 22:23:06 +02:00
|
|
|
WHILE i < tcount DO
|
2019-10-06 19:55:12 +02:00
|
|
|
BIN.PutData64LE(prog, CHL.GetInt(IL.codes.types, i));
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(i)
|
|
|
|
END;
|
|
|
|
|
|
|
|
i := 0;
|
2019-10-06 19:55:12 +02:00
|
|
|
WHILE i < CHL.Length(IL.codes.data) DO
|
|
|
|
BIN.PutData(prog, CHL.GetByte(IL.codes.data, i));
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(i)
|
|
|
|
END;
|
|
|
|
|
|
|
|
BIN.PutDataStr(prog, modname);
|
|
|
|
BIN.PutData(prog, 0);
|
|
|
|
n := CHL.Length(prog.data);
|
2019-09-26 22:23:06 +02:00
|
|
|
ASSERT(UTILS.Align(n, 16));
|
2019-03-11 09:59:55 +01:00
|
|
|
i := n - CHL.Length(prog.data);
|
|
|
|
WHILE i > 0 DO
|
|
|
|
BIN.PutData(prog, 0);
|
|
|
|
DEC(i)
|
|
|
|
END;
|
|
|
|
number := Numbers.first(Number);
|
|
|
|
FOR i := 0 TO Numbers_Count - 1 DO
|
|
|
|
BIN.PutData64LE(prog, number.value);
|
|
|
|
number := number.next(Number)
|
|
|
|
END;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
exp := IL.codes.export.first(IL.EXPORT_PROC);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE exp # NIL DO
|
|
|
|
BIN.Export(prog, exp.name, exp.label);
|
2019-09-26 22:23:06 +02:00
|
|
|
exp := exp.next(IL.EXPORT_PROC)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_import(IL.codes._import)
|
2019-03-11 09:59:55 +01:00
|
|
|
END epilog;
|
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE CodeGen* (outname: ARRAY OF CHAR; target: INTEGER; options: PROG.OPTIONS);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
path, modname, ext: PATHS.PATH;
|
|
|
|
|
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
Xmm[0] := 0;
|
2023-01-21 15:34:25 +01:00
|
|
|
X86.align16(TRUE);
|
2019-10-06 19:55:12 +02:00
|
|
|
tcount := CHL.Length(IL.codes.types);
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
Win64RegPar[0] := rcx;
|
|
|
|
Win64RegPar[1] := rdx;
|
|
|
|
Win64RegPar[2] := r8;
|
|
|
|
Win64RegPar[3] := r9;
|
|
|
|
|
|
|
|
SystemVRegPar[0] := rdi;
|
|
|
|
SystemVRegPar[1] := rsi;
|
|
|
|
SystemVRegPar[2] := rdx;
|
|
|
|
SystemVRegPar[3] := rcx;
|
|
|
|
SystemVRegPar[4] := r8;
|
|
|
|
SystemVRegPar[5] := r9;
|
|
|
|
|
|
|
|
PATHS.split(outname, path, modname, ext);
|
|
|
|
S.append(modname, ext);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
REG.Init(R, push, pop, mov, xchg, {rax, rcx, rdx, r8, r9, r10, r11});
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
IL.set_bss(MAX(IL.codes.bss, MAX(IL.codes.dmin - CHL.Length(IL.codes.data), 8)));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
Numbers := LISTS.create(NIL);
|
|
|
|
Numbers_Count := 0;
|
|
|
|
NewNumber(ROR(1, 1)); (* 8000000000000000H *)
|
|
|
|
NewNumber(0);
|
|
|
|
NewNumber(ROR(-2, 1)); (* 7FFFFFFFFFFFFFFFH *)
|
|
|
|
NewNumber(-1);
|
|
|
|
NewNumber(ROR(7FFH, 12)); (* +Infinity *)
|
|
|
|
NewNumber(ORD(-BITS(LSR(ASR(ROR(1, 1), 10), 1)))); (* {0..51, 63} *)
|
|
|
|
NewNumber(LSR(ASR(ROR(1, 1), 9), 2)); (* {52..61} *)
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
prog := BIN.create(IL.codes.lcount);
|
|
|
|
BIN.SetParams(prog, IL.codes.bss, 1, WCHR(1), WCHR(0));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
X86.SetProgram(prog);
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
prolog(modname, target, options.stack);
|
|
|
|
translate(IL.codes.commands, tcount * 8);
|
|
|
|
epilog(modname, target);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BIN.fixup(prog);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.OS = TARGETS.osWIN64 THEN
|
|
|
|
PE32.write(prog, outname, target = TARGETS.Win64C, target = TARGETS.Win64DLL, TRUE)
|
|
|
|
ELSIF TARGETS.OS = TARGETS.osLINUX64 THEN
|
|
|
|
ELF.write(prog, outname, sofinit, target = TARGETS.Linux64SO, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END CodeGen;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END AMD64.
|