Began rewrite

This commit is contained in:
2025-02-16 16:27:46 +01:00
parent 295e3d9c18
commit 7d41cf45ed
82 changed files with 99 additions and 3028 deletions
+27 -95
View File
@@ -1,108 +1,40 @@
;
; Kernel entry point
;
MBH_MAGIC equ 0xe85250d6
MBH_ARCH equ 0x00000000
STACK_SIZE equ 4096
global VIRT_BASE
KERN_VIRT_BASE equ 0xC000000
KERN_PAGE_NUM equ (KERN_VIRT_BASE >> 22)
bits 32
; Multiboot2 Header
; Flag bits
%define ALIGN 1<<0
%define MEMINFO 1<<1
; Field values
%define MAGIC 0x1BADB002
%define FLAGS (ALIGN | MEMINFO)
%define CHECK -(MAGIC + FLAGS)
; Multiboot 1 header
section .multiboot
align 64
mbh:
; Magic fields
.magic: dd MBH_MAGIC
.arch: dd MBH_ARCH
.size: dd (mbh.end - mbh)
.checksum: dd 0x10000000 - (MBH_MAGIC + MBH_ARCH + (mbh.end - mbh))
align 4
multiboot:
dd MAGIC
dd FLAGS
dd CHECK
; Framebuffer Tag
align 8
dw 5 ; Type - Framebuffer
dw 1 ; Flags - Optional
dd 20 ; Size
dd 1920 ; Width
dd 1080 ; Height
dd 32 ; Depth
; Zero Tag
align 8
dw 0 ; Type - Zero
dw 0 ; Flags
dd 8 ; Size
.end:
; Stack
; Initialize stack
section .bss
align 16
stack_bottom:
resb 16384*8
resb 16384 ; 16kB
stack_top:
; Entry section
section .boot
global start
extern kmain
start:
; Init temporary paging
mov eax, (initpd - 0xC0000000)
mov cr3, eax
mov ecx, cr4
or ecx, 0x10 ; Paging enable bit
mov cr4, ecx
mov ecx, cr0
or ecx, 0x8000000
mov cr0, ecx
jmp higher_half
Shutdown:
mov ax, 0x1000
mov ss, ax
mov sp, 0xf000
mov ax, 0x5307
mov bx, 0x0001
mov cx, 0x0003
int 0x15
; Entry point
section .text
higher_half:
mov esp, stack_top ; Stack Pointer
global _start
extern kmain
_start:
mov esp, stack_top
add ebx, KERN_VIRT_BASE ; Make address in EBX virtual
push ebx ; Push multiboot mem info pointer
call kmain ; Call kernel main
call kmain
; Halt on return
cli
h: hlt
jmp h
section .data
; Inital Page Directory
align 4096
global initpd
initpd:
dd 0b10000011 ; Initial 4MB identity map
times 768-1 dd 0 ; Padding
; Higher half kernel start, map 16MB
dd (0 << 22) | 0b10000011
dd (1 << 22) | 0b10000011
dd (2 << 22) | 0b10000011
dd (3 << 22) | 0b10000011
times 256-4 dd 0 ; More padding
; Hang if kernel returns
cli
.hlt: hlt
jmp .hlt