2007-03-26 14:18:08 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; ;;
|
2008-12-28 22:21:41 +01:00
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
|
2007-03-26 14:18:08 +02:00
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
|
;; ;;
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
2007-07-27 15:52:03 +02:00
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
align 4
|
|
|
|
|
proc alloc_page
|
|
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
|
cli
|
2007-10-20 19:11:22 +02:00
|
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov ebx, [page_start]
|
|
|
|
|
mov ecx, [page_end]
|
|
|
|
|
.l1:
|
|
|
|
|
bsf eax,[ebx];
|
|
|
|
|
jnz .found
|
|
|
|
|
add ebx,4
|
|
|
|
|
cmp ebx, ecx
|
|
|
|
|
jb .l1
|
2007-10-20 19:11:22 +02:00
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
popfd
|
|
|
|
|
xor eax,eax
|
|
|
|
|
ret
|
|
|
|
|
.found:
|
|
|
|
|
btr [ebx], eax
|
|
|
|
|
mov [page_start],ebx
|
|
|
|
|
sub ebx, sys_pgmap
|
2006-12-29 08:12:27 +01:00
|
|
|
|
lea eax, [eax+ebx*8]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
shl eax, 12
|
|
|
|
|
dec [pg_data.pages_free]
|
2007-10-20 19:11:22 +02:00
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
popfd
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc alloc_pages stdcall, count:dword
|
|
|
|
|
pushfd
|
2007-10-20 19:11:22 +02:00
|
|
|
|
push ebx
|
|
|
|
|
push edi
|
2006-10-06 08:09:41 +02:00
|
|
|
|
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
|
2007-10-20 19:11:22 +02:00
|
|
|
|
.fail:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
popfd
|
|
|
|
|
ret
|
|
|
|
|
.next:
|
|
|
|
|
inc ecx
|
|
|
|
|
cmp ecx, ebx
|
|
|
|
|
jb .find
|
2007-10-20 19:11:22 +02:00
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
popfd
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
|
|
|
|
.ok:
|
|
|
|
|
sub ecx, edi
|
|
|
|
|
inc ecx
|
2007-10-21 04:16:16 +02:00
|
|
|
|
push esi
|
2006-10-06 08:09:41 +02:00
|
|
|
|
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
|
2007-10-21 04:16:16 +02:00
|
|
|
|
pop esi
|
2007-10-20 19:11:22 +02:00
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
popfd
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
|
2007-02-05 15:20:36 +01:00
|
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, [phis_addr]
|
|
|
|
|
and eax, not 0xFFF
|
|
|
|
|
or eax, [flags]
|
|
|
|
|
mov ebx, [lin_addr]
|
|
|
|
|
shr ebx, 12
|
2007-02-20 13:05:24 +01:00
|
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, [lin_addr]
|
|
|
|
|
invlpg [eax]
|
2007-02-05 15:20:36 +01:00
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
2007-01-19 04:58:46 +01:00
|
|
|
|
align 4
|
|
|
|
|
map_space: ;not implemented
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
align 4
|
|
|
|
|
proc free_page
|
|
|
|
|
;arg: eax page address
|
|
|
|
|
pushfd
|
|
|
|
|
cli
|
2008-07-04 22:44:53 +02:00
|
|
|
|
shr eax, 12 ;page index
|
|
|
|
|
bts dword [sys_pgmap], eax ;that's all!
|
2007-01-23 15:55:03 +01:00
|
|
|
|
cmc
|
2007-02-08 02:02:14 +01:00
|
|
|
|
adc [pg_data.pages_free], 0
|
2006-10-06 08:09:41 +02:00
|
|
|
|
shr eax, 3
|
2008-07-04 22:44:53 +02:00
|
|
|
|
and eax, not 3 ;dword offset from page_map
|
2007-04-02 16:29:39 +02:00
|
|
|
|
add eax, sys_pgmap
|
2006-10-06 08:09:41 +02:00
|
|
|
|
cmp [page_start], eax
|
|
|
|
|
ja @f
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
mov [page_start], eax
|
|
|
|
|
popfd
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
2008-02-16 09:46:57 +01:00
|
|
|
|
proc map_io_mem stdcall, base:dword, size:dword, flags:dword
|
|
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
|
push edi
|
|
|
|
|
mov eax, [size]
|
|
|
|
|
add eax, 4095
|
|
|
|
|
and eax, -4096
|
|
|
|
|
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]
|
|
|
|
|
@@:
|
|
|
|
|
mov [page_tabs+eax*4], edx
|
2008-07-04 22:44:53 +02:00
|
|
|
|
; push eax
|
|
|
|
|
; invlpg [ebx]
|
|
|
|
|
; pop eax
|
2008-02-16 09:46:57 +01:00
|
|
|
|
inc eax
|
|
|
|
|
add ebx, edi
|
|
|
|
|
add edx, edi
|
|
|
|
|
loop @B
|
|
|
|
|
|
|
|
|
|
pop eax
|
|
|
|
|
mov edx, [base]
|
|
|
|
|
and edx, 4095
|
|
|
|
|
add eax, edx
|
|
|
|
|
.fail:
|
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
2007-01-18 08:31:56 +01:00
|
|
|
|
; param
|
2007-02-08 02:02:14 +01:00
|
|
|
|
; eax= page base + page flags
|
2008-07-04 22:44:53 +02:00
|
|
|
|
; ebx= linear address
|
2007-01-19 04:58:46 +01:00
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
|
|
align 4
|
2007-02-08 02:02:14 +01:00
|
|
|
|
commit_pages:
|
2008-02-16 09:46:57 +01:00
|
|
|
|
push edi
|
2007-02-08 02:02:14 +01:00
|
|
|
|
test ecx, ecx
|
|
|
|
|
jz .fail
|
2007-01-19 04:58:46 +01:00
|
|
|
|
|
2007-02-08 02:02:14 +01: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 13:05:24 +01:00
|
|
|
|
mov [page_tabs+ebx*4], eax
|
2008-07-04 22:44:53 +02:00
|
|
|
|
; push eax
|
|
|
|
|
; invlpg [edi]
|
|
|
|
|
; pop eax
|
2007-02-08 02:02:14 +01:00
|
|
|
|
add edi, edx
|
|
|
|
|
add eax, edx
|
|
|
|
|
inc ebx
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz @B
|
|
|
|
|
mov [pg_data.pg_mutex],ecx
|
|
|
|
|
.fail:
|
2008-02-16 09:46:57 +01:00
|
|
|
|
pop edi
|
2007-01-19 04:58:46 +01:00
|
|
|
|
ret
|
|
|
|
|
|
2007-02-08 02:02:14 +01:00
|
|
|
|
|
2007-01-19 04:58:46 +01:00
|
|
|
|
; param
|
2007-01-18 08:31:56 +01:00
|
|
|
|
; eax= base
|
2007-01-19 04:58:46 +01:00
|
|
|
|
; ecx= count
|
2007-01-18 08:31:56 +01:00
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
release_pages:
|
2007-02-05 15:20:36 +01:00
|
|
|
|
|
|
|
|
|
pushad
|
2007-01-18 08:31:56 +01:00
|
|
|
|
mov ebx, pg_data.pg_mutex
|
|
|
|
|
call wait_mutex ;ebx
|
|
|
|
|
|
|
|
|
|
mov esi, eax
|
|
|
|
|
mov edi, eax
|
|
|
|
|
|
|
|
|
|
shr esi, 10
|
2007-02-20 13:05:24 +01:00
|
|
|
|
add esi, page_tabs
|
2007-02-08 02:02:14 +01:00
|
|
|
|
|
|
|
|
|
mov ebp, [pg_data.pages_free]
|
2007-01-18 08:31:56 +01:00
|
|
|
|
mov ebx, [page_start]
|
|
|
|
|
mov edx, sys_pgmap
|
|
|
|
|
@@:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
xchg eax, [esi]
|
2008-11-17 13:04:16 +01:00
|
|
|
|
push eax
|
2007-01-18 08:31:56 +01:00
|
|
|
|
invlpg [edi]
|
2008-11-17 13:04:16 +01:00
|
|
|
|
pop eax
|
2007-01-18 08:31:56 +01:00
|
|
|
|
|
|
|
|
|
test eax, 1
|
|
|
|
|
jz .next
|
|
|
|
|
|
|
|
|
|
shr eax, 12
|
|
|
|
|
bts [edx], eax
|
2007-01-23 15:55:03 +01:00
|
|
|
|
cmc
|
2007-02-08 02:02:14 +01:00
|
|
|
|
adc ebp, 0
|
2007-01-18 08:31:56 +01: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 02:02:14 +01:00
|
|
|
|
mov [pg_data.pages_free], ebp
|
2007-01-18 08:31:56 +01:00
|
|
|
|
and [pg_data.pg_mutex],0
|
2007-02-05 15:20:36 +01:00
|
|
|
|
popad
|
2007-01-18 08:31:56 +01:00
|
|
|
|
ret
|
|
|
|
|
|
2008-07-04 22:44:53 +02:00
|
|
|
|
; param
|
|
|
|
|
; eax= base
|
|
|
|
|
; ecx= count
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
unmap_pages:
|
|
|
|
|
|
|
|
|
|
push edi
|
|
|
|
|
|
|
|
|
|
mov edi, eax
|
|
|
|
|
mov edx, eax
|
|
|
|
|
|
|
|
|
|
shr edi, 10
|
|
|
|
|
add edi, page_tabs
|
|
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
|
@@:
|
|
|
|
|
stosd
|
|
|
|
|
invlpg [edx]
|
|
|
|
|
add edx, 0x1000
|
|
|
|
|
loop @b
|
|
|
|
|
|
|
|
|
|
pop edi
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
align 4
|
2006-10-20 16:02:26 +02:00
|
|
|
|
proc map_page_table stdcall, lin_addr:dword, phis_addr:dword
|
2007-02-05 15:20:36 +01:00
|
|
|
|
push ebx
|
2006-10-06 08:09:41 +02: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 12:47:52 +01:00
|
|
|
|
mov dword [master_tab+ebx*4], eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, [lin_addr]
|
|
|
|
|
shr eax, 10
|
2007-02-20 13:05:24 +01:00
|
|
|
|
add eax, page_tabs
|
2006-10-06 08:09:41 +02:00
|
|
|
|
invlpg [eax]
|
2007-02-05 15:20:36 +01:00
|
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc init_LFB
|
2007-02-27 12:47:52 +01:00
|
|
|
|
locals
|
|
|
|
|
pg_count dd ?
|
|
|
|
|
endl
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
cmp dword [LFBAddress], -1
|
|
|
|
|
jne @f
|
2007-03-10 17:04:35 +01:00
|
|
|
|
mov [BOOT_VAR+0x901c],byte 2
|
2006-10-06 08:09:41 +02:00
|
|
|
|
stdcall kernel_alloc, 0x280000
|
|
|
|
|
mov [LFBAddress], eax
|
|
|
|
|
ret
|
|
|
|
|
@@:
|
|
|
|
|
test [SCR_MODE],word 0100000000000000b
|
2006-11-16 06:47:31 +01:00
|
|
|
|
jnz @f
|
2007-03-10 17:04:35 +01:00
|
|
|
|
mov [BOOT_VAR+0x901c],byte 2
|
2006-11-16 06:47:31 +01:00
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
|
@@:
|
2007-05-14 06:27:51 +02:00
|
|
|
|
call init_mtrr
|
|
|
|
|
|
2007-02-27 12:47:52 +01:00
|
|
|
|
mov edx, LFB_BASE
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov esi, [LFBAddress]
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov edi, 0x00800000
|
2007-02-28 09:52:06 +01:00
|
|
|
|
mov dword [exp_lfb+4], edx
|
2006-11-20 08:06:00 +01:00
|
|
|
|
|
2006-10-06 08:09:41 +02: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-04-18 08:37:14 +02:00
|
|
|
|
mov edx, sys_pgdir+(LFB_BASE shr 20)
|
2006-10-06 08:09:41 +02:00
|
|
|
|
@@:
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov [edx], esi
|
2007-02-27 12:47:52 +01:00
|
|
|
|
add edx, 4
|
2006-10-06 08:09:41 +02:00
|
|
|
|
add esi, 0x00400000
|
|
|
|
|
dec edi
|
|
|
|
|
jnz @B
|
|
|
|
|
|
2006-11-03 17:26:10 +01:00
|
|
|
|
bt [cpu_caps], CAPS_PGE
|
|
|
|
|
jnc @F
|
2007-04-18 08:37:14 +02:00
|
|
|
|
or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL
|
2006-11-03 17:26:10 +01:00
|
|
|
|
@@:
|
2007-02-27 12:47:52 +01:00
|
|
|
|
mov dword [LFBAddress], LFB_BASE
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, cr3 ;flush TLB
|
|
|
|
|
mov cr3, eax
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.map_page_tables:
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
@@:
|
2006-10-06 08:09:41 +02:00
|
|
|
|
call alloc_page
|
2007-02-27 12:47:52 +01:00
|
|
|
|
stdcall map_page_table, edx, eax
|
2007-03-05 22:37:28 +01:00
|
|
|
|
add edx, 0x00400000
|
2006-10-06 08:09:41 +02:00
|
|
|
|
dec edi
|
2007-04-18 08:37:14 +02:00
|
|
|
|
jnz @B
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
mov eax, [LFBAddress]
|
2007-02-27 12:47:52 +01:00
|
|
|
|
mov edi, page_tabs + (LFB_BASE shr 10)
|
2006-10-06 08:09:41 +02:00
|
|
|
|
or eax, PG_UW
|
|
|
|
|
mov ecx, [pg_count]
|
2007-02-27 12:47:52 +01:00
|
|
|
|
cld
|
2007-03-05 22:37:28 +01:00
|
|
|
|
@@:
|
|
|
|
|
stosd
|
|
|
|
|
add eax, 0x1000
|
|
|
|
|
dec ecx
|
|
|
|
|
jnz @B
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
2007-02-27 12:47:52 +01:00
|
|
|
|
mov dword [LFBAddress], LFB_BASE
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, cr3 ;flush TLB
|
|
|
|
|
mov cr3, eax
|
|
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
proc new_mem_resize stdcall, new_size:dword
|
|
|
|
|
|
2007-01-17 05:43:21 +01:00
|
|
|
|
mov ebx, pg_data.pg_mutex
|
|
|
|
|
call wait_mutex ;ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
mov edi, [new_size]
|
|
|
|
|
add edi,4095
|
|
|
|
|
and edi,not 4095
|
|
|
|
|
mov [new_size], edi
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov edx,[current_slot]
|
|
|
|
|
cmp [edx+APPDATA.heap_base],0
|
2006-10-10 07:11:30 +02:00
|
|
|
|
jne .exit
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov esi, [edx+APPDATA.mem_size]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
add esi, 4095
|
|
|
|
|
and esi, not 4095
|
|
|
|
|
|
|
|
|
|
cmp edi, esi
|
|
|
|
|
jae .expand
|
|
|
|
|
|
|
|
|
|
shr edi, 12
|
|
|
|
|
shr esi, 12
|
|
|
|
|
@@:
|
2007-02-27 12:47:52 +01:00
|
|
|
|
mov eax, [app_page_tabs+edi*4]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
test eax, 1
|
|
|
|
|
jz .next
|
2007-02-27 12:47:52 +01:00
|
|
|
|
mov dword [app_page_tabs+edi*4], 2
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov ebx, edi
|
|
|
|
|
shl ebx, 12
|
2008-11-17 13:04:16 +01:00
|
|
|
|
push eax
|
2007-10-20 15:07:32 +02:00
|
|
|
|
invlpg [ebx]
|
2008-11-17 13:04:16 +01:00
|
|
|
|
pop eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
call free_page
|
|
|
|
|
|
|
|
|
|
.next: add edi, 1
|
|
|
|
|
cmp edi, esi
|
|
|
|
|
jb @B
|
|
|
|
|
|
|
|
|
|
.update_size:
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov ebx, [new_size]
|
|
|
|
|
call update_mem_size
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
|
dec [pg_data.pg_mutex]
|
|
|
|
|
ret
|
|
|
|
|
.expand:
|
|
|
|
|
|
|
|
|
|
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
|
2009-06-04 21:43:17 +02:00
|
|
|
|
jz .exit_pop
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
|
stdcall map_page_table, edi, eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
push edi
|
|
|
|
|
shr edi, 10
|
2007-02-20 13:05:24 +01:00
|
|
|
|
add edi, page_tabs
|
2006-10-06 08:09:41 +02: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 14:42:23 +01:00
|
|
|
|
jb @B
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
jmp .update_size
|
2009-06-04 21:43:17 +02:00
|
|
|
|
.exit_pop:
|
|
|
|
|
pop edi
|
|
|
|
|
pop esi
|
2006-10-06 08:09:41 +02:00
|
|
|
|
.exit:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
inc eax
|
|
|
|
|
dec [pg_data.pg_mutex]
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
2007-01-25 14:42:23 +01:00
|
|
|
|
update_mem_size:
|
2007-04-18 08:37:14 +02:00
|
|
|
|
; in: edx = slot base
|
2007-01-25 14:42:23 +01:00
|
|
|
|
; ebx = new memory size
|
|
|
|
|
; destroys eax,ecx,edx
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov [APPDATA.mem_size+edx],ebx
|
2007-01-25 14:42:23 +01:00
|
|
|
|
;search threads and update
|
|
|
|
|
;application memory size infomation
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov ecx,[APPDATA.dir_table+edx]
|
2007-01-25 14:42:23 +01: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 11:51:05 +01:00
|
|
|
|
cmp [SLOT_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread?
|
2007-01-25 14:42:23 +01:00
|
|
|
|
jnz .search_threads_next
|
2007-02-28 11:51:05 +01:00
|
|
|
|
mov [SLOT_BASE+edx+APPDATA.mem_size],ebx ;update memory size
|
2007-01-25 14:42:23 +01:00
|
|
|
|
.search_threads_next:
|
|
|
|
|
inc eax
|
|
|
|
|
jmp .search_threads
|
|
|
|
|
.search_threads_end:
|
|
|
|
|
ret
|
|
|
|
|
|
2007-01-20 08:48:13 +01:00
|
|
|
|
; param
|
|
|
|
|
; eax= linear address
|
|
|
|
|
;
|
|
|
|
|
; retval
|
|
|
|
|
; eax= phisical page address
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
align 4
|
2007-01-20 08:48:13 +01:00
|
|
|
|
get_pg_addr:
|
|
|
|
|
shr eax, 12
|
2007-02-20 13:05:24 +01:00
|
|
|
|
mov eax, [page_tabs+eax*4]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
ret
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
|
align 4
|
2009-04-04 21:58:42 +02:00
|
|
|
|
; Now it is called from sys32::exc_c (see stack frame there)
|
2006-10-06 08:09:41 +02:00
|
|
|
|
proc page_fault_handler
|
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
.err_addr equ ebp-4
|
2008-02-04 16:31:59 +01:00
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
mov ebp, esp
|
|
|
|
|
mov ebx, cr2
|
|
|
|
|
push ebx ; that is locals: .err_addr = cr2
|
|
|
|
|
inc [pg_data.pages_faults]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
; push eax
|
|
|
|
|
; push edx
|
|
|
|
|
; mov edx, 0x400 ;bochs
|
|
|
|
|
; mov al,0xff ;bochs
|
|
|
|
|
; out dx, al ;bochs
|
|
|
|
|
; pop edx
|
|
|
|
|
; pop eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
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
|
2009-05-29 18:09:05 +02:00
|
|
|
|
push 14 ;#PF
|
|
|
|
|
pop ebx
|
2009-04-04 21:58:42 +02:00
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
.user_space:
|
2009-04-04 21:58:42 +02:00
|
|
|
|
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>
|
2006-10-20 16:02:26 +02:00
|
|
|
|
.alloc:
|
2009-04-04 21:58:42 +02:00
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
stdcall map_page,[.err_addr],eax,dword PG_UW
|
|
|
|
|
|
|
|
|
|
mov edi, [.err_addr]
|
|
|
|
|
and edi, 0xFFFFF000
|
|
|
|
|
mov ecx, 1024
|
|
|
|
|
xor eax, eax
|
|
|
|
|
;cld ;caller is duty for this
|
|
|
|
|
rep stosd
|
|
|
|
|
.exit: ;iret with repeat fault instruction
|
|
|
|
|
add esp,8 ; clear in stack: locals(.err_addr) + ret_to_caller
|
|
|
|
|
restore_ring3_context
|
|
|
|
|
iretd
|
|
|
|
|
|
|
|
|
|
.err_access = .fail
|
2007-04-18 08:37:14 +02:00
|
|
|
|
;<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-04-04 21:58:42 +02:00
|
|
|
|
;jmp .fail
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
|
|
.kernel_space:
|
2009-04-04 21:58:42 +02:00
|
|
|
|
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>
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
test eax,12 ;U/S (+below)
|
|
|
|
|
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
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
|
|
;<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>
|
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
cmp ebx, tss._io_map_0
|
|
|
|
|
jb .fail
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
cmp ebx, tss._io_map_0+8192
|
|
|
|
|
jae .fail
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
|
|
; io permission map
|
|
|
|
|
; copy-on-write protection
|
|
|
|
|
|
2009-04-04 21:58:42 +02:00
|
|
|
|
call alloc_page
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
push eax
|
|
|
|
|
stdcall map_page,[.err_addr],eax,dword PG_SW
|
|
|
|
|
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
|
|
|
|
|
rep movsd
|
|
|
|
|
jmp .exit
|
2006-10-06 08:09:41 +02: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
|
|
|
|
|
|
2007-06-07 15:34:43 +02:00
|
|
|
|
stdcall map_page,[ipc_pdir],eax,PG_UW
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov ebx, [ofs]
|
|
|
|
|
shr ebx, 22
|
|
|
|
|
mov esi, [ipc_pdir]
|
|
|
|
|
mov edi, [ipc_ptab]
|
|
|
|
|
mov eax, [esi+ebx*4]
|
|
|
|
|
and eax, 0xFFFFF000
|
|
|
|
|
jz .exit
|
2007-06-07 15:34:43 +02:00
|
|
|
|
stdcall map_page,edi,eax,PG_UW
|
2006-10-06 08:09:41 +02:00
|
|
|
|
; 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
|
2007-06-07 15:34:43 +02:00
|
|
|
|
jz .exit
|
|
|
|
|
stdcall map_page,edi,eax,PG_UW
|
|
|
|
|
dec ecx
|
|
|
|
|
jz .exit
|
2006-10-06 08:09:41 +02:00
|
|
|
|
add edi, 0x1000
|
|
|
|
|
inc edx
|
2007-06-07 15:34:43 +02:00
|
|
|
|
cmp edx, 0x400
|
2006-10-06 08:09:41 +02:00
|
|
|
|
jnz .map
|
2007-06-07 15:34:43 +02:00
|
|
|
|
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
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
.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
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov eax,[current_slot]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
pushf
|
|
|
|
|
cli
|
2007-04-18 08:37:14 +02:00
|
|
|
|
mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area
|
|
|
|
|
mov [eax+APPDATA.ipc_size],ecx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
add ecx, ebx
|
|
|
|
|
add ecx, 4095
|
|
|
|
|
and ecx, not 4095
|
|
|
|
|
|
|
|
|
|
.touch: mov eax, [ebx]
|
|
|
|
|
add ebx, 0x1000
|
|
|
|
|
cmp ebx, ecx
|
2007-06-07 15:34:43 +02:00
|
|
|
|
jb .touch
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
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 ?
|
2007-06-07 15:34:43 +02:00
|
|
|
|
used_buf dd ?
|
2006-10-06 08:09:41 +02:00
|
|
|
|
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 11:51:05 +01:00
|
|
|
|
mov edi,[eax+SLOT_BASE+0xa0] ;is ipc area defined?
|
2006-10-06 08:09:41 +02:00
|
|
|
|
test edi,edi
|
|
|
|
|
jz .no_ipc_area
|
|
|
|
|
|
|
|
|
|
mov ebx, edi
|
|
|
|
|
and ebx, 0xFFF
|
|
|
|
|
mov [dst_offset], ebx
|
|
|
|
|
|
2007-02-28 11:51:05 +01:00
|
|
|
|
mov esi, [eax+SLOT_BASE+0xa4]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov [buf_size], esi
|
|
|
|
|
|
2007-06-07 15:34:43 +02:00
|
|
|
|
mov ecx, [ipc_tmp]
|
|
|
|
|
cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page
|
|
|
|
|
jbe @f
|
|
|
|
|
push eax esi edi
|
|
|
|
|
add esi,0x1000
|
|
|
|
|
stdcall alloc_kernel_space,esi
|
|
|
|
|
mov ecx, eax
|
|
|
|
|
pop edi esi eax
|
|
|
|
|
@@:
|
|
|
|
|
mov [used_buf], ecx
|
|
|
|
|
stdcall map_mem, ecx, [SLOT_BASE+eax+0xB8],\
|
2006-10-06 08:09:41 +02:00
|
|
|
|
edi, esi
|
|
|
|
|
|
|
|
|
|
mov edi, [dst_offset]
|
2007-06-07 15:34:43 +02:00
|
|
|
|
add edi, [used_buf]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
cmp dword [edi], 0
|
|
|
|
|
jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
2007-07-06 10:12:11 +02:00
|
|
|
|
mov edx, dword [edi+4]
|
|
|
|
|
lea ebx, [edx+8]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
add ebx, [msg_size]
|
|
|
|
|
cmp ebx, [buf_size]
|
|
|
|
|
ja .buffer_overflow ;esi<0 - not enough memory in buffer
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
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]
|
2007-04-18 08:37:14 +02:00
|
|
|
|
; add esi, new_app_base
|
2006-10-06 08:09:41 +02:00
|
|
|
|
cld
|
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
|
|
mov ebx, [ipc_tmp]
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
xor eax, eax
|
2007-02-20 13:05:24 +01:00
|
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
|
|
mov ebx, [ipc_pdir]
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
xor eax, eax
|
2007-02-20 13:05:24 +01:00
|
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
|
|
mov ebx, [ipc_ptab]
|
|
|
|
|
mov edx, ebx
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
xor eax, eax
|
2007-02-20 13:05:24 +01:00
|
|
|
|
mov [page_tabs+ebx*4], eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
invlpg [edx]
|
|
|
|
|
|
|
|
|
|
mov eax, [dst_slot]
|
|
|
|
|
shl eax, 8
|
2007-02-28 11:51:05 +01:00
|
|
|
|
or [eax+SLOT_BASE+0xA8],dword 0x40
|
2006-10-06 08:09:41 +02:00
|
|
|
|
cmp dword [check_idle_semaphore],20
|
|
|
|
|
jge .ipc_no_cis
|
|
|
|
|
|
|
|
|
|
mov dword [check_idle_semaphore],5
|
|
|
|
|
.ipc_no_cis:
|
2007-06-07 15:34:43 +02:00
|
|
|
|
push 0
|
|
|
|
|
jmp .ret
|
2006-10-06 08:09:41 +02:00
|
|
|
|
.no_pid:
|
|
|
|
|
popf
|
2007-06-07 15:34:43 +02:00
|
|
|
|
mov eax, 4
|
2006-10-06 08:09:41 +02:00
|
|
|
|
ret
|
|
|
|
|
.no_ipc_area:
|
|
|
|
|
popf
|
|
|
|
|
xor eax, eax
|
|
|
|
|
inc eax
|
|
|
|
|
ret
|
|
|
|
|
.ipc_blocked:
|
2007-06-07 15:34:43 +02:00
|
|
|
|
push 2
|
|
|
|
|
jmp .ret
|
2006-10-06 08:09:41 +02:00
|
|
|
|
.buffer_overflow:
|
2007-06-07 15:34:43 +02:00
|
|
|
|
push 3
|
|
|
|
|
.ret:
|
|
|
|
|
mov eax, [used_buf]
|
|
|
|
|
cmp eax, [ipc_tmp]
|
|
|
|
|
jz @f
|
|
|
|
|
stdcall free_kernel_space,eax
|
|
|
|
|
@@:
|
|
|
|
|
pop eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
popf
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
2006-10-08 09:48:38 +02:00
|
|
|
|
sysfn_meminfo:
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
2009-05-18 20:26:34 +02:00
|
|
|
|
; add ecx, new_app_base
|
|
|
|
|
cmp ecx, OS_BASE
|
2007-04-18 08:37:14 +02:00
|
|
|
|
jae .fail
|
2006-10-10 07:11:30 +02:00
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, [pg_data.pages_count]
|
2009-05-18 20:26:34 +02:00
|
|
|
|
mov [ecx], eax
|
2006-10-10 07:11:30 +02:00
|
|
|
|
shl eax, 12
|
2009-05-18 20:26:34 +02:00
|
|
|
|
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
|
2006-10-08 09:48:38 +02:00
|
|
|
|
mov eax, [heap_blocks]
|
2009-05-18 20:26:34 +02:00
|
|
|
|
mov [ecx+20], eax
|
|
|
|
|
mov eax, [free_blocks]
|
|
|
|
|
mov [ecx+24], eax
|
2006-10-10 07:11:30 +02:00
|
|
|
|
ret
|
|
|
|
|
.fail:
|
2009-05-18 20:26:34 +02:00
|
|
|
|
mov dword [esp+32], -1
|
2006-10-06 08:09:41 +02:00
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
align 4
|
2008-11-30 20:04:25 +01:00
|
|
|
|
f68call:
|
|
|
|
|
dd f68.11
|
|
|
|
|
dd f68.12
|
|
|
|
|
dd f68.13
|
|
|
|
|
dd f68.14
|
2009-05-23 10:23:03 +02:00
|
|
|
|
dd f68.fail ;moved to f68.24
|
2008-11-30 20:04:25 +01:00
|
|
|
|
dd f68.16
|
|
|
|
|
dd f68.17
|
2009-05-23 10:23:03 +02:00
|
|
|
|
dd f68.fail ;moved to f68.25
|
2008-11-30 20:04:25 +01:00
|
|
|
|
dd f68.19
|
|
|
|
|
dd f68.20
|
|
|
|
|
dd f68.21
|
|
|
|
|
dd f68.22
|
2008-12-04 07:04:21 +01:00
|
|
|
|
dd f68.23
|
2009-05-23 10:23:03 +02:00
|
|
|
|
dd f68.24
|
|
|
|
|
dd f68.25
|
2008-11-30 20:04:25 +01:00
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
f68:
|
2006-10-06 08:09:41 +02:00
|
|
|
|
cmp eax,4
|
|
|
|
|
jle sys_sheduler
|
|
|
|
|
|
2006-10-08 09:48:38 +02:00
|
|
|
|
cmp eax, 11
|
2006-10-06 08:09:41 +02:00
|
|
|
|
jb .fail
|
|
|
|
|
|
2009-05-23 10:23:03 +02:00
|
|
|
|
cmp eax, 25
|
2008-11-30 20:04:25 +01:00
|
|
|
|
ja .fail
|
|
|
|
|
|
|
|
|
|
jmp dword [f68call+eax*4-11*4]
|
|
|
|
|
.11:
|
2006-10-20 16:02:26 +02:00
|
|
|
|
call init_heap
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.12:
|
2006-10-06 08:09:41 +02:00
|
|
|
|
stdcall user_alloc, ebx
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.13:
|
2006-10-06 08:09:41 +02:00
|
|
|
|
stdcall user_free, ebx
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.14:
|
2007-04-18 08:37:14 +02:00
|
|
|
|
cmp ebx, OS_BASE
|
|
|
|
|
jae .fail
|
2009-03-28 19:36:41 +01:00
|
|
|
|
mov edi,ebx
|
|
|
|
|
call get_event_ex
|
2006-12-02 09:18:48 +01:00
|
|
|
|
mov [esp+36], eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
ret
|
2009-05-23 10:23:03 +02:00
|
|
|
|
.24:
|
2009-05-22 10:55:09 +02:00
|
|
|
|
mov eax, [current_slot]
|
|
|
|
|
xchg ebx, [eax+APPDATA.exc_handler]
|
|
|
|
|
xchg ecx, [eax+APPDATA.except_mask]
|
|
|
|
|
mov [esp+36], ebx ; reg_eax+8
|
|
|
|
|
mov [esp+24], ecx ; reg_ebx+8
|
2006-10-06 08:09:41 +02:00
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.16:
|
2006-10-20 16:02:26 +02:00
|
|
|
|
test ebx, ebx
|
|
|
|
|
jz .fail
|
2007-04-18 08:37:14 +02:00
|
|
|
|
cmp ebx, OS_BASE
|
|
|
|
|
jae .fail
|
2006-10-06 08:09:41 +02:00
|
|
|
|
stdcall get_service, ebx
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.17:
|
2007-02-27 12:47:52 +01:00
|
|
|
|
call srv_handlerEx ;ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2009-05-23 10:23:03 +02:00
|
|
|
|
.25:
|
2009-05-25 12:29:59 +02:00
|
|
|
|
cmp ebx,32
|
|
|
|
|
jae .fail
|
2009-05-22 10:55:09 +02:00
|
|
|
|
mov eax, [current_slot]
|
|
|
|
|
btr [eax+APPDATA.except_mask],ebx
|
|
|
|
|
setc byte[esp+36]
|
|
|
|
|
jecxz @f
|
|
|
|
|
bts [eax+APPDATA.except_mask],ebx
|
|
|
|
|
@@: ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.19:
|
2007-04-18 08:37:14 +02:00
|
|
|
|
cmp ebx, OS_BASE
|
|
|
|
|
jae .fail
|
2006-10-27 17:08:19 +02:00
|
|
|
|
stdcall load_library, ebx
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.20:
|
2007-05-14 06:27:51 +02:00
|
|
|
|
mov eax, ecx
|
|
|
|
|
call user_realloc
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.21:
|
2008-02-15 17:15:47 +01:00
|
|
|
|
cmp ebx, OS_BASE
|
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
|
|
stdcall load_PE, ebx
|
|
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
|
|
|
|
|
|
|
|
|
mov esi, eax
|
|
|
|
|
stdcall eax, DRV_ENTRY
|
|
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz @F
|
|
|
|
|
|
|
|
|
|
mov [eax+SRV.entry], esi
|
|
|
|
|
|
|
|
|
|
@@:
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-11-30 20:04:25 +01:00
|
|
|
|
.22:
|
|
|
|
|
cmp ebx, OS_BASE
|
|
|
|
|
jae .fail
|
2008-02-15 17:15:47 +01:00
|
|
|
|
|
2008-11-30 20:04:25 +01:00
|
|
|
|
stdcall shmem_open, ebx, ecx, edx
|
|
|
|
|
mov [esp+28], edx
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
2008-02-15 17:15:47 +01:00
|
|
|
|
|
2008-12-04 07:04:21 +01:00
|
|
|
|
.23:
|
|
|
|
|
cmp ebx, OS_BASE
|
|
|
|
|
jae .fail
|
|
|
|
|
|
|
|
|
|
stdcall shmem_close, ebx
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
.fail:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
mov [esp+36], eax
|
|
|
|
|
ret
|
|
|
|
|
|
2008-07-04 22:44:53 +02:00
|
|
|
|
align 4
|
|
|
|
|
proc load_pe_driver stdcall, file:dword
|
|
|
|
|
|
|
|
|
|
stdcall load_PE, [file]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
mov esi, eax
|
|
|
|
|
stdcall eax, DRV_ENTRY
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
mov [eax+SRV.entry], esi
|
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
|
xor eax, eax
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
align 4
|
|
|
|
|
proc init_mtrr
|
|
|
|
|
|
2007-03-10 17:04:35 +01:00
|
|
|
|
cmp [BOOT_VAR+0x901c],byte 2
|
2006-10-06 08:09:41 +02:00
|
|
|
|
je .exit
|
|
|
|
|
|
2006-11-16 06:47:31 +01:00
|
|
|
|
bt [cpu_caps], CAPS_MTRR
|
|
|
|
|
jnc .exit
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov eax, cr0
|
|
|
|
|
or eax, 0x60000000 ;disable caching
|
|
|
|
|
mov cr0, eax
|
|
|
|
|
wbinvd ;invalidate cache
|
|
|
|
|
|
|
|
|
|
mov ecx, 0x2FF
|
|
|
|
|
rdmsr ;
|
2009-02-12 00:20:18 +01:00
|
|
|
|
; has BIOS already initialized MTRRs?
|
|
|
|
|
test ah, 8
|
|
|
|
|
jnz .skip_init
|
|
|
|
|
; rarely needed, so mainly placeholder
|
|
|
|
|
; main memory - cached
|
2006-10-06 08:09:41 +02:00
|
|
|
|
push eax
|
|
|
|
|
|
2008-07-09 23:46:35 +02:00
|
|
|
|
mov eax, [MEM_AMOUNT]
|
|
|
|
|
; round eax up to next power of 2
|
|
|
|
|
dec eax
|
|
|
|
|
bsr ecx, eax
|
2009-02-12 00:20:18 +01:00
|
|
|
|
mov ebx, 2
|
|
|
|
|
shl ebx, cl
|
|
|
|
|
dec ebx
|
|
|
|
|
; base of memory range = 0, type of memory range = MEM_WB
|
2006-10-06 08:09:41 +02:00
|
|
|
|
xor edx, edx
|
2009-02-12 00:20:18 +01:00
|
|
|
|
mov eax, MEM_WB
|
|
|
|
|
mov ecx, 0x200
|
|
|
|
|
wrmsr
|
|
|
|
|
; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1
|
|
|
|
|
mov eax, 0xFFFFFFFF
|
|
|
|
|
mov edx, 0x0000000F
|
|
|
|
|
sub eax, ebx
|
|
|
|
|
sbb edx, 0
|
|
|
|
|
or eax, 0x800
|
|
|
|
|
inc ecx
|
|
|
|
|
wrmsr
|
|
|
|
|
; clear unused MTRRs
|
2006-10-06 08:09:41 +02:00
|
|
|
|
xor eax, eax
|
2009-02-12 00:20:18 +01:00
|
|
|
|
xor edx, edx
|
2006-10-06 08:09:41 +02:00
|
|
|
|
@@:
|
|
|
|
|
wrmsr
|
|
|
|
|
inc ecx
|
2009-02-12 00:20:18 +01:00
|
|
|
|
cmp ecx, 0x210
|
|
|
|
|
jb @b
|
|
|
|
|
; enable MTRRs
|
2006-10-06 08:09:41 +02:00
|
|
|
|
pop eax
|
2009-02-12 00:20:18 +01:00
|
|
|
|
or ah, 8
|
|
|
|
|
and al, 0xF0 ; default memtype = UC
|
2006-10-06 08:09:41 +02:00
|
|
|
|
mov ecx, 0x2FF
|
2009-02-12 00:20:18 +01:00
|
|
|
|
wrmsr
|
|
|
|
|
.skip_init:
|
|
|
|
|
stdcall set_mtrr, [LFBAddress],[LFBSize],MEM_WC
|
|
|
|
|
|
|
|
|
|
wbinvd ;again invalidate
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
mov eax, cr0
|
|
|
|
|
and eax, not 0x60000000
|
|
|
|
|
mov cr0, eax ; enable caching
|
|
|
|
|
.exit:
|
|
|
|
|
ret
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
align 4
|
2009-02-12 00:20:18 +01:00
|
|
|
|
proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword
|
|
|
|
|
; find unused register
|
|
|
|
|
mov ecx, 0x201
|
|
|
|
|
@@:
|
|
|
|
|
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
|
|
|
|
|
; no free registers, ignore the call
|
|
|
|
|
.ret:
|
|
|
|
|
ret
|
|
|
|
|
.found:
|
|
|
|
|
; found, write values
|
2006-10-06 08:09:41 +02:00
|
|
|
|
xor edx, edx
|
|
|
|
|
mov eax, [base]
|
|
|
|
|
or eax, [mem_type]
|
|
|
|
|
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 07:11:30 +02: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
|
|
|
|
|
|
2007-05-24 09:36:48 +02:00
|
|
|
|
align 4
|
|
|
|
|
proc create_ring_buffer stdcall, size:dword, flags:dword
|
|
|
|
|
locals
|
|
|
|
|
buf_ptr dd ?
|
|
|
|
|
endl
|
|
|
|
|
|
|
|
|
|
mov eax, [size]
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
|
|
add eax, eax
|
|
|
|
|
stdcall alloc_kernel_space, eax
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .fail
|
|
|
|
|
|
2007-10-20 23:02:38 +02:00
|
|
|
|
push ebx
|
|
|
|
|
|
2007-05-24 09:36:48 +02:00
|
|
|
|
mov [buf_ptr], eax
|
|
|
|
|
|
|
|
|
|
mov ebx, [size]
|
|
|
|
|
shr ebx, 12
|
|
|
|
|
push ebx
|
|
|
|
|
|
|
|
|
|
stdcall alloc_pages, ebx
|
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
|
jz .mm_fail
|
|
|
|
|
|
2007-10-20 23:02:38 +02:00
|
|
|
|
push edi
|
|
|
|
|
|
2007-05-24 09:36:48 +02:00
|
|
|
|
or eax, [flags]
|
|
|
|
|
mov edi, [buf_ptr]
|
|
|
|
|
mov ebx, [buf_ptr]
|
|
|
|
|
mov edx, ecx
|
2007-07-06 10:12:11 +02:00
|
|
|
|
shl edx, 2
|
2007-05-24 09:36:48 +02:00
|
|
|
|
shr edi, 10
|
|
|
|
|
@@:
|
|
|
|
|
mov [page_tabs+edi], eax
|
|
|
|
|
mov [page_tabs+edi+edx], eax
|
2008-11-17 13:04:16 +01:00
|
|
|
|
invlpg [ebx]
|
|
|
|
|
invlpg [ebx+0x10000]
|
2007-05-24 09:36:48 +02:00
|
|
|
|
add eax, 0x1000
|
|
|
|
|
add ebx, 0x1000
|
2007-07-06 10:12:11 +02:00
|
|
|
|
add edi, 4
|
2007-05-24 09:36:48 +02:00
|
|
|
|
dec ecx
|
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
|
|
mov eax, [buf_ptr]
|
2007-10-20 23:02:38 +02:00
|
|
|
|
pop edi
|
|
|
|
|
pop ebx
|
2007-05-24 09:36:48 +02:00
|
|
|
|
ret
|
|
|
|
|
.mm_fail:
|
|
|
|
|
stdcall free_kernel_space, [buf_ptr]
|
|
|
|
|
xor eax, eax
|
2007-10-20 23:02:38 +02:00
|
|
|
|
pop ebx
|
2007-05-24 09:36:48 +02:00
|
|
|
|
.fail:
|
|
|
|
|
ret
|
|
|
|
|
endp
|