Some very evil testing things...

This commit is contained in:
xolatile 2024-07-08 14:38:45 -04:00
parent 0a3095a5d8
commit 8b0ed7579d
5 changed files with 77 additions and 8 deletions

View File

@ -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)));

17
tool/metalatten.sh Normal file
View File

@ -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

39
tool/nop.c Normal file
View File

@ -0,0 +1,39 @@
#include <xolatile/xtandard.c>
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);
}

View File

@ -5,7 +5,7 @@
#include "../source/assembler.c"
static unsigned int array [] = {
#include "xlatten.txt"
#include "include.txt"
};
int main (void) {

7
tool/test.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -xe
diff flatten.txt xlatten.txt
exit