Rev 5596 | Rev 6317 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5596 | Rev 6252 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 5596 $ |
8 | $Revision: 6252 $ |
9 | 9 | ||
10 | 10 | ||
11 | align 4 |
11 | align 4 |
12 | proc alloc_page |
12 | proc alloc_page |
13 | 13 | ||
14 | pushfd |
14 | pushfd |
15 | cli |
15 | cli |
16 | push ebx |
16 | push ebx |
17 | ;//- |
17 | ;//- |
18 | cmp [pg_data.pages_free], 1 |
18 | cmp [pg_data.pages_free], 1 |
19 | jle .out_of_memory |
19 | jle .out_of_memory |
20 | ;//- |
20 | ;//- |
21 | 21 | ||
22 | mov ebx, [page_start] |
22 | mov ebx, [page_start] |
23 | mov ecx, [page_end] |
23 | mov ecx, [page_end] |
24 | .l1: |
24 | .l1: |
25 | bsf eax, [ebx]; |
25 | bsf eax, [ebx]; |
26 | jnz .found |
26 | jnz .found |
27 | add ebx, 4 |
27 | add ebx, 4 |
28 | cmp ebx, ecx |
28 | cmp ebx, ecx |
29 | jb .l1 |
29 | jb .l1 |
30 | pop ebx |
30 | pop ebx |
31 | popfd |
31 | popfd |
32 | xor eax, eax |
32 | xor eax, eax |
33 | ret |
33 | ret |
34 | .found: |
34 | .found: |
35 | ;//- |
35 | ;//- |
36 | dec [pg_data.pages_free] |
36 | dec [pg_data.pages_free] |
37 | jz .out_of_memory |
37 | jz .out_of_memory |
38 | ;//- |
38 | ;//- |
39 | btr [ebx], eax |
39 | btr [ebx], eax |
40 | mov [page_start], ebx |
40 | mov [page_start], ebx |
41 | sub ebx, sys_pgmap |
41 | sub ebx, sys_pgmap |
42 | lea eax, [eax+ebx*8] |
42 | lea eax, [eax+ebx*8] |
43 | shl eax, 12 |
43 | shl eax, 12 |
44 | ;//- dec [pg_data.pages_free] |
44 | ;//- dec [pg_data.pages_free] |
45 | pop ebx |
45 | pop ebx |
46 | popfd |
46 | popfd |
47 | ret |
47 | ret |
48 | ;//- |
48 | ;//- |
49 | .out_of_memory: |
49 | .out_of_memory: |
50 | mov [pg_data.pages_free], 1 |
50 | mov [pg_data.pages_free], 1 |
51 | xor eax, eax |
51 | xor eax, eax |
52 | pop ebx |
52 | pop ebx |
53 | popfd |
53 | popfd |
54 | ret |
54 | ret |
55 | ;//- |
55 | ;//- |
56 | endp |
56 | endp |
57 | 57 | ||
58 | align 4 |
58 | align 4 |
59 | proc alloc_pages stdcall, count:dword |
59 | proc alloc_pages stdcall, count:dword |
60 | pushfd |
60 | pushfd |
61 | push ebx |
61 | push ebx |
62 | push edi |
62 | push edi |
63 | cli |
63 | cli |
64 | mov eax, [count] |
64 | mov eax, [count] |
65 | add eax, 7 |
65 | add eax, 7 |
66 | shr eax, 3 |
66 | shr eax, 3 |
67 | mov [count], eax |
67 | mov [count], eax |
68 | ;//- |
68 | ;//- |
69 | mov ebx, [pg_data.pages_free] |
69 | mov ebx, [pg_data.pages_free] |
70 | sub ebx, 9 |
70 | sub ebx, 9 |
71 | js .out_of_memory |
71 | js .out_of_memory |
72 | shr ebx, 3 |
72 | shr ebx, 3 |
73 | cmp eax, ebx |
73 | cmp eax, ebx |
74 | jg .out_of_memory |
74 | jg .out_of_memory |
75 | ;//- |
75 | ;//- |
76 | mov ecx, [page_start] |
76 | mov ecx, [page_start] |
77 | mov ebx, [page_end] |
77 | mov ebx, [page_end] |
78 | .find: |
78 | .find: |
79 | mov edx, [count] |
79 | mov edx, [count] |
80 | mov edi, ecx |
80 | mov edi, ecx |
81 | .match: |
81 | .match: |
82 | cmp byte [ecx], 0xFF |
82 | cmp byte [ecx], 0xFF |
83 | jne .next |
83 | jne .next |
84 | dec edx |
84 | dec edx |
85 | jz .ok |
85 | jz .ok |
86 | inc ecx |
86 | inc ecx |
87 | cmp ecx, ebx |
87 | cmp ecx, ebx |
88 | jb .match |
88 | jb .match |
89 | .out_of_memory: |
89 | .out_of_memory: |
90 | .fail: |
90 | .fail: |
91 | xor eax, eax |
91 | xor eax, eax |
92 | pop edi |
92 | pop edi |
93 | pop ebx |
93 | pop ebx |
94 | popfd |
94 | popfd |
95 | ret |
95 | ret |
96 | .next: |
96 | .next: |
97 | inc ecx |
97 | inc ecx |
98 | cmp ecx, ebx |
98 | cmp ecx, ebx |
99 | jb .find |
99 | jb .find |
100 | pop edi |
100 | pop edi |
101 | pop ebx |
101 | pop ebx |
102 | popfd |
102 | popfd |
103 | xor eax, eax |
103 | xor eax, eax |
104 | ret |
104 | ret |
105 | .ok: |
105 | .ok: |
106 | sub ecx, edi |
106 | sub ecx, edi |
107 | inc ecx |
107 | inc ecx |
108 | push esi |
108 | push esi |
109 | mov esi, edi |
109 | mov esi, edi |
110 | xor eax, eax |
110 | xor eax, eax |
111 | rep stosb |
111 | rep stosb |
112 | sub esi, sys_pgmap |
112 | sub esi, sys_pgmap |
113 | shl esi, 3+12 |
113 | shl esi, 3+12 |
114 | mov eax, esi |
114 | mov eax, esi |
115 | mov ebx, [count] |
115 | mov ebx, [count] |
116 | shl ebx, 3 |
116 | shl ebx, 3 |
117 | sub [pg_data.pages_free], ebx |
117 | sub [pg_data.pages_free], ebx |
118 | pop esi |
118 | pop esi |
119 | pop edi |
119 | pop edi |
120 | pop ebx |
120 | pop ebx |
121 | popfd |
121 | popfd |
122 | ret |
122 | ret |
123 | endp |
123 | endp |
124 | 124 | ||
125 | align 4 |
125 | align 4 |
126 | ;proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword |
126 | ;proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword |
127 | map_page: |
127 | map_page: |
128 | push ebx |
128 | push ebx |
129 | mov eax, [esp+12] ; phis_addr |
129 | mov eax, [esp+12] ; phis_addr |
130 | or eax, [esp+16] ; flags |
130 | or eax, [esp+16] ; flags |
131 | and eax, [pte_valid_mask] |
131 | and eax, [pte_valid_mask] |
132 | mov ebx, [esp+8] ; lin_addr |
132 | mov ebx, [esp+8] ; lin_addr |
133 | shr ebx, 12 |
133 | shr ebx, 12 |
134 | mov [page_tabs+ebx*4], eax |
134 | mov [page_tabs+ebx*4], eax |
135 | mov eax, [esp+8] ; lin_addr |
135 | mov eax, [esp+8] ; lin_addr |
136 | pop ebx |
136 | pop ebx |
137 | invlpg [eax] |
137 | invlpg [eax] |
138 | ret 12 |
138 | ret 12 |
139 | 139 | ||
140 | align 4 |
140 | align 4 |
141 | map_space: ;not implemented |
141 | map_space: ;not implemented |
142 | 142 | ||
143 | 143 | ||
144 | ret |
144 | ret |
145 | 145 | ||
146 | 146 | ||
147 | align 4 |
147 | align 4 |
148 | proc free_page |
148 | proc free_page |
149 | ;arg: eax page address |
149 | ;arg: eax page address |
150 | pushfd |
150 | pushfd |
151 | cli |
151 | cli |
152 | shr eax, 12 ;page index |
152 | shr eax, 12 ;page index |
153 | bts dword [sys_pgmap], eax ;that's all! |
153 | bts dword [sys_pgmap], eax ;that's all! |
154 | cmc |
154 | cmc |
155 | adc [pg_data.pages_free], 0 |
155 | adc [pg_data.pages_free], 0 |
156 | shr eax, 3 |
156 | shr eax, 3 |
157 | and eax, not 3 ;dword offset from page_map |
157 | and eax, not 3 ;dword offset from page_map |
158 | add eax, sys_pgmap |
158 | add eax, sys_pgmap |
159 | cmp [page_start], eax |
159 | cmp [page_start], eax |
160 | ja @f |
160 | ja @f |
161 | popfd |
161 | popfd |
162 | ret |
162 | ret |
163 | @@: |
163 | @@: |
164 | mov [page_start], eax |
164 | mov [page_start], eax |
165 | popfd |
165 | popfd |
166 | ret |
166 | ret |
167 | endp |
167 | endp |
168 | 168 | ||
169 | align 4 |
169 | align 4 |
170 | proc map_io_mem stdcall, base:dword, size:dword, flags:dword |
170 | proc map_io_mem stdcall, base:dword, size:dword, flags:dword |
171 | 171 | ||
172 | push ebx |
172 | push ebx |
173 | push edi |
173 | push edi |
174 | mov eax, [size] |
174 | mov eax, [size] |
175 | add eax, [base] |
175 | add eax, [base] |
176 | add eax, 4095 |
176 | add eax, 4095 |
177 | and eax, -4096 |
177 | and eax, -4096 |
178 | mov ecx, [base] |
178 | mov ecx, [base] |
179 | and ecx, -4096 |
179 | and ecx, -4096 |
180 | sub eax, ecx |
180 | sub eax, ecx |
181 | mov [size], eax |
181 | mov [size], eax |
182 | 182 | ||
183 | stdcall alloc_kernel_space, eax |
183 | stdcall alloc_kernel_space, eax |
184 | test eax, eax |
184 | test eax, eax |
185 | jz .fail |
185 | jz .fail |
186 | push eax |
186 | push eax |
187 | 187 | ||
188 | mov edi, 0x1000 |
188 | mov edi, 0x1000 |
189 | mov ebx, eax |
189 | mov ebx, eax |
190 | mov ecx, [size] |
190 | mov ecx, [size] |
191 | mov edx, [base] |
191 | mov edx, [base] |
192 | shr eax, 12 |
192 | shr eax, 12 |
193 | shr ecx, 12 |
193 | shr ecx, 12 |
194 | or edx, [flags] |
194 | or edx, [flags] |
195 | and edx, [pte_valid_mask] |
195 | and edx, [pte_valid_mask] |
196 | @@: |
196 | @@: |
197 | mov [page_tabs+eax*4], edx |
197 | mov [page_tabs+eax*4], edx |
198 | invlpg [ebx] |
198 | invlpg [ebx] |
199 | inc eax |
199 | inc eax |
200 | add ebx, edi |
200 | add ebx, edi |
201 | add edx, edi |
201 | add edx, edi |
202 | loop @B |
202 | loop @B |
203 | 203 | ||
204 | pop eax |
204 | pop eax |
205 | mov edx, [base] |
205 | mov edx, [base] |
206 | and edx, 4095 |
206 | and edx, 4095 |
207 | add eax, edx |
207 | add eax, edx |
208 | .fail: |
208 | .fail: |
209 | pop edi |
209 | pop edi |
210 | pop ebx |
210 | pop ebx |
211 | ret |
211 | ret |
212 | endp |
212 | endp |
213 | 213 | ||
214 | ; param |
214 | ; param |
215 | ; eax= page base + page flags |
215 | ; eax= page base + page flags |
216 | ; ebx= linear address |
216 | ; ebx= linear address |
217 | ; ecx= count |
217 | ; ecx= count |
218 | 218 | ||
219 | align 4 |
219 | align 4 |
220 | commit_pages: |
220 | commit_pages: |
221 | test ecx, ecx |
221 | test ecx, ecx |
222 | jz .fail |
222 | jz .fail |
223 | 223 | ||
224 | push edi |
224 | push edi |
225 | push eax |
225 | push eax |
226 | push ecx |
226 | push ecx |
227 | mov ecx, pg_data.mutex |
227 | mov ecx, pg_data.mutex |
228 | call mutex_lock |
228 | call mutex_lock |
229 | pop ecx |
229 | pop ecx |
230 | pop eax |
230 | pop eax |
231 | 231 | ||
232 | and eax, [pte_valid_mask ] |
232 | and eax, [pte_valid_mask ] |
233 | mov edi, ebx |
233 | mov edi, ebx |
234 | shr edi, 12 |
234 | shr edi, 12 |
235 | lea edi, [page_tabs+edi*4] |
235 | lea edi, [page_tabs+edi*4] |
236 | @@: |
236 | @@: |
237 | stosd |
237 | stosd |
238 | invlpg [ebx] |
238 | invlpg [ebx] |
239 | add eax, 0x1000 |
239 | add eax, 0x1000 |
240 | add ebx, 0x1000 |
240 | add ebx, 0x1000 |
241 | loop @B |
241 | loop @B |
242 | 242 | ||
243 | pop edi |
243 | pop edi |
244 | 244 | ||
245 | mov ecx, pg_data.mutex |
245 | mov ecx, pg_data.mutex |
246 | call mutex_unlock |
246 | call mutex_unlock |
247 | .fail: |
247 | .fail: |
248 | ret |
248 | ret |
249 | 249 | ||
250 | 250 | ||
251 | ; param |
251 | ; param |
252 | ; eax= base |
252 | ; eax= base |
253 | ; ecx= count |
253 | ; ecx= count |
254 | 254 | ||
255 | align 4 |
255 | align 4 |
256 | release_pages: |
256 | release_pages: |
257 | 257 | ||
258 | push ebp |
258 | push ebp |
259 | push esi |
259 | push esi |
260 | push edi |
260 | push edi |
261 | push ebx |
261 | push ebx |
262 | 262 | ||
263 | mov esi, eax |
263 | mov esi, eax |
264 | mov edi, eax |
264 | mov edi, eax |
265 | 265 | ||
266 | shr esi, 12 |
266 | shr esi, 12 |
267 | lea esi, [page_tabs+esi*4] |
267 | lea esi, [page_tabs+esi*4] |
268 | 268 | ||
269 | push ecx |
269 | push ecx |
270 | mov ecx, pg_data.mutex |
270 | mov ecx, pg_data.mutex |
271 | call mutex_lock |
271 | call mutex_lock |
272 | pop ecx |
272 | pop ecx |
273 | 273 | ||
274 | mov ebp, [pg_data.pages_free] |
274 | mov ebp, [pg_data.pages_free] |
275 | mov ebx, [page_start] |
275 | mov ebx, [page_start] |
276 | mov edx, sys_pgmap |
276 | mov edx, sys_pgmap |
277 | @@: |
277 | @@: |
278 | xor eax, eax |
278 | xor eax, eax |
279 | xchg eax, [esi] |
279 | xchg eax, [esi] |
280 | invlpg [edi] |
280 | invlpg [edi] |
281 | 281 | ||
282 | test eax, 1 |
282 | test eax, 1 |
283 | jz .next |
283 | jz .next |
284 | 284 | ||
285 | shr eax, 12 |
285 | shr eax, 12 |
286 | bts [edx], eax |
286 | bts [edx], eax |
287 | cmc |
287 | cmc |
288 | adc ebp, 0 |
288 | adc ebp, 0 |
289 | shr eax, 3 |
289 | shr eax, 3 |
290 | and eax, -4 |
290 | and eax, -4 |
291 | add eax, edx |
291 | add eax, edx |
292 | cmp eax, ebx |
292 | cmp eax, ebx |
293 | jae .next |
293 | jae .next |
294 | 294 | ||
295 | mov ebx, eax |
295 | mov ebx, eax |
296 | .next: |
296 | .next: |
297 | add edi, 0x1000 |
297 | add edi, 0x1000 |
298 | add esi, 4 |
298 | add esi, 4 |
299 | loop @B |
299 | loop @B |
300 | 300 | ||
301 | mov [pg_data.pages_free], ebp |
301 | mov [pg_data.pages_free], ebp |
302 | mov ecx, pg_data.mutex |
302 | mov ecx, pg_data.mutex |
303 | call mutex_unlock |
303 | call mutex_unlock |
304 | 304 | ||
305 | pop ebx |
305 | pop ebx |
306 | pop edi |
306 | pop edi |
307 | pop esi |
307 | pop esi |
308 | pop ebp |
308 | pop ebp |
309 | ret |
309 | ret |
310 | 310 | ||
311 | ; param |
311 | ; param |
312 | ; eax= base |
312 | ; eax= base |
313 | ; ecx= count |
313 | ; ecx= count |
314 | 314 | ||
315 | align 4 |
315 | align 4 |
316 | unmap_pages: |
316 | unmap_pages: |
317 | 317 | ||
318 | push edi |
318 | push edi |
319 | 319 | ||
320 | mov edi, eax |
320 | mov edi, eax |
321 | mov edx, eax |
321 | mov edx, eax |
322 | 322 | ||
323 | shr edi, 10 |
323 | shr edi, 10 |
324 | add edi, page_tabs |
324 | add edi, page_tabs |
325 | 325 | ||
326 | xor eax, eax |
326 | xor eax, eax |
327 | @@: |
327 | @@: |
328 | stosd |
328 | stosd |
329 | invlpg [edx] |
329 | invlpg [edx] |
330 | add edx, 0x1000 |
330 | add edx, 0x1000 |
331 | loop @b |
331 | loop @b |
332 | 332 | ||
333 | pop edi |
333 | pop edi |
334 | ret |
334 | ret |
335 | 335 | ||
336 | 336 | ||
337 | align 4 |
337 | align 4 |
338 | proc map_page_table stdcall, lin_addr:dword, phis_addr:dword |
338 | proc map_page_table stdcall, lin_addr:dword, phis_addr:dword |
339 | push ebx |
339 | push ebx |
340 | mov ebx, [lin_addr] |
340 | mov ebx, [lin_addr] |
341 | shr ebx, 22 |
341 | shr ebx, 22 |
342 | mov eax, [phis_addr] |
342 | mov eax, [phis_addr] |
343 | and eax, not 0xFFF |
343 | and eax, not 0xFFF |
344 | or eax, PG_UWR |
344 | or eax, PG_UWR |
345 | mov dword [master_tab+ebx*4], eax |
345 | mov dword [master_tab+ebx*4], eax |
346 | mov eax, [lin_addr] |
346 | mov eax, [lin_addr] |
347 | shr eax, 10 |
347 | shr eax, 10 |
348 | add eax, page_tabs |
348 | add eax, page_tabs |
349 | invlpg [eax] |
349 | invlpg [eax] |
350 | pop ebx |
350 | pop ebx |
351 | ret |
351 | ret |
352 | endp |
352 | endp |
353 | 353 | ||
354 | uglobal |
354 | uglobal |
355 | sb16_buffer_allocated db 0 |
355 | sb16_buffer_allocated db 0 |
356 | endg |
356 | endg |
357 | 357 | ||
358 | ; Allocates [.size] bytes so that the target memory block |
358 | ; Allocates [.size] bytes so that the target memory block |
359 | ; is inside one 64K page for 24-bit DMA controller, |
359 | ; is inside one 64K page for 24-bit DMA controller, |
360 | ; that is, somewhere between 00xx0000h and 00xxFFFFh. |
360 | ; that is, somewhere between 00xx0000h and 00xxFFFFh. |
361 | proc alloc_dma24 |
361 | proc alloc_dma24 |
362 | ; Implementation note. |
362 | ; Implementation note. |
363 | ; The only user of that function is SB16 driver, |
363 | ; The only user of that function is SB16 driver, |
364 | ; so just return a statically allocated buffer. |
364 | ; so just return a statically allocated buffer. |
365 | virtual at esp |
365 | virtual at esp |
366 | dd ? ; return address |
366 | dd ? ; return address |
367 | .size dd ? |
367 | .size dd ? |
368 | end virtual |
368 | end virtual |
369 | cmp [sb16_buffer_allocated], 0 |
369 | cmp [sb16_buffer_allocated], 0 |
370 | jnz .fail |
370 | jnz .fail |
371 | inc [sb16_buffer_allocated] |
371 | inc [sb16_buffer_allocated] |
372 | mov eax, SB16Buffer |
372 | mov eax, SB16Buffer |
373 | ret 4 |
373 | ret 4 |
374 | .fail: |
374 | .fail: |
375 | xor eax, eax |
375 | xor eax, eax |
376 | ret 4 |
376 | ret 4 |
377 | endp |
377 | endp |
378 | 378 | ||
379 | ; Allocates a physical page for master page table |
379 | ; Allocates a physical page for master page table |
380 | ; that duplicates first Mb of OS_BASE at address 0; |
380 | ; that duplicates first Mb of OS_BASE at address 0; |
381 | ; used for starting APs and for shutting down, |
381 | ; used for starting APs and for shutting down, |
382 | ; where it is important to execute code in trivial-mapped pages. |
382 | ; where it is important to execute code in trivial-mapped pages. |
383 | ; Returns eax = allocated physical page. |
383 | ; Returns eax = allocated physical page. |
384 | proc create_trampoline_pgmap |
384 | proc create_trampoline_pgmap |
385 | ; The only non-trivial moment: |
385 | ; The only non-trivial moment: |
386 | ; we need a linear address to fill information, |
386 | ; we need a linear address to fill information, |
387 | ; but we don't need it outside of this function, |
387 | ; but we don't need it outside of this function, |
388 | ; so we're returning physical address. |
388 | ; so we're returning physical address. |
389 | ; Therefore, allocate memory with kernel_alloc, |
389 | ; Therefore, allocate memory with kernel_alloc, |
390 | ; this will allocate physical page and a linear address somewhere, |
390 | ; this will allocate physical page and a linear address somewhere, |
391 | ; and deallocate only linear address with free_kernel_space. |
391 | ; and deallocate only linear address with free_kernel_space. |
392 | stdcall kernel_alloc, 0x1000 |
392 | stdcall kernel_alloc, 0x1000 |
393 | mov edi, eax |
393 | mov edi, eax |
394 | mov esi, master_tab |
394 | mov esi, master_tab |
395 | mov ecx, 1024 |
395 | mov ecx, 1024 |
396 | rep movsd |
396 | rep movsd |
397 | mov ecx, [master_tab+(OS_BASE shr 20)] |
397 | mov ecx, [master_tab+(OS_BASE shr 20)] |
398 | mov [eax], ecx |
398 | mov [eax], ecx |
399 | mov edi, eax |
399 | mov edi, eax |
400 | call get_pg_addr |
400 | call get_pg_addr |
401 | push eax |
401 | push eax |
402 | stdcall free_kernel_space, edi |
402 | stdcall free_kernel_space, edi |
403 | pop eax |
403 | pop eax |
404 | ret |
404 | ret |
405 | endp |
- | |
406 | - | ||
407 | align 4 |
- | |
408 | proc init_LFB |
- | |
409 | locals |
- | |
410 | pg_count dd ? |
- | |
411 | endl |
- | |
412 | - | ||
413 | cmp dword [LFBAddress], -1 |
- | |
414 | jne @f |
- | |
415 | mov [BOOT_VARS+BOOT_MTRR], byte 2 |
- | |
416 | ; max VGA=640*480*4=1228800 bytes |
- | |
417 | ; + 32*640*4=81920 bytes for mouse pointer |
- | |
418 | stdcall alloc_pages, ((1228800+81920)/4096) |
- | |
419 | - | ||
420 | push eax |
- | |
421 | call alloc_page |
- | |
422 | stdcall map_page_table, LFB_BASE, eax |
- | |
423 | pop eax |
- | |
424 | or eax, PG_UWR |
- | |
425 | mov ebx, LFB_BASE |
- | |
426 | ; max VGA=640*480*4=1228800 bytes |
- | |
427 | ; + 32*640*4=81920 bytes for mouse pointer |
- | |
428 | mov ecx, (1228800+81920)/4096 |
- | |
429 | call commit_pages |
- | |
430 | mov [LFBAddress], dword LFB_BASE |
- | |
431 | ret |
- | |
432 | @@: |
- | |
433 | test [SCR_MODE], word 0100000000000000b |
- | |
434 | jnz @f |
- | |
435 | mov [BOOT_VARS+BOOT_MTRR], byte 2 |
- | |
436 | ret |
- | |
437 | @@: |
- | |
438 | call init_mtrr |
- | |
439 | - | ||
440 | mov edx, LFB_BASE |
- | |
441 | mov esi, [LFBAddress] |
- | |
442 | mov edi, 0x00C00000 |
- | |
443 | mov dword [exp_lfb+4], edx |
- | |
444 | - | ||
445 | shr edi, 12 |
- | |
446 | mov [pg_count], edi |
- | |
447 | shr edi, 10 |
- | |
448 | - | ||
449 | bt [cpu_caps], CAPS_PSE |
- | |
450 | jnc .map_page_tables |
- | |
451 | or esi, PDE_LARGE+PG_UWR |
- | |
452 | mov edx, sys_proc+PROC.pdt_0+(LFB_BASE shr 20) |
- | |
453 | @@: |
- | |
454 | mov [edx], esi |
- | |
455 | add edx, 4 |
- | |
456 | add esi, 0x00400000 |
- | |
457 | dec edi |
- | |
458 | jnz @B |
- | |
459 | - | ||
460 | bt [cpu_caps], CAPS_PGE |
- | |
461 | jnc @F |
- | |
462 | or dword [sys_proc+PROC.pdt_0+(LFB_BASE shr 20)], PG_GLOBAL |
- | |
463 | @@: |
- | |
464 | mov dword [LFBAddress], LFB_BASE |
- | |
465 | mov eax, cr3 ;flush TLB |
- | |
466 | mov cr3, eax |
- | |
467 | ret |
- | |
468 | - | ||
469 | .map_page_tables: |
- | |
470 | - | ||
471 | @@: |
- | |
472 | call alloc_page |
- | |
473 | stdcall map_page_table, edx, eax |
- | |
474 | add edx, 0x00400000 |
- | |
475 | dec edi |
- | |
476 | jnz @B |
- | |
477 | - | ||
478 | mov eax, [LFBAddress] |
- | |
479 | mov edi, page_tabs + (LFB_BASE shr 10) |
- | |
480 | or eax, PG_GLOBAL+PG_UWR |
- | |
481 | and eax, [pte_valid_mask] |
- | |
482 | mov ecx, [pg_count] |
- | |
483 | cld |
- | |
484 | @@: |
- | |
485 | stosd |
- | |
486 | add eax, 0x1000 |
- | |
487 | loop @B |
- | |
488 | - | ||
489 | mov dword [LFBAddress], LFB_BASE |
- | |
490 | mov eax, cr3 ;flush TLB |
- | |
491 | mov cr3, eax |
- | |
492 | - | ||
493 | ret |
- | |
494 | endp |
405 | endp |
495 | 406 | ||
496 | align 4 |
407 | align 4 |
497 | proc new_mem_resize stdcall, new_size:dword |
408 | proc new_mem_resize stdcall, new_size:dword |
498 | 409 | ||
499 | push ebx |
410 | push ebx |
500 | push esi |
411 | push esi |
501 | push edi |
412 | push edi |
502 | 413 | ||
503 | mov edx, [current_slot] |
414 | mov edx, [current_slot] |
504 | mov ebx, [edx+APPDATA.process] |
415 | mov ebx, [edx+APPDATA.process] |
505 | 416 | ||
506 | cmp [ebx+PROC.heap_base], 0 |
417 | cmp [ebx+PROC.heap_base], 0 |
507 | jne .exit |
418 | jne .exit |
508 | 419 | ||
509 | mov edi, [new_size] |
420 | mov edi, [new_size] |
510 | add edi, 4095 |
421 | add edi, 4095 |
511 | and edi, not 4095 |
422 | and edi, not 4095 |
512 | mov [new_size], edi |
423 | mov [new_size], edi |
513 | 424 | ||
514 | mov esi, [ebx+PROC.mem_used] |
425 | mov esi, [ebx+PROC.mem_used] |
515 | add esi, 4095 |
426 | add esi, 4095 |
516 | and esi, not 4095 |
427 | and esi, not 4095 |
517 | 428 | ||
518 | cmp edi, esi |
429 | cmp edi, esi |
519 | ja .expand |
430 | ja .expand |
520 | je .exit |
431 | je .exit |
521 | 432 | ||
522 | mov ebx, edi |
433 | mov ebx, edi |
523 | shr edi, 12 |
434 | shr edi, 12 |
524 | shr esi, 12 |
435 | shr esi, 12 |
525 | 436 | ||
526 | mov ecx, pg_data.mutex |
437 | mov ecx, pg_data.mutex |
527 | call mutex_lock |
438 | call mutex_lock |
528 | @@: |
439 | @@: |
529 | mov eax, [app_page_tabs+edi*4] |
440 | mov eax, [app_page_tabs+edi*4] |
530 | test eax, 1 |
441 | test eax, 1 |
531 | jz .next |
442 | jz .next |
532 | 443 | ||
533 | mov dword [app_page_tabs+edi*4], 0 |
444 | mov dword [app_page_tabs+edi*4], 0 |
534 | invlpg [ebx] |
445 | invlpg [ebx] |
535 | call free_page |
446 | call free_page |
536 | 447 | ||
537 | .next: |
448 | .next: |
538 | inc edi |
449 | inc edi |
539 | add ebx, 0x1000 |
450 | add ebx, 0x1000 |
540 | cmp edi, esi |
451 | cmp edi, esi |
541 | jb @B |
452 | jb @B |
542 | 453 | ||
543 | mov ecx, pg_data.mutex |
454 | mov ecx, pg_data.mutex |
544 | call mutex_unlock |
455 | call mutex_unlock |
545 | 456 | ||
546 | .update_size: |
457 | .update_size: |
547 | mov edx, [current_slot] |
458 | mov edx, [current_slot] |
548 | mov ebx, [new_size] |
459 | mov ebx, [new_size] |
549 | mov edx, [edx+APPDATA.process] |
460 | mov edx, [edx+APPDATA.process] |
550 | mov [edx+PROC.mem_used], ebx |
461 | mov [edx+PROC.mem_used], ebx |
551 | .exit: |
462 | .exit: |
552 | pop edi |
463 | pop edi |
553 | pop esi |
464 | pop esi |
554 | pop ebx |
465 | pop ebx |
555 | xor eax, eax |
466 | xor eax, eax |
556 | ret |
467 | ret |
557 | 468 | ||
558 | .expand: |
469 | .expand: |
559 | 470 | ||
560 | mov ecx, pg_data.mutex |
471 | mov ecx, pg_data.mutex |
561 | call mutex_lock |
472 | call mutex_lock |
562 | 473 | ||
563 | xchg esi, edi |
474 | xchg esi, edi |
564 | 475 | ||
565 | push esi ;new size |
476 | push esi ;new size |
566 | push edi ;old size |
477 | push edi ;old size |
567 | 478 | ||
568 | add edi, 0x3FFFFF |
479 | add edi, 0x3FFFFF |
569 | and edi, not(0x3FFFFF) |
480 | and edi, not(0x3FFFFF) |
570 | add esi, 0x3FFFFF |
481 | add esi, 0x3FFFFF |
571 | and esi, not(0x3FFFFF) |
482 | and esi, not(0x3FFFFF) |
572 | 483 | ||
573 | cmp edi, esi |
484 | cmp edi, esi |
574 | jae .grow |
485 | jae .grow |
575 | @@: |
486 | @@: |
576 | call alloc_page |
487 | call alloc_page |
577 | test eax, eax |
488 | test eax, eax |
578 | jz .exit_fail |
489 | jz .exit_fail |
579 | 490 | ||
580 | stdcall map_page_table, edi, eax |
491 | stdcall map_page_table, edi, eax |
581 | 492 | ||
582 | push edi |
493 | push edi |
583 | shr edi, 10 |
494 | shr edi, 10 |
584 | add edi, page_tabs |
495 | add edi, page_tabs |
585 | mov ecx, 1024 |
496 | mov ecx, 1024 |
586 | xor eax, eax |
497 | xor eax, eax |
587 | cld |
498 | cld |
588 | rep stosd |
499 | rep stosd |
589 | pop edi |
500 | pop edi |
590 | 501 | ||
591 | add edi, 0x00400000 |
502 | add edi, 0x00400000 |
592 | cmp edi, esi |
503 | cmp edi, esi |
593 | jb @B |
504 | jb @B |
594 | .grow: |
505 | .grow: |
595 | pop edi ;old size |
506 | pop edi ;old size |
596 | pop ecx ;new size |
507 | pop ecx ;new size |
597 | 508 | ||
598 | shr edi, 10 |
509 | shr edi, 10 |
599 | shr ecx, 10 |
510 | shr ecx, 10 |
600 | sub ecx, edi |
511 | sub ecx, edi |
601 | shr ecx, 2 ;pages count |
512 | shr ecx, 2 ;pages count |
602 | mov eax, 2 |
513 | mov eax, 2 |
603 | 514 | ||
604 | add edi, app_page_tabs |
515 | add edi, app_page_tabs |
605 | rep stosd |
516 | rep stosd |
606 | 517 | ||
607 | mov ecx, pg_data.mutex |
518 | mov ecx, pg_data.mutex |
608 | call mutex_unlock |
519 | call mutex_unlock |
609 | 520 | ||
610 | jmp .update_size |
521 | jmp .update_size |
611 | 522 | ||
612 | .exit_fail: |
523 | .exit_fail: |
613 | mov ecx, pg_data.mutex |
524 | mov ecx, pg_data.mutex |
614 | call mutex_unlock |
525 | call mutex_unlock |
615 | 526 | ||
616 | add esp, 8 |
527 | add esp, 8 |
617 | pop edi |
528 | pop edi |
618 | pop esi |
529 | pop esi |
619 | pop ebx |
530 | pop ebx |
620 | xor eax, eax |
531 | xor eax, eax |
621 | inc eax |
532 | inc eax |
622 | ret |
533 | ret |
623 | endp |
534 | endp |
624 | 535 | ||
625 | 536 | ||
626 | ; param |
537 | ; param |
627 | ; eax= linear address |
538 | ; eax= linear address |
628 | ; |
539 | ; |
629 | ; retval |
540 | ; retval |
630 | ; eax= phisical page address |
541 | ; eax= phisical page address |
631 | 542 | ||
632 | align 4 |
543 | align 4 |
633 | get_pg_addr: |
544 | get_pg_addr: |
634 | sub eax, OS_BASE |
545 | sub eax, OS_BASE |
635 | cmp eax, 0x400000 |
546 | cmp eax, 0x400000 |
636 | jb @f |
547 | jb @f |
637 | shr eax, 12 |
548 | shr eax, 12 |
638 | mov eax, [page_tabs+(eax+(OS_BASE shr 12))*4] |
549 | mov eax, [page_tabs+(eax+(OS_BASE shr 12))*4] |
639 | @@: |
550 | @@: |
640 | and eax, 0xFFFFF000 |
551 | and eax, 0xFFFFF000 |
641 | ret |
552 | ret |
642 | 553 | ||
643 | 554 | ||
644 | align 4 |
555 | align 4 |
645 | ; Now it is called from core/sys32::exc_c (see stack frame there) |
556 | ; Now it is called from core/sys32::exc_c (see stack frame there) |
646 | proc page_fault_handler |
557 | proc page_fault_handler |
647 | 558 | ||
648 | .err_addr equ ebp-4 |
559 | .err_addr equ ebp-4 |
649 | 560 | ||
650 | push ebx ;save exception number (#PF) |
561 | push ebx ;save exception number (#PF) |
651 | mov ebp, esp |
562 | mov ebp, esp |
652 | mov ebx, cr2 |
563 | mov ebx, cr2 |
653 | push ebx ;that is locals: .err_addr = cr2 |
564 | push ebx ;that is locals: .err_addr = cr2 |
654 | inc [pg_data.pages_faults] |
565 | inc [pg_data.pages_faults] |
655 | 566 | ||
656 | mov eax, [pf_err_code] |
567 | mov eax, [pf_err_code] |
657 | 568 | ||
658 | cmp ebx, OS_BASE ;ebx == .err_addr |
569 | cmp ebx, OS_BASE ;ebx == .err_addr |
659 | jb .user_space ;страница в памяти приложения ; |
570 | jb .user_space ;страница в памяти приложения ; |
660 | 571 | ||
661 | cmp ebx, page_tabs |
572 | cmp ebx, page_tabs |
662 | jb .kernel_space ;страница в памяти ядра |
573 | jb .kernel_space ;страница в памяти ядра |
663 | 574 | ||
664 | cmp ebx, kernel_tabs |
575 | cmp ebx, kernel_tabs |
665 | jb .alloc;.app_tabs ;таблицы страниц приложения ; |
576 | jb .alloc;.app_tabs ;таблицы страниц приложения ; |
666 | ;просто создадим одну |
577 | ;просто создадим одну |
667 | if 0 ;пока это просто лишнее |
578 | if 0 ;пока это просто лишнее |
668 | cmp ebx, LFB_BASE |
579 | cmp ebx, LFB_BASE |
669 | jb .core_tabs ;таблицы страниц ядра |
580 | jb .core_tabs ;таблицы страниц ядра |
670 | ;Ошибка |
581 | ;Ошибка |
671 | .lfb: |
582 | .lfb: |
672 | ;область LFB |
583 | ;область LFB |
673 | ;Ошибка |
584 | ;Ошибка |
674 | jmp .fail |
585 | jmp .fail |
675 | end if |
586 | end if |
676 | .core_tabs: |
587 | .core_tabs: |
677 | .fail: ;simply return to caller |
588 | .fail: ;simply return to caller |
678 | mov esp, ebp |
589 | mov esp, ebp |
679 | pop ebx ;restore exception number (#PF) |
590 | pop ebx ;restore exception number (#PF) |
680 | ret |
591 | ret |
681 | 592 | ||
682 | .user_space: |
593 | .user_space: |
683 | test eax, PG_READ |
594 | test eax, PG_READ |
684 | jnz .err_access ;Страница присутствует |
595 | jnz .err_access ;Страница присутствует |
685 | ;Ошибка доступа ? |
596 | ;Ошибка доступа ? |
686 | 597 | ||
687 | shr ebx, 12 |
598 | shr ebx, 12 |
688 | mov ecx, ebx |
599 | mov ecx, ebx |
689 | shr ecx, 10 |
600 | shr ecx, 10 |
690 | mov edx, [master_tab+ecx*4] |
601 | mov edx, [master_tab+ecx*4] |
691 | test edx, PG_READ |
602 | test edx, PG_READ |
692 | jz .fail ;таблица страниц не создана |
603 | jz .fail ;таблица страниц не создана |
693 | ;неверный адрес в программе |
604 | ;неверный адрес в программе |
694 | 605 | ||
695 | mov eax, [page_tabs+ebx*4] |
606 | mov eax, [page_tabs+ebx*4] |
696 | test eax, 2 |
607 | test eax, 2 |
697 | jz .fail ;адрес не зарезервирован для ; |
608 | jz .fail ;адрес не зарезервирован для ; |
698 | ;использования. Ошибка |
609 | ;использования. Ошибка |
699 | .alloc: |
610 | .alloc: |
700 | call alloc_page |
611 | call alloc_page |
701 | test eax, eax |
612 | test eax, eax |
702 | jz .fail |
613 | jz .fail |
703 | 614 | ||
704 | stdcall map_page, [.err_addr], eax, PG_UWR |
615 | stdcall map_page, [.err_addr], eax, PG_UWR |
705 | 616 | ||
706 | mov edi, [.err_addr] |
617 | mov edi, [.err_addr] |
707 | and edi, 0xFFFFF000 |
618 | and edi, 0xFFFFF000 |
708 | mov ecx, 1024 |
619 | mov ecx, 1024 |
709 | xor eax, eax |
620 | xor eax, eax |
710 | ;cld ;caller is duty for this |
621 | ;cld ;caller is duty for this |
711 | rep stosd |
622 | rep stosd |
712 | .exit: ;iret with repeat fault instruction |
623 | .exit: ;iret with repeat fault instruction |
713 | add esp, 12;clear in stack: locals(.err_addr) + #PF + ret_to_caller |
624 | add esp, 12;clear in stack: locals(.err_addr) + #PF + ret_to_caller |
714 | restore_ring3_context |
625 | restore_ring3_context |
715 | iretd |
626 | iretd |
716 | 627 | ||
717 | .err_access: |
628 | .err_access: |
718 | ; access denied? this may be a result of copy-on-write protection for DLL |
629 | ; access denied? this may be a result of copy-on-write protection for DLL |
719 | ; check list of HDLLs |
630 | ; check list of HDLLs |
720 | and ebx, not 0xFFF |
631 | and ebx, not 0xFFF |
721 | mov eax, [current_process] |
632 | mov eax, [current_process] |
722 | mov eax, [eax+PROC.dlls_list_ptr] |
633 | mov eax, [eax+PROC.dlls_list_ptr] |
723 | test eax, eax |
634 | test eax, eax |
724 | jz .fail |
635 | jz .fail |
725 | mov esi, [eax+HDLL.fd] |
636 | mov esi, [eax+HDLL.fd] |
726 | .scan_hdll: |
637 | .scan_hdll: |
727 | cmp esi, eax |
638 | cmp esi, eax |
728 | jz .fail |
639 | jz .fail |
729 | mov edx, ebx |
640 | mov edx, ebx |
730 | sub edx, [esi+HDLL.base] |
641 | sub edx, [esi+HDLL.base] |
731 | cmp edx, [esi+HDLL.size] |
642 | cmp edx, [esi+HDLL.size] |
732 | jb .fault_in_hdll |
643 | jb .fault_in_hdll |
733 | .scan_hdll.next: |
644 | .scan_hdll.next: |
734 | mov esi, [esi+HDLL.fd] |
645 | mov esi, [esi+HDLL.fd] |
735 | jmp .scan_hdll |
646 | jmp .scan_hdll |
736 | .fault_in_hdll: |
647 | .fault_in_hdll: |
737 | ; allocate new page, map it as rw and copy data |
648 | ; allocate new page, map it as rw and copy data |
738 | call alloc_page |
649 | call alloc_page |
739 | test eax, eax |
650 | test eax, eax |
740 | jz .fail |
651 | jz .fail |
741 | stdcall map_page, ebx, eax, PG_UWR |
652 | stdcall map_page, ebx, eax, PG_UWR |
742 | mov edi, ebx |
653 | mov edi, ebx |
743 | mov ecx, 1024 |
654 | mov ecx, 1024 |
744 | sub ebx, [esi+HDLL.base] |
655 | sub ebx, [esi+HDLL.base] |
745 | mov esi, [esi+HDLL.parent] |
656 | mov esi, [esi+HDLL.parent] |
746 | mov esi, [esi+DLLDESCR.data] |
657 | mov esi, [esi+DLLDESCR.data] |
747 | add esi, ebx |
658 | add esi, ebx |
748 | rep movsd |
659 | rep movsd |
749 | jmp .exit |
660 | jmp .exit |
750 | 661 | ||
751 | .kernel_space: |
662 | .kernel_space: |
752 | test eax, PG_READ |
663 | test eax, PG_READ |
753 | jz .fail ;страница не присутствует |
664 | jz .fail ;страница не присутствует |
754 | 665 | ||
755 | test eax, 12 ;U/S (+below) |
666 | test eax, 12 ;U/S (+below) |
756 | jnz .fail ;приложение обратилось к памяти |
667 | jnz .fail ;приложение обратилось к памяти |
757 | ;ядра |
668 | ;ядра |
758 | ;test eax, 8 |
669 | ;test eax, 8 |
759 | ;jnz .fail ;установлен зарезервированный бит |
670 | ;jnz .fail ;установлен зарезервированный бит |
760 | ;в таблицах страниц. добавлено в P4/Xeon |
671 | ;в таблицах страниц. добавлено в P4/Xeon |
761 | 672 | ||
762 | ;попытка записи в защищённую страницу ядра |
673 | ;попытка записи в защищённую страницу ядра |
763 | 674 | ||
764 | cmp ebx, tss._io_map_0 |
675 | cmp ebx, tss._io_map_0 |
765 | jb .fail |
676 | jb .fail |
766 | 677 | ||
767 | cmp ebx, tss._io_map_0+8192 |
678 | cmp ebx, tss._io_map_0+8192 |
768 | jae .fail |
679 | jae .fail |
769 | 680 | ||
770 | ; io permission map |
681 | ; io permission map |
771 | ; copy-on-write protection |
682 | ; copy-on-write protection |
772 | 683 | ||
773 | call alloc_page |
684 | call alloc_page |
774 | test eax, eax |
685 | test eax, eax |
775 | jz .fail |
686 | jz .fail |
776 | 687 | ||
777 | push eax |
688 | push eax |
778 | stdcall map_page, [.err_addr], eax, dword PG_SWR |
689 | stdcall map_page, [.err_addr], eax, dword PG_SWR |
779 | pop eax |
690 | pop eax |
780 | mov edi, [.err_addr] |
691 | mov edi, [.err_addr] |
781 | and edi, -4096 |
692 | and edi, -4096 |
782 | lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 |
693 | lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 |
783 | 694 | ||
784 | mov ebx, esi |
695 | mov ebx, esi |
785 | shr ebx, 12 |
696 | shr ebx, 12 |
786 | mov edx, [current_slot] |
697 | mov edx, [current_slot] |
787 | or eax, PG_SWR |
698 | or eax, PG_SWR |
788 | mov [edx+APPDATA.io_map+ebx*4], eax |
699 | mov [edx+APPDATA.io_map+ebx*4], eax |
789 | 700 | ||
790 | add esi, [default_io_map] |
701 | add esi, [default_io_map] |
791 | mov ecx, 4096/4 |
702 | mov ecx, 4096/4 |
792 | ;cld ;caller is duty for this |
703 | ;cld ;caller is duty for this |
793 | rep movsd |
704 | rep movsd |
794 | jmp .exit |
705 | jmp .exit |
795 | endp |
706 | endp |
796 | 707 | ||
797 | ; returns number of mapped bytes |
708 | ; returns number of mapped bytes |
798 | proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\ |
709 | proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\ |
799 | ofs:dword,buf_size:dword,req_access:dword |
710 | ofs:dword,buf_size:dword,req_access:dword |
800 | locals |
711 | locals |
801 | count dd ? |
712 | count dd ? |
802 | process dd ? |
713 | process dd ? |
803 | endl |
714 | endl |
804 | 715 | ||
805 | mov [count], 0 |
716 | mov [count], 0 |
806 | cmp [buf_size], 0 |
717 | cmp [buf_size], 0 |
807 | jz .exit |
718 | jz .exit |
808 | 719 | ||
809 | mov eax, [slot] |
720 | mov eax, [slot] |
810 | shl eax, 8 |
721 | shl eax, 8 |
811 | mov eax, [SLOT_BASE+eax+APPDATA.process] |
722 | mov eax, [SLOT_BASE+eax+APPDATA.process] |
812 | test eax, eax |
723 | test eax, eax |
813 | jz .exit |
724 | jz .exit |
814 | 725 | ||
815 | mov [process], eax |
726 | mov [process], eax |
816 | mov ebx, [ofs] |
727 | mov ebx, [ofs] |
817 | shr ebx, 22 |
728 | shr ebx, 22 |
818 | mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table |
729 | mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table |
819 | mov esi, [ipc_ptab] |
730 | mov esi, [ipc_ptab] |
820 | and eax, 0xFFFFF000 |
731 | and eax, 0xFFFFF000 |
821 | jz .exit |
732 | jz .exit |
822 | stdcall map_page, esi, eax, PG_SWR |
733 | stdcall map_page, esi, eax, PG_SWR |
823 | @@: |
734 | @@: |
824 | mov edi, [lin_addr] |
735 | mov edi, [lin_addr] |
825 | and edi, 0xFFFFF000 |
736 | and edi, 0xFFFFF000 |
826 | mov ecx, [buf_size] |
737 | mov ecx, [buf_size] |
827 | add ecx, 4095 |
738 | add ecx, 4095 |
828 | shr ecx, 12 |
739 | shr ecx, 12 |
829 | inc ecx ; ??????????? |
740 | inc ecx ; ??????????? |
830 | 741 | ||
831 | mov edx, [ofs] |
742 | mov edx, [ofs] |
832 | shr edx, 12 |
743 | shr edx, 12 |
833 | and edx, 0x3FF |
744 | and edx, 0x3FF |
834 | .map: |
745 | .map: |
835 | stdcall safe_map_page, [slot], [req_access], [ofs] |
746 | stdcall safe_map_page, [slot], [req_access], [ofs] |
836 | jnc .exit |
747 | jnc .exit |
837 | add [count], PAGE_SIZE |
748 | add [count], PAGE_SIZE |
838 | add [ofs], PAGE_SIZE |
749 | add [ofs], PAGE_SIZE |
839 | dec ecx |
750 | dec ecx |
840 | jz .exit |
751 | jz .exit |
841 | 752 | ||
842 | add edi, PAGE_SIZE |
753 | add edi, PAGE_SIZE |
843 | inc edx |
754 | inc edx |
844 | cmp edx, 1024 |
755 | cmp edx, 1024 |
845 | jnz .map |
756 | jnz .map |
846 | 757 | ||
847 | inc ebx |
758 | inc ebx |
848 | mov eax, [process] |
759 | mov eax, [process] |
849 | mov eax, [eax+PROC.pdt_0+ebx*4] |
760 | mov eax, [eax+PROC.pdt_0+ebx*4] |
850 | and eax, 0xFFFFF000 |
761 | and eax, 0xFFFFF000 |
851 | jz .exit |
762 | jz .exit |
852 | 763 | ||
853 | stdcall map_page, esi, eax, PG_SWR |
764 | stdcall map_page, esi, eax, PG_SWR |
854 | xor edx, edx |
765 | xor edx, edx |
855 | jmp .map |
766 | jmp .map |
856 | .exit: |
767 | .exit: |
857 | mov eax, [count] |
768 | mov eax, [count] |
858 | ret |
769 | ret |
859 | endp |
770 | endp |
860 | 771 | ||
861 | proc map_memEx stdcall, lin_addr:dword,slot:dword,\ |
772 | proc map_memEx stdcall, lin_addr:dword,slot:dword,\ |
862 | ofs:dword,buf_size:dword,req_access:dword |
773 | ofs:dword,buf_size:dword,req_access:dword |
863 | locals |
774 | locals |
864 | count dd ? |
775 | count dd ? |
865 | process dd ? |
776 | process dd ? |
866 | endl |
777 | endl |
867 | 778 | ||
868 | mov [count], 0 |
779 | mov [count], 0 |
869 | cmp [buf_size], 0 |
780 | cmp [buf_size], 0 |
870 | jz .exit |
781 | jz .exit |
871 | 782 | ||
872 | mov eax, [slot] |
783 | mov eax, [slot] |
873 | shl eax, 8 |
784 | shl eax, 8 |
874 | mov eax, [SLOT_BASE+eax+APPDATA.process] |
785 | mov eax, [SLOT_BASE+eax+APPDATA.process] |
875 | test eax, eax |
786 | test eax, eax |
876 | jz .exit |
787 | jz .exit |
877 | 788 | ||
878 | mov [process], eax |
789 | mov [process], eax |
879 | mov ebx, [ofs] |
790 | mov ebx, [ofs] |
880 | shr ebx, 22 |
791 | shr ebx, 22 |
881 | mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table |
792 | mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table |
882 | mov esi, [proc_mem_tab] |
793 | mov esi, [proc_mem_tab] |
883 | and eax, 0xFFFFF000 |
794 | and eax, 0xFFFFF000 |
884 | jz .exit |
795 | jz .exit |
885 | stdcall map_page, esi, eax, PG_SWR |
796 | stdcall map_page, esi, eax, PG_SWR |
886 | @@: |
797 | @@: |
887 | mov edi, [lin_addr] |
798 | mov edi, [lin_addr] |
888 | and edi, 0xFFFFF000 |
799 | and edi, 0xFFFFF000 |
889 | mov ecx, [buf_size] |
800 | mov ecx, [buf_size] |
890 | add ecx, 4095 |
801 | add ecx, 4095 |
891 | shr ecx, 12 |
802 | shr ecx, 12 |
892 | inc ecx ; ??????????? |
803 | inc ecx ; ??????????? |
893 | 804 | ||
894 | mov edx, [ofs] |
805 | mov edx, [ofs] |
895 | shr edx, 12 |
806 | shr edx, 12 |
896 | and edx, 0x3FF |
807 | and edx, 0x3FF |
897 | .map: |
808 | .map: |
898 | stdcall safe_map_page, [slot], [req_access], [ofs] |
809 | stdcall safe_map_page, [slot], [req_access], [ofs] |
899 | jnc .exit |
810 | jnc .exit |
900 | add [count], PAGE_SIZE |
811 | add [count], PAGE_SIZE |
901 | add [ofs], PAGE_SIZE |
812 | add [ofs], PAGE_SIZE |
902 | dec ecx |
813 | dec ecx |
903 | jz .exit |
814 | jz .exit |
904 | 815 | ||
905 | add edi, PAGE_SIZE |
816 | add edi, PAGE_SIZE |
906 | inc edx |
817 | inc edx |
907 | cmp edx, 1024 |
818 | cmp edx, 1024 |
908 | jnz .map |
819 | jnz .map |
909 | 820 | ||
910 | inc ebx |
821 | inc ebx |
911 | mov eax, [process] |
822 | mov eax, [process] |
912 | mov eax, [eax+PROC.pdt_0+ebx*4] |
823 | mov eax, [eax+PROC.pdt_0+ebx*4] |
913 | and eax, 0xFFFFF000 |
824 | and eax, 0xFFFFF000 |
914 | jz .exit |
825 | jz .exit |
915 | 826 | ||
916 | stdcall map_page, esi, eax, PG_SWR |
827 | stdcall map_page, esi, eax, PG_SWR |
917 | xor edx, edx |
828 | xor edx, edx |
918 | jmp .map |
829 | jmp .map |
919 | .exit: |
830 | .exit: |
920 | mov eax, [count] |
831 | mov eax, [count] |
921 | ret |
832 | ret |
922 | endp |
833 | endp |
923 | 834 | ||
924 | ; in: esi+edx*4 = pointer to page table entry |
835 | ; in: esi+edx*4 = pointer to page table entry |
925 | ; in: [slot], [req_access], [ofs] on the stack |
836 | ; in: [slot], [req_access], [ofs] on the stack |
926 | ; in: edi = linear address to map |
837 | ; in: edi = linear address to map |
927 | ; out: CF cleared <=> failed |
838 | ; out: CF cleared <=> failed |
928 | ; destroys: only eax |
839 | ; destroys: only eax |
929 | proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword |
840 | proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword |
930 | mov eax, [esi+edx*4] |
841 | mov eax, [esi+edx*4] |
931 | test al, PG_READ |
842 | test al, PG_READ |
932 | jz .not_present |
843 | jz .not_present |
933 | test al, PG_WRITE |
844 | test al, PG_WRITE |
934 | jz .resolve_readonly |
845 | jz .resolve_readonly |
935 | ; normal case: writable page, just map with requested access |
846 | ; normal case: writable page, just map with requested access |
936 | .map: |
847 | .map: |
937 | stdcall map_page, edi, eax, [req_access] |
848 | stdcall map_page, edi, eax, [req_access] |
938 | stc |
849 | stc |
939 | .fail: |
850 | .fail: |
940 | ret |
851 | ret |
941 | .not_present: |
852 | .not_present: |
942 | ; check for alloc-on-demand page |
853 | ; check for alloc-on-demand page |
943 | test al, 2 |
854 | test al, 2 |
944 | jz .fail |
855 | jz .fail |
945 | ; allocate new page, save it to source page table |
856 | ; allocate new page, save it to source page table |
946 | push ecx |
857 | push ecx |
947 | call alloc_page |
858 | call alloc_page |
948 | pop ecx |
859 | pop ecx |
949 | test eax, eax |
860 | test eax, eax |
950 | jz .fail |
861 | jz .fail |
951 | or al, PG_UWR |
862 | or al, PG_UWR |
952 | mov [esi+edx*4], eax |
863 | mov [esi+edx*4], eax |
953 | jmp .map |
864 | jmp .map |
954 | .resolve_readonly: |
865 | .resolve_readonly: |
955 | ; readonly page, probably copy-on-write |
866 | ; readonly page, probably copy-on-write |
956 | ; check: readonly request of readonly page is ok |
867 | ; check: readonly request of readonly page is ok |
957 | test [req_access], PG_WRITE |
868 | test [req_access], PG_WRITE |
958 | jz .map |
869 | jz .map |
959 | ; find control structure for this page |
870 | ; find control structure for this page |
960 | pushf |
871 | pushf |
961 | cli |
872 | cli |
962 | cld |
873 | cld |
963 | push ebx ecx |
874 | push ebx ecx |
964 | mov eax, [slot] |
875 | mov eax, [slot] |
965 | shl eax, 8 |
876 | shl eax, 8 |
966 | mov eax, [SLOT_BASE+eax+APPDATA.process] |
877 | mov eax, [SLOT_BASE+eax+APPDATA.process] |
967 | mov eax, [eax+PROC.dlls_list_ptr] |
878 | mov eax, [eax+PROC.dlls_list_ptr] |
968 | test eax, eax |
879 | test eax, eax |
969 | jz .no_hdll |
880 | jz .no_hdll |
970 | mov ecx, [eax+HDLL.fd] |
881 | mov ecx, [eax+HDLL.fd] |
971 | .scan_hdll: |
882 | .scan_hdll: |
972 | cmp ecx, eax |
883 | cmp ecx, eax |
973 | jz .no_hdll |
884 | jz .no_hdll |
974 | mov ebx, [ofs] |
885 | mov ebx, [ofs] |
975 | and ebx, not 0xFFF |
886 | and ebx, not 0xFFF |
976 | sub ebx, [ecx+HDLL.base] |
887 | sub ebx, [ecx+HDLL.base] |
977 | cmp ebx, [ecx+HDLL.size] |
888 | cmp ebx, [ecx+HDLL.size] |
978 | jb .hdll_found |
889 | jb .hdll_found |
979 | mov ecx, [ecx+HDLL.fd] |
890 | mov ecx, [ecx+HDLL.fd] |
980 | jmp .scan_hdll |
891 | jmp .scan_hdll |
981 | .no_hdll: |
892 | .no_hdll: |
982 | pop ecx ebx |
893 | pop ecx ebx |
983 | popf |
894 | popf |
984 | clc |
895 | clc |
985 | ret |
896 | ret |
986 | .hdll_found: |
897 | .hdll_found: |
987 | ; allocate page, save it in page table, map it, copy contents from base |
898 | ; allocate page, save it in page table, map it, copy contents from base |
988 | mov eax, [ecx+HDLL.parent] |
899 | mov eax, [ecx+HDLL.parent] |
989 | add ebx, [eax+DLLDESCR.data] |
900 | add ebx, [eax+DLLDESCR.data] |
990 | call alloc_page |
901 | call alloc_page |
991 | test eax, eax |
902 | test eax, eax |
992 | jz .no_hdll |
903 | jz .no_hdll |
993 | or al, PG_UWR |
904 | or al, PG_UWR |
994 | mov [esi+edx*4], eax |
905 | mov [esi+edx*4], eax |
995 | stdcall map_page, edi, eax, [req_access] |
906 | stdcall map_page, edi, eax, [req_access] |
996 | push esi edi |
907 | push esi edi |
997 | mov esi, ebx |
908 | mov esi, ebx |
998 | mov ecx, 4096/4 |
909 | mov ecx, 4096/4 |
999 | rep movsd |
910 | rep movsd |
1000 | pop edi esi |
911 | pop edi esi |
1001 | pop ecx ebx |
912 | pop ecx ebx |
1002 | popf |
913 | popf |
1003 | stc |
914 | stc |
1004 | ret |
915 | ret |
1005 | endp |
916 | endp |
1006 | 917 | ||
1007 | sys_IPC: |
918 | sys_IPC: |
1008 | ;input: |
919 | ;input: |
1009 | ; ebx=1 - set ipc buffer area |
920 | ; ebx=1 - set ipc buffer area |
1010 | ; ecx=address of buffer |
921 | ; ecx=address of buffer |
1011 | ; edx=size of buffer |
922 | ; edx=size of buffer |
1012 | ; eax=2 - send message |
923 | ; eax=2 - send message |
1013 | ; ebx=PID |
924 | ; ebx=PID |
1014 | ; ecx=address of message |
925 | ; ecx=address of message |
1015 | ; edx=size of message |
926 | ; edx=size of message |
1016 | 927 | ||
1017 | dec ebx |
928 | dec ebx |
1018 | jnz @f |
929 | jnz @f |
1019 | 930 | ||
1020 | mov eax, [current_slot] |
931 | mov eax, [current_slot] |
1021 | pushf |
932 | pushf |
1022 | cli |
933 | cli |
1023 | mov [eax+APPDATA.ipc_start], ecx ;set fields in extended information area |
934 | mov [eax+APPDATA.ipc_start], ecx ;set fields in extended information area |
1024 | mov [eax+APPDATA.ipc_size], edx |
935 | mov [eax+APPDATA.ipc_size], edx |
1025 | 936 | ||
1026 | add edx, ecx |
937 | add edx, ecx |
1027 | add edx, 4095 |
938 | add edx, 4095 |
1028 | and edx, not 4095 |
939 | and edx, not 4095 |
1029 | 940 | ||
1030 | .touch: |
941 | .touch: |
1031 | mov eax, [ecx] |
942 | mov eax, [ecx] |
1032 | add ecx, 0x1000 |
943 | add ecx, 0x1000 |
1033 | cmp ecx, edx |
944 | cmp ecx, edx |
1034 | jb .touch |
945 | jb .touch |
1035 | 946 | ||
1036 | popf |
947 | popf |
1037 | mov [esp+32], ebx ;ebx=0 |
948 | mov [esp+32], ebx ;ebx=0 |
1038 | ret |
949 | ret |
1039 | 950 | ||
1040 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
951 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1041 | ;2 |
952 | ;2 |
1042 | @@: |
953 | @@: |
1043 | dec ebx |
954 | dec ebx |
1044 | jnz @f |
955 | jnz @f |
1045 | 956 | ||
1046 | stdcall sys_ipc_send, ecx, edx, esi |
957 | stdcall sys_ipc_send, ecx, edx, esi |
1047 | mov [esp+32], eax |
958 | mov [esp+32], eax |
1048 | ret |
959 | ret |
1049 | @@: |
960 | @@: |
1050 | or eax, -1 |
961 | or eax, -1 |
1051 | mov [esp+32], eax |
962 | mov [esp+32], eax |
1052 | ret |
963 | ret |
1053 | 964 | ||
1054 | proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword |
965 | proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword |
1055 | locals |
966 | locals |
1056 | dst_slot dd ? |
967 | dst_slot dd ? |
1057 | dst_offset dd ? |
968 | dst_offset dd ? |
1058 | buf_size dd ? |
969 | buf_size dd ? |
1059 | used_buf dd ? |
970 | used_buf dd ? |
1060 | endl |
971 | endl |
1061 | 972 | ||
1062 | pushf |
973 | pushf |
1063 | cli |
974 | cli |
1064 | 975 | ||
1065 | mov eax, [PID] |
976 | mov eax, [PID] |
1066 | call pid_to_slot |
977 | call pid_to_slot |
1067 | test eax, eax |
978 | test eax, eax |
1068 | jz .no_pid |
979 | jz .no_pid |
1069 | 980 | ||
1070 | mov [dst_slot], eax |
981 | mov [dst_slot], eax |
1071 | shl eax, 8 |
982 | shl eax, 8 |
1072 | mov edi, [eax+SLOT_BASE+APPDATA.ipc_start] ;is ipc area defined? |
983 | mov edi, [eax+SLOT_BASE+APPDATA.ipc_start] ;is ipc area defined? |
1073 | test edi, edi |
984 | test edi, edi |
1074 | jz .no_ipc_area |
985 | jz .no_ipc_area |
1075 | 986 | ||
1076 | mov ebx, edi |
987 | mov ebx, edi |
1077 | and ebx, 0xFFF |
988 | and ebx, 0xFFF |
1078 | mov [dst_offset], ebx |
989 | mov [dst_offset], ebx |
1079 | 990 | ||
1080 | mov esi, [eax+SLOT_BASE+APPDATA.ipc_size] |
991 | mov esi, [eax+SLOT_BASE+APPDATA.ipc_size] |
1081 | mov [buf_size], esi |
992 | mov [buf_size], esi |
1082 | 993 | ||
1083 | mov ecx, [ipc_tmp] |
994 | mov ecx, [ipc_tmp] |
1084 | cmp esi, 0x40000-0x1000; size of [ipc_tmp] minus one page |
995 | cmp esi, 0x40000-0x1000; size of [ipc_tmp] minus one page |
1085 | jbe @f |
996 | jbe @f |
1086 | push esi edi |
997 | push esi edi |
1087 | add esi, 0x1000 |
998 | add esi, 0x1000 |
1088 | stdcall alloc_kernel_space, esi |
999 | stdcall alloc_kernel_space, esi |
1089 | mov ecx, eax |
1000 | mov ecx, eax |
1090 | pop edi esi |
1001 | pop edi esi |
1091 | @@: |
1002 | @@: |
1092 | mov [used_buf], ecx |
1003 | mov [used_buf], ecx |
1093 | stdcall map_mem_ipc, ecx, [dst_slot], \ |
1004 | stdcall map_mem_ipc, ecx, [dst_slot], \ |
1094 | edi, esi, PG_SWR |
1005 | edi, esi, PG_SWR |
1095 | 1006 | ||
1096 | mov edi, [dst_offset] |
1007 | mov edi, [dst_offset] |
1097 | add edi, [used_buf] |
1008 | add edi, [used_buf] |
1098 | cmp dword [edi], 0 |
1009 | cmp dword [edi], 0 |
1099 | jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now |
1010 | jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now |
1100 | 1011 | ||
1101 | mov edx, dword [edi+4] |
1012 | mov edx, dword [edi+4] |
1102 | lea ebx, [edx+8] |
1013 | lea ebx, [edx+8] |
1103 | add ebx, [msg_size] |
1014 | add ebx, [msg_size] |
1104 | cmp ebx, [buf_size] |
1015 | cmp ebx, [buf_size] |
1105 | ja .buffer_overflow ;esi<0 - not enough memory in buffer |
1016 | ja .buffer_overflow ;esi<0 - not enough memory in buffer |
1106 | 1017 | ||
1107 | mov dword [edi+4], ebx |
1018 | mov dword [edi+4], ebx |
1108 | mov eax, [TASK_BASE] |
1019 | mov eax, [TASK_BASE] |
1109 | mov eax, [eax+0x04] ;eax - our PID |
1020 | mov eax, [eax+0x04] ;eax - our PID |
1110 | add edi, edx |
1021 | add edi, edx |
1111 | mov [edi], eax |
1022 | mov [edi], eax |
1112 | mov ecx, [msg_size] |
1023 | mov ecx, [msg_size] |
1113 | 1024 | ||
1114 | mov [edi+4], ecx |
1025 | mov [edi+4], ecx |
1115 | add edi, 8 |
1026 | add edi, 8 |
1116 | mov esi, [msg_addr] |
1027 | mov esi, [msg_addr] |
1117 | ; add esi, new_app_base |
1028 | ; add esi, new_app_base |
1118 | cld |
1029 | cld |
1119 | rep movsb |
1030 | rep movsb |
1120 | 1031 | ||
1121 | mov ebx, [ipc_tmp] |
1032 | mov ebx, [ipc_tmp] |
1122 | mov edx, ebx |
1033 | mov edx, ebx |
1123 | shr ebx, 12 |
1034 | shr ebx, 12 |
1124 | xor eax, eax |
1035 | xor eax, eax |
1125 | mov [page_tabs+ebx*4], eax |
1036 | mov [page_tabs+ebx*4], eax |
1126 | invlpg [edx] |
1037 | invlpg [edx] |
1127 | 1038 | ||
1128 | mov ebx, [ipc_pdir] |
1039 | mov ebx, [ipc_pdir] |
1129 | mov edx, ebx |
1040 | mov edx, ebx |
1130 | shr ebx, 12 |
1041 | shr ebx, 12 |
1131 | xor eax, eax |
1042 | xor eax, eax |
1132 | mov [page_tabs+ebx*4], eax |
1043 | mov [page_tabs+ebx*4], eax |
1133 | invlpg [edx] |
1044 | invlpg [edx] |
1134 | 1045 | ||
1135 | mov ebx, [ipc_ptab] |
1046 | mov ebx, [ipc_ptab] |
1136 | mov edx, ebx |
1047 | mov edx, ebx |
1137 | shr ebx, 12 |
1048 | shr ebx, 12 |
1138 | xor eax, eax |
1049 | xor eax, eax |
1139 | mov [page_tabs+ebx*4], eax |
1050 | mov [page_tabs+ebx*4], eax |
1140 | invlpg [edx] |
1051 | invlpg [edx] |
1141 | 1052 | ||
1142 | mov eax, [dst_slot] |
1053 | mov eax, [dst_slot] |
1143 | shl eax, 8 |
1054 | shl eax, 8 |
1144 | or [eax+SLOT_BASE+0xA8], dword 0x40 |
1055 | or [eax+SLOT_BASE+0xA8], dword 0x40 |
1145 | push 0 |
1056 | push 0 |
1146 | jmp .ret |
1057 | jmp .ret |
1147 | .no_pid: |
1058 | .no_pid: |
1148 | popf |
1059 | popf |
1149 | mov eax, 4 |
1060 | mov eax, 4 |
1150 | ret |
1061 | ret |
1151 | .no_ipc_area: |
1062 | .no_ipc_area: |
1152 | popf |
1063 | popf |
1153 | xor eax, eax |
1064 | xor eax, eax |
1154 | inc eax |
1065 | inc eax |
1155 | ret |
1066 | ret |
1156 | .ipc_blocked: |
1067 | .ipc_blocked: |
1157 | push 2 |
1068 | push 2 |
1158 | jmp .ret |
1069 | jmp .ret |
1159 | .buffer_overflow: |
1070 | .buffer_overflow: |
1160 | push 3 |
1071 | push 3 |
1161 | .ret: |
1072 | .ret: |
1162 | mov eax, [used_buf] |
1073 | mov eax, [used_buf] |
1163 | cmp eax, [ipc_tmp] |
1074 | cmp eax, [ipc_tmp] |
1164 | je @f |
1075 | je @f |
1165 | stdcall free_kernel_space, eax |
1076 | stdcall free_kernel_space, eax |
1166 | @@: |
1077 | @@: |
1167 | pop eax |
1078 | pop eax |
1168 | popf |
1079 | popf |
1169 | ret |
1080 | ret |
1170 | endp |
1081 | endp |
1171 | 1082 | ||
1172 | align 4 |
1083 | align 4 |
1173 | sysfn_meminfo: |
1084 | sysfn_meminfo: |
1174 | cmp ecx, OS_BASE |
1085 | cmp ecx, OS_BASE |
1175 | jae .fail |
1086 | jae .fail |
1176 | 1087 | ||
1177 | mov eax, [pg_data.pages_count] |
1088 | mov eax, [pg_data.pages_count] |
1178 | mov [ecx], eax |
1089 | mov [ecx], eax |
1179 | shl eax, 12 |
1090 | shl eax, 12 |
1180 | mov [esp+32], eax |
1091 | mov [esp+32], eax |
1181 | mov eax, [pg_data.pages_free] |
1092 | mov eax, [pg_data.pages_free] |
1182 | mov [ecx+4], eax |
1093 | mov [ecx+4], eax |
1183 | mov eax, [pg_data.pages_faults] |
1094 | mov eax, [pg_data.pages_faults] |
1184 | mov [ecx+8], eax |
1095 | mov [ecx+8], eax |
1185 | mov eax, [heap_size] |
1096 | mov eax, [heap_size] |
1186 | mov [ecx+12], eax |
1097 | mov [ecx+12], eax |
1187 | mov eax, [heap_free] |
1098 | mov eax, [heap_free] |
1188 | mov [ecx+16], eax |
1099 | mov [ecx+16], eax |
1189 | mov eax, [heap_blocks] |
1100 | mov eax, [heap_blocks] |
1190 | mov [ecx+20], eax |
1101 | mov [ecx+20], eax |
1191 | mov eax, [free_blocks] |
1102 | mov eax, [free_blocks] |
1192 | mov [ecx+24], eax |
1103 | mov [ecx+24], eax |
1193 | ret |
1104 | ret |
1194 | .fail: |
1105 | .fail: |
1195 | or dword [esp+32], -1 |
1106 | or dword [esp+32], -1 |
1196 | ret |
1107 | ret |
1197 | 1108 | ||
1198 | align 4 |
1109 | align 4 |
1199 | f68: |
1110 | f68: |
1200 | cmp ebx, 4 |
1111 | cmp ebx, 4 |
1201 | jbe sys_sheduler |
1112 | jbe sys_sheduler |
1202 | 1113 | ||
1203 | cmp ebx, 11 |
1114 | cmp ebx, 11 |
1204 | jb .fail |
1115 | jb .fail |
1205 | 1116 | ||
1206 | cmp ebx, 27 |
1117 | cmp ebx, 27 |
1207 | ja .fail |
1118 | ja .fail |
1208 | 1119 | ||
1209 | jmp dword [f68call+ebx*4-11*4] |
1120 | jmp dword [f68call+ebx*4-11*4] |
1210 | .11: |
1121 | .11: |
1211 | call init_heap |
1122 | call init_heap |
1212 | mov [esp+32], eax |
1123 | mov [esp+32], eax |
1213 | ret |
1124 | ret |
1214 | .12: |
1125 | .12: |
1215 | stdcall user_alloc, ecx |
1126 | stdcall user_alloc, ecx |
1216 | mov [esp+32], eax |
1127 | mov [esp+32], eax |
1217 | ret |
1128 | ret |
1218 | .13: |
1129 | .13: |
1219 | stdcall user_free, ecx |
1130 | stdcall user_free, ecx |
1220 | mov [esp+32], eax |
1131 | mov [esp+32], eax |
1221 | ret |
1132 | ret |
1222 | .14: |
1133 | .14: |
1223 | cmp ecx, OS_BASE |
1134 | cmp ecx, OS_BASE |
1224 | jae .fail |
1135 | jae .fail |
1225 | mov edi, ecx |
1136 | mov edi, ecx |
1226 | call get_event_ex |
1137 | call get_event_ex |
1227 | mov [esp+32], eax |
1138 | mov [esp+32], eax |
1228 | ret |
1139 | ret |
1229 | .16: |
1140 | .16: |
1230 | test ecx, ecx |
1141 | test ecx, ecx |
1231 | jz .fail |
1142 | jz .fail |
1232 | cmp ecx, OS_BASE |
1143 | cmp ecx, OS_BASE |
1233 | jae .fail |
1144 | jae .fail |
1234 | stdcall get_service, ecx |
1145 | stdcall get_service, ecx |
1235 | mov [esp+32], eax |
1146 | mov [esp+32], eax |
1236 | ret |
1147 | ret |
1237 | .17: |
1148 | .17: |
1238 | call srv_handlerEx ;ecx |
1149 | call srv_handlerEx ;ecx |
1239 | mov [esp+32], eax |
1150 | mov [esp+32], eax |
1240 | ret |
1151 | ret |
1241 | .19: |
1152 | .19: |
1242 | cmp ecx, OS_BASE |
1153 | cmp ecx, OS_BASE |
1243 | jae .fail |
1154 | jae .fail |
1244 | stdcall load_library, ecx |
1155 | stdcall load_library, ecx |
1245 | mov [esp+32], eax |
1156 | mov [esp+32], eax |
1246 | ret |
1157 | ret |
1247 | .20: |
1158 | .20: |
1248 | mov eax, edx |
1159 | mov eax, edx |
1249 | mov ebx, ecx |
1160 | mov ebx, ecx |
1250 | call user_realloc ;in: eax = pointer, ebx = new size |
1161 | call user_realloc ;in: eax = pointer, ebx = new size |
1251 | mov [esp+32], eax |
1162 | mov [esp+32], eax |
1252 | ret |
1163 | ret |
1253 | .21: |
1164 | .21: |
1254 | cmp ecx, OS_BASE |
1165 | cmp ecx, OS_BASE |
1255 | jae .fail |
1166 | jae .fail |
1256 | 1167 | ||
1257 | cmp edx, OS_BASE |
1168 | cmp edx, OS_BASE |
1258 | jae .fail |
1169 | jae .fail |
1259 | 1170 | ||
1260 | stdcall load_pe_driver, ecx, edx |
1171 | stdcall load_pe_driver, ecx, edx |
1261 | mov [esp+32], eax |
1172 | mov [esp+32], eax |
1262 | ret |
1173 | ret |
1263 | .22: |
1174 | .22: |
1264 | cmp ecx, OS_BASE |
1175 | cmp ecx, OS_BASE |
1265 | jae .fail |
1176 | jae .fail |
1266 | 1177 | ||
1267 | stdcall shmem_open, ecx, edx, esi |
1178 | stdcall shmem_open, ecx, edx, esi |
1268 | mov [esp+24], edx |
1179 | mov [esp+24], edx |
1269 | mov [esp+32], eax |
1180 | mov [esp+32], eax |
1270 | ret |
1181 | ret |
1271 | 1182 | ||
1272 | .23: |
1183 | .23: |
1273 | cmp ecx, OS_BASE |
1184 | cmp ecx, OS_BASE |
1274 | jae .fail |
1185 | jae .fail |
1275 | 1186 | ||
1276 | stdcall shmem_close, ecx |
1187 | stdcall shmem_close, ecx |
1277 | mov [esp+32], eax |
1188 | mov [esp+32], eax |
1278 | ret |
1189 | ret |
1279 | .24: |
1190 | .24: |
1280 | mov eax, [current_slot] |
1191 | mov eax, [current_slot] |
1281 | xchg ecx, [eax+APPDATA.exc_handler] |
1192 | xchg ecx, [eax+APPDATA.exc_handler] |
1282 | xchg edx, [eax+APPDATA.except_mask] |
1193 | xchg edx, [eax+APPDATA.except_mask] |
1283 | mov [esp+32], ecx ; reg_eax+8 |
1194 | mov [esp+32], ecx ; reg_eax+8 |
1284 | mov [esp+20], edx ; reg_ebx+8 |
1195 | mov [esp+20], edx ; reg_ebx+8 |
1285 | ret |
1196 | ret |
1286 | .25: |
1197 | .25: |
1287 | cmp ecx, 32 |
1198 | cmp ecx, 32 |
1288 | jae .fail |
1199 | jae .fail |
1289 | mov eax, [current_slot] |
1200 | mov eax, [current_slot] |
1290 | btr [eax+APPDATA.except_mask], ecx |
1201 | btr [eax+APPDATA.except_mask], ecx |
1291 | setc byte[esp+32] |
1202 | setc byte[esp+32] |
1292 | jecxz @f |
1203 | jecxz @f |
1293 | bts [eax+APPDATA.except_mask], ecx |
1204 | bts [eax+APPDATA.except_mask], ecx |
1294 | @@: |
1205 | @@: |
1295 | ret |
1206 | ret |
1296 | 1207 | ||
1297 | .26: |
1208 | .26: |
1298 | stdcall user_unmap, ecx, edx, esi |
1209 | stdcall user_unmap, ecx, edx, esi |
1299 | mov [esp+32], eax |
1210 | mov [esp+32], eax |
1300 | ret |
1211 | ret |
1301 | 1212 | ||
1302 | .27: |
1213 | .27: |
1303 | cmp ecx, OS_BASE |
1214 | cmp ecx, OS_BASE |
1304 | jae .fail |
1215 | jae .fail |
1305 | 1216 | ||
1306 | stdcall load_file_umode, ecx |
1217 | stdcall load_file_umode, ecx |
1307 | mov [esp+24], edx |
1218 | mov [esp+24], edx |
1308 | mov [esp+32], eax |
1219 | mov [esp+32], eax |
1309 | ret |
1220 | ret |
1310 | 1221 | ||
1311 | .fail: |
1222 | .fail: |
1312 | xor eax, eax |
1223 | xor eax, eax |
1313 | mov [esp+32], eax |
1224 | mov [esp+32], eax |
1314 | ret |
1225 | ret |
1315 | 1226 | ||
1316 | 1227 | ||
1317 | align 4 |
1228 | align 4 |
1318 | f68call: ; keep this table closer to main code |
1229 | f68call: ; keep this table closer to main code |
1319 | 1230 | ||
1320 | dd f68.11 ; init_heap |
1231 | dd f68.11 ; init_heap |
1321 | dd f68.12 ; user_alloc |
1232 | dd f68.12 ; user_alloc |
1322 | dd f68.13 ; user_free |
1233 | dd f68.13 ; user_free |
1323 | dd f68.14 ; get_event_ex |
1234 | dd f68.14 ; get_event_ex |
1324 | dd f68.fail ; moved to f68.24 |
1235 | dd f68.fail ; moved to f68.24 |
1325 | dd f68.16 ; get_service |
1236 | dd f68.16 ; get_service |
1326 | dd f68.17 ; call_service |
1237 | dd f68.17 ; call_service |
1327 | dd f68.fail ; moved to f68.25 |
1238 | dd f68.fail ; moved to f68.25 |
1328 | dd f68.19 ; load_dll |
1239 | dd f68.19 ; load_dll |
1329 | dd f68.20 ; user_realloc |
1240 | dd f68.20 ; user_realloc |
1330 | dd f68.21 ; load_driver |
1241 | dd f68.21 ; load_driver |
1331 | dd f68.22 ; shmem_open |
1242 | dd f68.22 ; shmem_open |
1332 | dd f68.23 ; shmem_close |
1243 | dd f68.23 ; shmem_close |
1333 | dd f68.24 ; set exception handler |
1244 | dd f68.24 ; set exception handler |
1334 | dd f68.25 ; unmask exception |
1245 | dd f68.25 ; unmask exception |
1335 | dd f68.26 ; user_unmap |
1246 | dd f68.26 ; user_unmap |
1336 | dd f68.27 ; load_file_umode |
1247 | dd f68.27 ; load_file_umode |
1337 | 1248 | ||
1338 | 1249 | ||
1339 | align 4 |
1250 | align 4 |
1340 | proc load_pe_driver stdcall, file:dword, cmdline:dword |
1251 | proc load_pe_driver stdcall, file:dword, cmdline:dword |
1341 | push esi |
1252 | push esi |
1342 | 1253 | ||
1343 | stdcall load_PE, [file] |
1254 | stdcall load_PE, [file] |
1344 | test eax, eax |
1255 | test eax, eax |
1345 | jz .fail |
1256 | jz .fail |
1346 | 1257 | ||
1347 | mov esi, eax |
1258 | mov esi, eax |
1348 | push [cmdline] |
1259 | push [cmdline] |
1349 | push DRV_ENTRY |
1260 | push DRV_ENTRY |
1350 | call eax |
1261 | call eax |
1351 | pop ecx |
1262 | pop ecx |
1352 | pop ecx |
1263 | pop ecx |
1353 | test eax, eax |
1264 | test eax, eax |
1354 | jz .fail |
1265 | jz .fail |
1355 | 1266 | ||
1356 | mov [eax+SRV.entry], esi |
1267 | mov [eax+SRV.entry], esi |
1357 | pop esi |
1268 | pop esi |
1358 | ret |
1269 | ret |
1359 | 1270 | ||
1360 | .fail: |
1271 | .fail: |
1361 | xor eax, eax |
1272 | xor eax, eax |
1362 | pop esi |
1273 | pop esi |
1363 | ret |
1274 | ret |
1364 | endp |
1275 | endp |
1365 | 1276 | ||
1366 | align 4 |
1277 | align 4 |
1367 | proc create_ring_buffer stdcall, size:dword, flags:dword |
1278 | proc create_ring_buffer stdcall, size:dword, flags:dword |
1368 | locals |
1279 | locals |
1369 | buf_ptr dd ? |
1280 | buf_ptr dd ? |
1370 | endl |
1281 | endl |
1371 | 1282 | ||
1372 | mov eax, [size] |
1283 | mov eax, [size] |
1373 | test eax, eax |
1284 | test eax, eax |
1374 | jz .fail |
1285 | jz .fail |
1375 | 1286 | ||
1376 | add eax, eax |
1287 | add eax, eax |
1377 | stdcall alloc_kernel_space, eax |
1288 | stdcall alloc_kernel_space, eax |
1378 | test eax, eax |
1289 | test eax, eax |
1379 | jz .fail |
1290 | jz .fail |
1380 | 1291 | ||
1381 | push ebx |
1292 | push ebx |
1382 | 1293 | ||
1383 | mov [buf_ptr], eax |
1294 | mov [buf_ptr], eax |
1384 | 1295 | ||
1385 | mov ebx, [size] |
1296 | mov ebx, [size] |
1386 | shr ebx, 12 |
1297 | shr ebx, 12 |
1387 | push ebx |
1298 | push ebx |
1388 | 1299 | ||
1389 | stdcall alloc_pages, ebx |
1300 | stdcall alloc_pages, ebx |
1390 | pop ecx |
1301 | pop ecx |
1391 | 1302 | ||
1392 | test eax, eax |
1303 | test eax, eax |
1393 | jz .mm_fail |
1304 | jz .mm_fail |
1394 | 1305 | ||
1395 | push edi |
1306 | push edi |
1396 | 1307 | ||
1397 | or eax, [flags] |
1308 | or eax, [flags] |
1398 | mov edi, [buf_ptr] |
1309 | mov edi, [buf_ptr] |
1399 | mov ebx, [buf_ptr] |
1310 | mov ebx, [buf_ptr] |
1400 | mov edx, ecx |
1311 | mov edx, ecx |
1401 | shl edx, 2 |
1312 | shl edx, 2 |
1402 | shr edi, 10 |
1313 | shr edi, 10 |
1403 | @@: |
1314 | @@: |
1404 | mov [page_tabs+edi], eax |
1315 | mov [page_tabs+edi], eax |
1405 | mov [page_tabs+edi+edx], eax |
1316 | mov [page_tabs+edi+edx], eax |
1406 | invlpg [ebx] |
1317 | invlpg [ebx] |
1407 | invlpg [ebx+0x10000] |
1318 | invlpg [ebx+0x10000] |
1408 | add eax, 0x1000 |
1319 | add eax, 0x1000 |
1409 | add ebx, 0x1000 |
1320 | add ebx, 0x1000 |
1410 | add edi, 4 |
1321 | add edi, 4 |
1411 | dec ecx |
1322 | dec ecx |
1412 | jnz @B |
1323 | jnz @B |
1413 | 1324 | ||
1414 | mov eax, [buf_ptr] |
1325 | mov eax, [buf_ptr] |
1415 | pop edi |
1326 | pop edi |
1416 | pop ebx |
1327 | pop ebx |
1417 | ret |
1328 | ret |
1418 | .mm_fail: |
1329 | .mm_fail: |
1419 | stdcall free_kernel_space, [buf_ptr] |
1330 | stdcall free_kernel_space, [buf_ptr] |
1420 | xor eax, eax |
1331 | xor eax, eax |
1421 | pop ebx |
1332 | pop ebx |
1422 | .fail: |
1333 | .fail: |
1423 | ret |
1334 | ret |
1424 | endp |
1335 | endp |
1425 | 1336 | ||
1426 | 1337 | ||
1427 | align 4 |
1338 | align 4 |
1428 | proc print_mem |
1339 | proc print_mem |
1429 | mov edi, BOOT_VAR + 0x9104 |
1340 | mov edi, BOOT_VAR + 0x9104 |
1430 | mov ecx, [edi-4] |
1341 | mov ecx, [edi-4] |
1431 | test ecx, ecx |
1342 | test ecx, ecx |
1432 | jz .done |
1343 | jz .done |
1433 | 1344 | ||
1434 | @@: |
1345 | @@: |
1435 | mov eax, [edi] |
1346 | mov eax, [edi] |
1436 | mov edx, [edi+4] |
1347 | mov edx, [edi+4] |
1437 | add eax, [edi+8] |
1348 | add eax, [edi+8] |
1438 | adc edx, [edi+12] |
1349 | adc edx, [edi+12] |
1439 | 1350 | ||
1440 | DEBUGF 1, "K : E820 %x%x - %x%x type %d\n", \ |
1351 | DEBUGF 1, "K : E820 %x%x - %x%x type %d\n", \ |
1441 | [edi+4], [edi],\ |
1352 | [edi+4], [edi],\ |
1442 | edx, eax, [edi+16] |
1353 | edx, eax, [edi+16] |
1443 | add edi, 20 |
1354 | add edi, 20 |
1444 | dec ecx |
1355 | dec ecx |
1445 | jnz @b |
1356 | jnz @b |
1446 | .done: |
1357 | .done: |
1447 | ret |
1358 | ret |
1448 | endp0>>=> |
1359 | endp0>>=> |