Subversion Repositories Kolibri OS

Rev

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

Rev 448 Rev 465
Line 1... Line 1...
1
$Revision: 448 $
1
$Revision: 465 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
Line 619... Line 619...
619
HEAP_TOP  equ 0x5FC00000
619
HEAP_TOP  equ 0x5FC00000
Line 620... Line 620...
620
 
620
 
621
align 4
621
align 4
Line 622... Line 622...
622
proc init_heap
622
proc init_heap
623
 
-
 
624
           mov ebx,[CURRENT_TASK]
623
 
625
           shl ebx,8
624
           mov ebx,[current_slot]
626
           mov eax, [SLOT_BASE+APPDATA.heap_top+ebx]
625
           mov eax, [ebx+APPDATA.heap_top]
627
           test eax, eax
626
           test eax, eax
628
           jz @F
627
           jz @F
629
           sub eax,[SLOT_BASE+APPDATA.heap_base+ebx]
628
           sub eax,[ebx+APPDATA.heap_base]
630
           sub eax, 4096
629
           sub eax, 4096
631
           ret
630
           ret
632
@@:
631
@@:
633
           mov esi, [SLOT_BASE+APPDATA.mem_size+ebx]
632
           mov esi, [ebx+APPDATA.mem_size]
634
           add esi, 4095
633
           add esi, 4095
635
           and esi, not 4095
634
           and esi, not 4095
636
           mov [SLOT_BASE+APPDATA.mem_size+ebx], esi
635
           mov [ebx+APPDATA.mem_size], esi
637
           mov eax, HEAP_TOP
636
           mov eax, HEAP_TOP
Line 638... Line 637...
638
           mov [SLOT_BASE+APPDATA.heap_base+ebx], esi
637
           mov [ebx+APPDATA.heap_base], esi
639
           mov [SLOT_BASE+APPDATA.heap_top+ebx], eax
638
           mov [ebx+APPDATA.heap_top], eax
640
 
639
 
641
           sub eax, esi
640
           sub eax, esi
642
           add esi, new_app_base
641
       ;    add esi, new_app_base
643
           shr esi, 10
642
           shr esi, 10
644
           mov ecx, eax
643
           mov ecx, eax
Line 656... Line 655...
656
 
655
 
657
           mov ecx, [alloc_size]
656
           mov ecx, [alloc_size]
658
           add ecx, (4095+4096)
657
           add ecx, (4095+4096)
Line 659... Line 658...
659
           and ecx, not 4095
658
           and ecx, not 4095
660
 
-
 
661
           mov ebx, [CURRENT_TASK]
659
 
662
           shl ebx, 8
660
           mov ebx, [current_slot]
663
           mov esi, dword [ebx+SLOT_BASE+APPDATA.heap_base]; heap_base
-
 
664
           mov edi, dword [ebx+SLOT_BASE+APPDATA.heap_top]; heap_top
-
 
665
           add esi, new_app_base
661
           mov esi, dword [ebx+APPDATA.heap_base]  ; heap_base
666
           add edi, new_app_base
662
           mov edi, dword [ebx+APPDATA.heap_top]   ; heap_top
667
l_0:
663
l_0:
Line 668... Line 664...
668
           cmp esi, edi
664
           cmp esi, edi
Line 682... Line 678...
682
           add edx, ecx
678
           add edx, ecx
683
           sub eax, ecx;
679
           sub eax, ecx;
684
           or eax, FREE_BLOCK
680
           or eax, FREE_BLOCK
685
           shr edx, 12
681
           shr edx, 12
686
           mov [page_tabs+edx*4], eax
682
           mov [page_tabs+edx*4], eax
687
 
-
 
688
@@:
683
@@:
689
           or ecx, USED_BLOCK
684
           or ecx, USED_BLOCK
690
           mov [page_tabs+ebx*4], ecx
685
           mov [page_tabs+ebx*4], ecx
691
           shr ecx, 12
686
           shr ecx, 12
692
           dec ecx
687
           dec ecx
Line 695... Line 690...
695
           mov dword [page_tabs+ebx*4], 2
690
           mov dword [page_tabs+ebx*4], 2
