2010-10-01 13:21:55 +04:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
2012-03-15 16:41:29 +04:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc alloc_page
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pushfd
|
|
|
|
|
cli
|
|
|
|
|
push ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp [pg_data.pages_free], 1
|
|
|
|
|
jle .out_of_memory
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ebx, [page_start]
|
|
|
|
|
mov ecx, [page_end]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.l1:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
bsf eax, [ebx];
|
|
|
|
|
jnz .found
|
|
|
|
|
add ebx, 4
|
|
|
|
|
cmp ebx, ecx
|
|
|
|
|
jb .l1
|
|
|
|
|
pop ebx
|
|
|
|
|
popfd
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.found:
|
|
|
|
|
;//-
|
2012-03-08 12:33:38 +04:00
|
|
|
|
dec [pg_data.pages_free]
|
|
|
|
|
jz .out_of_memory
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
2012-03-08 12:33:38 +04:00
|
|
|
|
btr [ebx], eax
|
|
|
|
|
mov [page_start], ebx
|
|
|
|
|
sub ebx, sys_pgmap
|
|
|
|
|
lea eax, [eax+ebx*8]
|
|
|
|
|
shl eax, 12
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//- dec [pg_data.pages_free]
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop ebx
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
|
|
|
|
.out_of_memory:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [pg_data.pages_free], 1
|
|
|
|
|
xor eax, eax
|
|
|
|
|
pop ebx
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc alloc_pages stdcall, count:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pushfd
|
|
|
|
|
push ebx
|
|
|
|
|
push edi
|
|
|
|
|
cli
|
|
|
|
|
mov eax, [count]
|
|
|
|
|
add eax, 7
|
|
|
|
|
shr eax, 3
|
|
|
|
|
mov [count], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ebx, [pg_data.pages_free]
|
|
|
|
|
sub ebx, 9
|
|
|
|
|
js .out_of_memory
|
|
|
|
|
shr ebx, 3
|
|
|
|
|
cmp eax, ebx
|
|
|
|
|
jg .out_of_memory
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;//-
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, [page_start]
|
|
|
|
|
mov ebx, [page_end]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.find:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edx, [count]
|
|
|
|
|
mov edi, ecx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.match:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp byte [ecx], 0xFF
|
|
|
|
|
jne .next
|
|
|
|
|
dec edx
|
|
|
|
|
jz .ok
|
|
|
|
|
inc ecx
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
jb .match
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.out_of_memory:
|
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.next:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
inc ecx
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
jb .find
|
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
|
|
|
|
popfd
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.ok:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
sub ecx, edi
|
|
|
|
|
inc ecx
|
|
|
|
|
push esi
|
|
|
|
|
mov esi, edi
|
|
|
|
|
xor eax, eax
|
|
|
|
|
rep stosb
|
|
|
|
|
sub esi, sys_pgmap
|
|
|
|
|
shl esi, 3+12
|
|
|
|
|
mov eax, esi
|
|
|
|
|
mov ebx, [count]
|
|
|
|
|
shl ebx, 3
|
|
|
|
|
sub [pg_data.pages_free], ebx
|
|
|
|
|
pop esi
|
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ebx
|
|
|
|
|
mov eax, [phis_addr]
|
|
|
|
|
and eax, not 0xFFF
|
|
|
|
|
or eax, [flags]
|
|
|
|
|
mov ebx, [lin_addr]
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
|
mov eax, [lin_addr]
|
|
|
|
|
invlpg [eax]
|
|
|
|
|
pop ebx
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
map_space: ;not implemented
|
|
|
|
|
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc free_page
|
|
|
|
|
;arg: eax page address
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pushfd
|
|
|
|
|
cli
|
|
|
|
|
shr eax, 12 ;page index
|
|
|
|
|
bts dword [sys_pgmap], eax ;that's all!
|
|
|
|
|
cmc
|
|
|
|
|
adc [pg_data.pages_free], 0
|
|
|
|
|
shr eax, 3
|
|
|
|
|
and eax, not 3 ;dword offset from page_map
|
|
|
|
|
add eax, sys_pgmap
|
|
|
|
|
cmp [page_start], eax
|
|
|
|
|
ja @f
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [page_start], eax
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
|
proc map_io_mem stdcall, base:dword, size:dword, flags:dword
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ebx
|
|
|
|
|
push edi
|
|
|
|
|
mov eax, [size]
|
|
|
|
|
add eax, [base]
|
|
|
|
|
add eax, 4095
|
|
|
|
|
and eax, -4096
|
|
|
|
|
mov ecx, [base]
|
|
|
|
|
and ecx, -4096
|
|
|
|
|
sub eax, ecx
|
|
|
|
|
mov [size], eax
|
|
|
|
|
|
|
|
|
|
stdcall alloc_kernel_space, eax
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
push eax
|
|
|
|
|
|
|
|
|
|
mov edi, 0x1000
|
|
|
|
|
mov ebx, eax
|
|
|
|
|
mov ecx, [size]
|
|
|
|
|
mov edx, [base]
|
|
|
|
|
shr eax, 12
|
|
|
|
|
shr ecx, 12
|
|
|
|
|
and edx, -4096
|
|
|
|
|
or edx, [flags]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [page_tabs+eax*4], edx
|
|
|
|
|
invlpg [ebx]
|
|
|
|
|
inc eax
|
|
|
|
|
add ebx, edi
|
|
|
|
|
add edx, edi
|
|
|
|
|
loop @B
|
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
mov edx, [base]
|
|
|
|
|
and edx, 4095
|
|
|
|
|
add eax, edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
; param
|
|
|
|
|
; eax= page base + page flags
|
|
|
|
|
; ebx= linear address
|
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
commit_pages:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test ecx, ecx
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
push edi
|
|
|
|
|
push eax
|
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_lock
|
|
|
|
|
pop ecx
|
|
|
|
|
pop eax
|
|
|
|
|
|
|
|
|
|
mov edi, ebx
|
|
|
|
|
shr edi, 12
|
|
|
|
|
lea edi, [page_tabs+edi*4]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stosd
|
|
|
|
|
invlpg [ebx]
|
|
|
|
|
add eax, 0x1000
|
|
|
|
|
add ebx, 0x1000
|
|
|
|
|
loop @B
|
2011-08-27 15:24:26 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop edi
|
2011-08-27 15:24:26 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_unlock
|
2011-08-27 15:24:26 +04:00
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; param
|
|
|
|
|
; eax= base
|
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
release_pages:
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ebp
|
|
|
|
|
push esi
|
|
|
|
|
push edi
|
|
|
|
|
push ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov esi, eax
|
|
|
|
|
mov edi, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
shr esi, 12
|
|
|
|
|
lea esi, [page_tabs+esi*4]
|
2011-08-27 15:24:26 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ecx
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_lock
|
|
|
|
|
pop ecx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ebp, [pg_data.pages_free]
|
|
|
|
|
mov ebx, [page_start]
|
|
|
|
|
mov edx, sys_pgmap
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
xchg eax, [esi]
|
|
|
|
|
invlpg [edi]
|
|
|
|
|
|
|
|
|
|
test eax, 1
|
|
|
|
|
jz .next
|
|
|
|
|
|
|
|
|
|
shr eax, 12
|
|
|
|
|
bts [edx], eax
|
|
|
|
|
cmc
|
|
|
|
|
adc ebp, 0
|
|
|
|
|
shr eax, 3
|
|
|
|
|
and eax, -4
|
|
|
|
|
add eax, edx
|
|
|
|
|
cmp eax, ebx
|
|
|
|
|
jae .next
|
|
|
|
|
|
|
|
|
|
mov ebx, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.next:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
add edi, 0x1000
|
|
|
|
|
add esi, 4
|
|
|
|
|
loop @B
|
|
|
|
|
|
|
|
|
|
mov [pg_data.pages_free], ebp
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_unlock
|
|
|
|
|
|
|
|
|
|
pop ebx
|
|
|
|
|
pop edi
|
|
|
|
|
pop esi
|
|
|
|
|
pop ebp
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
; param
|
|
|
|
|
; eax= base
|
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
unmap_pages:
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push edi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edi, eax
|
|
|
|
|
mov edx, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
shr edi, 10
|
|
|
|
|
add edi, page_tabs
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stosd
|
|
|
|
|
invlpg [edx]
|
|
|
|
|
add edx, 0x1000
|
|
|
|
|
loop @b
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop edi
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc map_page_table stdcall, lin_addr:dword, phis_addr:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ebx
|
|
|
|
|
mov ebx, [lin_addr]
|
|
|
|
|
shr ebx, 22
|
|
|
|
|
mov eax, [phis_addr]
|
|
|
|
|
and eax, not 0xFFF
|
|
|
|
|
or eax, PG_UW ;+PG_NOCACHE
|
|
|
|
|
mov dword [master_tab+ebx*4], eax
|
|
|
|
|
mov eax, [lin_addr]
|
|
|
|
|
shr eax, 10
|
|
|
|
|
add eax, page_tabs
|
|
|
|
|
invlpg [eax]
|
|
|
|
|
pop ebx
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc init_LFB
|
|
|
|
|
locals
|
|
|
|
|
pg_count dd ?
|
|
|
|
|
endl
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp dword [LFBAddress], -1
|
|
|
|
|
jne @f
|
2012-03-09 15:35:26 +04:00
|
|
|
|
mov [BOOT_VAR+BOOT_MTRR], byte 2
|
2012-03-08 12:33:38 +04:00
|
|
|
|
; max VGA=640*480*4=1228800 bytes
|
|
|
|
|
; + 32*640*4=81920 bytes for mouse pointer
|
|
|
|
|
stdcall alloc_pages, ((1228800+81920)/4096)
|
|
|
|
|
|
|
|
|
|
push eax
|
|
|
|
|
call alloc_page
|
|
|
|
|
stdcall map_page_table, LFB_BASE, eax
|
|
|
|
|
pop eax
|
|
|
|
|
or eax, PG_UW
|
|
|
|
|
mov ebx, LFB_BASE
|
|
|
|
|
; max VGA=640*480*4=1228800 bytes
|
|
|
|
|
; + 32*640*4=81920 bytes for mouse pointer
|
|
|
|
|
mov ecx, (1228800+81920)/4096
|
|
|
|
|
call commit_pages
|
|
|
|
|
mov [LFBAddress], dword LFB_BASE
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test [SCR_MODE], word 0100000000000000b
|
|
|
|
|
jnz @f
|
2012-03-09 15:35:26 +04:00
|
|
|
|
mov [BOOT_VAR+BOOT_MTRR], byte 2
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
call init_mtrr
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edx, LFB_BASE
|
|
|
|
|
mov esi, [LFBAddress]
|
|
|
|
|
mov edi, 0x00C00000
|
|
|
|
|
mov dword [exp_lfb+4], edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
shr edi, 12
|
|
|
|
|
mov [pg_count], edi
|
|
|
|
|
shr edi, 10
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
bt [cpu_caps], CAPS_PSE
|
|
|
|
|
jnc .map_page_tables
|
|
|
|
|
or esi, PG_LARGE+PG_UW
|
|
|
|
|
mov edx, sys_pgdir+(LFB_BASE shr 20)
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [edx], esi
|
|
|
|
|
add edx, 4
|
|
|
|
|
add esi, 0x00400000
|
|
|
|
|
dec edi
|
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
|
|
bt [cpu_caps], CAPS_PGE
|
|
|
|
|
jnc @F
|
|
|
|
|
or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov dword [LFBAddress], LFB_BASE
|
|
|
|
|
mov eax, cr3 ;flush TLB
|
|
|
|
|
mov cr3, eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.map_page_tables:
|
|
|
|
|
|
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
call alloc_page
|
|
|
|
|
stdcall map_page_table, edx, eax
|
|
|
|
|
add edx, 0x00400000
|
|
|
|
|
dec edi
|
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
|
|
mov eax, [LFBAddress]
|
|
|
|
|
mov edi, page_tabs + (LFB_BASE shr 10)
|
|
|
|
|
or eax, PG_UW
|
|
|
|
|
mov ecx, [pg_count]
|
|
|
|
|
cld
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stosd
|
|
|
|
|
add eax, 0x1000
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz @B
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov dword [LFBAddress], LFB_BASE
|
|
|
|
|
mov eax, cr3 ;flush TLB
|
|
|
|
|
mov cr3, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc new_mem_resize stdcall, new_size:dword
|
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
push ebx
|
|
|
|
|
push esi
|
|
|
|
|
push edi
|
|
|
|
|
|
|
|
|
|
mov edx, [current_slot]
|
|
|
|
|
cmp [edx+APPDATA.heap_base], 0
|
|
|
|
|
jne .exit
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edi, [new_size]
|
|
|
|
|
add edi, 4095
|
|
|
|
|
and edi, not 4095
|
|
|
|
|
mov [new_size], edi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov esi, [edx+APPDATA.mem_size]
|
|
|
|
|
add esi, 4095
|
|
|
|
|
and esi, not 4095
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp edi, esi
|
2012-10-12 22:24:48 +04:00
|
|
|
|
ja .expand
|
|
|
|
|
je .exit
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
mov ebx, edi
|
2012-03-08 12:33:38 +04:00
|
|
|
|
shr edi, 12
|
|
|
|
|
shr esi, 12
|
2012-10-12 22:24:48 +04:00
|
|
|
|
|
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_lock
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [app_page_tabs+edi*4]
|
|
|
|
|
test eax, 1
|
|
|
|
|
jz .next
|
2012-10-12 22:24:48 +04:00
|
|
|
|
|
|
|
|
|
mov dword [app_page_tabs+edi*4], 0
|
2012-03-08 12:33:38 +04:00
|
|
|
|
invlpg [ebx]
|
|
|
|
|
call free_page
|
|
|
|
|
|
|
|
|
|
.next:
|
2012-10-12 22:24:48 +04:00
|
|
|
|
inc edi
|
|
|
|
|
add ebx, 0x1000
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp edi, esi
|
|
|
|
|
jb @B
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_unlock
|
2011-08-27 15:24:26 +04:00
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
.update_size:
|
|
|
|
|
mov edx, [current_slot]
|
|
|
|
|
mov ebx, [new_size]
|
|
|
|
|
call update_mem_size
|
|
|
|
|
.exit:
|
|
|
|
|
pop edi
|
|
|
|
|
pop esi
|
|
|
|
|
pop ebx
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2012-10-12 22:24:48 +04:00
|
|
|
|
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.expand:
|
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_lock
|
|
|
|
|
|
|
|
|
|
xchg esi, edi
|
|
|
|
|
|
|
|
|
|
push esi ;new size
|
|
|
|
|
push edi ;old size
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
add edi, 0x3FFFFF
|
|
|
|
|
and edi, not(0x3FFFFF)
|
|
|
|
|
add esi, 0x3FFFFF
|
|
|
|
|
and esi, not(0x3FFFFF)
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
cmp edi, esi
|
2012-03-08 12:33:38 +04:00
|
|
|
|
jae .grow
|
2012-10-12 22:24:48 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
2012-10-12 22:24:48 +04:00
|
|
|
|
jz .exit_fail
|
2012-03-08 12:33:38 +04:00
|
|
|
|
|
|
|
|
|
stdcall map_page_table, edi, eax
|
|
|
|
|
|
|
|
|
|
push edi
|
|
|
|
|
shr edi, 10
|
|
|
|
|
add edi, page_tabs
|
|
|
|
|
mov ecx, 1024
|
|
|
|
|
xor eax, eax
|
|
|
|
|
cld
|
|
|
|
|
rep stosd
|
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
|
|
add edi, 0x00400000
|
|
|
|
|
cmp edi, esi
|
|
|
|
|
jb @B
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.grow:
|
2012-10-12 22:24:48 +04:00
|
|
|
|
pop edi ;old size
|
|
|
|
|
pop ecx ;new size
|
2012-03-08 12:33:38 +04:00
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
shr edi, 10
|
|
|
|
|
shr ecx, 10
|
|
|
|
|
sub ecx, edi
|
|
|
|
|
shr ecx, 2 ;pages count
|
|
|
|
|
mov eax, 2
|
|
|
|
|
|
|
|
|
|
add edi, app_page_tabs
|
2012-03-08 12:33:38 +04:00
|
|
|
|
rep stosd
|
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_unlock
|
2012-03-08 12:33:38 +04:00
|
|
|
|
|
|
|
|
|
jmp .update_size
|
2012-10-12 22:24:48 +04:00
|
|
|
|
|
|
|
|
|
.exit_fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, pg_data.mutex
|
|
|
|
|
call mutex_unlock
|
2011-08-27 15:24:26 +04:00
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
add esp, 8
|
|
|
|
|
pop edi
|
|
|
|
|
pop esi
|
|
|
|
|
pop ebx
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
inc eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
|
|
|
|
|
align 4
|
2010-10-01 13:21:55 +04:00
|
|
|
|
update_mem_size:
|
|
|
|
|
; in: edx = slot base
|
|
|
|
|
; ebx = new memory size
|
|
|
|
|
; destroys eax,ecx,edx
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [APPDATA.mem_size+edx], ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
;search threads and update
|
|
|
|
|
;application memory size infomation
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, [APPDATA.dir_table+edx]
|
|
|
|
|
mov eax, 2
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.search_threads:
|
|
|
|
|
;eax = current slot
|
|
|
|
|
;ebx = new memory size
|
|
|
|
|
;ecx = page directory
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp eax, [TASK_COUNT]
|
|
|
|
|
jg .search_threads_end
|
|
|
|
|
mov edx, eax
|
|
|
|
|
shl edx, 5
|
|
|
|
|
cmp word [CURRENT_TASK+edx+TASKDATA.state], 9 ;if slot empty?
|
|
|
|
|
jz .search_threads_next
|
|
|
|
|
shl edx, 3
|
|
|
|
|
cmp [SLOT_BASE+edx+APPDATA.dir_table], ecx ;if it is our thread?
|
|
|
|
|
jnz .search_threads_next
|
|
|
|
|
mov [SLOT_BASE+edx+APPDATA.mem_size], ebx ;update memory size
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.search_threads_next:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
inc eax
|
|
|
|
|
jmp .search_threads
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.search_threads_end:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
; param
|
|
|
|
|
; eax= linear address
|
|
|
|
|
;
|
|
|
|
|
; retval
|
|
|
|
|
; eax= phisical page address
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
get_pg_addr:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
shr eax, 12
|
|
|
|
|
mov eax, [page_tabs+eax*4]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
; Now it is called from core/sys32::exc_c (see stack frame there)
|
|
|
|
|
proc page_fault_handler
|
|
|
|
|
|
|
|
|
|
.err_addr equ ebp-4
|
|
|
|
|
|
|
|
|
|
push ebx ;save exception number (#PF)
|
|
|
|
|
mov ebp, esp
|
|
|
|
|
mov ebx, cr2
|
|
|
|
|
push ebx ;that is locals: .err_addr = cr2
|
|
|
|
|
inc [pg_data.pages_faults]
|
|
|
|
|
|
|
|
|
|
mov eax, [pf_err_code]
|
|
|
|
|
|
|
|
|
|
cmp ebx, OS_BASE ;ebx == .err_addr
|
|
|
|
|
jb .user_space ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ;
|
|
|
|
|
|
|
|
|
|
cmp ebx, page_tabs
|
|
|
|
|
jb .kernel_space ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
cmp ebx, kernel_tabs
|
|
|
|
|
jb .alloc;.app_tabs ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ;
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if 0 ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
cmp ebx, LFB_BASE
|
|
|
|
|
jb .core_tabs ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
.lfb:
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> LFB
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
jmp .fail
|
|
|
|
|
end if
|
|
|
|
|
.core_tabs:
|
|
|
|
|
.fail: ;simply return to caller
|
|
|
|
|
mov esp, ebp
|
|
|
|
|
pop ebx ;restore exception number (#PF)
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
; xchg bx, bx
|
|
|
|
|
; add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller
|
|
|
|
|
; restore_ring3_context
|
|
|
|
|
; iretd
|
|
|
|
|
|
|
|
|
|
.user_space:
|
|
|
|
|
test eax, PG_MAP
|
|
|
|
|
jnz .err_access ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ?
|
|
|
|
|
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
mov ecx, ebx
|
|
|
|
|
shr ecx, 10
|
|
|
|
|
mov edx, [master_tab+ecx*4]
|
|
|
|
|
test edx, PG_MAP
|
|
|
|
|
jz .fail ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
mov eax, [page_tabs+ebx*4]
|
|
|
|
|
test eax, 2
|
|
|
|
|
jz .fail ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> ;
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
.alloc:
|
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall map_page, [.err_addr], eax, PG_UW
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
mov edi, [.err_addr]
|
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
|
mov ecx, 1024
|
|
|
|
|
xor eax, eax
|
|
|
|
|
;cld ;caller is duty for this
|
2012-03-08 12:33:38 +04:00
|
|
|
|
rep stosd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.exit: ;iret with repeat fault instruction
|
2012-03-08 12:33:38 +04:00
|
|
|
|
add esp, 12;clear in stack: locals(.err_addr) + #PF + ret_to_caller
|
2010-10-01 13:21:55 +04:00
|
|
|
|
restore_ring3_context
|
|
|
|
|
iretd
|
|
|
|
|
|
|
|
|
|
.err_access:
|
|
|
|
|
; access denied? this may be a result of copy-on-write protection for DLL
|
|
|
|
|
; check list of HDLLs
|
|
|
|
|
and ebx, not 0xFFF
|
|
|
|
|
mov eax, [CURRENT_TASK]
|
|
|
|
|
shl eax, 8
|
|
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
mov esi, [eax+HDLL.fd]
|
|
|
|
|
.scan_hdll:
|
|
|
|
|
cmp esi, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
sub edx, [esi+HDLL.base]
|
|
|
|
|
cmp edx, [esi+HDLL.size]
|
|
|
|
|
jb .fault_in_hdll
|
|
|
|
|
.scan_hdll.next:
|
|
|
|
|
mov esi, [esi+HDLL.fd]
|
|
|
|
|
jmp .scan_hdll
|
|
|
|
|
.fault_in_hdll:
|
|
|
|
|
; allocate new page, map it as rw and copy data
|
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall map_page, ebx, eax, PG_UW
|
2010-10-01 13:21:55 +04:00
|
|
|
|
mov edi, ebx
|
|
|
|
|
mov ecx, 1024
|
|
|
|
|
sub ebx, [esi+HDLL.base]
|
|
|
|
|
mov esi, [esi+HDLL.parent]
|
|
|
|
|
mov esi, [esi+DLLDESCR.data]
|
|
|
|
|
add esi, ebx
|
2012-03-08 12:33:38 +04:00
|
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
|
|
.kernel_space:
|
|
|
|
|
test eax, PG_MAP
|
|
|
|
|
jz .fail ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test eax, 12 ;U/S (+below)
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jnz .fail ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
;test eax, 8
|
|
|
|
|
;jnz .fail ;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
;<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> P4/Xeon
|
|
|
|
|
|
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
cmp ebx, tss._io_map_0
|
|
|
|
|
jb .fail
|
|
|
|
|
|
|
|
|
|
cmp ebx, tss._io_map_0+8192
|
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
|
|
; io permission map
|
|
|
|
|
; copy-on-write protection
|
|
|
|
|
|
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
push eax
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall map_page, [.err_addr], eax, dword PG_SW
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pop eax
|
|
|
|
|
mov edi, [.err_addr]
|
|
|
|
|
and edi, -4096
|
|
|
|
|
lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0
|
|
|
|
|
|
|
|
|
|
mov ebx, esi
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
mov edx, [current_slot]
|
|
|
|
|
or eax, PG_SW
|
|
|
|
|
mov [edx+APPDATA.io_map+ebx*4], eax
|
|
|
|
|
|
|
|
|
|
add esi, [default_io_map]
|
|
|
|
|
mov ecx, 4096/4
|
|
|
|
|
;cld ;caller is duty for this
|
2012-03-08 12:33:38 +04:00
|
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
jmp .exit
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
; returns number of mapped bytes
|
|
|
|
|
proc map_mem stdcall, lin_addr:dword,slot:dword,\
|
|
|
|
|
ofs:dword,buf_size:dword,req_access:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push 0 ; initialize number of mapped bytes
|
|
|
|
|
|
|
|
|
|
cmp [buf_size], 0
|
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
|
|
mov eax, [slot]
|
|
|
|
|
shl eax, 8
|
|
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
|
|
|
|
|
stdcall map_page, [ipc_pdir], eax, PG_UW
|
|
|
|
|
mov ebx, [ofs]
|
|
|
|
|
shr ebx, 22
|
|
|
|
|
mov esi, [ipc_pdir]
|
|
|
|
|
mov edi, [ipc_ptab]
|
|
|
|
|
mov eax, [esi+ebx*4]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
jz .exit
|
|
|
|
|
stdcall map_page, edi, eax, PG_UW
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; inc ebx
|
|
|
|
|
; add edi, 0x1000
|
|
|
|
|
; mov eax, [esi+ebx*4]
|
|
|
|
|
; test eax, eax
|
|
|
|
|
; jz @f
|
|
|
|
|
; and eax, 0xFFFFF000
|
|
|
|
|
; stdcall map_page, edi, eax
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
@@:
|
|
|
|
|
mov edi, [lin_addr]
|
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
|
mov ecx, [buf_size]
|
|
|
|
|
add ecx, 4095
|
|
|
|
|
shr ecx, 12
|
|
|
|
|
inc ecx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edx, [ofs]
|
|
|
|
|
shr edx, 12
|
|
|
|
|
and edx, 0x3FF
|
|
|
|
|
mov esi, [ipc_ptab]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.map:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall safe_map_page, [slot], [req_access], [ofs]
|
|
|
|
|
jnc .exit
|
|
|
|
|
add dword [ebp-4], 4096
|
|
|
|
|
add [ofs], 4096
|
|
|
|
|
dec ecx
|
|
|
|
|
jz .exit
|
|
|
|
|
add edi, 0x1000
|
|
|
|
|
inc edx
|
|
|
|
|
cmp edx, 0x400
|
|
|
|
|
jnz .map
|
|
|
|
|
inc ebx
|
|
|
|
|
mov eax, [ipc_pdir]
|
|
|
|
|
mov eax, [eax+ebx*4]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
jz .exit
|
|
|
|
|
stdcall map_page, esi, eax, PG_UW
|
|
|
|
|
xor edx, edx
|
|
|
|
|
jmp .map
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.exit:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
|
|
|
|
|
ofs:dword,buf_size:dword,req_access:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push 0 ; initialize number of mapped bytes
|
|
|
|
|
|
|
|
|
|
cmp [buf_size], 0
|
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
|
|
mov eax, [slot]
|
|
|
|
|
shl eax, 8
|
|
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
|
|
|
|
|
stdcall map_page, [proc_mem_pdir], eax, PG_UW
|
|
|
|
|
mov ebx, [ofs]
|
|
|
|
|
shr ebx, 22
|
|
|
|
|
mov esi, [proc_mem_pdir]
|
|
|
|
|
mov edi, [proc_mem_tab]
|
|
|
|
|
mov eax, [esi+ebx*4]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .exit
|
|
|
|
|
stdcall map_page, edi, eax, PG_UW
|
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
mov edi, [lin_addr]
|
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
|
mov ecx, [buf_size]
|
|
|
|
|
add ecx, 4095
|
|
|
|
|
shr ecx, 12
|
|
|
|
|
inc ecx
|
|
|
|
|
|
|
|
|
|
mov edx, [ofs]
|
|
|
|
|
shr edx, 12
|
|
|
|
|
and edx, 0x3FF
|
|
|
|
|
mov esi, [proc_mem_tab]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.map:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall safe_map_page, [slot], [req_access], [ofs]
|
|
|
|
|
jnc .exit
|
|
|
|
|
add dword [ebp-4], 0x1000
|
|
|
|
|
add edi, 0x1000
|
|
|
|
|
add [ofs], 0x1000
|
|
|
|
|
inc edx
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz .map
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.exit:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
; in: esi+edx*4 = pointer to page table entry
|
|
|
|
|
; in: [slot], [req_access], [ofs] on the stack
|
|
|
|
|
; in: edi = linear address to map
|
|
|
|
|
; out: CF cleared <=> failed
|
|
|
|
|
; destroys: only eax
|
|
|
|
|
proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [esi+edx*4]
|
|
|
|
|
test al, PG_MAP
|
|
|
|
|
jz .not_present
|
|
|
|
|
test al, PG_WRITE
|
|
|
|
|
jz .resolve_readonly
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; normal case: writable page, just map with requested access
|
|
|
|
|
.map:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall map_page, edi, eax, [req_access]
|
|
|
|
|
stc
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.not_present:
|
|
|
|
|
; check for alloc-on-demand page
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test al, 2
|
|
|
|
|
jz .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; allocate new page, save it to source page table
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ecx
|
|
|
|
|
call alloc_page
|
|
|
|
|
pop ecx
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
or al, PG_UW
|
|
|
|
|
mov [esi+edx*4], eax
|
|
|
|
|
jmp .map
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.resolve_readonly:
|
|
|
|
|
; readonly page, probably copy-on-write
|
|
|
|
|
; check: readonly request of readonly page is ok
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test [req_access], PG_WRITE
|
|
|
|
|
jz .map
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; find control structure for this page
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pushf
|
|
|
|
|
cli
|
|
|
|
|
cld
|
|
|
|
|
push ebx ecx
|
|
|
|
|
mov eax, [slot]
|
|
|
|
|
shl eax, 8
|
|
|
|
|
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .no_hdll
|
|
|
|
|
mov ecx, [eax+HDLL.fd]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.scan_hdll:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, eax
|
|
|
|
|
jz .no_hdll
|
|
|
|
|
mov ebx, [ofs]
|
|
|
|
|
and ebx, not 0xFFF
|
|
|
|
|
sub ebx, [ecx+HDLL.base]
|
|
|
|
|
cmp ebx, [ecx+HDLL.size]
|
|
|
|
|
jb .hdll_found
|
|
|
|
|
mov ecx, [ecx+HDLL.fd]
|
|
|
|
|
jmp .scan_hdll
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.no_hdll:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop ecx ebx
|
|
|
|
|
popf
|
|
|
|
|
clc
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.hdll_found:
|
|
|
|
|
; allocate page, save it in page table, map it, copy contents from base
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [ecx+HDLL.parent]
|
|
|
|
|
add ebx, [eax+DLLDESCR.data]
|
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .no_hdll
|
|
|
|
|
or al, PG_UW
|
|
|
|
|
mov [esi+edx*4], eax
|
|
|
|
|
stdcall map_page, edi, eax, [req_access]
|
|
|
|
|
push esi edi
|
|
|
|
|
mov esi, ebx
|
|
|
|
|
mov ecx, 4096/4
|
|
|
|
|
rep movsd
|
|
|
|
|
pop edi esi
|
|
|
|
|
pop ecx ebx
|
|
|
|
|
popf
|
|
|
|
|
stc
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
sys_IPC:
|
|
|
|
|
;input:
|
|
|
|
|
; ebx=1 - set ipc buffer area
|
|
|
|
|
; ecx=address of buffer
|
|
|
|
|
; edx=size of buffer
|
|
|
|
|
; eax=2 - send message
|
|
|
|
|
; ebx=PID
|
|
|
|
|
; ecx=address of message
|
|
|
|
|
; edx=size of message
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
dec ebx
|
|
|
|
|
jnz @f
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [current_slot]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
pushf
|
|
|
|
|
cli
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [eax+APPDATA.ipc_start], ecx ;set fields in extended information area
|
|
|
|
|
mov [eax+APPDATA.ipc_size], edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
add edx, ecx
|
|
|
|
|
add edx, 4095
|
|
|
|
|
and edx, not 4095
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
.touch:
|
|
|
|
|
mov eax, [ecx]
|
|
|
|
|
add ecx, 0x1000
|
|
|
|
|
cmp ecx, edx
|
|
|
|
|
jb .touch
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
popf
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [esp+32], ebx ;ebx=0
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;2
|
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
dec ebx
|
|
|
|
|
jnz @f
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
stdcall sys_ipc_send, ecx, edx, esi
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [esp+32], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
or eax, -1
|
|
|
|
|
mov [esp+32], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
;align 4
|
|
|
|
|
;proc set_ipc_buff
|
|
|
|
|
|
|
|
|
|
; mov eax,[current_slot]
|
|
|
|
|
; pushf
|
|
|
|
|
; cli
|
|
|
|
|
; mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area
|
|
|
|
|
; mov [eax+APPDATA.ipc_size],ecx
|
|
|
|
|
;
|
|
|
|
|
; add ecx, ebx
|
|
|
|
|
; add ecx, 4095
|
|
|
|
|
; and ecx, not 4095
|
|
|
|
|
;
|
|
|
|
|
;.touch: mov eax, [ebx]
|
|
|
|
|
; add ebx, 0x1000
|
|
|
|
|
; cmp ebx, ecx
|
|
|
|
|
; jb .touch
|
|
|
|
|
;
|
|
|
|
|
; popf
|
|
|
|
|
; xor eax, eax
|
|
|
|
|
; ret
|
|
|
|
|
;endp
|
|
|
|
|
|
|
|
|
|
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
|
|
|
|
locals
|
|
|
|
|
dst_slot dd ?
|
|
|
|
|
dst_offset dd ?
|
|
|
|
|
buf_size dd ?
|
|
|
|
|
used_buf dd ?
|
|
|
|
|
endl
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pushf
|
|
|
|
|
cli
|
|
|
|
|
|
|
|
|
|
mov eax, [PID]
|
|
|
|
|
call pid_to_slot
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .no_pid
|
|
|
|
|
|
|
|
|
|
mov [dst_slot], eax
|
|
|
|
|
shl eax, 8
|
|
|
|
|
mov edi, [eax+SLOT_BASE+0xa0] ;is ipc area defined?
|
|
|
|
|
test edi, edi
|
|
|
|
|
jz .no_ipc_area
|
|
|
|
|
|
|
|
|
|
mov ebx, edi
|
|
|
|
|
and ebx, 0xFFF
|
|
|
|
|
mov [dst_offset], ebx
|
|
|
|
|
|
|
|
|
|
mov esi, [eax+SLOT_BASE+0xa4]
|
|
|
|
|
mov [buf_size], esi
|
|
|
|
|
|
|
|
|
|
mov ecx, [ipc_tmp]
|
|
|
|
|
cmp esi, 0x40000-0x1000; size of [ipc_tmp] minus one page
|
|
|
|
|
jbe @f
|
|
|
|
|
push esi edi
|
|
|
|
|
add esi, 0x1000
|
|
|
|
|
stdcall alloc_kernel_space, esi
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
pop edi esi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [used_buf], ecx
|
|
|
|
|
stdcall map_mem, ecx, [dst_slot], \
|
|
|
|
|
edi, esi, PG_SW
|
|
|
|
|
|
|
|
|
|
mov edi, [dst_offset]
|
|
|
|
|
add edi, [used_buf]
|
|
|
|
|
cmp dword [edi], 0
|
|
|
|
|
jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now
|
|
|
|
|
|
|
|
|
|
mov edx, dword [edi+4]
|
|
|
|
|
lea ebx, [edx+8]
|
|
|
|
|
add ebx, [msg_size]
|
|
|
|
|
cmp ebx, [buf_size]
|
|
|
|
|
ja .buffer_overflow ;esi<0 - not enough memory in buffer
|
|
|
|
|
|
|
|
|
|
mov dword [edi+4], ebx
|
|
|
|
|
mov eax, [TASK_BASE]
|
|
|
|
|
mov eax, [eax+0x04] ;eax - our PID
|
|
|
|
|
add edi, edx
|
|
|
|
|
mov [edi], eax
|
|
|
|
|
mov ecx, [msg_size]
|
|
|
|
|
|
|
|
|
|
mov [edi+4], ecx
|
|
|
|
|
add edi, 8
|
|
|
|
|
mov esi, [msg_addr]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; add esi, new_app_base
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cld
|
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
|
|
mov ebx, [ipc_tmp]
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
|
|
mov ebx, [ipc_pdir]
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
|
|
mov ebx, [ipc_ptab]
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [page_tabs+ebx*4], eax
|
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
|
|
mov eax, [dst_slot]
|
|
|
|
|
shl eax, 8
|
|
|
|
|
or [eax+SLOT_BASE+0xA8], dword 0x40
|
|
|
|
|
cmp dword [check_idle_semaphore], 20
|
|
|
|
|
jge .ipc_no_cis
|
|
|
|
|
|
|
|
|
|
mov dword [check_idle_semaphore], 5
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.ipc_no_cis:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push 0
|
|
|
|
|
jmp .ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.no_pid:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
popf
|
|
|
|
|
mov eax, 4
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.no_ipc_area:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
popf
|
|
|
|
|
xor eax, eax
|
|
|
|
|
inc eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.ipc_blocked:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push 2
|
|
|
|
|
jmp .ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.buffer_overflow:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push 3
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.ret:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [used_buf]
|
|
|
|
|
cmp eax, [ipc_tmp]
|
|
|
|
|
jz @f
|
|
|
|
|
stdcall free_kernel_space, eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop eax
|
|
|
|
|
popf
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
sysfn_meminfo:
|
|
|
|
|
|
|
|
|
|
; add ecx, new_app_base
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
|
|
mov eax, [pg_data.pages_count]
|
|
|
|
|
mov [ecx], eax
|
|
|
|
|
shl eax, 12
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
mov eax, [pg_data.pages_free]
|
|
|
|
|
mov [ecx+4], eax
|
|
|
|
|
mov eax, [pg_data.pages_faults]
|
|
|
|
|
mov [ecx+8], eax
|
|
|
|
|
mov eax, [heap_size]
|
|
|
|
|
mov [ecx+12], eax
|
|
|
|
|
mov eax, [heap_free]
|
|
|
|
|
mov [ecx+16], eax
|
|
|
|
|
mov eax, [heap_blocks]
|
|
|
|
|
mov [ecx+20], eax
|
|
|
|
|
mov eax, [free_blocks]
|
|
|
|
|
mov [ecx+24], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
or dword [esp+32], -1
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
f68:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ebx, 4
|
|
|
|
|
jbe sys_sheduler
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ebx, 11
|
|
|
|
|
jb .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ebx, 25
|
|
|
|
|
ja .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
jmp dword [f68call+ebx*4-11*4]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.11:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
call init_heap
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.12:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall user_alloc, ecx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.13:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall user_free, ecx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.14:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
|
|
|
|
mov edi, ecx
|
|
|
|
|
call get_event_ex
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.16:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test ecx, ecx
|
|
|
|
|
jz .fail
|
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
|
|
|
|
stdcall get_service, ecx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.17:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
call srv_handlerEx ;ecx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.19:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
|
|
|
|
stdcall load_library, ecx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.20:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, edx
|
|
|
|
|
mov ebx, ecx
|
|
|
|
|
call user_realloc ;in: eax = pointer, ebx = new size
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.21:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-10-12 22:24:48 +04:00
|
|
|
|
cmp edx, OS_BASE
|
2012-03-08 12:33:38 +04:00
|
|
|
|
jae .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov edi, edx
|
|
|
|
|
stdcall load_PE, ecx
|
|
|
|
|
mov esi, eax
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push edi
|
|
|
|
|
push DRV_ENTRY
|
|
|
|
|
call eax
|
|
|
|
|
add esp, 8
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [eax+SRV.entry], esi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.22:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall shmem_open, ecx, edx, esi
|
|
|
|
|
mov [esp+24], edx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.23:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, OS_BASE
|
|
|
|
|
jae .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall shmem_close, ecx
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.24:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [current_slot]
|
|
|
|
|
xchg ecx, [eax+APPDATA.exc_handler]
|
|
|
|
|
xchg edx, [eax+APPDATA.except_mask]
|
|
|
|
|
mov [esp+32], ecx ; reg_eax+8
|
|
|
|
|
mov [esp+20], edx ; reg_ebx+8
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.25:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
cmp ecx, 32
|
|
|
|
|
jae .fail
|
|
|
|
|
mov eax, [current_slot]
|
|
|
|
|
btr [eax+APPDATA.except_mask], ecx
|
|
|
|
|
setc byte[esp+32]
|
|
|
|
|
jecxz @f
|
|
|
|
|
bts [eax+APPDATA.except_mask], ecx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.26:
|
|
|
|
|
stdcall user_unmap, ecx, edx, esi
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [esp+32], eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
f68call: ; keep this table closer to main code
|
|
|
|
|
|
|
|
|
|
dd f68.11 ; init_heap
|
|
|
|
|
dd f68.12 ; user_alloc
|
|
|
|
|
dd f68.13 ; user_free
|
|
|
|
|
dd f68.14 ; get_event_ex
|
|
|
|
|
dd f68.fail ; moved to f68.24
|
|
|
|
|
dd f68.16 ; get_service
|
|
|
|
|
dd f68.17 ; call_service
|
|
|
|
|
dd f68.fail ; moved to f68.25
|
|
|
|
|
dd f68.19 ; load_dll
|
|
|
|
|
dd f68.20 ; user_realloc
|
|
|
|
|
dd f68.21 ; load_driver
|
|
|
|
|
dd f68.22 ; shmem_open
|
|
|
|
|
dd f68.23 ; shmem_close
|
2012-03-08 12:33:38 +04:00
|
|
|
|
dd f68.24 ; set exception handler
|
|
|
|
|
dd f68.25 ; unmask exception
|
|
|
|
|
dd f68.26 ; user_unmap
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc load_pe_driver stdcall, file:dword
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall load_PE, [file]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov esi, eax
|
|
|
|
|
stdcall eax, DRV_ENTRY
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [eax+SRV.entry], esi
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc init_mtrr
|
|
|
|
|
|
2012-03-09 15:35:26 +04:00
|
|
|
|
cmp [BOOT_VAR+BOOT_MTRR], byte 2
|
2012-03-08 12:33:38 +04:00
|
|
|
|
je .exit
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
bt [cpu_caps], CAPS_MTRR
|
|
|
|
|
jnc .exit
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, cr0
|
|
|
|
|
or eax, 0x60000000 ;disable caching
|
|
|
|
|
mov cr0, eax
|
|
|
|
|
wbinvd ;invalidate cache
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, 0x2FF
|
|
|
|
|
rdmsr ;
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; has BIOS already initialized MTRRs?
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test ah, 8
|
|
|
|
|
jnz .skip_init
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; rarely needed, so mainly placeholder
|
|
|
|
|
; main memory - cached
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [MEM_AMOUNT]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; round eax up to next power of 2
|
2012-03-08 12:33:38 +04:00
|
|
|
|
dec eax
|
|
|
|
|
bsr ecx, eax
|
|
|
|
|
mov ebx, 2
|
|
|
|
|
shl ebx, cl
|
|
|
|
|
dec ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; base of memory range = 0, type of memory range = MEM_WB
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor edx, edx
|
|
|
|
|
mov eax, MEM_WB
|
|
|
|
|
mov ecx, 0x200
|
|
|
|
|
wrmsr
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, 0xFFFFFFFF
|
|
|
|
|
mov edx, 0x0000000F
|
|
|
|
|
sub eax, ebx
|
|
|
|
|
sbb edx, 0
|
|
|
|
|
or eax, 0x800
|
|
|
|
|
inc ecx
|
|
|
|
|
wrmsr
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; clear unused MTRRs
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor eax, eax
|
|
|
|
|
xor edx, edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
wrmsr
|
|
|
|
|
inc ecx
|
|
|
|
|
cmp ecx, 0x210
|
|
|
|
|
jb @b
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; enable MTRRs
|
2012-03-08 12:33:38 +04:00
|
|
|
|
pop eax
|
|
|
|
|
or ah, 8
|
|
|
|
|
and al, 0xF0; default memtype = UC
|
|
|
|
|
mov ecx, 0x2FF
|
|
|
|
|
wrmsr
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.skip_init:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall set_mtrr, [LFBAddress], [LFBSize], MEM_WC
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
wbinvd ;again invalidate
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, cr0
|
|
|
|
|
and eax, not 0x60000000
|
|
|
|
|
mov cr0, eax ; enable caching
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.exit:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword
|
|
|
|
|
; find unused register
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ecx, 0x201
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
rdmsr
|
|
|
|
|
dec ecx
|
|
|
|
|
test ah, 8
|
|
|
|
|
jz .found
|
|
|
|
|
rdmsr
|
|
|
|
|
mov al, 0; clear memory type field
|
|
|
|
|
cmp eax, [base]
|
|
|
|
|
jz .ret
|
|
|
|
|
add ecx, 3
|
|
|
|
|
cmp ecx, 0x210
|
|
|
|
|
jb @b
|
2010-10-01 13:21:55 +04:00
|
|
|
|
; no free registers, ignore the call
|
|
|
|
|
.ret:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.found:
|
|
|
|
|
; found, write values
|
2012-03-08 12:33:38 +04:00
|
|
|
|
xor edx, edx
|
|
|
|
|
mov eax, [base]
|
|
|
|
|
or eax, [mem_type]
|
|
|
|
|
wrmsr
|
|
|
|
|
|
|
|
|
|
mov ebx, [size]
|
|
|
|
|
dec ebx
|
|
|
|
|
mov eax, 0xFFFFFFFF
|
2012-10-12 22:24:48 +04:00
|
|
|
|
mov edx, 0x0000000F
|
2012-03-08 12:33:38 +04:00
|
|
|
|
sub eax, ebx
|
|
|
|
|
sbb edx, 0
|
|
|
|
|
or eax, 0x800
|
|
|
|
|
inc ecx
|
|
|
|
|
wrmsr
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc stall stdcall, delay:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ecx
|
|
|
|
|
push edx
|
|
|
|
|
push ebx
|
|
|
|
|
push eax
|
|
|
|
|
|
|
|
|
|
mov eax, [delay]
|
|
|
|
|
mul [stall_mcs]
|
|
|
|
|
mov ebx, eax ;low
|
|
|
|
|
mov ecx, edx ;high
|
|
|
|
|
rdtsc
|
|
|
|
|
add ebx, eax
|
|
|
|
|
adc ecx, edx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
rdtsc
|
|
|
|
|
sub eax, ebx
|
|
|
|
|
sbb edx, ecx
|
|
|
|
|
jb @B
|
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
pop ebx
|
|
|
|
|
pop edx
|
|
|
|
|
pop ecx
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc create_ring_buffer stdcall, size:dword, flags:dword
|
|
|
|
|
locals
|
|
|
|
|
buf_ptr dd ?
|
|
|
|
|
endl
|
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov eax, [size]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
add eax, eax
|
|
|
|
|
stdcall alloc_kernel_space, eax
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [buf_ptr], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov ebx, [size]
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
push ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall alloc_pages, ebx
|
|
|
|
|
pop ecx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
test eax, eax
|
|
|
|
|
jz .mm_fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
push edi
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
|
or eax, [flags]
|
|
|
|
|
mov edi, [buf_ptr]
|
|
|
|
|
mov ebx, [buf_ptr]
|
|
|
|
|
mov edx, ecx
|
|
|
|
|
shl edx, 2
|
|
|
|
|
shr edi, 10
|
2010-10-01 13:21:55 +04:00
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
mov [page_tabs+edi], eax
|
|
|
|
|
mov [page_tabs+edi+edx], eax
|
|
|
|
|
invlpg [ebx]
|
|
|
|
|
invlpg [ebx+0x10000]
|
|
|
|
|
add eax, 0x1000
|
|
|
|
|
add ebx, 0x1000
|
|
|
|
|
add edi, 4
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
|
|
mov eax, [buf_ptr]
|
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.mm_fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
stdcall free_kernel_space, [buf_ptr]
|
|
|
|
|
xor eax, eax
|
|
|
|
|
pop ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
|
endp
|
2012-03-09 16:55:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
2012-03-15 19:34:46 +04:00
|
|
|
|
proc print_mem
|
2012-03-09 16:55:55 +04:00
|
|
|
|
mov edi, BOOT_VAR + 0x9104
|
|
|
|
|
mov ecx, [edi-4]
|
|
|
|
|
test ecx, ecx
|
|
|
|
|
jz .done
|
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
mov eax, [edi]
|
|
|
|
|
mov edx, [edi+4]
|
|
|
|
|
add eax, [edi+8]
|
|
|
|
|
adc edx, [edi+12]
|
|
|
|
|
|
|
|
|
|
DEBUGF 1, "K : E820 %x%x - %x%x type %d\n", \
|
|
|
|
|
[edi+4], [edi],\
|
|
|
|
|
edx, eax, [edi+16]
|
|
|
|
|
add edi, 20
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz @b
|
|
|
|
|
.done:
|
|
|
|
|
ret
|
2012-03-15 19:34:46 +04:00
|
|
|
|
endp
|