aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-11 11:42:29 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-11 11:42:29 +0200
commite093bdeb10ec79a5e22a9a792c098e876ed91a63 (patch)
tree06211324ae53c7a959dad8afb99f13e8c48463f5
parentvmm: display segment map info (diff)
downloadkernel.cpp-e093bdeb10ec79a5e22a9a792c098e876ed91a63.tar.xz
Add linker script to ld depends
-rw-r--r--linker.ld5
-rw-r--r--makefile4
-rw-r--r--src/boot.S19
-rw-r--r--src/kernel.cc2
-rw-r--r--src/kernel/dump_multiboot.cc4
-rw-r--r--toolchain.makefile2
6 files changed, 21 insertions, 15 deletions
diff --git a/linker.ld b/linker.ld
index e9f1d73..9383b44 100644
--- a/linker.ld
+++ b/linker.ld
@@ -10,17 +10,18 @@ SECTIONS
* early in the image or the bootloader won't recognize the file format.
*/
. = 0;
- _kernel_start = .;
.multiboot : {
*(.multiboot.header)
- *(.multiboot.text)
}
/* Begin putting sections at 1 MiB */
+ /* TODO load sections at VADDR_BASE rather than at VADDR_BASE + 1M */
. = VADDR_BASE + 1M;
+ _kernel_start = .;
.text ALIGN(4K) : AT(ADDR(.text) - VADDR_BASE) {
begin_text = .;
+ *(.multiboot.text)
*(.text*)
end_text = .;
}
diff --git a/makefile b/makefile
index dd65197..ab3a513 100644
--- a/makefile
+++ b/makefile
@@ -16,9 +16,9 @@ CXX_TEST_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_TEST_OBJ))
CXX_INCLUDE := $(addprefix -I, $(CXX_INCLUDE))
CXX_SYSTEM_INCLUDE := $(addprefix -isystem, $(CXX_SYSTEM_INCLUDE))
-$(OBJ_DIR)/glitch.elf: $(autogen) $(AS_OBJ) $(CXX_OBJ)
+$(OBJ_DIR)/glitch.elf: $(autogen) $(AS_OBJ) $(CXX_OBJ) linker.ld
@echo " LD $@"
- @$(LD) $(LD_FLAGS) -o $@ $(AS_OBJ) $(CXX_OBJ)
+ @$(LD) $(LD_FLAGS) -o $@ $(AS_OBJ) $(CXX_OBJ) -T $(CURDIR)/linker.ld
$(AS_OBJ): $(OBJ_DIR)/%.o: %.S
@mkdir -p $(@D)
diff --git a/src/boot.S b/src/boot.S
index e5686c8..23c1e25 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -49,11 +49,14 @@ boot_page_table1:
bootloader will jump to this position once the kernel has been loaded.
*/
.section .multiboot.text, "ax"
+.set VADDR_BASE, 0xc0000000
.global _start
.type _start, @function
_start:
+ cli
+
# Physical address of boot_page_table1.
- movl $(boot_page_table1 - 0xC0000000), %edi
+ movl $(boot_page_table1 - VADDR_BASE), %edi
# First address to map is address 0.
movl $0, %esi
# Map 1023 pages. The 1024th will be the VGA text buffer.
@@ -63,7 +66,7 @@ _start:
# Only map the kernel.
cmpl $_kernel_start, %esi
jl 2f
- cmpl $(_kernel_end - 0xC0000000), %esi
+ cmpl $(_kernel_end - VADDR_BASE), %esi
jge 3f
# Map physical address as "present, writable". Note that this maps
@@ -82,21 +85,21 @@ _start:
3:
# Map VGA video memory to 0xC03FF000 as "present, writable".
- movl $(0x000B8000 | 0x003), boot_page_table1 - 0xC0000000 + 1023 * 4
+ movl $(0x000B8000 | 0x003), boot_page_table1 - VADDR_BASE + 1023 * 4
# The page table is used at both page directory entry 0 (virtually from 0x0
# to 0x3FFFFF) (thus identity mapping the kernel) and page directory entry
- # 768 (virtually from 0xC0000000 to 0xC03FFFFF) (thus mapping it in the
+ # 768 (virtually from VADDR_BASE to 0xC03FFFFF) (thus mapping it in the
# higher half). The kernel is identity mapped because enabling paging does
# not change the next instruction, which continues to be physical. The CPU
# would instead page fault if there was no identity mapping.
- # Map the page table to both virtual addresses 0x00000000 and 0xC0000000.
- movl $(boot_page_table1 - 0xC0000000 + 0x003), boot_page_directory - 0xC0000000 + 0
- movl $(boot_page_table1 - 0xC0000000 + 0x003), boot_page_directory - 0xC0000000 + 768 * 4
+ # Map the page table to both virtual addresses 0x00000000 and VADDR_BASE.
+ movl $(boot_page_table1 - VADDR_BASE + 0x003), boot_page_directory - VADDR_BASE + 0
+ movl $(boot_page_table1 - VADDR_BASE + 0x003), boot_page_directory - VADDR_BASE + 768 * 4
# Set cr3 to the address of the boot_page_directory.
- movl $(boot_page_directory - 0xC0000000), %ecx
+ movl $(boot_page_directory - VADDR_BASE), %ecx
movl %ecx, %cr3
# Enable paging and the write-protect bit.
diff --git a/src/kernel.cc b/src/kernel.cc
index 98c3a1a..b7aae2f 100644
--- a/src/kernel.cc
+++ b/src/kernel.cc
@@ -37,7 +37,7 @@ void kernel_main([[maybe_unused]] uint32_t mb_magic, [[maybe_unused]] uint32_t m
printk("Hello, kernel World!\n");
dump_address();
- // dump_multiboot(mb_magic, mb_addr + 0xc0000000);
+ dump_multiboot(mb_magic, mb_addr);
// dump_gdt();
GDT gdt;
diff --git a/src/kernel/dump_multiboot.cc b/src/kernel/dump_multiboot.cc
index 219d64f..35c2874 100644
--- a/src/kernel/dump_multiboot.cc
+++ b/src/kernel/dump_multiboot.cc
@@ -5,6 +5,8 @@ extern "C" void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr) {
printk("multiboot magic: ", uhex{mb_magic}, mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC ? " valid" : " invalid", '\n');
printk("multiboot addr: ", uhex{mb_addr}, !(mb_addr & 7) ? " is aligned" : " is not aligned", '\n');
+ return;
+
struct multiboot_tag* tag;
const uint32_t size = *reinterpret_cast<uint32_t*>(mb_addr);
printk("Announced mbi size ", size, '\n');
@@ -24,7 +26,7 @@ extern "C" void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr) {
case MULTIBOOT_TAG_TYPE_BOOTDEV: {
auto* t = reinterpret_cast<multiboot_tag_bootdev*>(tag);
- printk("Boot device ", uhex{t->biosdev}, " slice ", t->slice, " part ", t->part, '\n');
+ printk("Boot device ", uhex{t->biosdev}, " slice ", uhex{t->slice}, " part ", uhex{t->part}, '\n');
} break;
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: {
diff --git a/toolchain.makefile b/toolchain.makefile
index aa13852..c3ac2d8 100644
--- a/toolchain.makefile
+++ b/toolchain.makefile
@@ -8,7 +8,7 @@ AS := clang
AS_FLAGS :=
LD := ld.lld
-LD_FLAGS := -T linker.ld
+LD_FLAGS :=
CXX := clang++
TEST_CXX := clang++