From fd9e51b838f454894940940110f2f18bedf5e621 Mon Sep 17 00:00:00 2001 From: Druid520 Date: Mon, 17 Aug 2026 15:57:04 -0700 Subject: MOD: improve charge and update. --- cfg.ld | 55 ------------------------------------------------------- linux-cfg.ld | 36 ++++++++++++++++++++++++++++++++++++ mk.conf | 11 ++++++----- mk/b.sh | 9 --------- mk/linux/b.sh | 8 ++++++++ mk/netbsd/b.sh | 9 +++++++++ netbsd-cfg.ld | 41 +++++++++++++++++++++++++++++++++++++++++ src/netbsd-note.s | 9 +++++++++ src/note.s | 9 --------- 9 files changed, 109 insertions(+), 78 deletions(-) delete mode 100644 cfg.ld create mode 100644 linux-cfg.ld delete mode 100644 mk/b.sh create mode 100644 mk/linux/b.sh create mode 100644 mk/netbsd/b.sh create mode 100644 netbsd-cfg.ld create mode 100644 src/netbsd-note.s delete mode 100644 src/note.s diff --git a/cfg.ld b/cfg.ld deleted file mode 100644 index a4dc193..0000000 --- a/cfg.ld +++ /dev/null @@ -1,55 +0,0 @@ -OUTPUT_FORMAT("elf64-x86-64") -OUTPUT_ARCH("i386:x86-64") -ENTRY(_start) - -SECTIONS -{ - . = 0x100000; /* start at 1mb. */ - - .text : ALIGN(4K) - { - *(.text.startup) - *(.text) - *(.text.*) - } - - .rodata : ALIGN(4K) - { - *(.rodata) - *(.rodata.*) - } - - .data : ALIGN(4K) - { - *(.data) - *(.data.*) - } - - .bss : ALIGN(4K) - { - *(.bss) - *(.bss.*) - *(COMMON) - } - - .note.netbsd.ident : ALIGN(4) - { - *(.note.netbsd.ident) - } - - /DISCARD/ : - { - *(.comment) - *(.eh_frame) - *(.eh_frame_hdr) - *(.debug_*) - *(.stab) - *(.stabstr) - *(.shstrtab) - *(.strtab) - *(.symtab) - } -} - -PROVIDE(__stack = 0x400000); -PROVIDE(_end = .); diff --git a/linux-cfg.ld b/linux-cfg.ld new file mode 100644 index 0000000..b2a5f17 --- /dev/null +++ b/linux-cfg.ld @@ -0,0 +1,36 @@ +OUTPUT_FORMAT("elf64-x86-64") +OUTPUT_ARCH("i386:x86-64") +ENTRY(_start) +MAXPAGESIZE = 0; + +SECTIONS +{ + . = 0x100000; /* start at 1mb. */ + + .text : + { + *(.text.startup) + *(.text) + *(.rodata) + *(.data) + } + + .bss : + { + *(.bss) + } + + /DISCARD/ : + { + *(.comment) + *(.eh_frame) + *(.eh_frame_hdr) + *(.debug_*) + *(.symtab) + *(.strtab) + *(.shstrtab) + } +} + +PROVIDE(__stack = 0x400000); +PROVIDE(_end = .); diff --git a/mk.conf b/mk.conf index 8f3ff1f..c520246 100644 --- a/mk.conf +++ b/mk.conf @@ -4,8 +4,8 @@ out="out" bin="$out/bin" bin_ln="bin" -note_src="$src/note.s" -note_bin="$out/note.o" +netbsd_note_src="$src/netbsd-note.s" +netbsd_note_bin="$out/netbsd-note.o" start_src="$src/start.s" start_bin="$out/start.o" main_src="$src/main.c" @@ -14,10 +14,11 @@ main_bin="$out/main.o" ln="ln" as="as" ld="ld" -ld_cfg="cfg.ld" +ld_netbsd_cfg="netbsd-cfg.ld" +ld_linux_cfg="linux-cfg.ld" cc="gcc" lnflgs="-sf" asflgs="" -ldflgs="-O0 -static -no-pie -T $ld_cfg" -ccflgs="-nostdlib -ffreestanding -fno-pie -fno-builtin -std=c99 -O0 -g0" +ldflgs="-Os -s -static -no-pie --omagic -N -z nosectionheader --no-warn-rwx-segments" +ccflgs="-nostdlib -ffreestanding -fno-pie -fno-builtin -std=c99 -Os -pipe -s -g0 -I$src" diff --git a/mk/b.sh b/mk/b.sh deleted file mode 100644 index d8b27d5..0000000 --- a/mk/b.sh +++ /dev/null @@ -1,9 +0,0 @@ -. ./mk.conf -set -e - -mkdir $out -$as $asflgs -o $note_bin $note_src -$as $asflgs -o $start_bin $start_src -$cc $ccflgs -o $main_bin -c $main_src -$ld $ldflgs -o $bin $note_bin $start_bin $main_bin -$ln $lnflgs $bin $bin_ln diff --git a/mk/linux/b.sh b/mk/linux/b.sh new file mode 100644 index 0000000..c9b9b04 --- /dev/null +++ b/mk/linux/b.sh @@ -0,0 +1,8 @@ +. ./mk.conf +set -e + +mkdir $out +$as $asflgs -o $start_bin $start_src +$cc $ccflgs -o $main_bin -c $main_src +$ld $ldflgs -T $ld_linux_cfg -o $bin $start_bin $main_bin +$ln $lnflgs $bin $bin_ln diff --git a/mk/netbsd/b.sh b/mk/netbsd/b.sh new file mode 100644 index 0000000..6a4251c --- /dev/null +++ b/mk/netbsd/b.sh @@ -0,0 +1,9 @@ +. ./mk.conf +set -e + +mkdir $out +$as $asflgs -o $netbsd_note_bin $netbsd_note_src +$as $asflgs -o $start_bin $start_src +$cc $ccflgs -o $main_bin -c $main_src +$ld $ldflgs -T $ld_netbsd_cfg -o $bin $netbsd_note_bin $start_bin $main_bin +$ln $lnflgs $bin $bin_ln diff --git a/netbsd-cfg.ld b/netbsd-cfg.ld new file mode 100644 index 0000000..235af62 --- /dev/null +++ b/netbsd-cfg.ld @@ -0,0 +1,41 @@ +OUTPUT_FORMAT("elf64-x86-64") +OUTPUT_ARCH("i386:x86-64") +ENTRY(_start) +MAXPAGESIZE = 0; + +SECTIONS +{ + . = 0x100000; /* start at 1mb. */ + + .text : + { + *(.text.startup) + *(.text) + *(.rodata) + *(.data) + } + + .bss : + { + *(.bss) + } + + .note.netbsd.ident : + { + *(.note.netbsd.ident) + } + + /DISCARD/ : + { + *(.comment) + *(.eh_frame) + *(.eh_frame_hdr) + *(.debug_*) + *(.symtab) + *(.strtab) + *(.shstrtab) + } +} + +PROVIDE(__stack = 0x400000); +PROVIDE(_end = .); diff --git a/src/netbsd-note.s b/src/netbsd-note.s new file mode 100644 index 0000000..a8b606e --- /dev/null +++ b/src/netbsd-note.s @@ -0,0 +1,9 @@ +.section .note.netbsd.ident, "a" # allocatable section. + .align 4 + .int 7 # namesz = "NetBSD" = 7 bytes. + .int 4 # descsz = version = 4 bytes. + .int 1 # type = ELF_NOTE_TYPE_NETBSD_TAG. + .ascii "NetBSD" # name. + .byte 0 # null term for name. + .long 110000000 # desc = 11.0 (netbsd ver). + .align 4 diff --git a/src/note.s b/src/note.s deleted file mode 100644 index a8b606e..0000000 --- a/src/note.s +++ /dev/null @@ -1,9 +0,0 @@ -.section .note.netbsd.ident, "a" # allocatable section. - .align 4 - .int 7 # namesz = "NetBSD" = 7 bytes. - .int 4 # descsz = version = 4 bytes. - .int 1 # type = ELF_NOTE_TYPE_NETBSD_TAG. - .ascii "NetBSD" # name. - .byte 0 # null term for name. - .long 110000000 # desc = 11.0 (netbsd ver). - .align 4 -- cgit 1.4.1