feat: initial paging setup

This commit is contained in:
2021-08-06 20:46:44 +02:00
parent 8152ad6e9a
commit f0cc2c73b7
15 changed files with 257 additions and 114 deletions

View File

@@ -19,7 +19,7 @@ forced to be within the first 8 KiB of the kernel file.
.long CHECKSUM
#.include "gdt.S"
.section .data
.section .boot.data, "aw", @progbits
gdt:
.quad 0x0000000000000000
.quad 0x00CF9A000000FFFF
@@ -42,7 +42,7 @@ 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.
*/
.section .bss
.section .boot.bss, "aw", @nobits
.align 16
stack_bottom:
.skip 16384 # 16 KiB
@@ -53,7 +53,10 @@ The linker script specifies _start as the entry point to the kernel and the
bootloader will jump to this position once the kernel has been loaded. It
doesn't make sense to return from this function as the bootloader is gone.
*/
.section .text
.section .boot.text, "ax", @progbits
.extern _boot_paging
.global _start
.type _start, @function
_start:
@@ -77,6 +80,8 @@ _start:
*/
mov $stack_top, %esp
call _boot_paging
// store multiboot on stack
pushl 0
pushl %eax // MB code
@@ -101,6 +106,13 @@ _start:
movw %ax,%gs
ljmp $0x8, $continue_boot
/*
Set the size of the _start symbol to the current location '.' minus its start.
This is useful when debugging or when you implement call tracing.
*/
.size _start, . - _start
.section .text
continue_boot:
sti
/*
@@ -129,9 +141,3 @@ continue_boot:
cli
1: #hlt
jmp 1b
/*
Set the size of the _start symbol to the current location '.' minus its start.
This is useful when debugging or when you implement call tracing.
*/
.size _start, . - _start

51
boot/bootpaging.S Normal file
View File

@@ -0,0 +1,51 @@
.code32
.extern boot_paging_directory
.extern boot_primary_table
.section .boot.text, "ax", @progbits
.global _boot_paging
.type _boot_paging, @function
_boot_paging:
push %ebp
mov %esp, %ebp
pusha
# Physical address of paging table 1
# movl $(boot_primary_table - 0xC0000000), %edi
movl $(boot_primary_table - 0xC0000000), %edi
movl $0, %esi
movl $1024, %ecx
cmpl %esi, %ecx
_boot_paging_loop:
# stop when after kernel's last address
# cmpl $(_kernel_end -0xC0000000), %esi
cmpl $(_kernel_end), %esi
jge _boot_paging_after_kernel
# make address present and writable
movl %esi, %edx
orl $0x003, %edx
movl %edx, (%edi)
# next address
addl $4096, %esi
addl $4, %edi
loop _boot_paging_loop
_boot_paging_after_kernel:
# write to directory
movl $(boot_primary_table - 0xC0000000 + 0x003), boot_paging_directory - 0xC0000000 + 0
movl $(boot_primary_table - 0xC0000000 + 0x003), boot_paging_directory - 0xC0000000 + 768 * 4
# write paging directory to cr3
movl $(boot_paging_directory - 0xC0000000), %ecx
movl %ecx, %cr3
# enable paging and write protect in cr0
movl %cr0, %ecx
orl $0x80010000, %ecx
movl %ecx, %cr0
_boot_pagin_end:
popa
pop %ebp
ret