Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
846 serge 1
DWORD equ dword
2
WORD  equ word
3
BYTE  equ byte
4
 
5
PTR   equ
6
 
7
_mem_counter   equ (BOOT_VAR + 0x9100)
8
_mem_table     equ (BOOT_VAR + 0x9104)
9
 
10
_spinlock_initialize:
11
	mov	eax, DWORD PTR [esp+4]
12
	mov	DWORD PTR [eax], 0
13
	ret
14
 
15
_buddy_find_block:
16
	push	ebx
17
	mov	eax, DWORD PTR [eax+12]
18
	mov	ebx, ecx
19
	sub	edx, eax
20
	sar	edx, 2
21
	imul	ecx, edx, -858993459
22
	lea	eax, [eax+edx*4]
23
.L4:
24
	cmp	DWORD PTR [eax+12], ebx
25
        jne     .L7
26
	sub	ecx, 1
27
	sub	eax, 20
28
	cmp	ecx, -1
29
        jne     .L4
30
	xor	eax, eax
31
.L7:
32
	pop	ebx
33
	ret
34
 
35
@buddy_system_free@8:
36
	push	ebp
37
	mov	ebp, edx
38
	push	edi
39
	push	esi
40
	mov	esi, edx
41
	push	ebx
42
	sub	esp, 8
43
	mov	ebx, DWORD PTR [edx+12]
44
	mov	DWORD PTR [esp+4], ecx
45
	cmp	BYTE PTR [ecx+24], bl
46
	mov	edi, ebx
47
        je      .L17
48
	mov	edx, DWORD PTR [ecx+12]
49
	mov	DWORD PTR [esp], edx
50
        jmp     .L15
51
.L30:
52
	mov	eax, 1
53
	sal	eax, cl
54
	add	edx, eax
55
	mov	eax, DWORD PTR [esp+4]
56
	cmp	edx, DWORD PTR [eax+8]
57
        jae     .L17
58
.L31:
59
	lea	eax, [edx+edx*4]
60
	mov	edx, DWORD PTR [esp]
61
	lea	ecx, [edx+eax*4]
62
	cmp	ebx, DWORD PTR [ecx+12]
63
        jne     .L17
64
	mov	eax, DWORD PTR [ecx+8]
65
	test	eax, eax
66
        jne     .L17
67
	mov	eax, DWORD PTR [ecx+4]
68
	cmp	esi, ecx
69
	mov	edx, DWORD PTR [ecx]
70
	mov	DWORD PTR [esi+12], 255
71
	mov	DWORD PTR [ecx+12], 255
72
	mov	DWORD PTR [eax], edx
73
	mov	edx, DWORD PTR [ecx]
74
	mov	DWORD PTR [ecx], 0
75
	mov	DWORD PTR [edx+4], eax
76
	mov	edx, ebp
77
	mov	DWORD PTR [ecx+4], 0
78
        jb      .L26
79
	mov	edx, ecx
80
.L26:
81
	mov	ecx, edi
82
	mov	esi, edx
83
	movzx	eax, cl
84
	mov	ebp, edx
85
	lea	ebx, [eax+1]
86
	mov	eax, DWORD PTR [esp+4]
87
	mov	DWORD PTR [edx+12], ebx
88
	movzx	edi, BYTE PTR [eax+24]
89
	mov	edx, edi
90
	cmp	dl, bl
91
        je      .L17
92
	mov	edi, ebx
93
.L15:
94
	mov	eax, esi
95
	mov	ecx, ebx
96
	sub	eax, DWORD PTR [esp]
97
	sar	eax, 2
98
	imul	edx, eax, -858993459
99
	mov	eax, edx
100
	shr	eax, cl
101
	test	al, 1
102
        je      .L30
103
	mov	eax, 1
104
	mov	ecx, ebx
105
	sal	eax, cl
106
	sub	edx, eax
107
	mov	eax, DWORD PTR [esp+4]
108
	cmp	edx, DWORD PTR [eax+8]
109
        jb      .L31
110
.L17:
111
	mov	ecx, edi
112
	movzx	edx, cl
113
	mov	ecx, DWORD PTR [esp+4]
114
	mov	eax, DWORD PTR [ecx+28+edx*8]
115
	mov	DWORD PTR [ebp], eax
116
	lea	eax, [ecx+28+edx*8]
117
	mov	DWORD PTR [ebp+4], eax
118
	mov	eax, DWORD PTR [ecx+28+edx*8]
119
	mov	DWORD PTR [ecx+28+edx*8], ebp
120
	mov	DWORD PTR [eax+4], ebp
121
	add	esp, 8
122
	pop	ebx
123
	pop	esi
124
	pop	edi
125
	pop	ebp
126
	ret
127
 
128
@buddy_system_alloc_block@8:
129
	push	ebp
130
	mov	ebp, ecx
131
	push	edi
132
	mov	ecx, 255
133
	push	esi
134
	mov	eax, ebp
135
	push	ebx
136
	sub	esp, 4
137
	mov	DWORD PTR [esp], edx
138
	call	_buddy_find_block
139
	mov	ebx, eax
140
	mov	eax, DWORD PTR [eax+4]
141
	mov	edx, DWORD PTR [ebx]
142
	mov	DWORD PTR [eax], edx
143
	mov	edx, DWORD PTR [ebx]
144
	mov	DWORD PTR [ebx], 0
145
	mov	DWORD PTR [edx+4], eax
146
	mov	eax, DWORD PTR [ebx+12]
147
	mov	DWORD PTR [ebx+4], 0
148
	test	eax, eax
149
        jne     .L38
150
        jmp     .L34
151
.L35:
152
	mov	DWORD PTR [ebx+8], 1
153
	mov	edx, esi
154
	mov	ecx, ebp
155
	call	@buddy_system_free@8
156
	mov	eax, DWORD PTR [ebx+12]
157
	mov	DWORD PTR [ebx+8], 0
158
	test	eax, eax
159
        je      .L34
160
.L38:
161
	lea	ecx, [eax-1]
162
	mov	edx, DWORD PTR [esp]
163
	mov	eax, 20
164
	sal	eax, cl
165
	lea	edi, [ebx+eax]
166
	mov	eax, ebp
167
	mov	DWORD PTR [ebx+12], ecx
168
	mov	esi, edi
169
	mov	DWORD PTR [edi+12], ecx
170
	mov	ecx, 255
171
	call	_buddy_find_block
172
	cmp	edi, eax
173
        jne     .L35
174
	mov	esi, ebx
175
	mov	ebx, edi
176
        jmp     .L35
177
.L34:
178
	mov	DWORD PTR [ebx+8], 1
179
	mov	eax, ebx
180
	add	esp, 4
181
	pop	ebx
182
	pop	esi
183
	pop	edi
184
	pop	ebp
185
	ret
186
 
187
_zone_release:
188
	push	edi
189
	push	esi
190
	push	ebx
191
	mov	esi, DWORD PTR [esp+16]
192
	mov	eax, DWORD PTR [esp+20]
193
	mov	edi, DWORD PTR [esp+24]
194
	mov	edx, DWORD PTR [esi+4]
195
	add	edi, eax
196
	cmp	edi, edx
197
        jb      .L48
198
	mov	ebx, edx
199
	add	ebx, DWORD PTR [esi+8]
200
	cmp	eax, ebx
201
        ja      .L48
202
	cmp	eax, edx
203
	mov	ecx, eax
204
        jae     .L44
205
	mov	ecx, edx
206
.L44:
207
	cmp	edi, ebx
208
        jbe     .L45
209
	mov	edi, ebx
210
.L45:
211
	cmp	ecx, edi
212
        jae     .L48
213
	mov	ebx, ecx
214
.L47:
215
	mov	edx, DWORD PTR [esi+12]
216
	mov	eax, ecx
217
	add	ebx, 1
218
	sub	eax, DWORD PTR [esi+4]
219
	lea	eax, [eax+eax*4]
220
	mov	DWORD PTR [edx+8+eax*4], 0
221
	sub	ecx, DWORD PTR [esi+4]
222
	lea	edx, [ecx+ecx*4]
223
	mov	ecx, esi
224
	sal	edx, 2
225
	add	edx, DWORD PTR [esi+12]
226
	call	@buddy_system_free@8
227
	cmp	edi, ebx
228
	mov	ecx, ebx
229
        ja      .L47
230
.L48:
231
	pop	ebx
232
	pop	esi
233
	pop	edi
234
	ret
235
 
236
_zone_reserve:
237
	push	edi
238
	push	esi
239
	push	ebx
240
	mov	esi, DWORD PTR [esp+16]
241
	mov	eax, DWORD PTR [esp+20]
242
	mov	ebx, DWORD PTR [esp+24]
243
	mov	edx, DWORD PTR [esi+4]
244
	add	ebx, eax
245
	cmp	ebx, edx
246
        jb      .L61
247
	mov	ecx, edx
248
	add	ecx, DWORD PTR [esi+8]
249
	cmp	eax, ecx
250
        ja      .L61
251
	cmp	eax, edx
252
        jae     .L54
253
	mov	eax, edx
254
.L54:
255
	cmp	ebx, ecx
256
	mov	edi, ebx
257
        jbe     .L55
258
	mov	edi, ecx
259
.L55:
260
	cmp	eax, edi
261
        jae     .L61
262
	mov	ebx, eax
263
        jmp     .L57
264
.L58:
265
	add	ebx, 1
266
	cmp	edi, ebx
267
	mov	eax, ebx
268
        jbe     .L61
269
.L62:
270
	mov	edx, DWORD PTR [esi+4]
271
.L57:
272
	sub	eax, edx
273
	lea	eax, [eax+eax*4]
274
	lea	edx, [0+eax*4]
275
	add	edx, DWORD PTR [esi+12]
276
	mov	ecx, DWORD PTR [edx+8]
277
	test	ecx, ecx
278
        jne     .L58
279
	add	ebx, 1
280
	mov	ecx, esi
281
	call	@buddy_system_alloc_block@8
282
	mov	eax, ebx
283
	sub	DWORD PTR [esi+16], 1
284
	cmp	edi, ebx
285
        ja      .L62
286
.L61:
287
	pop	ebx
288
	pop	esi
289
	pop	edi
290
	ret
291
 
292
@buddy_system_alloc@8:
293
	sub	esp, 12
294
	mov	DWORD PTR [esp], ebx
295
	lea	eax, [ecx+28+edx*8]
296
	mov	ebx, edx
297
	mov	DWORD PTR [esp+4], esi
298
	mov	esi, ecx
299
	mov	DWORD PTR [esp+8], edi
300
	cmp	DWORD PTR [ecx+32+edx*8], eax
301
        je      .L64
302
	mov	ecx, DWORD PTR [ecx+32+edx*8]
303
	mov	eax, DWORD PTR [ecx+4]
304
	mov	edx, DWORD PTR [ecx]
305
	mov	DWORD PTR [ecx+8], 1
306
	mov	DWORD PTR [eax], edx
307
	mov	edx, DWORD PTR [ecx]
308
	mov	DWORD PTR [ecx], 0
309
	mov	DWORD PTR [edx+4], eax
310
	mov	DWORD PTR [ecx+4], 0
311
.L66:
312
	mov	ebx, DWORD PTR [esp]
313
	mov	eax, ecx
314
	mov	esi, DWORD PTR [esp+4]
315
	mov	edi, DWORD PTR [esp+8]
316
	add	esp, 12
317
	ret
318
.L64:
319
	movzx	eax, BYTE PTR [ecx+24]
320
	cmp	eax, edx
321
        jne     .L71
322
.L67:
323
	xor	ecx, ecx
324
        jmp     .L66
325
.L71:
326
	lea	edx, [edx+1]
327
	call	@buddy_system_alloc@8
328
	test	eax, eax
329
	mov	edi, eax
330
        je      .L67
331
	mov	ecx, DWORD PTR [eax+12]
332
	mov	edx, 20
333
	mov	DWORD PTR [eax+12], ebx
334
	mov	DWORD PTR [eax+8], 1
335
	sub	ecx, 1
336
	sal	edx, cl
337
	mov	ecx, esi
338
	add	edx, eax
339
	mov	DWORD PTR [edx+12], ebx
340
	call	@buddy_system_free@8
341
	mov	ecx, edi
342
        jmp     .L66
343
 
344
_zone_frame_alloc:
345
	sub	esp, 8
346
	mov	ecx, eax
347
	mov	DWORD PTR [esp], ebx
348
	mov	ebx, eax
349
	mov	DWORD PTR [esp+4], esi
350
	mov	esi, edx
351
	call	@buddy_system_alloc@8
352
	mov	ecx, esi
353
	mov	edx, 1
354
	sal	edx, cl
355
	mov	esi, DWORD PTR [esp+4]
356
	sub	DWORD PTR [ebx+16], edx
357
	sub	eax, DWORD PTR [ebx+12]
358
	add	DWORD PTR [ebx+20], edx
359
	mov	ebx, DWORD PTR [esp]
360
	add	esp, 8
361
	sar	eax, 2
362
	imul	eax, eax, -858993459
363
	ret
364
 
365
_frame_set_parent:
366
	mov	eax, DWORD PTR [esp+4]
367
        sub     eax, DWORD PTR [_z_core+4]
368
	mov	ecx, DWORD PTR [esp+8]
369
        mov     edx, DWORD PTR [_z_core+12]
370
	lea	eax, [eax+eax*4]
371
	mov	DWORD PTR [edx+16+eax*4], ecx
372
	ret
373
 
374
@zone_free@8:
375
	sub	esp, 8
376
	lea	edx, [edx+edx*4]
377
	mov	DWORD PTR [esp], ebx
378
	sal	edx, 2
379
	mov	ebx, ecx
380
	mov	DWORD PTR [esp+4], esi
381
	add	edx, DWORD PTR [ecx+12]
382
	mov	eax, DWORD PTR [edx+8]
383
	mov	esi, DWORD PTR [edx+12]
384
	sub	eax, 1
385
	test	eax, eax
386
	mov	DWORD PTR [edx+8], eax
387
        jne     .L79
388
	call	@buddy_system_free@8
389
	mov	eax, 1
390
	mov	ecx, esi
391
	sal	eax, cl
392
	add	DWORD PTR [ebx+16], eax
393
	sub	DWORD PTR [ebx+20], eax
394
.L79:
395
	mov	ebx, DWORD PTR [esp]
396
	mov	esi, DWORD PTR [esp+4]
397
	add	esp, 8
398
	ret
399
 
400
 
401
@zone_alloc@8:
402
	sub	esp, 8
403
	mov	DWORD PTR [esp], ebx
404
	mov	ebx, ecx
405
	mov	DWORD PTR [esp+4], esi
406
 
407
	pushf
408
	pop esi
409
	cli
410
 
411
@@:
412
        pause
413
        mov eax, [_z_core]
414
        test eax, eax
415
        jnz @b
416
        inc eax
417
        xchg [_z_core], eax
418
        test eax, eax
419
        jnz @b
420
 
421
	mov	eax, ecx
422
	call	_zone_frame_alloc
423
	mov	edx, DWORD PTR [ebx+4]
424
	mov	DWORD PTR [ebx], 0
425
 
426
	push esi
427
	popf
428
 
429
	mov	ebx, DWORD PTR [esp]
430
	add	eax, edx
431
	mov	esi, DWORD PTR [esp+4]
432
	sal	eax, 12
433
	add	esp, 8
434
	ret
435
 
436
alloc_page:
437
_alloc_page:
438
	push	ebx
439
 
440
	pushf
441
	pop ebx
442
	cli
443
@@:
444
        pause
445
        mov eax, [_z_core]
446
        test eax, eax
447
        jnz @b
448
        inc eax
449
        xchg [_z_core], eax
450
        test eax, eax
451
        jnz @b
452
 
453
        push edx
454
	xor	edx, edx
455
        mov     eax, _z_core
456
	call	_zone_frame_alloc
457
        pop edx
458
        mov     [_z_core], 0
459
 
460
	push ebx
461
	popf
462
 
463
	pop	ebx
464
	sal	eax, 12
465
	ret
466
 
467
alloc_pages:
468
_alloc_pages@4:
469
	push	ebx
470
 
471
	pushf
472
	pop ebx
473
	cli
474
@@:
475
        pause
476
        mov eax, [_z_core]
477
        test eax, eax
478
        jnz @b
479
        inc eax
480
        xchg [_z_core], eax
481
        test eax, eax
482
        jnz @b
483
 
484
	mov	eax, DWORD PTR [esp+8]
485
	add	eax, 7
486
	and	eax, -8
487
 
488
	xor ecx, ecx
489
	bsr ecx, eax
490
        inc ecx
491
 
492
        push edx
493
 
494
        mov     edx, ecx
495
        mov     eax, _z_core
496
	call	_zone_frame_alloc
497
        pop edx
498
 
499
        mov     [_z_core], 0
500
	push ebx
501
	popf
502
 
503
	pop	ebx
504
	sal	eax, 12
505
	ret	4
506
 
507
_zone_create:
508
	push	esi
509
	push	ebx
510
	sub	esp, 4
511
	mov	ebx, DWORD PTR [esp+16]
512
	mov	esi, DWORD PTR [esp+24]
513
	mov	DWORD PTR [esp], ebx
514
	call	_spinlock_initialize
515
	mov	eax, DWORD PTR [esp+20]
516
	mov	DWORD PTR [ebx+8], esi
517
	mov	DWORD PTR [ebx+16], esi
518
	mov	DWORD PTR [ebx+20], 0
519
	mov	DWORD PTR [ebx+4], eax
520
 
521
        xor eax, eax
522
	bsr eax, esi
523
 
524
        xor     edx, edx
525
	mov	BYTE PTR [ebx+24], al
526
.L81:
527
	lea	eax, [ebx+28+edx*8]
528
	mov	DWORD PTR [ebx+28+edx*8], eax
529
	mov	DWORD PTR [ebx+32+edx*8], eax
530
	movzx	eax, BYTE PTR [ebx+24]
531
	add	edx, 1
532
	cmp	eax, edx
533
        jae     .L81
534
	lea	ecx, [esi+esi*4]
535
	sal	ecx, 2
536
	call	@balloc@4
537
	test	esi, esi
538
	mov	DWORD PTR [ebx+12], eax
539
        je      .L83
540
	xor	ecx, ecx
541
	xor	edx, edx
542
.L85:
543
	mov	eax, edx
544
	add	ecx, 1
545
	add	eax, DWORD PTR [ebx+12]
546
	add	edx, 20
547
	cmp	ecx, esi
548
	mov	DWORD PTR [eax+8], 1
549
	mov	DWORD PTR [eax+12], 0
550
        jne     .L85
551
.L83:
552
	add	esp, 4
553
	mov	eax, 1
554
	pop	ebx
555
	pop	esi
556
	ret
557
 
558
_init_mm:
559
	push	ebx
847 serge 560
	sub	esp, 24
561
        mov     eax, DWORD PTR [_mem_amount]
562
        mov     DWORD PTR [esp], .LC3
563
	mov	ebx, eax
564
	shr	ebx, 12
565
	mov	DWORD PTR [esp+8], ebx
846 serge 566
	mov	DWORD PTR [esp+4], eax
847 serge 567
	call	_printf
568
        mov     eax, DWORD PTR [_pg_balloc]
569
        mov     DWORD PTR [esp], .LC4
570
	mov	DWORD PTR [esp+8], eax
571
	lea	eax, [ebx+ebx*4]
572
	sal	eax, 2
573
	mov	DWORD PTR [esp+4], eax
574
	call	_printf
575
	mov	DWORD PTR [esp+8], ebx
846 serge 576
	mov	DWORD PTR [esp+4], 0
577
        mov     DWORD PTR [esp], _z_core
578
	call	_zone_create
847 serge 579
	mov	DWORD PTR [esp+8], ebx
846 serge 580
	mov	DWORD PTR [esp+4], 0
581
        mov     DWORD PTR [esp], _z_core
582
	call	_zone_release
583
        mov     eax, DWORD PTR [_pg_balloc]
584
	mov	DWORD PTR [esp+4], 0
585
        mov     DWORD PTR [esp], _z_core
586
	shr	eax, 12
587
	mov	DWORD PTR [esp+8], eax
588
	call	_zone_reserve
847 serge 589
	add	esp, 24
846 serge 590
	pop	ebx
847 serge 591
        ret
592
.LC3:
593
        db "last page = %x total pages =  %x",10,0
594
.LC4:
595
        db "conf_size = %x  free mem start =%x",10,0
846 serge 596
 
847 serge 597
 
846 serge 598
_frame_free:
599
	push	ebx
600
	mov	edx, DWORD PTR [esp+8]
601
 
602
	pushf
603
	pop ebx
604
	cli
605
@@:
606
        pause
607
        mov eax, [_z_core]
608
        test eax, eax
609
        jnz @b
610
        inc eax
611
        xchg [_z_core], eax
612
        test eax, eax
613
        jnz @b
614
 
615
        mov     ecx, _z_core
616
	shr	edx, 12
617
	call	@zone_free@8
618
        mov     [_z_core], 0
619
 
620
	push ebx
621
	popf
622
 
623
	pop	ebx
624
	ret
625
 
626
_core_free:
627
	push	ebx
628
	mov	edx, DWORD PTR [esp+8]
629
 
630
	pushf
631
	pop ebx
632
	cli
633
@@:
634
        pause
635
        mov eax, [_z_core]
636
        test eax, eax
637
        jnz @b
638
        inc eax
639
        xchg [_z_core], eax
640
        test eax, eax
641
        jnz @b
642
 
643
        mov     ecx, _z_core
644
	shr	edx, 12
645
	call	@zone_free@8
646
        mov     [_z_core], 0
647
 
648
	push ebx
649
	popf
650
 
651
	pop	ebx
652
	ret
653
 
654
_core_alloc:
655
	push	ebx
656
	pushf
657
	pop ebx
658
	cli
659
@@:
660
        pause
661
        mov eax, [_z_core]
662
        test eax, eax
663
        jnz @b
664
        inc eax
665
        xchg [_z_core], eax
666
        test eax, eax
667
        jnz @b
668
 
669
	mov	edx, DWORD PTR [esp+8]
670
        mov     eax, _z_core
671
	call	_zone_frame_alloc
672
        mov     [_z_core], 0
673
 
674
	push ebx
675
	popf
676
 
677
	pop	ebx
678
	sal	eax, 12
679
	ret
680
 
681
 
682
restore DWORD
683
restore WORD
684
restore BYTE
685
 
686
restore PTR
687