blob: 98b59be6906d85e1578090a7b2a0879dd5cfc916 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
global start
bits 32
; create the multiboot header
section .bootstrap.data
align 8
mb_start:
dd 0xe85250d6
dd 0
dd mb_end - mb_start
dd -(0xe85250d6 + (mb_end - mb_start))
dw 0
dw 0
dd 8
mb_end:
; create the stack for bootstrapping
section .bootstrap.bss
align 16
bootstrap_stack_start:
resb 1024 ; 1 KiB
bootstrap_stack_end:
; create the stack for the kernel
section .bss
align 16
stack_start:
resb 16384 ; 16 KiB
stack_end:
; load the kernel into the higher half
section .bootstrap.text
align 8
start:
; init bootstrap stack
mov esp, bootstrap_stack_end
mov ebp, bootstrap_stack_end
; load kernel into higher half and init paging
extern paging_init
call paging_init
jmp near load_kernel
; initalize kernel after it has been loaded in higher half
section .text
align 8
load_kernel:
; init stack
mov esp, stack_end
mov ebp, stack_end
; load global descripter table
extern load_gdt
call load_gdt
; unmap kernel at page 0
extern paging_finish
call paging_finish
; initalize the FPU
finit
; start kernel
sti
extern KERNEL_MAPPING
add ebx, KERNEL_MAPPING
push ebx
call kernel_main
extern kernel_main
; hlt forever if kernel quits (it should never)
cli
halt:
hlt
jmp halt
|