Subversion Repositories Kolibri OS

Rev

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

Rev 4429 Rev 4430
Line 564... Line 564...
564
 
564
 
565
align 4
565
align 4
Line 566... Line 566...
566
proc init_heap
566
proc init_heap
-
 
567
 
567
 
568
        mov     ebx, [current_slot]
568
        mov     ebx, [current_slot]
569
        mov     ebx, [ebx+APPDATA.process]
569
        mov     eax, [ebx+APPDATA.heap_top]
570
        mov     eax, [ebx+PROC.heap_top]
570
        test    eax, eax
571
        test    eax, eax
571
        jz      @F
572
        jz      @F
572
        sub     eax, [ebx+APPDATA.heap_base]
573
        sub     eax, [ebx+PROC.heap_base]
573
        sub     eax, 4096
574
        sub     eax, PAGE_SIZE
574
        ret
575
        ret
575
@@:
576
@@:
576
        mov     esi, [ebx+APPDATA.mem_size]
577
        mov     esi, [ebx+PROC.mem_used]
577
        add     esi, 4095
578
        add     esi, 4095
578
        and     esi, not 4095
579
        and     esi, not 4095
579
        mov     [ebx+APPDATA.mem_size], esi
580
        mov     [ebx+PROC.mem_used], esi
580
        mov     eax, HEAP_TOP
581
        mov     eax, HEAP_TOP
Line 581... Line 582...
581
        mov     [ebx+APPDATA.heap_base], esi
582
        mov     [ebx+PROC.heap_base], esi
582
        mov     [ebx+APPDATA.heap_top], eax
583
        mov     [ebx+PROC.heap_top], eax
583
 
584
 
584
        sub     eax, esi
585
        sub     eax, esi
585
        shr     esi, 10
586
        shr     esi, 10
586
        mov     ecx, eax
587
        mov     ecx, eax
587
        sub     eax, 4096
588
        sub     eax, PAGE_SIZE
588
        or      ecx, FREE_BLOCK
589
        or      ecx, FREE_BLOCK
Line 596... Line 597...
596
        push    ebx
597
        push    ebx
597
        push    esi
598
        push    esi
598
        push    edi
599
        push    edi
Line 599... Line 600...
599
 
600
 
600
        mov     ecx, [alloc_size]
601
        mov     ecx, [alloc_size]
601
        add     ecx, (4095+4096)
602
        add     ecx, (4095+PAGE_SIZE)
Line 602... Line 603...
602
        and     ecx, not 4095
603
        and     ecx, not 4095
-
 
604
 
603
 
605
        mov     ebx, [current_slot]
604
        mov     ebx, [current_slot]
606
        mov     ebx, [ebx+APPDATA.process]
605
        mov     esi, dword [ebx+APPDATA.heap_base] ; heap_base
607
        mov     esi, dword [ebx+PROC.heap_base] ; heap_base
606
        mov     edi, dword [ebx+APPDATA.heap_top]  ; heap_top
608
        mov     edi, dword [ebx+PROC.heap_top]  ; heap_top
607
l_0:
609
.scan:
Line 608... Line 610...
608
        cmp     esi, edi
610
        cmp     esi, edi
609
        jae     m_exit
611
        jae     .m_exit
610
 
612
 
611
        mov     ebx, esi
613
        mov     ebx, esi
612
        shr     ebx, 12
614
        shr     ebx, 12
613
        mov     eax, [page_tabs+ebx*4]
615
        mov     eax, [page_tabs+ebx*4]
614
        test    al, FREE_BLOCK
616
        test    al, FREE_BLOCK
615
        jz      test_used
617
        jz      .test_used
616
        and     eax, 0xFFFFF000
618
        and     eax, 0xFFFFF000
Line 617... Line 619...
617
        cmp     eax, ecx   ;alloc_size
619
        cmp     eax, ecx   ;alloc_size
618
        jb      m_next
620
        jb      .m_next
619
        jz      @f
621
        jz      @f
Line 636... Line 638...
636
        dec     ecx
638
        dec     ecx
637
        jnz     @B
639
        jnz     @B
638
.no:
640
.no:
Line 639... Line 641...
639
 
641
 
-
 
642
        mov     edx, [current_slot]
-
 
643
        mov     edx, [edx+APPDATA.process]
640
        mov     edx, [current_slot]
644
 
641
        mov     ebx, [alloc_size]
645
        mov     ebx, [alloc_size]
642
        add     ebx, 0xFFF
646
        add     ebx, 0xFFF
