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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
; multiboot header constants
MBALIGN equ 1 << 0
MEMINFO equ 1 << 1
MBFLAGS equ MBALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC+MBFLAGS)
; multiboot header
section .multiboot
align 4
dd MAGIC
dd MBFLAGS
dd CHECKSUM
section .data
%include "arch/i386/gdt.asm"
; defines the stack
section .bss
align 16
stack_bottom:
resb 16384 ; 16 KiB
stack_top:
; temporary paging tables
align 4
boot_page_directory:
resb 4096
boot_page_table:
resb 4096
section .text
global _start:function (_start.end - _start)
_start:
cli
; setup stack
mov esp, stack_top
; push the multiboot header data into the stack for later use
push eax
push ebx
; get multiboot header data (for memory map)
;extern multiboot_main
;call multiboot_main
;extern _init
;Scall _init
lgdt [gdt_descriptor]
jmp 0x08:.gdt_jmp
.gdt_jmp:
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp .gdt_jmp2
.gdt_jmp2:
; setup paging (to map kernel to the higher half)
;mov eax, 0
;mov cr3, eax
;mov eax, cr0
;or eax, 0x80000001
;mov cr0, eax
; setup idt
extern idt_setup
call idt_setup
extern idtr
lidt [idtr]
; initialize pic
push ebp
mov ebp, esp
mov ebx, 0x28
push ebx
mov ebx, 0x20
push ebx
extern pic_remap
call pic_remap
pop ebx
pop ebx
mov esp, ebp
pop ebp
sti
; enter the kernel
extern kernel_main
call kernel_main
; indefinite loop once system exits
;cli
.hang: hlt
jmp .hang
.end:
|