Subversion Repositories Kolibri OS

Rev

Rev 168 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
164 serge 1
 
2
3
 
4
proc mem_test
5
           mov eax, cr0
6
           or eax, (CR0_CD+CR0_NW);disable caching
168 serge 7
           mov cr0, eax
164 serge 8
           wbinvd                 ;invalidate cache
168 serge 9
164 serge 10
 
11
           mov ebx, 'TEST'
12
@@:
13
           add edi, 0x400000
14
           xchg ebx, dword [edi]
15
           cmp dword [edi], 'TEST'
16
           xchg ebx, dword [edi]
17
           je @b
18
19
 
168 serge 20
           mov cr0, eax
164 serge 21
           mov eax, edi
22
           ret
23
endp
24
25
 
26
proc init_memEx
27
           xor eax, eax
28
           mov edi, sys_pgdir
29
           mov ecx, 2048
30
           rep stosd
31
32
 
33
           jnc .no_PSE
34
35
 
36
           or ebx, CR4_PSE
37
           mov eax, PG_LARGE+PG_SW
38
           bt [cpu_caps], CAPS_PGE
39
           jnc @F
40
           or eax, PG_GLOBAL
41
           or ebx, CR4_PGE
42
168 serge 43
 
164 serge 44
           mov cr4, ebx
168 serge 45
46
 
164 serge 47
           add eax, 0x00400000
48
           mov dword [sys_pgdir+4], eax
49
           add eax, 0x00400000
50
           mov dword [sys_pgdir+8], eax
51
           add eax, 0x00400000
52
           mov dword [sys_pgdir+12], eax
53
54
 
55
           mov dword [sys_master_tab+0x600], sys_master_tab+PG_SW
56
57
 
58
           sub ecx, 4
59
           mov eax, tmp_page_tab+PG_SW
60
           mov edi, sys_pgdir+16
61
           mov esi, sys_master_tab+16
62
63
 
64
.no_PSE:
65
           mov eax, PG_SW
66
           mov esi, tmp_page_tab
67
           mov ecx, 4096/4      ;0x0 - 0x00FFFFFF
68
.map_low:
69
           mov [esi], eax
70
           add eax, 0x1000
71
           mov [esi+4], eax
72
           add eax, 0x1000
73
           mov [esi+8], eax
74
           add eax, 0x1000
75
           mov [esi+12], eax
76
           add eax, 0x1000
77
           add esi, 16
78
           dec ecx
79
           jnz .map_low            ;ядро
80
81
 
82
           mov eax, tmp_page_tab+PG_SW
83
           mov edi, sys_pgdir
84
           mov esi, sys_master_tab
85
86
 
87
88
 
89
           mov [esi], eax
90
           add eax, 0x1000
91
           add edi, 4
92
           add esi, 4
93
           dec ecx
94
           jnz .map_kernel_tabs
95
96
 
97
           bt [cpu_caps], CAPS_PSE
98
           jc @F
99
           add edi, 4096*4      ;skip low kernel memory
100
@@:
101
           mov ecx, [pg_data.kernel_tables]
102
           sub ecx, 4
103
           shl ecx, 10
104
           xor eax, eax
105
           cld
106
           rep stosd
107
108
 
109
           mov dword [sys_master_tab+0x600], sys_master_tab+PG_SW
110
           ret
111
endp
112
113
 
114
proc init_page_map
115
           mov edi, sys_pgmap
116
           mov ecx, 512/4
117
           xor eax,eax
118
           cld
119
           rep stosd
120
121
 
122
           mov ecx, [pg_data.pagemap_size]
123
           sub ecx, 512
124
           shr ecx, 2
125
           rep stosd
126
127
 
128
           mov edx, [pg_data.pages_count]
129
           mov ecx, [pg_data.kernel_tables]
130
           bt [cpu_caps], CAPS_PSE
131
           jnc @f
132
           sub ecx, 4
133
@@:
134
           sub edx, 4096
135
           sub edx, ecx
136
           mov [pg_data.pages_free], edx
137
138
 
139
           mov ebx, ecx
140
           shr ecx, 5
141
           rep stosd
142
143
 
144
           mov ecx, ebx
145
           and ecx, 31
146
           shl eax, cl
147
           stosd
148
149
 
150
           mov ebx, sys_pgmap
151
           add ebx, [pg_data.pagemap_size]
152
           mov [page_end], ebx
153
154
 
155
156
 
157
endp
158
159
 
160
proc alloc_page
161
162
 
163
           cli
164
           mov ebx, [page_start]
165
           mov ecx, [page_end]
166
.l1:
167
           bsf eax,[ebx];
168
           jnz .found
169
           add ebx,4
170
           cmp ebx, ecx
171
           jb .l1
172
           popfd
173
           xor eax,eax
174
           ret
175
.found:
176
           btr [ebx], eax
177
           mov [page_start],ebx
178
           sub ebx, sys_pgmap
179
           shl ebx, 3
180
           add eax,ebx
181
           shl eax, 12
182
           dec [pg_data.pages_free]
183
           popfd
184
           ret
185
endp
186
187
 
188
proc alloc_pages stdcall, count:dword
189
           pushfd
190
           cli
191
           mov eax, [count]
192
           add eax, 7
193
           shr eax, 3
194
           mov [count], eax
195
           cmp eax, [pg_data.pages_free]
196
           ja .fail
197
198
 
199
           mov ebx, [page_end]
200
.find:
201
           mov edx, [count]
202
           mov edi, ecx
203
204
 
205
           cmp byte [ecx], 0xFF
206
           jne .next
207
           dec edx
208
           jz .ok
209
           inc ecx
210
           cmp ecx,ebx
211
           jb .match
212
.fail:     xor eax, eax
213
           popfd
214
           ret
215
.next:
216
           inc ecx
217
           cmp ecx, ebx
218
           jb .find
219
           popfd
220
           xor eax, eax
221
           ret
222
.ok:
223
           sub ecx, edi
224
           inc ecx
225
           mov esi, edi
226
           xor eax, eax
227
           rep stosb
228
           sub esi, sys_pgmap
229
           shl esi, 3+12
230
           mov eax, esi
231
           mov ebx, [count]
232
           shl ebx, 3
233
           sub [pg_data.pages_free], ebx
234
           popfd
235
           ret
236
endp
237
238
 
239
proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
240
           mov eax, [phis_addr]
241
           and eax, not 0xFFF
242
           or eax, [flags]
243
           mov ebx, [lin_addr]
244
           shr ebx, 12
245
           mov [pages_tab+ebx*4], eax
246
           mov eax, [lin_addr]
247
           invlpg [eax]
248
           ret
249
endp
250
251
 
252
proc free_page
253
;arg:  eax  page address
254
           pushfd
255
           cli
256
           inc [pg_data.pages_free]
257
           shr eax, 12              ;page index
258
           mov ebx, sys_pgmap
259
           bts [ebx], eax           ;that's all!
260
           shr eax, 3
261
           and eax, not 3           ;dword offset from page_map
262
           add eax, ebx
263
           cmp [page_start], eax
264
           ja @f
265
           popfd
266
           ret
267
@@:
268
           mov [page_start], eax
269
           popfd
270
           ret
271
endp
272
</