Merge branch 'master' of https://codeberg.org/eaxcc/eaxcc
This commit is contained in:
@ -8,9 +8,9 @@
|
||||
#define IRREGULAR_BEGIN (INC)
|
||||
#define IRREGULAR_END (IDIV)
|
||||
#define SPECIAL_1_BEGIN (NOP)
|
||||
#define SPECIAL_1_END (HLT)
|
||||
#define SPECIAL_1_END (PUSHF)
|
||||
#define SPECIAL_2_BEGIN (SYSENTER)
|
||||
#define SPECIAL_2_END (CPUID)
|
||||
#define SPECIAL_2_END (EMMS)
|
||||
#define JUMP_IF_BEGIN (JO)
|
||||
#define JUMP_IF_END (JG)
|
||||
#define MOVE_IF_BEGIN (CMOVO)
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
#define REGULAR_COUNT (REGULAR_END - REGULAR_BEGIN + 1) // 16
|
||||
#define IRREGULAR_COUNT (IRREGULAR_END - IRREGULAR_BEGIN + 1) // 16
|
||||
#define SPECIAL_1_COUNT (SPECIAL_1_END - SPECIAL_1_BEGIN + 1) // 6
|
||||
#define SPECIAL_1_COUNT (SPECIAL_1_END - SPECIAL_1_BEGIN + 1) // 8
|
||||
#define SPECIAL_2_COUNT (SPECIAL_2_END - SPECIAL_2_BEGIN + 1) // 6
|
||||
#define JUMP_IF_COUNT (JUMP_IF_END - JUMP_IF_BEGIN + 1) // 16
|
||||
#define MOVE_IF_COUNT (MOVE_IF_END - MOVE_IF_BEGIN + 1) // 16
|
||||
@ -144,7 +144,7 @@ static void build_regular (operation_index operation,
|
||||
next destination,
|
||||
type_index from,
|
||||
next source) {
|
||||
// 00-3F : add, or, adc, sbb, and, sub, xor, cmp
|
||||
// 00-3F : add, or, adc, sbb, and, sub, xor, cmp;
|
||||
build_short_prefix (size == D16);
|
||||
|
||||
build_long_prefix (size == D64,
|
||||
@ -194,7 +194,7 @@ static void build_irregular (operation_index operation,
|
||||
size_index size,
|
||||
type_index to,
|
||||
next destination) {
|
||||
// F0-FF : inc, dec, not, neg, mul, imul, div, idiv
|
||||
// F0-FF : inc, dec, not, neg, mul, imul, div, idiv;
|
||||
build_short_prefix (size == D16);
|
||||
|
||||
build_long_prefix (size == D64,
|
||||
@ -219,19 +219,19 @@ static void build_irregular (operation_index operation,
|
||||
}
|
||||
|
||||
static void build_special_1 (operation_index operation) {
|
||||
// nop, retn, retf, leave, lock, hlt
|
||||
// XX : nop, retn, retf, leave, lock, hlt, popf, pushf;
|
||||
const byte data [1 * SPECIAL_1_COUNT] = {
|
||||
0x90, 0xc3, 0xcb, 0xc9, 0xf0, 0xf4
|
||||
0x90, 0xc3, 0xcb, 0xc9, 0xf0, 0xf4, 0x9d, 0x9c
|
||||
};
|
||||
|
||||
input (1, data [operation - SPECIAL_1_BEGIN]);
|
||||
}
|
||||
|
||||
static void build_special_2 (operation_index operation) {
|
||||
// sysenter, sysleave, syscall, sysret, pause, cpuid
|
||||
// XX XX : sysenter, sysleave, syscall, sysret, pause, cpuid, emms;
|
||||
const byte data [2 * SPECIAL_2_COUNT] = {
|
||||
0x0f, 0x0f, 0x0f, 0x0f, 0xf3, 0x0f,
|
||||
0x34, 0x35, 0x05, 0x07, 0x90, 0xa2
|
||||
0x0f, 0x0f, 0x0f, 0x0f, 0xf3, 0x0f, 0x0f,
|
||||
0x34, 0x35, 0x05, 0x07, 0x90, 0xa2, 0x77
|
||||
};
|
||||
|
||||
input (1, data [operation - SPECIAL_2_BEGIN]);
|
||||
@ -328,9 +328,71 @@ static void build_move (size_index size,
|
||||
static void build_call (type_index from,
|
||||
next source) {
|
||||
// call
|
||||
input ((from == REG) && (upper ((form) source)), (byte) 0x41);
|
||||
|
||||
input (from == REL, (byte) 0xe8);
|
||||
input (from == REG, (byte) 0xff);
|
||||
|
||||
input_at (from == REL, D32, source, (next) -(text_sector_size + 4));
|
||||
|
||||
input (from == REG, (byte) (0xd0 + 0x01 * (source & 0x07)));
|
||||
}
|
||||
|
||||
static void build_enter (next dynamic_storage,
|
||||
next nesting_level) {
|
||||
// enter
|
||||
input (1, (byte) 0xc8);
|
||||
|
||||
input_by (1, D16, dynamic_storage);
|
||||
input_by (1, D8, nesting_level & (next) 0x1f);
|
||||
}
|
||||
|
||||
static void build_in_out (form move,
|
||||
size_index size,
|
||||
type_index type,
|
||||
next port) {
|
||||
// E4-EF : in, out;
|
||||
build_short_prefix (size == D16);
|
||||
|
||||
input (1,
|
||||
(byte) 0xe4
|
||||
+ 0x01 * (size != D8)
|
||||
+ 0x02 * (move != OUT)
|
||||
+ 0x08 * (type == REG));
|
||||
|
||||
input_by (type == IMM, D8, port);
|
||||
}
|
||||
|
||||
static void build_pop (size_index size,
|
||||
type_index to,
|
||||
next destination) {
|
||||
// pop
|
||||
build_short_prefix (size == D16);
|
||||
|
||||
input ((to == REG) && (upper ((form) destination)), (byte) 0x41);
|
||||
|
||||
input (to == REG, (byte) (0x58 + 0x01 * (destination & 0x07)));
|
||||
input (to == MEM, (byte) 0x8f);
|
||||
input (to == MEM, (byte) 0x05);
|
||||
|
||||
input_at (to == MEM, D32, destination, 0);
|
||||
}
|
||||
|
||||
static void build_push (size_index size,
|
||||
type_index from,
|
||||
next source) {
|
||||
// push
|
||||
build_short_prefix (size == D16);
|
||||
|
||||
input ((from == REG) && (upper ((form) source)), (byte) 0x41);
|
||||
|
||||
input (from == REG, (byte) (0x50 + 0x01 * (source & 0x07)));
|
||||
input (from == MEM, (byte) 0xff);
|
||||
input (from == MEM, (byte) 0x35);
|
||||
input (from == IMM, (byte) 0x68 + 0x02 * (size == D8));
|
||||
|
||||
input_at (from == MEM, D32, source, 0);
|
||||
input_by (from == IMM, size, source);
|
||||
}
|
||||
|
||||
static void assemble_clean_up (void) {
|
||||
@ -429,6 +491,21 @@ void assemble (next count,
|
||||
} else if (array [index] == CALL) {
|
||||
build_call (array [index + 1], array [index + 2]);
|
||||
index += 2;
|
||||
} else if (array [index] == ENTER) {
|
||||
build_enter (array [index + 1], array [index + 2]);
|
||||
index += 2;
|
||||
} else if ((array [index] == IN) || (array [index] == OUT)) {
|
||||
build_in_out (array [index + 0], array [index + 1],
|
||||
array [index + 2], array [index + 3]);
|
||||
index += 3;
|
||||
} else if (array [index] == POP) {
|
||||
build_pop (array [index + 1], array [index + 2],
|
||||
array [index + 3]);
|
||||
index += 3;
|
||||
} else if (array [index] == PUSH) {
|
||||
build_push (array [index + 1], array [index + 2],
|
||||
array [index + 3]);
|
||||
index += 3;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@ -438,8 +515,11 @@ void assemble (next count,
|
||||
|
||||
for (index = 0; index < empty_holes; ++index) {
|
||||
next set = 0, get = empty_array [index];
|
||||
|
||||
memcpy (& set, & text_sector_byte [get], sizeof (set));
|
||||
|
||||
set += empty_store [empty_imbue [index]];
|
||||
|
||||
memcpy (& text_sector_byte [get], & set, sizeof (set));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ typedef signed int form;
|
||||
typedef unsigned int next;
|
||||
typedef unsigned char byte;
|
||||
|
||||
// XXX: we could be using binary literals IF SOMEONE WERE WILLING TO UPGRADE HIS GRANNY SYSTEM
|
||||
typedef enum {
|
||||
D8 = 0,
|
||||
D16 = 1,
|
||||
@ -17,37 +16,37 @@ typedef enum {
|
||||
} type_index;
|
||||
|
||||
typedef enum {
|
||||
ASMDIRMEM, // Assembler directive: >LABEL '"goto" clabel;'
|
||||
ASMDIRREL, // Assembler directive: LABEL: 'clabel:'
|
||||
ASMDIRIMM, // Assembler directive: D8-D64 {REDO} {DATA}
|
||||
ASMDIRREP, // Assembler directive: ...
|
||||
/* HIGHLY EXPERIMENTAL CODE ABOVE... */
|
||||
ASMDIRMEM, // Assembler directive: Insert label location.
|
||||
ASMDIRREL, // Assembler directive: Insert relative location.
|
||||
ASMDIRIMM, // Assembler directive: Append immediate.
|
||||
ASMDIRREP, // Assembler directive: --
|
||||
//
|
||||
ADD, OR, ADC, SBB,
|
||||
AND, SUB, XOR, CMP,
|
||||
/* */
|
||||
//
|
||||
INC, DEC, NOT, NEG,
|
||||
MUL, IMUL, DIV, IDIV,
|
||||
/* */
|
||||
//
|
||||
NOP, RETN, RETF, LEAVE,
|
||||
LOCK, HLT,
|
||||
/* */
|
||||
LOCK, HLT, POPF, PUSHF,
|
||||
//
|
||||
SYSENTER, SYSEXIT, SYSCALL, SYSRET,
|
||||
PAUSE, CPUID,
|
||||
/* */
|
||||
PAUSE, CPUID, EMMS,
|
||||
//
|
||||
ENTER, CALL, IN, OUT,
|
||||
/* */
|
||||
//
|
||||
JMP,
|
||||
JO, JNO, JB, JAE,
|
||||
JE, JNE, JBE, JA,
|
||||
JS, JNS, JPE, JPO,
|
||||
JL, JGE, JLE, JG,
|
||||
/* */
|
||||
//
|
||||
MOV,
|
||||
CMOVO, CMOVNO, CMOVB, CMOVAE,
|
||||
CMOVE, CMOVNE, CMOVBE, CMOVA,
|
||||
CMOVS, CMOVNS, CMOVPE, CMOVPO,
|
||||
CMOVL, CMOVGE, CMOVLE, CMOVG,
|
||||
/* */
|
||||
//
|
||||
PUSH, POP, BSWAP, TEST,
|
||||
RCL, RCR, ROL, ROR,
|
||||
SHL, SHR, SAL, SAR,
|
||||
|
110
test/proc.asm
110
test/proc.asm
@ -1,71 +1,45 @@
|
||||
; fasm proc.asm proc && chmod +x proc && ./proc
|
||||
fast procedure heyo
|
||||
s8 <> h = "Heyo world!\n"
|
||||
begin
|
||||
nop mov eax 1
|
||||
nop mov edi 1
|
||||
nop mov esi h
|
||||
nop mov edx 12
|
||||
nop syscall
|
||||
end procedure
|
||||
|
||||
format ELF64 executable 3
|
||||
fast procedure lnao
|
||||
s8 <> l = "Lnao world!!!!\n"
|
||||
begin
|
||||
nop mov eax 1
|
||||
nop mov edi 1
|
||||
nop mov esi l
|
||||
nop mov edx 15
|
||||
nop syscall
|
||||
end procedure
|
||||
|
||||
segment readable executable
|
||||
fast procedure cyaa
|
||||
s8 <> c = "Cyaa world!!!\n"
|
||||
begin
|
||||
nop mov eax 1
|
||||
nop mov edi 1
|
||||
nop mov esi c
|
||||
nop mov edx 14
|
||||
nop syscall
|
||||
end procedure
|
||||
|
||||
entry main
|
||||
|
||||
heyo:
|
||||
nop
|
||||
mov eax, 1
|
||||
nop
|
||||
mov edi, 1
|
||||
nop
|
||||
mov esi, h
|
||||
nop
|
||||
mov edx, 12
|
||||
nop
|
||||
syscall
|
||||
nop
|
||||
call meme
|
||||
nop
|
||||
ret
|
||||
|
||||
cyaa:
|
||||
nop
|
||||
mov eax, 1
|
||||
nop
|
||||
mov edi, 1
|
||||
nop
|
||||
mov esi, c
|
||||
nop
|
||||
mov edx, 12
|
||||
nop
|
||||
syscall
|
||||
nop
|
||||
ret
|
||||
|
||||
main:
|
||||
nop
|
||||
call heyo
|
||||
nop
|
||||
call cyaa
|
||||
nop
|
||||
mov eax, 60
|
||||
nop
|
||||
mov edi, 60
|
||||
nop
|
||||
syscall
|
||||
|
||||
meme:
|
||||
nop
|
||||
mov eax, 1
|
||||
nop
|
||||
mov edi, 1
|
||||
nop
|
||||
mov esi, m
|
||||
nop
|
||||
mov edx, 12
|
||||
nop
|
||||
syscall
|
||||
nop
|
||||
ret
|
||||
|
||||
nop
|
||||
|
||||
segment readable writable
|
||||
|
||||
h: db "Heyo world!", 10
|
||||
c: db "Cyaa world!", 10
|
||||
m: db "Meme world!", 10
|
||||
unix program main
|
||||
s8 <> m = "Meme world!!\n"
|
||||
begin
|
||||
nop fastcall heyo
|
||||
nop mov eax 1
|
||||
nop mov edi 1
|
||||
nop mov esi m
|
||||
nop mov edx 13
|
||||
nop syscall
|
||||
nop fastcall cyaa
|
||||
nop fastcall lnao
|
||||
nop mov eax 60
|
||||
nop mov edi 60
|
||||
nop syscall
|
||||
end program
|
||||
|
@ -47,12 +47,31 @@ main:
|
||||
syscall
|
||||
nop
|
||||
call cyaa
|
||||
lod:
|
||||
nop
|
||||
mov eax, 60
|
||||
nop
|
||||
mov edi, 60
|
||||
nop
|
||||
syscall
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
call rax
|
||||
nop
|
||||
call rcx
|
||||
nop
|
||||
call r8
|
||||
nop
|
||||
call r9
|
||||
nop
|
||||
call loc
|
||||
nop
|
||||
call lod
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
|
||||
segment readable writable
|
||||
|
||||
@ -60,6 +79,8 @@ h: db "Heyo world!", 10
|
||||
m: db "Meme world!!", 10
|
||||
c: db "Cyaa world!!!", 10
|
||||
|
||||
loc: dq 0
|
||||
|
||||
;~FASM EAXHLA
|
||||
;~7F 45 4C 46 02 01 01 03 00 00 00 00 00 00 00 00 7F 45 4C 46 02 01 01 03 00 00 00 00 00 00 00 00
|
||||
;~02 00 3E 00 01 00 00 00 EA 00 40 00 00 00 00 00 02 00 3E 00 01 00 00 00 7C 00 00 00 00 00 00 00
|
||||
|
Reference in New Issue
Block a user