From f3f5eca707af2a61fd75065fa962935a96870b14 Mon Sep 17 00:00:00 2001 From: Axel PASCON Date: Sat, 26 Oct 2024 16:02:18 +0200 Subject: [PATCH] slight modifications --- scripts/gensectioninfo.py | 4 ++-- zerOS/linker-x86_64.ld.template | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/scripts/gensectioninfo.py b/scripts/gensectioninfo.py index b4997dc..19f8c10 100755 --- a/scripts/gensectioninfo.py +++ b/scripts/gensectioninfo.py @@ -48,8 +48,8 @@ def main() -> int: section_ldsyms = Template( """ /* --- SECTIONINFO START: ${section} --- */ -zerOS_${section}_start = ADDR(.${section}); -zerOS_${section}_end = ADDR(.${section}) + SIZEOF(.${section}); +zerOS_${section}_start = ABSOLUTE(ADDR(.${section})); +zerOS_${section}_end = ABSOLUTE(ADDR(.${section})) + SIZEOF(.${section}); zerOS_${section}_size = SIZEOF(.${section}); /* --- SECTIONINFO END: ${section} --- */ """ diff --git a/zerOS/linker-x86_64.ld.template b/zerOS/linker-x86_64.ld.template index cf1da2e..0bda9c8 100644 --- a/zerOS/linker-x86_64.ld.template +++ b/zerOS/linker-x86_64.ld.template @@ -1,4 +1,4 @@ -/* TODO: Write a custom bootloader */ +/* TODO: Write a custom EFI-stub */ /* Tell the linker that we want an x86_64 ELF64 output file */ OUTPUT_FORMAT(elf64-x86-64) @@ -17,7 +17,7 @@ PHDRS rodata PT_LOAD; data PT_LOAD; dynamic PT_DYNAMIC; - /* TODO: Add support for "TLS" or per-cpu variables / sections */ + percpu PT_LOAD; } SECTIONS @@ -30,9 +30,7 @@ SECTIONS /* base load address. */ . = 0xffffffff80000000 + SIZEOF_HEADERS; - .start_kern : { - zerOS_kernel_start = .; - } :rodata + zerOS_kernel_start = ABSOLUTE(.); /* Emit zerOS__start and zerOS__end symbols for each section. */ @@ -57,6 +55,12 @@ SECTIONS !!!__GENSECTION_FILL__!!! } :rodata + . = ALIGN(CONSTANT(MAXPAGESIZE)); + + .percpu : { + *(.percpu .percpu.*) + } :percpu + /* Move to the next memory page for .data */ . = ALIGN(CONSTANT(MAXPAGESIZE)); @@ -70,10 +74,7 @@ SECTIONS KEEP(*(.requests_end_marker)) } :data - /* Dynamic section for relocations, both in its own PHDR and inside data PHDR. */ - /*.dynamic : { */ - /* *(.dynamic) */ - /*} :data :dynamic*/ + . = ALIGN(CONSTANT(MAXPAGESIZE)); /* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */ /* unnecessary zeros will be written to the binary. */ @@ -84,9 +85,8 @@ SECTIONS *(COMMON) } :data - .end_kern : { - zerOS_kernel_end = .; - } :rodata + zerOS_kernel_end = ABSOLUTE(.); + /* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */ /* Also discard the program interpreter section since we do not need one. This is */ @@ -97,4 +97,9 @@ SECTIONS *(.note .note.*) *(.interp) } -} \ No newline at end of file +} + +NOCROSSREFS_TO(.text, .bootcode) + +ASSERT( ADDR(zerOS_kernel_start) == 0xffffffff80000000 + SIZEOF_HEADERS, "zerOS_kernel_start is not at the correct VMA") +ASSERT(LOADADDR(zerOS_kernel_start) == 0xffffffff80000000 + SIZEOF_HEADERS, "zerOS_kernel_start is not at the correct LMA") \ No newline at end of file