summaryrefslogtreecommitdiff
path: root/kernel/src/boot
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksav013@gmail.com>2022-08-08 19:50:11 +0200
committerAleksa Vuckovic <aleksav013@gmail.com>2022-08-08 19:50:11 +0200
commit0162997df4ae7769bd4fc055b2c03b473846d1f5 (patch)
treef6c40a64cbb15cf3fd102e5e8f15b48030e96f4e /kernel/src/boot
parent71396c5cd460890c52e348687e6e7c864e2dfeed (diff)
higher half
Diffstat (limited to 'kernel/src/boot')
-rw-r--r--kernel/src/boot/boot.S58
-rw-r--r--kernel/src/boot/multiboot2.c7
2 files changed, 49 insertions, 16 deletions
diff --git a/kernel/src/boot/boot.S b/kernel/src/boot/boot.S
index bf5251b..81584ce 100644
--- a/kernel/src/boot/boot.S
+++ b/kernel/src/boot/boot.S
@@ -1,12 +1,13 @@
+.code32
.global _start
.extern begin_long_mode
-.section .text
-.code32
+.set KERNEL_VMA, 0xc0000000
+.section .boot.text, "a"
_start:
cli
- mov $stack_top, %esp
+ mov $stack_top - KERNEL_VMA, %esp
pushl $0
pushl %eax
pushl $0
@@ -19,9 +20,9 @@ _start:
call setup_page_tables
call enable_paging
- lgdt gdt_pointer
- ljmp $0x08, $begin_long_mode
-
+ addl $KERNEL_VMA, %esp
+ mov $4f, %ecx
+ jmp *%ecx
check_multiboot:
cmp $0x36d76289, %eax
@@ -59,27 +60,46 @@ check_long_mode:
ret
setup_page_tables:
- mov $pt_lvl3, %eax
+ mov $pt_lvl3 - KERNEL_VMA, %eax
or $0x3, %eax
- mov %eax, pt_lvl4
+ mov %eax, pt_lvl4 - KERNEL_VMA
- // 0x00000000 - 0x00200000 : 0x00000000
- mov $pt_lvl2, %eax
+ // 0x00000000 - 0x00200000 : 0x00000000 - 0x00200000
+ mov $pt_lvl2 - KERNEL_VMA, %eax
or $0x3, %eax
- mov %eax, pt_lvl3
+ mov %eax, pt_lvl3 - KERNEL_VMA
- movl $0, %ecx
+ // 0xc0000000 - 0xc0200000 : 0xc0000000 - 0xc0200000
+ mov $pt_lvl2_hh - KERNEL_VMA, %eax
+ or $0x3, %eax
+ mov %eax, pt_lvl3 + 24 - KERNEL_VMA
+
+// first 2mb
+ xor %ecx, %ecx
1:
movl $0x00200000, %eax
mul %ecx
or $0b10000011, %eax
- movl $pt_lvl2, %edx
+ movl $pt_lvl2 - KERNEL_VMA, %edx
leal (%edx, %ecx, 8), %edx
movl %eax, (%edx)
inc %ecx
cmp $1, %ecx
jne 1b
+// first 2mb in higher_half
+ xor %ecx, %ecx
+2:
+ movl $0x00200000, %eax
+ mul %ecx
+ or $0b10000011, %eax
+ movl $pt_lvl2_hh - KERNEL_VMA, %edx
+ leal (%edx, %ecx, 8), %edx
+ movl %eax, (%edx)
+ inc %ecx
+ cmp $1, %ecx
+ jne 2b
+
ret
enable_paging:
@@ -95,7 +115,7 @@ enable_paging:
wrmsr
// pt_lvl4
- mov $pt_lvl4, %eax
+ mov $pt_lvl4 - KERNEL_VMA, %eax
mov %eax, %cr3
// enable paging (+ protected mode if not already enabled)
@@ -114,6 +134,11 @@ no_cpuid:
no_long_mode:
hlt
+.section .text
+4:
+ lgdt gdt_pointer
+ ljmp $0x08, $begin_long_mode
+
.section .bss
.align 4096
@@ -123,14 +148,17 @@ stack_bottom:
.skip 4096*4
stack_top:
+
// page tables
pt_lvl4:
.skip 4096
pt_lvl3:
.skip 4096
-// map first 4GB
pt_lvl2:
.skip 4096
+pt_lvl2_hh:
+ .skip 4096
+
// Access bits
.section .rodata
diff --git a/kernel/src/boot/multiboot2.c b/kernel/src/boot/multiboot2.c
index 2badae9..fd8a652 100644
--- a/kernel/src/boot/multiboot2.c
+++ b/kernel/src/boot/multiboot2.c
@@ -2,6 +2,10 @@
#include <multiboot2.h>
#include <graphics.h>
+#include <debug.h>
+
+
+#define KERNEL_VMA 0xc0000000
fb_t fb;
@@ -18,7 +22,8 @@ void init_fb(mb2_tag_header* multiboot_bootinfo, uint32_t multiboot_magic)
static mb2_tag_fb* tag_fb;
// skip first 8 bytes (total_size + reserved)
- mb2_tag_header* tag_header = multiboot_bootinfo + 1;
+ mb2_tag_header* tag_header = (mb2_tag_header*)((char*)multiboot_bootinfo + 8 + KERNEL_VMA);
+ bochs_breakpoint();
while (tag_header->type != MB2_TAG_END) {
// process tag_type