Subversion Repositories Kolibri OS

Rev

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

Rev 444 Rev 453
Line 1... Line 1...
1
$Revision: 431 $
1
$Revision: 448 $
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 743... Line 743...
743
           xor eax, eax
743
           xor eax, eax
744
           xchg eax, [page_tabs+esi*4]
744
           xchg eax, [page_tabs+esi*4]
745
           test eax, 1
745
           test eax, 1
746
           jz @F
746
           jz @F
747
           call free_page
747
           call free_page
-
 
748
           mov eax, esi
-
 
749
           shl eax, 12
-
 
750
           invlpg [eax]
748
@@:
751
@@:
749
           inc esi
752
           inc esi
750
           dec ecx
753
           dec ecx
751
           jnz .release
754
           jnz .release
752
.not_used:
755
.not_used:
Line 754... Line 757...
754
           mov esi, dword [edx+APPDATA.heap_base]
757
           mov esi, dword [edx+APPDATA.heap_base]
755
           mov edi, dword [edx+APPDATA.heap_top]
758
           mov edi, dword [edx+APPDATA.heap_top]
756
           sub ebx, [edx+APPDATA.mem_size]
759
           sub ebx, [edx+APPDATA.mem_size]
757
           neg ebx
760
           neg ebx
758
           call update_mem_size
761
           call update_mem_size
-
 
762
           call user_normalize
-
 
763
           ret
-
 
764
.exit:
-
 
765
           xor eax, eax
-
 
766
           inc eax
-
 
767
           ret
-
 
768
endp
-
 
769
 
-
 
770
user_normalize:
-
 
771
; in: esi=heap_base, edi=heap_top
-
 
772
; out: eax=0 <=> OK
-
 
773
; destroys: ebx,edx,esi,edi
759
           shr esi, 12
774
           shr esi, 12
760
           shr edi, 12
775
           shr edi, 12
761
@@:
776
@@:
762
           mov eax, [page_tabs+esi*4]
777
           mov eax, [page_tabs+esi*4]
763
           test eax, USED_BLOCK
778
           test eax, USED_BLOCK
Line 796... Line 811...
796
           inc eax
811
           inc eax
797
           ret
812
           ret
798
.err:
813
.err:
799
           xor eax, eax
814
           xor eax, eax
800
           ret
815
           ret
-
 
816
 
-
 
817
user_realloc:
-
 
818
; in: eax = pointer, ebx = new size
-
 
819
; out: eax = new pointer or NULL
-
 
820
        test    eax, eax
-
 
821
        jnz     @f
-
 
822
; realloc(NULL,sz) - same as malloc(sz)
-
 
823
        push    ebx
-
 
824
        call    user_alloc
-
 
825
        ret
-
 
826
@@:
-
 
827
        push    ecx edx
-
 
828
        lea     ecx, [eax - 0x1000]
-
 
829
        shr     ecx, 12
-
 
830
        mov     edx, [page_tabs+ecx*4]
-
 
831
        test    edx, USED_BLOCK
-
 
832
        jnz     @f
-
 
833
; attempt to realloc invalid pointer
801
endp
834
.ret0:
-
 
835
        pop     edx ecx
-
 
836
        xor     eax, eax
-
 
837
        ret
-
 
838
@@:
-
 
839
        add     ebx, 0x1FFF
-
 
840
        shr     edx, 12
-
 
841
        shr     ebx, 12
-
 
842
; edx = allocated size, ebx = new size
-
 
843
        add     edx, ecx
-
 
844
        add     ebx, ecx
-
 
845
        cmp     edx, ebx
-
 
846
        jb      .realloc_add
-
 
847
; release part of allocated memory
-
 
848
.loop:
-
 
849
        cmp     edx, ebx
-
 
850
        jz      .release_done
-
 
851
        dec     edx
-
 
852
        xor     eax, eax
-
 
853
        xchg    eax, [page_tabs+edx*4]
-
 
854
        test    al, 1
-
 
855
        jz      .loop
-
 
856
        call    free_page
-
 
857
        mov     eax, edx
-
 
858
        shl     eax, 12
-
 
859
        invlpg  [eax]
-
 
860
        jmp     .loop
-
 
861
.release_done:
-
 
862
        sub     ebx, ecx
-
 
863
        cmp     ebx, 1
-
 
864
        jnz     .nofreeall
-
 
865
        mov     eax, [page_tabs+ecx*4]
-
 
866
        and     eax, not 0xFFF
-
 
867
        mov     edx, [CURRENT_TASK]
-
 
868
        shl     edx, 8
-
 
869
        mov     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
870
        sub     ebx, eax
-
 
871
        add     ebx, 0x1000
-
 
872
        or      al, FREE_BLOCK
-
 
873
        mov     [page_tabs+ecx*4], eax
-
 
874
        push    esi edi
-
 
875
        mov     esi, [SLOT_BASE+APPDATA.heap_base+edx]
-
 
876
        mov     edi, [SLOT_BASE+APPDATA.heap_top+edx]
-
 
877
        call    update_mem_size
-
 
878
        call    user_normalize
-
 
879
        pop     edi esi
-
 
880
        jmp     .ret0   ; all freed
-
 
881
.nofreeall:
-
 
882
        sub     edx, ecx
-
 
883
        shl     ebx, 12
-
 
884
        or      ebx, USED_BLOCK
-
 
885
        xchg    [page_tabs+ecx*4], ebx
-
 
886
        shr     ebx, 12
-
 
887
        sub     ebx, edx
-
 
888
        push    ebx ecx edx
-
 
889
        mov     edx, [CURRENT_TASK]
-
 
890
        shl     edx, 8
-
 
891
        shl     ebx, 12
-
 
892
        sub     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
893
        neg     ebx
-
 
894
        call    update_mem_size
-
 
895
        pop     edx ecx ebx
-
 
896
        lea     eax, [ecx+1]
-
 
897
        shl     eax, 12
-
 
898
        push    eax
-
 
899
        add     ecx, ebx
-
 
900
        add     edx, ecx
-
 
901
        shl     ebx, 12
-
 
902
        jz      .ret
-
 
903
        push    esi
-
 
904
        mov     esi, [CURRENT_TASK]
-
 
905
        shl     esi, 8
-
 
906
        mov     esi, [SLOT_BASE+APPDATA.heap_top+esi]
-
 
907
        shr     esi, 12
-
 
908
@@:
-
 
909
        cmp     edx, esi
-
 
910
        jae     .merge_done
-
 
911
        mov     eax, [page_tabs+edx*4]
-
 
912
        test    al, USED_BLOCK
-
 
913
        jz      .merge_done
-
 
914
        and     dword [page_tabs+edx*4], 0
-
 
915
        and     eax, not 0xFFF
-
 
916
        add     ebx, eax
-
 
917
        add     edx, eax
-
 
918
        jmp     @b
-
 
919
.merge_done:
-
 
920
        pop     esi
-
 
921
        or      ebx, FREE_BLOCK
-
 
922
        mov     [page_tabs+ecx*4], ebx
-
 
923
.ret:
-
 
924
        pop     eax edx ecx
-
 
925
        ret
-
 
926
.realloc_add:
-
 
927
; get some additional memory
-
 
928
        mov     eax, [CURRENT_TASK]
-
 
929
        shl     eax, 8
-
 
930
        mov     eax, [SLOT_BASE+APPDATA.heap_top+eax]
-
 
931
        shr     eax, 12
-
 
932
        cmp     edx, eax
-
 
933
        jae     .cant_inplace
-
 
934
        mov     eax, [page_tabs+edx*4]
-
 
935
        shr     eax, 12
-
 
936
        add     eax, edx
-
 
937
        cmp     eax, ebx
-
 
938
        jb      .cant_inplace
-
 
939
        sub     eax, ebx
-
 
940
        jz      @f
-
 
941
        shl     eax, 12
-
 
942
        or      al, FREE_BLOCK
-
 
943
        mov     [page_tabs+ebx*4], eax
-
 
944
@@:
-
 
945
        mov     eax, ebx
-
 
946
        sub     eax, ecx
-
 
947
        shl     eax, 12
-
 
948
        or      al, USED_BLOCK
-
 
949
        mov     [page_tabs+ecx*4], eax
-
 
950
        lea     eax, [ecx+1]
-
 
951
        shl     eax, 12
-
 
952
        push    eax
-
 
953
        push    edi
-
 
