hazel/kernel/init.asm

86 lines
1.3 KiB
NASM

%define MAGIC 0x1BADB002
%define ALIGN 1<<0
%define MMAP 1<<1
%define VID 1<<2
%define FLAGS (ALIGN | MMAP | VID)
section .multiboot
dd MAGIC
dd FLAGS
dd -(MAGIC + FLAGS)
dd 0 ; header_addr
dd 0 ; load_addr
dd 0 ; load_end_addr
dd 0 ; bss_end_addr
dd 0 ; entry_addr
dd 1 ; mode_type
dd 80 ; width
dd 25 ; height
dd 0 ; depth
section .text
global _start
_start:
cli
; Check if EAX contains this magic value that our bootloader should've set
cmp eax, 0x2BADB002
jne halt
; Load GDT
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
; Offset to kernel code descriptor
jmp 0x8:.use_code_seg
.use_code_seg:
mov esp, stack_bottom
mov ebp, esp
push ebx
and esp, 0xfffffff0
extern kernel
call kernel
cli
halt:
hlt
jmp halt
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:
resb 16384
stack_bottom: