aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-07 21:44:12 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-07 21:44:12 +0200
commit361f02166cc939879b58328cbf5e75a050c93e1d (patch)
tree09c6f0a2be4182d78d9fbbe6c4ffe56838bd1642
parentscheduler: fix task switching (diff)
downloadkernel.cpp-361f02166cc939879b58328cbf5e75a050c93e1d.tar.xz
Move multiboot header to its own section
-rw-r--r--linker.ld70
-rw-r--r--makefile5
-rw-r--r--src/boot.S4
-rw-r--r--src/idt.cc2
4 files changed, 41 insertions, 40 deletions
diff --git a/linker.ld b/linker.ld
index eaf118c..cd4139c 100644
--- a/linker.ld
+++ b/linker.ld
@@ -1,47 +1,45 @@
ENTRY(_start)
OUTPUT_FORMAT(elf32-i386)
-/* Tell where the various sections of the object files will be put in the final
- kernel image. */
SECTIONS
{
- /* Begin putting sections at 1 MiB, a conventional place for kernels to be
- loaded at by the bootloader. */
- . = 1M;
+ /* Begin putting sections at 1 MiB */
+ . = 1M;
- /* First put the multiboot header, as it is required to be put very early
- early in the image or the bootloader won't recognize the file format.
- Next we'll put the .text section. */
- .text :
- {
- *(.multiboot)
- *(.text)
- }
+ /* First put the multiboot header, as it is required to be put very early
+ * early in the image or the bootloader won't recognize the file format.
+ */
+ .multiboot : {
+ *(.multiboot.header)
+ *(.multiboot.text)
+ }
+
+ .text : {
+ *(.text*)
+ }
- /* Read-only data. */
- .rodata :
- {
- *(.rodata)
- }
+ /* Read-only data. */
+ .rodata : {
+ *(.rodata*)
+ }
- /* Read-write data (initialized) */
- .data :
- {
- start_ctors = .;
- KEEP(*(.init_array));
- KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)));
- end_ctors = .;
- *(.data)
- }
+ /* Read-write data (initialized) */
+ .data : {
+ start_ctors = .;
+ KEEP(*(.init_array)); /* global constructors */
+ end_ctors = .;
+
+ begin_constinit = .;
+ *(.constinit)
+ end_constinit = .;
+
+ *(.data)
+ }
- /* Read-write data (uninitialized) and stack */
- .bss :
- {
- *(COMMON)
- *(.bss)
- *(.stack)
- }
+ /* Read-write data (uninitialized) and stack */
+ .bss : {
+ *(.bss)
+ *(.stack)
+ }
- /* The compiler may produce other sections, by default it will put them in
- a segment with the same name. Simply add stuff here as needed. */
}
diff --git a/makefile b/makefile
index 829d566..afbe1d1 100644
--- a/makefile
+++ b/makefile
@@ -2,7 +2,7 @@ include toolchain.makefile
include .config
OBJ_DIR != echo $(CONFIG_OBJ_DIR)
-.PHONY: default clean test check-grub run
+.PHONY: default clean test todo run
default: glitch.elf
include libk/makefile
@@ -42,6 +42,9 @@ clean:
# testing
test: $(CXX_TEST_OBJ)
+todo:
+ @grep TODO -r libk/ src/ drivers/
+
# disk image
glitch.iso: glitch.elf grub/grub.cfg
@mkdir -p isodir/boot/grub
diff --git a/src/boot.S b/src/boot.S
index fff1644..b17aea3 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -9,7 +9,7 @@
.set MULTIBOOT_ARCHITECTURE, 0 # protected mode i386
.set MULTIBOOT_HEADER_TAG_END, 0
-.section .multiboot
+.section .multiboot.header, "a"
.align 8
header_start:
.int MULTIBOOT_HEADER_MAGIC
@@ -40,7 +40,7 @@ stack_top:
The linker script specifies _start as the entry point to the kernel and the
bootloader will jump to this position once the kernel has been loaded.
*/
-.section .text
+.section .multiboot.text, "ax"
.extern kernel_constructors
.extern kernel_main
.global _start
diff --git a/src/idt.cc b/src/idt.cc
index 5022f3e..edf7b37 100644
--- a/src/idt.cc
+++ b/src/idt.cc
@@ -6,7 +6,7 @@
static_assert(sizeof(IDT::Pointer) == 6);
constexpr uint8_t irq_base = 0x20;
-static IDT::Entry table[256];
+__attribute__((section(".constinit"))) static IDT::Entry table[256];
static InterruptHandler* handlers[256] = {nullptr};
bool IDT::install(uint8_t irq, InterruptHandler* h) {