StupidOS/kernel/kernel.asm

157 lines
2.3 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
2024-09-10 08:03:32 +00:00
;; Kernel entry point
2024-04-28 06:41:36 +00:00
;;
2024-09-10 08:03:32 +00:00
;; In:
2024-04-28 06:41:36 +00:00
;;
;; 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
2024-09-10 08:03:32 +00:00
mov edi, stBootInfo
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-07-21 16:14:38 +00:00
mov esi, szMsgBuildDate
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
2024-09-10 08:03:32 +00:00
mov ebx, [stBootInfo.high_mem]
add ebx, KERNEL_VIRT_BASE
call pmm_free_range
2024-09-10 08:03:32 +00:00
;mov eax, [stBootInfo.low_mem]
2024-07-19 07:53:03 +00:00
;call heap_init
2024-07-18 09:28:07 +00:00
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-18 10:36:43 +00:00
call tss_flush
2024-07-12 06:58:25 +00:00
2024-07-13 07:43:27 +00:00
call idt_setup
2024-07-28 09:09:24 +00:00
mov ax, 100 ; 100Hz
2024-07-14 13:11:28 +00:00
call pit_init
2024-07-23 05:50:35 +00:00
call bio_init
2024-07-21 16:14:38 +00:00
call proc_init
2024-07-16 07:52:08 +00:00
call dev_init
2024-07-16 06:29:16 +00:00
call vfs_init
2024-09-11 13:52:55 +00:00
; Root inode
; rootino = newino(dev(0.0), BLK)
; fs_mountroot(rootino);
2024-09-10 08:03:32 +00:00
mov ah, 2
call bio_bread
2024-09-11 13:52:55 +00:00
xor eax, eax
call bio_bread
;mov eax, SYSCALL_EXIT
;int 0x42
2024-07-14 13:11:28 +00:00
2024-07-15 06:32:59 +00:00
;mov al, 'X'
;call cga_putc
2024-05-02 11:34:27 +00:00
.halt:
2024-07-21 16:14:38 +00:00
; hlt
2024-05-02 11:34:27 +00:00
jmp $
.error_magic:
mov esi, szErrorBootProtocol
.error:
call klog
jmp .halt
2024-03-20 15:51:27 +00:00
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-19 07:53:03 +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-19 07:53:03 +00:00
include 'proc.inc'
2024-07-23 05:50:35 +00:00
include 'bio.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
2024-07-21 16:14:38 +00:00
szMsgBuildDate db "Built ", BUILD_DATE, 0
szErrorBootProtocol db "Error: wrong magic number", 0
2024-03-20 15:51:27 +00:00
2024-09-10 08:03:32 +00:00
;; Variable: stBootInfo
;; <BootInfo>
stBootInfo BootInfo
2024-07-13 17:02:35 +00:00
kTSS TSS
2024-07-23 05:50:35 +00:00
align 4096
2024-07-19 07:53:03 +00:00
aProcs rb 64*sizeof.Process
2024-07-23 05:50:35 +00:00
align 4096
aBuffers rb 30*sizeof.Buffer
2024-07-19 07:53:03 +00:00
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: