Subversion Repositories Kolibri OS

Rev

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

Rev 1311 Rev 1314
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 1311 $
8
$Revision: 1314 $
9
 
9
 
Line 712... Line 712...
712
       ;cld     ;caller is duty for this
712
       ;cld     ;caller is duty for this
713
        rep     movsd
713
        rep     movsd
714
        jmp     .exit
714
        jmp     .exit
715
endp
715
endp
Line 716... Line 716...
716
 
716
 
717
align 4
717
; returns number of mapped bytes
718
proc map_mem stdcall, lin_addr:dword,pdir:dword,\
718
proc map_mem stdcall, lin_addr:dword,slot:dword,\
719
                      ofs:dword,buf_size:dword
719
                      ofs:dword,buf_size:dword,req_access:dword
-
 
720
           push 0 ; initialize number of mapped bytes
720
           mov eax, [buf_size]
721
 
721
           test eax, eax
722
           cmp [buf_size], 0
Line 722... Line 723...
722
           jz .exit
723
           jz .exit
-
 
724
 
-
 
725
           mov eax, [slot]
723
 
726
           shl eax, 8
Line 724... Line 727...
724
           mov eax, [pdir]
727
           mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
725
           and eax, 0xFFFFF000
728
           and eax, 0xFFFFF000
726
 
729
 
Line 751... Line 754...
751
           mov edx, [ofs]
754
           mov edx, [ofs]
752
           shr edx, 12
755
           shr edx, 12
753
           and edx, 0x3FF
756
           and edx, 0x3FF
754
           mov esi, [ipc_ptab]
757
           mov esi, [ipc_ptab]
Line 755... Line 758...
755
 
758
 
756
.map:      mov eax, [esi+edx*4]
759
.map:
757
           and eax, 0xFFFFF000
760
           stdcall safe_map_page,[slot],[req_access],[ofs]
758
           jz  .exit
761
           jnc .exit
-
 
762
           add dword [ebp-4], 4096
759
           stdcall map_page,edi,eax,PG_UW
763
           add [ofs], 4096
760
           dec ecx
764
           dec ecx
761
           jz  .exit
765
           jz  .exit
762
           add edi, 0x1000
766
           add edi, 0x1000
763
           inc edx
767
           inc edx
Line 771... Line 775...
771
           stdcall map_page,esi,eax,PG_UW
775
           stdcall map_page,esi,eax,PG_UW
772
           xor edx, edx
776
           xor edx, edx
773
           jmp .map
777
           jmp .map
Line 774... Line 778...
774
 
778
 
-
 
779
.exit:
775
.exit:
780
           pop eax
776
           ret
781
           ret
Line 777... Line -...
777
endp
-
 
778
 
782
endp
779
align 4
783
 
780
proc map_memEx stdcall, lin_addr:dword,pdir:dword,\
784
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
-
 
785
                        ofs:dword,buf_size:dword,req_access:dword
781
                        ofs:dword,buf_size:dword
786
           push 0 ; initialize number of mapped bytes
782
           mov eax, [buf_size]
787
 
Line 783... Line 788...
783
           test eax, eax
788
           cmp [buf_size], 0
-
 
789
           jz .exit
-
 
790
 
784
           jz .exit
791
           mov eax, [slot]
Line 785... Line 792...
785
 
792
           shl eax, 8
786
           mov eax, [pdir]
793
           mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
787
           and eax, 0xFFFFF000
794
           and eax, 0xFFFFF000
788
 
795
 
789
           stdcall map_page,[proc_mem_pdir],eax,dword PG_UW
796
           stdcall map_page,[proc_mem_pdir],eax,PG_UW
790
           mov ebx, [ofs]
797
           mov ebx, [ofs]
791
           shr ebx, 22
798
           shr ebx, 22
792
           mov esi, [proc_mem_pdir]
799
           mov esi, [proc_mem_pdir]
793
           mov edi, [proc_mem_tab]
800
           mov edi, [proc_mem_tab]
794
           mov eax, [esi+ebx*4]
801
           mov eax, [esi+ebx*4]
Line 795... Line 802...
795
           and eax, 0xFFFFF000
802
           and eax, 0xFFFFF000
796
           test eax, eax
803
           test eax, eax
797
           jz .exit
804
           jz .exit
798
           stdcall map_page,edi,eax,dword PG_UW
805
           stdcall map_page,edi,eax,PG_UW
Line 807... Line 814...
807
           mov edx, [ofs]
814
           mov edx, [ofs]
808
           shr edx, 12
815
           shr edx, 12
809
           and edx, 0x3FF
816
           and edx, 0x3FF
810
           mov esi, [proc_mem_tab]
817
           mov esi, [proc_mem_tab]
Line 811... Line 818...
811
 
818
 
812
.map:      mov eax, [esi+edx*4]
819
.map:
813
;           and eax, 0xFFFFF000
-
 
814
;           test eax, eax
820
           stdcall safe_map_page,[slot],[req_access],[ofs]
815
;           jz .exit
821
           jnc .exit
816
           stdcall map_page,edi,eax,dword PG_UW
822
           add dword [ebp-4], 0x1000
-
 
823
           add edi, 0x1000
