Subversion Repositories Kolibri OS

Rev

Rev 278 | Rev 281 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 278 Rev 279
Line 136... Line 136...
136
 
136
 
Line 137... Line 137...
137
           mov [mem_used_list], eax
137
           mov [mem_used_list], eax
138
           mov [mem_block_list+63*4], ebx
138
           mov [mem_block_list+63*4], ebx
139
           mov byte [mem_block_map], 0xFC
139
           mov byte [mem_block_map], 0xFC
-
 
140
           and [heap_mutex], 0
140
           mov [heap_blocks], 4095
141
           mov [heap_blocks], 4095
141
           mov [free_blocks], 4095
142
           mov [free_blocks], 4095
142
           ret
143
           ret
143
endp
144
endp
Line 194... Line 195...
194
 
195
 
Line 195... Line 196...
195
align 4
196
align 4
196
proc alloc_mem_block
197
proc alloc_mem_block
Line 197... Line -...
197
 
-
 
198
           pushfd
-
 
199
           cli
198
 
200
           mov ebx, [mem_block_start]
199
           mov ebx, [mem_block_start]
201
           mov ecx, [mem_block_end]
200
           mov ecx, [mem_block_end]
202
.l1:
201
.l1:
203
           bsf eax,[ebx];
202
           bsf eax,[ebx];
204
           jnz found
203
           jnz found
205
           add ebx,4
204
           add ebx,4
206
           cmp ebx, ecx
205
           cmp ebx, ecx
207
           jb .l1
-
 
208
           popfd
206
           jb .l1
209
           xor eax,eax
207
           xor eax,eax
Line 210... Line 208...
210
           ret
208
           ret
211
 
209
 
Line 216... Line 214...
216
           lea eax,[eax+ebx*8]
214
           lea eax,[eax+ebx*8]
217
           shl eax, 5
215
           shl eax, 5
218
           add eax, [mem_block_arr]
216
           add eax, [mem_block_arr]
219
           dec [free_blocks]
217
           dec [free_blocks]
220
           popfd
218
           ret
221
           ret
-
 
222
endp
219
endp
223
 
220
 
Line 224... Line 221...
224
proc free_mem_block
221
proc free_mem_block
225
           pushfd
-
 
226
           cli
-
 
227
           sub eax, [mem_block_arr]
222
           sub eax, [mem_block_arr]
228
           shr eax, 5
223
           shr eax, 5
Line 229... Line 224...
229
 
224
 
230
           mov ebx, mem_block_map
225
           mov ebx, mem_block_map
Line 234... Line 229...
234
           and eax, not 3
229
           and eax, not 3
235
           add eax, ebx
230
           add eax, ebx
236
           cmp [mem_block_start], eax
231
           cmp [mem_block_start], eax
237
           ja @f
232
           ja @f
238
           popfd
233
           ret
239
           ret
-
 
240
@@:
234
@@:
241
           mov [mem_block_start], eax
235
           mov [mem_block_start], eax
242
           popfd
236
	   ret
243
	   ret
-
 
244
.err:
237
.err:
245
           xor eax, eax
238
           xor eax, eax
246
           popfd
239
	   ret
247
	   ret
-
 
248
endp
240
endp
249
 
241
 
Line 250... Line 242...
250
align 4
242
align 4
251
proc alloc_kernel_space stdcall, size:dword
243
proc alloc_kernel_space stdcall, size:dword
252
           local block_ind:DWORD
244
           local block_ind:DWORD
Line 253... Line -...
253
 
-
 
254
           pushfd
-
 
255
           cli
-
 
256
 
245
 
257
           mov eax, [size]
246
           mov eax, [size]
258
           add eax, 4095
247
           add eax, 4095
259
           and eax, not 4095
248
           and eax, not 4095
-
 
249
           mov [size], eax
-
 
250
 
-
 
251
           mov ebx, heap_mutex
-
 
252
           call wait_mutex    ;ebx
260
           mov [size], eax
253
 
261
           cmp eax, [heap_free]
254
           cmp eax, [heap_free]
Line 262... Line 255...
262
           ja .error
255
           ja .error
263
 
256
 
Line 264... Line 257...
264
           shr eax, 12
257
           shr eax, 12
Line 265... Line 258...
265
           sub eax, 1
258
           sub eax, 1
266
 
259
 
267
           mov [block_ind], eax
260
           mov [block_ind], eax
Line 268... Line 261...
268
 
261
 
Line 269... Line 262...
269
           stdcall get_block, eax
262
           stdcall get_block, eax
Line 342... Line 335...
342
           mov [mem_used_list], esi
335
           mov [mem_used_list], esi
343
           mov eax, [esi+block_base]
336
           mov eax, [esi+block_base]
344
           mov ebx, [size]
337
           mov ebx, [size]
345
           sub [heap_free], ebx
338
           sub [heap_free], ebx
346
           popfd
339
           and [heap_mutex], 0
347
           ret
340
           ret
348
 
341
.m_eq_size:
349
.m_eq_size:
-
 
350
           remove_from_list edi
342
           remove_from_list edi
351
           mov [mem_block_list+ebx*4], edx
343
           mov [mem_block_list+ebx*4], edx
352
           and edx, edx
344
           and edx, edx
353
           jnz @f
