2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
2016-10-24 01:30:27 +02:00
|
|
|
|
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.
|
2016-10-24 01:30:27 +02:00
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE X86;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IMPORT IL, REG, UTILS, LISTS, BIN, PE32, KOS, MSCOFF, ELF, PROG,
|
2020-10-13 09:58:51 +02:00
|
|
|
CHL := CHUNKLISTS, PATHS, TARGETS, ERRORS;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
CONST
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
eax = REG.R0; ecx = REG.R1; edx = REG.R2;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
al = eax; cl = ecx; dl = edx; ah = 4;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ax = eax; cx = ecx; dx = edx;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
esp = 4;
|
|
|
|
ebp = 5;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
MAX_FR = 7;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
sete = 94H; setne = 95H; setl = 9CH; setge = 9DH; setle = 9EH; setg = 9FH; setc = 92H; setnc = 93H;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
je = 84H; jne = 85H; jl = 8CH; jge = 8DH; jle = 8EH; jg = 8FH; jb = 82H; jnb = 83H;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
CODECHUNK = 8;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
FPR_ERR = 41;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
COMMAND = IL.COMMAND;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
ANYCODE = POINTER TO RECORD (LISTS.ITEM)
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
offset: INTEGER
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
END;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CODE = POINTER TO RECORD (ANYCODE)
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
code: ARRAY CODECHUNK OF BYTE;
|
|
|
|
length: INTEGER
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
LABEL = POINTER TO RECORD (ANYCODE)
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
label: INTEGER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
JUMP = POINTER TO RECORD (ANYCODE)
|
|
|
|
|
|
|
|
label, diff: INTEGER;
|
|
|
|
short: BOOLEAN
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
JMP = POINTER TO RECORD (JUMP)
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
JCC = POINTER TO RECORD (JUMP)
|
|
|
|
|
|
|
|
jmp: INTEGER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
CALL = POINTER TO RECORD (JUMP)
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
RELOC = POINTER TO RECORD (ANYCODE)
|
|
|
|
|
|
|
|
op, value: INTEGER
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
VAR
|
|
|
|
|
|
|
|
R: REG.REGS;
|
|
|
|
|
|
|
|
program: BIN.PROGRAM;
|
|
|
|
|
|
|
|
CodeList: LISTS.LIST;
|
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
tcount, LocVarSize, mainLocVarSize: INTEGER;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
FR: ARRAY 1000 OF INTEGER;
|
|
|
|
|
|
|
|
fname: PATHS.PATH;
|
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
FltConstLabel, mainFltConstLabel: LABEL;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE OutByte* (n: BYTE);
|
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
c: CODE;
|
2019-03-11 09:59:55 +01:00
|
|
|
last: ANYCODE;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
last := CodeList.last(ANYCODE);
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
IF (last IS CODE) & (last(CODE).length < CODECHUNK) THEN
|
|
|
|
c := last(CODE);
|
2019-03-11 09:59:55 +01:00
|
|
|
c.code[c.length] := n;
|
|
|
|
INC(c.length)
|
|
|
|
ELSE
|
|
|
|
NEW(c);
|
|
|
|
c.code[0] := n;
|
|
|
|
c.length := 1;
|
|
|
|
LISTS.push(CodeList, c)
|
|
|
|
END
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
END OutByte;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE OutInt (n: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(n MOD 256);
|
2019-09-26 22:23:06 +02:00
|
|
|
OutByte(UTILS.Byte(n, 1));
|
|
|
|
OutByte(UTILS.Byte(n, 2));
|
|
|
|
OutByte(UTILS.Byte(n, 3))
|
2016-10-24 01:30:27 +02:00
|
|
|
END OutInt;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE OutByte2 (a, b: BYTE);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte(a);
|
|
|
|
OutByte(b)
|
|
|
|
END OutByte2;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE OutByte3 (a, b, c: BYTE);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte(a);
|
|
|
|
OutByte(b);
|
|
|
|
OutByte(c)
|
|
|
|
END OutByte3;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE OutWord (n: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT((0 <= n) & (n <= 65535));
|
|
|
|
OutByte2(n MOD 256, n DIV 256)
|
|
|
|
END OutWord;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE isByte* (n: INTEGER): BOOLEAN;
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN (-128 <= n) & (n <= 127)
|
|
|
|
END isByte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE short (n: INTEGER): INTEGER;
|
|
|
|
RETURN 2 * ORD(isByte(n))
|
|
|
|
END short;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE long (n: INTEGER): INTEGER;
|
|
|
|
RETURN 40H * ORD(~isByte(n))
|
|
|
|
END long;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutIntByte (n: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF 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;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE shift* (op, reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
CASE op OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR, IL.opASR1, IL.opASR2: OutByte(0F8H + reg)
|
|
|
|
|IL.opROR, IL.opROR1, IL.opROR2: OutByte(0C8H + reg)
|
|
|
|
|IL.opLSL, IL.opLSL1, IL.opLSL2: OutByte(0E0H + reg)
|
|
|
|
|IL.opLSR, IL.opLSR1, IL.opLSR2: OutByte(0E8H + reg)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END shift;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE oprr (op: BYTE; reg1, reg2: INTEGER); (* op reg1, reg2 *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte2(op, 0C0H + 8 * reg2 + reg1)
|
|
|
|
END oprr;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE mov (reg1, reg2: INTEGER); (* mov reg1, reg2 *)
|
|
|
|
BEGIN
|
|
|
|
oprr(89H, reg1, reg2)
|
|
|
|
END mov;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|
|
|
|
PROCEDURE xchg (reg1, reg2: INTEGER); (* xchg reg1, reg2 *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF eax IN {reg1, reg2} THEN
|
|
|
|
OutByte(90H + reg1 + reg2)
|
|
|
|
ELSE
|
|
|
|
oprr(87H, reg1, reg2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END xchg;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE pop (reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(58H + reg) (* pop reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END pop;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE push (reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(50H + reg) (* push reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END push;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE xor (reg1, reg2: INTEGER); (* xor reg1, reg2 *)
|
|
|
|
BEGIN
|
|
|
|
oprr(31H, reg1, reg2)
|
|
|
|
END xor;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE movrc (reg, n: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF n = 0 THEN
|
|
|
|
xor(reg, reg)
|
|
|
|
ELSE
|
|
|
|
OutByte(0B8H + reg); (* mov reg, n *)
|
|
|
|
OutInt(n)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END movrc;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE pushc* (n: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(68H + short(n)); (* push n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n)
|
|
|
|
END pushc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE test (reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(85H, 0C0H + reg * 9) (* test reg, reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END test;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE neg (reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0F7H, 0D8H + reg) (* neg reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END neg;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE not (reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0F7H, 0D0H + reg) (* not reg *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END not;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE add (reg1, reg2: INTEGER); (* add reg1, reg2 *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprr(01H, reg1, reg2)
|
2019-03-11 09:59:55 +01:00
|
|
|
END add;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE oprc* (op, reg, n: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF (reg = eax) & ~isByte(n) THEN
|
|
|
|
CASE op OF
|
|
|
|
|0C0H: op := 05H (* add *)
|
|
|
|
|0E8H: op := 2DH (* sub *)
|
|
|
|
|0F8H: op := 3DH (* cmp *)
|
|
|
|
|0E0H: op := 25H (* and *)
|
|
|
|
|0C8H: op := 0DH (* or *)
|
|
|
|
|0F0H: op := 35H (* xor *)
|
|
|
|
END;
|
|
|
|
OutByte(op);
|
|
|
|
OutInt(n)
|
|
|
|
ELSE
|
|
|
|
OutByte2(81H + short(n), op + reg MOD 8);
|
|
|
|
OutIntByte(n)
|
|
|
|
END
|
|
|
|
END oprc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE andrc (reg, n: INTEGER); (* and reg, n *)
|
|
|
|
BEGIN
|
|
|
|
oprc(0E0H, reg, n)
|
2019-03-11 09:59:55 +01:00
|
|
|
END andrc;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE orrc (reg, n: INTEGER); (* or reg, n *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprc(0C8H, reg, n)
|
2019-03-11 09:59:55 +01:00
|
|
|
END orrc;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE xorrc (reg, n: INTEGER); (* xor reg, n *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprc(0F0H, reg, n)
|
|
|
|
END xorrc;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE addrc (reg, n: INTEGER); (* add reg, n *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprc(0C0H, reg, n)
|
|
|
|
END addrc;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE subrc (reg, n: INTEGER); (* sub reg, n *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprc(0E8H, reg, n)
|
|
|
|
END subrc;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE cmprc (reg, n: INTEGER); (* cmp reg, n *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
IF n = 0 THEN
|
|
|
|
test(reg)
|
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
oprc(0F8H, reg, n)
|
2020-05-25 22:48:33 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END cmprc;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE cmprr (reg1, reg2: INTEGER); (* cmp reg1, reg2 *)
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
oprr(39H, reg1, reg2)
|
|
|
|
END cmprr;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE setcc* (cc, reg: INTEGER); (* setcc reg *)
|
2019-06-04 09:22:50 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF reg >= 8 THEN
|
|
|
|
OutByte(41H)
|
|
|
|
END;
|
|
|
|
OutByte3(0FH, cc, 0C0H + reg MOD 8)
|
|
|
|
END setcc;
|
2019-06-04 09:22:50 +02:00
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE ret*;
|
|
|
|
BEGIN
|
|
|
|
OutByte(0C3H)
|
|
|
|
END ret;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE drop;
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
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 cond* (op: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
CASE op OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGT, IL.opGTC: res := jg
|
|
|
|
|IL.opGE, IL.opGEC: res := jge
|
|
|
|
|IL.opLT, IL.opLTC: res := jl
|
|
|
|
|IL.opLE, IL.opLEC: res := jle
|
|
|
|
|IL.opEQ, IL.opEQC: res := je
|
|
|
|
|IL.opNE, IL.opNEC: res := jne
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END cond;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
PROCEDURE inv0* (op: INTEGER): INTEGER;
|
|
|
|
RETURN ORD(BITS(op) / {0})
|
|
|
|
END inv0;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Reloc* (op, value: INTEGER);
|
|
|
|
VAR
|
|
|
|
reloc: RELOC;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
NEW(reloc);
|
|
|
|
reloc.op := op;
|
|
|
|
reloc.value := value;
|
|
|
|
LISTS.push(CodeList, reloc)
|
|
|
|
END Reloc;
|
|
|
|
|
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
PROCEDURE PushFlt (label: LABEL; value: REAL);
|
|
|
|
VAR
|
|
|
|
a, b, n: INTEGER;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE pushImm (label: LABEL; value: INTEGER);
|
|
|
|
VAR
|
|
|
|
c: CODE;
|
|
|
|
i: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
NEW(c);
|
|
|
|
IF isByte(value) THEN
|
|
|
|
c.code[0] := 6AH;
|
|
|
|
c.code[1] := value MOD 256;
|
|
|
|
c.length := 2
|
|
|
|
ELSE
|
|
|
|
c.code[0] := 68H;
|
|
|
|
FOR i := 1 TO 4 DO
|
|
|
|
c.code[i] := UTILS.Byte(value, i - 1)
|
|
|
|
END;
|
|
|
|
c.length := 5
|
|
|
|
END;
|
|
|
|
LISTS.insertL(CodeList, label, c)
|
|
|
|
END pushImm;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
n := UTILS.splitf(value, a, b);
|
|
|
|
pushImm(label, b);
|
|
|
|
pushImm(label, a)
|
|
|
|
END PushFlt;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE jcc* (cc, label: INTEGER);
|
|
|
|
VAR
|
|
|
|
j: JCC;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
NEW(j);
|
|
|
|
j.label := label;
|
|
|
|
j.jmp := cc;
|
|
|
|
j.short := FALSE;
|
|
|
|
LISTS.push(CodeList, j)
|
|
|
|
END jcc;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE jmp* (label: INTEGER);
|
|
|
|
VAR
|
|
|
|
j: JMP;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
NEW(j);
|
|
|
|
j.label := label;
|
|
|
|
j.short := FALSE;
|
|
|
|
LISTS.push(CodeList, j)
|
|
|
|
END jmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE call* (label: INTEGER);
|
|
|
|
VAR
|
|
|
|
c: CALL;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
NEW(c);
|
|
|
|
c.label := label;
|
|
|
|
c.short := TRUE;
|
|
|
|
LISTS.push(CodeList, c)
|
|
|
|
END call;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Pic (reg, opcode, value: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0E8H); OutInt(0); (* call L
|
|
|
|
L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(reg);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(081H, 0C0H + reg); (* add reg, ... *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(opcode, value)
|
|
|
|
END Pic;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE CallRTL (pic: BOOLEAN; proc: INTEGER);
|
|
|
|
VAR
|
|
|
|
label: INTEGER;
|
|
|
|
reg1: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
label := -label;
|
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICIMP, label);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 010H + reg1); (* call dword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 015H); (* call dword[label] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RIMP, label)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
call(label)
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END CallRTL;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE SetLabel* (label: INTEGER);
|
|
|
|
VAR
|
|
|
|
L: LABEL;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
NEW(L);
|
|
|
|
L.label := label;
|
|
|
|
LISTS.push(CodeList, L)
|
|
|
|
END SetLabel;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE fixup*;
|
|
|
|
VAR
|
|
|
|
code: ANYCODE;
|
|
|
|
count, i: INTEGER;
|
|
|
|
shorted: BOOLEAN;
|
|
|
|
jump: JUMP;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
REPEAT
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
shorted := FALSE;
|
|
|
|
count := 0;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
code := CodeList.first(ANYCODE);
|
|
|
|
WHILE code # NIL DO
|
|
|
|
code.offset := count;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
CASE code OF
|
2019-09-26 22:23:06 +02:00
|
|
|
|CODE: INC(count, code.length)
|
2019-03-11 09:59:55 +01:00
|
|
|
|LABEL: BIN.SetLabel(program, code.label, count)
|
|
|
|
|JMP: IF code.short THEN INC(count, 2) ELSE INC(count, 5) END; code.offset := count
|
|
|
|
|JCC: IF code.short THEN INC(count, 2) ELSE INC(count, 6) END; code.offset := count
|
|
|
|
|CALL: INC(count, 5); code.offset := count
|
|
|
|
|RELOC: INC(count, 4)
|
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
code := code.next(ANYCODE)
|
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
code := CodeList.first(ANYCODE);
|
|
|
|
WHILE code # NIL DO
|
|
|
|
|
|
|
|
IF code IS JUMP THEN
|
|
|
|
jump := code(JUMP);
|
|
|
|
jump.diff := BIN.GetLabel(program, jump.label) - code.offset;
|
|
|
|
IF ~jump.short & isByte(jump.diff) THEN
|
|
|
|
jump.short := TRUE;
|
|
|
|
shorted := TRUE
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
|
|
|
|
code := code.next(ANYCODE)
|
|
|
|
END
|
|
|
|
|
|
|
|
UNTIL ~shorted;
|
|
|
|
|
|
|
|
code := CodeList.first(ANYCODE);
|
|
|
|
WHILE code # NIL DO
|
|
|
|
|
|
|
|
CASE code OF
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|CODE:
|
2019-03-11 09:59:55 +01:00
|
|
|
FOR i := 0 TO code.length - 1 DO
|
|
|
|
BIN.PutCode(program, code.code[i])
|
|
|
|
END
|
|
|
|
|
|
|
|
|LABEL:
|
|
|
|
|
|
|
|
|JMP:
|
|
|
|
IF code.short THEN
|
|
|
|
BIN.PutCode(program, 0EBH);
|
2020-05-25 22:48:33 +02:00
|
|
|
BIN.PutCode(program, code.diff MOD 256)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
BIN.PutCode(program, 0E9H);
|
|
|
|
BIN.PutCode32LE(program, code.diff)
|
|
|
|
END
|
|
|
|
|
|
|
|
|JCC:
|
|
|
|
IF code.short THEN
|
|
|
|
BIN.PutCode(program, code.jmp - 16);
|
2020-05-25 22:48:33 +02:00
|
|
|
BIN.PutCode(program, code.diff MOD 256)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
BIN.PutCode(program, 0FH);
|
|
|
|
BIN.PutCode(program, code.jmp);
|
|
|
|
BIN.PutCode32LE(program, code.diff)
|
|
|
|
END
|
|
|
|
|
|
|
|
|CALL:
|
|
|
|
BIN.PutCode(program, 0E8H);
|
|
|
|
BIN.PutCode32LE(program, code.diff)
|
|
|
|
|
|
|
|
|RELOC:
|
|
|
|
BIN.PutReloc(program, code.op);
|
|
|
|
BIN.PutCode32LE(program, code.value)
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
code := code.next(ANYCODE)
|
|
|
|
END
|
|
|
|
|
|
|
|
END fixup;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE UnOp (VAR reg: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
REG.UnOp(R, reg)
|
|
|
|
END UnOp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE BinOp (VAR reg1, reg2: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
REG.BinOp(R, reg1, reg2)
|
|
|
|
END BinOp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE PushAll (NumberOfParameters: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
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;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE NewLabel (): INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
BIN.NewLabel(program)
|
2019-09-26 22:23:06 +02:00
|
|
|
RETURN IL.NewLabel()
|
2019-03-11 09:59:55 +01:00
|
|
|
END NewLabel;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE GetRegA;
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(REG.GetReg(R, eax))
|
|
|
|
END GetRegA;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE fcmp;
|
|
|
|
BEGIN
|
|
|
|
GetRegA;
|
|
|
|
OutByte2(0DAH, 0E9H); (* fucompp *)
|
|
|
|
OutByte3(09BH, 0DFH, 0E0H); (* fstsw ax *)
|
|
|
|
OutByte(09EH); (* sahf *)
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte(0B8H); OutInt(0) (* mov eax, 0 *)
|
2020-05-25 22:48:33 +02:00
|
|
|
END fcmp;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movzx* (reg1, reg2, offs: INTEGER; word: BOOLEAN); (* movzx reg1, byte/word[reg2 + offs] *)
|
|
|
|
VAR
|
|
|
|
b: BYTE;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
OutByte2(0FH, 0B6H + ORD(word));
|
|
|
|
IF (offs = 0) & (reg2 # ebp) THEN
|
|
|
|
b := 0
|
|
|
|
ELSE
|
|
|
|
b := 40H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + (reg1 MOD 8) * 8 + reg2 MOD 8);
|
|
|
|
IF reg2 = esp 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 # ebp) THEN
|
|
|
|
b := 0
|
|
|
|
ELSE
|
|
|
|
b := 40H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + (reg1 MOD 8) * 8 + reg2 MOD 8);
|
|
|
|
IF reg2 = esp THEN
|
|
|
|
OutByte(24H)
|
|
|
|
END;
|
|
|
|
IF b # 0 THEN
|
|
|
|
OutIntByte(offs)
|
|
|
|
END
|
|
|
|
END _movrm;
|
|
|
|
|
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
PROCEDURE movmr (reg1, offs, reg2: INTEGER); (* mov dword[reg1+offs], reg2 *)
|
2020-05-25 22:48:33 +02:00
|
|
|
BEGIN
|
|
|
|
_movrm(reg2, reg1, offs, 32, TRUE)
|
|
|
|
END movmr;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE movrm (reg1, reg2, offs: INTEGER); (* mov reg1, dword[reg2 + offs] *)
|
|
|
|
BEGIN
|
|
|
|
_movrm(reg1, reg2, offs, 32, FALSE)
|
|
|
|
END movrm;
|
|
|
|
|
|
|
|
|
|
|
|
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 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 # ebp) THEN
|
|
|
|
b := 30H
|
|
|
|
ELSE
|
|
|
|
b := 70H + long(offs)
|
|
|
|
END;
|
|
|
|
OutByte(b + reg MOD 8);
|
|
|
|
IF reg = esp THEN
|
|
|
|
OutByte(24H)
|
|
|
|
END;
|
|
|
|
IF b # 30H THEN
|
|
|
|
OutIntByte(offs)
|
|
|
|
END
|
|
|
|
END pushm;
|
|
|
|
|
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
PROCEDURE LoadFltConst (value: REAL);
|
|
|
|
BEGIN
|
|
|
|
PushFlt(FltConstLabel, value);
|
|
|
|
INC(LocVarSize, 8);
|
|
|
|
IF FltConstLabel = mainFltConstLabel THEN
|
|
|
|
mainLocVarSize := LocVarSize
|
|
|
|
END;
|
|
|
|
OutByte2(0DDH, 045H + long(-LocVarSize)); (* fld qword[ebp - LocVarSize] *)
|
|
|
|
OutIntByte(-LocVarSize)
|
|
|
|
END LoadFltConst;
|
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE translate (pic: BOOLEAN; stroffs: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2020-05-25 22:48:33 +02:00
|
|
|
cmd, next: COMMAND;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
reg1, reg2, reg3, fr: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
n, a, label, cc: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
opcode, param1, param2: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
float: REAL;
|
|
|
|
|
|
|
|
BEGIN
|
2019-10-06 19:55:12 +02:00
|
|
|
cmd := IL.codes.commands.first(COMMAND);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
fr := -1;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
WHILE cmd # NIL DO
|
|
|
|
|
|
|
|
param1 := cmd.param1;
|
|
|
|
param2 := cmd.param2;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
opcode := cmd.opcode;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
CASE opcode OF
|
|
|
|
|
|
|
|
|IL.opJMP:
|
2019-03-11 09:59:55 +01:00
|
|
|
jmp(param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALL:
|
2019-03-11 09:59:55 +01:00
|
|
|
call(param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALLI:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICIMP, param1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 010H + reg1); (* call dword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 015H); (* call dword[L] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RIMP, param1)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCALLP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 0D0H + reg1); (* call reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
ASSERT(R.top = -1)
|
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
|IL.opFASTCALL:
|
|
|
|
IF param2 = 1 THEN
|
|
|
|
pop(ecx)
|
|
|
|
ELSIF param2 = 2 THEN
|
|
|
|
pop(ecx);
|
|
|
|
pop(edx)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPRECALL:
|
2020-10-13 09:58:51 +02:00
|
|
|
PushAll(0);
|
|
|
|
IF (param2 # 0) & (fr >= 0) THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(esp, 8)
|
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(FR[0]);
|
|
|
|
FR[FR[0]] := fr + 1;
|
|
|
|
WHILE fr >= 0 DO
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(esp, 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0DDH, 01CH, 024H); (* fstp qword[esp] *)
|
2020-10-13 09:58:51 +02:00
|
|
|
DEC(fr)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr = -1)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opALIGN16:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(eax IN R.regs);
|
|
|
|
mov(eax, esp);
|
|
|
|
andrc(esp, -16);
|
|
|
|
n := (3 - param2 MOD 4) * 4;
|
|
|
|
IF n > 0 THEN
|
|
|
|
subrc(esp, n)
|
|
|
|
END;
|
|
|
|
push(eax)
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opRESF, IL.opRES:
|
2019-03-11 09:59:55 +01:00
|
|
|
ASSERT(R.top = -1);
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr = -1);
|
|
|
|
n := FR[FR[0]]; DEC(FR[0]);
|
|
|
|
|
|
|
|
IF opcode = IL.opRESF THEN
|
|
|
|
INC(fr);
|
|
|
|
IF n > 0 THEN
|
|
|
|
OutByte3(0DDH, 5CH + long(n * 8), 24H);
|
|
|
|
OutIntByte(n * 8); (* fstp qword[esp + n*8] *)
|
|
|
|
DEC(fr);
|
|
|
|
INC(n)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF fr + n > MAX_FR THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END
|
|
|
|
ELSE
|
|
|
|
GetRegA
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
WHILE n > 0 DO
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0DDH, 004H, 024H); (* fld qword[esp] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
addrc(esp, 8);
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(fr);
|
2019-03-11 09:59:55 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
SetLabel(param1);
|
|
|
|
|
2022-06-21 22:32:43 +02:00
|
|
|
IF cmd.param3 > 0 THEN
|
|
|
|
pop(eax);
|
|
|
|
IF cmd.param3 >= 2 THEN
|
|
|
|
push(edx)
|
|
|
|
END;
|
|
|
|
push(ecx);
|
|
|
|
push(eax)
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
push(ebp);
|
|
|
|
mov(ebp, esp);
|
|
|
|
|
|
|
|
n := param2;
|
|
|
|
IF n > 4 THEN
|
|
|
|
movrc(ecx, n);
|
2020-05-25 22:48:33 +02:00
|
|
|
pushc(0); (* L: push 0 *)
|
|
|
|
OutByte2(0E2H, 0FCH) (* loop L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
WHILE n > 0 DO
|
|
|
|
pushc(0);
|
|
|
|
DEC(n)
|
|
|
|
END
|
2022-08-31 22:51:32 +02:00
|
|
|
END;
|
|
|
|
SetLabel(NewLabel());
|
|
|
|
FltConstLabel := CodeList.last(LABEL);
|
|
|
|
LocVarSize := param2 * 4
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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 # eax THEN
|
2021-06-15 19:33:16 +02:00
|
|
|
mov(eax, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(R.top = -1);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF opcode = IL.opLEAVEF THEN
|
|
|
|
DEC(fr)
|
|
|
|
END;
|
|
|
|
|
|
|
|
ASSERT(fr = -1);
|
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
IF LocVarSize > 0 THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
mov(esp, ebp)
|
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(ebp);
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
IF param2 > 0 THEN
|
|
|
|
OutByte(0C2H); OutWord(param2 * 4 MOD 65536) (* ret param2*4 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
ret
|
2022-08-31 22:51:32 +02:00
|
|
|
END;
|
|
|
|
FltConstLabel := mainFltConstLabel;
|
|
|
|
LocVarSize := mainLocVarSize
|
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)
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opONERR:
|
|
|
|
pushc(param2);
|
|
|
|
jmp(param1)
|
|
|
|
|
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-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCLEANUP:
|
2020-10-13 09:58:51 +02:00
|
|
|
IF param2 # 0 THEN
|
|
|
|
addrc(esp, param2 * 4)
|
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(esp)
|
|
|
|
|
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.opLABEL:
|
2020-05-25 22:48:33 +02:00
|
|
|
SetLabel(param1) (* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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.opGADR:
|
2020-10-13 09:58:51 +02:00
|
|
|
next := cmd.next(COMMAND);
|
|
|
|
IF next.opcode = IL.opADDC THEN
|
|
|
|
INC(param2, next.param2);
|
|
|
|
cmd := next
|
|
|
|
END;
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICBSS, param2)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0B8H + reg1); (* mov reg1, _bss + param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RBSS, param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR:
|
2020-10-13 09:58:51 +02:00
|
|
|
next := cmd.next(COMMAND);
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 4;
|
2020-10-13 09:58:51 +02:00
|
|
|
IF next.opcode = IL.opADDC THEN
|
|
|
|
INC(n, next.param2);
|
|
|
|
cmd := next
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(8DH, 45H + GetAnyReg() * 8 + long(n)); (* lea reg1, dword[ebp + n] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n)
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opVADR, IL.opLLOAD32:
|
|
|
|
movrm(GetAnyReg(), ebp, param2 * 4)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSADR:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICDATA, stroffs + param2);
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0B8H + reg1); (* mov reg1, _data + stroffs + param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RDATA, stroffs + param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0C7H, reg1); OutInt(param2); (* mov dword[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE8C:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0C6H, reg1, param2 MOD 256); (* 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);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(66H, 0C7H, reg1); OutWord(param2 MOD 65536); (* mov word[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVLOAD32:
|
|
|
|
reg1 := GetAnyReg();
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(reg1, ebp, param2 * 4);
|
|
|
|
movrm(reg1, reg1, 0)
|
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
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICBSS, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(reg1, reg1, 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(08BH, 05H + reg1 * 8); (* mov reg1, dword[_bss + param2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RBSS, param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD32:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(reg1, reg1, 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVLOAD8:
|
|
|
|
reg1 := GetAnyReg();
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(reg1, ebp, param2 * 4);
|
|
|
|
movzx(reg1, reg1, 0, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD8:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICBSS, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
movzx(reg1, reg1, 0, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(00FH, 0B6H, 05H + reg1 * 8); (* movzx reg1, byte[_bss + param2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RBSS, param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD8:
|
2020-05-25 22:48:33 +02:00
|
|
|
movzx(GetAnyReg(), ebp, param2 * 4, FALSE)
|
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);
|
2020-05-25 22:48:33 +02:00
|
|
|
movzx(reg1, reg1, 0, FALSE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opVLOAD16:
|
|
|
|
reg1 := GetAnyReg();
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(reg1, ebp, param2 * 4);
|
|
|
|
movzx(reg1, reg1, 0, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD16:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICBSS, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
movzx(reg1, reg1, 0, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(00FH, 0B7H, 05H + reg1 * 8); (* movzx reg1, word[_bss + param2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RBSS, param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLLOAD16:
|
2020-05-25 22:48:33 +02:00
|
|
|
movzx(GetAnyReg(), ebp, param2 * 4, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD16:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
movzx(reg1, reg1, 0, TRUE)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opADDC:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF param2 # 0 THEN
|
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
next := cmd.next(COMMAND);
|
|
|
|
CASE next.opcode OF
|
|
|
|
|IL.opLOAD32:
|
|
|
|
movrm(reg1, reg1, param2);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD16:
|
|
|
|
movzx(reg1, reg1, param2, TRUE);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD8:
|
|
|
|
movzx(reg1, reg1, param2, FALSE);
|
|
|
|
cmd := next
|
|
|
|
|IL.opLOAD32_PARAM:
|
|
|
|
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
|
|
|
|
OutByte(40H + reg1) (* inc reg1 *)
|
|
|
|
ELSIF param2 = -1 THEN
|
|
|
|
OutByte(48H + reg1) (* dec reg1 *)
|
|
|
|
ELSE
|
|
|
|
addrc(reg1, param2)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUB:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2020-10-13 09:58:51 +02:00
|
|
|
oprr(29H, reg1, reg2); (* sub reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
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
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(48H + reg1) (* dec reg1 *)
|
2020-10-13 09:58:51 +02:00
|
|
|
ELSIF param2 = -1 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(40H + reg1) (* inc 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
|
|
|
|
|
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);
|
|
|
|
OutByte3(8DH, 04H + reg1 * 8, reg1 + reg2 * 8 + 40H * UTILS.Log2(param2)); (* lea reg1, [reg1 + reg2 * 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);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
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)
|
|
|
|
ELSE
|
|
|
|
IF n > 0 THEN
|
|
|
|
IF a < 0 THEN
|
|
|
|
neg(reg1)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF n # 1 THEN
|
|
|
|
OutByte3(0C1H, 0E0H + reg1, n) (* shl reg1, n *)
|
|
|
|
ELSE
|
|
|
|
OutByte2(0D1H, 0E0H + reg1) (* shl reg1, 1 *)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(69H + short(a), 0C0H + reg1 * 9); (* imul reg1, a *)
|
|
|
|
OutIntByte(a)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
END
|
|
|
|
END
|
|
|
|
|
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
|
|
|
OutByte3(0FH, 0AFH, 0C0H + reg1 * 8 + reg2); (* imul reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVE, IL.opSAVE32:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
movmr(reg1, 0, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
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
|
|
|
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
|
|
|
movmr16(reg1, 0, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg2, BIN.PICCODE, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
movmr(reg1, 0, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0C7H, reg1); (* mov dword[reg1], L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RCODE, param2)
|
|
|
|
END;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVEIP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg2, BIN.PICIMP, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
pushm(reg2, 0);
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte2(08FH, reg1); (* pop dword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 035H); (* push dword[L] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RIMP, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(08FH, reg1) (* pop dword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHP:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICCODE, param2)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0B8H + reg1); (* mov reg1, L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RCODE, param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHIP:
|
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
|
|
|
Pic(reg1, BIN.PICIMP, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(reg1, reg1, 0)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(08BH, 05H + reg1 * 8); (* mov reg1, dword[L] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RIMP, param2)
|
|
|
|
END
|
|
|
|
|
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.opSBOOL:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg2, reg1);
|
|
|
|
test(reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 95H, reg1); (* 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);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0C6H, reg1, 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.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-09-26 22:23:06 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
drop;
|
2019-09-26 22:23:06 +02:00
|
|
|
cc := cond(opcode);
|
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(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();
|
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.opEQB, IL.opNEB:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
drop;
|
|
|
|
|
|
|
|
test(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(74H, 5); (* je @f *)
|
|
|
|
movrc(reg1, 1); (* mov reg1, 1
|
|
|
|
@@: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
test(reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(74H, 5); (* je @f *)
|
|
|
|
movrc(reg2, 1); (* mov reg2, 1
|
|
|
|
@@: *)
|
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.opDROP:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
drop
|
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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);
|
2019-09-26 22:23:06 +02:00
|
|
|
drop
|
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 := eax
|
|
|
|
ELSE
|
|
|
|
reg2 := ecx
|
|
|
|
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(eax, param1);
|
|
|
|
jcc(jl, param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASER:
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(eax, param1);
|
|
|
|
jcc(jg, param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCASELR:
|
2019-03-11 09:59:55 +01:00
|
|
|
cmprc(eax, 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
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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.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
|
|
|
IF param2 # 8 THEN
|
|
|
|
_movrm(reg1, reg1, 0, param2 * 8, FALSE);
|
|
|
|
_movrm(reg1, reg2, 0, param2 * 8, TRUE)
|
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(0);
|
|
|
|
push(reg1);
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(8);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, IL._move)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSAVES:
|
2019-10-06 19:55:12 +02:00
|
|
|
UnOp(reg2);
|
|
|
|
REG.PushAll_1(R);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
IF pic THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICDATA, stroffs + param2);
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg1);
|
|
|
|
drop
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(068H); (* push _data + stroffs + param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RDATA, stroffs + param2);
|
|
|
|
END;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
push(reg2);
|
|
|
|
drop;
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(param1);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, IL._move)
|
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);
|
|
|
|
jcc(jb, param1)
|
2020-05-25 22:48:33 +02:00
|
|
|
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.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.opINCC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF param2 = 1 THEN
|
|
|
|
OutByte2(0FFH, reg1) (* inc dword[reg1] *)
|
|
|
|
ELSIF param2 = -1 THEN
|
|
|
|
OutByte2(0FFH, reg1 + 8) (* dec dword[reg1] *)
|
|
|
|
ELSE
|
|
|
|
OutByte2(81H + short(param2), reg1); OutIntByte(param2) (* add dword[reg1], param2 *)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
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
|
|
|
OutByte2(01H + 28H * ORD(opcode = IL.opDEC), reg1 * 8 + reg2); (* add/sub dword[reg2], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCCB, IL.opDECCB:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(80H, 28H * ORD(opcode = IL.opDECCB) + reg1, param2 MOD 256); (* add/sub byte[reg1], n *)
|
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);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(28H * ORD(opcode = IL.opDECB), reg1 * 8 + reg2); (* add/sub byte[reg2], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2020-10-13 09:58:51 +02:00
|
|
|
oprr(21H, reg1, reg2); (* and reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
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.opDIVS:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2019-06-04 09:22:50 +02:00
|
|
|
xor(reg1, reg2);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVSC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-10-13 09:58:51 +02:00
|
|
|
xorrc(reg1, param2)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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
|
|
|
oprr(9H, reg1, reg2); (* 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);
|
2020-10-13 09:58:51 +02:00
|
|
|
oprr(21H, reg1, reg2); (* and reg1, reg2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opADDSC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
orrc(reg1, 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);
|
2019-09-26 22:23:06 +02:00
|
|
|
andrc(reg1, ORD(-BITS(param2)))
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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.opLENGTH:
|
2019-03-11 09:59:55 +01:00
|
|
|
PushAll(2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, 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(pic, IL._lengthw);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opASR, IL.opROR, IL.opLSL, IL.opLSR:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 # ecx THEN
|
|
|
|
ASSERT(REG.GetReg(R, ecx));
|
|
|
|
ASSERT(REG.Exchange(R, reg1, ecx));
|
|
|
|
drop
|
|
|
|
END;
|
|
|
|
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
ASSERT(reg2 = ecx);
|
|
|
|
OutByte(0D3H);
|
2020-05-25 22:48:33 +02:00
|
|
|
shift(opcode, reg1); (* 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:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
IF reg1 # ecx THEN
|
|
|
|
ASSERT(REG.GetReg(R, ecx));
|
|
|
|
ASSERT(REG.Exchange(R, reg1, ecx));
|
|
|
|
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);
|
|
|
|
ASSERT(reg1 = ecx);
|
|
|
|
OutByte(0D3H);
|
2020-05-25 22:48:33 +02:00
|
|
|
shift(opcode, reg2); (* 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
|
|
|
n := param2 MOD 32;
|
2019-03-11 09:59:55 +01:00
|
|
|
IF n # 1 THEN
|
|
|
|
OutByte(0C1H)
|
|
|
|
ELSE
|
|
|
|
OutByte(0D1H)
|
|
|
|
END;
|
2020-05-25 22:48:33 +02:00
|
|
|
shift(opcode, reg1); (* shift reg1, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
IF n # 1 THEN
|
|
|
|
OutByte(n)
|
|
|
|
END
|
|
|
|
|
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(07DH + ORD(opcode = IL.opMIN), 2); (* jge/jle L *)
|
|
|
|
mov(reg1, reg2);
|
|
|
|
(* 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);
|
2020-10-13 09:58:51 +02:00
|
|
|
label := NewLabel();
|
|
|
|
IF opcode = IL.opMINC THEN
|
|
|
|
cc := jle
|
|
|
|
ELSE
|
|
|
|
cc := jge
|
|
|
|
END;
|
|
|
|
jcc(cc, label);
|
|
|
|
movrc(reg1, param2);
|
|
|
|
SetLabel(label)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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();
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
cmprc(reg1, 32);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(72H, 4); (* jb L *)
|
2019-06-04 09:22:50 +02:00
|
|
|
xor(reg1, reg1);
|
2019-03-11 09:59:55 +01:00
|
|
|
jmp(label);
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
|
|
|
OutByte3(0FH, 0A3H, 0C0H + reg2 + 8 * reg1); (* bt reg2, reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setc, reg1);
|
|
|
|
andrc(reg1, 1);
|
|
|
|
SetLabel(label);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINL:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0BAH, 0E0H + reg1); OutByte(param2); (* bt reg1, param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setc, reg1);
|
|
|
|
andrc(reg1, 1)
|
|
|
|
|
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(pic, 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(pic, 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(pic, 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(pic, 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, 32);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(73H, 03H); (* jnb L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutByte(0FH);
|
2019-09-26 22:23:06 +02:00
|
|
|
IF opcode = IL.opINCL THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0ABH) (* bts dword[reg2], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0B3H) (* btr dword[reg2], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
OutByte(reg2 + 8 * reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
(* L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opINCLC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0BAH, 28H + reg1); OutByte(param2); (* bts dword[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEXCLC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0BAH, 30H + reg1); OutByte(param2); (* btr dword[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
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(pic, 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
|
|
|
IF n # 1 THEN
|
|
|
|
OutByte3(0C1H, 0F8H + reg1, n) (* sar reg1, n *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D1H, 0F8H + reg1) (* sar reg1, 1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF n < 0 THEN
|
|
|
|
PushAll(1);
|
|
|
|
pushc(param2);
|
|
|
|
CallRTL(pic, 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(pic, 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(pic, IL._divmod);
|
|
|
|
mov(eax, edx);
|
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(pic, IL._divmod);
|
|
|
|
mov(eax, edx);
|
|
|
|
GetRegA
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
|
|
|
UnOp(reg1);
|
2019-06-04 09:22:50 +02:00
|
|
|
xor(reg1, reg1)
|
2019-03-11 09:59:55 +01:00
|
|
|
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(pic, IL._divmod);
|
|
|
|
mov(eax, edx);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opERR:
|
|
|
|
CallRTL(pic, IL._error)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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(07DH, 002H); (* jge L *)
|
|
|
|
neg(reg1) (* neg reg1
|
|
|
|
L: *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCOPY:
|
2022-06-21 22:32:43 +02:00
|
|
|
IF (0 < param2) & (param2 <= 64) THEN
|
|
|
|
BinOp(reg1, reg2);
|
|
|
|
reg3 := GetAnyReg();
|
|
|
|
FOR n := 0 TO param2 - param2 MOD 4 - 1 BY 4 DO
|
|
|
|
movrm(reg3, reg1, n);
|
|
|
|
movmr(reg2, n, reg3)
|
|
|
|
END;
|
|
|
|
n := param2 - param2 MOD 4;
|
|
|
|
IF param2 MOD 4 >= 2 THEN
|
|
|
|
movrm16(reg3, reg1, n);
|
|
|
|
movmr16(reg2, n, reg3);
|
|
|
|
INC(n, 2);
|
|
|
|
DEC(param2, 2)
|
|
|
|
END;
|
|
|
|
IF param2 MOD 4 = 1 THEN
|
|
|
|
movrm8(reg3, reg1, n);
|
|
|
|
movmr8(reg2, n, reg3);
|
|
|
|
END;
|
|
|
|
drop;
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
ELSE
|
|
|
|
PushAll(2);
|
|
|
|
pushc(param2);
|
|
|
|
CallRTL(pic, 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(pic, 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(pic, 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(pic, 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(esp);
|
|
|
|
pushc(param2);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, 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
|
|
|
CASE TARGETS.OS OF
|
|
|
|
|TARGETS.osWIN32:
|
|
|
|
n := param2 + 4;
|
|
|
|
ASSERT(UTILS.Align(n, 4))
|
|
|
|
|TARGETS.osLINUX32:
|
|
|
|
n := param2 + 16;
|
|
|
|
ASSERT(UTILS.Align(n, 16))
|
|
|
|
|TARGETS.osKOS:
|
|
|
|
n := param2 + 8;
|
|
|
|
ASSERT(UTILS.Align(n, 32))
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(n);
|
|
|
|
pushc(param1);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, 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(pic, IL._dispose)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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(pic, 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(pic, IL._strcmpw);
|
2019-03-11 09:59:55 +01:00
|
|
|
GetRegA
|
|
|
|
|
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
|
|
|
CASE opcode OF
|
|
|
|
|IL.opEQP, IL.opNEP:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg2, BIN.PICCODE, param1);
|
|
|
|
cmprr(reg1, reg2);
|
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(081H, 0F8H + reg1); (* cmp reg1, L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RCODE, param1)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQIP, IL.opNEIP:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg2 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg2, BIN.PICIMP, param1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(03BH, reg1 * 8 + reg2); (* cmp reg1, dword [reg2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(3BH, 05H + reg1 * 8); (* cmp reg1, dword[L] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RIMP, param1)
|
|
|
|
END
|
|
|
|
|
|
|
|
END;
|
|
|
|
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.opPUSHT:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
movrm(GetAnyReg(), reg1, -4)
|
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(pic, 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(pic, 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(pic, 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(pic, 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
|
|
|
pushm(reg1, -4);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(pic, 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(ecx);
|
|
|
|
push(ecx);
|
2019-09-26 22:23:06 +02:00
|
|
|
pushc(param2 * tcount);
|
|
|
|
CallRTL(pic, IL._guardrec);
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(ecx);
|
|
|
|
test(eax);
|
|
|
|
jcc(jne, param1)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPACK:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
|
|
|
push(reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0DBH, 004H, 024H); (* fild dword[esp] *)
|
|
|
|
OutByte2(0DDH, reg1); (* fld qword[reg1] *)
|
|
|
|
OutByte2(0D9H, 0FDH); (* fscale *)
|
|
|
|
OutByte2(0DDH, 018H + reg1); (* fstp qword[reg1] *)
|
|
|
|
OutByte3(0DBH, 01CH, 024H); (* fistp dword[esp] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(reg2);
|
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPACKC:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
pushc(param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0DBH, 004H, 024H); (* fild dword[esp] *)
|
|
|
|
OutByte2(0DDH, reg1); (* fld qword[reg1] *)
|
|
|
|
OutByte2(0D9H, 0FDH); (* fscale *)
|
|
|
|
OutByte2(0DDH, 018H + reg1); (* fstp qword[reg1] *)
|
|
|
|
OutByte3(0DBH, 01CH, 024H); (* fistp dword[esp] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(reg1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opUNPK:
|
2019-03-11 09:59:55 +01:00
|
|
|
BinOp(reg1, reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DDH, reg1); (* fld qword[reg1] *)
|
|
|
|
OutByte2(0D9H, 0F4H); (* fxtract *)
|
|
|
|
OutByte2(0DDH, 018H + reg1); (* fstp qword[reg1] *)
|
|
|
|
OutByte2(0DBH, 018H + reg2); (* fistp dword[reg2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opPUSHF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 0);
|
|
|
|
DEC(fr);
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(esp, 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0DDH, 01CH, 024H) (* fstp qword[esp] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOADF:
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(fr);
|
|
|
|
IF fr > MAX_FR THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DDH, reg1); (* fld qword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opCONSTF:
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(fr);
|
|
|
|
IF fr > MAX_FR THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
float := cmd.float;
|
|
|
|
IF float = 0.0 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D9H, 0EEH) (* fldz *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF float = 1.0 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D9H, 0E8H) (* fld1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSIF float = -1.0 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D9H, 0E8H); (* fld1 *)
|
|
|
|
OutByte2(0D9H, 0E0H) (* fchs *)
|
2019-03-11 09:59:55 +01:00
|
|
|
ELSE
|
2022-08-31 22:51:32 +02:00
|
|
|
LoadFltConst(float)
|
2019-03-11 09:59:55 +01:00
|
|
|
END
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opSAVEF, IL.opSAVEFI:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 0);
|
|
|
|
DEC(fr);
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DDH, 018H + reg1); (* fstp qword[reg1] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
|IL.opADDF:
|
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DEH, 0C1H) (* faddp st1, st *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DEH, 0E9H) (* fsubp st1, st *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSUBFI:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DEH, 0E1H) (* fsubrp st1, st *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opMULF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DEH, 0C9H) (* fmulp st1, st *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DEH, 0F9H) (* fdivp st1, st *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opDIVFI:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DEH, 0F1H) (* fdivrp st1, st *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opUMINF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D9H, 0E0H) (* fchs *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFABS:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D9H, 0E1H) (* fabs *)
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFLT:
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(fr);
|
|
|
|
IF fr > MAX_FR THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
|
|
|
push(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0DBH, 004H, 024H); (* fild dword[esp] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
pop(reg1);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opFLOOR:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 0);
|
|
|
|
DEC(fr);
|
2019-03-11 09:59:55 +01:00
|
|
|
subrc(esp, 8);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(09BH, 0D9H); OutByte3(07CH, 024H, 004H); (* fstcw word[esp+4] *)
|
|
|
|
OutByte2(09BH, 0D9H); OutByte3(07CH, 024H, 006H); (* fstcw word[esp+6] *)
|
|
|
|
OutByte2(066H, 081H); OutByte3(064H, 024H, 004H); OutWord(0F3FFH); (* and word[esp+4], 1111001111111111b *)
|
|
|
|
OutByte2(066H, 081H); OutByte3(04CH, 024H, 004H); OutWord(00400H); (* or word[esp+4], 0000010000000000b *)
|
|
|
|
OutByte2(0D9H, 06CH); OutByte2(024H, 004H); (* fldcw word[esp+4] *)
|
|
|
|
OutByte2(0D9H, 0FCH); (* frndint *)
|
|
|
|
OutByte3(0DBH, 01CH, 024H); (* fistp dword[esp] *)
|
2019-09-26 22:23:06 +02:00
|
|
|
pop(GetAnyReg());
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0D9H, 06CH); OutByte2(024H, 002H); (* fldcw word[esp+2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
addrc(esp, 4)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opEQF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr, 2);
|
2020-05-25 22:48:33 +02:00
|
|
|
fcmp;
|
|
|
|
OutByte2(07AH, 003H); (* jp L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(sete, al)
|
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.opNEF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr, 2);
|
2020-05-25 22:48:33 +02:00
|
|
|
fcmp;
|
|
|
|
OutByte2(07AH, 003H); (* jp L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setne, al)
|
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.opLTF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr, 2);
|
2020-05-25 22:48:33 +02:00
|
|
|
fcmp;
|
|
|
|
OutByte2(07AH, 00EH); (* jp L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setc, al);
|
|
|
|
setcc(sete, ah);
|
|
|
|
test(eax);
|
|
|
|
setcc(sete, al);
|
|
|
|
andrc(eax, 1)
|
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.opGTF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr, 2);
|
2020-05-25 22:48:33 +02:00
|
|
|
fcmp;
|
|
|
|
OutByte2(07AH, 00FH); (* jp L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setc, al);
|
|
|
|
setcc(sete, ah);
|
|
|
|
cmprc(eax, 1);
|
|
|
|
setcc(sete, al);
|
|
|
|
andrc(eax, 1)
|
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.opLEF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr, 2);
|
2020-05-25 22:48:33 +02:00
|
|
|
fcmp;
|
|
|
|
OutByte2(07AH, 003H); (* jp L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setnc, al)
|
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.opGEF:
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(fr >= 1);
|
|
|
|
DEC(fr, 2);
|
2020-05-25 22:48:33 +02:00
|
|
|
fcmp;
|
|
|
|
OutByte2(07AH, 010H); (* jp L *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(setc, al);
|
|
|
|
setcc(sete, ah);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(000H, 0E0H); (* add al, ah *)
|
|
|
|
OutByte2(03CH, 001H); (* cmp al, 1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
setcc(sete, al);
|
|
|
|
andrc(eax, 1)
|
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.opINF:
|
2020-10-13 09:58:51 +02:00
|
|
|
INC(fr);
|
|
|
|
IF fr > MAX_FR THEN
|
|
|
|
ERRORS.ErrorMsg(fname, param1, param2, FPR_ERR)
|
|
|
|
END;
|
2022-08-31 22:51:32 +02:00
|
|
|
LoadFltConst(UTILS.inf)
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_UNPK:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 4;
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(8DH, 45H + reg1 * 8 + long(n)); (* lea reg1, dword[ebp + n] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
BinOp(reg1, reg2);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0DDH, reg1); (* fld qword[reg1] *)
|
|
|
|
OutByte2(0D9H, 0F4H); (* fxtract *)
|
|
|
|
OutByte2(0DDH, 018H + reg1); (* fstp qword[reg1] *)
|
|
|
|
OutByte2(0DBH, 018H + reg2); (* fistp dword[reg2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop;
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opSADR_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICDATA, stroffs + param2);
|
|
|
|
push(reg1);
|
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(068H); (* push _data + stroffs + param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RDATA, stroffs + param2)
|
|
|
|
END
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
|IL.opVADR_PARAM, IL.opLLOAD32_PARAM:
|
|
|
|
pushm(ebp, param2 * 4)
|
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)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGLOAD32_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICBSS, param2);
|
2020-05-25 22:48:33 +02:00
|
|
|
pushm(reg1, 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 035H); (* push dword[_bss + param2] *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RBSS, param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLOAD32_PARAM:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
pushm(reg1, 0);
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opGADR_SAVEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICBSS, param1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0C7H, reg1); (* mov dword[reg1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutInt(param2);
|
|
|
|
drop
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0C7H, 05H); (* mov dword[_bss + param1], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RBSS, param1);
|
|
|
|
OutInt(param2)
|
|
|
|
END
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_SAVEC:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param1 * 4;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0C7H, 45H + long(n)); (* mov dword[ebp + n], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
OutInt(param2)
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_SAVE:
|
2019-03-11 09:59:55 +01:00
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
movmr(ebp, param2 * 4, 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
|
|
|
n := param1 * 4;
|
2019-09-26 22:23:06 +02:00
|
|
|
IF ABS(param2) = 1 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FFH, 45H + 8 * ORD(param2 = -1) + long(n)); (* inc/dec dword[ebp + n] *)
|
2019-09-26 22:23:06 +02:00
|
|
|
OutIntByte(n)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(81H + short(param2), 45H + long(n)); (* add dword[ebp + n], param2 *)
|
2019-09-26 22:23:06 +02:00
|
|
|
OutIntByte(n);
|
|
|
|
OutIntByte(param2)
|
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCCB, IL.opLADR_DECCB:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param1 * 4;
|
2019-09-26 22:23:06 +02:00
|
|
|
IF param2 = 1 THEN
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(0FEH, 45H + 8 * ORD(opcode = IL.opLADR_DECCB) + long(n)); (* inc/dec byte[ebp + n] *)
|
2019-09-26 22:23:06 +02:00
|
|
|
OutIntByte(n)
|
|
|
|
ELSE
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(80H, 45H + 28H * ORD(opcode = IL.opLADR_DECCB) + long(n)); (* add/sub byte[ebp + n], param2 *)
|
2019-09-26 22:23:06 +02:00
|
|
|
OutIntByte(n);
|
|
|
|
OutByte(param2 MOD 256)
|
|
|
|
END
|
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
|
|
|
n := param2 * 4;
|
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(01H + 28H * ORD(opcode = IL.opLADR_DEC), 45H + long(n) + reg1 * 8); (* add/sub dword[ebp + n], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCB, IL.opLADR_DECB:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 4;
|
|
|
|
UnOp(reg1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte2(28H * ORD(opcode = IL.opLADR_DECB), 45H + long(n) + reg1 * 8); (* add/sub byte[ebp + n], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCL, IL.opLADR_EXCL:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param2 * 4;
|
|
|
|
UnOp(reg1);
|
|
|
|
cmprc(reg1, 32);
|
|
|
|
label := NewLabel();
|
|
|
|
jcc(jnb, label);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0ABH + 8 * ORD(opcode = IL.opLADR_EXCL), 45H + long(n) + reg1 * 8); (* bts(r) dword[ebp + n], reg1 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
SetLabel(label);
|
|
|
|
drop
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
|IL.opLADR_INCLC, IL.opLADR_EXCLC:
|
2019-03-11 09:59:55 +01:00
|
|
|
n := param1 * 4;
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte3(0FH, 0BAH, 6DH + long(n) + 8 * ORD(opcode = IL.opLADR_EXCLC)); (* bts(r) dword[ebp + n], param2 *)
|
2019-03-11 09:59:55 +01:00
|
|
|
OutIntByte(n);
|
|
|
|
OutByte(param2)
|
|
|
|
|
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)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
ASSERT(R.pushed = 0);
|
2020-10-13 09:58:51 +02:00
|
|
|
ASSERT(R.top = -1);
|
|
|
|
ASSERT(fr = -1)
|
2019-03-11 09:59:55 +01:00
|
|
|
END translate;
|
|
|
|
|
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
PROCEDURE prolog (pic: BOOLEAN; target, stack, dllret: INTEGER): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-10-06 19:55:12 +02:00
|
|
|
reg1, entry, L, dcount: INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
entry := NewLabel();
|
|
|
|
SetLabel(entry);
|
2020-10-13 09:58:51 +02:00
|
|
|
dcount := CHL.Length(IL.codes.data);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
push(ebp);
|
|
|
|
mov(ebp, esp);
|
|
|
|
SetLabel(NewLabel());
|
|
|
|
mainFltConstLabel := CodeList.last(LABEL);
|
|
|
|
FltConstLabel := mainFltConstLabel;
|
|
|
|
mainLocVarSize := 0;
|
|
|
|
LocVarSize := 0;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.Win32DLL THEN
|
|
|
|
pushm(ebp, 16);
|
|
|
|
pushm(ebp, 12);
|
|
|
|
pushm(ebp, 8);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, IL._dllentry);
|
2019-03-11 09:59:55 +01:00
|
|
|
test(eax);
|
2020-10-13 09:58:51 +02:00
|
|
|
jcc(je, dllret);
|
|
|
|
pushc(0)
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF target = TARGETS.KolibriOSDLL THEN
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte(68H); (* push IMPORT *)
|
|
|
|
Reloc(BIN.IMPTAB, 0)
|
|
|
|
ELSIF target = TARGETS.KolibriOS THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.IMPTAB, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
push(reg1); (* push IMPORT *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF target = TARGETS.Linux32 THEN
|
2022-08-31 22:51:32 +02:00
|
|
|
mov(eax, ebp);
|
|
|
|
addrc(eax, 4);
|
|
|
|
push(eax)
|
2016-10-24 01:30:27 +02:00
|
|
|
ELSE
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(0)
|
2019-06-04 09:22:50 +02:00
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IF pic THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
reg1 := GetAnyReg();
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICCODE, entry);
|
2020-10-13 09:58:51 +02:00
|
|
|
push(reg1); (* push CODE *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICDATA, 0);
|
2020-05-25 22:48:33 +02:00
|
|
|
push(reg1); (* push _data *)
|
2020-10-13 09:58:51 +02:00
|
|
|
pushc(tcount);
|
2019-03-11 09:59:55 +01:00
|
|
|
Pic(reg1, BIN.PICDATA, tcount * 4 + dcount);
|
2020-05-25 22:48:33 +02:00
|
|
|
push(reg1); (* push _data + tcount * 4 + dcount *)
|
2019-03-11 09:59:55 +01:00
|
|
|
drop
|
2016-10-24 01:30:27 +02:00
|
|
|
ELSE
|
2020-10-13 09:58:51 +02:00
|
|
|
OutByte(68H); (* push CODE *)
|
|
|
|
Reloc(BIN.RCODE, entry);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(68H); (* push _data *)
|
2020-10-13 09:58:51 +02:00
|
|
|
Reloc(BIN.RDATA, 0);
|
|
|
|
pushc(tcount);
|
|
|
|
OutByte(68H); (* push _data + tcount * 4 + dcount *)
|
2019-03-11 09:59:55 +01:00
|
|
|
Reloc(BIN.RDATA, tcount * 4 + dcount)
|
|
|
|
END;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
CallRTL(pic, IL._init);
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
IF target IN {TARGETS.Win32C, TARGETS.Win32GUI, TARGETS.Linux32} THEN
|
2019-10-06 19:55:12 +02:00
|
|
|
L := NewLabel();
|
|
|
|
pushc(0);
|
|
|
|
push(esp);
|
|
|
|
pushc(1024 * 1024 * stack);
|
|
|
|
pushc(0);
|
|
|
|
CallRTL(pic, IL._new);
|
|
|
|
pop(eax);
|
|
|
|
test(eax);
|
|
|
|
jcc(je, L);
|
|
|
|
addrc(eax, 1024 * 1024 * stack - 4);
|
|
|
|
mov(esp, eax);
|
|
|
|
SetLabel(L)
|
|
|
|
END
|
2022-08-31 22:51:32 +02:00
|
|
|
|
|
|
|
RETURN entry
|
2019-03-11 09:59:55 +01:00
|
|
|
END prolog;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE epilog (pic: BOOLEAN; modname: ARRAY OF CHAR; target, stack, ver, dllinit, dllret, sofinit: INTEGER);
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2019-09-26 22:23:06 +02:00
|
|
|
exp: IL.EXPORT_PROC;
|
2019-03-11 09:59:55 +01:00
|
|
|
path, name, ext: PATHS.PATH;
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
dcount, i: INTEGER;
|
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(program, 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(program, 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;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target IN {TARGETS.Win32C, TARGETS.Win32GUI, TARGETS.KolibriOS, TARGETS.Linux32} THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
pushc(0);
|
2019-09-26 22:23:06 +02:00
|
|
|
CallRTL(pic, IL._exit);
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF target = TARGETS.Win32DLL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
SetLabel(dllret);
|
|
|
|
movrc(eax, 1);
|
2020-05-25 22:48:33 +02:00
|
|
|
OutByte(0C9H); (* leave *)
|
|
|
|
OutByte3(0C2H, 0CH, 0) (* ret 12 *)
|
|
|
|
ELSIF target = TARGETS.KolibriOSDLL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
movrc(eax, 1);
|
2022-08-31 22:51:32 +02:00
|
|
|
OutByte(0C9H); (* leave *)
|
2020-05-25 22:48:33 +02:00
|
|
|
ret
|
|
|
|
ELSIF target = TARGETS.Linux32SO THEN
|
2022-08-31 22:51:32 +02:00
|
|
|
OutByte(0C9H); (* leave *)
|
2020-05-25 22:48:33 +02:00
|
|
|
ret;
|
2019-09-26 22:23:06 +02:00
|
|
|
SetLabel(sofinit);
|
|
|
|
CallRTL(pic, IL._sofinit);
|
2020-05-25 22:48:33 +02:00
|
|
|
ret
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
fixup;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
dcount := CHL.Length(IL.codes.data);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
FOR i := 0 TO tcount - 1 DO
|
2019-10-06 19:55:12 +02:00
|
|
|
BIN.PutData32LE(program, CHL.GetInt(IL.codes.types, i))
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
FOR i := 0 TO dcount - 1 DO
|
2019-10-06 19:55:12 +02:00
|
|
|
BIN.PutData(program, CHL.GetByte(IL.codes.data, i))
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
program.modname := CHL.Length(program.data);
|
|
|
|
|
|
|
|
PATHS.split(modname, path, name, ext);
|
|
|
|
BIN.PutDataStr(program, name);
|
|
|
|
BIN.PutDataStr(program, ext);
|
|
|
|
BIN.PutData(program, 0);
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.KolibriOSDLL THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
BIN.Export(program, "lib_init", dllinit);
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
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(program, exp.name, exp.label);
|
2019-09-26 22:23:06 +02:00
|
|
|
exp := exp.next(IL.EXPORT_PROC)
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
_import(IL.codes._import);
|
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), 4)));
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
BIN.SetParams(program, IL.codes.bss, stack * (1024 * 1024), WCHR(ver DIV 65536), WCHR(ver MOD 65536))
|
2019-03-11 09:59:55 +01:00
|
|
|
END epilog;
|
|
|
|
|
|
|
|
|
2023-01-21 15:34:25 +01:00
|
|
|
PROCEDURE align16* (bit64: BOOLEAN);
|
|
|
|
BEGIN
|
|
|
|
IF TARGETS.WinLin THEN
|
|
|
|
WHILE CHL.Length(IL.codes.data) MOD 16 # 0 DO
|
|
|
|
CHL.PushByte(IL.codes.data, 0)
|
|
|
|
END;
|
|
|
|
WHILE CHL.Length(IL.codes.types) MOD (4 - 2*ORD(bit64)) # 0 DO
|
|
|
|
CHL.PushInt(IL.codes.types, 0)
|
|
|
|
END
|
|
|
|
END
|
|
|
|
END align16;
|
|
|
|
|
|
|
|
|
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
|
2019-09-26 22:23:06 +02:00
|
|
|
dllret, dllinit, sofinit: INTEGER;
|
|
|
|
opt: PROG.OPTIONS;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
FR[0] := 0;
|
2023-01-21 15:34:25 +01:00
|
|
|
align16(FALSE);
|
2019-10-06 19:55:12 +02:00
|
|
|
tcount := CHL.Length(IL.codes.types);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
opt := options;
|
2019-03-11 09:59:55 +01:00
|
|
|
CodeList := LISTS.create(NIL);
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
program := BIN.create(IL.codes.lcount);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
dllret := NewLabel();
|
2019-09-26 22:23:06 +02:00
|
|
|
sofinit := NewLabel();
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF target = TARGETS.KolibriOSDLL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
opt.pic := FALSE
|
2016-10-24 01:30:27 +02:00
|
|
|
END;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.OS IN {TARGETS.osWIN32, TARGETS.osLINUX32} THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
opt.pic := TRUE
|
2019-03-11 09:59:55 +01:00
|
|
|
END;
|
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
REG.Init(R, push, pop, mov, xchg, {eax, ecx, edx});
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2022-08-31 22:51:32 +02:00
|
|
|
dllinit := prolog(opt.pic, target, opt.stack, dllret);
|
2019-10-06 19:55:12 +02:00
|
|
|
translate(opt.pic, tcount * 4);
|
|
|
|
epilog(opt.pic, outname, target, opt.stack, opt.version, dllinit, dllret, sofinit);
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
BIN.fixup(program);
|
2020-05-25 22:48:33 +02:00
|
|
|
IF TARGETS.OS = TARGETS.osWIN32 THEN
|
|
|
|
PE32.write(program, outname, target = TARGETS.Win32C, target = TARGETS.Win32DLL, FALSE)
|
|
|
|
ELSIF target = TARGETS.KolibriOS THEN
|
2019-03-11 09:59:55 +01:00
|
|
|
KOS.write(program, outname)
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF target = TARGETS.KolibriOSDLL THEN
|
2019-09-26 22:23:06 +02:00
|
|
|
MSCOFF.write(program, outname, opt.version)
|
2020-05-25 22:48:33 +02:00
|
|
|
ELSIF TARGETS.OS = TARGETS.osLINUX32 THEN
|
|
|
|
ELF.write(program, outname, sofinit, target = TARGETS.Linux32SO, FALSE)
|
2016-10-24 01:30:27 +02:00
|
|
|
END
|
2019-03-11 09:59:55 +01:00
|
|
|
END CodeGen;
|
|
|
|
|
2018-03-23 23:01:12 +01:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE SetProgram* (prog: BIN.PROGRAM);
|
2018-03-23 23:01:12 +01:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
program := prog;
|
|
|
|
CodeList := LISTS.create(NIL)
|
|
|
|
END SetProgram;
|
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
END X86.
|