817
           add edi, 0x1000
824
           add [ofs], 0x1000
818
           inc edx
825
           inc edx
819
           dec ecx
826
           dec ecx
820
           jnz .map
827
           jnz .map
-
 
828
.exit:
821
.exit:
829
           pop eax
822
           ret
830
           ret
Line -... Line 831...
-
 
831
endp
-
 
832
 
-
 
833
; in: esi+edx*4 = pointer to page table entry
-
 
834
; in: [slot], [req_access], [ofs] on the stack
-
 
835
; in: edi = linear address to map
-
 
836
; out: CF cleared <=> failed
-
 
837
; destroys: only eax
-
 
838
proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword
-
 
839
	mov	eax, [esi+edx*4]
-
 
840
	test	al, PG_MAP
-
 
841
	jz	.not_present
-
 
842
	test	al, PG_WRITE
-
 
843
	jz	.resolve_readonly
-
 
844
; normal case: writable page, just map with requested access
-
 
845
.map:
-
 
846
	stdcall	map_page, edi, eax, [req_access]
-
 
847
	stc
-
 
848
.fail:
-
 
849
	ret
-
 
850
.not_present:
-
 
851
; check for alloc-on-demand page
-
 
852
	test	al, 2
-
 
853
	jz	.fail
-
 
854
; allocate new page, save it to source page table
-
 
855
	push	ecx
-
 
856
	call	alloc_page
-
 
857
	pop	ecx
-
 
858
	test	eax, eax
-
 
859
	jz	.fail
-
 
860
	or	al, PG_UW
-
 
861
	mov	[esi+edx*4], eax
-
 
862
	jmp	.map
-
 
863
.resolve_readonly:
-
 
864
; readonly page, probably copy-on-write
-
 
865
; check: readonly request of readonly page is ok
-
 
866
	test	[req_access], PG_WRITE
-
 
867
	jz	.map
-
 
868
; find control structure for this page
-
 
869
	pushf
-
 
870
	cli
-
 
871
	cld
-
 
872
	push	ebx ecx
-
 
873
	mov	eax, [slot]
-
 
874
	shl	eax, 8
-
 
875
	mov	eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
-
 
876
	test	eax, eax
-
 
877
	jz	.no_hdll
-
 
878
	mov	ecx, [eax+HDLL.fd]
-
 
879
.scan_hdll:
-
 
880
	cmp	ecx, eax
-
 
881
	jz	.no_hdll
-
 
882
	mov	ebx, [ofs]
-
 
883
	and	ebx, not 0xFFF
-
 
884
	sub	ebx, [ecx+HDLL.base]
-
 
885
	cmp	ebx, [ecx+HDLL.size]
-
 
886
	jb	.hdll_found
-
 
887
	mov	ecx, [ecx+HDLL.fd]
-
 
888
	jmp	.scan_hdll
-
 
889
.no_hdll:
-
 
890
	pop	ecx ebx
-
 
891
	popf
-
 
892
	clc
-
 
893
	ret
-
 
894
.hdll_found:
-
 
895
; allocate page, save it in page table, map it, copy contents from base
-
 
896
	mov	eax, [ecx+HDLL.parent]
-
 
897
	add	ebx, [eax+DLLDESCR.data]
-
 
898
	call	alloc_page
-
 
899
	test	eax, eax
-
 
900
	jz	.no_hdll
-
 
901
	or	al, PG_UW
-
 
902
	mov	[esi+edx*4], eax
-
 
903
	stdcall	map_page, edi, eax, [req_access]
-
 
904
	push	esi edi
-
 
905
	mov	esi, ebx
-
 
906
	mov	ecx, 4096/4
-
 
907
	rep	movsd
-
 
908
	pop	edi esi
-
 
909
	pop	ecx ebx
823
endp
910
	popf
824
 
911
	stc
Line 825... Line 912...
825
 
912
	ret
826
 
913
endp
827
 
914
 
828
sys_IPC:
915
sys_IPC:
Line 905... Line 992...
905
           mov [buf_size], esi
992
           mov [buf_size], esi
Line 906... Line 993...
906
 
993
 
907
           mov ecx, [ipc_tmp]
994
           mov ecx, [ipc_tmp]
908
           cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page
995
           cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page
909
           jbe @f
996
           jbe @f
910
           push eax esi edi
997
           push esi edi
911
           add esi,0x1000
998
           add esi,0x1000
912
           stdcall alloc_kernel_space,esi
999
           stdcall alloc_kernel_space,esi
913
           mov ecx, eax
1000
           mov ecx, eax
914
           pop edi esi eax
1001
           pop edi esi
915
@@:
1002
@@:
916
           mov [used_buf], ecx
1003
           mov [used_buf], ecx
917
           stdcall map_mem, ecx, [SLOT_BASE+eax+0xB8],\
1004
           stdcall map_mem, ecx, [dst_slot],\
Line 918... Line 1005...
918
                             edi, esi
1005
                             edi, esi, PG_SW
919
 
1006
 
920
           mov edi, [dst_offset]
1007
           mov edi, [dst_offset]
921
           add edi, [used_buf]
1008
           add edi, [used_buf]