aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-21 22:14:12 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-21 22:14:12 +0200
commitd4405dfb012ca70c06dfc3217265e4e9cd01b68a (patch)
tree76a99805e7a0f948bd885c89b219db13240efebd
parentCheck multiboot2 header length, and if needed map the next page as well (diff)
downloadkernel.cpp-d4405dfb012ca70c06dfc3217265e4e9cd01b68a.tar.xz
Place bootstrap code into multiboot section
-rw-r--r--linker.ld5
-rw-r--r--makefile2
-rw-r--r--src/boot.S15
3 files changed, 19 insertions, 3 deletions
diff --git a/linker.ld b/linker.ld
index f7010e7..8eba287 100644
--- a/linker.ld
+++ b/linker.ld
@@ -12,7 +12,11 @@ SECTIONS
. = 0;
.multiboot : {
. = ALIGN(8);
+ begin_multiboot = .;
KEEP(*(.multiboot.header))
+ *(.multiboot.text)
+ *(.multiboot.pages))
+ end_multiboot = .;
}
/* Begin putting sections at 4 MiB */
@@ -20,7 +24,6 @@ SECTIONS
.text ALIGN(4K) : AT(ADDR(.text) - VADDR_BASE + 4M) {
begin_text = .;
- *(.multiboot.text)
*(.text*)
end_text = .;
}
diff --git a/makefile b/makefile
index 7eecced..6e44faf 100644
--- a/makefile
+++ b/makefile
@@ -3,7 +3,7 @@ OBJ_DIR != echo $(CONFIG_OBJ_DIR)
include toolchain.makefile
.PHONY: default clean test todo run menuconfig
-default: $(OBJ_DIR)/glitch.elf
+all: $(OBJ_DIR)/glitch.elf
include libk/makefile
include src/makefile
diff --git a/src/boot.S b/src/boot.S
index 3a07c19..976a6f4 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -34,6 +34,11 @@ module_tag_end:
.int 8
header_end:
+.section .multiboot.pages, "aw", @nobits
+.align 4096
+bootstrap_page0:
+ .skip 1024 * 4
+
/* The stack on x86 must be 16-byte aligned according to the System V ABI standard and de-facto extensions. The
* compiler will assume the stack is properly aligned and failure to align the stack will result in undefined
* behavior.
@@ -60,7 +65,7 @@ kernel_ptable0:
*/
.section .multiboot.text, "ax"
.global VADDR_OFFSET
- .set VADDR_OFFSET, 0xc0000000 - 0x400000
+.set VADDR_OFFSET, 0
.macro map begin, end, access
mov $\begin - VADDR_OFFSET, %esi
@@ -83,6 +88,12 @@ kernel_ptable0:
_start:
cli
+ movl $bootstrap_page0, %edi
+ movl $1024, %ecx
+ map begin_multiboot, end_multiboot, 0x003
+
+.set VADDR_OFFSET, 0xc0000000 - 0x400000
+
# Physical address of kernel_ptable0.
movl $(kernel_ptable0 - VADDR_OFFSET), %edi
# Map 1024 pages
@@ -98,6 +109,7 @@ _start:
# Use the page table at:
# - entry 1 starts 0x0040 0000 ends 0x007f ffff
# - entry 768 starts 0xc000 0000 ends 0xc03f ffff
+ movl $(bootstrap_page0 + 0x003), kernel_pagedir - VADDR_OFFSET + 0 * 4
movl $(kernel_ptable0 - VADDR_OFFSET + 0x003), kernel_pagedir - VADDR_OFFSET + 1 * 4
movl $(kernel_ptable0 - VADDR_OFFSET + 0x003), kernel_pagedir - VADDR_OFFSET + 768 * 4
@@ -120,6 +132,7 @@ _start:
kinit:
# At this point, paging is fully set up and enabled.
# Unmap the identity mapping as it is now unnecessary.
+ movl $0, kernel_pagedir + 0 * 4
movl $0, kernel_pagedir + 1 * 4
# Reload crc3 to force a TLB flush so the changes to take effect.
movl %cr3, %ecx