954
        lea     edi, [page_tabs+edx*4]
-
 
955
        mov     eax, 2
-
 
956
        sub     ebx, edx
-
 
957
        mov     ecx, ebx
-
 
958
        cld
-
 
959
        rep     stosd
-
 
960
        pop     edi
-
 
961
        mov     edx, [CURRENT_TASK]
-
 
962
        shl     edx, 8
-
 
963
        shl     ebx, 12
-
 
964
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
965
        call    update_mem_size
-
 
966
        pop     eax edx ecx
-
 
967
        ret
-
 
968
.cant_inplace:
-
 
969
        push    esi edi
-
 
970
        mov     eax, [CURRENT_TASK]
-
 
971
        shl     eax, 8
-
 
972
        mov     esi, [SLOT_BASE+APPDATA.heap_base+eax]
-
 
973
        mov     edi, [SLOT_BASE+APPDATA.heap_top+eax]
-
 
974
        shr     esi, 12
-
 
975
        shr     edi, 12
-
 
976
        sub     ebx, ecx
-
 
977
.find_place:
-
 
978
        cmp     esi, edi
-
 
979
        jae     .place_not_found
-
 
980
        mov     eax, [page_tabs+esi*4]
-
 
981
        test    al, FREE_BLOCK
-
 
982
        jz      .next_place
-
 
983
        shr     eax, 12
-
 
984
        cmp     eax, ebx
-
 
985
        jae     .place_found
-
 
986
        add     esi, eax
-
 
987
        jmp     .find_place
-
 
988
.next_place:
-
 
989
        shr     eax, 12
-
 
990
        add     esi, eax
-
 
991
        jmp     .find_place
-
 
992
.place_not_found:
-
 
993
        pop     edi esi
-
 
994
        jmp     .ret0
-
 
995
.place_found:
-
 
996
        sub     eax, ebx
-
 
997
        jz      @f
-
 
998
        push    esi
-
 
999
        add     esi, eax
-
 
1000
        shl     eax, 12
-
 
1001
        or      al, FREE_BLOCK
-
 
1002
        mov     [page_tabs+esi*4], eax
-
 
1003
        pop     esi
-
 
1004
@@:
-
 
1005
        mov     eax, ebx
-
 
1006
        shl     eax, 12
-
 
1007
        or      al, USED_BLOCK
-
 
1008
        mov     [page_tabs+esi*4], eax
-
 
1009
        inc     esi
-
 
1010
        mov     eax, esi
-
 
1011
        shl     eax, 12
-
 
1012
        sub     eax, new_app_base
-
 
1013
        push    eax
-
 
1014
        mov     eax, [page_tabs+ecx*4]
-
 
1015
        and     eax, not 0xFFF
-
 
1016
        or      al, FREE_BLOCK
-
 
1017
        sub     edx, ecx
-
 
1018
        mov     [page_tabs+ecx*4], eax
-
 
1019
        inc     ecx
-
 
1020
@@:
-
 
1021
        xor     eax, eax
-
 
1022
        xchg    eax, [page_tabs+ecx*4]
-
 
1023
        mov     [page_tabs+esi*4], eax
-
 
1024
	mov     eax, ecx
-
 
1025
	shl     eax, 12
-
 
1026
	invlpg  [eax]
-
 
1027
        inc     ecx
-
 
1028
        inc     esi
-
 
1029
        dec     ebx
-
 
1030
        dec     edx
-
 
1031
        jnz     @b
-
 
1032
        push    ebx
-
 
1033
        mov     edx, [CURRENT_TASK]
-
 
1034
        shl     edx, 8
-
 
1035
        shl     ebx, 12
-
 
1036
        add     ebx, [SLOT_BASE+APPDATA.mem_size+edx]
-
 
1037
        call    update_mem_size
-
 
1038
        pop     ebx
-
 
1039
@@:
-
 
1040
        mov     dword [page_tabs+esi*4], 2
-
 
1041
        inc     esi
-
 
1042
        dec     ebx
-
 
1043
        jnz     @b
-
 
1044
        pop     eax edi esi edx ecx
-
 
1045
        ret
Line 802... Line 1046...
802
 
1046
 
803
if 0
1047
if 0
804
align 4
1048
align 4
805
proc alloc_dll
1049
proc alloc_dll