diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2024-09-16 14:07:41 +0000 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2024-09-17 08:58:55 +0200 |
| commit | 8f9b9cd8aac30572b7e275bbeb1b32d2cbb8950a (patch) | |
| tree | 5e215dd93c34b3d58c287b036ad2d190e0a9a772 /arch/x86_64/scripts | |
| parent | c16a3739649fa15178df667d610553e93db83e4c (diff) | |
| download | teachos-8f9b9cd8aac30572b7e275bbeb1b32d2cbb8950a.tar.xz teachos-8f9b9cd8aac30572b7e275bbeb1b32d2cbb8950a.zip | |
build: migrate away from conan
Diffstat (limited to 'arch/x86_64/scripts')
| -rw-r--r-- | arch/x86_64/scripts/kernel.ld | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld new file mode 100644 index 0000000..765a432 --- /dev/null +++ b/arch/x86_64/scripts/kernel.ld @@ -0,0 +1,139 @@ +ENTRY(_start) + +/***************************************************************************** + * Virtual and linear start addresses of the TeachOS kernel + *****************************************************************************/ +TEACHOS_HIGH = -2048M; +TEACHOS_LOW = 1M; + +PHDRS { + boot_rodata PT_LOAD FLAGS(4); + boot_text PT_LOAD FLAGS(5); + boot_data PT_LOAD FLAGS(6); + + text PT_LOAD FLAGS(5); + data PT_LOAD FLAGS(6); + rodata PT_LOAD FLAGS(4); +} + +SECTIONS +{ + /*************************************************************************** + * Load the bootstrap code into low memory. We need to be accessible in + * 32-Bit mode, so we want to live down low, but we need to leave the 1MiB + * hole open since some BIOS functionality resides below it. + ***************************************************************************/ + . = TEACHOS_LOW; + + /*************************************************************************** + * We want to be able to be able to access all memory (linear and virtual) + * during bootstrapping and operation. To achieve this, we define some + * symbols at the beginning. + ***************************************************************************/ + _start_linear = .; + _start_virtual = . + TEACHOS_HIGH; + + /*************************************************************************** + * The bootstrapping infratructure goes first. We first place the read-only + * data, followed by our code, initialized mutable data, and finally our + * uninitialized mutable data. + ***************************************************************************/ + .boot_rodata : + { + KEEP(*(.boot_mbh)) + *(.boot_rodata) + } :boot_rodata + + .boot_text : + { + *(.boot_text) + } :boot_text + + .boot_data : + { + *(.boot_data) + } :boot_data + + .boot_bss : + { + *(.boot_bss) + *(.boot_stack) + } + + /*************************************************************************** + * Now it is time to load the 64-bit kernel code. We virtually load it into + * the upper 2GiB, while adjusting the linear load address appropriately. We + * also make sure to align the loaded data onto a page boundary. + ***************************************************************************/ + . = ALIGN(4K); + . += TEACHOS_HIGH; + + .init ALIGN(4K) : AT(ADDR (.init) - TEACHOS_HIGH) + { + /* + * Make sure that the crt code is wrapped around the compiler generated + * initialization code. + */ + KEEP(*crti.s.obj(.init)) + KEEP(*(EXCLUDE_FILE (*crti.s.obj *crtn.s.obj) .init)) + KEEP(*crtn.s.obj(.init)) + } :text + + .fini ALIGN(4K) : AT(ADDR (.fini) - TEACHOS_HIGH) + { + /* + * Make sure that the crt code is wrapped around the compiler generated + * finalizer code. + */ + KEEP(*crti.s.obj(.fini)) + KEEP(*(EXCLUDE_FILE (*crti.s.obj *crtn.s.obj) .fini)) + KEEP(*crtn.s.obj(.fini)) + } + + .text ALIGN(4K) : AT(ADDR (.text) - TEACHOS_HIGH) + { + *(.text*) + } + + .rodata ALIGN(4K) : AT (ADDR (.rodata) - TEACHOS_HIGH) + { + *(.rodata) + *(.rodata.*) + } :rodata + + .ctors ALIGN(4K) : AT (ADDR (.ctors) - TEACHOS_HIGH) + { + KEEP(*crtbegin.o(.ctors)) + KEEP(*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP(*(SORT(.ctors.*))) + KEEP(*crtend.o(.ctors)) + } :data + + .dtors ALIGN(4K) : AT (ADDR (.dtors) - TEACHOS_HIGH) + { + KEEP(*crtbegin.o(.dtors)) + KEEP(*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP(*(SORT(.dtors.*))) + KEEP(*crtend.o(.dtors)) + } + + .data ALIGN(4K) : AT (ADDR (.data) - TEACHOS_HIGH) + { + *(.data*) + } + + .bss ALIGN(4K) : AT (ADDR (.bss) - TEACHOS_HIGH) + { + *(COMMON) + *(.bss*) + } + + /*************************************************************************** + * In accordance with the symbol definitions at the start, we generate some + * symbols to mark the end of our loaded image. + ***************************************************************************/ + _end_virtual = ADDR(.bss) + SIZEOF(.bss); + _end_linear = _end_virtual - TEACHOS_HIGH; + + /DISCARD/ : { *(.comment) } +} |
