-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathpage32.asm
165 lines (138 loc) · 2.79 KB
/
page32.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
; --------------------------------------- Paging routines ---------------------------------------
USE32
InitPageTable32a:
; A more clean version of what we are doing.
; We map the entire 4GB address space (1024*1024*4096) See Through
pushad
push ds
push es
mov ax,data16_idx
push gs
mov gs,ax
mov ebp,[gs:PhysicalPagingOffset32]
pop gs
mov ax,page32_idx
mov ds,ax
mov es,ax
; Tables Clear
mov edi,ebp
mov ecx,2048
xor eax,eax
rep stosd
; PageDir32 points to PageTables32
; Create 1024 entries
mov edi,ebp
xor ecx,ecx
LoopPageDir1:
xor eax,eax
mov eax,ebp
add eax,4096
shr eax,12 ; Get rid of lower 12 bits (4096 alignment)
mov ebx,ecx
add eax,ebx
shl eax,12
or al,7 ; Present, Writable, Everyone,
stosd
inc ecx
cmp ecx,1024
jnz LoopPageDir1
; PageTables32 create 1024 entries
mov edi,ebp
add edi,4096
xor ecx,ecx
LoopPageTables1:
xor eax,eax
mov eax,0 ; See-Through, so we start at 0
add eax,ecx
shl eax,12
or al,7 ; Present, Writable, Everyone,
stosd
inc ecx
cmp ecx,1024
jnz LoopPageTables1
pop es
pop ds
popad
ret
InitPageTable642:
pushad
push ds
push es
mov ax,data16_idx
push gs
mov gs,ax
mov esi,[gs:PhysicalPagingOffset64]
pop gs
mov ax,page64_idx
mov ds,ax
mov es,ax
xor eax, eax
mov edi,esi
mov ecx,03000h
rep stosb
;top level page table
mov eax, esi
add eax,0x1000
or eax,3
mov [esi],eax
mov eax, esi
add eax,0x2000
or eax,3
mov [esi + 0x1000],eax
;2MB pages to identity map the first 16MB ram
mov eax,1
shl eax,7
or eax,3
mov [esi + 0x2000],eax
add eax,0x200000
mov [esi + 0x2008],eax
add eax,0x200000
mov [esi + 0x2010],eax
add eax,0x200000
mov [esi + 0x2018],eax
add eax,0x200000
mov [esi + 0x2020],eax
add eax,0x200000
mov [esi + 0x2028],eax
add eax,0x200000
mov [esi + 0x2030],eax
add eax,0x200000
mov [esi + 0x2038],eax
pop es
pop ds
popad
ret
InitPageTable643:
; a function to use 1GB pages
pushad
push es
push gs
mov ax,data16_idx
mov gs,ax
mov ax,page32_idx
mov es,ax
mov esi,[gs:PhysicalPagingOffset64]
; clear
mov edi,esi
xor eax,eax
mov ecx,03000h
rep stosb
; Put the PML4T to 0x0000, these are 512 entries, so it takes 0x1000 bytes
; We only want the first PML4T
mov eax,esi
add eax,0x1000 ; point it to the first PDPT
or eax,3 ; Present, Readable/Writable
mov [es:esi + 0x0000],eax
mov ecx,4 ; Map 4GB (512*1GB).
mov eax,0x83 ; Also bit 7
mov edi,esi
add edi,0x1000
.lxf1:
mov [es:edi],eax
add eax,1024*1024*1024
add edi,8
loop .lxf1
pop gs
pop es
popad
ret