696
           inc ebx
691
           inc ebx
697
           dec ecx
692
           dec ecx
698
           jnz @B
693
           jnz @B
Line 699... Line 694...
699
 
694
 
700
        mov     edx, [CURRENT_TASK]
-
 
701
        shl     edx, 8
695
           mov     edx, [current_slot]
702
        mov     ebx, [alloc_size]
696
           mov     ebx, [alloc_size]
703
        add     ebx, 0xFFF
697
           add     ebx, 0xFFF
704
        and     ebx, not 0xFFF
698
           and     ebx, not 0xFFF
705
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
699
           add     ebx, [edx+APPDATA.mem_size]
Line 706... Line 700...
706
        call    update_mem_size
700
           call    update_mem_size
707
 
701
 
708
           mov eax, esi
-
 
709
           add eax, 4096
702
           mov eax, esi
710
           sub eax, new_app_base
703
           add eax, 4096
711
           ret
704
           ret
712
m_next:
705
m_next:
713
           add esi, eax
706
           add esi, eax
Line 758... Line 751...
758
@@:
751
@@:
759
           inc esi
752
           inc esi
760
           dec ecx
753
           dec ecx
761
           jnz .release
754
           jnz .release
762
.not_used:
755
.not_used:
763
           mov edx, [CURRENT_TASK]
756
           mov edx, [current_slot]
764
           shl edx, 8
-
 
765
           mov esi, dword [edx+SLOT_BASE+APPDATA.heap_base]; heap_base
757
           mov esi, dword [edx+APPDATA.heap_base]
766
           mov edi, dword [edx+SLOT_BASE+APPDATA.heap_top]; heap_top
758
           mov edi, dword [edx+APPDATA.heap_top]
767
           sub ebx, [edx+SLOT_BASE+APPDATA.mem_size]
759
           sub ebx, [edx+APPDATA.mem_size]
768
           neg ebx
760
           neg ebx
769
           call update_mem_size
761
           call update_mem_size
770
           call user_normalize
762
           call user_normalize
771
           ret
763
           ret
772
.exit:
764
.exit:
Line 777... Line 769...
777
 
769
 
778
user_normalize:
770
user_normalize:
779
; in: esi=heap_base, edi=heap_top
771
; in: esi=heap_base, edi=heap_top
780
; out: eax=0 <=> OK
772
; out: eax=0 <=> OK
781
; destroys: ebx,edx,esi,edi
-
 
782
           add esi, new_app_base
-
 
783
           add edi, new_app_base
773
; destroys: ebx,edx,esi,edi
784
           shr esi, 12
774
           shr esi, 12
785
           shr edi, 12
775
           shr edi, 12
786
@@:
776
@@:
787
           mov eax, [page_tabs+esi*4]
777
           mov eax, [page_tabs+esi*4]
Line 833... Line 823...
833
        push    ebx
823
        push    ebx
834
        call    user_alloc
824
        call    user_alloc
835
        ret
825
        ret
836
@@:
826
@@:
837
        push    ecx edx
827
        push    ecx edx
838
        lea     ecx, [eax + new_app_base - 0x1000]
828
        lea     ecx, [eax - 0x1000]
839
        shr     ecx, 12
829
        shr     ecx, 12
840
        mov     edx, [page_tabs+ecx*4]
830
        mov     edx, [page_tabs+ecx*4]
841
        test    edx, USED_BLOCK
831
        test    edx, USED_BLOCK
842
        jnz     @f
832
        jnz     @f
843
; attempt to realloc invalid pointer
833
; attempt to realloc invalid pointer
Line 872... Line 862...
872
        sub     ebx, ecx
862
        sub     ebx, ecx
873
        cmp     ebx, 1
863
        cmp     ebx, 1
874
        jnz     .nofreeall
864
        jnz     .nofreeall
875
        mov     eax, [page_tabs+ecx*4]
865
        mov     eax, [page_tabs+ecx*4]
876
        and     eax, not 0xFFF
866
        and     eax, not 0xFFF
877
        mov     edx, [CURRENT_TASK]
867
        mov     edx, [current_slot]
878
        shl     edx, 8
-
 
879
        mov     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
