Added initial UNIX stuff, unfinished...

This commit is contained in:
xolatile 2024-07-11 08:10:22 -04:00
parent 268ba6e012
commit e5aa18ffaa
4 changed files with 215 additions and 0 deletions

View File

@ -53,6 +53,7 @@ typedef enum {
FNOP, FXAM, FABS, FSCALE,
FSIN, FCOS, FSQRT, FCHS,
FXCH, FREM, FLDPI, FLDZ,
DECLARE,
} operation_index;
typedef enum {

39
source/unix.c Normal file
View File

@ -0,0 +1,39 @@
#include "unix.h"
static const uint16_t main_header_size = 0x40;
static const uint16_t text_sector_size = 0x38;
static const uint16_t data_sector_size = 0x38;
static const uint16_t full_header_size = main_header_size
+ text_sector_size
+ data_sector_size; // 0xb0
static const uint32_t softcore = 0x1000; // I DON'T KNOW WHAT IS THIS...
static const uint32_t hardcore = 0x400000; // I DON'T KNOW WHAT IS THIS...
uint8_t header_bytes [64] = {
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,
};
void header (uint8_t has_program,
uint8_t for_linux,
uint8_t for_x86_64,
uint64_t entry_point) {
/* */
uint64_t enter = entry_point; // TEST
header_bytes [16] = (has_program) ? 0x02 : 0x03; // else linkable
header_bytes [ 7] = (for_linux) ? 0x03 : 0x00; // else system v
header_bytes [18] = (for_x86_64) ? 0x3e : 0x00; // else ?
if (entry_point != 0) {
memcpy (& header_bytes [24], & enter, 8);
}
}

9
source/unix.h Normal file
View File

@ -0,0 +1,9 @@
#include <stdint.h>
#include <string.h>
extern uint8_t elf_header_bytes [64];
extern void header (uint8_t has_program,
uint8_t for_linux,
uint8_t for_x86_64,
uint64_t entry_point);

View File

@ -4,16 +4,182 @@ segment readable executable
entry $
fff:
nop
mov eax, 1
nop
mov edi, 1
nop
mov esi, heyo
nop
mov edx, 12
nop
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
nop
mov edi, 0
nop
syscall
nop
jmp fff
nop
jmp nnn
nop
nop
nop
nnn:
segment readable writable
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_