-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot.asm
More file actions
44 lines (36 loc) · 1.37 KB
/
boot.asm
File metadata and controls
44 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
; Multiboot header constants
MBALIGN equ 1 << 0 ; align loaded modules on page boundaries
MEMINFO equ 1 << 1 ; provide memory map
FLAGS equ MBALIGN | MEMINFO ; Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find header
CHECKSUM equ -(MAGIC + FLAGS) ; Checksum of above to prove we are multiboot
; Declaring a multiboot header to mark program as a kernel
section .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
; Create stack pointer register
section .bss
align 16
stack_bottom:
resb 16384 ; 16 KiB
stack_top:
section .text
global _start:function (_start.end - _start)
_start:
; Kernel now has full absolute control of the CPU
; Set ESP register to point to the top of the created stack (grows downward on x86) for C
mov esp, stack_top
; Initalize curcial processor state (TODO)
; Enter high-level kernel (C)
extern kmain
call kmain
; Infinite loop when computer has nothing to do
; 1) Disable interrupts with cli
; 2) Wait for next interrupt to arrive with hlt instruction (will lock up computer to it being disabled)
; 3) Jump to the hlt instruction if it ever wakes up due to a non-masklable interrupt occuring or due to system management mode.
cli
.hang: hlt
jmp .hang
.end: