Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | 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	esi
560
	xor	eax, eax
561
	push	ebx
562
	xor	esi, esi
563
	sub	esp, 20
564
        mov     ebx, DWORD PTR [_mem_counter]
565
	test	ebx, ebx
566
        jle     .L93
567
	xor	ecx, ecx
568
	xor	edx, edx
569
        jmp     .L94
570
.L95:
571
	add	ecx, 1
572
	add	edx, 20
573
	cmp	ecx, ebx
574
        je      .L103
575
.L94:
576
        cmp     DWORD PTR [_mem_table+edx+16], 1
577
        jne     .L95
578
        mov     eax, DWORD PTR [_mem_table+edx]
579
        add     eax, DWORD PTR [_mem_table+edx+8]
580
	and	eax, -4096
581
	cmp	esi, eax
582
        jae     .L95
583
	add	ecx, 1
584
	add	edx, 20
585
	cmp	ecx, ebx
586
	mov	esi, eax
587
        jne     .L94
588
.L103:
589
	cmp	esi, 268435456
590
	mov	eax, esi
591
        ja      .L104
592
	mov	esi, eax
593
	shr	esi, 12
594
.L93:
595
        mov     DWORD PTR [_mem_amount], eax
596
        mov [pg_data.mem_amount], eax
597
        mov [pg_data.pages_count], esi
598
 
599
        mov     DWORD PTR [esp+8], esi
600
	mov	DWORD PTR [esp+4], eax
601
        mov     DWORD PTR [esp], .LC1
602
        call    _printf
603
 
604
	mov	DWORD PTR [esp+8], esi
605
	mov	DWORD PTR [esp+4], 0
606
        mov     DWORD PTR [esp], _z_core
607
 
608
	call	_zone_create
609
	mov	DWORD PTR [esp+8], esi
610
	mov	DWORD PTR [esp+4], 0
611
        mov     DWORD PTR [esp], _z_core
612
	call	_zone_release
613
        mov     eax, DWORD PTR [_pg_balloc]
614
	mov	DWORD PTR [esp+4], 0
615
        mov     DWORD PTR [esp], _z_core
616
	shr	eax, 12
617
	mov	DWORD PTR [esp+8], eax
618
	call	_zone_reserve
619
	add	esp, 20
620
	pop	ebx
621
	pop	esi
622
	ret
623
.L104:
624
	mov	eax, 268435456
625
	mov	esi, eax
626
	shr	esi, 12
627
        jmp     .L93
628
.LC1:
629
        db 'memory size = %x total pages =  %x',10,0
630
 
631
_frame_free:
632
	push	ebx
633
	mov	edx, DWORD PTR [esp+8]
634
 
635
	pushf
636
	pop ebx
637
	cli
638
@@:
639
        pause
640
        mov eax, [_z_core]
641
        test eax, eax
642
        jnz @b
643
        inc eax
644
        xchg [_z_core], eax
645
        test eax, eax
646
        jnz @b
647
 
648
        mov     ecx, _z_core
649
	shr	edx, 12
650
	call	@zone_free@8
651
        mov     [_z_core], 0
652
 
653
	push ebx
654
	popf
655
 
656
	pop	ebx
657
	ret
658
 
659
_core_free:
660
	push	ebx
661
	mov	edx, DWORD PTR [esp+8]
662
 
663
	pushf
664
	pop ebx
665
	cli
666
@@:
667
        pause
668
        mov eax, [_z_core]
669
        test eax, eax
670
        jnz @b
671
        inc eax
672
        xchg [_z_core], eax
673
        test eax, eax
674
        jnz @b
675
 
676
        mov     ecx, _z_core
677
	shr	edx, 12
678
	call	@zone_free@8
679
        mov     [_z_core], 0
680
 
681
	push ebx
682
	popf
683
 
684
	pop	ebx
685
	ret
686
 
687
_core_alloc:
688
	push	ebx
689
	pushf
690
	pop ebx
691
	cli
692
@@:
693
        pause
694
        mov eax, [_z_core]
695
        test eax, eax
696
        jnz @b
697
        inc eax
698
        xchg [_z_core], eax
699
        test eax, eax
700
        jnz @b
701
 
702
	mov	edx, DWORD PTR [esp+8]
703
        mov     eax, _z_core
704
	call	_zone_frame_alloc
705
        mov     [_z_core], 0
706
 
707
	push ebx
708
	popf
709
 
710
	pop	ebx
711
	sal	eax, 12
712
	ret
713
 
714
 
715
restore DWORD
716
restore WORD
717
restore BYTE
718
 
719
restore PTR
720