diff options
| author | Druid520 <r.ustydruid520@proton.me> | 2026-08-17 10:47:46 -0700 |
|---|---|---|
| committer | Druid520 <r.ustydruid520@proton.me> | 2026-08-17 10:47:46 -0700 |
| commit | 848c0c6a3fcd3a05a2d8d5fbb3eb550bc423f807 (patch) | |
| tree | ce887d52b87656b16f8b82a2aa95082cd8529428 | |
ADD: charge basics stuff.
| -rw-r--r-- | cfg.ld | 55 | ||||
| -rw-r--r-- | mk.conf | 23 | ||||
| -rw-r--r-- | mk/b.sh | 9 | ||||
| -rw-r--r-- | mk/c.sh | 4 | ||||
| -rw-r--r-- | src/main.c | 6 | ||||
| -rw-r--r-- | src/note.s | 9 | ||||
| -rw-r--r-- | src/start.s | 17 |
7 files changed, 123 insertions, 0 deletions
| diff --git a/cfg.ld b/cfg.ld new file mode 100644 index 0000000..a4dc193 --- /dev/null +++ b/cfg.ld | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | OUTPUT_FORMAT("elf64-x86-64") | ||
| 2 | OUTPUT_ARCH("i386:x86-64") | ||
| 3 | ENTRY(_start) | ||
| 4 | |||
| 5 | SECTIONS | ||
| 6 | { | ||
| 7 | . = 0x100000; /* start at 1mb. */ | ||
| 8 | |||
| 9 | .text : ALIGN(4K) | ||
| 10 | { | ||
| 11 | *(.text.startup) | ||
| 12 | *(.text) | ||
| 13 | *(.text.*) | ||
| 14 | } | ||
| 15 | |||
| 16 | .rodata : ALIGN(4K) | ||
| 17 | { | ||
| 18 | *(.rodata) | ||
| 19 | *(.rodata.*) | ||
| 20 | } | ||
| 21 | |||
| 22 | .data : ALIGN(4K) | ||
| 23 | { | ||
| 24 | *(.data) | ||
| 25 | *(.data.*) | ||
| 26 | } | ||
| 27 | |||
| 28 | .bss : ALIGN(4K) | ||
| 29 | { | ||
| 30 | *(.bss) | ||
| 31 | *(.bss.*) | ||
| 32 | *(COMMON) | ||
| 33 | } | ||
| 34 | |||
| 35 | .note.netbsd.ident : ALIGN(4) | ||
| 36 | { | ||
| 37 | *(.note.netbsd.ident) | ||
| 38 | } | ||
| 39 | |||
| 40 | /DISCARD/ : | ||
| 41 | { | ||
| 42 | *(.comment) | ||
| 43 | *(.eh_frame) | ||
| 44 | *(.eh_frame_hdr) | ||
| 45 | *(.debug_*) | ||
| 46 | *(.stab) | ||
| 47 | *(.stabstr) | ||
| 48 | *(.shstrtab) | ||
| 49 | *(.strtab) | ||
| 50 | *(.symtab) | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | PROVIDE(__stack = 0x400000); | ||
| 55 | PROVIDE(_end = .); | ||
| diff --git a/mk.conf b/mk.conf new file mode 100644 index 0000000..8f3ff1f --- /dev/null +++ b/mk.conf | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | src="src" | ||
| 2 | out="out" | ||
| 3 | |||
| 4 | bin="$out/bin" | ||
| 5 | bin_ln="bin" | ||
| 6 | |||
| 7 | note_src="$src/note.s" | ||
| 8 | note_bin="$out/note.o" | ||
| 9 | start_src="$src/start.s" | ||
| 10 | start_bin="$out/start.o" | ||
| 11 | main_src="$src/main.c" | ||
| 12 | main_bin="$out/main.o" | ||
| 13 | |||
| 14 | ln="ln" | ||
| 15 | as="as" | ||
| 16 | ld="ld" | ||
| 17 | ld_cfg="cfg.ld" | ||
| 18 | cc="gcc" | ||
| 19 | |||
| 20 | lnflgs="-sf" | ||
| 21 | asflgs="" | ||
| 22 | ldflgs="-O0 -static -no-pie -T $ld_cfg" | ||
| 23 | ccflgs="-nostdlib -ffreestanding -fno-pie -fno-builtin -std=c99 -O0 -g0" | ||
| diff --git a/mk/b.sh b/mk/b.sh new file mode 100644 index 0000000..d8b27d5 --- /dev/null +++ b/mk/b.sh | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | . ./mk.conf | ||
| 2 | set -e | ||
| 3 | |||
| 4 | mkdir $out | ||
| 5 | $as $asflgs -o $note_bin $note_src | ||
| 6 | $as $asflgs -o $start_bin $start_src | ||
| 7 | $cc $ccflgs -o $main_bin -c $main_src | ||
| 8 | $ld $ldflgs -o $bin $note_bin $start_bin $main_bin | ||
| 9 | $ln $lnflgs $bin $bin_ln | ||
| diff --git a/mk/c.sh b/mk/c.sh new file mode 100644 index 0000000..d637651 --- /dev/null +++ b/mk/c.sh | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | . ./mk.conf | ||
| 2 | set -e | ||
| 3 | |||
| 4 | rm -rf $out $bin_ln | ||
| diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..83423bb --- /dev/null +++ b/src/main.c | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | int main(int argc, char** argv); | ||
| 2 | |||
| 3 | int main(int argc, char** argv) | ||
| 4 | { | ||
| 5 | return 0; | ||
| 6 | } | ||
| diff --git a/src/note.s b/src/note.s new file mode 100644 index 0000000..a8b606e --- /dev/null +++ b/src/note.s | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | .section .note.netbsd.ident, "a" # allocatable section. | ||
| 2 | .align 4 | ||
| 3 | .int 7 # namesz = "NetBSD" = 7 bytes. | ||
| 4 | .int 4 # descsz = version = 4 bytes. | ||
| 5 | .int 1 # type = ELF_NOTE_TYPE_NETBSD_TAG. | ||
| 6 | .ascii "NetBSD" # name. | ||
| 7 | .byte 0 # null term for name. | ||
| 8 | .long 110000000 # desc = 11.0 (netbsd ver). | ||
| 9 | .align 4 | ||
| diff --git a/src/start.s b/src/start.s new file mode 100644 index 0000000..58efed0 --- /dev/null +++ b/src/start.s | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | .section .text | ||
| 2 | .globl _start | ||
| 3 | .type _start, @function | ||
| 4 | _start: | ||
| 5 | xorq %rbp, %rbp # frame ptr (%rbp) = null. marks stack bottom. | ||
| 6 | |||
| 7 | movl (%rsp), %edi # argc = first 4 bytes of stack. | ||
| 8 | leaq 8(%rsp), %rsi # argv = address of first arg ptr. | ||
| 9 | |||
| 10 | call main # see main.c. | ||
| 11 | |||
| 12 | movl %eax, %edi # status = ret val. | ||
| 13 | movl $1, %eax # SYS_exit = 1. | ||
| 14 | syscall | ||
| 15 | |||
| 16 | .size _start, .-_start | ||
| 17 | hlt # if syscall fails hang. | ||