643
        and     ebx, not 0xFFF
647
        and     ebx, not 0xFFF
644
        add     ebx, [edx+APPDATA.mem_size]
-
 
Line 645... Line 648...
645
        call    update_mem_size
648
        add     [edx+PROC.mem_used], ebx
Line 646... Line 649...
646
 
649
 
647
        lea     eax, [esi+4096]
650
        lea     eax, [esi+4096]
648
 
651
 
649
        pop     edi
652
        pop     edi
650
        pop     esi
653
        pop     esi
651
        pop     ebx
654
        pop     ebx
652
        ret
655
        ret
Line 653... Line 656...
653
test_used:
656
.test_used:
654
        test    al, USED_BLOCK
657
        test    al, USED_BLOCK
655
        jz      m_exit
658
        jz      .m_exit
656
 
659
 
657
        and     eax, 0xFFFFF000
660
        and     eax, 0xFFFFF000
658
m_next:
661
.m_next:
659
        add     esi, eax
662
        add     esi, eax
660
        jmp     l_0
663
        jmp     .scan
661
m_exit:
664
.m_exit:
662
        xor     eax, eax
665
        xor     eax, eax
Line 672... Line 675...
672
        push    ebx
675
        push    ebx
673
        push    esi
676
        push    esi
674
        push    edi
677
        push    edi
Line 675... Line 678...
675
 
678
 
-
 
679
        mov     ebx, [current_slot]
-
 
680
        mov     ebx, [ebx+APPDATA.process]
676
        mov     ebx, [current_slot]
681
 
677
        mov     edx, [address]
682
        mov     edx, [address]
678
        and     edx, not 0xFFF
683
        and     edx, not 0xFFF
679
        mov     [address], edx
684
        mov     [address], edx
680
        sub     edx, 0x1000
685
        sub     edx, 0x1000
681
        jb      .error
686
        jb      .error
682
        mov     esi, [ebx+APPDATA.heap_base]
687
        mov     esi, [ebx+PROC.heap_base]
683
        mov     edi, [ebx+APPDATA.heap_top]
688
        mov     edi, [ebx+PROC.heap_top]
684
        cmp     edx, esi
689
        cmp     edx, esi
685
        jb      .error
690
        jb      .error
686
.scan:
691
.scan:
687
        cmp     esi, edi
692
        cmp     esi, edi
Line 746... Line 751...
746
        jz      .nothird
751
        jz      .nothird
747
        or      cl, FREE_BLOCK
752
        or      cl, FREE_BLOCK
748
        mov     [page_tabs+ebx*4], ecx
753
        mov     [page_tabs+ebx*4], ecx
Line 749... Line 754...
749
 
754
 
750
.nothird:
-
 
751
 
755
.nothird:
-
 
756
        mov     edx, [current_slot]
-
 
757
        mov     edx, [edx+APPDATA.process]
752
        mov     edx, [current_slot]
758
 
753
        mov     ebx, [alloc_size]
759
        mov     ebx, [alloc_size]
754
        add     ebx, 0xFFF
760
        add     ebx, 0xFFF
755
        and     ebx, not 0xFFF
761
        and     ebx, not 0xFFF
756
        add     ebx, [edx+APPDATA.mem_size]
-
 
Line 757... Line 762...
757
        call    update_mem_size
762
        add     [edx+PROC.mem_used], ebx
Line 758... Line 763...
758
 
763
 
759
        mov     eax, [address]
764
        mov     eax, [address]
Line 809... Line 814...
809
 
814
 
810
.released:
815
.released:
Line 811... Line 816...
811
        push    edi
816
        push    edi
-
 
817
 
812
 
818
        mov     edx, [current_slot]
813
        mov     edx, [current_slot]
819
        mov     edx, [edx+APPDATA.process]
814
        mov     esi, dword [edx+APPDATA.heap_base]
820
        mov     esi, dword [edx+PROC.heap_base]
815
        mov     edi, dword [edx+APPDATA.heap_top]
821
        mov     edi, dword [edx+PROC.heap_top]
816
        sub     ebx, [edx+APPDATA.mem_size]
822
        sub     ebx, [edx+PROC.mem_used]
817
        neg     ebx
823
        neg     ebx
818
        call    update_mem_size
824
        mov     [edx+PROC.mem_used], ebx
819
        call    user_normalize
825
        call    user_normalize
820
        pop     edi
826
        pop     edi
821
        pop     ebx
827
        pop     ebx
Line 997... Line 1003...
997
        cmp     ebx, 1
