From e093bdeb10ec79a5e22a9a792c098e876ed91a63 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 11 Mar 2021 11:42:29 +0200 Subject: Add linker script to ld depends --- src/boot.S | 19 +++++++++++-------- src/kernel.cc | 2 +- src/kernel/dump_multiboot.cc | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src') 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(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(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: { -- cgit v1.2.1