rk/multiboot.asm

87 lines
1.5 KiB
NASM
Raw Normal View History

2024-05-20 05:59:07 -04:00
%define MAGIC 0x1BADB002
%define FLAGS 0
; Multiboot v1 Specification
; https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
section .multiboot
align 4
dd MAGIC
dd FLAGS
dd -(MAGIC + FLAGS)
section .text
global _start
_start:
cli
; Check if EAX contains the multiboot magic number the bootloader is supposed to give us
cmp eax, 0x2BADB002
jne halt
lgdt [gdtp]
mov ax, 0x10 ; Offset to kernel data descriptor
mov es, ax
mov ds, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x8:.use_code_seg ; Offset to kernel code descriptor
.use_code_seg:
mov esp, stack_bottom
2024-05-21 22:07:04 -04:00
mov ebp, esp
2024-05-20 05:59:07 -04:00
push ebx
extern kmain
call kmain
; If the kernel function somehow returns, disable interrupts and hang
cli
halt:
hlt
jmp halt
2024-05-21 22:07:04 -04:00
global exception_handler
exception_handler:
add esp, 4
mov byte [0xb8000], 'X'
iret
global ps2_isr
ps2_isr:
extern ps2_handler
pushad
cld
call ps2_handler
popad
iret
2024-05-20 05:59:07 -04:00
; GDT for a flat memory layout
; We get access to all memory and can utilize paging
gdt_start:
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_start - 1
dd gdt_start
2024-05-21 22:07:04 -04:00
2024-05-20 05:59:07 -04:00
; Reserve 16KiB of kernel stack space
section .bss
2024-05-21 22:07:04 -04:00
align 16
2024-05-20 05:59:07 -04:00
stack_top:
resb 16384
stack_bottom: