-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkernel_entry.asm
More file actions
56 lines (50 loc) · 1.04 KB
/
kernel_entry.asm
File metadata and controls
56 lines (50 loc) · 1.04 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
45
46
47
48
49
50
51
52
53
54
55
56
extern main
extern l2_page_table
section .text.head
global kernel_entry
; flags for a megapage
MEGAPAGE_FLAGS equ (1 << 7) | (1 << 1) | (1 << 0)
L2_PAGE_BASE equ l2_page_table - (0x80100000)
kernel_entry:
; enable page size extensions
mov eax, cr4
or eax, 1 << 4
mov cr4, eax
; zero out the level 2 page table
mov edi, L2_PAGE_BASE
xor eax, eax
mov ecx, 1024
rep stosd
; zero out [4MiB, 8MiB), the memory reserved for level 1 page tables
mov edi, 1 << 22
xor eax, eax
mov ecx, 1 << 20
rep stosd
mov dword [1 << 22], 0x69696969
; identity map [0, 4MiB)
mov dword [L2_PAGE_BASE], MEGAPAGE_FLAGS
; map 32 MiB of higher half virtual addresses to physical addresses
mov ecx, 0
mov edi, L2_PAGE_BASE + (1 << 9) * 4
.pageloop:
mov eax, ecx
shl eax, 22
or eax, MEGAPAGE_FLAGS
mov [edi], eax
inc ecx
add edi, 4
cmp ecx, 8
jl .pageloop
; enable paging
mov eax, L2_PAGE_BASE
mov cr3, eax
mov eax, cr0
or eax, 1 << 31
mov cr0, eax
; initialize stack
mov esp, (1 << 31) + (1 << 22)
mov eax, call_main
jmp eax
call_main:
call main
jmp $