Merge branch 'master' of https://codeberg.org/eaxcc/eaxcc
This commit is contained in:
commit
bdf303028b
2
Makefile
2
Makefile
@ -26,7 +26,7 @@ OUT := eaxhla
|
|||||||
SOURCE.d := source
|
SOURCE.d := source
|
||||||
OBJECT.d := object
|
OBJECT.d := object
|
||||||
|
|
||||||
SOURCE := main.c assembler.c eaxhla.c
|
SOURCE := main.c assembler.c eaxhla.c unix.c
|
||||||
OBJECT := $(addprefix ${OBJECT.d}/,${SOURCE})
|
OBJECT := $(addprefix ${OBJECT.d}/,${SOURCE})
|
||||||
OBJECT := ${OBJECT:.c=.o}
|
OBJECT := ${OBJECT:.c=.o}
|
||||||
|
|
||||||
|
38
documentation/INSTRUCTIONS.md
Normal file
38
documentation/INSTRUCTIONS.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# 2 argument instructions (t6)
|
||||||
|
|
||||||
|
## add, or, adc, sbb, and, sub, xor, cmp;
|
||||||
|
|
||||||
|
- REG REG // This means that arg1 can only be REG or MEM.
|
||||||
|
- REG MEM // And arg2 can only be REG, MEM or IMM, but:
|
||||||
|
- REG IMM // You can't use MEM as both arguments.
|
||||||
|
- MEM REG // This limitation stems from x64 encoding.
|
||||||
|
- MEM IMM // Hardware we use can't encode that.
|
||||||
|
|
||||||
|
- REG or MEM can use D8 ... D64, any size.
|
||||||
|
- IMM in this case must be maximum 32 bit.
|
||||||
|
- Examples:
|
||||||
|
|
||||||
|
```c
|
||||||
|
add rax 0x11223344 // ADD D64 REG R0 IMM 0x11223344
|
||||||
|
or ecx 0x11223344 // OR D32 REG R1 IMM 0x11223344
|
||||||
|
adc dx 0x1122 // ADC D16 REG R2 IMM 0x1122
|
||||||
|
sbb bl 0x11 // SBB D8 REG R3 IMM 0x11
|
||||||
|
```
|
||||||
|
|
||||||
|
# 1 argument instructions (t4)
|
||||||
|
|
||||||
|
## inc, dec, not, neg, mul, imul, div, idiv;
|
||||||
|
|
||||||
|
- REG
|
||||||
|
- MEM
|
||||||
|
|
||||||
|
- REG or MEM can use D8 ... D64, any size.
|
||||||
|
- IMM can't be used with these instructions.
|
||||||
|
- Examples:
|
||||||
|
|
||||||
|
```c
|
||||||
|
inc rsp // INC D64 REG R4
|
||||||
|
dec ebp // DEC D32 REG R5
|
||||||
|
not si // NOT D16 REG R6
|
||||||
|
neg dil // NEG D8 REG R7
|
||||||
|
```
|
@ -2,23 +2,6 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
|
||||||
gcc -c -ansi -Wall -Wextra -Wpedantic -Werror:
|
|
||||||
-- warns about trailing comma in enumerations.
|
|
||||||
-- kept because of chad coding standard.
|
|
||||||
-- unused functions for now, obviously...
|
|
||||||
clang -c -ansi -Weverything -Werror:
|
|
||||||
-- exactly same warnings as with gcc above.
|
|
||||||
splint -fcnuse +boolint +charint assembler.c:
|
|
||||||
-- we obviously ignore unused functions for now.
|
|
||||||
-- we assume bool is int, which is true.
|
|
||||||
-- we assume char is int, which is true.
|
|
||||||
-- assembler.c:167:13: Function fabs shadows outer declaration
|
|
||||||
-- ^ function from <math.h>, which we don't even use.
|
|
||||||
splint assembler.h:
|
|
||||||
-- no warnings at all.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define REGULAR_BEGIN (ADD)
|
#define REGULAR_BEGIN (ADD)
|
||||||
#define REGULAR_END (CMP)
|
#define REGULAR_END (CMP)
|
||||||
#define IRREGULAR_BEGIN (INC)
|
#define IRREGULAR_BEGIN (INC)
|
||||||
@ -40,41 +23,40 @@ splint assembler.h:
|
|||||||
#define MOVE_IF_COUNT (MOVE_IF_END - MOVE_IF_BEGIN + 1)
|
#define MOVE_IF_COUNT (MOVE_IF_END - MOVE_IF_BEGIN + 1)
|
||||||
|
|
||||||
// Regulates displacement, immediate, label, variable, constant, string data.
|
// Regulates displacement, immediate, label, variable, constant, string data.
|
||||||
static next * empty_from;
|
/*static next * empty_from;
|
||||||
static next * empty_to;
|
static next * empty_to;
|
||||||
static next * imbue_with;
|
static next * imbue_with;
|
||||||
static next * imbue_size;
|
static next * imbue_size;*/
|
||||||
|
|
||||||
// Main function.
|
// Main function.
|
||||||
static void place (form when,
|
static void place (form when,
|
||||||
byte data) {
|
byte data) {
|
||||||
/* */
|
/* */
|
||||||
token_array [token_count] = data;
|
text_sector_byte [text_sector_size] = data;
|
||||||
|
|
||||||
token_count += (next) when;
|
text_sector_size += (next) when;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print (form when,
|
static void print (form when,
|
||||||
size_index size,
|
size_index size,
|
||||||
next data) {
|
next data) {
|
||||||
/* */
|
/* */
|
||||||
place ((when != 0) && (size >= D8), (byte) ((data >> 0) & 0XFF));
|
place ((when != 0) && (size >= D8), (byte) ((data >> 0) & 0xff));
|
||||||
place ((when != 0) && (size >= D16), (byte) ((data >> 8) & 0XFF));
|
place ((when != 0) && (size >= D16), (byte) ((data >> 8) & 0xff));
|
||||||
place ((when != 0) && (size >= D32), (byte) ((data >> 16) & 0XFF));
|
place ((when != 0) && (size >= D32), (byte) ((data >> 16) & 0xff));
|
||||||
place ((when != 0) && (size >= D32), (byte) ((data >> 24) & 0XFF));
|
place ((when != 0) && (size >= D32), (byte) ((data >> 24) & 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
static form front (form data) { return ((data >= 4) && (data <= 7)); }
|
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 lower (form data) { return ((data >= 0) && (data <= 7)); }
|
||||||
static form upper (form data) { return ((data >= 8) && (data <= 15)); }
|
static form upper (form data) { return ((data >= 8) && (data <= 15)); }
|
||||||
|
|
||||||
// Important stuff that I need to handle later, it saves bytes!
|
// Important stuff that I need to handle later, it saves bytes!
|
||||||
static form far (next label) { return (1); /* DO NOT CHANGE YET! */ }
|
static form far (next label) { return (label && 1); }
|
||||||
static form near (next label) { return (0); /* DO NOT CHANGE YET! */ }
|
static form near (next label) { return (label && 0); }
|
||||||
|
|
||||||
static void build_short_prefix (form when) {
|
static void build_short_prefix (form when) {
|
||||||
place (when, 0X66);
|
place (when, 0x66);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 40-4D!0X02
|
// 40-4D!0X02
|
||||||
@ -83,10 +65,10 @@ static void build_long_prefix (form use_big_registers,
|
|||||||
form use_new_source) {
|
form use_new_source) {
|
||||||
/* */
|
/* */
|
||||||
place (use_big_registers || use_new_destination || use_new_source,
|
place (use_big_registers || use_new_destination || use_new_source,
|
||||||
(byte) (0X40
|
(byte) (0x40
|
||||||
+ 0X01 * use_new_destination
|
+ 0x01 * use_new_destination
|
||||||
+ 0X04 * use_new_source
|
+ 0x04 * use_new_source
|
||||||
+ 0X08 * use_big_registers));
|
+ 0x08 * use_big_registers));
|
||||||
}
|
}
|
||||||
|
|
||||||
// C0-FF
|
// C0-FF
|
||||||
@ -94,25 +76,25 @@ static void build_register_direction (form when,
|
|||||||
next destination,
|
next destination,
|
||||||
next source) {
|
next source) {
|
||||||
/* */
|
/* */
|
||||||
place (when, (byte) (0XC0
|
place (when, (byte) (0xc0
|
||||||
+ 0X01 * (destination & 0X07)
|
+ 0x01 * (destination & 0x07)
|
||||||
+ 0X08 * (source & 0X07)));
|
+ 0x08 * (source & 0x07)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 05-3D
|
// 05-3D
|
||||||
static void build_register_redirection (form when,
|
static void build_register_redirection (form when,
|
||||||
next direction) {
|
next direction) {
|
||||||
/* */
|
/* */
|
||||||
place (when, (byte) (0X05
|
place (when, (byte) (0x05
|
||||||
+ 0X08 * (direction & 0X07)));
|
+ 0x08 * (direction & 0x07)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 80/81
|
// 80/81
|
||||||
static void build_constant (form when,
|
static void build_constant (form when,
|
||||||
size_index size) {
|
size_index size) {
|
||||||
/* */
|
/* */
|
||||||
place (when, (byte) (0X80
|
place (when, (byte) (0x80
|
||||||
+ 0X01 * (size != D8)));
|
+ 0x01 * (size != D8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// REGULAR_BEGIN-REGULAR_END D8-D64 REG/MEM R0-R15/MEM -||-/IMM -||-/IMM
|
// REGULAR_BEGIN-REGULAR_END D8-D64 REG/MEM R0-R15/MEM -||-/IMM -||-/IMM
|
||||||
@ -130,20 +112,28 @@ static void build_regular (operation_index operation,
|
|||||||
(from == REG) && (upper ((form) source)));
|
(from == REG) && (upper ((form) source)));
|
||||||
|
|
||||||
// 40>front
|
// 40>front
|
||||||
place ((size == D8) && (to == REG) && (from == REG)
|
place ((size == D8) && (to == REG) && ((from == REG) || (from == IMM))
|
||||||
&& ((front (destination) && lower (source))
|
&& (((front (destination) && lower (source))
|
||||||
|| (lower (destination) && front (source))), (byte) 0X40);
|
|| (lower (destination) && front (source))) ||
|
||||||
|
((to == REG) && (from == IMM) && front (destination))),
|
||||||
|
(byte) 0x40);
|
||||||
|
|
||||||
build_constant (from == IMM, size);
|
place ((from == IMM) && (to == REG) && (destination == 0),
|
||||||
|
(byte) (0x05
|
||||||
|
+ 0x08 * (operation & 0x07))
|
||||||
|
- 0x01 * (size == D8));
|
||||||
|
|
||||||
place (1, (byte) (0X08 * (operation - REGULAR_BEGIN)
|
build_constant ((from == IMM) && ! ((to == REG) && (destination == 0)), size);
|
||||||
+ (destination & 0X07) * ((to == REG) && (from == IMM))
|
|
||||||
+ 0X01 * ((to == MEM) && (from == IMM) && (size == D8)) //
|
place (! ((from == IMM) && (to == REG) && (destination == 0)),
|
||||||
- 0X01 * ((to == REG) && (from == IMM)) //
|
(byte) (0x08 * (operation - REGULAR_BEGIN)
|
||||||
+ 0X01 * (size != D8)
|
+ (destination & 0x07) * ((to == REG) && (from == IMM))
|
||||||
+ 0X02 * ((to == REG) && (from == MEM))
|
+ 0x01 * ((to == MEM) && (from == IMM) && (size == D8)) //
|
||||||
+ 0X04 * ((to == MEM) && (from == IMM))
|
- 0x01 * ((to == REG) && (from == IMM) && (size != D8)) //
|
||||||
+ 0XC0 * ((to == REG) && (from == IMM))));
|
+ 0x01 * (size != D8)
|
||||||
|
+ 0x02 * ((to == REG) && (from == MEM))
|
||||||
|
+ 0x04 * ((to == MEM) && (from == IMM))
|
||||||
|
+ 0xc0 * ((to == REG) && (from == IMM))));
|
||||||
|
|
||||||
build_register_direction ((to == REG) && (from == REG),
|
build_register_direction ((to == REG) && (from == REG),
|
||||||
destination, source);
|
destination, source);
|
||||||
@ -169,22 +159,25 @@ static void build_irregular (operation_index operation,
|
|||||||
build_long_prefix (size == D64,
|
build_long_prefix (size == D64,
|
||||||
(to == REG) && (upper ((form) destination)), 0);
|
(to == REG) && (upper ((form) destination)), 0);
|
||||||
|
|
||||||
place (1, (byte) (0XF6
|
// 40>front
|
||||||
+ 0X08 * ((operation == INC) || (operation == DEC))
|
place ((size == D8) && (to == REG) && front (destination), (byte) 0x40);
|
||||||
+ 0X01 * (size != D8)));
|
|
||||||
|
|
||||||
place (to == REG, (byte) (0XC0
|
place (1, (byte) (0xf7
|
||||||
+ 0X08 * (operation - IRREGULAR_BEGIN))
|
+ 0x08 * ((operation == INC) || (operation == DEC))
|
||||||
+ 0X01 * (destination & 0X07));
|
- 0x01 * (size == D8)));
|
||||||
|
|
||||||
place (to == MEM, (byte) (0X05
|
place (to == REG, (byte) (0xc0
|
||||||
+ 0X08 * (operation - IRREGULAR_BEGIN)));
|
+ 0x08 * (operation - IRREGULAR_BEGIN))
|
||||||
|
+ 0x01 * (destination & 0x07));
|
||||||
|
|
||||||
|
place (to == MEM, (byte) (0x05
|
||||||
|
+ 0x08 * (operation - IRREGULAR_BEGIN)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// SPECIAL_1_BEGIN-SPECIAL_1_END
|
// SPECIAL_1_BEGIN-SPECIAL_1_END
|
||||||
static void build_special_1 (operation_index operation) {
|
static void build_special_1 (operation_index operation) {
|
||||||
const byte data [1 * SPECIAL_1_COUNT] = {
|
const byte data [1 * SPECIAL_1_COUNT] = {
|
||||||
0X90, 0XC3, 0XCB, 0XC9, 0XF0, 0XF4
|
0x90, 0xc3, 0xcb, 0xc9, 0xf0, 0xf4
|
||||||
};
|
};
|
||||||
|
|
||||||
place (1, data [operation - SPECIAL_1_BEGIN]);
|
place (1, data [operation - SPECIAL_1_BEGIN]);
|
||||||
@ -193,8 +186,8 @@ static void build_special_1 (operation_index operation) {
|
|||||||
// SPECIAL_2_BEGIN-SPECIAL_2_END
|
// SPECIAL_2_BEGIN-SPECIAL_2_END
|
||||||
static void build_special_2 (operation_index operation) {
|
static void build_special_2 (operation_index operation) {
|
||||||
const byte data [2 * SPECIAL_2_COUNT] = {
|
const byte data [2 * SPECIAL_2_COUNT] = {
|
||||||
0X0F, 0X0F, 0X0F, 0X0F, 0XF3, 0X0F,
|
0x0f, 0x0f, 0x0f, 0x0f, 0xf3, 0x0f,
|
||||||
0X34, 0X35, 0X05, 0X07, 0X90, 0XA2
|
0x34, 0x35, 0x05, 0x07, 0x90, 0xa2
|
||||||
};
|
};
|
||||||
|
|
||||||
place (1, data [operation - SPECIAL_2_BEGIN]);
|
place (1, data [operation - SPECIAL_2_BEGIN]);
|
||||||
@ -208,9 +201,9 @@ static void build_jump_if (operation_index operation,
|
|||||||
/* */
|
/* */
|
||||||
(void) size; /* HIGHLY DEPENDS FOR FAR AND NEAR JUMPS! */
|
(void) size; /* HIGHLY DEPENDS FOR FAR AND NEAR JUMPS! */
|
||||||
|
|
||||||
place (far (location), 0X0F); /* EVERYTHING IS FAR JUMP! */
|
place (far (location), 0x0f); /* EVERYTHING IS FAR JUMP! */
|
||||||
place (far (location), (byte) (0X80 + operation - JUMP_IF_BEGIN));
|
place (far (location), (byte) (0x80 + operation - JUMP_IF_BEGIN));
|
||||||
place (near (location), (byte) (0X70 + operation - JUMP_IF_BEGIN));
|
place (near (location), (byte) (0x70 + operation - JUMP_IF_BEGIN));
|
||||||
|
|
||||||
//~displacement (4, 0X12345678);
|
//~displacement (4, 0X12345678);
|
||||||
}
|
}
|
||||||
@ -229,8 +222,8 @@ static void build_move_if (operation_index operation,
|
|||||||
(to == REG) && (upper ((form) destination)),
|
(to == REG) && (upper ((form) destination)),
|
||||||
(from == REG) && (upper ((form) source)));
|
(from == REG) && (upper ((form) source)));
|
||||||
|
|
||||||
place (1, 0X0F);
|
place (1, 0x0f);
|
||||||
place (1, (byte) (0X40 + operation - MOVE_IF_BEGIN));
|
place (1, (byte) (0x40 + operation - MOVE_IF_BEGIN));
|
||||||
|
|
||||||
build_register_direction ((to == REG) && (from == REG),
|
build_register_direction ((to == REG) && (from == REG),
|
||||||
destination, source);
|
destination, source);
|
||||||
@ -247,13 +240,13 @@ static void build_jump (size_index size,
|
|||||||
/* */
|
/* */
|
||||||
place ((to == REG) && upper ((form) destination), (byte) 0X41);
|
place ((to == REG) && upper ((form) destination), (byte) 0X41);
|
||||||
|
|
||||||
place (to == REL, (byte) (0XE9 + 0X02 * (size == D8)));
|
place (to == REL, (byte) (0xe9 + 0x02 * (size == D8)));
|
||||||
place (to == REG, (byte) 0XFF);
|
place (to == REG, (byte) 0xff);
|
||||||
place (to == REG, (byte) (0XE0 + 0X01 * (destination & 0X07)));
|
place (to == REG, (byte) (0xe0 + 0x01 * (destination & 0x07)));
|
||||||
place (to == MEM, (byte) 0XFF);
|
place (to == MEM, (byte) 0xff);
|
||||||
place (to == MEM, (byte) 0X25);
|
place (to == MEM, (byte) 0x25);
|
||||||
|
|
||||||
//~displacement (to == MEM, 4, 0X12345678); // Keep when in mind!
|
//~displacement (to == MEM, 4, 0x12345678); // Keep when in mind!
|
||||||
}
|
}
|
||||||
|
|
||||||
// VERY FUCKING SPECIAL!
|
// VERY FUCKING SPECIAL!
|
||||||
@ -269,29 +262,29 @@ static void build_move (size_index size,
|
|||||||
(to == REG) && (upper ((form) destination)),
|
(to == REG) && (upper ((form) destination)),
|
||||||
(from == REG) && (upper ((form) source)));
|
(from == REG) && (upper ((form) source)));
|
||||||
|
|
||||||
place ((to == REG) && (from == REG), (byte) (0X88 + (size != D8)));
|
place ((to == REG) && (from == REG), (byte) (0x88 + (size != D8)));
|
||||||
place ((to == REG) && (from == MEM), (byte) (0X8A + (size != D8)));
|
place ((to == REG) && (from == MEM), (byte) (0x8a + (size != D8)));
|
||||||
place ((to == MEM) && (from == REG), (byte) (0X88 + (size != D8)));
|
place ((to == MEM) && (from == REG), (byte) (0x88 + (size != D8)));
|
||||||
|
|
||||||
build_register_redirection ((to == REG) && (from == MEM), destination);
|
build_register_redirection ((to == REG) && (from == MEM), destination);
|
||||||
build_register_redirection ((to == MEM) && (from == REG), source);
|
build_register_redirection ((to == MEM) && (from == REG), source);
|
||||||
|
|
||||||
place ((to == REG) && (from == IMM), (byte) (0XB0
|
place ((to == REG) && (from == IMM), (byte) (0xb8
|
||||||
+ 0X08 * (size != D8)
|
+ 0x08 * (size != D8)
|
||||||
+ 0X01 * (destination & 0X07)));
|
+ 0x01 * (destination & 0x07)));
|
||||||
|
|
||||||
place ((to == MEM) && (from == IMM), (byte) (0XC6 + (size != D8)));
|
place ((to == MEM) && (from == IMM), (byte) (0xc6 + (size != D8)));
|
||||||
place ((to == MEM) && (from == IMM), (byte) (0X05));
|
place ((to == MEM) && (from == IMM), (byte) (0x05));
|
||||||
|
|
||||||
print ((to == REG) && (from == MEM), D32, (next) ~0);
|
print ((to == REG) && (from == MEM), D32, (next) ~0);
|
||||||
print ((to == REG) && (from == IMM), size, source);
|
print ((to == REG) && (from == IMM), D32, source);
|
||||||
print ((to == MEM) && (from == REG), D32, (next) ~0);
|
print ((to == MEM) && (from == REG), D32, (next) ~0);
|
||||||
print ((to == MEM) && (from == IMM), D32, (next) ~0);
|
print ((to == MEM) && (from == IMM), D32, (next) ~0);
|
||||||
print ((to == MEM) && (from == IMM), size, source);
|
print ((to == MEM) && (from == IMM), size, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
next token_count = 0;
|
next text_sector_size = 0;
|
||||||
byte * token_array = NULL;
|
byte * text_sector_byte = NULL;
|
||||||
|
|
||||||
int was_instruction_array_empty = 0;
|
int was_instruction_array_empty = 0;
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ typedef enum {
|
|||||||
} type_index;
|
} type_index;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
XDCL, XLBL, XRPT, XLCT,
|
||||||
|
/* HIGHLY EXPERIMENTAL CODE ABOVE... */
|
||||||
ADD, OR, ADC, SBB,
|
ADD, OR, ADC, SBB,
|
||||||
AND, SUB, XOR, CMP,
|
AND, SUB, XOR, CMP,
|
||||||
/* */
|
/* */
|
||||||
@ -62,8 +64,8 @@ typedef enum {
|
|||||||
R12, R13, R14, R15,
|
R12, R13, R14, R15,
|
||||||
} operand_index;
|
} operand_index;
|
||||||
|
|
||||||
extern next token_count;
|
extern next text_sector_size;
|
||||||
extern byte * token_array;
|
extern byte * text_sector_byte;
|
||||||
|
|
||||||
extern int was_instruction_array_empty;
|
extern int was_instruction_array_empty;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ static void dump (const char * file_name);
|
|||||||
#include "eaxhla.yy.h"
|
#include "eaxhla.yy.h"
|
||||||
#include "eaxhla.tab.h"
|
#include "eaxhla.tab.h"
|
||||||
#include "assembler.h"
|
#include "assembler.h"
|
||||||
|
#include "unix.h"
|
||||||
|
|
||||||
extern void yyfree_leftovers(void);
|
extern void yyfree_leftovers(void);
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ signed main(int argc, char * argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
token_array = calloc (1440UL, sizeof (* token_array));
|
text_sector_byte = calloc (1440UL, sizeof (* text_sector_byte));
|
||||||
t_array = calloc (1440UL, sizeof (* t_array));
|
t_array = calloc (1440UL, sizeof (* t_array));
|
||||||
|
|
||||||
#if DEBUG == 1
|
#if DEBUG == 1
|
||||||
@ -52,43 +53,29 @@ signed main(int argc, char * argv[]) {
|
|||||||
|
|
||||||
eaxhla_destroy();
|
eaxhla_destroy();
|
||||||
|
|
||||||
free (token_array);
|
free (text_sector_byte);
|
||||||
free (t_array);
|
free (t_array);
|
||||||
|
|
||||||
return has_encountered_error;
|
return has_encountered_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump (const char * file_name) {
|
void dump (const char * file_name) {
|
||||||
/* DO NOT TRY THIS AT HOME! */
|
elf_main_header (1, 1, 1, 0);
|
||||||
#define hackery \
|
elf_text_sector (34);
|
||||||
"\x7F\x45\x4C\x46\x02\x01\x01\x03"\
|
elf_data_sector (34, 12);
|
||||||
"\x00\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x02\x00\x3E\x00\x01\x00\x00\x00"\
|
|
||||||
"\xB0\x00\x40\x00\x00\x00\x00\x00"\
|
|
||||||
"\x40\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x00\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x00\x00\x00\x00\x40\x00\x38\x00"\
|
|
||||||
"\x02\x00\x40\x00\x00\x00\x00\x00"\
|
|
||||||
"\x01\x00\x00\x00\x05\x00\x00\x00"\
|
|
||||||
"\x00\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x00\x00\x40\x00\x00\x00\x00\x00"\
|
|
||||||
"\x00\x00\x40\x00\x00\x00\x00\x00"\
|
|
||||||
"\xC5\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\xC5\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x00\x10\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x01\x00\x00\x00\x06\x00\x00\x00"\
|
|
||||||
"\xC5\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\xC5\x10\x40\x00\x00\x00\x00\x00"\
|
|
||||||
"\xC5\x10\x40\x00\x00\x00\x00\x00"\
|
|
||||||
"\x0C\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x0C\x00\x00\x00\x00\x00\x00\x00"\
|
|
||||||
"\x00\x10\x00\x00\x00\x00\x00\x00"
|
|
||||||
|
|
||||||
char meme [1024] = "";
|
char meme [1024] = "";
|
||||||
FILE * file = fopen (file_name, "w");
|
FILE * file = fopen (file_name, "w");
|
||||||
|
|
||||||
fwrite (hackery, 1UL, 64UL + 2UL * 56UL, file);
|
fwrite (elf_main_header_byte, 1UL, ELF_MAIN_HEADER_SIZE, file);
|
||||||
fwrite (token_array, sizeof (* token_array), (size_t) token_count, file);
|
fwrite (elf_text_sector_byte, 1UL, ELF_TEXT_SECTOR_SIZE, file);
|
||||||
|
fwrite (elf_data_sector_byte, 1UL, ELF_DATA_SECTOR_SIZE, file);
|
||||||
|
|
||||||
|
//text
|
||||||
|
fwrite (text_sector_byte, sizeof (* text_sector_byte),
|
||||||
|
(size_t) text_sector_size, file);
|
||||||
|
|
||||||
|
// data
|
||||||
fwrite ("heyo world!\n", 1UL, 12UL, file);
|
fwrite ("heyo world!\n", 1UL, 12UL, file);
|
||||||
|
|
||||||
snprintf (meme, 1023UL, "chmod +x %s", file_name);
|
snprintf (meme, 1023UL, "chmod +x %s", file_name);
|
||||||
|
70
source/unix.c
Normal file
70
source/unix.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "unix.h"
|
||||||
|
|
||||||
|
uint8_t elf_main_header_byte [ELF_MAIN_HEADER_SIZE] = {
|
||||||
|
0X7F, 0X45, 0X4C, 0X46, 0X02, 0X01, 0X01, 0X03,
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
0X02, 0X00, 0X3E, 0X00, 0X01, 0X00, 0X00, 0X00,
|
||||||
|
0XB0, 0X00, 0X40, 0X00, 0X00, 0X00, 0X00, 0X00, // entry_point
|
||||||
|
0X40, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X40, 0X00, 0X38, 0X00,
|
||||||
|
0X02, 0X00, 0X40, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t elf_text_sector_byte [ELF_TEXT_SECTOR_SIZE] = {
|
||||||
|
0X01, 0X00, 0X00, 0X00, 0X05, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X40, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X40, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // HDR + TXT
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // HDR + TXT
|
||||||
|
0X00, 0X10, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t elf_data_sector_byte [ELF_DATA_SECTOR_SIZE] = {
|
||||||
|
0X01, 0X00, 0X00, 0X00, 0X06, 0X00, 0X00, 0X00,
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // HDR + TXT
|
||||||
|
0X00, 0X10, 0X40, 0X00, 0X00, 0X00, 0X00, 0X00, // +++ ^
|
||||||
|
0X00, 0X10, 0X40, 0X00, 0X00, 0X00, 0X00, 0X00, // +++ ^
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // DAT
|
||||||
|
0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // DAT
|
||||||
|
0X00, 0X10, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00,
|
||||||
|
};
|
||||||
|
|
||||||
|
void elf_main_header (uint8_t has_program,
|
||||||
|
uint8_t for_linux,
|
||||||
|
uint8_t for_x86_64,
|
||||||
|
uint64_t entry_point) {
|
||||||
|
/* */
|
||||||
|
uint64_t enter = entry_point; // TEST
|
||||||
|
|
||||||
|
elf_main_header_byte [16] = (has_program) ? 0x02 : 0x03; // library
|
||||||
|
elf_main_header_byte [ 7] = (for_linux) ? 0x03 : 0x00; // system v
|
||||||
|
elf_main_header_byte [18] = (for_x86_64) ? 0x3e : 0x00;
|
||||||
|
|
||||||
|
if (entry_point != 0) {
|
||||||
|
memcpy (& elf_main_header_byte [24], & enter, sizeof (enter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void elf_text_sector (uint64_t text_size) {
|
||||||
|
/* */
|
||||||
|
uint64_t text = ELF_HEADER_SIZE + text_size; // TEST
|
||||||
|
|
||||||
|
memcpy (& elf_text_sector_byte [32], & text, sizeof (text));
|
||||||
|
memcpy (& elf_text_sector_byte [40], & text, sizeof (text));
|
||||||
|
}
|
||||||
|
|
||||||
|
void elf_data_sector (uint64_t text_size,
|
||||||
|
uint64_t data_size) {
|
||||||
|
/* */
|
||||||
|
uint64_t data = data_size; // TEST
|
||||||
|
uint64_t core = ELF_HEADER_SIZE + text_size;
|
||||||
|
uint64_t move = 0x401000 + core;
|
||||||
|
|
||||||
|
memcpy (& elf_data_sector_byte [ 8], & core, sizeof (core));
|
||||||
|
memcpy (& elf_data_sector_byte [16], & move, sizeof (move));
|
||||||
|
memcpy (& elf_data_sector_byte [24], & move, sizeof (move));
|
||||||
|
memcpy (& elf_data_sector_byte [32], & data, sizeof (data));
|
||||||
|
memcpy (& elf_data_sector_byte [40], & data, sizeof (data));
|
||||||
|
}
|
29
source/unix.h
Normal file
29
source/unix.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef UNIX_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define ELF_MAIN_HEADER_SIZE (0x40)
|
||||||
|
#define ELF_TEXT_SECTOR_SIZE (0x38)
|
||||||
|
#define ELF_DATA_SECTOR_SIZE (0x38)
|
||||||
|
|
||||||
|
#define ELF_HEADER_SIZE (ELF_MAIN_HEADER_SIZE \
|
||||||
|
+ ELF_TEXT_SECTOR_SIZE \
|
||||||
|
+ ELF_DATA_SECTOR_SIZE)
|
||||||
|
|
||||||
|
extern uint8_t elf_main_header_byte [ELF_MAIN_HEADER_SIZE];
|
||||||
|
extern uint8_t elf_text_sector_byte [ELF_TEXT_SECTOR_SIZE];
|
||||||
|
extern uint8_t elf_data_sector_byte [ELF_DATA_SECTOR_SIZE];
|
||||||
|
|
||||||
|
extern void elf_main_header (uint8_t has_program,
|
||||||
|
uint8_t for_linux,
|
||||||
|
uint8_t for_x86_64,
|
||||||
|
uint64_t entry_point);
|
||||||
|
|
||||||
|
extern void elf_text_sector (uint64_t text_size);
|
||||||
|
|
||||||
|
extern void elf_data_sector (uint64_t text_size,
|
||||||
|
uint64_t data_size);
|
||||||
|
|
||||||
|
#define UNIX_H
|
||||||
|
#endif
|
19
test/heyo.asm
Normal file
19
test/heyo.asm
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
format ELF64 executable 3
|
||||||
|
|
||||||
|
segment readable executable
|
||||||
|
|
||||||
|
entry $
|
||||||
|
|
||||||
|
mov eax, 1
|
||||||
|
mov edi, 1
|
||||||
|
mov esi, heyo
|
||||||
|
mov edx, 12
|
||||||
|
syscall
|
||||||
|
|
||||||
|
mov eax, 60
|
||||||
|
mov edi, 0
|
||||||
|
syscall
|
||||||
|
|
||||||
|
segment readable writable
|
||||||
|
|
||||||
|
heyo: db "heyo world!", 10
|
47
test/heyo.eax
Normal file
47
test/heyo.eax
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
program heyo_world
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
mov eax 1
|
||||||
|
mov edi 1
|
||||||
|
mov esi 4198610
|
||||||
|
mov edx 12
|
||||||
|
syscall
|
||||||
|
|
||||||
|
mov eax 60
|
||||||
|
mov edi 0
|
||||||
|
syscall
|
||||||
|
|
||||||
|
end program
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
22 00 00 00 00 00 00 00
|
||||||
|
22 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
|
||||||
|
|
||||||
|
B0 01 00 00 00 B7 01 00 00 00 B6 D2 10 40 00 B2 0C 00 00 00
|
||||||
|
0F 05 B0 3C 00 00 00 B7 00 00 00 00 0F 05
|
||||||
|
|
||||||
|
68 65 79 6F 20 77 6F 72 6C 64 21 0A
|
||||||
|
*/
|
@ -1,15 +1,13 @@
|
|||||||
program heyo_world
|
program heyo_world
|
||||||
|
s8 <12> message "Heyo world!\n" // AVAR D8 12 ...
|
||||||
|
begin // DECL 0XFFFFFFFFU
|
||||||
|
|
||||||
begin
|
mov eax 1 // MOV D32 REG R0 IMM 1
|
||||||
|
mov edi 1 // MOV D32 REG R7 IMM 1
|
||||||
|
mov esi message // MOV D32 REG R6 MEM 0 [message]
|
||||||
|
mov edx 12 // MOV D32 REG R2 IMM 12
|
||||||
|
syscall // SYSCALL
|
||||||
|
|
||||||
mov eax 1
|
end program // MOV D64 REG R0 IMM 0X3CU
|
||||||
mov edi 1
|
// MOV D64 REG R7 IMM 0X0U
|
||||||
mov esi 4198610
|
// SYSCALL
|
||||||
mov edx 12
|
|
||||||
syscall
|
|
||||||
|
|
||||||
mov eax 60
|
|
||||||
mov edi 0
|
|
||||||
syscall
|
|
||||||
|
|
||||||
end program
|
|
||||||
|
@ -4,15 +4,19 @@ static char * fa [] = {
|
|||||||
"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"
|
"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char * faa [] = {
|
||||||
|
"inc", "dec", "not", "neg", "mul", "imul", "div", "idiv"
|
||||||
|
};
|
||||||
|
|
||||||
static char * fr [] = {
|
static char * fr [] = {
|
||||||
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
|
"al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
|
||||||
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
"r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b",
|
||||||
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
|
|
||||||
"r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d",
|
|
||||||
"ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
|
"ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
|
||||||
"r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w",
|
"r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w",
|
||||||
"al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
|
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
|
||||||
"r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
|
"r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d",
|
||||||
|
"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
|
||||||
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char * fm [] = {
|
static char * fm [] = {
|
||||||
@ -20,7 +24,7 @@ static char * fm [] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static char * fi [] = {
|
static char * fi [] = {
|
||||||
"11h", "1122h", "11223344h", "1122334455667788h",
|
"11h", "1122h", "11223344h", "11223344h"
|
||||||
};
|
};
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
@ -33,6 +37,7 @@ int main (void) {
|
|||||||
printf ("nop\n");
|
printf ("nop\n");
|
||||||
printf ("nop\n");
|
printf ("nop\n");
|
||||||
|
|
||||||
|
// INR REG REG
|
||||||
for (a = 0; a < (int) (sizeof (fa) / sizeof (* fa)); ++a) {
|
for (a = 0; a < (int) (sizeof (fa) / sizeof (* fa)); ++a) {
|
||||||
for (w = 0; w < 4; ++w) {
|
for (w = 0; w < 4; ++w) {
|
||||||
for (d = 0; d < 16; ++d) {
|
for (d = 0; d < 16; ++d) {
|
||||||
@ -44,15 +49,23 @@ int main (void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//~a = 0;
|
// INR REG IMM
|
||||||
//~w = 3;
|
for (a = 0; a < (int) (sizeof (fa) / sizeof (* fa)); ++a) {
|
||||||
|
for (d = 0; d < 64; ++d) {
|
||||||
|
printf ("nop\n");
|
||||||
|
printf ("%s %s, %s\n", fa [a], fr [d], fi [d / 16]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//~for (d = 0; d < 16; ++d) {
|
// INI REG
|
||||||
//~for (s = 0; s < 16; ++s) {
|
for (a = 0; a < (int) (sizeof (faa) / sizeof (* faa)); ++a) {
|
||||||
//~printf ("nop\n");
|
for (w = 0; w < 4; ++w) {
|
||||||
//~printf ("%s %s, %s\n", fa [a], fr [d + 16 * w], fr [s + 16 * w]);
|
for (d = 0; d < 16; ++d) {
|
||||||
//~}
|
printf ("nop\n");
|
||||||
//~}
|
printf ("%s %s\n", faa [a], fr [d + 16 * w]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf ("nop\n");
|
printf ("nop\n");
|
||||||
printf ("nop\n");
|
printf ("nop\n");
|
||||||
|
166
tool/heyo.asm
166
tool/heyo.asm
@ -4,16 +4,182 @@ segment readable executable
|
|||||||
|
|
||||||
entry $
|
entry $
|
||||||
|
|
||||||
|
fff:
|
||||||
|
nop
|
||||||
|
|
||||||
mov eax, 1
|
mov eax, 1
|
||||||
|
nop
|
||||||
mov edi, 1
|
mov edi, 1
|
||||||
|
nop
|
||||||
mov esi, heyo
|
mov esi, heyo
|
||||||
|
nop
|
||||||
mov edx, 12
|
mov edx, 12
|
||||||
|
nop
|
||||||
syscall
|
syscall
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
|
mov eax, 1
|
||||||
|
nop
|
||||||
|
mov edi, 1
|
||||||
|
nop
|
||||||
|
mov esi, cyaa
|
||||||
|
nop
|
||||||
|
mov edx, 12
|
||||||
|
nop
|
||||||
|
syscall
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
|
mov eax, 1
|
||||||
|
nop
|
||||||
|
mov edi, 1
|
||||||
|
nop
|
||||||
|
mov esi, neko
|
||||||
|
nop
|
||||||
|
mov edx, 12
|
||||||
|
nop
|
||||||
|
syscall
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
|
mov rax, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rcx, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rdx, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rbx, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rsp, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rbp, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rsi, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rdi, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r8, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r9, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r10, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r11, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r12, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r13, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r14, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r15, 1122334455667788h
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
mov eax, 60
|
mov eax, 60
|
||||||
|
nop
|
||||||
mov edi, 0
|
mov edi, 0
|
||||||
|
nop
|
||||||
syscall
|
syscall
|
||||||
|
nop
|
||||||
|
jmp fff
|
||||||
|
nop
|
||||||
|
jmp nnn
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nnn:
|
||||||
|
|
||||||
segment readable writable
|
segment readable writable
|
||||||
|
|
||||||
heyo: db "heyo world!", 10
|
heyo: db "heyo world!", 10
|
||||||
|
cyaa: db "cyaa world!", 10
|
||||||
|
neko: db "neko world!", 10
|
||||||
|
|
||||||
|
;~176 / 00B0 ; header
|
||||||
|
;~504 / 01F8 ; executable
|
||||||
|
;~292 / 0124 ; readable
|
||||||
|
;~36 / 0024 ; writable
|
||||||
|
|
||||||
|
;~328 / 0148 ; executable - header
|
||||||
|
|
||||||
|
;~7F_45_4C_46_02_01_01_03_
|
||||||
|
;~00_00_00_00_00_00_00_00_ ; 0
|
||||||
|
;~02_00_3E_00_01_00_00_00_
|
||||||
|
;~B0_00_40_00_00_00_00_00_ ; header + hardcore
|
||||||
|
;~40_00_00_00_00_00_00_00_
|
||||||
|
;~00_00_00_00_00_00_00_00_ ; 0
|
||||||
|
;~00_00_00_00_40_00_38_00_
|
||||||
|
;~02_00_40_00_00_00_00_00_
|
||||||
|
|
||||||
|
;~01_00_00_00_05_00_00_00_ ; text
|
||||||
|
;~00_00_00_00_00_00_00_00_ ; 0
|
||||||
|
;~00_00_40_00_00_00_00_00_ ; hardcore
|
||||||
|
;~00_00_40_00_00_00_00_00_ ; hardcore
|
||||||
|
;~D4_01_00_00_00_00_00_00_ ; executable - writable
|
||||||
|
;~D4_01_00_00_00_00_00_00_ ; executable - writable
|
||||||
|
;~00_10_00_00_00_00_00_00_ ; softcore
|
||||||
|
|
||||||
|
;~01_00_00_00_06_00_00_00_ ; data
|
||||||
|
;~D4_01_00_00_00_00_00_00_ ; executable - writable
|
||||||
|
;~D4_11_40_00_00_00_00_00_ ; hardcore + softcore + executable - writable
|
||||||
|
;~D4_11_40_00_00_00_00_00_ ; hardcore + softcore + executable - writable
|
||||||
|
;~24_00_00_00_00_00_00_00_ ; writable
|
||||||
|
;~24_00_00_00_00_00_00_00_ ; writable
|
||||||
|
;~00_10_00_00_00_00_00_00_ ; softcore
|
||||||
|
|
||||||
|
;~90_B8_01_00_00_00_
|
||||||
|
;~90_BF_01_00_00_00_
|
||||||
|
;~90_BE_D4_11_40_00_
|
||||||
|
;~90_BA_0C_00_00_00_
|
||||||
|
;~90_0F_05_
|
||||||
|
;~90_
|
||||||
|
;~90_
|
||||||
|
;~90_B8_01_00_00_00_
|
||||||
|
;~90_BF_01_00_00_00_
|
||||||
|
;~90_BE_E0_11_40_00_
|
||||||
|
;~90_BA_0C_00_00_00_
|
||||||
|
;~90_0F_05_
|
||||||
|
;~90_
|
||||||
|
;~90_
|
||||||
|
;~90_B8_01_00_00_00_
|
||||||
|
;~90_BF_01_00_00_00_
|
||||||
|
;~90_BE_EC_11_40_00_
|
||||||
|
;~90_BA_0C_00_00_00_
|
||||||
|
;~90_0F_05_
|
||||||
|
;~90_
|
||||||
|
;~90_
|
||||||
|
;~90_48_B8_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_B9_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_BA_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_BB_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_BC_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_BD_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_BE_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_48_BF_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_B8_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_B9_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_BA_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_BB_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_BC_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_BD_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_BE_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_49_BF_88_77_66_55_44_33_22_11_
|
||||||
|
;~90_
|
||||||
|
;~90_
|
||||||
|
;~90_B8_3C_00_00_00_
|
||||||
|
;~90_BF_00_00_00_00_
|
||||||
|
;~90_0F_05_
|
||||||
|
;~90_E9_E2_FE_FF_FF_
|
||||||
|
;~90_EB_03_
|
||||||
|
;~90_
|
||||||
|
;~90_
|
||||||
|
;~90_
|
||||||
|
;~68_65_79_6F_20_77_6F_72_6C_64_21_0A_
|
||||||
|
;~63_79_61_61_20_77_6F_72_6C_64_21_0A_
|
||||||
|
;~6E_65_6B_6F_20_77_6F_72_6C_64_21_0A_
|
||||||
|
@ -6,15 +6,66 @@ section '.text' executable
|
|||||||
|
|
||||||
_start:
|
_start:
|
||||||
|
|
||||||
|
fff:
|
||||||
|
nop
|
||||||
mov eax, 1
|
mov eax, 1
|
||||||
|
nop
|
||||||
mov edi, 1
|
mov edi, 1
|
||||||
|
nop
|
||||||
mov esi, heyo
|
mov esi, heyo
|
||||||
|
nop
|
||||||
mov edx, 12
|
mov edx, 12
|
||||||
|
nop
|
||||||
syscall
|
syscall
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
|
mov rax, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rcx, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rdx, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rbx, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rsp, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rbp, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rsi, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov rdi, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r8, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r9, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r10, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r11, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r12, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r13, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r14, 1122334455667788h
|
||||||
|
nop
|
||||||
|
mov r15, 1122334455667788h
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
mov eax, 60
|
mov eax, 60
|
||||||
|
nop
|
||||||
mov edi, 0
|
mov edi, 0
|
||||||
|
nop
|
||||||
syscall
|
syscall
|
||||||
|
nop
|
||||||
|
jmp fff
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
nop
|
||||||
|
|
||||||
section '.data' writable
|
section '.data' writable
|
||||||
|
|
||||||
|
9216
tool/include.txt
Normal file
9216
tool/include.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -11,15 +11,15 @@ static unsigned int array [] = {
|
|||||||
int main (void) {
|
int main (void) {
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
|
|
||||||
token_array = malloc (1024UL * 1024UL * sizeof (* token_array));
|
text_sector_byte = malloc (1024UL * 1024UL * sizeof (* text_sector_byte));
|
||||||
|
|
||||||
assemble ((unsigned int) (sizeof (array) / sizeof (array [0])), array);
|
assemble ((unsigned int) (sizeof (array) / sizeof (array [0])), array);
|
||||||
|
|
||||||
for (index = 0; index < token_count; ++index) {
|
for (index = 0; index < text_sector_size; ++index) {
|
||||||
printf ("%c%02X", (token_array [index] == 0x90) ? '\n' : ' ', token_array [index]);
|
printf ("%c%02X", (text_sector_byte [index] == 0x90) ? '\n' : ' ', text_sector_byte [index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free (token_array);
|
free (text_sector_byte);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
diff -s -y -t --color=auto flatten.txt xlatten.txt
|
#~diff -y -W 40 --ignore-trailing-space --ignore-blank-lines --suppress-common-lines --color=always flatten.txt xlatten.txt
|
||||||
|
#~diff -y -W 40 --ignore-trailing-space --ignore-blank-lines --color=always flatten.txt xlatten.txt
|
||||||
|
#~diff -y flatten.txt xlatten.txt
|
||||||
|
diff flatten.txt xlatten.txt
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
10
tool/xfat.c
10
tool/xfat.c
@ -13,11 +13,11 @@
|
|||||||
"};\n" \
|
"};\n" \
|
||||||
"int main (void) {\n" \
|
"int main (void) {\n" \
|
||||||
" unsigned int index;\n" \
|
" unsigned int index;\n" \
|
||||||
" token_array = malloc (144UL * sizeof (* token_array));\n" \
|
" text_sector_byte = malloc (144UL * sizeof (* text_sector_byte));\n" \
|
||||||
" assemble ((unsigned int) (sizeof (array) / sizeof (array [0])), array);\n" \
|
" assemble ((unsigned int) (sizeof (array) / sizeof (array [0])), array);\n" \
|
||||||
" for (index = 0; index < token_count; ++index)\n" \
|
" for (index = 0; index < text_sector_size; ++index)\n" \
|
||||||
" printf (\"%02X \", token_array [index]);\n" \
|
" printf (\"%02X \", text_sector_byte [index]);\n" \
|
||||||
" free (token_array);\n" \
|
" free (text_sector_byte);\n" \
|
||||||
" return (0);\n" \
|
" return (0);\n" \
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ int main (int argc, char * * argv) {
|
|||||||
|
|
||||||
file = file_close (file);
|
file = file_close (file);
|
||||||
|
|
||||||
execute ("cat x.c && gcc x.c && ./a.out && echo -- && rm a.out x.c");
|
execute ("gcc x.c && ./a.out && echo -- && rm a.out x.c");
|
||||||
|
|
||||||
return (log_success);
|
return (log_success);
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static char * fw [] = {
|
static char * fw [] = {
|
||||||
"D64", "D32", "D16", "D8"
|
"D8", "D16", "D32", "D64"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char * fa [] = {
|
static char * fa [] = {
|
||||||
"ADD", "OR", "ADC", "SBB", "AND", "SUB", "XOR", "CMP"
|
"ADD", "OR", "ADC", "SBB", "AND", "SUB", "XOR", "CMP"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char * faa [] = {
|
||||||
|
"INC", "DEC", "NOT", "NEG", "UMUL", "IMUL", "UDIV", "IDIV"
|
||||||
|
};
|
||||||
|
|
||||||
static char * fr [] = {
|
static char * fr [] = {
|
||||||
"REG, R0", "REG, R1", "REG, R2", "REG, R3", "REG, R4", "REG, R5", "REG, R6", "REG, R7",
|
"REG, R0", "REG, R1", "REG, R2", "REG, R3", "REG, R4", "REG, R5", "REG, R6", "REG, R7",
|
||||||
"REG, R8", "REG, R9", "REG, R10", "REG, R11", "REG, R12", "REG, R13", "REG, R14", "REG, R15"
|
"REG, R8", "REG, R9", "REG, R10", "REG, R11", "REG, R12", "REG, R13", "REG, R14", "REG, R15"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char * fi [] = {
|
static char * fi [] = {
|
||||||
"0x11", "0x1122", "0x11223344", "0x1122334455667788",
|
"IMM, 0x11", "IMM, 0x1122", "IMM, 0x11223344", "IMM, 0x11223344"
|
||||||
};
|
};
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
@ -24,20 +28,27 @@ int main (void) {
|
|||||||
for (w = 0; w < 4; ++w) {
|
for (w = 0; w < 4; ++w) {
|
||||||
for (d = 0; d < 16; ++d) {
|
for (d = 0; d < 16; ++d) {
|
||||||
for (s = 0; s < 16; ++s) {
|
for (s = 0; s < 16; ++s) {
|
||||||
printf ("NOP, %s, %s, %s, %s,\n", fa [a], fw [w], fr [d], fr [s]);
|
printf ("NOP, %s, %s, %s, %s,\n", fa [a], fw [w], fr [d], fr [s]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//~a = 0;
|
for (a = 0; a < (int) (sizeof (fa) / sizeof (* fa)); ++a) {
|
||||||
//~w = 3;
|
for (w = 0; w < 4; ++w) {
|
||||||
|
for (d = 0; d < 16; ++d) {
|
||||||
|
printf ("NOP, %s, %s, %s, %s,\n", fa [a], fw [w], fr [d], fi [w]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//~for (d = 0; d < 16; ++d) {
|
for (a = 0; a < (int) (sizeof (faa) / sizeof (* faa)); ++a) {
|
||||||
//~for (s = 0; s < 16; ++s) {
|
for (w = 0; w < 4; ++w) {
|
||||||
//~printf ("NOP, %s, %s, %s, %s,\n", fa [a], fw [w], fr [d], fr [s]);
|
for (d = 0; d < 16; ++d) {
|
||||||
//~}
|
printf ("NOP, %s, %s, %s,\n", faa [a], fw [w], fr [d]);
|
||||||
//~}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user