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 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/boot.S') 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. -- cgit v1.2.1