1003
        cmp     ebx, 1
998
        jnz     .nofreeall
1004
        jnz     .nofreeall
999
        mov     eax, [page_tabs+ecx*4]
1005
        mov     eax, [page_tabs+ecx*4]
1000
        and     eax, not 0xFFF
1006
        and     eax, not 0xFFF
1001
        mov     edx, [current_slot]
1007
        mov     edx, [current_slot]
-
 
1008
        mov     edx, [edx+APPDATA.process]
1002
        mov     ebx, [APPDATA.mem_size+edx]
1009
        mov     ebx, [edx+PROC.mem_used]
1003
        sub     ebx, eax
1010
        sub     ebx, eax
1004
        add     ebx, 0x1000
1011
        add     ebx, 0x1000
1005
        or      al, FREE_BLOCK
1012
        or      al, FREE_BLOCK
1006
        mov     [page_tabs+ecx*4], eax
1013
        mov     [page_tabs+ecx*4], eax
1007
        push    esi edi
1014
        push    esi edi
1008
        mov     esi, [APPDATA.heap_base+edx]
1015
        mov     esi, [edx+PROC.heap_base]
1009
        mov     edi, [APPDATA.heap_top+edx]
1016
        mov     edi, [edx+PROC.heap_top]
1010
        call    update_mem_size
1017
        mov     [edx+PROC.mem_used], ebx
1011
        call    user_normalize
1018
        call    user_normalize
1012
        pop     edi esi
1019
        pop     edi esi
1013
        jmp     .ret0   ; all freed
1020
        jmp     .ret0   ; all freed
1014
.nofreeall:
1021
.nofreeall:
1015
        sub     edx, ecx
1022
        sub     edx, ecx
Line 1018... Line 1025...
1018
        xchg    [page_tabs+ecx*4], ebx
1025
        xchg    [page_tabs+ecx*4], ebx
1019
        shr     ebx, 12
1026
        shr     ebx, 12
1020
        sub     ebx, edx
1027
        sub     ebx, edx
1021
        push    ebx ecx edx
1028
        push    ebx ecx edx
1022
        mov     edx, [current_slot]
1029
        mov     edx, [current_slot]
-
 
1030
        mov     edx, [edx+APPDATA.process]
1023
        shl     ebx, 12
1031
        shl     ebx, 12
1024
        sub     ebx, [APPDATA.mem_size+edx]
1032
        sub     ebx, [edx+PROC.mem_used]
1025
        neg     ebx
1033
        neg     ebx
1026
        call    update_mem_size
1034
        mov     [edx+PROC.mem_used], ebx
1027
        pop     edx ecx ebx
1035
        pop     edx ecx ebx
1028
        lea     eax, [ecx+1]
1036
        lea     eax, [ecx+1]
1029
        shl     eax, 12
1037
        shl     eax, 12
1030
        push    eax
1038
        push    eax
1031
        add     ecx, edx
1039
        add     ecx, edx
1032
        lea     edx, [ecx+ebx]
1040
        lea     edx, [ecx+ebx]
1033
        shl     ebx, 12
1041
        shl     ebx, 12
1034
        jz      .ret
1042
        jz      .ret
1035
        push    esi
1043
        push    esi
1036
        mov     esi, [current_slot]
1044
        mov     esi, [current_slot]
1037
        mov     esi, [APPDATA.heap_top+esi]
1045
        mov     esi, [esi+APPDATA.process]
-
 
1046
        mov     esi, [esi+PROC.heap_top]
1038
        shr     esi, 12
1047
        shr     esi, 12
1039
@@:
1048
@@:
1040
        cmp     edx, esi
1049
        cmp     edx, esi
1041
        jae     .merge_done
1050
        jae     .merge_done
1042
        mov     eax, [page_tabs+edx*4]
1051
        mov     eax, [page_tabs+edx*4]
Line 1056... Line 1065...
1056
        pop     eax edx ecx
1065
        pop     eax edx ecx
1057
        ret
1066
        ret
1058
.realloc_add:
1067
.realloc_add:
1059
; get some additional memory
1068
; get some additional memory
1060
        mov     eax, [current_slot]
1069
        mov     eax, [current_slot]
-
 
1070
        mov     eax, [eax+APPDATA.process]
1061
        mov     eax, [APPDATA.heap_top+eax]
1071
        mov     eax, [eax+PROC.heap_top]
1062
        shr     eax, 12
1072
        shr     eax, 12
1063
        cmp     edx, eax
