2007-03-22 01:58:33 +03:00
|
|
|
$Revision$
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
tmp_page_tab equ HEAP_BASE
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
align 4
|
|
|
|
proc mem_test
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, cr0
|
2006-11-16 13:59:49 +03:00
|
|
|
and eax, not (CR0_CD+CR0_NW)
|
2006-11-20 10:06:00 +03:00
|
|
|
or eax, CR0_CD ;disable caching
|
2006-10-06 10:09:41 +04:00
|
|
|
mov cr0, eax
|
2006-11-20 10:06:00 +03:00
|
|
|
wbinvd ;invalidate cache
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2006-11-20 10:06:00 +03:00
|
|
|
xor edi, edi
|
2006-10-06 10:09:41 +04:00
|
|
|
mov ebx, 'TEST'
|
|
|
|
@@:
|
|
|
|
add edi, 0x400000
|
|
|
|
xchg ebx, dword [edi]
|
|
|
|
cmp dword [edi], 'TEST'
|
|
|
|
xchg ebx, dword [edi]
|
|
|
|
je @b
|
2007-02-17 13:09:23 +03:00
|
|
|
mov [MEM_AMOUNT], edi
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2006-11-16 13:59:49 +03:00
|
|
|
and eax, not (CR0_CD+CR0_NW) ;enable caching
|
2006-10-06 10:09:41 +04:00
|
|
|
mov cr0, eax
|
|
|
|
mov eax, edi
|
2006-11-20 10:06:00 +03:00
|
|
|
mov [LFBSize], 0x00800000
|
2006-10-06 10:09:41 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2007-02-17 13:09:23 +03:00
|
|
|
proc init_mem
|
|
|
|
|
|
|
|
mov eax, [MEM_AMOUNT]
|
|
|
|
|
|
|
|
mov [pg_data.mem_amount], eax
|
|
|
|
mov [pg_data.kernel_max], eax
|
|
|
|
|
|
|
|
shr eax, 12
|
|
|
|
mov edx, eax
|
|
|
|
mov [pg_data.pages_count], eax
|
|
|
|
mov [pg_data.kernel_pages], eax
|
|
|
|
|
|
|
|
shr eax, 3
|
|
|
|
mov [pg_data.pagemap_size], eax
|
|
|
|
|
|
|
|
shr edx, 10
|
|
|
|
cmp edx, 3
|
|
|
|
ja @f
|
|
|
|
inc edx ;at least 4Mb for kernel heap
|
|
|
|
@@:
|
|
|
|
mov [pg_data.kernel_tables], edx
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
xor eax, eax
|
|
|
|
mov edi, sys_pgdir
|
|
|
|
mov ecx, 2048
|
2007-02-17 13:09:23 +03:00
|
|
|
cld
|
2006-10-06 10:09:41 +04:00
|
|
|
rep stosd
|
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
mov edx, sys_pgdir
|
2006-10-06 10:09:41 +04:00
|
|
|
bt [cpu_caps], CAPS_PSE
|
|
|
|
jnc .no_PSE
|
|
|
|
|
|
|
|
mov ebx, cr4
|
|
|
|
or ebx, CR4_PSE
|
|
|
|
mov eax, PG_LARGE+PG_SW
|
|
|
|
bt [cpu_caps], CAPS_PGE
|
|
|
|
jnc @F
|
|
|
|
or eax, PG_GLOBAL
|
|
|
|
or ebx, CR4_PGE
|
|
|
|
@@:
|
2006-10-07 13:47:03 +04:00
|
|
|
mov cr4, ebx
|
2007-02-17 13:09:23 +03:00
|
|
|
sub [pg_data.kernel_tables], 2
|
2006-10-07 13:47:03 +04:00
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
mov [edx], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
add eax, 0x00400000
|
2007-02-17 13:09:23 +03:00
|
|
|
mov [edx+4], eax
|
|
|
|
add edx, 8
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
mov eax, 0x800000+PG_SW
|
|
|
|
mov ecx, (HEAP_BASE-0x800000)/4096
|
|
|
|
jmp .map_low
|
2006-10-06 10:09:41 +04:00
|
|
|
.no_PSE:
|
|
|
|
mov eax, PG_SW
|
2007-02-17 13:09:23 +03:00
|
|
|
mov ecx, HEAP_BASE/4096
|
2006-10-06 10:09:41 +04:00
|
|
|
.map_low:
|
2007-02-17 13:09:23 +03:00
|
|
|
mov edi, tmp_page_tab
|
|
|
|
@@: ;
|
|
|
|
stosd
|
2006-10-06 10:09:41 +04:00
|
|
|
add eax, 0x1000
|
|
|
|
dec ecx
|
2007-02-17 13:09:23 +03:00
|
|
|
jnz @B
|
|
|
|
|
|
|
|
mov ecx, [pg_data.kernel_tables]
|
|
|
|
shl ecx, 10
|
|
|
|
xor eax, eax
|
|
|
|
rep stosd
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
mov ecx, [pg_data.kernel_tables]
|
|
|
|
mov eax, tmp_page_tab+PG_SW
|
2007-02-17 13:09:23 +03:00
|
|
|
mov edi, edx
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
.map_kernel_tabs:
|
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
stosd
|
2006-10-06 10:09:41 +04:00
|
|
|
add eax, 0x1000
|
|
|
|
dec ecx
|
|
|
|
jnz .map_kernel_tabs
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
mov dword [sys_pgdir+(page_tabs shr 20)], sys_pgdir+PG_SW
|
2006-10-06 10:09:41 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc init_page_map
|
2007-02-17 13:09:23 +03:00
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mov edi, sys_pgmap
|
2007-02-17 13:09:23 +03:00
|
|
|
mov ecx, (HEAP_BASE/4096)/32 ;384/4
|
|
|
|
mov ebx, ecx
|
2006-10-06 10:09:41 +04:00
|
|
|
xor eax,eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
not eax
|
|
|
|
mov ecx, [pg_data.pagemap_size]
|
2007-02-17 13:09:23 +03:00
|
|
|
sub ecx, ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
shr ecx, 2
|
|
|
|
rep stosd
|
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
lea edi, [sys_pgmap+ebx*4] ;+384
|
2006-10-06 10:09:41 +04:00
|
|
|
mov edx, [pg_data.pages_count]
|
|
|
|
mov ecx, [pg_data.kernel_tables]
|
2007-02-17 13:09:23 +03:00
|
|
|
add ecx, (HEAP_BASE/4096) and 31
|
|
|
|
sub edx, HEAP_BASE/4096
|
2006-10-06 10:09:41 +04:00
|
|
|
sub edx, ecx
|
|
|
|
mov [pg_data.pages_free], edx
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov ebx, ecx
|
|
|
|
shr ecx, 5
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
not eax
|
|
|
|
mov ecx, ebx
|
|
|
|
and ecx, 31
|
|
|
|
shl eax, cl
|
2007-02-17 13:09:23 +03:00
|
|
|
mov [page_start], edi; sys_pgmap+384
|
2006-10-06 10:09:41 +04:00
|
|
|
stosd
|
|
|
|
|
|
|
|
mov ebx, sys_pgmap
|
|
|
|
add ebx, [pg_data.pagemap_size]
|
|
|
|
mov [page_end], ebx
|
|
|
|
|
|
|
|
mov [pg_data.pg_mutex], 0
|
|
|
|
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc alloc_page
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov ebx, [page_start]
|
|
|
|
mov ecx, [page_end]
|
|
|
|
.l1:
|
|
|
|
bsf eax,[ebx];
|
|
|
|
jnz .found
|
|
|
|
add ebx,4
|
|
|
|
cmp ebx, ecx
|
|
|
|
jb .l1
|
|
|
|
popfd
|
|
|
|
xor eax,eax
|
|
|
|
ret
|
|
|
|
.found:
|
|
|
|
btr [ebx], eax
|
|
|
|
mov [page_start],ebx
|
|
|
|
sub ebx, sys_pgmap
|
2006-12-29 10:12:27 +03:00
|
|
|
lea eax, [eax+ebx*8]
|
2006-10-06 10:09:41 +04:00
|
|
|
shl eax, 12
|
|
|
|
dec [pg_data.pages_free]
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc alloc_pages stdcall, count:dword
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov eax, [count]
|
|
|
|
add eax, 7
|
|
|
|
shr eax, 3
|
|
|
|
mov [count], eax
|
|
|
|
cmp eax, [pg_data.pages_free]
|
|
|
|
ja .fail
|
|
|
|
|
|
|
|
mov ecx, [page_start]
|
|
|
|
mov ebx, [page_end]
|
|
|
|
.find:
|
|
|
|
mov edx, [count]
|
|
|
|
mov edi, ecx
|
|
|
|
.match:
|
|
|
|
cmp byte [ecx], 0xFF
|
|
|
|
jne .next
|
|
|
|
dec edx
|
|
|
|
jz .ok
|
|
|
|
inc ecx
|
|
|
|
cmp ecx,ebx
|
|
|
|
jb .match
|
|
|
|
.fail: xor eax, eax
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
.next:
|
|
|
|
inc ecx
|
|
|
|
cmp ecx, ebx
|
|
|
|
jb .find
|
|
|
|
popfd
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
.ok:
|
|
|
|
sub ecx, edi
|
|
|
|
inc ecx
|
|
|
|
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
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
|
2007-02-05 17:20:36 +03:00
|
|
|
push ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, [phis_addr]
|
|
|
|
and eax, not 0xFFF
|
|
|
|
or eax, [flags]
|
|
|
|
mov ebx, [lin_addr]
|
|
|
|
shr ebx, 12
|
2007-02-20 15:05:24 +03:00
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, [lin_addr]
|
|
|
|
invlpg [eax]
|
2007-02-05 17:20:36 +03:00
|
|
|
pop ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-01-19 06:58:46 +03:00
|
|
|
align 4
|
|
|
|
map_space: ;not implemented
|
|
|
|
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
align 4
|
|
|
|
proc free_page
|
|
|
|
;arg: eax page address
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
shr eax, 12 ;page index
|
|
|
|
mov ebx, sys_pgmap
|
|
|
|
bts [ebx], eax ;that's all!
|
2007-01-23 17:55:03 +03:00
|
|
|
cmc
|
2007-02-08 04:02:14 +03:00
|
|
|
adc [pg_data.pages_free], 0
|
2006-10-06 10:09:41 +04:00
|
|
|
shr eax, 3
|
|
|
|
and eax, not 3 ;dword offset from page_map
|
|
|
|
add eax, ebx
|
|
|
|
cmp [page_start], eax
|
|
|
|
ja @f
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
mov [page_start], eax
|
|
|
|
popfd
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-01-18 10:31:56 +03:00
|
|
|
; param
|
2007-02-08 04:02:14 +03:00
|
|
|
; eax= page base + page flags
|
2007-01-19 06:58:46 +03:00
|
|
|
; ebx= liear address
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
align 4
|
2007-02-08 04:02:14 +03:00
|
|
|
commit_pages:
|
2007-01-19 06:58:46 +03:00
|
|
|
|
2007-02-08 04:02:14 +03:00
|
|
|
test ecx, ecx
|
|
|
|
jz .fail
|
2007-01-19 06:58:46 +03:00
|
|
|
|
2007-02-08 04:02:14 +03:00
|
|
|
mov edi, ebx
|
|
|
|
mov ebx, pg_data.pg_mutex
|
|
|
|
call wait_mutex ;ebx
|
|
|
|
|
|
|
|
mov edx, 0x1000
|
|
|
|
mov ebx, edi
|
|
|
|
shr ebx, 12
|
|
|
|
@@:
|
2007-02-20 15:05:24 +03:00
|
|
|
mov [page_tabs+ebx*4], eax
|
2007-02-08 04:02:14 +03:00
|
|
|
invlpg [edi]
|
|
|
|
add edi, edx
|
|
|
|
add eax, edx
|
|
|
|
inc ebx
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
|
|
|
mov [pg_data.pg_mutex],ecx
|
|
|
|
.fail:
|
2007-01-19 06:58:46 +03:00
|
|
|
ret
|
|
|
|
|
2007-02-08 04:02:14 +03:00
|
|
|
|
2007-01-19 06:58:46 +03:00
|
|
|
; param
|
2007-01-18 10:31:56 +03:00
|
|
|
; eax= base
|
2007-01-19 06:58:46 +03:00
|
|
|
; ecx= count
|
2007-01-18 10:31:56 +03:00
|
|
|
|
|
|
|
align 4
|
|
|
|
release_pages:
|
2007-02-05 17:20:36 +03:00
|
|
|
|
|
|
|
pushad
|
2007-01-18 10:31:56 +03:00
|
|
|
mov ebx, pg_data.pg_mutex
|
|
|
|
call wait_mutex ;ebx
|
|
|
|
|
|
|
|
mov esi, eax
|
|
|
|
mov edi, eax
|
|
|
|
|
|
|
|
shr esi, 10
|
2007-02-20 15:05:24 +03:00
|
|
|
add esi, page_tabs
|
2007-02-08 04:02:14 +03:00
|
|
|
|
|
|
|
mov ebp, [pg_data.pages_free]
|
2007-01-18 10:31:56 +03:00
|
|
|
mov ebx, [page_start]
|
|
|
|
mov edx, sys_pgmap
|
|
|
|
@@:
|
|
|
|
xor eax, eax
|
|
|
|
xchg eax, [esi]
|
|
|
|
invlpg [edi]
|
|
|
|
|
|
|
|
test eax, 1
|
|
|
|
jz .next
|
|
|
|
|
|
|
|
shr eax, 12
|
|
|
|
bts [edx], eax
|
2007-01-23 17:55:03 +03:00
|
|
|
cmc
|
2007-02-08 04:02:14 +03:00
|
|
|
adc ebp, 0
|
2007-01-18 10:31:56 +03:00
|
|
|
shr eax, 3
|
|
|
|
and eax, -4
|
|
|
|
add eax, edx
|
|
|
|
cmp eax, ebx
|
|
|
|
jae .next
|
|
|
|
|
|
|
|
mov ebx, eax
|
|
|
|
.next:
|
|
|
|
add edi, 0x1000
|
|
|
|
add esi, 4
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
2007-02-08 04:02:14 +03:00
|
|
|
mov [pg_data.pages_free], ebp
|
2007-01-18 10:31:56 +03:00
|
|
|
and [pg_data.pg_mutex],0
|
2007-02-05 17:20:36 +03:00
|
|
|
popad
|
2007-01-18 10:31:56 +03:00
|
|
|
ret
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
align 4
|
2006-10-20 18:02:26 +04:00
|
|
|
proc map_page_table stdcall, lin_addr:dword, phis_addr:dword
|
2007-02-05 17:20:36 +03:00
|
|
|
push ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
mov ebx, [lin_addr]
|
|
|
|
shr ebx, 22
|
|
|
|
mov eax, [phis_addr]
|
|
|
|
and eax, not 0xFFF
|
|
|
|
or eax, PG_UW ;+PG_NOCACHE
|
2007-02-27 14:47:52 +03:00
|
|
|
mov dword [master_tab+ebx*4], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, [lin_addr]
|
|
|
|
shr eax, 10
|
2007-02-20 15:05:24 +03:00
|
|
|
add eax, page_tabs
|
2006-10-06 10:09:41 +04:00
|
|
|
invlpg [eax]
|
2007-02-05 17:20:36 +03:00
|
|
|
pop ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc init_LFB
|
2007-02-27 14:47:52 +03:00
|
|
|
locals
|
|
|
|
pg_count dd ?
|
|
|
|
endl
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
cmp dword [LFBAddress], -1
|
|
|
|
jne @f
|
2007-03-10 19:04:35 +03:00
|
|
|
mov [BOOT_VAR+0x901c],byte 2
|
2006-10-06 10:09:41 +04:00
|
|
|
stdcall kernel_alloc, 0x280000
|
|
|
|
mov [LFBAddress], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
test [SCR_MODE],word 0100000000000000b
|
2006-11-16 08:47:31 +03:00
|
|
|
jnz @f
|
2007-03-10 19:04:35 +03:00
|
|
|
mov [BOOT_VAR+0x901c],byte 2
|
2006-11-16 08:47:31 +03:00
|
|
|
ret
|
2006-10-06 10:09:41 +04:00
|
|
|
@@:
|
2007-02-27 14:47:52 +03:00
|
|
|
mov edx, LFB_BASE
|
2006-10-06 10:09:41 +04:00
|
|
|
mov esi, [LFBAddress]
|
2007-02-27 14:47:52 +03:00
|
|
|
mov edi, [LFBSize]
|
2007-02-28 11:52:06 +03:00
|
|
|
mov dword [exp_lfb+4], edx
|
2006-11-20 10:06:00 +03:00
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
shr edi, 12
|
|
|
|
mov [pg_count], edi
|
|
|
|
shr edi, 10
|
|
|
|
|
|
|
|
bt [cpu_caps], CAPS_PSE
|
|
|
|
jnc .map_page_tables
|
|
|
|
or esi, PG_LARGE+PG_UW
|
2007-02-27 14:47:52 +03:00
|
|
|
shr edx, 20
|
|
|
|
mov ecx, edx
|
2006-10-06 10:09:41 +04:00
|
|
|
@@:
|
2007-02-27 14:47:52 +03:00
|
|
|
mov [sys_pgdir+edx], esi
|
|
|
|
add edx, 4
|
2006-10-06 10:09:41 +04:00
|
|
|
add esi, 0x00400000
|
|
|
|
dec edi
|
|
|
|
jnz @B
|
|
|
|
|
2006-11-03 19:26:10 +03:00
|
|
|
bt [cpu_caps], CAPS_PGE
|
|
|
|
jnc @F
|
2006-10-06 10:09:41 +04:00
|
|
|
or dword [sys_pgdir+ecx], PG_GLOBAL
|
2006-11-03 19:26:10 +03:00
|
|
|
@@:
|
2007-02-27 14:47:52 +03:00
|
|
|
mov dword [LFBAddress], LFB_BASE
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, cr3 ;flush TLB
|
|
|
|
mov cr3, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
.map_page_tables:
|
|
|
|
|
|
|
|
call alloc_page
|
2007-02-27 14:47:52 +03:00
|
|
|
stdcall map_page_table, edx, eax
|
2007-03-06 00:37:28 +03:00
|
|
|
add edx, 0x00400000
|
2006-10-06 10:09:41 +04:00
|
|
|
dec edi
|
2007-03-06 00:37:28 +03:00
|
|
|
jnz .map_page_tables
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
mov eax, [LFBAddress]
|
2007-02-27 14:47:52 +03:00
|
|
|
mov edi, page_tabs + (LFB_BASE shr 10)
|
2006-10-06 10:09:41 +04:00
|
|
|
or eax, PG_UW
|
|
|
|
mov ecx, [pg_count]
|
2007-02-27 14:47:52 +03:00
|
|
|
cld
|
2007-03-06 00:37:28 +03:00
|
|
|
@@:
|
|
|
|
stosd
|
|
|
|
add eax, 0x1000
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
mov dword [LFBAddress], LFB_BASE
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, cr3 ;flush TLB
|
|
|
|
mov cr3, eax
|
|
|
|
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc new_mem_resize stdcall, new_size:dword
|
|
|
|
|
2007-01-17 07:43:21 +03:00
|
|
|
mov ebx, pg_data.pg_mutex
|
|
|
|
call wait_mutex ;ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
mov edi, [new_size]
|
|
|
|
add edi,4095
|
|
|
|
and edi,not 4095
|
|
|
|
mov [new_size], edi
|
|
|
|
|
|
|
|
mov edx,[CURRENT_TASK]
|
|
|
|
shl edx,8
|
2007-02-28 13:51:05 +03:00
|
|
|
cmp [SLOT_BASE+APPDATA.heap_base+edx],0
|
2006-10-10 09:11:30 +04:00
|
|
|
jne .exit
|
|
|
|
|
2007-02-28 13:51:05 +03:00
|
|
|
mov esi, [SLOT_BASE+APPDATA.mem_size+edx]
|
2006-10-06 10:09:41 +04:00
|
|
|
add esi, 4095
|
|
|
|
and esi, not 4095
|
|
|
|
|
|
|
|
cmp edi, esi
|
|
|
|
jae .expand
|
|
|
|
|
|
|
|
shr edi, 12
|
|
|
|
shr esi, 12
|
|
|
|
@@:
|
2007-02-27 14:47:52 +03:00
|
|
|
mov eax, [app_page_tabs+edi*4]
|
2006-10-06 10:09:41 +04:00
|
|
|
test eax, 1
|
|
|
|
jz .next
|
2007-02-27 14:47:52 +03:00
|
|
|
mov dword [app_page_tabs+edi*4], 2
|
2006-10-06 10:09:41 +04:00
|
|
|
mov ebx, edi
|
|
|
|
shl ebx, 12
|
|
|
|
invlpg [ebx+std_application_base_address]
|
|
|
|
call free_page
|
|
|
|
|
|
|
|
.next: add edi, 1
|
|
|
|
cmp edi, esi
|
|
|
|
jb @B
|
|
|
|
|
|
|
|
.update_size:
|
2007-01-25 16:42:23 +03:00
|
|
|
mov ebx, [new_size]
|
|
|
|
call update_mem_size
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
dec [pg_data.pg_mutex]
|
|
|
|
ret
|
|
|
|
|
|
|
|
.expand:
|
|
|
|
add edi, new_app_base
|
|
|
|
add esi, new_app_base
|
|
|
|
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
add edi, 0x3FFFFF
|
|
|
|
and edi, not(0x3FFFFF)
|
|
|
|
add esi, 0x3FFFFF
|
|
|
|
and esi, not(0x3FFFFF)
|
|
|
|
|
|
|
|
cmp esi, edi
|
|
|
|
jae .grow
|
|
|
|
|
|
|
|
xchg esi, edi
|
|
|
|
|
|
|
|
@@:
|
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
|
2006-10-20 18:02:26 +04:00
|
|
|
stdcall map_page_table, edi, eax
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
push edi
|
|
|
|
shr edi, 10
|
2007-02-20 15:05:24 +03:00
|
|
|
add edi, page_tabs
|
2006-10-06 10:09:41 +04:00
|
|
|
mov ecx, 1024
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
add edi, 0x00400000
|
|
|
|
cmp edi, esi
|
|
|
|
jb @B
|
|
|
|
.grow:
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
@@:
|
|
|
|
call alloc_page
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
stdcall map_page,esi,eax,dword PG_UW
|
|
|
|
|
|
|
|
push edi
|
|
|
|
mov edi, esi
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, 1024
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
add esi, 0x1000
|
|
|
|
cmp esi, edi
|
2007-01-25 16:42:23 +03:00
|
|
|
jb @B
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
jmp .update_size
|
|
|
|
.exit:
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
dec [pg_data.pg_mutex]
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-01-25 16:42:23 +03:00
|
|
|
update_mem_size:
|
|
|
|
; in: edx = slot shl 8
|
|
|
|
; ebx = new memory size
|
|
|
|
; destroys eax,ecx,edx
|
|
|
|
|
2007-02-28 13:51:05 +03:00
|
|
|
mov [SLOT_BASE+APPDATA.mem_size+edx],ebx
|
2007-01-25 16:42:23 +03:00
|
|
|
;search threads and update
|
|
|
|
;application memory size infomation
|
2007-02-28 13:51:05 +03:00
|
|
|
mov ecx,[SLOT_BASE+APPDATA.dir_table+edx]
|
2007-01-25 16:42:23 +03:00
|
|
|
mov eax,2
|
|
|
|
|
|
|
|
.search_threads:
|
|
|
|
;eax = current slot
|
|
|
|
;ebx = new memory size
|
|
|
|
;ecx = page directory
|
|
|
|
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
|
2007-02-28 13:51:05 +03:00
|
|
|
cmp [SLOT_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread?
|
2007-01-25 16:42:23 +03:00
|
|
|
jnz .search_threads_next
|
2007-02-28 13:51:05 +03:00
|
|
|
mov [SLOT_BASE+edx+APPDATA.mem_size],ebx ;update memory size
|
2007-01-25 16:42:23 +03:00
|
|
|
.search_threads_next:
|
|
|
|
inc eax
|
|
|
|
jmp .search_threads
|
|
|
|
.search_threads_end:
|
|
|
|
ret
|
|
|
|
|
2007-01-20 10:48:13 +03:00
|
|
|
; param
|
|
|
|
; eax= linear address
|
|
|
|
;
|
|
|
|
; retval
|
|
|
|
; eax= phisical page address
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
align 4
|
2007-01-20 10:48:13 +03:00
|
|
|
get_pg_addr:
|
|
|
|
shr eax, 12
|
2007-02-20 15:05:24 +03:00
|
|
|
mov eax, [page_tabs+eax*4]
|
2006-10-06 10:09:41 +04:00
|
|
|
and eax, 0xFFFFF000
|
|
|
|
ret
|
|
|
|
|
2006-10-20 18:02:26 +04:00
|
|
|
align 4
|
2006-10-06 10:09:41 +04:00
|
|
|
proc page_fault_handler
|
|
|
|
pushad
|
|
|
|
|
|
|
|
mov ebp, esp
|
|
|
|
mov eax, cr2
|
2006-10-10 09:11:30 +04:00
|
|
|
push eax
|
2006-10-06 10:09:41 +04:00
|
|
|
push ds
|
2006-10-20 18:02:26 +04:00
|
|
|
push es
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
2006-10-20 18:02:26 +04:00
|
|
|
mov es, ax
|
|
|
|
|
|
|
|
inc [pg_data.pages_faults]
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
mov ebx, [ebp-4]
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
cmp ebx, 0x80000000
|
2006-10-06 10:09:41 +04:00
|
|
|
jae .user_space
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
cmp ebx, app_page_tabs
|
2006-10-20 18:02:26 +04:00
|
|
|
jae .alloc
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
cmp ebx, page_tabs
|
2006-10-06 10:09:41 +04:00
|
|
|
jae .tab_space
|
|
|
|
|
2007-02-27 14:47:52 +03:00
|
|
|
cmp ebx, 0x7DC00000
|
|
|
|
jae .lfb_addr
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
jmp .kernel_space
|
|
|
|
|
|
|
|
.user_space:
|
|
|
|
shr ebx, 12
|
2006-10-10 09:11:30 +04:00
|
|
|
mov ecx, ebx
|
|
|
|
shr ecx, 10
|
|
|
|
mov edx, [master_tab+ecx*4]
|
|
|
|
test edx, 1
|
|
|
|
jz .fail
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2007-02-20 15:05:24 +03:00
|
|
|
mov eax, [page_tabs+ebx*4]
|
2006-10-06 10:09:41 +04:00
|
|
|
test eax, 2
|
2006-10-10 09:11:30 +04:00
|
|
|
jz .fail
|
2006-10-20 18:02:26 +04:00
|
|
|
.alloc:
|
2006-10-06 10:09:41 +04:00
|
|
|
call alloc_page
|
|
|
|
and eax, eax
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
stdcall map_page,[ebp-4],eax,dword PG_UW
|
|
|
|
|
2006-10-20 18:02:26 +04:00
|
|
|
mov edi, [ebp-4]
|
|
|
|
and edi, 0xFFFFF000
|
2006-10-06 10:09:41 +04:00
|
|
|
mov ecx, 1024
|
|
|
|
xor eax, eax
|
2006-10-20 18:02:26 +04:00
|
|
|
cld
|
|
|
|
rep stosd
|
2006-10-06 10:09:41 +04:00
|
|
|
.exit:
|
2006-10-20 18:02:26 +04:00
|
|
|
pop es
|
2006-10-06 10:09:41 +04:00
|
|
|
pop ds
|
|
|
|
mov esp, ebp
|
|
|
|
popad
|
|
|
|
add esp, 4
|
|
|
|
iretd
|
2006-10-10 09:11:30 +04:00
|
|
|
.fail:
|
2006-10-20 18:02:26 +04:00
|
|
|
pop es
|
2006-10-10 09:11:30 +04:00
|
|
|
pop ds
|
|
|
|
mov esp, ebp
|
|
|
|
popad
|
|
|
|
add esp, 4
|
|
|
|
|
|
|
|
save_ring3_context ;debugger support
|
|
|
|
|
|
|
|
mov bl, 14
|
|
|
|
jmp exc_c
|
|
|
|
iretd
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
.kernel_space:
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 12
|
2007-02-20 15:05:24 +03:00
|
|
|
; mov eax, [page_tabs+ebx*4]
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 10
|
|
|
|
; mov eax, [master_tab+ebx*4]
|
|
|
|
jmp .exit
|
2006-10-06 10:09:41 +04:00
|
|
|
.old_addr:
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 12
|
2007-02-20 15:05:24 +03:00
|
|
|
; mov eax, [page_tabs+ebx*4]
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 10
|
|
|
|
; mov eax, [master_tab+ebx*4]
|
|
|
|
jmp .exit
|
2006-10-06 10:09:41 +04:00
|
|
|
.lfb_addr:
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 22
|
|
|
|
; ;mov ecx, [sys_page_dir]
|
|
|
|
; mov eax, [master_tab+ebx*4]
|
|
|
|
jmp .exit
|
2006-10-06 10:09:41 +04:00
|
|
|
.tab_space:
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 12
|
2007-02-20 15:05:24 +03:00
|
|
|
; mov eax, [page_tabs+ebx*4]
|
2006-10-20 18:02:26 +04:00
|
|
|
; shr ebx, 10
|
|
|
|
; ;mov ecx, [sys_page_dir]
|
|
|
|
; mov eax, [master_tab+ebx*4]
|
|
|
|
jmp .exit
|
2006-10-06 10:09:41 +04:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc map_mem stdcall, lin_addr:dword,pdir:dword,\
|
|
|
|
ofs:dword,buf_size:dword
|
|
|
|
mov eax, [buf_size]
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
mov eax, [pdir]
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
|
|
|
stdcall map_page,[ipc_pdir],eax,dword PG_UW
|
|
|
|
mov ebx, [ofs]
|
|
|
|
shr ebx, 22
|
|
|
|
mov esi, [ipc_pdir]
|
|
|
|
mov edi, [ipc_ptab]
|
|
|
|
mov eax, [esi+ebx*4]
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
stdcall map_page,edi,eax,dword PG_UW
|
|
|
|
; inc ebx
|
|
|
|
; add edi, 0x1000
|
|
|
|
; mov eax, [esi+ebx*4]
|
|
|
|
; test eax, eax
|
|
|
|
; jz @f
|
|
|
|
; and eax, 0xFFFFF000
|
|
|
|
; stdcall map_page, edi, eax
|
|
|
|
|
|
|
|
@@: 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, [ipc_ptab]
|
|
|
|
|
|
|
|
.map: mov eax, [esi+edx*4]
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
stdcall map_page,edi,eax,dword PG_UW
|
|
|
|
add edi, 0x1000
|
|
|
|
inc edx
|
|
|
|
dec ecx
|
|
|
|
jnz .map
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc map_memEx stdcall, lin_addr:dword,pdir:dword,\
|
|
|
|
ofs:dword,buf_size:dword
|
|
|
|
mov eax, [buf_size]
|
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
|
|
|
|
|
|
|
mov eax, [pdir]
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
|
|
|
stdcall map_page,[proc_mem_pdir],eax,dword 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,dword 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]
|
|
|
|
|
|
|
|
.map: mov eax, [esi+edx*4]
|
|
|
|
; and eax, 0xFFFFF000
|
|
|
|
; test eax, eax
|
|
|
|
; jz .exit
|
|
|
|
stdcall map_page,edi,eax,dword PG_UW
|
|
|
|
add edi, 0x1000
|
|
|
|
inc edx
|
|
|
|
dec ecx
|
|
|
|
jnz .map
|
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sys_IPC:
|
|
|
|
;input:
|
|
|
|
; eax=1 - set ipc buffer area
|
|
|
|
; ebx=address of buffer
|
|
|
|
; ecx=size of buffer
|
|
|
|
; eax=2 - send message
|
|
|
|
; ebx=PID
|
|
|
|
; ecx=address of message
|
|
|
|
; edx=size of message
|
|
|
|
|
|
|
|
cmp eax,1
|
|
|
|
jne @f
|
|
|
|
call set_ipc_buff
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 2
|
|
|
|
jne @f
|
|
|
|
stdcall sys_ipc_send, ebx, ecx, edx
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc set_ipc_buff
|
|
|
|
|
|
|
|
mov eax,[CURRENT_TASK]
|
|
|
|
shl eax,8
|
2007-02-28 13:51:05 +03:00
|
|
|
add eax, SLOT_BASE
|
2006-10-06 10:09:41 +04:00
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
mov [eax+0xA0],ebx ;set fields in extended information area
|
|
|
|
mov [eax+0xA4],ecx
|
|
|
|
|
|
|
|
add ebx, new_app_base
|
|
|
|
add ecx, ebx
|
|
|
|
add ecx, 4095
|
|
|
|
and ecx, not 4095
|
|
|
|
|
|
|
|
.touch: mov eax, [ebx]
|
|
|
|
add ebx, 0x1000
|
|
|
|
cmp ebx, ecx
|
|
|
|
jna .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 ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
pushf
|
|
|
|
cli
|
|
|
|
|
|
|
|
mov eax, [PID]
|
|
|
|
call pid_to_slot
|
|
|
|
test eax,eax
|
|
|
|
jz .no_pid
|
|
|
|
|
|
|
|
mov [dst_slot], eax
|
|
|
|
shl eax,8
|
2007-02-28 13:51:05 +03:00
|
|
|
mov edi,[eax+SLOT_BASE+0xa0] ;is ipc area defined?
|
2006-10-06 10:09:41 +04:00
|
|
|
test edi,edi
|
|
|
|
jz .no_ipc_area
|
|
|
|
|
|
|
|
mov ebx, edi
|
|
|
|
add edi, new_app_base
|
|
|
|
and ebx, 0xFFF
|
|
|
|
mov [dst_offset], ebx
|
|
|
|
|
2007-02-28 13:51:05 +03:00
|
|
|
mov esi, [eax+SLOT_BASE+0xa4]
|
2006-10-06 10:09:41 +04:00
|
|
|
mov [buf_size], esi
|
|
|
|
|
2007-02-28 13:51:05 +03:00
|
|
|
stdcall map_mem, [ipc_tmp], [SLOT_BASE+eax+0xB8],\
|
2006-10-06 10:09:41 +04:00
|
|
|
edi, esi
|
|
|
|
|
|
|
|
mov edi, [dst_offset]
|
|
|
|
add edi, [ipc_tmp]
|
|
|
|
cmp dword [edi], 0
|
|
|
|
jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now
|
2006-12-02 11:18:48 +03:00
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mov ebx, dword [edi+4]
|
|
|
|
mov edx, ebx
|
|
|
|
add ebx, 8
|
|
|
|
add ebx, [msg_size]
|
|
|
|
cmp ebx, [buf_size]
|
|
|
|
ja .buffer_overflow ;esi<0 - not enough memory in buffer
|
2006-12-02 11:18:48 +03:00
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mov dword [edi+4], ebx
|
|
|
|
mov eax,[TASK_BASE]
|
|
|
|
mov eax, [eax+0x04] ;eax - our PID
|
|
|
|
mov edi, [dst_offset]
|
|
|
|
add edi, [ipc_tmp]
|
|
|
|
add edi, edx
|
|
|
|
mov [edi], eax
|
|
|
|
mov ecx, [msg_size]
|
|
|
|
|
|
|
|
mov [edi+4], ecx
|
|
|
|
add edi, 8
|
|
|
|
mov esi, [msg_addr]
|
|
|
|
add esi, new_app_base
|
|
|
|
cld
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
mov ebx, [ipc_tmp]
|
|
|
|
mov edx, ebx
|
|
|
|
shr ebx, 12
|
|
|
|
xor eax, eax
|
2007-02-20 15:05:24 +03:00
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
mov ebx, [ipc_pdir]
|
|
|
|
mov edx, ebx
|
|
|
|
shr ebx, 12
|
|
|
|
xor eax, eax
|
2007-02-20 15:05:24 +03:00
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
mov ebx, [ipc_ptab]
|
|
|
|
mov edx, ebx
|
|
|
|
shr ebx, 12
|
|
|
|
xor eax, eax
|
2007-02-20 15:05:24 +03:00
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
mov eax, [dst_slot]
|
|
|
|
shl eax, 8
|
2007-02-28 13:51:05 +03:00
|
|
|
or [eax+SLOT_BASE+0xA8],dword 0x40
|
2006-10-06 10:09:41 +04:00
|
|
|
cmp dword [check_idle_semaphore],20
|
|
|
|
jge .ipc_no_cis
|
|
|
|
|
|
|
|
mov dword [check_idle_semaphore],5
|
|
|
|
.ipc_no_cis:
|
|
|
|
popf
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
.no_pid:
|
|
|
|
popf
|
|
|
|
mov eax, 4
|
|
|
|
ret
|
|
|
|
.no_ipc_area:
|
|
|
|
popf
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
ret
|
|
|
|
.ipc_blocked:
|
|
|
|
popf
|
|
|
|
mov eax, 2
|
|
|
|
ret
|
|
|
|
.buffer_overflow:
|
|
|
|
popf
|
|
|
|
mov eax, 3
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2006-10-08 11:48:38 +04:00
|
|
|
sysfn_meminfo:
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2006-10-08 11:48:38 +04:00
|
|
|
add ebx, new_app_base
|
2006-10-10 09:11:30 +04:00
|
|
|
cmp ebx, new_app_base
|
|
|
|
jb .fail
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, [pg_data.pages_count]
|
2006-10-08 11:48:38 +04:00
|
|
|
mov [ebx], eax
|
2006-10-10 09:11:30 +04:00
|
|
|
shl eax, 12
|
|
|
|
mov [esp+36], eax
|
2006-10-08 11:48:38 +04:00
|
|
|
mov ecx, [pg_data.pages_free]
|
|
|
|
mov [ebx+4], ecx
|
|
|
|
mov edx, [pg_data.pages_faults]
|
|
|
|
mov [ebx+8], edx
|
|
|
|
mov esi, [heap_size]
|
|
|
|
mov [ebx+12], esi
|
|
|
|
mov edi, [heap_free]
|
|
|
|
mov [ebx+16], edi
|
|
|
|
mov eax, [heap_blocks]
|
|
|
|
mov [ebx+20], eax
|
|
|
|
mov ecx, [free_blocks]
|
|
|
|
mov [ebx+24], ecx
|
2006-10-10 09:11:30 +04:00
|
|
|
ret
|
|
|
|
.fail:
|
|
|
|
mov dword [esp+36], -1
|
2006-10-06 10:09:41 +04:00
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
new_services:
|
|
|
|
|
|
|
|
cmp eax,4
|
|
|
|
jle sys_sheduler
|
|
|
|
|
2006-10-08 11:48:38 +04:00
|
|
|
cmp eax, 11
|
2006-10-06 10:09:41 +04:00
|
|
|
jb .fail
|
|
|
|
ja @f
|
|
|
|
|
2006-10-20 18:02:26 +04:00
|
|
|
call init_heap
|
2006-10-06 10:09:41 +04:00
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 12
|
|
|
|
ja @f
|
|
|
|
|
|
|
|
stdcall user_alloc, ebx
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 13
|
|
|
|
ja @f
|
2006-10-20 18:02:26 +04:00
|
|
|
add ebx, new_app_base
|
2006-10-06 10:09:41 +04:00
|
|
|
stdcall user_free, ebx
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 14
|
|
|
|
ja @f
|
2006-12-02 11:18:48 +03:00
|
|
|
add ebx, new_app_base
|
2006-10-10 09:11:30 +04:00
|
|
|
cmp ebx, new_app_base
|
|
|
|
jb .fail
|
2006-12-02 11:18:48 +03:00
|
|
|
stdcall get_event_ex, ebx, ecx
|
|
|
|
mov [esp+36], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 15
|
|
|
|
ja @f
|
|
|
|
mov ecx, [CURRENT_TASK]
|
|
|
|
shl ecx, 8
|
2007-02-28 13:51:05 +03:00
|
|
|
mov eax, [ecx+SLOT_BASE+APPDATA.fpu_handler]
|
|
|
|
mov [ecx+SLOT_BASE+APPDATA.fpu_handler], ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 16
|
|
|
|
ja @f
|
|
|
|
|
2006-10-20 18:02:26 +04:00
|
|
|
test ebx, ebx
|
|
|
|
jz .fail
|
2006-10-06 10:09:41 +04:00
|
|
|
add ebx, new_app_base
|
2006-10-10 09:11:30 +04:00
|
|
|
cmp ebx, new_app_base
|
|
|
|
jb .fail
|
2006-10-06 10:09:41 +04:00
|
|
|
stdcall get_service, ebx
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
cmp eax, 17
|
|
|
|
ja @f
|
2007-02-27 14:47:52 +03:00
|
|
|
call srv_handlerEx ;ebx
|
2006-10-06 10:09:41 +04:00
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
2006-10-07 13:47:03 +04:00
|
|
|
@@:
|
|
|
|
cmp eax, 18
|
|
|
|
ja @f
|
|
|
|
mov ecx, [CURRENT_TASK]
|
|
|
|
shl ecx, 8
|
2007-02-28 13:51:05 +03:00
|
|
|
mov eax, [ecx+SLOT_BASE+APPDATA.sse_handler]
|
|
|
|
mov [ecx+SLOT_BASE+APPDATA.sse_handler], ebx
|
2006-10-07 13:47:03 +04:00
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
2006-10-27 19:08:19 +04:00
|
|
|
@@:
|
|
|
|
cmp eax, 19
|
2006-12-02 11:18:48 +03:00
|
|
|
ja .fail
|
2006-10-27 19:08:19 +04:00
|
|
|
add ebx, new_app_base
|
|
|
|
cmp ebx, new_app_base
|
|
|
|
jb .fail
|
|
|
|
stdcall load_library, ebx
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
2006-12-02 11:18:48 +03:00
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
|
|
|
mov [esp+36], eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc strncmp stdcall, str1:dword, str2:dword, count:dword
|
|
|
|
|
|
|
|
mov ecx,[count]
|
|
|
|
jecxz .end
|
|
|
|
|
|
|
|
mov ebx,ecx
|
|
|
|
|
|
|
|
mov edi,[str1]
|
|
|
|
mov esi,edi
|
|
|
|
xor eax,eax
|
|
|
|
repne scasb
|
|
|
|
neg ecx ; cx = count - strlen
|
|
|
|
add ecx,ebx ; strlen + count - strlen
|
|
|
|
|
|
|
|
.okay:
|
|
|
|
mov edi,esi
|
|
|
|
mov esi,[str2]
|
|
|
|
repe cmpsb
|
|
|
|
mov al,[esi-1]
|
|
|
|
xor ecx,ecx
|
|
|
|
|
|
|
|
cmp al,[edi-1]
|
|
|
|
ja .str2_big
|
|
|
|
je .end
|
|
|
|
|
|
|
|
.str1_big:
|
|
|
|
sub ecx,2
|
|
|
|
|
|
|
|
.str2_big:
|
|
|
|
not ecx
|
|
|
|
.end:
|
|
|
|
mov eax,ecx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc test_cpu
|
|
|
|
locals
|
2006-10-06 12:39:23 +04:00
|
|
|
cpu_type dd ?
|
|
|
|
cpu_id dd ?
|
|
|
|
cpu_Intel dd ?
|
|
|
|
cpu_AMD dd ?
|
2006-10-06 10:09:41 +04:00
|
|
|
endl
|
|
|
|
|
|
|
|
mov [cpu_type], 0
|
2006-11-16 08:47:31 +03:00
|
|
|
xor eax, eax
|
|
|
|
mov [cpu_caps], eax
|
|
|
|
mov [cpu_caps+4], eax
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
pushfd
|
|
|
|
pop eax
|
|
|
|
mov ecx, eax
|
|
|
|
xor eax, 0x40000
|
|
|
|
push eax
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
pop eax
|
|
|
|
xor eax, ecx
|
|
|
|
mov [cpu_type], CPU_386
|
2006-11-27 13:07:51 +03:00
|
|
|
jz .end_cpuid
|
2006-10-06 10:09:41 +04:00
|
|
|
push ecx
|
|
|
|
popfd
|
|
|
|
|
|
|
|
mov [cpu_type], CPU_486
|
|
|
|
mov eax, ecx
|
|
|
|
xor eax, 0x200000
|
|
|
|
push eax
|
|
|
|
popfd
|
|
|
|
pushfd
|
|
|
|
pop eax
|
|
|
|
xor eax, ecx
|
2006-11-27 13:07:51 +03:00
|
|
|
je .end_cpuid
|
2006-10-06 10:09:41 +04:00
|
|
|
mov [cpu_id], 1
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
cpuid
|
|
|
|
mov [cpu_vendor], ebx
|
|
|
|
mov [cpu_vendor+4], edx
|
|
|
|
mov [cpu_vendor+8], ecx
|
|
|
|
cmp ebx, dword [intel_str]
|
|
|
|
jne .check_AMD
|
|
|
|
cmp edx, dword [intel_str+4]
|
|
|
|
jne .check_AMD
|
|
|
|
cmp ecx, dword [intel_str+8]
|
|
|
|
jne .check_AMD
|
|
|
|
mov [cpu_Intel], 1
|
|
|
|
cmp eax, 1
|
|
|
|
jl .end_cpuid
|
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
|
|
|
mov [cpu_sign], eax
|
|
|
|
mov [cpu_info], ebx
|
|
|
|
mov [cpu_caps], edx
|
|
|
|
mov [cpu_caps+4],ecx
|
|
|
|
|
|
|
|
shr eax, 8
|
|
|
|
and eax, 0x0f
|
|
|
|
ret
|
|
|
|
.end_cpuid:
|
|
|
|
mov eax, [cpu_type]
|
|
|
|
ret
|
|
|
|
|
|
|
|
.check_AMD:
|
|
|
|
cmp ebx, dword [AMD_str]
|
2006-11-27 13:07:51 +03:00
|
|
|
jne .unknown
|
2006-10-06 10:09:41 +04:00
|
|
|
cmp edx, dword [AMD_str+4]
|
2006-11-27 13:07:51 +03:00
|
|
|
jne .unknown
|
2006-10-06 10:09:41 +04:00
|
|
|
cmp ecx, dword [AMD_str+8]
|
2006-11-27 13:07:51 +03:00
|
|
|
jne .unknown
|
2006-10-06 10:09:41 +04:00
|
|
|
mov [cpu_AMD], 1
|
|
|
|
cmp eax, 1
|
2006-11-27 13:07:51 +03:00
|
|
|
jl .unknown
|
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
|
|
|
mov [cpu_sign], eax
|
|
|
|
mov [cpu_info], ebx
|
|
|
|
mov [cpu_caps], edx
|
|
|
|
mov [cpu_caps+4],ecx
|
|
|
|
shr eax, 8
|
|
|
|
and eax, 0x0f
|
|
|
|
ret
|
|
|
|
.unknown:
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
|
|
|
mov [cpu_sign], eax
|
|
|
|
mov [cpu_info], ebx
|
|
|
|
mov [cpu_caps], edx
|
|
|
|
mov [cpu_caps+4],ecx
|
|
|
|
shr eax, 8
|
|
|
|
and eax, 0x0f
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
MEM_WB equ 6 ;write-back memory
|
|
|
|
MEM_WC equ 1 ;write combined memory
|
|
|
|
MEM_UC equ 0 ;uncached memory
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc init_mtrr
|
|
|
|
|
2007-03-10 19:04:35 +03:00
|
|
|
cmp [BOOT_VAR+0x901c],byte 2
|
2006-10-06 10:09:41 +04:00
|
|
|
je .exit
|
|
|
|
|
2006-11-16 08:47:31 +03:00
|
|
|
bt [cpu_caps], CAPS_MTRR
|
|
|
|
jnc .exit
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mov eax, cr0
|
|
|
|
or eax, 0x60000000 ;disable caching
|
|
|
|
mov cr0, eax
|
|
|
|
wbinvd ;invalidate cache
|
|
|
|
|
|
|
|
mov ecx, 0x2FF
|
|
|
|
rdmsr ;
|
|
|
|
push eax
|
|
|
|
|
|
|
|
xor edx, edx
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, 0x2FF
|
|
|
|
wrmsr ;disable all MTRR
|
|
|
|
|
|
|
|
stdcall set_mtrr, dword 0,dword 0,[MEM_AMOUNT],MEM_WB
|
|
|
|
stdcall set_mtrr, dword 1,[LFBAddress],[LFBSize],MEM_WC
|
|
|
|
xor edx, edx
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, 0x204
|
|
|
|
mov ebx, 6
|
|
|
|
@@:
|
|
|
|
wrmsr ;disable unused MTRR
|
|
|
|
inc ecx
|
|
|
|
wrmsr
|
|
|
|
inc ecx
|
|
|
|
dec ebx
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
wbinvd ;again invalidate
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
or eax, 0x800 ;set default memtype to UC
|
|
|
|
and al, 0xF0
|
|
|
|
mov ecx, 0x2FF
|
|
|
|
wrmsr ;and enable MTRR
|
|
|
|
|
|
|
|
mov eax, cr0
|
|
|
|
and eax, not 0x60000000
|
|
|
|
mov cr0, eax ; enable caching
|
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc set_mtrr stdcall, reg:dword,base:dword,size:dword,mem_type:dword
|
|
|
|
|
|
|
|
xor edx, edx
|
|
|
|
mov eax, [base]
|
|
|
|
or eax, [mem_type]
|
|
|
|
mov ecx, [reg]
|
|
|
|
lea ecx, [0x200+ecx*2]
|
|
|
|
wrmsr
|
|
|
|
|
|
|
|
mov ebx, [size]
|
|
|
|
dec ebx
|
|
|
|
mov eax, 0xFFFFFFFF
|
|
|
|
mov edx, 0x0000000F
|
|
|
|
sub eax, ebx
|
|
|
|
sbb edx, 0
|
|
|
|
or eax, 0x800
|
|
|
|
inc ecx
|
|
|
|
wrmsr
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2006-10-10 09:11:30 +04:00
|
|
|
align 4
|
|
|
|
proc stall stdcall, delay:dword
|
|
|
|
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
|
|
|
|
@@:
|
|
|
|
rdtsc
|
|
|
|
sub eax, ebx
|
|
|
|
sbb edx, ecx
|
|
|
|
jb @B
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
pop ebx
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
iglobal
|
|
|
|
align 4
|
|
|
|
intel_str db "GenuineIntel",0
|
|
|
|
AMD_str db "AuthenticAMD",0
|
|
|
|
endg
|
|
|
|
|
|
|
|
uglobal
|
|
|
|
align 16
|
|
|
|
irq_tab rd 16
|
|
|
|
|
|
|
|
MEM_FreeSpace rd 1
|
|
|
|
|
|
|
|
ipc_tmp rd 1
|
|
|
|
ipc_pdir rd 1
|
|
|
|
ipc_ptab rd 1
|
|
|
|
|
|
|
|
proc_mem_map rd 1
|
|
|
|
proc_mem_pdir rd 1
|
|
|
|
proc_mem_tab rd 1
|
|
|
|
|
|
|
|
tmp_task_pdir rd 1
|
|
|
|
tmp_task_ptab rd 1
|
|
|
|
|
|
|
|
fdd_buff rd 1
|
2006-11-20 10:06:00 +03:00
|
|
|
LFBSize rd 1
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2006-10-10 09:11:30 +04:00
|
|
|
stall_mcs rd 1
|
2006-10-06 10:09:41 +04:00
|
|
|
;;CPUID information
|
|
|
|
|
|
|
|
cpu_vendor rd 3
|
|
|
|
cpu_sign rd 1
|
|
|
|
cpu_info rd 1
|
|
|
|
|
2006-11-27 13:07:51 +03:00
|
|
|
;;;;; cursors data
|
|
|
|
|
|
|
|
align 16
|
|
|
|
cur_saved_data rb 4096
|
|
|
|
|
|
|
|
def_cursor rd 1
|
2006-12-12 00:48:12 +03:00
|
|
|
hw_cursor rd 1
|
2006-11-27 13:07:51 +03:00
|
|
|
|
|
|
|
scr_width rd 1
|
|
|
|
scr_height rd 1
|
|
|
|
|
|
|
|
cur_def_interl rd 1
|
|
|
|
cur_saved_base rd 1
|
|
|
|
cur_saved_interl rd 1
|
|
|
|
cur_saved_w rd 1
|
|
|
|
cur_saved_h rd 1
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
endg
|
|
|
|
|
|
|
|
uglobal
|
|
|
|
align 16
|
2007-02-17 13:09:23 +03:00
|
|
|
fpu_data:
|
|
|
|
rb 512
|
2006-12-02 11:18:48 +03:00
|
|
|
|
2007-01-17 07:43:21 +03:00
|
|
|
mst MEM_STATE
|
|
|
|
|
2006-12-02 11:18:48 +03:00
|
|
|
mem_block_map rb 512
|
2007-02-16 07:16:52 +03:00
|
|
|
event_map rb 64
|
2006-12-02 11:18:48 +03:00
|
|
|
mem_block_list rd 64
|
|
|
|
mem_block_mask rd 2
|
|
|
|
|
2007-01-18 05:06:00 +03:00
|
|
|
srv.fd rd 1
|
|
|
|
srv.bk rd 1
|
2006-10-06 10:09:41 +04:00
|
|
|
|
2007-02-17 13:09:23 +03:00
|
|
|
mem_used.fd rd 1
|
|
|
|
mem_used.bk rd 1
|
|
|
|
|
2006-10-06 10:09:41 +04:00
|
|
|
mem_block_arr rd 1
|
|
|
|
mem_block_start rd 1
|
|
|
|
mem_block_end rd 1
|
2007-01-18 10:31:56 +03:00
|
|
|
|
|
|
|
heap_mutex rd 1
|
2006-10-08 11:48:38 +04:00
|
|
|
heap_size rd 1
|
|
|
|
heap_free rd 1
|
|
|
|
heap_blocks rd 1
|
|
|
|
free_blocks rd 1
|
2006-10-06 10:09:41 +04:00
|
|
|
|
|
|
|
page_start rd 1
|
|
|
|
page_end rd 1
|
2006-12-02 11:18:48 +03:00
|
|
|
events rd 1
|
|
|
|
event_start rd 1
|
|
|
|
event_end rd 1
|
2007-02-16 07:16:52 +03:00
|
|
|
event_uid rd 1
|
2006-10-06 10:09:41 +04:00
|
|
|
sys_page_map rd 1
|
2007-02-17 13:09:23 +03:00
|
|
|
os_stack rd 1
|
2006-10-06 10:09:41 +04:00
|
|
|
endg
|
|
|
|
|
2007-02-08 04:02:14 +03:00
|
|
|
if 0
|
|
|
|
push eax
|
|
|
|
push edx
|
|
|
|
mov edx, 0x400 ;bocsh
|
|
|
|
mov al,0xff ;bocsh
|
|
|
|
out dx, al ;bocsh
|
|
|
|
pop edx
|
|
|
|
pop eax
|
|
|
|
end if
|
2006-12-17 09:22:59 +03:00
|
|
|
|
|
|
|
align 4
|
|
|
|
k_strrchr:
|
|
|
|
push eax
|
|
|
|
xor eax,eax
|
|
|
|
or ecx,-1
|
|
|
|
repne scasb
|
|
|
|
add ecx,1
|
|
|
|
neg ecx
|
|
|
|
sub edi,1
|
|
|
|
pop eax
|
|
|
|
std
|
|
|
|
repne scasb
|
|
|
|
cld
|
|
|
|
add edi,1
|
|
|
|
|
|
|
|
cmp [edi],al
|
|
|
|
jne @F
|
|
|
|
mov eax,edi
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
xor eax,eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc k_strncpy stdcall, dest:dword, src:dword, maxlen:dword
|
|
|
|
mov eax, [dest]
|
|
|
|
mov esi, [src]
|
|
|
|
mov ecx, [maxlen]
|
|
|
|
test eax, eax
|
|
|
|
jz .L9
|
|
|
|
test esi, esi
|
|
|
|
jz .L9
|
|
|
|
test ecx, ecx
|
|
|
|
jz .L9
|
|
|
|
|
|
|
|
sub esi, eax
|
|
|
|
jmp .L1
|
|
|
|
|
|
|
|
align 4
|
|
|
|
.L2:
|
|
|
|
mov edx, [esi+eax]
|
|
|
|
mov [eax], dl
|
|
|
|
test dl, dl
|
|
|
|
jz .L7
|
|
|
|
|
|
|
|
mov [eax+1], dh
|
|
|
|
test dh, dh
|
|
|
|
jz .L6
|
|
|
|
|
|
|
|
shr edx, 16
|
|
|
|
mov [eax+2],dl
|
|
|
|
test dl, dl
|
|
|
|
jz .L5
|
|
|
|
|
|
|
|
mov [eax+3], dh
|
|
|
|
test dh, dh
|
|
|
|
jz .L4
|
|
|
|
add eax, 4
|
|
|
|
.L1:
|
|
|
|
sub ecx, 4
|
|
|
|
jae .L2
|
|
|
|
|
|
|
|
add ecx, 4
|
|
|
|
jz .L9
|
|
|
|
|
|
|
|
mov dl, [eax+esi]
|
|
|
|
mov [eax], dl
|
|
|
|
test dl, dl
|
|
|
|
jz .L3
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
dec ecx
|
|
|
|
jz .L9
|
|
|
|
|
|
|
|
mov dl, [eax+esi]
|
|
|
|
mov [eax], dl
|
|
|
|
test dl, dl
|
|
|
|
jz .L3
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
dec ecx
|
|
|
|
jz .L9
|
|
|
|
|
|
|
|
mov dl, [eax+esi]
|
|
|
|
mov [eax], dl
|
|
|
|
test dl, dl
|
|
|
|
jz .L3
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
jmp .L9
|
|
|
|
|
|
|
|
.L4: dec ecx
|
|
|
|
inc eax
|
|
|
|
|
|
|
|
.L5: dec ecx
|
|
|
|
inc eax
|
|
|
|
|
|
|
|
.L6: dec ecx
|
|
|
|
inc eax
|
|
|
|
.L7:
|
|
|
|
add ecx,3
|
|
|
|
jz .L9
|
|
|
|
.L8:
|
|
|
|
mov byte [ecx+eax], 0
|
|
|
|
.L3:
|
|
|
|
dec ecx
|
|
|
|
jnz .L8
|
|
|
|
.L9:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
if 0
|
|
|
|
|
|
|
|
magic equ 0xfefefeff
|
|
|
|
|
|
|
|
k_strlen:
|
|
|
|
mov eax,[esp+4]
|
|
|
|
mov edx, 3
|
|
|
|
|
|
|
|
and edx, eax
|
|
|
|
jz .L1
|
|
|
|
jp .L0
|
|
|
|
|
|
|
|
cmp dh, byte [eax]
|
|
|
|
je .L2
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
cmp dh, byte [eax]
|
|
|
|
|
|
|
|
je .L2
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
xor edx, 2
|
|
|
|
|
|
|
|
jz .L1
|
|
|
|
.L0:
|
|
|
|
cmp dh, [eax]
|
|
|
|
je .L2
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
xor edx, edx
|
|
|
|
|
|
|
|
.L1:
|
|
|
|
mov ecx, [eax]
|
|
|
|
add eax, 4
|
|
|
|
|
|
|
|
sub edx, ecx
|
|
|
|
add ecx, magic
|
|
|
|
|
|
|
|
dec edx
|
|
|
|
jnc .L3
|
|
|
|
|
|
|
|
xor edx, ecx
|
|
|
|
and edx, not magic
|
|
|
|
jne .L3
|
|
|
|
|
|
|
|
mov ecx, [eax]
|
|
|
|
add eax, 4
|
|
|
|
|
|
|
|
sub edx, ecx
|
|
|
|
add ecx, magic
|
|
|
|
dec edx
|
|
|
|
jnc .L3
|
|
|
|
|
|
|
|
xor edx, ecx
|
|
|
|
and edx, not magic
|
|
|
|
jne .L3
|
|
|
|
|
|
|
|
mov ecx, [eax]
|
|
|
|
add eax, 4
|
|
|
|
|
|
|
|
sub edx, ecx
|
|
|
|
add ecx, magic
|
|
|
|
|
|
|
|
dec edx
|
|
|
|
jnc .L3
|
|
|
|
|
|
|
|
xor edx, ecx
|
|
|
|
|
|
|
|
and edx, not magic
|
|
|
|
jne .L3
|
|
|
|
|
|
|
|
mov ecx, [eax]
|
|
|
|
add eax, 4
|
|
|
|
|
|
|
|
sub edx, ecx
|
|
|
|
add ecx, magic
|
|
|
|
|
|
|
|
dec edx
|
|
|
|
jnc .L3
|
|
|
|
|
|
|
|
xor edx, ecx
|
|
|
|
|
|
|
|
and edx, not magic
|
|
|
|
je .L1
|
|
|
|
|
|
|
|
.L3: sub eax ,4
|
|
|
|
sub ecx, magic
|
|
|
|
|
|
|
|
cmp cl, 0
|
|
|
|
jz .L2
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
test ch, ch
|
|
|
|
jz .L2
|
|
|
|
|
|
|
|
shr ecx, 16
|
|
|
|
inc eax
|
|
|
|
|
|
|
|
cmp cl,0
|
|
|
|
jz .L2
|
|
|
|
|
|
|
|
inc eax
|
|
|
|
|
|
|
|
.L2:
|
|
|
|
sub eax, [esp+4]
|
|
|
|
ret
|
|
|
|
|
|
|
|
end if
|