Major aka minor bug fixes and refactoring...
This commit is contained in:
@ -31,6 +31,8 @@ static void replace(unsigned char * destination,
|
||||
while (--size) {
|
||||
destination [size] = source [size];
|
||||
}
|
||||
|
||||
destination [size] = source [size];
|
||||
}
|
||||
|
||||
static void input(int when, unsigned int data) {
|
||||
@ -66,10 +68,10 @@ static void asmdirimm(int when, unsigned int size, unsigned int data) {
|
||||
static void input_at(int when, unsigned int size, unsigned int data, unsigned int base) {
|
||||
asmdirrel(when, data);
|
||||
|
||||
input((when), ((base >> 0) & 0xff));
|
||||
input((when) && (size >= D16), ((base >> 8) & 0xff));
|
||||
input((when) && (size >= D32), ((base >> 16) & 0xff));
|
||||
input((when) && (size >= D32), ((base >> 24) & 0xff));
|
||||
input((when), (base >> 0) & 0xff);
|
||||
input((when) && (size >= D16), (base >> 8) & 0xff);
|
||||
input((when) && (size >= D32), (base >> 16) & 0xff);
|
||||
input((when) && (size >= D32), (base >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static int front(unsigned int data) { return ((data >= 4) && (data <= 7)); }
|
||||
@ -177,7 +179,7 @@ static void build_irregular(unsigned int operation,
|
||||
}
|
||||
|
||||
static void build_special_1(unsigned int operation) {
|
||||
const unsigned char data [SPECIAL_1_END - SPECIAL_1_BEGIN + 1] = {
|
||||
const unsigned char data [9] = {
|
||||
0x90, 0xc3, 0xcb, 0xc9, 0xf0, 0xf4, 0x9d, 0x9c,
|
||||
0x9b
|
||||
};
|
||||
@ -186,7 +188,7 @@ static void build_special_1(unsigned int operation) {
|
||||
}
|
||||
|
||||
static void build_special_2(unsigned int operation) {
|
||||
const unsigned char data [2 * (SPECIAL_2_END - SPECIAL_2_BEGIN + 1)] = {
|
||||
const unsigned short data [72] = {
|
||||
0x0f, 0x0f, 0x0f, 0x0f, 0xf3, 0x0f, 0x0f, 0x0f,
|
||||
0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9,
|
||||
0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9, 0xd9,
|
||||
@ -199,8 +201,9 @@ static void build_special_2(unsigned int operation) {
|
||||
0xfc, 0xfd, 0xfe, 0xff
|
||||
};
|
||||
|
||||
input(1, data[operation - 1 * SPECIAL_2_BEGIN]);
|
||||
input(1, data[operation - 2 * SPECIAL_2_BEGIN + SPECIAL_1_END + 1]);
|
||||
//~input_by(1, D16, data[operation - SPECIAL_2_BEGIN]);
|
||||
input(1, data[operation - SPECIAL_2_BEGIN]);
|
||||
input(1, data[operation - SPECIAL_2_BEGIN + 36]);
|
||||
}
|
||||
|
||||
static void build_jump_if(unsigned int operation,
|
||||
@ -241,6 +244,9 @@ static void build_jump(unsigned int size,
|
||||
input(to == REG, 0xe0 + 0x01 * (destination & 0x07));
|
||||
input(to == MEM, 0xff);
|
||||
input(to == MEM, 0x25);
|
||||
|
||||
input_at(to == REL, size, destination, 0x1000);
|
||||
input_at(to == MEM, D32, destination, 0x1000);
|
||||
}
|
||||
|
||||
static void build_move(unsigned int size,
|
||||
@ -375,10 +381,10 @@ void assemble(unsigned int count,
|
||||
return;
|
||||
}
|
||||
|
||||
text_sector_byte = calloc(1440UL, sizeof(* text_sector_byte));
|
||||
empty_array = calloc(144UL, sizeof(* empty_array));
|
||||
empty_imbue = calloc(144UL, sizeof(* empty_imbue));
|
||||
empty_store = calloc(144UL, sizeof(* empty_store));
|
||||
text_sector_byte = calloc(4096UL, sizeof(* text_sector_byte));
|
||||
empty_array = calloc(1024UL, sizeof(* empty_array));
|
||||
empty_imbue = calloc(1024UL, sizeof(* empty_imbue));
|
||||
empty_store = calloc(1024UL, sizeof(* empty_store));
|
||||
|
||||
if (!assemble_clean_up_queued) {
|
||||
atexit(assemble_clean_up);
|
||||
@ -443,9 +449,15 @@ void assemble(unsigned int count,
|
||||
build_move(array[index + 1], array[index + 2],
|
||||
array[index + 3], array[index + 4],
|
||||
array[index + 5]);
|
||||
printf ("MOV %i %i %i %i %i\n",
|
||||
array[index + 1], array[index + 2],
|
||||
array[index + 3], array[index + 4],
|
||||
array[index + 5]);
|
||||
index += 5;
|
||||
} else if (array[index] == CALL) {
|
||||
build_call(array[index + 1], array[index + 2]);
|
||||
printf ("CALL %i %i\n",
|
||||
array[index + 1], array[index + 2]);
|
||||
index += 2;
|
||||
} else if (array[index] == ENTER) {
|
||||
build_enter(array[index + 1], array[index + 2]);
|
||||
@ -473,6 +485,8 @@ void assemble(unsigned int count,
|
||||
|
||||
index = 0;
|
||||
|
||||
printf ("holes: %u\n", empty_holes);
|
||||
|
||||
while (index < empty_holes) {
|
||||
unsigned int set = 0;
|
||||
unsigned int get = empty_array[index];
|
||||
@ -481,8 +495,12 @@ void assemble(unsigned int count,
|
||||
& text_sector_byte[get],
|
||||
sizeof (set));
|
||||
|
||||
printf (">> %08x ", set);
|
||||
|
||||
set += empty_store[empty_imbue[index]];
|
||||
|
||||
printf (">> %08x\n", set);
|
||||
|
||||
replace(& text_sector_byte[get],
|
||||
(unsigned char *) & set,
|
||||
sizeof (set));
|
||||
|
@ -240,7 +240,7 @@ dereference: '[' IDENTIFIER ']' { $$ = 0; /* XXX: how the fuck do i dereference?
|
||||
|
||||
relative: IDENTIFIER {
|
||||
symbol_t * relative = get_symbol($1);
|
||||
breakpoint();
|
||||
/*breakpoint();*/
|
||||
$$ = relative->_id;
|
||||
}
|
||||
;
|
||||
@ -255,7 +255,7 @@ value: artimetric_block
|
||||
;
|
||||
|
||||
anon_variable: ARRAY_LITERAL {
|
||||
$$.array_value = $1.data;
|
||||
$$.array_value = $1.data;
|
||||
$$.elements = $1.len;
|
||||
int ignore = asprintf(&$$.name, "_anon_%llu", anon_variable_counter++);
|
||||
(void)ignore;
|
||||
@ -463,7 +463,7 @@ instruction: INOP { append_instructions(NOP); }
|
||||
| ITPAUSE { append_instructions(PAUSE); }
|
||||
| ITHLT { append_instructions(HLT); }
|
||||
| ITLOCK { append_instructions(LOCK); }
|
||||
| ITJMP relative { append_instructions( JMP, D32, REL, 0 ); }
|
||||
| ITJMP relative { append_instructions( JMP, D32, REL, $2 ); }
|
||||
| ITINC register { append_instructions( INC, $2.size, REG, $2.number ); }
|
||||
| ITDEC register { append_instructions( DEC, $2.size, REG, $2.number ); }
|
||||
| ITNOT register { append_instructions( NOT, $2.size, REG, $2.number ); }
|
||||
|
@ -2,17 +2,52 @@ format ELF64 executable 3
|
||||
|
||||
segment readable executable
|
||||
|
||||
entry $
|
||||
entry main
|
||||
|
||||
heyo:
|
||||
nop
|
||||
mov eax, 1
|
||||
nop
|
||||
mov edi, 1
|
||||
mov esi, heyo
|
||||
nop
|
||||
mov esi, heyo_data
|
||||
nop
|
||||
mov edx, 12
|
||||
nop
|
||||
syscall
|
||||
ret
|
||||
|
||||
cyaa:
|
||||
nop
|
||||
mov eax, 1
|
||||
nop
|
||||
mov edi, 1
|
||||
nop
|
||||
mov esi, cyaa_data
|
||||
nop
|
||||
mov edx, 12
|
||||
nop
|
||||
syscall
|
||||
ret
|
||||
|
||||
main:
|
||||
nop
|
||||
mov r10d, 11223344h
|
||||
nop
|
||||
call heyo
|
||||
nop
|
||||
call cyaa
|
||||
nop
|
||||
call heyo
|
||||
nop
|
||||
call cyaa
|
||||
nop
|
||||
mov eax, 60
|
||||
mov edi, 60
|
||||
syscall
|
||||
nop
|
||||
|
||||
segment readable writable
|
||||
|
||||
heyo: db "heyo world!", 10
|
||||
heyo_data: db "Heyo world!", 10
|
||||
cyaa_data: db "Cyaa world!", 10
|
||||
|
143
test/heyo.eax
143
test/heyo.eax
@ -1,135 +1,30 @@
|
||||
unix program heyo_world
|
||||
s8 <> heyo = "Heyo world!\n"
|
||||
s8 <> cyaa = "Cyaa world!\n"
|
||||
fast procedure heyo
|
||||
s8 <> heyo_data = "Heyo world!\n"
|
||||
begin
|
||||
nop mov eax 1
|
||||
nop mov edi 1
|
||||
nop mov esi heyo
|
||||
nop mov esi heyo_data
|
||||
nop mov edx 12
|
||||
nop syscall
|
||||
end procedure
|
||||
|
||||
fast procedure cyaa
|
||||
s8 <> cyaa_data = "Cyaa world!\n"
|
||||
begin
|
||||
nop mov eax 1
|
||||
nop mov edi 1
|
||||
nop mov esi cyaa
|
||||
nop mov esi cyaa_data
|
||||
nop mov edx 12
|
||||
nop syscall
|
||||
nop mov eax 60
|
||||
nop mov edi 60
|
||||
nop syscall
|
||||
end procedure
|
||||
|
||||
unix program main
|
||||
begin
|
||||
nop mov rg10d 0x11223344
|
||||
nop fastcall heyo
|
||||
nop fastcall cyaa
|
||||
nop fastcall heyo
|
||||
nop fastcall cyaa
|
||||
nop exit 60
|
||||
nop
|
||||
end program
|
||||
|
||||
/*
|
||||
Variable 't_array' expected:
|
||||
Decimal: | Hexadecimal: | Mnemo:
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
0 00 R0
|
||||
3 03 IMM
|
||||
1 01 1
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
7 07 R7
|
||||
3 03 IMM
|
||||
1 01 1
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
6 06 R6
|
||||
0 00 REL
|
||||
0 00 0 -- heyo
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
2 02 R2
|
||||
3 03 IMM
|
||||
12 0c 12 -- sizeof (heyo)
|
||||
20 14 NOP
|
||||
28 1c SYSCALL
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
0 00 R0
|
||||
3 03 IMM
|
||||
1 01 1
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
7 07 R7
|
||||
3 03 IMM
|
||||
1 01 1
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
6 06 R6
|
||||
0 00 REL
|
||||
1 01 1 -- cyaa
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
2 02 R2
|
||||
3 03 IMM
|
||||
12 0c 12 -- sizeof (cyaa)
|
||||
20 14 NOP
|
||||
28 1c SYSCALL
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
0 00 R0
|
||||
3 03 IMM
|
||||
60 3c 60
|
||||
20 14 NOP
|
||||
53 35 MOV
|
||||
2 02 D32
|
||||
1 01 REG
|
||||
7 07 R7
|
||||
3 03 IMM
|
||||
60 3c 60
|
||||
20 14 NOP
|
||||
28 1c SYSCALL
|
||||
20 14 NOP
|
||||
0 || ASMDIRMEM
|
||||
0 || 0 -- heyo:
|
||||
2 || ASMDIRIMM
|
||||
0 || D8 -- typeof (heyo)
|
||||
12 || 12 -- sizeof (heyo)
|
||||
72 || 'H'
|
||||
101 || 'e'
|
||||
121 || 'y'
|
||||
111 || 'o'
|
||||
32 || ' '
|
||||
119 || 'w'
|
||||
111 || 'o'
|
||||
114 || 'r'
|
||||
108 || 'l'
|
||||
100 || 'd'
|
||||
33 || '!'
|
||||
10 || '\n'
|
||||
0 || ASMDIRMEM
|
||||
1 || 1 -- cyaa:
|
||||
2 || ASMDIRIMM
|
||||
0 || D8 -- typeof (cyaa)
|
||||
12 || 12 -- sizeof (cyaa)
|
||||
67 || 'C'
|
||||
121 || 'y'
|
||||
97 || 'a'
|
||||
97 || 'a'
|
||||
32 || ' '
|
||||
119 || 'w'
|
||||
111 || 'o'
|
||||
114 || 'r'
|
||||
108 || 'l'
|
||||
100 || 'd'
|
||||
33 || '!'
|
||||
10 || '\n'
|
||||
*/
|
||||
|
13
test/xol.sh
Normal file
13
test/xol.sh
Normal file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
fasm heyo.asm heyo_asm
|
||||
./../eaxhla heyo.eax
|
||||
mv a.out heyo_eax
|
||||
xop heyo_eax > heyo_eax_xop.txt
|
||||
xop heyo_asm > heyo_asm_xop.txt
|
||||
diff heyo_eax_xop.txt heyo_asm_xop.txt
|
||||
|
||||
exit
|
||||
|
Reference in New Issue
Block a user