2019-10-06 19:55:12 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
Copyright (c) 2018-2019, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE AMD64;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IMPORT IL, BIN, WR := WRITER, CHL := CHUNKLISTS, LISTS, PATHS, PROG,
|
2019-03-11 09:59:55 +01:00
|
|
|
REG, C := CONSOLE, UTILS, mConst := CONSTANTS, S := STRINGS, PE32, ELF, X86;
|
|
|
|
|
|
|
|
|
|
|
|
CONST
|
|
|
|
|
|
|
|
rax = REG.R0;
|
|
|
|
r10 = REG.R10;
|
|
|
|
r11 = REG.R11;
|
|
|
|
|
|
|
|
rcx = REG.R1;
|
|
|
|
rdx = REG.R2;
|
|
|
|
r8 = REG.R8;
|
|
|
|
r9 = REG.R9;
|
|
|
|
|
|
|
|
rsp = 4;
|
|
|
|
rbp = 5;
|
|
|
|
rsi = 6;
|
|
|
|
rdi = 7;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutByte (b: BYTE);
|
|
|
|
BEGIN
|
|
|
|
X86.OutByte(b)
|
|
|
|
END OutByte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutByte2 (a, b: BYTE);
|
|
|
|
BEGIN
|
|
|
|
OutByte(a);
|
|
|
|
OutByte(b)
|
|
|
|
END OutByte2;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutByte3 (a, b, c: BYTE);
|
|
|
|
BEGIN
|
|
|
|
OutByte(a);
|
|
|
|
OutByte(b);
|
|
|
|
OutByte(c)
|
|
|
|
END OutByte3;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutInt (n: INTEGER);
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte(UTILS.Byte(n, 0));
|
|
|
|
OutByte(UTILS.Byte(n, 1));
|
|
|
|
OutByte(UTILS.Byte(n, 2));
|
|
|
|
OutByte(UTILS.Byte(n, 3))
|
2019-03-11 09:59:55 +01:00
|
|
|
END OutInt;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isByte (n: INTEGER): BOOLEAN;
|
|
|
|
RETURN (-128 <= n) & (n <= 127)
|
|
|
|
END isByte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE short (n: INTEGER): INTEGER;
|
|
|
|
RETURN 2 * ORD(isByte(n))
|
|
|
|
END short;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE long (n: INTEGER): INTEGER;
|
|
|
|
RETURN 40H * ORD(~isByte(n))
|
|
|
|
END long;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutIntByte (n: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
IF isByte(n) THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte(UTILS.Byte(n, 0))
|
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);
|
|
|
|
OutByte2(8DH, 05H + 8 * (reg MOD 8)); // lea reg, [rip + offset]
|
|
|
|
X86.Reloc(section, offset)
|
|
|
|
END lea;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE oprr (op: BYTE; reg1, reg2: INTEGER); // op reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
Rex(reg1, reg2);
|
|
|
|
OutByte2(op, 0C0H + 8 * (reg2 MOD 8) + reg1 MOD 8)
|
|
|
|
END oprr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE oprr2 (op1, op2: BYTE; reg1, reg2: INTEGER); // op reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
Rex(reg1, reg2);
|
|
|
|
OutByte3(op1, op2, 0C0H + 8 * (reg2 MOD 8) + reg1 MOD 8)
|
|
|
|
END oprr2;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE mov (reg1, reg2: INTEGER); // mov reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(89H, reg1, reg2)
|
|
|
|
END mov;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE xor (reg1, reg2: INTEGER); // xor reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(31H, reg1, reg2)
|
|
|
|
END xor;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE and (reg1, reg2: INTEGER); // and reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(21H, reg1, reg2)
|
|
|
|
END and;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE or (reg1, reg2: INTEGER); // and reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(09H, reg1, reg2)
|
|
|
|
END or;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE add (reg1, reg2: INTEGER); // add reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(01H, reg1, reg2)
|
|
|
|
END add;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE sub (reg1, reg2: INTEGER); // sub reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(29H, reg1, reg2)
|
|
|
|
END sub;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE xchg (reg1, reg2: INTEGER); // xchg reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(87H, reg1, reg2)
|
|
|
|
END xchg;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE cmprr (reg1, reg2: INTEGER); // cmp reg1, reg2
|
|
|
|
BEGIN
|
|
|
|
oprr(39H, reg1, reg2)
|
|
|
|
END cmprr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE pop (reg: INTEGER); // pop reg
|
|
|
|
BEGIN
|
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte(58H + reg MOD 8)
|
|
|
|
END pop;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE push (reg: INTEGER); // push reg
|
|
|
|
BEGIN
|
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte(50H + reg MOD 8)
|
|
|
|
END push;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE decr (reg: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0FFH, 0C8H + reg MOD 8) // dec reg1
|
|
|
|
END decr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE incr (reg: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0FFH, 0C0H + reg MOD 8) // inc reg1
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetVarReg (offs: INTEGER): INTEGER;
|
|
|
|
RETURN REG.GetVarReg(R, offs)
|
|
|
|
END GetVarReg;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE callimp (label: 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, label, sIMP);
|
|
|
|
IF reg >= 8 THEN // call qword[reg]
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte2(0FFH, 10H + reg MOD 8);
|
|
|
|
drop
|
|
|
|
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
|
|
|
|
REG.Store(R);
|
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)
|
|
|
|
END;
|
|
|
|
REG.Restore(R)
|
|
|
|
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);
|
|
|
|
OutByte(0B8H + reg MOD 8); // movabs reg, n
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movrc (reg, n: INTEGER); // mov reg, n
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE test (reg: INTEGER); // test reg, reg
|
|
|
|
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();
|
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);
|
|
|
|
OutByte2(81H + short(n), op + reg MOD 8);
|
|
|
|
OutIntByte(n)
|
|
|
|
END
|
|
|
|
END oprc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE cmprc (reg, n: INTEGER); // cmp reg, n
|
|
|
|
BEGIN
|
|
|
|
oprc(0F8H, reg, n, cmprr)
|
|
|
|
END cmprc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE addrc (reg, n: INTEGER); // add reg, n
|
|
|
|
BEGIN
|
|
|
|
oprc(0C0H, reg, n, add)
|
|
|
|
END addrc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE subrc (reg, n: INTEGER); // sub reg, n
|
|
|
|
BEGIN
|
|
|
|
oprc(0E8H, reg, n, sub)
|
|
|
|
END subrc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE andrc (reg, n: INTEGER); // and reg, n
|
|
|
|
BEGIN
|
|
|
|
oprc(0E0H, reg, n, and)
|
|
|
|
END andrc;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
OutByte(68H + short(n)); OutIntByte(n) // push n
|
|
|
|
END
|
|
|
|
END pushc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE not (reg: INTEGER); // not reg
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0F7H, 0D0H + reg MOD 8)
|
|
|
|
END not;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE neg (reg: INTEGER); // neg reg
|
|
|
|
BEGIN
|
|
|
|
Rex(reg, 0);
|
|
|
|
OutByte2(0F7H, 0D8H + reg MOD 8)
|
|
|
|
END neg;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movzx (reg1, reg2, offs: INTEGER; word: BOOLEAN); // movzx reg1, byte/word[reg2 + offs]
|
|
|
|
VAR
|
|
|
|
b: BYTE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
Rex(reg2, reg1);
|
|
|
|
OutByte2(0FH, 0B6H + ORD(word));
|
|
|
|
IF (offs = 0) & (reg2 # rbp) THEN
|
|
|
|
b := 0
|
|
|
|
ELSE
|
|
|
|
b := 40H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + (reg1 MOD 8) * 8 + reg2 MOD 8);
|
|
|
|
IF reg2 = rsp THEN
|
|
|
|
OutByte(24H)
|
|
|
|
END;
|
|
|
|
IF b # 0 THEN
|
|
|
|
OutIntByte(offs)
|
|
|
|
END
|
|
|
|
END movzx;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE _movrm (reg1, reg2, offs, size: INTEGER; mr: BOOLEAN);
|
|
|
|
VAR
|
|
|
|
b: BYTE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF size = 16 THEN
|
|
|
|
OutByte(66H)
|
|
|
|
END;
|
|
|
|
IF (reg1 >= 8) OR (reg2 >= 8) OR (size = 64) THEN
|
|
|
|
OutByte(40H + reg2 DIV 8 + 4 * (reg1 DIV 8) + 8 * ORD(size = 64))
|
|
|
|
END;
|
|
|
|
OutByte(8BH - 2 * ORD(mr) - ORD(size = 8));
|
|
|
|
IF (offs = 0) & (reg2 # rbp) THEN
|
|
|
|
b := 0
|
|
|
|
ELSE
|
|
|
|
b := 40H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + (reg1 MOD 8) * 8 + reg2 MOD 8);
|
|
|
|
IF reg2 = rsp THEN
|
|
|
|
OutByte(24H)
|
|
|
|
END;
|
|
|
|
IF b # 0 THEN
|
|
|
|
OutIntByte(offs)
|
|
|
|
END
|
|
|
|
END _movrm;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movmr32 (reg1, offs, reg2: INTEGER); // mov dword[reg1+offs], reg2_32
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg2, reg1, offs, 32, TRUE)
|
|
|
|
END movmr32;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movrm32 (reg1, reg2, offs: INTEGER); // mov reg1_32, dword[reg2+offs]
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg1, reg2, offs, 32, FALSE)
|
|
|
|
END movrm32;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movmr8 (reg1, offs, reg2: INTEGER); // mov byte[reg1+offs], reg2_8
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg2, reg1, offs, 8, TRUE)
|
|
|
|
END movmr8;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movrm8 (reg1, reg2, offs: INTEGER); // mov reg1_8, byte[reg2+offs]
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg1, reg2, offs, 8, FALSE)
|
|
|
|
END movrm8;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movmr16 (reg1, offs, reg2: INTEGER); // mov word[reg1+offs], reg2_16
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg2, reg1, offs, 16, TRUE)
|
|
|
|
END movmr16;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movrm16 (reg1, reg2, offs: INTEGER); // mov reg1_16, word[reg2+offs]
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg1, reg2, offs, 16, FALSE)
|
|
|
|
END movrm16;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movmr (reg1, offs, reg2: INTEGER); // mov qword[reg1+offs], reg2
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg2, reg1, offs, 64, TRUE)
|
|
|
|
END movmr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movrm (reg1, reg2, offs: INTEGER); // mov reg1, qword[reg2+offs]
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg1, reg2, offs, 64, FALSE)
|
|
|
|
END movrm;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE pushm (reg, offs: INTEGER); // push qword[reg+offs]
|
|
|
|
VAR
|
|
|
|
b: BYTE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte(0FFH);
|
|
|
|
IF (offs = 0) & (reg # rbp) THEN
|
|
|
|
b := 30H
|
|
|
|
ELSE
|
|
|
|
b := 70H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + reg MOD 8);
|
|
|
|
IF reg = rsp THEN
|
|
|
|
OutByte(24H)
|
|
|
|
END;
|
|
|
|
IF b # 30H THEN
|
|
|
|
OutIntByte(offs)
|
|
|
|
END
|
|
|
|
END pushm;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE comisd (xmm1, xmm2: INTEGER); // comisd xmm1, xmm2
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movsdrm (xmm, reg, offs: INTEGER); // movsd xmm, qword[reg+offs]
|
|
|
|
BEGIN
|
|
|
|
_movsdrm(xmm, reg, offs, FALSE)
|
|
|
|
END movsdrm;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movsdmr (reg, offs, xmm: INTEGER); // movsd qword[reg+offs], xmm
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE jcc (cc, label: INTEGER); // jcc label
|
|
|
|
BEGIN
|
|
|
|
X86.jcc(cc, label)
|
|
|
|
END jcc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE jmp (label: INTEGER); // jmp label
|
|
|
|
BEGIN
|
|
|
|
X86.jmp(label)
|
|
|
|
END jmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE setcc (cc, reg: INTEGER); //setcc reg8
|
|
|
|
BEGIN
|
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, cc, 0C0H + reg MOD 8)
|
|
|
|
END setcc;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE getVar (variables: LISTS.LIST; offset: INTEGER): IL.LOCALVAR;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
cur: IL.LOCALVAR;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
2019-09-26 22:23:06 +02:00
|
|
|
cur := variables.first(IL.LOCALVAR);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE (cur # NIL) & (cur.offset # offset) DO
|
2019-09-26 22:23:06 +02:00
|
|
|
cur := cur.next(IL.LOCALVAR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN cur
|
|
|
|
END getVar;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE allocReg (cmd: COMMAND);
|
|
|
|
VAR
|
|
|
|
leave: BOOLEAN;
|
|
|
|
leaf: BOOLEAN;
|
|
|
|
cur: COMMAND;
|
|
|
|
variables: LISTS.LIST;
|
2019-09-26 22:23:06 +02:00
|
|
|
lvar, rvar: IL.LOCALVAR;
|
2019-03-11 09:59:55 +01:00
|
|
|
reg: INTEGER;
|
|
|
|
max: INTEGER;
|
|
|
|
loop: INTEGER;
|
2019-06-04 09:22:50 +02:00
|
|
|
param2: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
loop := 1;
|
|
|
|
variables := cmd.variables;
|
|
|
|
leave := FALSE;
|
|
|
|
leaf := TRUE;
|
|
|
|
|
|
|
|
cur := cmd.next(COMMAND);
|
|
|
|
REPEAT
|
|
|
|
CASE cur.opcode OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD64,
|
|
|
|
IL.opLLOAD8,
|
|
|
|
IL.opLLOAD16,
|
|
|
|
IL.opLLOAD32,
|
|
|
|
IL.opLLOAD64_PARAM,
|
|
|
|
IL.opLLOAD32_PARAM,
|
|
|
|
IL.opLADR_SAVE,
|
|
|
|
IL.opLADR_INC,
|
|
|
|
IL.opLADR_DEC,
|
|
|
|
IL.opLADR_INCB,
|
|
|
|
IL.opLADR_DECB,
|
|
|
|
IL.opLADR_INCL,
|
|
|
|
IL.opLADR_EXCL,
|
|
|
|
IL.opLADR_UNPK:
|
2019-03-11 09:59:55 +01:00
|
|
|
lvar := getVar(variables, cur.param2);
|
|
|
|
IF (lvar # NIL) & (lvar.count # -1) THEN
|
|
|
|
INC(lvar.count, loop)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_SAVEC,
|
|
|
|
IL.opLADR_INCC,
|
|
|
|
IL.opLADR_INCCB,
|
|
|
|
IL.opLADR_DECCB,
|
|
|
|
IL.opLADR_INCLC,
|
|
|
|
IL.opLADR_EXCLC:
|
2019-03-11 09:59:55 +01:00
|
|
|
lvar := getVar(variables, cur.param1);
|
|
|
|
IF (lvar # NIL) & (lvar.count # -1) THEN
|
|
|
|
INC(lvar.count, loop)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR:
|
2019-03-11 09:59:55 +01:00
|
|
|
lvar := getVar(variables, cur.param2);
|
|
|
|
IF (lvar # NIL) & (lvar.count # -1) THEN
|
|
|
|
lvar.count := -1
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOOP:
|
2019-03-11 09:59:55 +01:00
|
|
|
INC(loop, 10)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opENDLOOP:
|
2019-03-11 09:59:55 +01:00
|
|
|
DEC(loop, 10)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLEAVE,
|
|
|
|
IL.opLEAVER,
|
|
|
|
IL.opLEAVEF:
|
2019-03-11 09:59:55 +01:00
|
|
|
leave := TRUE
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALL, IL.opCALLP, IL.opCALLI,
|
|
|
|
IL.opWIN64CALL, IL.opWIN64CALLP, IL.opWIN64CALLI,
|
|
|
|
IL.opSYSVCALL, IL.opSYSVCALLP, IL.opSYSVCALLI,
|
|
|
|
|
|
|
|
IL.opSAVES, IL.opRSET, IL.opRSETR,
|
|
|
|
IL.opRSETL, IL.opRSET1,
|
|
|
|
IL.opEQS .. IL.opGES,
|
|
|
|
IL.opEQSW .. IL.opGESW,
|
|
|
|
IL.opCOPY, IL.opMOVE, IL.opCOPYA,
|
|
|
|
IL.opCOPYS, IL.opROT,
|
|
|
|
IL.opNEW, IL.opDISP, IL.opISREC,
|
|
|
|
IL.opIS, IL.opTYPEGR, IL.opTYPEGP,
|
2019-10-06 19:55:12 +02:00
|
|
|
IL.opTYPEGD, IL.opCASET, IL.opDIV,
|
2019-09-26 22:23:06 +02:00
|
|
|
IL.opDIVL, IL.opMOD,
|
|
|
|
IL.opMODL, IL.opLENGTH, IL.opLENGTHW:
|
2019-03-11 09:59:55 +01:00
|
|
|
leaf := FALSE
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVR, IL.opMODR:
|
2019-06-04 09:22:50 +02:00
|
|
|
param2 := cur.param2;
|
|
|
|
IF param2 >= 1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
param2 := UTILS.Log2(param2)
|
2019-06-04 09:22:50 +02:00
|
|
|
ELSIF param2 <= -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
param2 := UTILS.Log2(-param2)
|
2019-06-04 09:22:50 +02:00
|
|
|
ELSE
|
|
|
|
param2 := -1
|
|
|
|
END;
|
|
|
|
IF param2 < 0 THEN
|
|
|
|
leaf := FALSE
|
|
|
|
END
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
|
|
|
|
END;
|
|
|
|
cur := cur.next(COMMAND)
|
|
|
|
UNTIL leave OR ~leaf;
|
|
|
|
|
|
|
|
IF leaf THEN
|
|
|
|
REPEAT
|
|
|
|
reg := -1;
|
|
|
|
max := -1;
|
|
|
|
rvar := NIL;
|
2019-09-26 22:23:06 +02:00
|
|
|
lvar := variables.first(IL.LOCALVAR);
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE lvar # NIL DO
|
|
|
|
IF lvar.count > max THEN
|
|
|
|
max := lvar.count;
|
|
|
|
rvar := lvar
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
lvar := lvar.next(IL.LOCALVAR)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
IF rvar # NIL THEN
|
|
|
|
reg := REG.GetAnyVarReg(R);
|
|
|
|
IF reg # -1 THEN
|
|
|
|
REG.Lock(R, reg, rvar.offset, rvar.size);
|
|
|
|
REG.Load(R, reg);
|
|
|
|
rvar.count := -1
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
|
|
|
UNTIL (rvar = NIL) OR (reg = -1)
|
|
|
|
END
|
|
|
|
|
|
|
|
END allocReg;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
ASSERT(r10 IN R.regs);
|
|
|
|
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
|
|
|
|
movrm(r10, rsp, ofs);
|
|
|
|
movmr(rsp, p, r10);
|
|
|
|
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;
|
|
|
|
OutByte2(7AH, 3 + reg DIV 8); // jp L
|
|
|
|
setcc(cc, reg);
|
|
|
|
//L:
|
|
|
|
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
|
|
|
|
|
|
|
reg1, reg2, xmm: INTEGER;
|
|
|
|
|
|
|
|
float: REAL;
|
|
|
|
|
|
|
|
regVar: BOOLEAN;
|
|
|
|
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
jmp(param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALL, IL.opWIN64CALL, IL.opSYSVCALL:
|
2019-03-11 09:59:55 +01:00
|
|
|
REG.Store(R);
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE opcode OF
|
|
|
|
|IL.opCALL:
|
|
|
|
|IL.opWIN64CALL: Win64Passing(param2)
|
|
|
|
|IL.opSYSVCALL: SysVPassing(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
X86.call(param1);
|
|
|
|
REG.Restore(R)
|
|
|
|
|
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
|
|
|
|
GetRegA;
|
|
|
|
ASSERT(REG.Exchange(R, reg1, rax));
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
drop;
|
|
|
|
REG.Store(R);
|
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;
|
|
|
|
OutByte2(0FFH, 0D0H); // call rax
|
|
|
|
REG.Restore(R);
|
|
|
|
ASSERT(R.top = -1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALLI, IL.opWIN64CALLI, IL.opSYSVCALLI:
|
2019-03-11 09:59:55 +01:00
|
|
|
REG.Store(R);
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE opcode OF
|
|
|
|
|IL.opCALLI:
|
|
|
|
|IL.opWIN64CALLI: Win64Passing(param2)
|
|
|
|
|IL.opSYSVCALLI: SysVPassing(param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
callimp(param1);
|
|
|
|
REG.Restore(R)
|
|
|
|
|
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
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2;
|
|
|
|
IF (param1 # 0) & (n # 0) THEN
|
|
|
|
subrc(rsp, 8)
|
|
|
|
END;
|
|
|
|
WHILE n > 0 DO
|
|
|
|
subrc(rsp, 8);
|
|
|
|
movsdmr(rsp, 0, xmm);
|
|
|
|
DEC(xmm);
|
|
|
|
DEC(n)
|
|
|
|
END;
|
|
|
|
ASSERT(xmm = -1);
|
|
|
|
PushAll(0)
|
|
|
|
|
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
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opRESF:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(xmm = -1);
|
|
|
|
INC(xmm);
|
|
|
|
n := param2;
|
|
|
|
IF n > 0 THEN
|
|
|
|
movsdmr(rsp, n * 8, xmm);
|
|
|
|
DEC(xmm);
|
|
|
|
INC(n)
|
|
|
|
END;
|
|
|
|
|
|
|
|
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.opRES:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(R.top = -1);
|
|
|
|
GetRegA;
|
|
|
|
n := param2;
|
|
|
|
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;
|
|
|
|
pop(r10);
|
|
|
|
subrc(rsp, n);
|
|
|
|
push(r10);
|
|
|
|
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
|
|
|
|
movrm(r10, rbp, n + c);
|
|
|
|
movmr(rbp, i, r10);
|
|
|
|
INC(c, 8)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
IF a <= 5 THEN
|
|
|
|
movmr(rbp, i, SystemVRegPar[a]);
|
|
|
|
INC(a)
|
|
|
|
ELSE
|
|
|
|
movrm(r10, rbp, n + c);
|
|
|
|
movmr(rbp, i, r10);
|
|
|
|
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);
|
|
|
|
// L:
|
|
|
|
pushc(0);
|
|
|
|
OutByte2(0E2H, 0FCH) // loop L
|
|
|
|
ELSE
|
|
|
|
WHILE n > 0 DO
|
|
|
|
pushc(0);
|
|
|
|
DEC(n)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF cmd.allocReg THEN
|
|
|
|
allocReg(cmd)
|
|
|
|
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
|
|
|
|
GetRegA;
|
|
|
|
ASSERT(REG.Exchange(R, reg1, rax));
|
|
|
|
drop
|
|
|
|
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
|
|
|
|
OutByte3(0C2H, (param2 * 8) MOD 256, (param2 * 8) DIV 256) // ret param2
|
|
|
|
ELSE
|
|
|
|
OutByte(0C3H) // ret
|
|
|
|
END;
|
|
|
|
REG.Reset(R)
|
|
|
|
|
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();
|
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
|
|
|
mov(reg1, reg2)
|
|
|
|
ELSE
|
|
|
|
movrm(reg1, rbp, param2 * 8)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD8,
|
|
|
|
IL.opLLOAD16:
|
|
|
|
reg1 := GetAnyReg();
|
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
|
|
|
mov(reg1, reg2)
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
movzx(reg1, rbp, param2 * 8, opcode = IL.opLLOAD16)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD32:
|
|
|
|
reg1 := GetAnyReg();
|
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
|
|
|
mov(reg1, reg2)
|
|
|
|
ELSE
|
|
|
|
n := param2 * 8;
|
|
|
|
xor(reg1, reg1);
|
|
|
|
movrm32(reg1, rbp, n)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD64:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, param2, sBSS);
|
|
|
|
movrm(reg1, reg1, 0)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD8:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, param2, sBSS);
|
|
|
|
movzx(reg1, reg1, 0, FALSE)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD16:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, param2, sBSS);
|
|
|
|
movzx(reg1, reg1, 0, TRUE)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD32:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
xor(reg1, reg1);
|
|
|
|
lea(reg1, param2, sBSS);
|
|
|
|
movrm32(reg1, reg1, 0)
|
|
|
|
|
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
|
|
|
xor(reg1, reg1);
|
|
|
|
movrm(reg2, rbp, param2 * 8);
|
|
|
|
movrm32(reg1, reg2, 0);
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF next.opcode = IL.opSAVEF THEN
|
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);
|
|
|
|
movsdrm(xmm, rbp, n);
|
|
|
|
cmd := next
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(0, reg1);
|
|
|
|
OutByte2(8DH, 45H + long(n) + (reg1 MOD 8) * 8); // lea reg1, qword[rbp+n]
|
|
|
|
OutIntByte(n)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGADR:
|
|
|
|
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;
|
|
|
|
OutByte3(0C6H, reg1 MOD 8, param2); // mov byte[reg1], param2
|
|
|
|
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);
|
|
|
|
OutByte2(param2 MOD 256, param2 DIV 256); // mov word[reg1], param2
|
|
|
|
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);
|
|
|
|
OutByte2(0C7H, reg1 MOD 8); // mov qword[reg1], param2
|
|
|
|
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);
|
|
|
|
OutByte2(73H, 04H); // jnb L
|
|
|
|
Rex(reg2, reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte3(0FH, 0ABH + 8 * ORD(opcode = IL.opEXCL), 8 * (reg1 MOD 8) + reg2 MOD 8); // bts/btr qword[reg2], reg1
|
2019-03-11 09:59:55 +01:00
|
|
|
// L:
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
IF param2 = 0 THEN
|
|
|
|
test(reg1)
|
|
|
|
ELSE
|
|
|
|
cmprc(reg1, param2)
|
|
|
|
END
|
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
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF cmd.next(COMMAND).opcode = IL.opJE THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
label := cmd.next(COMMAND).param1;
|
|
|
|
jcc(cc, label);
|
|
|
|
cmd := cmd.next(COMMAND)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF cmd.next(COMMAND).opcode = IL.opJNE THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
label := cmd.next(COMMAND).param1;
|
2019-09-26 22:23:06 +02:00
|
|
|
jcc(X86.inv0(cc), label);
|
2019-03-11 09:59:55 +01:00
|
|
|
cmd := cmd.next(COMMAND)
|
|
|
|
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(cc + 16, reg1);
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2;
|
|
|
|
IF n = 1 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
push(reg1);
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
ASSERT(R.top + 1 <= n);
|
|
|
|
PushAll(n)
|
2019-09-26 22:23:06 +02:00
|
|
|
END
|
|
|
|
|
|
|
|
|IL.opACC:
|
2019-06-04 09:22:50 +02:00
|
|
|
IF (R.top # 0) OR (R.stk[0] # rax) THEN
|
|
|
|
PushAll(0);
|
|
|
|
GetRegA;
|
|
|
|
pop(rax);
|
|
|
|
DEC(R.pushed)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opJNZ:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(jne, param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opJZ:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(je, param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opJE:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(jne, param1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opJNE:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
test(reg1);
|
|
|
|
jcc(je, param1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opIN:
|
2019-03-11 09:59:55 +01:00
|
|
|
label := NewLabel();
|
|
|
|
L := NewLabel();
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprc(reg1, 64);
|
|
|
|
jcc(jb, L);
|
|
|
|
xor(reg1, reg1);
|
|
|
|
jmp(label);
|
|
|
|
X86.SetLabel(L);
|
|
|
|
Rex(reg2, reg1);
|
|
|
|
OutByte3(0FH, 0A3H, 0C0H + 8 * (reg1 MOD 8) + reg2 MOD 8); // bt reg2, reg1
|
|
|
|
setcc(setc, reg1);
|
|
|
|
andrc(reg1, 1);
|
|
|
|
X86.SetLabel(label);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINR:
|
2019-03-11 09:59:55 +01:00
|
|
|
label := NewLabel();
|
|
|
|
L := NewLabel();
|
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(reg1, 64);
|
|
|
|
jcc(jb, L);
|
|
|
|
xor(reg1, reg1);
|
|
|
|
jmp(label);
|
|
|
|
X86.SetLabel(L);
|
|
|
|
movrc(reg2, param2);
|
|
|
|
Rex(reg2, reg1);
|
|
|
|
OutByte3(0FH, 0A3H, 0C0H + 8 * (reg1 MOD 8) + reg2 MOD 8); // bt reg2, reg1
|
|
|
|
setcc(setc, reg1);
|
|
|
|
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);
|
|
|
|
OutByte2(0FH, 0BAH); // bt reg1, param2
|
|
|
|
OutByte2(0E0H + reg1 MOD 8, param2);
|
|
|
|
setcc(setc, reg1);
|
|
|
|
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);
|
|
|
|
setcc(sete, reg1);
|
|
|
|
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);
|
|
|
|
setcc(setne, reg1);
|
|
|
|
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);
|
|
|
|
OutByte2(7DH, 03H); // jge L
|
|
|
|
neg(reg1)
|
|
|
|
// L:
|
|
|
|
|
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
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(sete, reg1)
|
|
|
|
ELSE
|
|
|
|
setcc(setne, reg1)
|
|
|
|
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)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVSC, IL.opADDSL, IL.opADDSR:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
Rex(reg1, 0);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(81H + short(param2), 0C8H + 28H * ORD(opcode = IL.opDIVSC) + reg1 MOD 8); // or/xor reg1, param2
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(param2)
|
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
|
|
|
pushc(param2);
|
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.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);
|
|
|
|
n := param2 + 16;
|
2019-09-26 22:23:06 +02:00
|
|
|
ASSERT(UTILS.Align(n, 64));
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrm(reg2, reg1, -8)
|
|
|
|
|
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);
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
push(r10);
|
|
|
|
push(r10);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(IL._guardrec);
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(r10);
|
|
|
|
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);
|
|
|
|
// add/sub qword[reg2], reg1
|
|
|
|
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);
|
2019-09-26 22:23:06 +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);
|
|
|
|
OutByte2(0FFH, reg1 MOD 8 + 8 * ORD(param2 = -1)) // inc/dec qword[reg1]
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +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);
|
|
|
|
movmr8(reg1, 0, reg2);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE16:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
|
|
|
movmr16(reg1, 0, reg2);
|
|
|
|
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
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMIN:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprr(reg1, reg2);
|
|
|
|
OutByte2(7EH, 3); // jle L
|
|
|
|
mov(reg1, reg2);
|
|
|
|
// L:
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMAX:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprr(reg1, reg2);
|
|
|
|
OutByte2(7DH, 3); // jge L
|
|
|
|
mov(reg1, reg2);
|
|
|
|
// L:
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMINC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
cmprc(reg1, param2);
|
|
|
|
label := NewLabel();
|
|
|
|
jcc(jle, label);
|
|
|
|
movrc(reg1, param2);
|
|
|
|
X86.SetLabel(label)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMAXC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
cmprc(reg1, param2);
|
|
|
|
label := NewLabel();
|
|
|
|
jcc(jge, label);
|
|
|
|
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;
|
|
|
|
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;
|
2019-09-26 22:23:06 +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.opODD:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, 1)
|
|
|
|
|
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);
|
|
|
|
n := param2;
|
|
|
|
IF n = 1 THEN
|
|
|
|
decr(reg1)
|
|
|
|
ELSIF n = -1 THEN
|
|
|
|
incr(reg1)
|
|
|
|
ELSIF n # 0 THEN
|
|
|
|
subrc(reg1, n)
|
|
|
|
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
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opADDL, IL.opADDR:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF param2 # 0 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
IF param2 = 1 THEN
|
|
|
|
incr(reg1)
|
|
|
|
ELSIF param2 = -1 THEN
|
|
|
|
decr(reg1)
|
|
|
|
ELSE
|
|
|
|
addrc(reg1, param2)
|
|
|
|
END
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
a := param2;
|
|
|
|
IF a > 1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
n := UTILS.Log2(a)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF a < -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
n := UTILS.Log2(-a)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
n := -1
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF a = 1 THEN
|
|
|
|
|
|
|
|
ELSIF a = -1 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
neg(reg1)
|
|
|
|
ELSE
|
|
|
|
IF n > 0 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
|
|
|
|
IF a < 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
mov(reg2, reg1);
|
|
|
|
shiftrc(sar, reg1, n);
|
|
|
|
sub(reg1, reg2);
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
shiftrc(sar, reg1, n)
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
PushAll(1);
|
|
|
|
pushc(param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(IL._divmod);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
END
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
a := param2;
|
|
|
|
IF a > 1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
n := UTILS.Log2(a)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF a < -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
n := UTILS.Log2(-a)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
n := -1
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF ABS(a) = 1 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
xor(reg1, reg1)
|
|
|
|
ELSE
|
|
|
|
IF n > 0 THEN
|
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, ABS(a) - 1);
|
|
|
|
|
|
|
|
IF a < 0 THEN
|
|
|
|
test(reg1);
|
|
|
|
label := NewLabel();
|
|
|
|
jcc(je, label);
|
|
|
|
addrc(reg1, a);
|
|
|
|
X86.SetLabel(label)
|
|
|
|
END
|
|
|
|
|
|
|
|
ELSE
|
|
|
|
PushAll(1);
|
|
|
|
pushc(param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(IL._divmod);
|
|
|
|
mov(rax, rdx);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
END
|
|
|
|
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);
|
|
|
|
oprr2(0FH, 0AFH, reg2, reg1); // imul reg1, reg2
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
|
|
|
|
a := param2;
|
|
|
|
IF a > 1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
n := UTILS.Log2(a)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF a < -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
n := UTILS.Log2(-a)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
n := -1
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF a = 1 THEN
|
|
|
|
|
|
|
|
ELSIF a = -1 THEN
|
|
|
|
neg(reg1)
|
|
|
|
ELSIF a = 0 THEN
|
|
|
|
xor(reg1, reg1)
|
|
|
|
ELSE
|
|
|
|
IF n > 0 THEN
|
|
|
|
IF a < 0 THEN
|
|
|
|
neg(reg1)
|
|
|
|
END;
|
|
|
|
shiftrc(shl, reg1, n)
|
|
|
|
ELSE
|
|
|
|
// imul reg1, a
|
|
|
|
Rex(reg1, reg1);
|
|
|
|
OutByte2(69H + short(a), 0C0H + (reg1 MOD 8) * 9);
|
|
|
|
OutIntByte(a)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opADDS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
or(reg1, reg2);
|
|
|
|
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
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opNOP:
|
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
|
|
|
|
reg2 := r10
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(rax, param1);
|
|
|
|
jcc(jl, param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASER:
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(rax, param1);
|
|
|
|
jcc(jg, param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASELR:
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(rax, param1);
|
|
|
|
jcc(jl, param2);
|
|
|
|
jcc(jg, cmd.param3)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR, IL.opROR, IL.opLSL, IL.opLSR:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
xchg(reg2, rcx);
|
|
|
|
Rex(reg1, 0);
|
|
|
|
OutByte(0D3H);
|
2019-09-26 22:23:06 +02:00
|
|
|
X86.shift(opcode, reg1 MOD 8); // shift reg1, cl
|
2019-03-11 09:59:55 +01:00
|
|
|
xchg(reg2, rcx);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR1, IL.opROR1, IL.opLSL1, IL.opLSR1:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(reg1, param2);
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
xchg(reg1, rcx);
|
|
|
|
Rex(reg2, 0);
|
|
|
|
OutByte(0D3H);
|
2019-09-26 22:23:06 +02:00
|
|
|
X86.shift(opcode, reg2 MOD 8); // shift reg2, cl
|
2019-03-11 09:59:55 +01:00
|
|
|
xchg(reg1, rcx);
|
|
|
|
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;
|
|
|
|
_movrm(reg1, reg1, 0, param2 * 8, FALSE);
|
|
|
|
_movrm(reg1, reg2, 0, param2 * 8, TRUE)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCHKBYTE:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprc(reg1, 256);
|
|
|
|
jcc(jb, param1)
|
|
|
|
|
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);
|
|
|
|
mov(reg1, reg2);
|
|
|
|
drop;
|
|
|
|
jcc(jb, param1)
|
|
|
|
ELSE
|
|
|
|
INCL(R.regs, reg1);
|
|
|
|
DEC(R.top);
|
|
|
|
R.stk[R.top] := reg2
|
|
|
|
END
|
|
|
|
|
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.opCHR:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, 255)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opWCHR:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
andrc(reg1, 65535)
|
|
|
|
|
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
|
|
|
|
|IL.opEQP, IL.opEQIP: setcc(sete, reg1)
|
|
|
|
|IL.opNEP, IL.opNEIP: 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;
|
2019-09-26 22:23:06 +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;
|
2019-09-26 22:23:06 +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;
|
|
|
|
OutByte2(8FH, reg1 MOD 8); // pop qword[reg1]
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCLEANUP:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 8;
|
|
|
|
IF n # 0 THEN
|
|
|
|
addrc(rsp, n)
|
|
|
|
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);
|
|
|
|
movsdrm(xmm, reg1, 0);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHF:
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, Numbers_Offs + Numbers_Count * 8, sDATA);
|
|
|
|
movsdrm(xmm, reg1, 0);
|
|
|
|
drop;
|
|
|
|
NewNumber(UTILS.splitf(float, a, b))
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEF:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
movsdmr(reg1, 0, xmm);
|
|
|
|
DEC(xmm);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opADDF, IL.opADDFI:
|
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:
|
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:
|
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:
|
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:
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
opxx(5EH, xmm, xmm - 1);
|
|
|
|
opxx(10H, xmm - 1, xmm);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opUMINF:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, Numbers_Offs, sDATA);
|
|
|
|
OutByte3(66H, 40H + reg1 DIV 8 + (xmm DIV 8) * 4, 0FH); // xorpd xmm, xmmword[reg1]
|
|
|
|
OutByte2(57H, reg1 MOD 8 + (xmm MOD 8) * 8);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFABS:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, Numbers_Offs + 16, sDATA);
|
|
|
|
OutByte3(66H, 40H + reg1 DIV 8 + (xmm DIV 8) * 4, 0FH); // andpd xmm, xmmword[reg1]
|
|
|
|
OutByte2(54H, reg1 MOD 8 + (xmm MOD 8) * 8);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFLT:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
INC(xmm);
|
|
|
|
OutByte(0F2H); Rex(reg1, xmm); OutByte(0FH); // cvtsi2sd xmm, reg1
|
|
|
|
OutByte2(2AH, 0C0H + (xmm MOD 8) * 8 + reg1 MOD 8);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFLOOR:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(rsp, 8);
|
|
|
|
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
|
|
|
|
OutByte2(2DH, 0C0H + xmm MOD 8 + (reg1 MOD 8) * 8);
|
|
|
|
OutByte3(00FH, 0AEH, 054H); OutByte2(024H, 004H); // ldmxcsr dword[rsp+4];
|
|
|
|
addrc(rsp, 8);
|
|
|
|
DEC(xmm)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQF .. IL.opGEF:
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg1, Numbers_Offs + 32, sDATA);
|
|
|
|
movsdrm(xmm, reg1, 0);
|
|
|
|
drop
|
|
|
|
|
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);
|
|
|
|
lea(reg1, Numbers_Offs + 40, sDATA); // {0..51, 63}
|
|
|
|
movrm(reg1, reg1, 0);
|
|
|
|
and(reg2, reg1);
|
|
|
|
pop(reg1);
|
|
|
|
|
|
|
|
or(reg2, reg1);
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
regVar := reg2 # -1;
|
|
|
|
IF ~regVar THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Rex(0, reg2);
|
|
|
|
OutByte2(8DH, 45H + long(n) + (reg2 MOD 8) * 8); // lea reg2, qword[rbp+n]
|
|
|
|
OutIntByte(n)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
regVar := FALSE
|
|
|
|
END;
|
|
|
|
|
|
|
|
push(reg1);
|
|
|
|
movrm(reg1, reg1, 0);
|
|
|
|
shiftrc(shl, reg1, 1);
|
|
|
|
shiftrc(shr, reg1, 53);
|
|
|
|
subrc(reg1, 1023);
|
|
|
|
|
|
|
|
IF regVar THEN
|
|
|
|
mov(reg2, reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg()
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
movmr(reg2, 0, reg1)
|
|
|
|
END;
|
|
|
|
|
|
|
|
pop(reg2);
|
|
|
|
movrm(reg1, reg2, 0);
|
|
|
|
|
|
|
|
push(reg2);
|
|
|
|
lea(reg2, Numbers_Offs + 48, sDATA); // {52..61}
|
|
|
|
movrm(reg2, reg2, 0);
|
|
|
|
or(reg1, reg2);
|
|
|
|
pop(reg2);
|
|
|
|
|
|
|
|
Rex(reg1, 0);
|
|
|
|
OutByte2(0FH, 0BAH);
|
|
|
|
OutByte2(0F0H + reg1 MOD 8, 3EH); // btr reg1, 62
|
|
|
|
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:
|
2019-03-11 09:59:55 +01:00
|
|
|
pushm(rbp, param2 * 8)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD64_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
pushm(reg1, 0);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD64_PARAM:
|
|
|
|
reg1 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg1 # -1 THEN
|
|
|
|
push(reg1)
|
|
|
|
ELSE
|
|
|
|
pushm(rbp, param2 * 8)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD64_PARAM:
|
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param2, sBSS);
|
|
|
|
movrm(reg2, reg2, 0);
|
|
|
|
push(reg2);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCONST_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD32_PARAM:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
xor(reg1, reg1);
|
|
|
|
lea(reg1, param2, sBSS);
|
|
|
|
movrm32(reg1, reg1, 0);
|
|
|
|
push(reg1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD32_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
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();
|
2019-03-11 09:59:55 +01:00
|
|
|
xor(reg1, reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
|
|
|
mov(reg1, reg2)
|
|
|
|
ELSE
|
|
|
|
movrm32(reg1, rbp, param2 * 8)
|
|
|
|
END;
|
|
|
|
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;
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetVarReg(param1);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg1 # -1 THEN
|
|
|
|
movrc(reg1, param2)
|
|
|
|
ELSE
|
|
|
|
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(rbp, n, reg2);
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
OutByte3(48H, 0C7H, 45H + long(n)); // mov qword[rbp+n],param2
|
|
|
|
OutIntByte(n);
|
|
|
|
OutInt(param2)
|
|
|
|
END
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(reg2, param1, sBSS);
|
|
|
|
Rex(reg2, 0);
|
|
|
|
OutByte2(0C7H, reg2 MOD 8); // mov qword[reg2], param2
|
|
|
|
OutInt(param2);
|
|
|
|
drop
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_SAVE:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
|
|
|
mov(reg2, reg1)
|
|
|
|
ELSE
|
|
|
|
movmr(rbp, param2 * 8, reg1)
|
|
|
|
END;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCC:
|
|
|
|
reg1 := GetVarReg(param1);
|
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);
|
|
|
|
IF reg1 # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
add(reg1, reg2)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
n := param1 * 8;
|
|
|
|
Rex(0, reg2);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(01H, 45H + long(n) + (reg2 MOD 8) * 8);
|
|
|
|
OutIntByte(n) // add qword[rbp+n],reg2
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
drop
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF ABS(param2) = 1 THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg1 # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF param2 = 1 THEN
|
|
|
|
incr(reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
decr(reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
n := param1 * 8;
|
2019-09-26 22:23:06 +02:00
|
|
|
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
|
|
|
END
|
|
|
|
ELSE
|
2019-09-26 22:23:06 +02:00
|
|
|
IF reg1 # -1 THEN
|
|
|
|
addrc(reg1, param2)
|
|
|
|
ELSE
|
|
|
|
n := param1 * 8;
|
|
|
|
OutByte3(48H, 81H + short(param2), 45H + long(n));
|
|
|
|
OutIntByte(n);
|
|
|
|
OutIntByte(param2) // add qword[rbp+n],param2
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCCB, IL.opLADR_DECCB:
|
|
|
|
reg1 := GetVarReg(param1);
|
2019-03-11 09:59:55 +01:00
|
|
|
param2 := param2 MOD 256;
|
|
|
|
IF reg1 # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opLADR_DECCB THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(reg1, param2)
|
|
|
|
ELSE
|
|
|
|
addrc(reg1, param2)
|
|
|
|
END;
|
|
|
|
andrc(reg1, 255)
|
|
|
|
ELSE
|
|
|
|
n := param1 * 8;
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(80H, 45H + long(n) + 28H * ORD(opcode = IL.opLADR_DECCB));
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
OutByte(param2) // add/sub byte[rbp+n],param2
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INC, IL.opLADR_DEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opLADR_DEC THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
sub(reg2, reg1)
|
|
|
|
ELSE
|
|
|
|
add(reg2, reg1)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
n := param2 * 8;
|
|
|
|
Rex(0, reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(01H + 28H * ORD(opcode = IL.opLADR_DEC), 45H + long(n) + (reg1 MOD 8) * 8);
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n) // add/sub qword[rbp+n],reg1
|
|
|
|
END;
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opLADR_DECB THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
sub(reg2, reg1)
|
|
|
|
ELSE
|
|
|
|
add(reg2, reg1)
|
|
|
|
END;
|
|
|
|
andrc(reg2, 255)
|
|
|
|
ELSE
|
|
|
|
n := param2 * 8;
|
|
|
|
IF reg1 >= 8 THEN
|
|
|
|
OutByte(44H)
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(28H * ORD(opcode = IL.opLADR_DECB), 45H + long(n) + 8 * (reg1 MOD 8));
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n) // add/sub byte[rbp+n], reg1_8
|
|
|
|
END;
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetVarReg(param2);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg2 # -1 THEN
|
|
|
|
OutByte2(73H, 4); // jnb L
|
2019-09-26 22:23:06 +02:00
|
|
|
oprr2(0FH, 0ABH + 8 * ORD(opcode = IL.opLADR_EXCL), reg2, reg1) // bts/btr reg2, reg1
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
n := param2 * 8;
|
|
|
|
OutByte2(73H, 5 + 3 * ORD(~isByte(n))); // jnb L
|
|
|
|
Rex(0, reg1);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte3(0FH, 0ABH + 8 * ORD(opcode = IL.opLADR_EXCL), 45H + long(n) + 8 * (reg1 MOD 8));
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n) // bts/btr qword[rbp+n], reg1
|
|
|
|
END;
|
|
|
|
// L:
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCLC, IL.opLADR_EXCLC:
|
|
|
|
reg1 := GetVarReg(param1);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF reg1 # -1 THEN
|
|
|
|
Rex(reg1, 0);
|
|
|
|
OutByte3(0FH, 0BAH, 0E8H); // bts/btr reg1, param2
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte2(reg1 MOD 8 + 8 * ORD(opcode = IL.opLADR_EXCLC), param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
n := param1 * 8;
|
|
|
|
OutByte3(48H, 0FH, 0BAH); // bts/btr qword[rbp+n], param2
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte(6DH + long(n) + 8 * ORD(opcode = IL.opLADR_EXCLC));
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
OutByte(param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOOP, IL.opENDLOOP:
|
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);
|
|
|
|
|
|
|
|
IF target = mConst.Target_iDLL64 THEN
|
|
|
|
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);
|
|
|
|
jcc(je, dllret)
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF target = mConst.Target_iELF64 THEN
|
|
|
|
push(rsp)
|
|
|
|
ELSE
|
|
|
|
pushc(0)
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
lea(rax, entry, sCODE);
|
|
|
|
push(rax);
|
|
|
|
pushDA(0); //TYPES
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(tcount);
|
2019-03-11 09:59:55 +01:00
|
|
|
pushDA(ModName_Offs); //MODNAME
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(IL._init);
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
IF target IN {mConst.Target_iConsole64, mConst.Target_iGUI64, mConst.Target_iELF64} 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);
|
|
|
|
addrc(rax, 1024 * 1024 * stack_size - 8);
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE import (imp: LISTS.LIST);
|
|
|
|
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
|
|
|
|
|
|
|
|
END import;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
IF target = mConst.Target_iDLL64 THEN
|
|
|
|
X86.SetLabel(dllret);
|
|
|
|
OutByte(0C3H) // ret
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF target = mConst.Target_iELFSO64 THEN
|
|
|
|
sofinit := NewLabel();
|
|
|
|
OutByte(0C3H); // ret
|
|
|
|
X86.SetLabel(sofinit);
|
|
|
|
CallRTL(IL._sofinit);
|
|
|
|
OutByte(0C3H) // 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;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
import(IL.codes.import)
|
2019-03-11 09:59:55 +01:00
|
|
|
END epilog;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE rload (reg, offs, size: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
offs := offs * 8;
|
|
|
|
CASE size OF
|
|
|
|
|1: movzx(reg, rbp, offs, FALSE)
|
|
|
|
|2: movzx(reg, rbp, offs, TRUE)
|
|
|
|
|4: xor(reg, reg); movrm32(reg, rbp, offs)
|
|
|
|
|8: movrm(reg, rbp, offs)
|
|
|
|
END
|
|
|
|
END rload;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE rsave (reg, offs, size: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
offs := offs * 8;
|
|
|
|
CASE size OF
|
|
|
|
|1: movmr8(rbp, offs, reg)
|
|
|
|
|2: movmr16(rbp, offs, reg)
|
|
|
|
|4: movmr32(rbp, offs, reg)
|
|
|
|
|8: movmr(rbp, offs, reg)
|
|
|
|
END
|
|
|
|
END rsave;
|
|
|
|
|
|
|
|
|
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
|
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);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
REG.Init(R, push, pop, mov, xchg, rload, rsave, {rax, r10, r11}, {rcx, rdx, r8, r9});
|
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);
|
|
|
|
IF target IN {mConst.Target_iConsole64, mConst.Target_iGUI64, mConst.Target_iDLL64} THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
PE32.write(prog, outname, target = mConst.Target_iConsole64, target = mConst.Target_iDLL64, TRUE)
|
2019-09-26 22:23:06 +02:00
|
|
|
ELSIF target IN {mConst.Target_iELF64, mConst.Target_iELFSO64} THEN
|
|
|
|
ELF.write(prog, outname, sofinit, target = mConst.Target_iELFSO64, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END CodeGen;
|
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
END AMD64.
|