345
           jnz @f
354
           btr [mem_block_mask], ebx
346
           btr [mem_block_mask], ebx
Line 363... Line 355...
363
           mov [edi+block_flags], USED_BLOCK
355
           mov [edi+block_flags], USED_BLOCK
364
           mov eax, [edi+block_base]
356
           mov eax, [edi+block_base]
365
           mov ebx, [size]
357
           mov ebx, [size]
366
           sub [heap_free], ebx
358
           sub [heap_free], ebx
367
           popfd
359
           and [heap_mutex], 0
368
           ret
360
           ret
369
.error:
361
.error:
370
           xor eax, eax
362
           xor eax, eax
371
           popfd
363
           mov [heap_mutex], eax
372
           ret
364
           ret
373
endp
365
endp
374
 
366
 
Line 375... Line 367...
375
align 4
367
align 4
376
proc free_kernel_space stdcall, base:dword
368
proc free_kernel_space stdcall, base:dword
Line -... Line 369...
-
 
369
 
-
 
370
           mov ebx, heap_mutex
-
 
371
           call wait_mutex    ;ebx
377
 
372
 
378
           mov eax, [base]
373
           mov eax, [base]
379
           mov esi, [mem_used_list]
374
           mov esi, [mem_used_list]
380
@@:
375
@@:
381
           test esi, esi
376
           test esi, esi
Line 463... Line 458...
463
@@:
458
@@:
464
           bts [mem_block_mask], eax
459
           bts [mem_block_mask], eax
465
.m_eq:
460
.m_eq:
466
           xor eax, eax
461
           xor eax, eax
467
           not eax
462
           mov [heap_mutex], eax
-
 
463
           not eax
468
           ret
464
           ret
469
.insert:
465
.insert:
470
           remove_from_used esi
466
           remove_from_used esi
471
 
467
 
Line 481... Line 477...
481
@@:
477
@@:
482
           bts [mem_block_mask], eax
478
           bts [mem_block_mask], eax
483
           mov [esi+block_flags],FREE_BLOCK
479
           mov [esi+block_flags],FREE_BLOCK
484
           xor eax, eax
480
           xor eax, eax
485
           not eax
481
           mov [heap_mutex], eax
-
 
482
           not eax
486
           ret
483
           ret
487
.fail:
484
.fail:
488
           xor eax, eax
485
           xor eax, eax
489
           ret
486
           mov [heap_mutex], eax
-
 
487
           ret
490
endp
488
endp
491
 
489
 
Line 492... Line 490...
492
align 4
490
align 4
493
proc kernel_alloc stdcall, size:dword
491
proc kernel_alloc stdcall, size:dword
Line 550... Line 548...
550
           jnz @B
548
           jnz @B
551
.end:
549
.end:
552
           mov eax, [lin_addr]
550
           mov eax, [lin_addr]
553
           ret
551
           ret
554
 
552
.error:
555
.error:
-
 
556
           xor eax, eax
553
           xor eax, eax
557
           ret
554
           ret
558
endp
555
endp
559
 
556
 
Line 560... Line 557...
560
align 4
557
align 4
561
proc kernel_free stdcall, base:dword
558
proc kernel_free stdcall, base:dword
-
 
559
 
562
           locals
560
           mov ebx, heap_mutex
563
             size  dd ?
561
           call wait_mutex    ;ebx
564
           endl
-
 
Line 565... Line 562...
565
 
562
 
566
           mov eax, [base]
563
           mov eax, [base]
567
           mov esi, [mem_used_list]
564
           mov esi, [mem_used_list]
568
@@:
565
@@:
Line 576... Line 573...
576
.found:
573
.found:
577
           cmp [esi+block_flags], USED_BLOCK
574
           cmp [esi+block_flags], USED_BLOCK
578
           jne .fail
575
           jne .fail
579
 
576
 
Line -... Line 577...
-
 
577
           and [heap_mutex], 0
-
 
578
 
580
           mov ecx, [esi+block_size];
579
           mov ecx, [esi+block_size];
581
           mov [size], ecx
-
 
Line -... Line 580...
-
 
580
 
582
 
581
           call release_pages   ;eax, ecx
583
           stdcall free_kernel_space, [base]
-
 
584
           test eax, eax
-
 
585
           jz .fail
-
 
586
 
-
 
587
           mov ecx, [size]
-
 
588
           mov edi, [base]
-
 
589
 
-
 
590
           shr ecx, 12
-
 
591
           mov esi, edi
-
 
592
           shr edi, 10
-
 
593
           add edi, pages_tab
-
 
594
           xor edx, edx
-
 
595
.release:
-
 
596
           mov eax, [edi]
-
 
597
           test eax, 1
582
           stdcall free_kernel_space, [base]
598
           jz .next
-
 
599
 
-
 
600
           call free_page
-
 
601
           mov [edi],edx
-
 
602
.next:
-
 
603
           invlpg [esi]
-
 
604
           add esi, 0x1000
-
 
605
           add edi, 4
-
 
606
           dec ecx
-
 
607
           jnz .release
583
           ret
-
 
584
.fail:
608
.fail:
585
           and [heap_mutex], 0
609
           ret
586
           ret
Line 610... Line 587...
610
endp
587
endp
611
 
588