aboutsummaryrefslogtreecommitdiff
path: root/defs
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@mailbox.org>2024-06-04 17:50:10 +0200
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:17:12 +0200
commit4bce609d2a0145e70f44227636a68348e9b23cf9 (patch)
tree8c753a99644172f0fd3bb5d382ae1b7790b137e6 /defs
parentf4b50dd826b81295dc9628b655fc5f360445230b (diff)
mm: fully map the kernel to high memory
Diffstat (limited to 'defs')
-rw-r--r--defs/x86_64-hm-linker.ld119
1 files changed, 119 insertions, 0 deletions
diff --git a/defs/x86_64-hm-linker.ld b/defs/x86_64-hm-linker.ld
new file mode 100644
index 0000000..2b12539
--- /dev/null
+++ b/defs/x86_64-hm-linker.ld
@@ -0,0 +1,119 @@
+
+/* defs for Multiboot headers */
+/* https://www.gnu.org/software/grub/manual/multiboot/multiboot.txt */
+MB_MAGIC = 0x1badb002;
+/* bit 0
+ * all boot modules loaded along with the operating system must be
+ * aligned on page (4KB) bit 1 must include mem_* structures
+ */
+MB_FLAGS = 0x3;
+MB_CHKSUM = 0x100000000 - (MB_MAGIC + MB_FLAGS);
+
+PROVIDE(KERNEL_OFFSET = 0xffff800000000000);
+
+SECTIONS
+{
+ . = 0x100000;
+ PROVIDE (___KERNEL_PM_START__ = . );
+ .boot :
+ {
+ header_start = .;
+ LONG(MB_MAGIC)
+ LONG(MB_FLAGS)
+ LONG(MB_CHKSUM)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ LONG(0)
+ header_end = .;
+ }
+
+
+ .d32 :
+ {
+ *(".data32")
+ }
+
+ .reserved :
+ {
+ *(".reserved")
+ *(".reserved.*")
+ *(".gdt")
+ }
+
+ /*
+ * basically the same as BSS, but I want some flexibility and I don't care
+ * for zeroing because it's explicitly overwritten anyways. I KNOW WHAT I'M
+ * DOING! An example is the idt.
+ */
+ .reserved_0 (NOLOAD) :
+ {
+ *(".init_k_stack")
+ *(".reserved_0")
+ *(".reserved_0.*")
+ *(".reserved_0.init_stack")
+ }
+
+
+ /* global page table for 64-bit long mode */
+ .global_pagetable ALIGN(4096) (NOLOAD) :
+ {
+ *(".global_pagetable")
+ }
+
+ . = ALIGN(4096);
+ /* reserve space for a premitive stack based physical frame allocator */
+ /* each frame is 4KiB in size and has a 64bit (physical) address. e.g. */
+ /* for every 1 GiB physical memory we need 2 MiB space reserved for the */
+ /* free stack. For a easier bootstraping we are using a fix-sized stack */
+ /* array. Currently using 4GiB, therefore reserve 8MiB. */
+ PROVIDE (___FREE_PAGE_STACK__ = .);
+ .global_free_page_stack ALIGN(4096) (NOLOAD) :
+ {
+ *("..global_free_page_stack")
+ }
+ . = ALIGN(4096);
+
+ .t32 :
+ {
+ *(".text32")
+ *(".text.interrupt_gate")
+ }
+
+ . = . + KERNEL_OFFSET;
+ .text : AT(ADDR(.text) - KERNEL_OFFSET)
+ {
+ *(".text")
+ *(".text.*")
+ *(".text$")
+ }
+
+ .data : AT(ADDR(.data) - KERNEL_OFFSET)
+ {
+ *(".data")
+ *(".data.*")
+ *(".data$")
+ }
+
+ .bss : AT(ADDR(.bss) - KERNEL_OFFSET)
+ {
+ PROVIDE (___BSS_PM_START__ = .);
+ *(".bss")
+ *(".bss.*")
+ PROVIDE (___BSS_PM_END__ = .);
+ }
+
+ .rodata : AT(ADDR(.rodata) - KERNEL_OFFSET)
+ {
+ *(".rodata")
+ *(".rodata$")
+ *(".rodata.*")
+ }
+
+ PROVIDE (___KERNEL_PM_END__ = . - KERNEL_OFFSET);
+}