From 8b0ed7579d33a79b58dcfa87691c4a65dcd16758 Mon Sep 17 00:00:00 2001 From: xolatile Date: Mon, 8 Jul 2024 14:38:45 -0400 Subject: [PATCH] Some very evil testing things... --- source/assembler.c | 20 +++++++++++++------- tool/metalatten.sh | 17 +++++++++++++++++ tool/nop.c | 39 +++++++++++++++++++++++++++++++++++++++ tool/test.c | 2 +- tool/test.sh | 7 +++++++ 5 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 tool/metalatten.sh create mode 100644 tool/nop.c create mode 100644 tool/test.sh diff --git a/source/assembler.c b/source/assembler.c index 919aa4d..2c7e13c 100644 --- a/source/assembler.c +++ b/source/assembler.c @@ -64,6 +64,7 @@ static void print (form when, place ((when != 0) && (size >= D32), (byte) ((data >> 24) & 0XFF)); } +static form front (form data) { return ((data >= 4) && (data <= 7)); } static form valid (form data) { return ((data >= 0) && (data <= 15)); } static form lower (form data) { return ((data >= 0) && (data <= 7)); } static form upper (form data) { return ((data >= 8) && (data <= 15)); } @@ -79,10 +80,11 @@ static void build_short_prefix (form when) { // 40-4D!0X02 static void build_long_prefix (form use_big_registers, form use_new_destination, - form use_new_source) { + form use_new_source, + form use_front_register) { /* */ - place (use_big_registers || use_new_destination || use_new_source, - (byte) (0X40 + place (use_big_registers || use_new_destination || use_new_source || use_front_register, + (byte) (0X40 * use_front_register + 0X01 * use_new_destination + 0X04 * use_new_source + 0X08 * use_big_registers)); @@ -126,7 +128,8 @@ static void build_regular (operation_index operation, build_long_prefix (size == D64, (to == REG) && (upper ((form) destination)), - (from == REG) && (upper ((form) source))); + (from == REG) && (upper ((form) source)), + (size == D8) && (to == REG) && (from == REG) && (front (destination) || front (source))); build_constant (from == IMM, size); @@ -161,7 +164,8 @@ static void build_irregular (operation_index operation, build_short_prefix (size == D16); build_long_prefix (size == D64, - (to == REG) && (upper ((form) destination)), 0); + (to == REG) && (upper ((form) destination)), 0, + (to == REG) && front (destination)); place (1, (byte) (0XF6 + 0X08 * ((operation == INC) || (operation == DEC)) @@ -221,7 +225,8 @@ static void build_move_if (operation_index operation, build_long_prefix (size == D64, (to == REG) && (upper ((form) destination)), - (from == REG) && (upper ((form) source))); + (from == REG) && (upper ((form) source)), + (to == REG) && (from == REG) && (front (destination) || front (source))); place (1, 0X0F); place (1, (byte) (0X40 + operation - MOVE_IF_BEGIN)); @@ -261,7 +266,8 @@ static void build_move (size_index size, build_long_prefix (size == D64, (to == REG) && (upper ((form) destination)), - (from == REG) && (upper ((form) source))); + (from == REG) && (upper ((form) source)), + (to == REG) && (from == REG) && (front (destination) || front (source))); place ((to == REG) && (from == REG), (byte) (0X88 + (size != D8))); place ((to == REG) && (from == MEM), (byte) (0X8A + (size != D8))); diff --git a/tool/metalatten.sh b/tool/metalatten.sh new file mode 100644 index 0000000..3b3f4b6 --- /dev/null +++ b/tool/metalatten.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -xe + +gcc -o flatten flatten.c +gcc -o xlatten xlatten.c + +./flatten > flatten.asm +./xlatten > include.txt + +fasm flatten.asm flatten.exe +./nop flatten.exe > flatten.txt + +gcc -o test test.c +./test > xlatten.txt + +exit diff --git a/tool/nop.c b/tool/nop.c new file mode 100644 index 0000000..7c30d27 --- /dev/null +++ b/tool/nop.c @@ -0,0 +1,39 @@ +#include + +int main (int argc, char * * argv) { + int file = -1; + int size = 0; + int offset = 0; + + unsigned char * buffer = NULL; + + file = file_open (argv [1], O_RDONLY); + size = file_size (argv [1]); + + buffer = allocate (size); + + file_read (file, buffer, size); + + file = file_close (file); + + offset = 64 + 2 * 56 + 3; + + do { + int byte = (int) buffer [offset]; + + if (byte == 0X90) { + echo ("\n"); + echo_byte ((int) buffer [offset]); + } else { + echo_byte (buffer [offset]); + } + + ++offset; + } while (offset != size); + + echo ("\n"); + + buffer = deallocate (buffer); + + return (EXIT_SUCCESS); +} diff --git a/tool/test.c b/tool/test.c index a6a48b0..450fa1d 100644 --- a/tool/test.c +++ b/tool/test.c @@ -5,7 +5,7 @@ #include "../source/assembler.c" static unsigned int array [] = { - #include "xlatten.txt" + #include "include.txt" }; int main (void) { diff --git a/tool/test.sh b/tool/test.sh new file mode 100644 index 0000000..e843529 --- /dev/null +++ b/tool/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -xe + +diff flatten.txt xlatten.txt + +exit