868
        mov     ebx, [APPDATA.mem_size+edx]
880
        sub     ebx, eax
869
        sub     ebx, eax
881
        add     ebx, 0x1000
870
        add     ebx, 0x1000
882
        or      al, FREE_BLOCK
871
        or      al, FREE_BLOCK
883
        mov     [page_tabs+ecx*4], eax
872
        mov     [page_tabs+ecx*4], eax
884
        push    esi edi
873
        push    esi edi
885
        mov     esi, [SLOT_BASE+APPDATA.heap_base+edx]
874
        mov     esi, [APPDATA.heap_base+edx]
886
        mov     edi, [SLOT_BASE+APPDATA.heap_top+edx]
875
        mov     edi, [APPDATA.heap_top+edx]
887
        call    update_mem_size
876
        call    update_mem_size
888
        call    user_normalize
877
        call    user_normalize
889
        pop     edi esi
878
        pop     edi esi
890
        jmp     .ret0   ; all freed
879
        jmp     .ret0   ; all freed
891
.nofreeall:
880
.nofreeall:
Line 894... Line 883...
894
        or      ebx, USED_BLOCK
883
        or      ebx, USED_BLOCK
895
        xchg    [page_tabs+ecx*4], ebx
884
        xchg    [page_tabs+ecx*4], ebx
896
        shr     ebx, 12
885
        shr     ebx, 12
897
        sub     ebx, edx
886
        sub     ebx, edx
898
        push    ebx ecx edx
887
        push    ebx ecx edx
899
        mov     edx, [CURRENT_TASK]
888
        mov     edx, [current_slot]
900
        shl     edx, 8
-
 
901
        shl     ebx, 12
889
        shl     ebx, 12
902
        sub     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
890
        sub     ebx, [APPDATA.mem_size+edx]
903
        neg     ebx
891
        neg     ebx
904
        call    update_mem_size
892
        call    update_mem_size
905
        pop     edx ecx ebx
893
        pop     edx ecx ebx
906
        lea     eax, [ecx+1-(new_app_base shr 12)]
894
        lea     eax, [ecx+1]
907
        shl     eax, 12
895
        shl     eax, 12
908
        push    eax
896
        push    eax
909
        add     ecx, ebx
897
        add     ecx, ebx
910
        add     edx, ecx
898
        add     edx, ecx
911
        shl     ebx, 12
899
        shl     ebx, 12
912
        jz      .ret
900
        jz      .ret
913
        push    esi
901
        push    esi
914
        mov     esi, [CURRENT_TASK]
902
        mov     esi, [current_slot]
915
        shl     esi, 8
-
 
916
        mov     esi, [SLOT_BASE+APPDATA.heap_top+esi]
903
        mov     esi, [APPDATA.heap_top+esi]
917
        shr     esi, 12
904
        shr     esi, 12
918
@@:
905
@@:
919
        cmp     edx, esi
906
        cmp     edx, esi
920
        jae     .merge_done
907
        jae     .merge_done
921
        mov     eax, [page_tabs+edx*4]
908
        mov     eax, [page_tabs+edx*4]
Line 933... Line 920...
933
.ret:
920
.ret:
934
        pop     eax edx ecx
921
        pop     eax edx ecx
935
        ret
922
        ret
936
.realloc_add:
923
.realloc_add:
937
; get some additional memory
924
; get some additional memory
938
        mov     eax, [CURRENT_TASK]
925
        mov     eax, [current_slot]
939
        shl     eax, 8
-
 
940
        mov     eax, [SLOT_BASE+APPDATA.heap_top+eax]
926
        mov     eax, [APPDATA.heap_top+eax]
941
        add     eax, new_app_base
-
 
942
        shr     eax, 12
927
        shr     eax, 12
943
        cmp     edx, eax
928
        cmp     edx, eax
944
        jae     .cant_inplace
929
        jae     .cant_inplace
945
        mov     eax, [page_tabs+edx*4]
930
        mov     eax, [page_tabs+edx*4]
946
        shr     eax, 12
931
        shr     eax, 12
Line 956... Line 941...
956
        mov     eax, ebx
941
        mov     eax, ebx
957
        sub     eax, ecx
942
        sub     eax, ecx
958
        shl     eax, 12
943
        shl     eax, 12
959
        or      al, USED_BLOCK
944
        or      al, USED_BLOCK
960
        mov     [page_tabs+ecx*4], eax
945
        mov     [page_tabs+ecx*4], eax
961
        lea     eax, [ecx+1-(new_app_base shr 12)]
946
        lea     eax, [ecx+1]
962
        shl     eax, 12
947
        shl     eax, 12
963
        push    eax
948
        push    eax
964
        push    edi
949
        push    edi
965
        lea     edi, [page_tabs+edx*4]
950
        lea     edi, [page_tabs+edx*4]
966
        mov     eax, 2
951
        mov     eax, 2
967
        sub     ebx, edx
952
        sub     ebx, edx
968
        mov     ecx, ebx
953
        mov     ecx, ebx
969
        cld
954
        cld
970
        rep     stosd
955
        rep     stosd
971
        pop     edi
956
        pop     edi
972
        mov     edx, [CURRENT_TASK]
957
        mov     edx, [current_slot]
973
        shl     edx, 8
-
 
974
        shl     ebx, 12
958
        shl     ebx, 12
975
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
959
        add     ebx, [APPDATA.mem_size+edx]
976
        call    update_mem_size
960
        call    update_mem_size
977
        pop     eax edx ecx
961
        pop     eax edx ecx
978
        ret
962
        ret
979
.cant_inplace:
963
.cant_inplace:
980
        push    esi edi
964
        push    esi edi
981
        mov     eax, [CURRENT_TASK]
965
        mov     eax, [current_slot]
982
        shl     eax, 8
-
 
983
        mov     esi, [SLOT_BASE+APPDATA.heap_base+eax]
966
        mov     esi, [APPDATA.heap_base+eax]
984
        mov     edi, [SLOT_BASE+APPDATA.heap_top+eax]
967
        mov     edi, [APPDATA.heap_top+eax]
985
        add     esi, new_app_base
-
 
986
        add     edi, new_app_base
-
 
987
        shr     esi, 12
968
        shr     esi, 12
988
        shr     edi, 12
969
        shr     edi, 12
989
        sub     ebx, ecx
970
        sub     ebx, ecx
990
.find_place:
971
.find_place:
991
        cmp     esi, edi
972
        cmp     esi, edi
Line 1020... Line 1001...
1020
        or      al, USED_BLOCK
1001
        or      al, USED_BLOCK
1021
        mov     [page_tabs+esi*4], eax
1002
        mov     [page_tabs+esi*4], eax
1022
        inc     esi
1003
        inc     esi
1023
        mov     eax, esi
1004
        mov     eax, esi
1024
        shl     eax, 12
1005
        shl     eax, 12
1025
        sub     eax, new_app_base
-
 
1026
        push    eax
1006
        push    eax
1027
        mov     eax, [page_tabs+ecx*4]
1007
        mov     eax, [page_tabs+ecx*4]
1028
        and     eax, not 0xFFF
1008
        and     eax, not 0xFFF
1029
        or      al, FREE_BLOCK
1009
        or      al, FREE_BLOCK
1030
        sub     edx, ecx
1010
        sub     edx, ecx
Line 1041... Line 1021...
1041
        inc     esi
1021
        inc     esi
1042
        dec     ebx
1022
        dec     ebx
1043
        dec     edx
1023
        dec     edx
1044
        jnz     @b
1024
        jnz     @b
1045
        push    ebx
1025
        push    ebx
1046
        mov     edx, [CURRENT_TASK]
1026
        mov     edx, [current_slot]
1047
        shl     edx, 8
-
 
1048
        shl     ebx, 12
1027
        shl     ebx, 12
1049
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
1028
        add     ebx, [APPDATA.mem_size+edx]
1050
        call    update_mem_size
1029
        call    update_mem_size
1051
        pop     ebx
1030
        pop     ebx
1052
@@:
1031
@@:
1053
        mov     dword [page_tabs+esi*4], 2
1032
        mov     dword [page_tabs+esi*4], 2
1054
        inc     esi
1033
        inc     esi