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
|
global page_directory
global page_tables
global paging_init
global paging_finish
global KERNEL_MAPPING
KERNEL_MAPPING equ 0xC0000000
VGABUF equ 0x000B8000
%define mapped(addr) addr - KERNEL_MAPPING
section .bss
align 4096
page_directory:
resb 1024 * 4
page_tables:
resb 1024 * 1024 * 4
section .bootstrap.text
align 8
paging_init:
extern kernel_start
extern kernel_end
paging_load:
mov edi, mapped(page_tables)
mov esi, 0
mov ecx, 1023
paging_cmp:
cmp esi, kernel_start
jl paging_add
cmp esi, mapped(kernel_end)
jge paging_map
mov edx, esi
or edx, 0x003
mov [edi], edx
paging_add:
add esi, 4096
add edi, 4
loop paging_cmp
paging_map:
lea eax, mapped(page_directory)
push eax
extern setup_pgdir
call mapped(setup_pgdir)
add esp, 0x04
; map VGA buffer
mov dword [mapped(page_tables) + 1023 * 4], VGABUF + 0x003
; map 8MB for the kernel
mov dword [mapped(page_directory) + 0 * 4], mapped(page_tables) + 0x003
mov dword [mapped(page_directory) + 1 * 4], mapped(page_tables) + 0x400000000 + 0x003
mov dword [mapped(page_directory) + 768 * 4], mapped(page_tables) + 0x003
mov dword [mapped(page_directory) + 769 * 4], mapped(page_tables) + 0x400000000 + 0x003
; tell the MMU where the page dir is
mov ecx, mapped(page_directory)
mov cr3, ecx
; finally init paging
mov ecx, cr0
or ecx, 0x80010000
mov cr0, ecx
ret
section .text
align 8
paging_finish:
; remove the 8MB ident mapping
mov dword [page_directory + 0 * 4], 0
mov dword [page_directory + 1 * 4], 0
mov ecx, cr3
mov cr3, ecx
ret
|