Rev 889 | Rev 908 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 889 | Rev 890 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2007. 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: 889 $ |
8 | $Revision: 890 $ |
9 | 9 | ||
10 | 10 | ||
11 | 11 | ||
12 | MEM_LIST_OFFSET equ 8 |
12 | MEM_LIST_OFFSET equ 8 |
13 | FREE_BLOCK equ 4 |
13 | FREE_BLOCK equ 4 |
14 | USED_BLOCK equ 8 |
14 | USED_BLOCK equ 8 |
15 | DONT_FREE_BLOCK equ 10h |
15 | DONT_FREE_BLOCK equ 10h |
16 | 16 | ||
17 | - | ||
18 | align 4 |
- | |
19 | proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword |
- | |
20 | - | ||
21 | ret |
- | |
22 | endp |
- | |
23 | 17 | ||
24 | 18 | ||
25 | ;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;; |
19 | ;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;; |
26 | 20 | ||
27 | HEAP_TOP equ 0x5FC00000 |
21 | HEAP_TOP equ 0x5FC00000 |
28 | 22 | ||
29 | align 4 |
23 | align 4 |
30 | proc init_heap |
24 | proc init_heap |
31 | 25 | ||
32 | mov ebx,[current_slot] |
26 | mov ebx,[current_slot] |
33 | mov eax, [ebx+APPDATA.heap_top] |
27 | mov eax, [ebx+APPDATA.heap_top] |
34 | test eax, eax |
28 | test eax, eax |
35 | jz @F |
29 | jz @F |
36 | sub eax,[ebx+APPDATA.heap_base] |
30 | sub eax,[ebx+APPDATA.heap_base] |
37 | sub eax, 4096 |
31 | sub eax, 4096 |
38 | ret |
32 | ret |
39 | @@: |
33 | @@: |
40 | mov esi, [ebx+APPDATA.mem_size] |
34 | mov esi, [ebx+APPDATA.mem_size] |
41 | add esi, 4095 |
35 | add esi, 4095 |
42 | and esi, not 4095 |
36 | and esi, not 4095 |
43 | mov [ebx+APPDATA.mem_size], esi |
37 | mov [ebx+APPDATA.mem_size], esi |
44 | mov eax, HEAP_TOP |
38 | mov eax, HEAP_TOP |
45 | mov [ebx+APPDATA.heap_base], esi |
39 | mov [ebx+APPDATA.heap_base], esi |
46 | mov [ebx+APPDATA.heap_top], eax |
40 | mov [ebx+APPDATA.heap_top], eax |
47 | 41 | ||
48 | sub eax, esi |
42 | sub eax, esi |
49 | shr esi, 10 |
43 | shr esi, 10 |
50 | mov ecx, eax |
44 | mov ecx, eax |
51 | sub eax, 4096 |
45 | sub eax, 4096 |
52 | or ecx, FREE_BLOCK |
46 | or ecx, FREE_BLOCK |
53 | mov [page_tabs+esi], ecx |
47 | mov [page_tabs+esi], ecx |
54 | ret |
48 | ret |
55 | endp |
49 | endp |
56 | 50 | ||
57 | align 4 |
51 | align 4 |
- | 52 | _UserAlloc: |
|
58 | proc user_alloc stdcall, alloc_size:dword |
53 | proc user_alloc stdcall, alloc_size:dword |
59 | 54 | ||
60 | push ebx |
55 | push ebx |
61 | push esi |
56 | push esi |
62 | push edi |
57 | push edi |
63 | 58 | ||
64 | mov ecx, [alloc_size] |
59 | mov ecx, [alloc_size] |
65 | add ecx, (4095+4096) |
60 | add ecx, (4095+4096) |
66 | and ecx, not 4095 |
61 | and ecx, not 4095 |
67 | 62 | ||
68 | mov ebx, [current_slot] |
63 | mov ebx, [current_slot] |
69 | mov esi, dword [ebx+APPDATA.heap_base] ; heap_base |
64 | mov esi, dword [ebx+APPDATA.heap_base] ; heap_base |
70 | mov edi, dword [ebx+APPDATA.heap_top] ; heap_top |
65 | mov edi, dword [ebx+APPDATA.heap_top] ; heap_top |
71 | l_0: |
66 | l_0: |
72 | cmp esi, edi |
67 | cmp esi, edi |
73 | jae m_exit |
68 | jae m_exit |
74 | 69 | ||
75 | mov ebx, esi |
70 | mov ebx, esi |
76 | shr ebx, 12 |
71 | shr ebx, 12 |
77 | mov eax, [page_tabs+ebx*4] |
72 | mov eax, [page_tabs+ebx*4] |
78 | test al, FREE_BLOCK |
73 | test al, FREE_BLOCK |
79 | jz test_used |
74 | jz test_used |
80 | and eax, 0xFFFFF000 |
75 | and eax, 0xFFFFF000 |
81 | cmp eax, ecx ;alloc_size |
76 | cmp eax, ecx ;alloc_size |
82 | jb m_next |
77 | jb m_next |
83 | jz @f |
78 | jz @f |
84 | 79 | ||
85 | lea edx, [esi+ecx] |
80 | lea edx, [esi+ecx] |
86 | sub eax, ecx |
81 | sub eax, ecx |
87 | or al, FREE_BLOCK |
82 | or al, FREE_BLOCK |
88 | shr edx, 12 |
83 | shr edx, 12 |
89 | mov [page_tabs+edx*4], eax |
84 | mov [page_tabs+edx*4], eax |
90 | @@: |
85 | @@: |
91 | or ecx, USED_BLOCK |
86 | or ecx, USED_BLOCK |
92 | mov [page_tabs+ebx*4], ecx |
87 | mov [page_tabs+ebx*4], ecx |
93 | shr ecx, 12 |
88 | shr ecx, 12 |
94 | inc ebx |
89 | inc ebx |
95 | dec ecx |
90 | dec ecx |
96 | jz .no |
91 | jz .no |
97 | @@: |
92 | @@: |
98 | mov dword [page_tabs+ebx*4], 2 |
93 | mov dword [page_tabs+ebx*4], 2 |
99 | inc ebx |
94 | inc ebx |
100 | dec ecx |
95 | dec ecx |
101 | jnz @B |
96 | jnz @B |
102 | .no: |
97 | .no: |
103 | 98 | ||
104 | mov edx, [current_slot] |
99 | mov edx, [current_slot] |
105 | mov ebx, [alloc_size] |
100 | mov ebx, [alloc_size] |
106 | add ebx, 0xFFF |
101 | add ebx, 0xFFF |
107 | and ebx, not 0xFFF |
102 | and ebx, not 0xFFF |
108 | add ebx, [edx+APPDATA.mem_size] |
103 | add ebx, [edx+APPDATA.mem_size] |
109 | call update_mem_size |
104 | call update_mem_size |
110 | 105 | ||
111 | lea eax, [esi+4096] |
106 | lea eax, [esi+4096] |
112 | 107 | ||
113 | pop edi |
108 | pop edi |
114 | pop esi |
109 | pop esi |
115 | pop ebx |
110 | pop ebx |
116 | ret |
111 | ret |
117 | test_used: |
112 | test_used: |
118 | test al, USED_BLOCK |
113 | test al, USED_BLOCK |
119 | jz m_exit |
114 | jz m_exit |
120 | 115 | ||
121 | and eax, 0xFFFFF000 |
116 | and eax, 0xFFFFF000 |
122 | m_next: |
117 | m_next: |
123 | add esi, eax |
118 | add esi, eax |
124 | jmp l_0 |
119 | jmp l_0 |
125 | m_exit: |
120 | m_exit: |
126 | xor eax, eax |
121 | xor eax, eax |
127 | pop edi |
122 | pop edi |
128 | pop esi |
123 | pop esi |
129 | pop ebx |
124 | pop ebx |
130 | ret |
125 | ret |
131 | endp |
126 | endp |
132 | 127 | ||
133 | align 4 |
128 | align 4 |
- | 129 | _UserFree: |
|
134 | proc user_free stdcall, base:dword |
130 | proc user_free stdcall, base:dword |
135 | 131 | ||
136 | push esi |
132 | push esi |
137 | 133 | ||
138 | mov esi, [base] |
134 | mov esi, [base] |
139 | test esi, esi |
135 | test esi, esi |
140 | jz .exit |
136 | jz .exit |
141 | 137 | ||
142 | push ebx |
138 | push ebx |
143 | 139 | ||
144 | xor ebx, ebx |
140 | xor ebx, ebx |
145 | shr esi, 12 |
141 | shr esi, 12 |
146 | mov eax, [page_tabs+(esi-1)*4] |
142 | mov eax, [page_tabs+(esi-1)*4] |
147 | test al, USED_BLOCK |
143 | test al, USED_BLOCK |
148 | jz .cantfree |
144 | jz .cantfree |
149 | 145 | ||
150 | test al, DONT_FREE_BLOCK |
146 | test al, DONT_FREE_BLOCK |
151 | jnz .cantfree |
147 | jnz .cantfree |
152 | 148 | ||
153 | push edi |
149 | push edi |
154 | 150 | ||
155 | and eax, not 4095 |
151 | and eax, not 4095 |
156 | mov edi, eax |
152 | mov edi, eax |
157 | or al, FREE_BLOCK |
153 | or al, FREE_BLOCK |
158 | mov [page_tabs+(esi-1)*4], eax |
154 | mov [page_tabs+(esi-1)*4], eax |
159 | sub edi, 4096 |
155 | sub edi, 4096 |
160 | mov ebx, edi |
156 | mov ebx, edi |
161 | shr edi, 12 |
157 | shr edi, 12 |
162 | jz .released |
158 | jz .released |
163 | 159 | ||
164 | .release: |
160 | .release: |
165 | xor ecx, ecx |
161 | xor ecx, ecx |
166 | xchg ecx, [page_tabs+esi*4] |
162 | xchg ecx, [page_tabs+esi*4] |
167 | test cl, 1 |
163 | test cl, 1 |
168 | jz @F |
164 | jz @F |
169 | 165 | ||
170 | call @core_free@4 |
166 | call @core_free@4 |
171 | mov eax, esi |
167 | mov eax, esi |
172 | shl eax, 12 |
168 | shl eax, 12 |
173 | invlpg [eax] |
169 | invlpg [eax] |
174 | @@: |
170 | @@: |
175 | inc esi |
171 | inc esi |
176 | dec edi |
172 | dec edi |
177 | jnz .release |
173 | jnz .release |
178 | .released: |
174 | .released: |
179 | mov edx, [current_slot] |
175 | mov edx, [current_slot] |
180 | mov esi, dword [edx+APPDATA.heap_base] |
176 | mov esi, dword [edx+APPDATA.heap_base] |
181 | mov edi, dword [edx+APPDATA.heap_top] |
177 | mov edi, dword [edx+APPDATA.heap_top] |
182 | sub ebx, [edx+APPDATA.mem_size] |
178 | sub ebx, [edx+APPDATA.mem_size] |
183 | neg ebx |
179 | neg ebx |
184 | call update_mem_size |
180 | call update_mem_size |
185 | call user_normalize |
181 | call user_normalize |
186 | pop edi |
182 | pop edi |
187 | pop ebx |
183 | pop ebx |
188 | pop esi |
184 | pop esi |
189 | ret |
185 | ret |
190 | .exit: |
186 | .exit: |
191 | xor eax, eax |
187 | xor eax, eax |
192 | inc eax |
188 | inc eax |
193 | pop esi |
189 | pop esi |
194 | ret |
190 | ret |
195 | .cantfree: |
191 | .cantfree: |
196 | xor eax, eax |
192 | xor eax, eax |
197 | pop ebx |
193 | pop ebx |
198 | pop esi |
194 | pop esi |
199 | ret |
195 | ret |
200 | endp |
196 | endp |
201 | 197 | ||
202 | user_normalize: |
198 | user_normalize: |
203 | ; in: esi=heap_base, edi=heap_top |
199 | ; in: esi=heap_base, edi=heap_top |
204 | ; out: eax=0 <=> OK |
200 | ; out: eax=0 <=> OK |
205 | ; destroys: ebx,edx,esi,edi |
201 | ; destroys: ebx,edx,esi,edi |
206 | shr esi, 12 |
202 | shr esi, 12 |
207 | shr edi, 12 |
203 | shr edi, 12 |
208 | @@: |
204 | @@: |
209 | mov eax, [page_tabs+esi*4] |
205 | mov eax, [page_tabs+esi*4] |
210 | test al, USED_BLOCK |
206 | test al, USED_BLOCK |
211 | jz .test_free |
207 | jz .test_free |
212 | shr eax, 12 |
208 | shr eax, 12 |
213 | add esi, eax |
209 | add esi, eax |
214 | jmp @B |
210 | jmp @B |
215 | .test_free: |
211 | .test_free: |
216 | test al, FREE_BLOCK |
212 | test al, FREE_BLOCK |
217 | jz .err |
213 | jz .err |
218 | mov edx, eax |
214 | mov edx, eax |
219 | shr edx, 12 |
215 | shr edx, 12 |
220 | add edx, esi |
216 | add edx, esi |
221 | cmp edx, edi |
217 | cmp edx, edi |
222 | jae .exit |
218 | jae .exit |
223 | 219 | ||
224 | mov ebx, [page_tabs+edx*4] |
220 | mov ebx, [page_tabs+edx*4] |
225 | test bl, USED_BLOCK |
221 | test bl, USED_BLOCK |
226 | jz .next_free |
222 | jz .next_free |
227 | 223 | ||
228 | shr ebx, 12 |
224 | shr ebx, 12 |
229 | add edx, ebx |
225 | add edx, ebx |
230 | mov esi, edx |
226 | mov esi, edx |
231 | jmp @B |
227 | jmp @B |
232 | .next_free: |
228 | .next_free: |
233 | test bl, FREE_BLOCK |
229 | test bl, FREE_BLOCK |
234 | jz .err |
230 | jz .err |
235 | and dword [page_tabs+edx*4], 0 |
231 | and dword [page_tabs+edx*4], 0 |
236 | add eax, ebx |
232 | add eax, ebx |
237 | and eax, not 4095 |
233 | and eax, not 4095 |
238 | or eax, FREE_BLOCK |
234 | or eax, FREE_BLOCK |
239 | mov [page_tabs+esi*4], eax |
235 | mov [page_tabs+esi*4], eax |
240 | jmp @B |
236 | jmp @B |
241 | .exit: |
237 | .exit: |
242 | xor eax, eax |
238 | xor eax, eax |
243 | inc eax |
239 | inc eax |
244 | ret |
240 | ret |
245 | .err: |
241 | .err: |
246 | xor eax, eax |
242 | xor eax, eax |
247 | ret |
243 | ret |
248 | 244 | ||
249 | user_realloc: |
245 | user_realloc: |
250 | ; in: eax = pointer, ebx = new size |
246 | ; in: eax = pointer, ebx = new size |
251 | ; out: eax = new pointer or NULL |
247 | ; out: eax = new pointer or NULL |
252 | test eax, eax |
248 | test eax, eax |
253 | jnz @f |
249 | jnz @f |
254 | ; realloc(NULL,sz) - same as malloc(sz) |
250 | ; realloc(NULL,sz) - same as malloc(sz) |
255 | push ebx |
251 | push ebx |
256 | call user_alloc |
252 | call user_alloc |
257 | ret |
253 | ret |
258 | @@: |
254 | @@: |
259 | push ecx edx |
255 | push ecx edx |
260 | lea ecx, [eax - 0x1000] |
256 | lea ecx, [eax - 0x1000] |
261 | shr ecx, 12 |
257 | shr ecx, 12 |
262 | mov edx, [page_tabs+ecx*4] |
258 | mov edx, [page_tabs+ecx*4] |
263 | test dl, USED_BLOCK |
259 | test dl, USED_BLOCK |
264 | jnz @f |
260 | jnz @f |
265 | ; attempt to realloc invalid pointer |
261 | ; attempt to realloc invalid pointer |
266 | .ret0: |
262 | .ret0: |
267 | pop edx ecx |
263 | pop edx ecx |
268 | xor eax, eax |
264 | xor eax, eax |
269 | ret |
265 | ret |
270 | @@: |
266 | @@: |
271 | test dl, DONT_FREE_BLOCK |
267 | test dl, DONT_FREE_BLOCK |
272 | jnz .ret0 |
268 | jnz .ret0 |
273 | add ebx, 0x1FFF |
269 | add ebx, 0x1FFF |
274 | shr edx, 12 |
270 | shr edx, 12 |
275 | shr ebx, 12 |
271 | shr ebx, 12 |
276 | ; edx = allocated size, ebx = new size |
272 | ; edx = allocated size, ebx = new size |
277 | add edx, ecx |
273 | add edx, ecx |
278 | add ebx, ecx |
274 | add ebx, ecx |
279 | cmp edx, ebx |
275 | cmp edx, ebx |
280 | jb .realloc_add |
276 | jb .realloc_add |
281 | ; release part of allocated memory |
277 | ; release part of allocated memory |
282 | 278 | ||
283 | push ecx |
279 | push ecx |
284 | .loop: |
280 | .loop: |
285 | cmp edx, ebx |
281 | cmp edx, ebx |
286 | jz .release_done |
282 | jz .release_done |
287 | dec edx |
283 | dec edx |
288 | xor ecx, ecx |
284 | xor ecx, ecx |
289 | xchg ecx, [page_tabs+edx*4] |
285 | xchg ecx, [page_tabs+edx*4] |
290 | test al, 1 |
286 | test al, 1 |
291 | jz .loop |
287 | jz .loop |
292 | 288 | ||
293 | push edx |
289 | push edx |
294 | call @core_free@4 |
290 | call @core_free@4 |
295 | pop edx |
291 | pop edx |
296 | mov eax, edx |
292 | mov eax, edx |
297 | shl eax, 12 |
293 | shl eax, 12 |
298 | invlpg [eax] |
294 | invlpg [eax] |
299 | jmp .loop |
295 | jmp .loop |
300 | .release_done: |
296 | .release_done: |
301 | 297 | ||
302 | pop ecx |
298 | pop ecx |
303 | 299 | ||
304 | sub ebx, ecx |
300 | sub ebx, ecx |
305 | cmp ebx, 1 |
301 | cmp ebx, 1 |
306 | jnz .nofreeall |
302 | jnz .nofreeall |
307 | mov eax, [page_tabs+ecx*4] |
303 | mov eax, [page_tabs+ecx*4] |
308 | and eax, not 0xFFF |
304 | and eax, not 0xFFF |
309 | mov edx, [current_slot] |
305 | mov edx, [current_slot] |
310 | mov ebx, [APPDATA.mem_size+edx] |
306 | mov ebx, [APPDATA.mem_size+edx] |
311 | sub ebx, eax |
307 | sub ebx, eax |
312 | add ebx, 0x1000 |
308 | add ebx, 0x1000 |
313 | or al, FREE_BLOCK |
309 | or al, FREE_BLOCK |
314 | mov [page_tabs+ecx*4], eax |
310 | mov [page_tabs+ecx*4], eax |
315 | push esi edi |
311 | push esi edi |
316 | mov esi, [APPDATA.heap_base+edx] |
312 | mov esi, [APPDATA.heap_base+edx] |
317 | mov edi, [APPDATA.heap_top+edx] |
313 | mov edi, [APPDATA.heap_top+edx] |
318 | call update_mem_size |
314 | call update_mem_size |
319 | call user_normalize |
315 | call user_normalize |
320 | pop edi esi |
316 | pop edi esi |
321 | jmp .ret0 ; all freed |
317 | jmp .ret0 ; all freed |
322 | .nofreeall: |
318 | .nofreeall: |
323 | sub edx, ecx |
319 | sub edx, ecx |
324 | shl ebx, 12 |
320 | shl ebx, 12 |
325 | or ebx, USED_BLOCK |
321 | or ebx, USED_BLOCK |
326 | xchg [page_tabs+ecx*4], ebx |
322 | xchg [page_tabs+ecx*4], ebx |
327 | shr ebx, 12 |
323 | shr ebx, 12 |
328 | sub ebx, edx |
324 | sub ebx, edx |
329 | push ebx ecx edx |
325 | push ebx ecx edx |
330 | mov edx, [current_slot] |
326 | mov edx, [current_slot] |
331 | shl ebx, 12 |
327 | shl ebx, 12 |
332 | sub ebx, [APPDATA.mem_size+edx] |
328 | sub ebx, [APPDATA.mem_size+edx] |
333 | neg ebx |
329 | neg ebx |
334 | call update_mem_size |
330 | call update_mem_size |
335 | pop edx ecx ebx |
331 | pop edx ecx ebx |
336 | lea eax, [ecx+1] |
332 | lea eax, [ecx+1] |
337 | shl eax, 12 |
333 | shl eax, 12 |
338 | push eax |
334 | push eax |
339 | add ecx, edx |
335 | add ecx, edx |
340 | lea edx, [ecx+ebx] |
336 | lea edx, [ecx+ebx] |
341 | shl ebx, 12 |
337 | shl ebx, 12 |
342 | jz .ret |
338 | jz .ret |
343 | push esi |
339 | push esi |
344 | mov esi, [current_slot] |
340 | mov esi, [current_slot] |
345 | mov esi, [APPDATA.heap_top+esi] |
341 | mov esi, [APPDATA.heap_top+esi] |
346 | shr esi, 12 |
342 | shr esi, 12 |
347 | @@: |
343 | @@: |
348 | cmp edx, esi |
344 | cmp edx, esi |
349 | jae .merge_done |
345 | jae .merge_done |
350 | mov eax, [page_tabs+edx*4] |
346 | mov eax, [page_tabs+edx*4] |
351 | test al, USED_BLOCK |
347 | test al, USED_BLOCK |
352 | jnz .merge_done |
348 | jnz .merge_done |
353 | and dword [page_tabs+edx*4], 0 |
349 | and dword [page_tabs+edx*4], 0 |
354 | shr eax, 12 |
350 | shr eax, 12 |
355 | add edx, eax |
351 | add edx, eax |
356 | shl eax, 12 |
352 | shl eax, 12 |
357 | add ebx, eax |
353 | add ebx, eax |
358 | jmp @b |
354 | jmp @b |
359 | .merge_done: |
355 | .merge_done: |
360 | pop esi |
356 | pop esi |
361 | or ebx, FREE_BLOCK |
357 | or ebx, FREE_BLOCK |
362 | mov [page_tabs+ecx*4], ebx |
358 | mov [page_tabs+ecx*4], ebx |
363 | .ret: |
359 | .ret: |
364 | pop eax edx ecx |
360 | pop eax edx ecx |
365 | ret |
361 | ret |
366 | .realloc_add: |
362 | .realloc_add: |
367 | ; get some additional memory |
363 | ; get some additional memory |
368 | mov eax, [current_slot] |
364 | mov eax, [current_slot] |
369 | mov eax, [APPDATA.heap_top+eax] |
365 | mov eax, [APPDATA.heap_top+eax] |
370 | shr eax, 12 |
366 | shr eax, 12 |
371 | cmp edx, eax |
367 | cmp edx, eax |
372 | jae .cant_inplace |
368 | jae .cant_inplace |
373 | mov eax, [page_tabs+edx*4] |
369 | mov eax, [page_tabs+edx*4] |
374 | test al, FREE_BLOCK |
370 | test al, FREE_BLOCK |
375 | jz .cant_inplace |
371 | jz .cant_inplace |
376 | shr eax, 12 |
372 | shr eax, 12 |
377 | add eax, edx |
373 | add eax, edx |
378 | sub eax, ebx |
374 | sub eax, ebx |
379 | jb .cant_inplace |
375 | jb .cant_inplace |
380 | jz @f |
376 | jz @f |
381 | shl eax, 12 |
377 | shl eax, 12 |
382 | or al, FREE_BLOCK |
378 | or al, FREE_BLOCK |
383 | mov [page_tabs+ebx*4], eax |
379 | mov [page_tabs+ebx*4], eax |
384 | @@: |
380 | @@: |
385 | mov eax, ebx |
381 | mov eax, ebx |
386 | sub eax, ecx |
382 | sub eax, ecx |
387 | shl eax, 12 |
383 | shl eax, 12 |
388 | or al, USED_BLOCK |
384 | or al, USED_BLOCK |
389 | mov [page_tabs+ecx*4], eax |
385 | mov [page_tabs+ecx*4], eax |
390 | lea eax, [ecx+1] |
386 | lea eax, [ecx+1] |
391 | shl eax, 12 |
387 | shl eax, 12 |
392 | push eax |
388 | push eax |
393 | push edi |
389 | push edi |
394 | lea edi, [page_tabs+edx*4] |
390 | lea edi, [page_tabs+edx*4] |
395 | mov eax, 2 |
391 | mov eax, 2 |
396 | sub ebx, edx |
392 | sub ebx, edx |
397 | mov ecx, ebx |
393 | mov ecx, ebx |
398 | cld |
394 | cld |
399 | rep stosd |
395 | rep stosd |
400 | pop edi |
396 | pop edi |
401 | mov edx, [current_slot] |
397 | mov edx, [current_slot] |
402 | shl ebx, 12 |
398 | shl ebx, 12 |
403 | add ebx, [APPDATA.mem_size+edx] |
399 | add ebx, [APPDATA.mem_size+edx] |
404 | call update_mem_size |
400 | call update_mem_size |
405 | pop eax edx ecx |
401 | pop eax edx ecx |
406 | ret |
402 | ret |
407 | .cant_inplace: |
403 | .cant_inplace: |
408 | push esi edi |
404 | push esi edi |
409 | mov eax, [current_slot] |
405 | mov eax, [current_slot] |
410 | mov esi, [APPDATA.heap_base+eax] |
406 | mov esi, [APPDATA.heap_base+eax] |
411 | mov edi, [APPDATA.heap_top+eax] |
407 | mov edi, [APPDATA.heap_top+eax] |
412 | shr esi, 12 |
408 | shr esi, 12 |
413 | shr edi, 12 |
409 | shr edi, 12 |
414 | sub ebx, ecx |
410 | sub ebx, ecx |
415 | .find_place: |
411 | .find_place: |
416 | cmp esi, edi |
412 | cmp esi, edi |
417 | jae .place_not_found |
413 | jae .place_not_found |
418 | mov eax, [page_tabs+esi*4] |
414 | mov eax, [page_tabs+esi*4] |
419 | test al, FREE_BLOCK |
415 | test al, FREE_BLOCK |
420 | jz .next_place |
416 | jz .next_place |
421 | shr eax, 12 |
417 | shr eax, 12 |
422 | cmp eax, ebx |
418 | cmp eax, ebx |
423 | jae .place_found |
419 | jae .place_found |
424 | add esi, eax |
420 | add esi, eax |
425 | jmp .find_place |
421 | jmp .find_place |
426 | .next_place: |
422 | .next_place: |
427 | shr eax, 12 |
423 | shr eax, 12 |
428 | add esi, eax |
424 | add esi, eax |
429 | jmp .find_place |
425 | jmp .find_place |
430 | .place_not_found: |
426 | .place_not_found: |
431 | pop edi esi |
427 | pop edi esi |
432 | jmp .ret0 |
428 | jmp .ret0 |
433 | .place_found: |
429 | .place_found: |
434 | sub eax, ebx |
430 | sub eax, ebx |
435 | jz @f |
431 | jz @f |
436 | push esi |
432 | push esi |
437 | add esi, ebx |
433 | add esi, ebx |
438 | shl eax, 12 |
434 | shl eax, 12 |
439 | or al, FREE_BLOCK |
435 | or al, FREE_BLOCK |
440 | mov [page_tabs+esi*4], eax |
436 | mov [page_tabs+esi*4], eax |
441 | pop esi |
437 | pop esi |
442 | @@: |
438 | @@: |
443 | mov eax, ebx |
439 | mov eax, ebx |
444 | shl eax, 12 |
440 | shl eax, 12 |
445 | or al, USED_BLOCK |
441 | or al, USED_BLOCK |
446 | mov [page_tabs+esi*4], eax |
442 | mov [page_tabs+esi*4], eax |
447 | inc esi |
443 | inc esi |
448 | mov eax, esi |
444 | mov eax, esi |
449 | shl eax, 12 |
445 | shl eax, 12 |
450 | push eax |
446 | push eax |
451 | mov eax, [page_tabs+ecx*4] |
447 | mov eax, [page_tabs+ecx*4] |
452 | and eax, not 0xFFF |
448 | and eax, not 0xFFF |
453 | or al, FREE_BLOCK |
449 | or al, FREE_BLOCK |
454 | sub edx, ecx |
450 | sub edx, ecx |
455 | mov [page_tabs+ecx*4], eax |
451 | mov [page_tabs+ecx*4], eax |
456 | inc ecx |
452 | inc ecx |
457 | dec ebx |
453 | dec ebx |
458 | dec edx |
454 | dec edx |
459 | jz .no |
455 | jz .no |
460 | @@: |
456 | @@: |
461 | xor eax, eax |
457 | xor eax, eax |
462 | xchg eax, [page_tabs+ecx*4] |
458 | xchg eax, [page_tabs+ecx*4] |
463 | mov [page_tabs+esi*4], eax |
459 | mov [page_tabs+esi*4], eax |
464 | mov eax, ecx |
460 | mov eax, ecx |
465 | shl eax, 12 |
461 | shl eax, 12 |
466 | invlpg [eax] |
462 | invlpg [eax] |
467 | inc esi |
463 | inc esi |
468 | inc ecx |
464 | inc ecx |
469 | dec ebx |
465 | dec ebx |
470 | dec edx |
466 | dec edx |
471 | jnz @b |
467 | jnz @b |
472 | .no: |
468 | .no: |
473 | push ebx |
469 | push ebx |
474 | mov edx, [current_slot] |
470 | mov edx, [current_slot] |
475 | shl ebx, 12 |
471 | shl ebx, 12 |
476 | add ebx, [APPDATA.mem_size+edx] |
472 | add ebx, [APPDATA.mem_size+edx] |
477 | call update_mem_size |
473 | call update_mem_size |
478 | pop ebx |
474 | pop ebx |
479 | @@: |
475 | @@: |
480 | mov dword [page_tabs+esi*4], 2 |
476 | mov dword [page_tabs+esi*4], 2 |
481 | inc esi |
477 | inc esi |
482 | dec ebx |
478 | dec ebx |
483 | jnz @b |
479 | jnz @b |
484 | pop eax edi esi edx ecx |
480 | pop eax edi esi edx ecx |
485 | ret |
481 | ret |
486 | 482 | ||
487 | if 0 |
483 | if 0 |
488 | align 4 |
484 | align 4 |
489 | proc alloc_dll |
485 | proc alloc_dll |
490 | pushf |
486 | pushf |
491 | cli |
487 | cli |
492 | bsf eax, [dll_map] |
488 | bsf eax, [dll_map] |
493 | jnz .find |
489 | jnz .find |
494 | popf |
490 | popf |
495 | xor eax, eax |
491 | xor eax, eax |
496 | ret |
492 | ret |
497 | .find: |
493 | .find: |
498 | btr [dll_map], eax |
494 | btr [dll_map], eax |
499 | popf |
495 | popf |
500 | shl eax, 5 |
496 | shl eax, 5 |
501 | add eax, dll_tab |
497 | add eax, dll_tab |
502 | ret |
498 | ret |
503 | endp |
499 | endp |
504 | 500 | ||
505 | align 4 |
501 | align 4 |
506 | proc alloc_service |
502 | proc alloc_service |
507 | pushf |
503 | pushf |
508 | cli |
504 | cli |
509 | bsf eax, [srv_map] |
505 | bsf eax, [srv_map] |
510 | jnz .find |
506 | jnz .find |
511 | popf |
507 | popf |
512 | xor eax, eax |
508 | xor eax, eax |
513 | ret |
509 | ret |
514 | .find: |
510 | .find: |
515 | btr [srv_map], eax |
511 | btr [srv_map], eax |
516 | popf |
512 | popf |
517 | shl eax,0x02 |
513 | shl eax,0x02 |
518 | lea eax,[srv_tab+eax+eax*8] ;srv_tab+eax*36 |
514 | lea eax,[srv_tab+eax+eax*8] ;srv_tab+eax*36 |
519 | ret |
515 | ret |
520 | endp |
516 | endp |
521 | 517 | ||
522 | end if=> |
518 | end if=> |