forked from FedorLap2006/DepthOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.asm
98 lines (70 loc) · 1.76 KB
/
loader.asm
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
; GRUB MULTIBOOT 1
MAGIC equ 0x1BADB002 ; multiboot 2 - 0xe85250d6 ; multiboot 1 - 0x1BADB002
; ARCH equ 0 ; i386
MEMINFO equ 1<<1
MBALIGN equ 1<<0
FLAGS equ 0 | MBALIGN | MEMINFO
HLEN equ __boot_header_end - __boot_header
CHECKSUM equ 0x100000000 - (MAGIC + FLAGS + HLEN)
STACK_SIZE equ 100000 ;4096 * 1024 * 1024 + 400 ;1048600
; mem
VM_BASE equ 0xC0000000
PDE_INDEX equ (VM_BASE >> 22)
PSE_BIT equ 0x00000010
PG_BIT equ 0x80000000
bits 32
section .bss
align 4
stack_end:
resb STACK_SIZE
stack_top:
section .boot
align 4
__boot_header:
dd MAGIC
; dd ARCH
dd FLAGS
dd -(MAGIC + FLAGS)
dd HLEN
dd CHECKSUM
; dw 0
; dw 0
; dd 8
__boot_header_end:
section .text
global TEMP_PG_DIR
align 4096
TEMP_PG_DIR:
; Map the first 4mb physical memory to first 4mb virtual memory. Otherwise, when paging is enabled, eip points to, 0x100004 for example, and MMU is not gonna know how to translate
; this address into phsyical mem address, because our PDE doesn't tell MMU how to find it.
dd 0x00000083
times(PDE_INDEX - 1) dd 0
dd 0x00000083
times(1024 - PDE_INDEX - 1) dd 0
align 4
global _loader
extern kmain
extern set_up_gdt
_loader:
; update page directory address, since eax and ebx is in use, have to use ecx or other register
mov ecx, TEMP_PG_DIR
mov cr3, ecx
; Enable 4mb pages
mov ecx, cr4;
or ecx, PSE_BIT
mov cr4, ecx
; Set PG bit, enable paging
mov ecx, cr0
or ecx, PG_BIT
mov cr0, ecx
finit
; sti - DO NOT enable interrupts until IDT is created!
mov esp,stack_top
push ebx
push eax
call set_up_gdt
call kmain
cli
.stop:
hlt
jmp .stop