#include "multiboot2.hpp"
-.set KERNEL_VMA, 0# 0xFFFFFFFF80000000
+.set KERNEL_VMA, 0xFFFFFFFF80000000
.section .multiboot_header
multiboot_header_start:
.int 0x00CF8900
GDT.PTR:
.short . - GDT - 1
- .quad GDT
+ .quad GDT - KERNEL_VMA
.section .bss
.align 0x1000
-PML4T: .skip 0x1000
-PDPT: .skip 0x1000
-PDT: .skip 0x1000
-PT: .skip 0x1000
+PML4T: .skip 0x1000
+PDPT_low: .skip 0x1000
+PDPT_high: .skip 0x1000
+PDT: .skip 0x1000
+PT: .skip 0x1000
.align 16
stack_bottom:
.skip 1024 * 16 # 16KiB
.code32
.globl _start
_start:
- mov $stack_top, %esp
+ mov $stack_top - KERNEL_VMA, %esp
# Check if cpuid is supported:
pushfl
mov %eax, %cr0
# Setup 64-bit paging:
- mov $PML4T, %eax
+ mov $PML4T - KERNEL_VMA, %eax
mov %eax, %cr3
- mov $PDPT + 3, %eax
- mov %eax, PML4T + 0 * 8
- mov $PDT + 3, %eax
- mov %eax, PDPT + 0 * 8
- mov $PT + 3, %eax
- mov %eax, PDT + 0 * 8
+ mov $PDPT_low - KERNEL_VMA + 3, %eax
+ mov %eax, PML4T - KERNEL_VMA + 0 * 8
+ mov $PDPT_high - KERNEL_VMA + 3, %eax
+ mov %eax, PML4T - KERNEL_VMA + 511 * 8
+ mov $PDT - KERNEL_VMA + 3, %eax
+ mov %eax, PDPT_low - KERNEL_VMA + 0 * 8
+ mov %eax, PDPT_high - KERNEL_VMA + 510 * 8
+ mov $PT - KERNEL_VMA + 3, %eax
+ mov %eax, PDT - KERNEL_VMA + 0 * 8
- mov $PT, %edi
+ mov $PT - KERNEL_VMA, %edi
mov $0x0003, %ebx
mov $512, %ecx
1: mov %ebx, (%edi)
mov %eax, %cr0
# Jump to 64 bits:
- lgdt (GDT.PTR)
+ lgdt (GDT.PTR - KERNEL_VMA)
jmp $GDT.CODE, $.trampoline
.code64
mov $.higher_half, %rax
jmp *%rax
+.section .text
.higher_half:
- movw $0x024F, 0xB8000
- movw $0x026B, 0xB8002
- movw $0x022E, 0xB8004
call kmain
- cli
-1: hlt
- jmp 1b
#include "multiboot2.hpp"
extern "C" void kmain() {
- // volatile short* vga_text = reinterpret_cast<volatile short*>((void*)0xFFFFFFFF800B8000);
- volatile short* vga_text = reinterpret_cast<volatile short*>((void*)0xB8000);
+ volatile short* vga_text = reinterpret_cast<volatile short*>((void*)0xFFFFFFFF800B8000);
const char* str = "Success ! Took me long enough.";
for (unsigned long i = 0; str[i] != '\0'; i++) {
vga_text[i] = (0x02 << 8) + str[i];