StupidOS/kernel/kernel.asm

94 lines
1.4 KiB
NASM
Raw Normal View History

2024-03-26 07:39:40 +00:00
;; File: kernel.asm
2024-07-05 12:23:58 +00:00
format binary
2024-03-26 07:39:40 +00:00
include 'const.inc'
2024-03-20 15:51:27 +00:00
2024-03-26 07:39:40 +00:00
org KBASE
use32
2024-03-20 15:51:27 +00:00
2024-05-28 04:54:10 +00:00
jmp short kmain
db 'STPDKRNL'
db 32 dup(0)
2024-03-20 15:51:27 +00:00
2024-04-28 06:41:36 +00:00
;; Function: kmain
;;
;; Parameters:
;;
;; EAX - Boot Magic
;; EBX - Boot structure address
;;
2024-03-20 15:51:27 +00:00
kmain:
2024-07-05 12:23:58 +00:00
mov esp, stack_top
2024-05-02 11:34:27 +00:00
cmp eax, STPDBOOT_MAGIC
jne .error_magic
2024-05-02 11:34:27 +00:00
; Copy boot structure
mov ecx, sizeof.BootInfo
mov esi, ebx
mov edi, boot_structure
rep movsb
2024-07-05 12:23:58 +00:00
; print hello world
2024-07-08 16:48:31 +00:00
mov [0xC00B8000], dword 0x08740953
mov [0xC00B8004], dword 0x05700675
mov [0xC00B8008], dword 0x03640469
mov [0xC00B800C], dword 0x0153024F
2024-07-05 12:23:58 +00:00
mov esi, szMsgKernelAlive
call klog
2024-05-02 11:34:27 +00:00
2024-07-08 16:48:31 +00:00
; init pmm (kend, 0x400000)
mov eax, kend
2024-07-08 16:48:31 +00:00
mov ebx, 0xC0400000
call pmm_init
; init vmm
call mm_init
mov eax, 0xC0400000
mov ebx, [boot_structure.high_mem]
add ebx, KERNEL_VIRT_BASE
call pmm_free_range
2024-07-12 06:58:25 +00:00
; load kernel gdt
lgdt [pGDT]
; I don't think i need to reload segment cuz their value are already correct
2024-07-13 08:17:36 +00:00
xchg bx, bx
call pic_disable
2024-07-13 07:43:27 +00:00
call idt_setup
2024-05-02 11:34:27 +00:00
.halt:
hlt
jmp $
.error_magic:
mov esi, szErrorBootProtocol
.error:
call klog
jmp .halt
2024-03-20 15:51:27 +00:00
2024-07-07 13:48:22 +00:00
include 'sys/bootinfo.inc'
2024-07-05 12:23:58 +00:00
include 'klog.inc'
include 'dev/vga_console.inc'
include 'mm/mm.inc'
2024-07-10 10:56:53 +00:00
include 'lock.inc'
2024-07-12 06:58:25 +00:00
include 'gdt.inc'
2024-07-13 07:43:27 +00:00
include 'isr.inc'
2024-07-13 08:17:36 +00:00
include 'pic.inc'
2024-07-05 12:23:58 +00:00
szMsgKernelAlive db "Kernel is alive", 0
szErrorBootProtocol db "Error: wrong magic number", 0
2024-03-20 15:51:27 +00:00
boot_structure BootInfo
align 4096
2024-07-05 12:23:58 +00:00
stack_bottom:
2024-03-20 15:51:27 +00:00
rb 0x4000
2024-07-05 12:23:58 +00:00
stack_top:
2024-03-20 15:51:27 +00:00
kend: