diff --git a/source/assembler.c b/source/assembler.c index 8759390..38ff39c 100644 --- a/source/assembler.c +++ b/source/assembler.c @@ -24,7 +24,7 @@ #define MOVE_IF_COUNT (MOVE_IF_END - MOVE_IF_BEGIN + 1) // Regulates displacement, immediate, label, variable, constant, string data. -#define TESTING_FOR_NOW (144) +#define TESTING_FOR_NOW (4) static next empty_count = 0; static next empty_holes = 0; static next empty_array [TESTING_FOR_NOW] = { 0 }; @@ -51,42 +51,44 @@ static void print (form when, /* 64-BIT SUPPORT */ } -static void asmdirrel (next data) { +static void asmdirrel (form when, + next data) { empty_array [empty_holes] = text_sector_size; empty_imbue [empty_holes] = data; - empty_holes += 1; + empty_holes += (next) when; } -static void asmdirmem (void) { +static void asmdirmem (form when) { empty_store [empty_count] = text_sector_size; - empty_count += 1; + empty_count += (next) when; } static void delay (form when, size_index size, next data) { /* */ - place ((when != 0) && (size >= D8), (byte) 0x00); - place ((when != 0) && (size >= D16), (byte) 0x40); - place ((when != 0) && (size >= D32), (byte) 0x10); + asmdirrel (when, data); + + place ((when != 0) && (size >= D8), (byte) 0xb0); + place ((when != 0) && (size >= D16), (byte) 0x10); + place ((when != 0) && (size >= D32), (byte) 0x40); place ((when != 0) && (size >= D32), (byte) 0x00); /* NO DEREFERENCING */ /* 64-BIT SUPPORT */ - - asmdirrel (data); } -static void asmdirimm (size_index size, - next redo, +static void asmdirimm (form when, + size_index size, + //~next redo, next data) { /* */ - next i; + //~next i; - for (i = 0; i < redo; ++i) { - print (1, size, data); - } + //~for (i = 0; i < redo; ++i) { + print (when, size, data); + //~} } static form front (form data) { return ((data >= 4) && (data <= 7)); } @@ -311,7 +313,7 @@ static void build_move (size_index size, build_register_redirection ((to == REG) && (from == MEM), destination); build_register_redirection ((to == MEM) && (from == REG), source); - place ((to == REG) && (from == IMM), (byte) (0xb8 + place ((to == REG) && ((from == IMM) || (from == REL)), (byte) (0xb8 //~+ 0x08 * (size != D8) + 0x01 * (destination & 0x07))); @@ -319,11 +321,11 @@ static void build_move (size_index size, place ((to == MEM) && (from == IMM), (byte) (0x05)); delay ((to == REG) && (from == MEM), D32, source); - delay ((to == REG) && (from == REL), D32, source); print ((to == REG) && (from == IMM), size, source); delay ((to == MEM) && (from == REG), D32, (next) ~0); delay ((to == MEM) && (from == IMM), D32, (next) ~0); print ((to == MEM) && (from == IMM), size, source); + delay ((to == REG) && (from == REL), D32, source); } next text_sector_size = 0; @@ -343,15 +345,17 @@ void assemble (next count, for (index = 0; index < count; ++index) { if (array [index] == ASMDIRREL) { - asmdirrel (array [index + 1]); + asmdirrel (1, array [index + 1]); index += 1; + printf ("array <%u> %08x\n", empty_holes - 1, empty_array [empty_holes - 1]); + printf ("imbue <%u> %08x\n", empty_holes - 1, empty_imbue [empty_holes - 1]); } else if (array [index] == ASMDIRMEM) { - asmdirmem (); - index += 0; - //~} else if (array [index] == ASMDIRIMM) { - //~asmdirimm (array [index + 1], array [index + 2], - //~array [index + 3]); - //~index += 3; + asmdirmem (1); + index += 1; + printf ("store <%u> %08x\n", empty_count - 1, empty_store [empty_count - 1]); + } else if (array [index] == ASMDIRIMM) { + asmdirimm (1, array [index + 1], array [index + 2]); + index += 2; //~} else if (array [index] == ASMDIRREP) { } else if ((array [index] >= REGULAR_BEGIN) && (array [index] <= REGULAR_END)) { @@ -395,16 +399,18 @@ void assemble (next count, array [index + 5]); index += 5; } else { - exit (array [index]); // For debugging only! + //~exit (array [index]); // For debugging only! } } - return; - 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)); + //~text_sector_byte [get + 3] += (byte) ((empty_store [empty_imbue [index]] >> 0) & 0xff); + //~text_sector_byte [get + 2] += (byte) ((empty_store [empty_imbue [index]] >> 8) & 0xff); + //~text_sector_byte [get + 1] += (byte) ((empty_store [empty_imbue [index]] >> 16) & 0xff); + //~text_sector_byte [get + 0] += (byte) ((empty_store [empty_imbue [index]] >> 24) & 0xff); } } diff --git a/tool/heyo.asm b/tool/heyo.asm index afa22c3..e86d1dd 100644 --- a/tool/heyo.asm +++ b/tool/heyo.asm @@ -4,13 +4,21 @@ segment readable executable entry $ + nop mov eax, 1 + nop mov edi, 1 + nop mov esi, heyo + nop mov edx, 12 + nop syscall + nop mov eax, 60 + nop mov edi, 60 + nop syscall segment readable writable diff --git a/tool/tester.c b/tool/tester.c index bbcc31e..c378d6d 100644 --- a/tool/tester.c +++ b/tool/tester.c @@ -9,16 +9,44 @@ static unsigned int array [] = { NOP, MOV, D32, REG, R0, IMM, 1, NOP, MOV, D32, REG, R7, IMM, 1, - //~NOP, MOV, D32, REG, R6, REL, 0, - NOP, MOV, D32, REG, R6, IMM, 0x004010DA, + NOP, MOV, D32, REG, R6, REL, 0, + NOP, MOV, D32, REG, R2, IMM, 12, + NOP, SYSCALL, + NOP, MOV, D32, REG, R0, IMM, 1, + NOP, MOV, D32, REG, R7, IMM, 1, + NOP, MOV, D32, REG, R6, REL, 1, NOP, MOV, D32, REG, R2, IMM, 12, NOP, SYSCALL, NOP, MOV, D32, REG, R0, IMM, 60, NOP, MOV, D32, REG, R7, IMM, 60, - NOP, SYSCALL - //~ASMDIRMEM, 0, - //~ASMDIRIMM, D8, 12, - //~72, 101, 121, 111, 32, 119, 111, 114, 108, 100, 10, 0 + NOP, SYSCALL, + NOP, + ASMDIRMEM, 0, + ASMDIRIMM, D8, 72, + ASMDIRIMM, D8, 101, + ASMDIRIMM, D8, 121, + ASMDIRIMM, D8, 111, + ASMDIRIMM, D8, 32, + ASMDIRIMM, D8, 119, + ASMDIRIMM, D8, 111, + ASMDIRIMM, D8, 114, + ASMDIRIMM, D8, 108, + ASMDIRIMM, D8, 100, + ASMDIRIMM, D8, 33, + ASMDIRIMM, D8, 10, + ASMDIRMEM, 1, + ASMDIRIMM, D8, 67, + ASMDIRIMM, D8, 121, + ASMDIRIMM, D8, 97, + ASMDIRIMM, D8, 97, + ASMDIRIMM, D8, 32, + ASMDIRIMM, D8, 119, + ASMDIRIMM, D8, 111, + ASMDIRIMM, D8, 114, + ASMDIRIMM, D8, 108, + ASMDIRIMM, D8, 100, + ASMDIRIMM, D8, 33, + ASMDIRIMM, D8, 10 }; int main (void) { @@ -29,8 +57,8 @@ int main (void) { file = fopen ("run_me_please", "w+"); elf_main_header (1, 1, 1, 0); - elf_text_sector (34); - elf_data_sector (34, 12); + elf_text_sector (70); + elf_data_sector (70, 24); fwrite (elf_main_header_byte, 1UL, ELF_MAIN_HEADER_SIZE, file); fwrite (elf_text_sector_byte, 1UL, ELF_TEXT_SECTOR_SIZE, file); @@ -42,7 +70,7 @@ int main (void) { fwrite (text_sector_byte, 1UL, (size_t) text_sector_size, file); - fwrite ("Heyo world!\n", 1UL, 12, file); + //~fwrite ("Heyo world!\n", 1UL, 12, file); free (text_sector_byte); @@ -52,24 +80,46 @@ int main (void) { } /* +7F_45_4C_46_02_01_01_03_00_00_00_00_00_00_00_00_ +02_00_3E_00_01_00_00_00_B0_00_40_00_00_00_00_00_ +40_00_00_00_00_00_00_00_00_00_00_00_00_00_00_00_ +00_00_00_00_40_00_38_00_02_00_40_00_00_00_00_00_ +01_00_00_00_05_00_00_00_00_00_00_00_00_00_00_00_ +00_00_40_00_00_00_00_00_00_00_40_00_00_00_00_00_ +D2_00_00_00_00_00_00_00_D2_00_00_00_00_00_00_00_ +00_10_00_00_00_00_00_00_01_00_00_00_06_00_00_00_ +D2_00_00_00_00_00_00_00_D2_10_40_00_00_00_00_00_ +D2_10_40_00_00_00_00_00_0C_00_00_00_00_00_00_00_ +0C_00_00_00_00_00_00_00_00_10_00_00_00_00_00_00_ +90_B8_01_00_00_00_ +90_BF_01_00_00_00_ +90_BE_00_40_10_2A_ +90_BA_0C_00_00_00_ +90_0F_05_ +90_B8_3C_00_00_00_ +90_BF_3C_00_00_00_ +90_0F_05_ + +-------------------------------------------------------------------------------- +GOOD +-------------------------------------------------------------------------------- 7F 45 4C 46 02 01 01 03 00 00 00 00 00 00 00 00 02 00 3E 00 01 00 00 00 B0 00 40 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 38 00 02 00 40 00 00 00 00 00 01 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 00 -D2 00 00 00 00 00 00 00 D2 00 00 00 00 00 00 00 +DA 00 00 00 00 00 00 00 DA 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 01 00 00 00 06 00 00 00 -D2 00 00 00 00 00 00 00 D2 10 40 00 00 00 00 00 -D2 10 40 00 00 00 00 00 0C 00 00 00 00 00 00 00 +DA 00 00 00 00 00 00 00 DA 10 40 00 00 00 00 00 +DA 10 40 00 00 00 00 00 0C 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 -C0 01 00 00 00 -C7 01 00 00 00 -C6 00 10 40 00 -C2 0C 00 00 00 -0F 05 -C0 3C 00 00 00 -C7 3C 00 00 00 -0F 05 -48 65 79 6F 20 77 6F 72 6C 64 21 0A +90 B8 01 00 00 00 +90 BF 01 00 00 00 +90 BE DA 10 40 00 +90 BA 0C 00 00 00 +90 0F 05 +90 B8 3C 00 00 00 +90 BF 3C 00 00 00 +90 0F 05 48 65 79 6F 20 77 6F 72 6C 64 21 0A */