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
|
global paging_init
align 4096
page_dir:
times 4096 db 0
align 4096
page_tables:
; two page tables
times 4096 db 0
times 4096 db 0
.end:
; here, we initialize paging. since the IDT
; has yet to be populated, we must take extra
; care as we can't afford to trigger a page
; fault.
paging_init:
push ebp
mov ebp, esp
push ebx
; populate the page directory
mov eax, page_tables
or eax, 0x007
mov [page_dir], eax
mov eax, (page_tables+4096)
or eax, 0x007
mov [page_dir+4], eax
; populate the page tables
mov ebx, page_tables
mov ecx, ((page_tables.end-page_tables)/4)
mov edx, 0
.loop:
mov eax, edx
or eax, 0x003
cmp edx, 0x100000
jb .skip
or eax, 0x004
.skip:
mov [ebx], eax
dec ecx
jz .end
add ebx, 4
add edx, 4096
jmp .loop
.end:
; load the page directory and enable paging
mov eax, page_dir
mov cr3, eax
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
pop ebx
pop ebp
ret
|