1073
        cmp     edx, eax
1064
        jae     .cant_inplace
1074
        jae     .cant_inplace
1065
        mov     eax, [page_tabs+edx*4]
1075
        mov     eax, [page_tabs+edx*4]
1066
        test    al, FREE_BLOCK
1076
        test    al, FREE_BLOCK
Line 1089... Line 1099...
1089
        mov     ecx, ebx
1099
        mov     ecx, ebx
1090
        cld
1100
        cld
1091
        rep stosd
1101
        rep stosd
1092
        pop     edi
1102
        pop     edi
1093
        mov     edx, [current_slot]
1103
        mov     edx, [current_slot]
-
 
1104
        mov     edx, [edx+APPDATA.process]
1094
        shl     ebx, 12
1105
        shl     ebx, 12
1095
        add     ebx, [APPDATA.mem_size+edx]
1106
        add     [edx+PROC.mem_used], ebx
1096
        call    update_mem_size
-
 
1097
        pop     eax edx ecx
1107
        pop     eax edx ecx
1098
        ret
1108
        ret
1099
.cant_inplace:
1109
.cant_inplace:
1100
        push    esi edi
1110
        push    esi edi
1101
        mov     eax, [current_slot]
1111
        mov     eax, [current_slot]
-
 
1112
        mov     eax, [eax+APPDATA.process]
1102
        mov     esi, [APPDATA.heap_base+eax]
1113
        mov     esi, [eax+PROC.heap_base]
1103
        mov     edi, [APPDATA.heap_top+eax]
1114
        mov     edi, [eax+PROC.heap_top]
1104
        shr     esi, 12
1115
        shr     esi, 12
1105
        shr     edi, 12
1116
        shr     edi, 12
1106
        sub     ebx, ecx
1117
        sub     ebx, ecx
1107
.find_place:
1118
.find_place:
1108
        cmp     esi, edi
1119
        cmp     esi, edi
Line 1162... Line 1173...
1162
        dec     edx
1173
        dec     edx
1163
        jnz     @b
1174
        jnz     @b
1164
.no:
1175
.no:
1165
        push    ebx
1176
        push    ebx
1166
        mov     edx, [current_slot]
1177
        mov     edx, [current_slot]
-
 
1178
        mov     edx, [eax+APPDATA.process]
1167
        shl     ebx, 12
1179
        shl     ebx, 12
1168
        add     ebx, [APPDATA.mem_size+edx]
1180
        add     [edx+PROC.mem_used], ebx
1169
        call    update_mem_size
-
 
1170
        pop     ebx
1181
        pop     ebx
1171
@@:
1182
@@:
1172
        mov     dword [page_tabs+esi*4], 2
1183
        mov     dword [page_tabs+esi*4], 2
1173
        inc     esi
1184
        inc     esi
1174
        dec     ebx
1185
        dec     ebx
1175
        jnz     @b
1186
        jnz     @b
1176
        pop     eax edi esi edx ecx
1187
        pop     eax edi esi edx ecx
1177
        ret
1188
        ret
Line 1178... Line -...
1178
 
-
 
1179
if 0
-
 
1180
align 4
-
 
1181
proc alloc_dll
-
 
1182
        pushf
-
 
1183
        cli
-
 
1184
        bsf     eax, [dll_map]
-
 
1185
        jnz     .find
-
 
1186
        popf
-
 
1187
        xor     eax, eax
-
 
1188
        ret
-
 
1189
.find:
-
 
1190
        btr     [dll_map], eax
-
 
1191
        popf
-
 
1192
        shl     eax, 5
-
 
1193
        add     eax, dll_tab
-
 
1194
        ret
-
 
1195
endp
-
 
1196
 
-
 
1197
align 4
-
 
1198
proc alloc_service
-
 
1199
        pushf
-
 
1200
        cli
-
 
1201
        bsf     eax, [srv_map]
-
 
1202
        jnz     .find
-
 
1203
        popf
-
 
1204
        xor     eax, eax
-
 
1205
        ret
-
 
1206
.find:
-
 
1207
        btr     [srv_map], eax
-
 
1208
        popf
-
 
1209
        shl     eax, 0x02
-
 
1210
        lea     eax, [srv_tab+eax+eax*8] ;srv_tab+eax*36
-
 
1211
        ret
-
 
1212
endp
-
 
1213
 
-
 
Line 1214... Line 1189...
1214
end if
1189
 
Line 1215... Line 1190...
1215
 
1190
 
1216
 
1191