hazel/kernel/init.asm

73 lines
1.1 KiB
NASM
Raw Normal View History

2024-06-25 21:43:07 -04:00
%define MAGIC 0x1BADB002
%define FLAGS 0x0
2024-06-25 15:28:44 -04:00
section .multiboot
dd MAGIC
2024-06-25 21:43:07 -04:00
dd FLAGS
dd -(MAGIC + FLAGS)
2024-06-25 15:28:44 -04:00
section .text
global _start
_start:
2024-06-27 14:49:11 -04:00
cli
2024-06-25 15:28:44 -04:00
2024-06-27 14:49:11 -04:00
; Check if EAX contains this magic value that our bootloader should've set
cmp eax, 0x2BADB002
jne halt
2024-06-25 22:47:21 -04:00
2024-06-27 14:49:11 -04:00
; Load GDT
2024-06-25 22:47:21 -04:00
lgdt [gdtp]
; Offset to kernel data descriptor
mov ax, 0x10
mov es, ax
mov ds, ax
mov fs, ax
mov gs, ax
mov ss, ax
2024-06-27 14:49:11 -04:00
; Offset to kernel code descriptor
2024-06-25 22:47:21 -04:00
jmp 0x8:.use_code_seg
.use_code_seg:
mov esp, stack_bottom
mov ebp, esp
push ebx
2024-06-27 14:49:11 -04:00
and esp, 0xfffffff0
2024-06-25 22:47:21 -04:00
extern kernel
call kernel
2024-06-27 14:49:11 -04:00
cli
2024-06-25 22:47:21 -04:00
halt:
2024-06-27 14:49:11 -04:00
hlt
jmp halt
2024-06-25 22:47:21 -04:00
section .data
; GDT for a flat memory layout
; We get access to all memory and can utilize paging
global gdt
gdt:
gdt_null:
dq 0
gdt_kern_code:
dw 0xffff
dw 0x0000
db 0x00
db 0b10011010
db 0b11001111
db 0x00
gdt_kern_data:
dw 0xffff
dw 0x0000
db 0x00
db 0b10010010
db 0b11001111
db 0x00
gdt_end:
gdtp:
dw gdt_end - gdt - 1
dd gdt
section .bss
align 16
stack_top:
2024-06-27 14:49:11 -04:00
resb 16384
2024-06-25 22:47:21 -04:00
stack_bottom: