diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-12-29 14:43:20 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-12-29 14:43:20 +0100 |
| commit | fb1c180c431e3ac07ca56f53299edea316883842 (patch) | |
| tree | 60344689657d6c9512c697e3ac714709cc3c958c /arch | |
| parent | c522a3634e0cd20804b1e3216caedd5e15cbee19 (diff) | |
| download | teachos-fb1c180c431e3ac07ca56f53299edea316883842.tar.xz teachos-fb1c180c431e3ac07ca56f53299edea316883842.zip | |
x86_64/boot: fix section assignments in ld script
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/scripts/kernel.ld | 133 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/boot32.S | 14 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/entry64.s | 14 | ||||
| -rw-r--r-- | arch/x86_64/src/boot/initialize_runtime.cpp | 11 |
4 files changed, 81 insertions, 91 deletions
diff --git a/arch/x86_64/scripts/kernel.ld b/arch/x86_64/scripts/kernel.ld index 064b8d7..9a5dfd8 100644 --- a/arch/x86_64/scripts/kernel.ld +++ b/arch/x86_64/scripts/kernel.ld @@ -3,17 +3,21 @@ ENTRY(_start) /***************************************************************************** * Virtual and linear start addresses of the TeachOS kernel *****************************************************************************/ -TEACHOS_PMA = 1M; -TEACHOS_VMA = 0xFFFFFFFF80000000; +PROVIDE_HIDDEN(TEACHOS_PMA = 1M); +PROVIDE_HIDDEN(TEACHOS_VMA = -2048M); 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); + kernel_rodata PT_LOAD FLAGS(4); + kernel_text PT_LOAD FLAGS(5); + kernel_data PT_LOAD FLAGS(6); + + user_rodata PT_LOAD FLAGS(4); + user_text PT_LOAD FLAGS(5); + user_data PT_LOAD FLAGS(6); } SECTIONS @@ -30,104 +34,99 @@ SECTIONS * during bootstrapping and operation. To achieve this, we define some * symbols at the beginning. ***************************************************************************/ - _start_physical = .; - _start_virtual = . + TEACHOS_VMA; - + PROVIDE_HIDDEN(_start_physical = .); + PROVIDE_HIDDEN(_start_virtual = . + TEACHOS_VMA); - /*************************************************************************** - * 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 ALIGN(4K) : AT(ADDR (.boot_rodata)) + .boot_rodata ALIGN(4K) : { - KEEP(*(.boot_mbh)) - *(.boot_rodata) + KEEP(*(.boot_mbh .boot_rodata*)) } :boot_rodata - .boot_text ALIGN(4K) : AT(ADDR (.boot_text)) + .boot_data ALIGN(4K) : { - *(.boot_text) - } :boot_text + KEEP(*(.boot_data*)) - .boot_bss ALIGN(4K) : AT(ADDR (.boot_bss)) - { - *(.boot_bss) - *(.boot_stack) - } + PROVIDE_HIDDEN(__init_array_start = .); + KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN(__init_array_end = .); + } :boot_data - .boot_data ALIGN(4K) : AT(ADDR (.boot_data)) + .boot_bss ALIGN(4K) : { - *(.boot_data) + KEEP(*(.boot_stack .boot_bss*)) } :boot_data + .boot_text ALIGN(4K) : + { + KEEP(*(.boot_text*)) + } :boot_text + /*************************************************************************** - * Now it is time to load the 64-bit kernel code. We - * make sure to align the loaded data onto a page boundary. + * Now it is time to load the 64-bit kernel code. We make sure to align the + * loaded data onto a page boundary. ***************************************************************************/ . = ALIGN(4K); . += TEACHOS_VMA; - .stl_text ALIGN(4K) : AT(ADDR (.stl_text) - TEACHOS_VMA) + .kernel_rodata ALIGN(4K) : AT (ADDR (.kernel_rodata) - TEACHOS_VMA) { - *(.stl_text .stl_text*) - KEEP(*libstdc++.a:*(.text .text.*)) - } :text + *(EXCLUDE_FILE (*libstdc++.a:*) .rodata*) + } :kernel_rodata - .text ALIGN(4K) : AT(ADDR (.text) - TEACHOS_VMA) + .kernel_data ALIGN(4K) : AT (ADDR (.kernel_data) - TEACHOS_VMA) { - *(.text .text.*) - } + *(EXCLUDE_FILE (*libstdc++.a:*) .data*) + } :kernel_data - .user_text ALIGN(4K) : AT(ADDR (.user_text) - TEACHOS_VMA) - { - *(.user_text .user_text.*) - } + . += 4K; - .rodata ALIGN(4K) : AT (ADDR (.rodata) - TEACHOS_VMA) + .kernel_bss ALIGN(4K) : AT (ADDR (.kernel_bss) - TEACHOS_VMA) { - *(.rodata) - *(.rodata.*) - } :rodata + *(EXCLUDE_FILE (*libstdc++.a:*) .stack .bss*) + } :kernel_data - .ctors ALIGN(4K) : AT (ADDR (.ctors) - TEACHOS_VMA) + .kernel_text ALIGN(4K) : AT(ADDR (.kernel_text) - TEACHOS_VMA) { - __ctors_start = .; - KEEP(*(SORT(.ctors.*))) - KEEP(*(.ctors)) - __ctors_end = .; - } :data + *(EXCLUDE_FILE (*libstdc++.a:*) .text*) + } :kernel_text + + /*************************************************************************** + * Finally, we load the user-accessible code and data. + ***************************************************************************/ - .init_array ALIGN(4K) : AT (ADDR (.init_array) - TEACHOS_VMA) + .user_rodata ALIGN(4K) : AT (ADDR (.user_rodata) - TEACHOS_VMA) { - __init_array_start = .; - KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*))) - KEEP(*(.init_array)) - __init_array_end = .; - } + *(.stl_rodata* .user_rodata*) + KEEP(*libstdc++.a:*(.rodata*)) + } :user_rodata - .bss ALIGN(4K) : AT (ADDR (.bss) - TEACHOS_VMA) + .user_data ALIGN(4K) : AT (ADDR (.user_data) - TEACHOS_VMA) { - *(COMMON) - *(.bss*) - } + *(.stl_data* .user_data*) + KEEP(*libstdc++.a:*(.data*)) + } :user_data + + . += 4K; - .data ALIGN(4K) : AT (ADDR (.data) - TEACHOS_VMA) + .user_bss ALIGN(4K) : AT(ADDR (.user_bss) - TEACHOS_VMA) { - *(.data*) - } + *(.stl_bss* .user_bss*) + KEEP(*libstdc++.a:*(.bss*)) + } :user_data - .user_data ALIGN(4K) : AT (ADDR (.user_data) - TEACHOS_VMA) + .user_text ALIGN(4K) : AT(ADDR (.user_text) - TEACHOS_VMA) { - *(.user_data .user_data.*) - } + KEEP(*(.stl_text* .user_text*)) + KEEP(*libstdc++.a:*(.text*)) + } :user_text /*************************************************************************** * In accordance with the symbol definitions at the start, we generate some * symbols to mark the end of our loaded image. ***************************************************************************/ - _end_virtual = .; - _end_physical = _end_virtual - TEACHOS_VMA; + PROVIDE_HIDDEN(_end_virtual = .); + PROVIDE_HIDDEN(_end_physical = _end_virtual - TEACHOS_VMA); /DISCARD/ : { *(.comment) } } diff --git a/arch/x86_64/src/boot/boot32.S b/arch/x86_64/src/boot/boot32.S index 79b3ec7..cea1607 100644 --- a/arch/x86_64/src/boot/boot32.S +++ b/arch/x86_64/src/boot/boot32.S @@ -5,14 +5,6 @@ */ .section .boot_bss, "aw", @nobits -/** - * @brief Storage for the multiboot2 information pointer. - */ -.global multiboot_information_pointer -multiboot_information_pointer: .skip 8 - -.align 4096 - page_maps_start: page_map_level_4: .skip 512 * 8 page_map_level_3_high: .skip 512 * 8 @@ -22,6 +14,12 @@ page_maps_end = . page_maps_size = page_maps_end - page_maps_start /** + * @brief Storage for the multiboot2 information pointer. + */ +.global multiboot_information_pointer +multiboot_information_pointer: .skip 8 + +/** * @brief Storage for the bootstrap stack. */ .section .boot_stack, "aw", @nobits diff --git a/arch/x86_64/src/boot/entry64.s b/arch/x86_64/src/boot/entry64.s index 657b0a8..29fb778 100644 --- a/arch/x86_64/src/boot/entry64.s +++ b/arch/x86_64/src/boot/entry64.s @@ -1,3 +1,11 @@ +.section .stack, "aw", @nobits + +.align 16 +.global stack_top +stack_bottom: .skip 1 << 20 +stack_top: +stack_size = stack_top - stack_bottom + .section .bss, "aw", @nobits //! A structure containing information gathered during the bootstrap process. @@ -11,12 +19,6 @@ .global bootstrap_information bootstrap_information: .skip 16 -.align 16 -.global stack_top -stack_bottom: .skip 1 << 20 -stack_top: -stack_size = stack_top - stack_bottom - .section .boot_text, "ax", @progbits .code64 diff --git a/arch/x86_64/src/boot/initialize_runtime.cpp b/arch/x86_64/src/boot/initialize_runtime.cpp index 46dd5e4..f413448 100644 --- a/arch/x86_64/src/boot/initialize_runtime.cpp +++ b/arch/x86_64/src/boot/initialize_runtime.cpp @@ -6,21 +6,12 @@ extern "C" { using global_initializer = auto (*)() -> void; - extern global_initializer __ctors_start; - extern global_initializer __ctors_end; extern global_initializer __init_array_start; extern global_initializer __init_array_end; auto invoke_global_constructors() -> void { - auto constructors = std::span{&__ctors_start, &__ctors_end}; auto initializers = std::span{&__init_array_start, &__init_array_end}; - - auto apply_invoke = [](auto invokable) -> void { - std::invoke(invokable); - }; - - std::ranges::for_each(constructors, apply_invoke); - std::ranges::for_each(initializers, apply_invoke); + std::ranges::for_each(initializers, [](auto invokable) { std::invoke(invokable); }); } } |
