StupidOS/kernel/kernel.asm

133 lines
2 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-07-16 06:29:16 +00:00
include 'sys/macro.inc'
2024-07-13 17:02:35 +00:00
include 'sys/bootinfo.inc'
include 'sys/cpu.inc'
2024-07-17 07:41:36 +00:00
include 'sys/errno.inc'
2024-07-18 09:28:07 +00:00
include 'sys/process.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
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-18 09:28:07 +00:00
mov eax, [boot_structure.low_mem]
call heap_init
2024-07-13 17:02:35 +00:00
call pic_init
2024-07-17 08:08:43 +00:00
; clear tss
mov ecx, sizeof.TSS
xor ax, ax
mov edi, kTSS
rep movsb
mov cx, 0xdfff
mov eax, kTSS
mov [eax + TSS.iomap], cx
call gdt_set_tss
call gdt_flush
2024-07-12 06:58:25 +00:00
2024-07-13 07:43:27 +00:00
call idt_setup
2024-07-14 13:11:28 +00:00
call pit_init
2024-07-16 07:52:08 +00:00
call dev_init
2024-07-16 06:29:16 +00:00
call vfs_init
2024-07-14 13:11:28 +00:00
mov eax, SYSCALL_EXIT
int 0x42
2024-07-15 06:32:59 +00:00
;mov al, 'X'
;call cga_putc
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-16 06:29:16 +00:00
include 'dev/at/cmos.inc'
include 'dev/at/pit.inc'
include 'dev/at/kbd.inc'
include 'dev/at/cga.inc'
include 'dev/at/floppy.inc'
2024-07-05 12:23:58 +00:00
include 'klog.inc'
2024-07-14 16:48:36 +00:00
include 'dev/console.inc'
2024-07-16 07:52:08 +00:00
include 'dev/dev.inc'
2024-07-05 12:23:58 +00:00
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 17:02:35 +00:00
include 'syscall.inc'
2024-07-13 07:43:27 +00:00
include 'isr.inc'
2024-07-14 13:11:28 +00:00
include 'idt.inc'
2024-07-13 08:17:36 +00:00
include 'pic.inc'
2024-07-18 09:28:07 +00:00
include 'heap.inc'
2024-07-16 06:29:16 +00:00
include 'vfs.inc'
include 'fs/fat.inc'
include 'fs/stpdfs.inc'
include 'fs/xv6fs.inc'
2024-07-05 12:23:58 +00:00
2024-07-13 17:02:35 +00:00
2024-07-14 09:22:43 +00:00
szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0
szErrorBootProtocol db "Error: wrong magic number", 0
2024-03-20 15:51:27 +00:00
boot_structure BootInfo
2024-07-13 17:02:35 +00:00
kTSS TSS
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: