forked from KolibriOS/kolibrios
kernel: kolibri-process merged into trunk. This is my little gift to myself for my birthday.
git-svn-id: svn://kolibrios.org@5130 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
73dfca6a00
commit
76d618357e
@ -182,7 +182,7 @@ restart_kernel_4000:
|
|||||||
pop es
|
pop es
|
||||||
mov cx, 0x8000
|
mov cx, 0x8000
|
||||||
push cx
|
push cx
|
||||||
push 0x7000
|
push 0x7100
|
||||||
pop ds
|
pop ds
|
||||||
xor si, si
|
xor si, si
|
||||||
xor di, di
|
xor di, di
|
||||||
|
@ -219,7 +219,7 @@ TASK_ACTIVATE equ (OS_BASE+0x000FF01)
|
|||||||
|
|
||||||
TMP_STACK_TOP equ 0x006CC00
|
TMP_STACK_TOP equ 0x006CC00
|
||||||
|
|
||||||
sys_pgdir equ (OS_BASE+0x006F000)
|
sys_proc equ (OS_BASE+0x006F000)
|
||||||
|
|
||||||
SLOT_BASE equ (OS_BASE+0x0080000)
|
SLOT_BASE equ (OS_BASE+0x0080000)
|
||||||
|
|
||||||
@ -268,6 +268,8 @@ REG_EDI equ (RING0_STACK_SIZE-52)
|
|||||||
REG_RET equ (RING0_STACK_SIZE-56) ;irq0.return
|
REG_RET equ (RING0_STACK_SIZE-56) ;irq0.return
|
||||||
|
|
||||||
|
|
||||||
|
PAGE_SIZE equ 4096
|
||||||
|
|
||||||
PG_UNMAP equ 0x000
|
PG_UNMAP equ 0x000
|
||||||
PG_MAP equ 0x001
|
PG_MAP equ 0x001
|
||||||
PG_WRITE equ 0x002
|
PG_WRITE equ 0x002
|
||||||
|
@ -918,10 +918,9 @@ proc load_library stdcall, file_name:dword
|
|||||||
; ignore timestamp
|
; ignore timestamp
|
||||||
cli
|
cli
|
||||||
|
|
||||||
mov esi, [CURRENT_TASK]
|
mov esi, [current_process]
|
||||||
shl esi, 8
|
|
||||||
lea edi, [fullname]
|
lea edi, [fullname]
|
||||||
mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr]
|
mov ebx, [esi+PROC.dlls_list_ptr]
|
||||||
test ebx, ebx
|
test ebx, ebx
|
||||||
jz .not_in_process
|
jz .not_in_process
|
||||||
mov esi, [ebx+HDLL.fd]
|
mov esi, [ebx+HDLL.fd]
|
||||||
@ -1281,28 +1280,21 @@ endp
|
|||||||
; out: eax = APPDATA.dlls_list_ptr if all is OK,
|
; out: eax = APPDATA.dlls_list_ptr if all is OK,
|
||||||
; NULL if memory allocation failed
|
; NULL if memory allocation failed
|
||||||
init_dlls_in_thread:
|
init_dlls_in_thread:
|
||||||
mov ebx, [current_slot]
|
mov ebx, [current_process]
|
||||||
mov eax, [ebx+APPDATA.dlls_list_ptr]
|
mov eax, [ebx+PROC.dlls_list_ptr]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz .ret
|
jnz .ret
|
||||||
push [ebx+APPDATA.dir_table]
|
|
||||||
mov eax, 8
|
mov eax, 8
|
||||||
call malloc
|
call malloc ; FIXME
|
||||||
pop edx
|
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .ret
|
jz .ret
|
||||||
|
|
||||||
mov [eax], eax
|
mov [eax], eax
|
||||||
mov [eax+4], eax
|
mov [eax+4], eax
|
||||||
mov ecx, [TASK_COUNT]
|
|
||||||
mov ebx, SLOT_BASE+256
|
mov ebx, [current_process]
|
||||||
.set:
|
mov [ebx+PROC.dlls_list_ptr], eax
|
||||||
cmp [ebx+APPDATA.dir_table], edx
|
|
||||||
jnz @f
|
|
||||||
mov [ebx+APPDATA.dlls_list_ptr], eax
|
|
||||||
@@:
|
|
||||||
add ebx, 256
|
|
||||||
dec ecx
|
|
||||||
jnz .set
|
|
||||||
.ret:
|
.ret:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -1323,59 +1315,10 @@ dereference_dll:
|
|||||||
|
|
||||||
destroy_hdll:
|
destroy_hdll:
|
||||||
push ebx ecx esi edi
|
push ebx ecx esi edi
|
||||||
push eax
|
|
||||||
mov ebx, [eax+HDLL.base]
|
mov ebx, [eax+HDLL.base]
|
||||||
mov esi, [eax+HDLL.parent]
|
mov esi, [eax+HDLL.parent]
|
||||||
mov edx, [esi+DLLDESCR.size]
|
mov edx, [esi+DLLDESCR.size]
|
||||||
; The following actions require the context of application where HDLL is mapped.
|
|
||||||
; However, destroy_hdll can be called in the context of OS thread when
|
|
||||||
; cleaning up objects created by the application which is destroyed.
|
|
||||||
; So remember current cr3 and set it to page table of target.
|
|
||||||
mov eax, [ecx+APPDATA.dir_table]
|
|
||||||
; Because we cheat with cr3, disable interrupts: task switch would restore
|
|
||||||
; page table from APPDATA of current thread.
|
|
||||||
; Also set [current_slot] because it is used by user_free.
|
|
||||||
pushf
|
|
||||||
cli
|
|
||||||
push [current_slot]
|
|
||||||
mov [current_slot], ecx
|
|
||||||
mov ecx, cr3
|
|
||||||
push ecx
|
|
||||||
mov cr3, eax
|
|
||||||
push ebx ; argument for user_free
|
|
||||||
mov eax, ebx
|
|
||||||
shr ebx, 12
|
|
||||||
push ebx
|
|
||||||
mov esi, [esi+DLLDESCR.data]
|
|
||||||
shr esi, 12
|
|
||||||
.unmap_loop:
|
|
||||||
push eax
|
|
||||||
mov eax, 2
|
|
||||||
xchg eax, [page_tabs+ebx*4]
|
|
||||||
mov ecx, [page_tabs+esi*4]
|
|
||||||
and eax, not 0xFFF
|
|
||||||
and ecx, not 0xFFF
|
|
||||||
cmp eax, ecx
|
|
||||||
jz @f
|
|
||||||
call free_page
|
|
||||||
@@:
|
|
||||||
pop eax
|
|
||||||
invlpg [eax]
|
|
||||||
add eax, 0x1000
|
|
||||||
inc ebx
|
|
||||||
inc esi
|
|
||||||
sub edx, 0x1000
|
|
||||||
ja .unmap_loop
|
|
||||||
pop ebx
|
|
||||||
and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK
|
|
||||||
call user_free
|
|
||||||
; Restore context.
|
|
||||||
pop eax
|
|
||||||
mov cr3, eax
|
|
||||||
pop [current_slot]
|
|
||||||
popf
|
|
||||||
; Ok, cheating is done.
|
|
||||||
pop eax
|
|
||||||
push eax
|
push eax
|
||||||
mov esi, [eax+HDLL.parent]
|
mov esi, [eax+HDLL.parent]
|
||||||
mov eax, [eax+HDLL.refcount]
|
mov eax, [eax+HDLL.refcount]
|
||||||
|
@ -558,33 +558,36 @@ restore block_base
|
|||||||
restore block_size
|
restore block_size
|
||||||
restore block_flags
|
restore block_flags
|
||||||
|
|
||||||
;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;; USER HEAP ;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
HEAP_TOP equ 0x80000000
|
HEAP_TOP equ 0x80000000
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc init_heap
|
proc init_heap
|
||||||
|
|
||||||
mov ebx, [current_slot]
|
mov ebx, [current_process]
|
||||||
mov eax, [ebx+APPDATA.heap_top]
|
mov eax, [ebx+PROC.heap_top]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz @F
|
jz @F
|
||||||
sub eax, [ebx+APPDATA.heap_base]
|
sub eax, [ebx+PROC.heap_base]
|
||||||
sub eax, 4096
|
sub eax, PAGE_SIZE
|
||||||
ret
|
ret
|
||||||
@@:
|
@@:
|
||||||
mov esi, [ebx+APPDATA.mem_size]
|
lea ecx, [ebx+PROC.heap_lock]
|
||||||
|
call mutex_init
|
||||||
|
|
||||||
|
mov esi, [ebx+PROC.mem_used]
|
||||||
add esi, 4095
|
add esi, 4095
|
||||||
and esi, not 4095
|
and esi, not 4095
|
||||||
mov [ebx+APPDATA.mem_size], esi
|
mov [ebx+PROC.mem_used], esi
|
||||||
mov eax, HEAP_TOP
|
mov eax, HEAP_TOP
|
||||||
mov [ebx+APPDATA.heap_base], esi
|
mov [ebx+PROC.heap_base], esi
|
||||||
mov [ebx+APPDATA.heap_top], eax
|
mov [ebx+PROC.heap_top], eax
|
||||||
|
|
||||||
sub eax, esi
|
sub eax, esi
|
||||||
shr esi, 10
|
shr esi, 10
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
sub eax, 4096
|
sub eax, PAGE_SIZE
|
||||||
or ecx, FREE_BLOCK
|
or ecx, FREE_BLOCK
|
||||||
mov [page_tabs+esi], ecx
|
mov [page_tabs+esi], ecx
|
||||||
ret
|
ret
|
||||||
@ -597,25 +600,28 @@ proc user_alloc stdcall, alloc_size:dword
|
|||||||
push esi
|
push esi
|
||||||
push edi
|
push edi
|
||||||
|
|
||||||
|
mov ebx, [current_process]
|
||||||
|
lea ecx, [ebx+PROC.heap_lock]
|
||||||
|
call mutex_lock
|
||||||
|
|
||||||
mov ecx, [alloc_size]
|
mov ecx, [alloc_size]
|
||||||
add ecx, (4095+4096)
|
add ecx, (4095+PAGE_SIZE)
|
||||||
and ecx, not 4095
|
and ecx, not 4095
|
||||||
|
|
||||||
mov ebx, [current_slot]
|
mov esi, dword [ebx+PROC.heap_base] ; heap_base
|
||||||
mov esi, dword [ebx+APPDATA.heap_base] ; heap_base
|
mov edi, dword [ebx+PROC.heap_top] ; heap_top
|
||||||
mov edi, dword [ebx+APPDATA.heap_top] ; heap_top
|
.scan:
|
||||||
l_0:
|
|
||||||
cmp esi, edi
|
cmp esi, edi
|
||||||
jae m_exit
|
jae .m_exit
|
||||||
|
|
||||||
mov ebx, esi
|
mov ebx, esi
|
||||||
shr ebx, 12
|
shr ebx, 12
|
||||||
mov eax, [page_tabs+ebx*4]
|
mov eax, [page_tabs+ebx*4]
|
||||||
test al, FREE_BLOCK
|
test al, FREE_BLOCK
|
||||||
jz test_used
|
jz .test_used
|
||||||
and eax, 0xFFFFF000
|
and eax, 0xFFFFF000
|
||||||
cmp eax, ecx ;alloc_size
|
cmp eax, ecx ;alloc_size
|
||||||
jb m_next
|
jb .m_next
|
||||||
jz @f
|
jz @f
|
||||||
|
|
||||||
lea edx, [esi+ecx]
|
lea edx, [esi+ecx]
|
||||||
@ -637,12 +643,14 @@ l_0:
|
|||||||
jnz @B
|
jnz @B
|
||||||
.no:
|
.no:
|
||||||
|
|
||||||
mov edx, [current_slot]
|
mov edx, [current_process]
|
||||||
mov ebx, [alloc_size]
|
mov ebx, [alloc_size]
|
||||||
add ebx, 0xFFF
|
add ebx, 0xFFF
|
||||||
and ebx, not 0xFFF
|
and ebx, not 0xFFF
|
||||||
add ebx, [edx+APPDATA.mem_size]
|
add [edx+PROC.mem_used], ebx
|
||||||
call update_mem_size
|
|
||||||
|
lea ecx, [edx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
|
|
||||||
lea eax, [esi+4096]
|
lea eax, [esi+4096]
|
||||||
|
|
||||||
@ -650,15 +658,19 @@ l_0:
|
|||||||
pop esi
|
pop esi
|
||||||
pop ebx
|
pop ebx
|
||||||
ret
|
ret
|
||||||
test_used:
|
.test_used:
|
||||||
test al, USED_BLOCK
|
test al, USED_BLOCK
|
||||||
jz m_exit
|
jz .m_exit
|
||||||
|
|
||||||
and eax, 0xFFFFF000
|
and eax, 0xFFFFF000
|
||||||
m_next:
|
.m_next:
|
||||||
add esi, eax
|
add esi, eax
|
||||||
jmp l_0
|
jmp .scan
|
||||||
m_exit:
|
.m_exit:
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
@ -673,14 +685,17 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
|
|||||||
push esi
|
push esi
|
||||||
push edi
|
push edi
|
||||||
|
|
||||||
mov ebx, [current_slot]
|
mov ebx, [current_process]
|
||||||
|
lea ecx, [ebx+PROC.heap_lock]
|
||||||
|
call mutex_lock
|
||||||
|
|
||||||
mov edx, [address]
|
mov edx, [address]
|
||||||
and edx, not 0xFFF
|
and edx, not 0xFFF
|
||||||
mov [address], edx
|
mov [address], edx
|
||||||
sub edx, 0x1000
|
sub edx, 0x1000
|
||||||
jb .error
|
jb .error
|
||||||
mov esi, [ebx+APPDATA.heap_base]
|
mov esi, [ebx+PROC.heap_base]
|
||||||
mov edi, [ebx+APPDATA.heap_top]
|
mov edi, [ebx+PROC.heap_top]
|
||||||
cmp edx, esi
|
cmp edx, esi
|
||||||
jb .error
|
jb .error
|
||||||
.scan:
|
.scan:
|
||||||
@ -697,6 +712,10 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
|
|||||||
mov esi, ecx
|
mov esi, ecx
|
||||||
jmp .scan
|
jmp .scan
|
||||||
.error:
|
.error:
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
@ -748,13 +767,14 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
|
|||||||
mov [page_tabs+ebx*4], ecx
|
mov [page_tabs+ebx*4], ecx
|
||||||
|
|
||||||
.nothird:
|
.nothird:
|
||||||
|
mov edx, [current_process]
|
||||||
mov edx, [current_slot]
|
|
||||||
mov ebx, [alloc_size]
|
mov ebx, [alloc_size]
|
||||||
add ebx, 0xFFF
|
add ebx, 0xFFF
|
||||||
and ebx, not 0xFFF
|
and ebx, not 0xFFF
|
||||||
add ebx, [edx+APPDATA.mem_size]
|
add [edx+PROC.mem_used], ebx
|
||||||
call update_mem_size
|
|
||||||
|
lea ecx, [edx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
|
|
||||||
mov eax, [address]
|
mov eax, [address]
|
||||||
|
|
||||||
@ -771,10 +791,14 @@ proc user_free stdcall, base:dword
|
|||||||
|
|
||||||
mov esi, [base]
|
mov esi, [base]
|
||||||
test esi, esi
|
test esi, esi
|
||||||
jz .exit
|
jz .fail
|
||||||
|
|
||||||
push ebx
|
push ebx
|
||||||
|
|
||||||
|
mov ebx, [current_process]
|
||||||
|
lea ecx, [ebx+PROC.heap_lock]
|
||||||
|
call mutex_lock
|
||||||
|
|
||||||
xor ebx, ebx
|
xor ebx, ebx
|
||||||
shr esi, 12
|
shr esi, 12
|
||||||
mov eax, [page_tabs+(esi-1)*4]
|
mov eax, [page_tabs+(esi-1)*4]
|
||||||
@ -810,25 +834,30 @@ proc user_free stdcall, base:dword
|
|||||||
.released:
|
.released:
|
||||||
push edi
|
push edi
|
||||||
|
|
||||||
mov edx, [current_slot]
|
mov edx, [current_process]
|
||||||
mov esi, dword [edx+APPDATA.heap_base]
|
lea ecx, [edx+PROC.heap_lock]
|
||||||
mov edi, dword [edx+APPDATA.heap_top]
|
mov esi, dword [edx+PROC.heap_base]
|
||||||
sub ebx, [edx+APPDATA.mem_size]
|
mov edi, dword [edx+PROC.heap_top]
|
||||||
|
sub ebx, [edx+PROC.mem_used]
|
||||||
neg ebx
|
neg ebx
|
||||||
call update_mem_size
|
mov [edx+PROC.mem_used], ebx
|
||||||
call user_normalize
|
call user_normalize
|
||||||
pop edi
|
pop edi
|
||||||
pop ebx
|
|
||||||
pop esi
|
|
||||||
ret
|
|
||||||
.exit:
|
.exit:
|
||||||
|
call mutex_unlock
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
inc eax
|
inc eax
|
||||||
|
pop ebx
|
||||||
pop esi
|
pop esi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.cantfree:
|
.cantfree:
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
jmp .exit
|
||||||
|
.fail:
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
pop ebx
|
|
||||||
pop esi
|
pop esi
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
@ -957,6 +986,13 @@ user_realloc:
|
|||||||
ret
|
ret
|
||||||
@@:
|
@@:
|
||||||
push ecx edx
|
push ecx edx
|
||||||
|
|
||||||
|
push eax
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_lock
|
||||||
|
pop eax
|
||||||
|
|
||||||
lea ecx, [eax - 0x1000]
|
lea ecx, [eax - 0x1000]
|
||||||
shr ecx, 12
|
shr ecx, 12
|
||||||
mov edx, [page_tabs+ecx*4]
|
mov edx, [page_tabs+ecx*4]
|
||||||
@ -964,6 +1000,10 @@ user_realloc:
|
|||||||
jnz @f
|
jnz @f
|
||||||
; attempt to realloc invalid pointer
|
; attempt to realloc invalid pointer
|
||||||
.ret0:
|
.ret0:
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
|
|
||||||
pop edx ecx
|
pop edx ecx
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
ret
|
ret
|
||||||
@ -998,16 +1038,16 @@ user_realloc:
|
|||||||
jnz .nofreeall
|
jnz .nofreeall
|
||||||
mov eax, [page_tabs+ecx*4]
|
mov eax, [page_tabs+ecx*4]
|
||||||
and eax, not 0xFFF
|
and eax, not 0xFFF
|
||||||
mov edx, [current_slot]
|
mov edx, [current_process]
|
||||||
mov ebx, [APPDATA.mem_size+edx]
|
mov ebx, [edx+PROC.mem_used]
|
||||||
sub ebx, eax
|
sub ebx, eax
|
||||||
add ebx, 0x1000
|
add ebx, 0x1000
|
||||||
or al, FREE_BLOCK
|
or al, FREE_BLOCK
|
||||||
mov [page_tabs+ecx*4], eax
|
mov [page_tabs+ecx*4], eax
|
||||||
push esi edi
|
push esi edi
|
||||||
mov esi, [APPDATA.heap_base+edx]
|
mov esi, [edx+PROC.heap_base]
|
||||||
mov edi, [APPDATA.heap_top+edx]
|
mov edi, [edx+PROC.heap_top]
|
||||||
call update_mem_size
|
mov [edx+PROC.mem_used], ebx
|
||||||
call user_normalize
|
call user_normalize
|
||||||
pop edi esi
|
pop edi esi
|
||||||
jmp .ret0 ; all freed
|
jmp .ret0 ; all freed
|
||||||
@ -1019,11 +1059,11 @@ user_realloc:
|
|||||||
shr ebx, 12
|
shr ebx, 12
|
||||||
sub ebx, edx
|
sub ebx, edx
|
||||||
push ebx ecx edx
|
push ebx ecx edx
|
||||||
mov edx, [current_slot]
|
mov edx, [current_process]
|
||||||
shl ebx, 12
|
shl ebx, 12
|
||||||
sub ebx, [APPDATA.mem_size+edx]
|
sub ebx, [edx+PROC.mem_used]
|
||||||
neg ebx
|
neg ebx
|
||||||
call update_mem_size
|
mov [edx+PROC.mem_used], ebx
|
||||||
pop edx ecx ebx
|
pop edx ecx ebx
|
||||||
lea eax, [ecx+1]
|
lea eax, [ecx+1]
|
||||||
shl eax, 12
|
shl eax, 12
|
||||||
@ -1033,8 +1073,8 @@ user_realloc:
|
|||||||
shl ebx, 12
|
shl ebx, 12
|
||||||
jz .ret
|
jz .ret
|
||||||
push esi
|
push esi
|
||||||
mov esi, [current_slot]
|
mov esi, [current_process]
|
||||||
mov esi, [APPDATA.heap_top+esi]
|
mov esi, [esi+PROC.heap_top]
|
||||||
shr esi, 12
|
shr esi, 12
|
||||||
@@:
|
@@:
|
||||||
cmp edx, esi
|
cmp edx, esi
|
||||||
@ -1053,12 +1093,16 @@ user_realloc:
|
|||||||
or ebx, FREE_BLOCK
|
or ebx, FREE_BLOCK
|
||||||
mov [page_tabs+ecx*4], ebx
|
mov [page_tabs+ecx*4], ebx
|
||||||
.ret:
|
.ret:
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
pop eax edx ecx
|
pop eax edx ecx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.realloc_add:
|
.realloc_add:
|
||||||
; get some additional memory
|
; get some additional memory
|
||||||
mov eax, [current_slot]
|
mov eax, [current_process]
|
||||||
mov eax, [APPDATA.heap_top+eax]
|
mov eax, [eax+PROC.heap_top]
|
||||||
shr eax, 12
|
shr eax, 12
|
||||||
cmp edx, eax
|
cmp edx, eax
|
||||||
jae .cant_inplace
|
jae .cant_inplace
|
||||||
@ -1090,17 +1134,21 @@ user_realloc:
|
|||||||
cld
|
cld
|
||||||
rep stosd
|
rep stosd
|
||||||
pop edi
|
pop edi
|
||||||
mov edx, [current_slot]
|
mov edx, [current_process]
|
||||||
shl ebx, 12
|
shl ebx, 12
|
||||||
add ebx, [APPDATA.mem_size+edx]
|
add [edx+PROC.mem_used], ebx
|
||||||
call update_mem_size
|
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
pop eax edx ecx
|
pop eax edx ecx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.cant_inplace:
|
.cant_inplace:
|
||||||
push esi edi
|
push esi edi
|
||||||
mov eax, [current_slot]
|
mov eax, [current_process]
|
||||||
mov esi, [APPDATA.heap_base+eax]
|
mov esi, [eax+PROC.heap_base]
|
||||||
mov edi, [APPDATA.heap_top+eax]
|
mov edi, [eax+PROC.heap_top]
|
||||||
shr esi, 12
|
shr esi, 12
|
||||||
shr edi, 12
|
shr edi, 12
|
||||||
sub ebx, ecx
|
sub ebx, ecx
|
||||||
@ -1163,58 +1211,25 @@ user_realloc:
|
|||||||
jnz @b
|
jnz @b
|
||||||
.no:
|
.no:
|
||||||
push ebx
|
push ebx
|
||||||
mov edx, [current_slot]
|
mov edx, [current_process]
|
||||||
shl ebx, 12
|
shl ebx, 12
|
||||||
add ebx, [APPDATA.mem_size+edx]
|
add [edx+PROC.mem_used], ebx
|
||||||
call update_mem_size
|
|
||||||
pop ebx
|
pop ebx
|
||||||
@@:
|
@@:
|
||||||
mov dword [page_tabs+esi*4], 2
|
mov dword [page_tabs+esi*4], 2
|
||||||
inc esi
|
inc esi
|
||||||
dec ebx
|
dec ebx
|
||||||
jnz @b
|
jnz @b
|
||||||
|
|
||||||
|
mov ecx, [current_process]
|
||||||
|
lea ecx, [ecx+PROC.heap_lock]
|
||||||
|
call mutex_unlock
|
||||||
pop eax edi esi edx ecx
|
pop eax edi esi edx ecx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
if 0
|
|
||||||
align 4
|
|
||||||
proc alloc_dll
|
|
||||||
pushf
|
|
||||||
cli
|
|
||||||
bsf eax, [dll_map]
|
|
||||||
jnz .find
|
|
||||||
popf
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
.find:
|
|
||||||
btr [dll_map], eax
|
|
||||||
popf
|
|
||||||
shl eax, 5
|
|
||||||
add eax, dll_tab
|
|
||||||
ret
|
|
||||||
endp
|
|
||||||
|
|
||||||
align 4
|
|
||||||
proc alloc_service
|
|
||||||
pushf
|
|
||||||
cli
|
|
||||||
bsf eax, [srv_map]
|
|
||||||
jnz .find
|
|
||||||
popf
|
|
||||||
xor eax, eax
|
|
||||||
ret
|
|
||||||
.find:
|
|
||||||
btr [srv_map], eax
|
|
||||||
popf
|
|
||||||
shl eax, 0x02
|
|
||||||
lea eax, [srv_tab+eax+eax*8] ;srv_tab+eax*36
|
|
||||||
ret
|
|
||||||
endp
|
|
||||||
|
|
||||||
end if
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;; SHARED ;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;; SHARED MEMORY ;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
; param
|
; param
|
||||||
|
@ -448,7 +448,7 @@ proc init_LFB
|
|||||||
bt [cpu_caps], CAPS_PSE
|
bt [cpu_caps], CAPS_PSE
|
||||||
jnc .map_page_tables
|
jnc .map_page_tables
|
||||||
or esi, PG_LARGE+PG_UW
|
or esi, PG_LARGE+PG_UW
|
||||||
mov edx, sys_pgdir+(LFB_BASE shr 20)
|
mov edx, sys_proc+PROC.pdt_0+(LFB_BASE shr 20)
|
||||||
@@:
|
@@:
|
||||||
mov [edx], esi
|
mov [edx], esi
|
||||||
add edx, 4
|
add edx, 4
|
||||||
@ -458,7 +458,7 @@ proc init_LFB
|
|||||||
|
|
||||||
bt [cpu_caps], CAPS_PGE
|
bt [cpu_caps], CAPS_PGE
|
||||||
jnc @F
|
jnc @F
|
||||||
or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL
|
or dword [sys_proc+PROC.pdt_0+(LFB_BASE shr 20)], PG_GLOBAL
|
||||||
@@:
|
@@:
|
||||||
mov dword [LFBAddress], LFB_BASE
|
mov dword [LFBAddress], LFB_BASE
|
||||||
mov eax, cr3 ;flush TLB
|
mov eax, cr3 ;flush TLB
|
||||||
@ -500,7 +500,9 @@ proc new_mem_resize stdcall, new_size:dword
|
|||||||
push edi
|
push edi
|
||||||
|
|
||||||
mov edx, [current_slot]
|
mov edx, [current_slot]
|
||||||
cmp [edx+APPDATA.heap_base], 0
|
mov ebx, [edx+APPDATA.process]
|
||||||
|
|
||||||
|
cmp [ebx+PROC.heap_base], 0
|
||||||
jne .exit
|
jne .exit
|
||||||
|
|
||||||
mov edi, [new_size]
|
mov edi, [new_size]
|
||||||
@ -508,7 +510,7 @@ proc new_mem_resize stdcall, new_size:dword
|
|||||||
and edi, not 4095
|
and edi, not 4095
|
||||||
mov [new_size], edi
|
mov [new_size], edi
|
||||||
|
|
||||||
mov esi, [edx+APPDATA.mem_size]
|
mov esi, [ebx+PROC.mem_used]
|
||||||
add esi, 4095
|
add esi, 4095
|
||||||
and esi, not 4095
|
and esi, not 4095
|
||||||
|
|
||||||
@ -543,7 +545,8 @@ proc new_mem_resize stdcall, new_size:dword
|
|||||||
.update_size:
|
.update_size:
|
||||||
mov edx, [current_slot]
|
mov edx, [current_slot]
|
||||||
mov ebx, [new_size]
|
mov ebx, [new_size]
|
||||||
call update_mem_size
|
mov edx, [edx+APPDATA.process]
|
||||||
|
mov [edx+PROC.mem_used], ebx
|
||||||
.exit:
|
.exit:
|
||||||
pop edi
|
pop edi
|
||||||
pop esi
|
pop esi
|
||||||
@ -619,38 +622,6 @@ proc new_mem_resize stdcall, new_size:dword
|
|||||||
endp
|
endp
|
||||||
|
|
||||||
|
|
||||||
align 4
|
|
||||||
update_mem_size:
|
|
||||||
; in: edx = slot base
|
|
||||||
; ebx = new memory size
|
|
||||||
; destroys eax,ecx,edx
|
|
||||||
|
|
||||||
mov [APPDATA.mem_size+edx], ebx
|
|
||||||
;search threads and update
|
|
||||||
;application memory size infomation
|
|
||||||
mov ecx, [APPDATA.dir_table+edx]
|
|
||||||
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
|
|
||||||
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
|
|
||||||
.search_threads_next:
|
|
||||||
inc eax
|
|
||||||
jmp .search_threads
|
|
||||||
.search_threads_end:
|
|
||||||
ret
|
|
||||||
|
|
||||||
; param
|
; param
|
||||||
; eax= linear address
|
; eax= linear address
|
||||||
;
|
;
|
||||||
@ -707,11 +678,6 @@ end if
|
|||||||
pop ebx ;restore exception number (#PF)
|
pop ebx ;restore exception number (#PF)
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; xchg bx, bx
|
|
||||||
; add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller
|
|
||||||
; restore_ring3_context
|
|
||||||
; iretd
|
|
||||||
|
|
||||||
.user_space:
|
.user_space:
|
||||||
test eax, PG_MAP
|
test eax, PG_MAP
|
||||||
jnz .err_access ;Страница присутствует
|
jnz .err_access ;Страница присутствует
|
||||||
@ -751,9 +717,8 @@ end if
|
|||||||
; access denied? this may be a result of copy-on-write protection for DLL
|
; access denied? this may be a result of copy-on-write protection for DLL
|
||||||
; check list of HDLLs
|
; check list of HDLLs
|
||||||
and ebx, not 0xFFF
|
and ebx, not 0xFFF
|
||||||
mov eax, [CURRENT_TASK]
|
mov eax, [current_process]
|
||||||
shl eax, 8
|
mov eax, [eax+PROC.dlls_list_ptr]
|
||||||
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
|
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .fail
|
jz .fail
|
||||||
mov esi, [eax+HDLL.fd]
|
mov esi, [eax+HDLL.fd]
|
||||||
@ -829,120 +794,129 @@ end if
|
|||||||
endp
|
endp
|
||||||
|
|
||||||
; returns number of mapped bytes
|
; returns number of mapped bytes
|
||||||
proc map_mem stdcall, lin_addr:dword,slot:dword,\
|
proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\
|
||||||
ofs:dword,buf_size:dword,req_access:dword
|
ofs:dword,buf_size:dword,req_access:dword
|
||||||
push 0 ; initialize number of mapped bytes
|
locals
|
||||||
|
count dd ?
|
||||||
|
process dd ?
|
||||||
|
endl
|
||||||
|
|
||||||
|
mov [count], 0
|
||||||
cmp [buf_size], 0
|
cmp [buf_size], 0
|
||||||
jz .exit
|
jz .exit
|
||||||
|
|
||||||
mov eax, [slot]
|
mov eax, [slot]
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
|
mov eax, [SLOT_BASE+eax+APPDATA.process]
|
||||||
and eax, 0xFFFFF000
|
test eax, eax
|
||||||
|
jz .exit
|
||||||
|
|
||||||
stdcall map_page, [ipc_pdir], eax, PG_UW
|
mov [process], eax
|
||||||
mov ebx, [ofs]
|
mov ebx, [ofs]
|
||||||
shr ebx, 22
|
shr ebx, 22
|
||||||
mov esi, [ipc_pdir]
|
mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table
|
||||||
mov edi, [ipc_ptab]
|
mov esi, [ipc_ptab]
|
||||||
mov eax, [esi+ebx*4]
|
|
||||||
and eax, 0xFFFFF000
|
and eax, 0xFFFFF000
|
||||||
jz .exit
|
jz .exit
|
||||||
stdcall map_page, edi, eax, PG_UW
|
stdcall map_page, esi, eax, PG_SW
|
||||||
; 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]
|
mov edi, [lin_addr]
|
||||||
and edi, 0xFFFFF000
|
and edi, 0xFFFFF000
|
||||||
mov ecx, [buf_size]
|
mov ecx, [buf_size]
|
||||||
add ecx, 4095
|
add ecx, 4095
|
||||||
shr ecx, 12
|
shr ecx, 12
|
||||||
inc ecx
|
inc ecx ; ???????????
|
||||||
|
|
||||||
mov edx, [ofs]
|
mov edx, [ofs]
|
||||||
shr edx, 12
|
shr edx, 12
|
||||||
and edx, 0x3FF
|
and edx, 0x3FF
|
||||||
mov esi, [ipc_ptab]
|
|
||||||
|
|
||||||
.map:
|
.map:
|
||||||
stdcall safe_map_page, [slot], [req_access], [ofs]
|
stdcall safe_map_page, [slot], [req_access], [ofs]
|
||||||
jnc .exit
|
jnc .exit
|
||||||
add dword [ebp-4], 4096
|
add [count], PAGE_SIZE
|
||||||
add [ofs], 4096
|
add [ofs], PAGE_SIZE
|
||||||
dec ecx
|
dec ecx
|
||||||
jz .exit
|
jz .exit
|
||||||
add edi, 0x1000
|
|
||||||
|
add edi, PAGE_SIZE
|
||||||
inc edx
|
inc edx
|
||||||
cmp edx, 0x400
|
cmp edx, 1024
|
||||||
jnz .map
|
jnz .map
|
||||||
|
|
||||||
inc ebx
|
inc ebx
|
||||||
mov eax, [ipc_pdir]
|
mov eax, [process]
|
||||||
mov eax, [eax+ebx*4]
|
mov eax, [eax+PROC.pdt_0+ebx*4]
|
||||||
and eax, 0xFFFFF000
|
and eax, 0xFFFFF000
|
||||||
jz .exit
|
jz .exit
|
||||||
stdcall map_page, esi, eax, PG_UW
|
|
||||||
|
stdcall map_page, esi, eax, PG_SW
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
jmp .map
|
jmp .map
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
pop eax
|
mov eax, [count]
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
|
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
|
||||||
ofs:dword,buf_size:dword,req_access:dword
|
ofs:dword,buf_size:dword,req_access:dword
|
||||||
push 0 ; initialize number of mapped bytes
|
locals
|
||||||
|
count dd ?
|
||||||
|
process dd ?
|
||||||
|
endl
|
||||||
|
|
||||||
|
mov [count], 0
|
||||||
cmp [buf_size], 0
|
cmp [buf_size], 0
|
||||||
jz .exit
|
jz .exit
|
||||||
|
|
||||||
mov eax, [slot]
|
mov eax, [slot]
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
|
mov eax, [SLOT_BASE+eax+APPDATA.process]
|
||||||
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
|
test eax, eax
|
||||||
jz .exit
|
jz .exit
|
||||||
stdcall map_page, edi, eax, PG_UW
|
|
||||||
|
|
||||||
|
mov [process], eax
|
||||||
|
mov ebx, [ofs]
|
||||||
|
shr ebx, 22
|
||||||
|
mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table
|
||||||
|
mov esi, [proc_mem_tab]
|
||||||
|
and eax, 0xFFFFF000
|
||||||
|
jz .exit
|
||||||
|
stdcall map_page, esi, eax, PG_SW
|
||||||
@@:
|
@@:
|
||||||
mov edi, [lin_addr]
|
mov edi, [lin_addr]
|
||||||
and edi, 0xFFFFF000
|
and edi, 0xFFFFF000
|
||||||
mov ecx, [buf_size]
|
mov ecx, [buf_size]
|
||||||
add ecx, 4095
|
add ecx, 4095
|
||||||
shr ecx, 12
|
shr ecx, 12
|
||||||
inc ecx
|
inc ecx ; ???????????
|
||||||
|
|
||||||
mov edx, [ofs]
|
mov edx, [ofs]
|
||||||
shr edx, 12
|
shr edx, 12
|
||||||
and edx, 0x3FF
|
and edx, 0x3FF
|
||||||
mov esi, [proc_mem_tab]
|
|
||||||
|
|
||||||
.map:
|
.map:
|
||||||
stdcall safe_map_page, [slot], [req_access], [ofs]
|
stdcall safe_map_page, [slot], [req_access], [ofs]
|
||||||
jnc .exit
|
jnc .exit
|
||||||
add dword [ebp-4], 0x1000
|
add [count], PAGE_SIZE
|
||||||
add edi, 0x1000
|
add [ofs], PAGE_SIZE
|
||||||
add [ofs], 0x1000
|
|
||||||
inc edx
|
|
||||||
dec ecx
|
dec ecx
|
||||||
|
jz .exit
|
||||||
|
|
||||||
|
add edi, PAGE_SIZE
|
||||||
|
inc edx
|
||||||
|
cmp edx, 1024
|
||||||
jnz .map
|
jnz .map
|
||||||
|
|
||||||
|
inc ebx
|
||||||
|
mov eax, [process]
|
||||||
|
mov eax, [eax+PROC.pdt_0+ebx*4]
|
||||||
|
and eax, 0xFFFFF000
|
||||||
|
jz .exit
|
||||||
|
|
||||||
|
stdcall map_page, esi, eax, PG_SW
|
||||||
|
xor edx, edx
|
||||||
|
jmp .map
|
||||||
.exit:
|
.exit:
|
||||||
pop eax
|
mov eax, [count]
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
@ -988,7 +962,8 @@ proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword
|
|||||||
push ebx ecx
|
push ebx ecx
|
||||||
mov eax, [slot]
|
mov eax, [slot]
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
|
mov eax, [SLOT_BASE+eax+APPDATA.process]
|
||||||
|
mov eax, [eax+PROC.dlls_list_ptr]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .no_hdll
|
jz .no_hdll
|
||||||
mov ecx, [eax+HDLL.fd]
|
mov ecx, [eax+HDLL.fd]
|
||||||
@ -1075,29 +1050,6 @@ sys_IPC:
|
|||||||
mov [esp+32], eax
|
mov [esp+32], eax
|
||||||
ret
|
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
|
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
||||||
locals
|
locals
|
||||||
dst_slot dd ?
|
dst_slot dd ?
|
||||||
@ -1116,7 +1068,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
|||||||
|
|
||||||
mov [dst_slot], eax
|
mov [dst_slot], eax
|
||||||
shl eax, 8
|
shl eax, 8
|
||||||
mov edi, [eax+SLOT_BASE+0xa0] ;is ipc area defined?
|
mov edi, [eax+SLOT_BASE+APPDATA.ipc_start] ;is ipc area defined?
|
||||||
test edi, edi
|
test edi, edi
|
||||||
jz .no_ipc_area
|
jz .no_ipc_area
|
||||||
|
|
||||||
@ -1124,7 +1076,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
|||||||
and ebx, 0xFFF
|
and ebx, 0xFFF
|
||||||
mov [dst_offset], ebx
|
mov [dst_offset], ebx
|
||||||
|
|
||||||
mov esi, [eax+SLOT_BASE+0xa4]
|
mov esi, [eax+SLOT_BASE+APPDATA.ipc_size]
|
||||||
mov [buf_size], esi
|
mov [buf_size], esi
|
||||||
|
|
||||||
mov ecx, [ipc_tmp]
|
mov ecx, [ipc_tmp]
|
||||||
@ -1137,7 +1089,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
|||||||
pop edi esi
|
pop edi esi
|
||||||
@@:
|
@@:
|
||||||
mov [used_buf], ecx
|
mov [used_buf], ecx
|
||||||
stdcall map_mem, ecx, [dst_slot], \
|
stdcall map_mem_ipc, ecx, [dst_slot], \
|
||||||
edi, esi, PG_SW
|
edi, esi, PG_SW
|
||||||
|
|
||||||
mov edi, [dst_offset]
|
mov edi, [dst_offset]
|
||||||
@ -1208,7 +1160,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
|
|||||||
.ret:
|
.ret:
|
||||||
mov eax, [used_buf]
|
mov eax, [used_buf]
|
||||||
cmp eax, [ipc_tmp]
|
cmp eax, [ipc_tmp]
|
||||||
jz @f
|
je @f
|
||||||
stdcall free_kernel_space, eax
|
stdcall free_kernel_space, eax
|
||||||
@@:
|
@@:
|
||||||
pop eax
|
pop eax
|
||||||
|
@ -847,7 +847,7 @@ proc mtrr_validate
|
|||||||
dec eax
|
dec eax
|
||||||
; LFB is mapped to virtual address LFB_BASE,
|
; LFB is mapped to virtual address LFB_BASE,
|
||||||
; it uses global pages if supported by CPU.
|
; it uses global pages if supported by CPU.
|
||||||
mov ebx, [sys_pgdir+(LFB_BASE shr 20)]
|
mov ebx, [sys_proc+PROC.pdt_0+(LFB_BASE shr 20)]
|
||||||
test ebx, PG_LARGE
|
test ebx, PG_LARGE
|
||||||
jnz @f
|
jnz @f
|
||||||
mov ebx, [page_tabs+(LFB_BASE shr 10)]
|
mov ebx, [page_tabs+(LFB_BASE shr 10)]
|
||||||
|
@ -104,10 +104,11 @@ do_change_task:
|
|||||||
Mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)],eax,[ebx+APPDATA.io_map]
|
Mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)],eax,[ebx+APPDATA.io_map]
|
||||||
Mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4]
|
Mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4]
|
||||||
; set new thread memory-map
|
; set new thread memory-map
|
||||||
mov ecx, APPDATA.dir_table
|
mov eax, [ebx+APPDATA.process]
|
||||||
mov eax, [ebx+ecx] ;offset>0x7F
|
cmp eax, [current_process]
|
||||||
cmp eax, [esi+ecx] ;offset>0x7F
|
|
||||||
je @f
|
je @f
|
||||||
|
mov [current_process], eax
|
||||||
|
mov eax, [eax+PROC.pdt_0_phys]
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
@@:
|
@@:
|
||||||
; set tss.esp0
|
; set tss.esp0
|
||||||
@ -142,7 +143,7 @@ do_change_task:
|
|||||||
jz @f
|
jz @f
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
mov dr6, eax
|
mov dr6, eax
|
||||||
lea esi, [ebx+ecx+APPDATA.dbg_regs-APPDATA.dir_table];offset>0x7F
|
lea esi, [ebx+APPDATA.dbg_regs]
|
||||||
cld
|
cld
|
||||||
macro lodsReg [reg] {
|
macro lodsReg [reg] {
|
||||||
lodsd
|
lodsd
|
||||||
|
@ -413,23 +413,26 @@ endg
|
|||||||
|
|
||||||
align 4
|
align 4
|
||||||
terminate: ; terminate application
|
terminate: ; terminate application
|
||||||
|
destroy_thread:
|
||||||
|
|
||||||
|
.slot equ esp+4 ;locals
|
||||||
|
.process equ esp ;ptr to parent process
|
||||||
|
|
||||||
.slot equ esp ;locals
|
|
||||||
|
|
||||||
push esi ;save .slot
|
push esi ;save .slot
|
||||||
|
|
||||||
shl esi, 8
|
shl esi, 8
|
||||||
cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
|
mov edx, [SLOT_BASE+esi+APPDATA.process]
|
||||||
jne @F
|
test edx, edx
|
||||||
|
jnz @F
|
||||||
pop esi
|
pop esi
|
||||||
shl esi, 5
|
shl esi, 5
|
||||||
mov [CURRENT_TASK+esi+TASKDATA.state], 9
|
mov [CURRENT_TASK+esi+TASKDATA.state], 9
|
||||||
ret
|
ret
|
||||||
@@:
|
@@:
|
||||||
|
push edx ;save .process
|
||||||
lea edx, [SLOT_BASE+esi]
|
lea edx, [SLOT_BASE+esi]
|
||||||
call scheduler_remove_thread
|
call scheduler_remove_thread
|
||||||
;mov esi,process_terminating
|
|
||||||
;call sys_msg_board_str
|
|
||||||
call lock_application_table
|
call lock_application_table
|
||||||
|
|
||||||
; if the process is in V86 mode...
|
; if the process is in V86 mode...
|
||||||
@ -442,14 +445,14 @@ terminate: ; terminate application
|
|||||||
; ...it has page directory for V86 mode
|
; ...it has page directory for V86 mode
|
||||||
mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
|
mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
|
||||||
mov ecx, [esi+4]
|
mov ecx, [esi+4]
|
||||||
mov [eax+SLOT_BASE+APPDATA.dir_table], ecx
|
mov [eax+SLOT_BASE+APPDATA.process], ecx
|
||||||
; ...and I/O permission map for V86 mode
|
; ...and I/O permission map for V86 mode
|
||||||
mov ecx, [esi+12]
|
mov ecx, [esi+12]
|
||||||
mov [eax+SLOT_BASE+APPDATA.io_map], ecx
|
mov [eax+SLOT_BASE+APPDATA.io_map], ecx
|
||||||
mov ecx, [esi+8]
|
mov ecx, [esi+8]
|
||||||
mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx
|
mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx
|
||||||
.nov86:
|
.nov86:
|
||||||
|
;destroy per-thread kernel objects
|
||||||
mov esi, [.slot]
|
mov esi, [.slot]
|
||||||
shl esi, 8
|
shl esi, 8
|
||||||
add esi, SLOT_BASE+APP_OBJ_OFFSET
|
add esi, SLOT_BASE+APP_OBJ_OFFSET
|
||||||
@ -467,11 +470,6 @@ terminate: ; terminate application
|
|||||||
pop esi
|
pop esi
|
||||||
jmp @B
|
jmp @B
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
mov eax, [.slot]
|
|
||||||
shl eax, 8
|
|
||||||
stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
|
|
||||||
|
|
||||||
mov esi, [.slot]
|
mov esi, [.slot]
|
||||||
cmp [fpu_owner], esi ; if user fpu last -> fpu user = 2
|
cmp [fpu_owner], esi ; if user fpu last -> fpu user = 2
|
||||||
jne @F
|
jne @F
|
||||||
@ -630,6 +628,9 @@ terminate: ; terminate application
|
|||||||
je @F
|
je @F
|
||||||
call free_page
|
call free_page
|
||||||
@@:
|
@@:
|
||||||
|
lea ebx, [edi+APPDATA.list]
|
||||||
|
list_del ebx ;destroys edx, ecx
|
||||||
|
|
||||||
mov eax, 0x20202020
|
mov eax, 0x20202020
|
||||||
stosd
|
stosd
|
||||||
stosd
|
stosd
|
||||||
@ -745,7 +746,17 @@ terminate: ; terminate application
|
|||||||
add ecx, 0x100
|
add ecx, 0x100
|
||||||
jmp .xd0
|
jmp .xd0
|
||||||
.xd1:
|
.xd1:
|
||||||
; call systest
|
;release slot
|
||||||
|
|
||||||
|
bts [thr_slot_map], esi
|
||||||
|
|
||||||
|
mov ecx, [.process]
|
||||||
|
lea eax, [ecx+PROC.thr_list]
|
||||||
|
cmp eax, [eax+LHEAD.next]
|
||||||
|
jne @F
|
||||||
|
|
||||||
|
call destroy_process.internal
|
||||||
|
@@:
|
||||||
sti ; .. and life goes on
|
sti ; .. and life goes on
|
||||||
|
|
||||||
mov eax, [draw_limits.left]
|
mov eax, [draw_limits.left]
|
||||||
@ -760,18 +771,10 @@ terminate: ; terminate application
|
|||||||
call unlock_application_table
|
call unlock_application_table
|
||||||
;mov esi,process_terminated
|
;mov esi,process_terminated
|
||||||
;call sys_msg_board_str
|
;call sys_msg_board_str
|
||||||
add esp, 4
|
add esp, 8
|
||||||
ret
|
ret
|
||||||
restore .slot
|
restore .slot
|
||||||
|
restore .process
|
||||||
;build_scheduler:
|
|
||||||
; mov esi, boot_sched_1
|
|
||||||
; call boot_log
|
|
||||||
; call build_process_gdt_tss_pointer
|
|
||||||
|
|
||||||
; mov esi,boot_sched_2
|
|
||||||
; call boot_log
|
|
||||||
; ret
|
|
||||||
|
|
||||||
; Three following procedures are used to guarantee that
|
; Three following procedures are used to guarantee that
|
||||||
; some part of kernel code will not be terminated from outside
|
; some part of kernel code will not be terminated from outside
|
||||||
|
@ -70,7 +70,7 @@ proc fs_execute
|
|||||||
filename rd 256 ;1024/4
|
filename rd 256 ;1024/4
|
||||||
flags dd ?
|
flags dd ?
|
||||||
|
|
||||||
save_cr3 dd ?
|
save_proc dd ?
|
||||||
slot dd ?
|
slot dd ?
|
||||||
slot_base dd ?
|
slot_base dd ?
|
||||||
file_base dd ?
|
file_base dd ?
|
||||||
@ -215,7 +215,7 @@ proc fs_execute
|
|||||||
|
|
||||||
call lock_application_table
|
call lock_application_table
|
||||||
|
|
||||||
call get_new_process_place
|
call alloc_thread_slot
|
||||||
test eax, eax
|
test eax, eax
|
||||||
mov esi, -0x20 ; too many processes
|
mov esi, -0x20 ; too many processes
|
||||||
jz .err
|
jz .err
|
||||||
@ -248,18 +248,23 @@ proc fs_execute
|
|||||||
loop .copy_process_name_loop
|
loop .copy_process_name_loop
|
||||||
.copy_process_name_done:
|
.copy_process_name_done:
|
||||||
|
|
||||||
mov ebx, cr3
|
mov ebx, [current_process]
|
||||||
mov [save_cr3], ebx
|
mov [save_proc], ebx
|
||||||
|
|
||||||
stdcall create_app_space, [hdr_mem], [file_base], [file_size]
|
stdcall create_process, [hdr_mem], [file_base], [file_size]
|
||||||
mov esi, -30; no memory
|
mov esi, -30; no memory
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .failed
|
jz .failed
|
||||||
|
|
||||||
|
mov ebx, [hdr_mem]
|
||||||
|
mov [eax+PROC.mem_used], ebx
|
||||||
|
|
||||||
mov ebx, [slot_base]
|
mov ebx, [slot_base]
|
||||||
mov [ebx+APPDATA.dir_table], eax
|
mov [ebx+APPDATA.process], eax
|
||||||
mov eax, [hdr_mem]
|
|
||||||
mov [ebx+APPDATA.mem_size], eax
|
lea edx, [ebx+APPDATA.list]
|
||||||
|
lea ecx, [eax+PROC.thr_list]
|
||||||
|
list_add_tail edx, ecx
|
||||||
|
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
cmp word [6], '02'
|
cmp word [6], '02'
|
||||||
@ -292,7 +297,7 @@ end if
|
|||||||
lea ecx, [filename]
|
lea ecx, [filename]
|
||||||
stdcall set_app_params , [slot], eax, ebx, ecx, [flags]
|
stdcall set_app_params , [slot], eax, ebx, ecx, [flags]
|
||||||
|
|
||||||
mov eax, [save_cr3]
|
mov eax, [save_proc]
|
||||||
call set_cr3
|
call set_cr3
|
||||||
|
|
||||||
mov eax, [process_number];set result
|
mov eax, [process_number];set result
|
||||||
@ -301,7 +306,7 @@ end if
|
|||||||
jmp .final
|
jmp .final
|
||||||
|
|
||||||
.failed:
|
.failed:
|
||||||
mov eax, [save_cr3]
|
mov eax, [save_proc]
|
||||||
call set_cr3
|
call set_cr3
|
||||||
.err:
|
.err:
|
||||||
.err_hdr:
|
.err_hdr:
|
||||||
@ -385,53 +390,55 @@ test_app_header:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc get_new_process_place
|
alloc_thread_slot:
|
||||||
;input:
|
;input:
|
||||||
; none
|
; none
|
||||||
;result:
|
;result:
|
||||||
; eax=[new_process_place]<>0 - ok
|
; eax=[new_thread_slot]<>0 - ok
|
||||||
; 0 - failed.
|
; 0 - failed.
|
||||||
;This function find least empty slot.
|
;This function find least empty slot.
|
||||||
;It doesn't increase [TASK_COUNT]!
|
;It doesn't increase [TASK_COUNT]!
|
||||||
mov eax, CURRENT_TASK
|
|
||||||
mov ebx, [TASK_COUNT]
|
|
||||||
inc ebx
|
mov edx, thr_slot_map
|
||||||
shl ebx, 5
|
pushfd
|
||||||
add ebx, eax ;ebx - address of process information for (last+1) slot
|
cli
|
||||||
.newprocessplace:
|
.l1:
|
||||||
;eax = address of process information for current slot
|
bsf eax, [edx]
|
||||||
cmp eax, ebx
|
jnz .found
|
||||||
jz .endnewprocessplace ;empty slot after high boundary
|
add edx, 4
|
||||||
add eax, 0x20
|
cmp edx, thr_slot_map+32
|
||||||
cmp word [eax+0xa], 9;check process state, 9 means that process slot is empty
|
jb .l1
|
||||||
jnz .newprocessplace
|
|
||||||
.endnewprocessplace:
|
popfd
|
||||||
mov ebx, eax
|
|
||||||
sub eax, CURRENT_TASK
|
|
||||||
shr eax, 5 ;calculate slot index
|
|
||||||
cmp eax, 256
|
|
||||||
jge .failed ;it should be <256
|
|
||||||
mov word [ebx+0xa], 9;set process state to 9 (for slot after hight boundary)
|
|
||||||
ret
|
|
||||||
.failed:
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
ret
|
ret
|
||||||
endp
|
.found:
|
||||||
|
btr [edx], eax
|
||||||
|
sub edx, thr_slot_map
|
||||||
|
lea eax, [eax+edx*8]
|
||||||
|
popfd
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
|
proc create_process stdcall, app_size:dword,img_base:dword,img_size:dword
|
||||||
locals
|
locals
|
||||||
app_pages dd ?
|
app_pages dd ?
|
||||||
img_pages dd ?
|
img_pages dd ?
|
||||||
dir_addr dd ?
|
process dd ?
|
||||||
app_tabs dd ?
|
app_tabs dd ?
|
||||||
endl
|
endl
|
||||||
|
|
||||||
|
push ebx
|
||||||
|
push esi
|
||||||
|
push edi
|
||||||
|
|
||||||
mov ecx, pg_data.mutex
|
mov ecx, pg_data.mutex
|
||||||
call mutex_lock
|
call mutex_lock
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
mov [dir_addr], eax
|
mov [process], eax
|
||||||
|
|
||||||
mov eax, [app_size]
|
mov eax, [app_size]
|
||||||
add eax, 4095
|
add eax, 4095
|
||||||
@ -454,39 +461,48 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
|
|||||||
shr ecx, 12
|
shr ecx, 12
|
||||||
mov [img_pages], ecx
|
mov [img_pages], ecx
|
||||||
|
|
||||||
if GREEDY_KERNEL
|
|
||||||
lea eax, [ecx+ebx+2];only image size
|
|
||||||
else
|
|
||||||
lea eax, [eax+ebx+2];all requested memory
|
lea eax, [eax+ebx+2];all requested memory
|
||||||
end if
|
|
||||||
cmp eax, [pg_data.pages_free]
|
cmp eax, [pg_data.pages_free]
|
||||||
ja .fail
|
ja .fail
|
||||||
|
|
||||||
call alloc_page
|
stdcall kernel_alloc, 0x2000
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .fail
|
jz .fail
|
||||||
mov [dir_addr], eax
|
mov [process], eax
|
||||||
stdcall map_page, [tmp_task_pdir], eax, dword PG_SW
|
|
||||||
|
lea edi, [eax+PROC.heap_lock]
|
||||||
|
mov ecx, (4096-PROC.heap_lock)/4
|
||||||
|
|
||||||
|
list_init eax
|
||||||
|
add eax, PROC.thr_list
|
||||||
|
list_init eax
|
||||||
|
|
||||||
mov edi, [tmp_task_pdir]
|
|
||||||
mov ecx, (OS_BASE shr 20)/4
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
cld
|
cld
|
||||||
rep stosd
|
rep stosd
|
||||||
|
|
||||||
|
mov eax, edi
|
||||||
|
call get_pg_addr
|
||||||
|
mov [edi-4096+PROC.pdt_0_phys], eax
|
||||||
|
|
||||||
mov ecx, (OS_BASE shr 20)/4
|
mov ecx, (OS_BASE shr 20)/4
|
||||||
mov esi, sys_pgdir+(OS_BASE shr 20)
|
xor eax, eax
|
||||||
|
rep stosd
|
||||||
|
|
||||||
|
mov ecx, (OS_BASE shr 20)/4
|
||||||
|
mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20)
|
||||||
rep movsd
|
rep movsd
|
||||||
|
|
||||||
mov eax, [dir_addr]
|
mov eax, [edi-8192+PROC.pdt_0_phys]
|
||||||
or eax, PG_SW
|
or eax, PG_SW
|
||||||
mov [edi-4096+(page_tabs shr 20)], eax
|
mov [edi-4096+(page_tabs shr 20)], eax
|
||||||
|
|
||||||
and eax, -4096
|
lea eax, [edi-8192]
|
||||||
call set_cr3
|
call set_cr3
|
||||||
|
|
||||||
mov edx, [app_tabs]
|
mov edx, [app_tabs]
|
||||||
mov edi, new_app_base
|
xor edi, edi
|
||||||
@@:
|
@@:
|
||||||
call alloc_page
|
call alloc_page
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -497,9 +513,7 @@ end if
|
|||||||
dec edx
|
dec edx
|
||||||
jnz @B
|
jnz @B
|
||||||
|
|
||||||
mov edi, new_app_base
|
mov edi, page_tabs
|
||||||
shr edi, 10
|
|
||||||
add edi, page_tabs
|
|
||||||
|
|
||||||
mov ecx, [app_tabs]
|
mov ecx, [app_tabs]
|
||||||
shl ecx, 10
|
shl ecx, 10
|
||||||
@ -508,13 +522,11 @@ end if
|
|||||||
|
|
||||||
mov ecx, [img_pages]
|
mov ecx, [img_pages]
|
||||||
mov ebx, PG_UW
|
mov ebx, PG_UW
|
||||||
mov edx, new_app_base
|
xor edx, edx
|
||||||
mov esi, [img_base]
|
mov esi, [img_base]
|
||||||
mov edi, new_app_base
|
|
||||||
shr esi, 10
|
shr esi, 10
|
||||||
shr edi, 10
|
|
||||||
add esi, page_tabs
|
add esi, page_tabs
|
||||||
add edi, page_tabs
|
mov edi, page_tabs
|
||||||
.remap:
|
.remap:
|
||||||
lodsd
|
lodsd
|
||||||
and eax, 0xFFFFF000
|
and eax, 0xFFFFF000
|
||||||
@ -529,11 +541,6 @@ end if
|
|||||||
test ecx, ecx
|
test ecx, ecx
|
||||||
jz .done
|
jz .done
|
||||||
|
|
||||||
if GREEDY_KERNEL
|
|
||||||
mov eax, 0x02
|
|
||||||
rep stosd
|
|
||||||
else
|
|
||||||
|
|
||||||
.alloc:
|
.alloc:
|
||||||
call alloc_page
|
call alloc_page
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -543,32 +550,40 @@ else
|
|||||||
add edx, 0x1000
|
add edx, 0x1000
|
||||||
dec [app_pages]
|
dec [app_pages]
|
||||||
jnz .alloc
|
jnz .alloc
|
||||||
end if
|
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
stdcall map_page, [tmp_task_pdir], dword 0, dword PG_UNMAP
|
|
||||||
|
|
||||||
mov ecx, pg_data.mutex
|
mov ecx, pg_data.mutex
|
||||||
call mutex_unlock
|
call mutex_unlock
|
||||||
mov eax, [dir_addr]
|
mov eax, [process]
|
||||||
|
|
||||||
|
pop edi
|
||||||
|
pop esi
|
||||||
|
pop ebx
|
||||||
ret
|
ret
|
||||||
.fail:
|
.fail:
|
||||||
mov ecx, pg_data.mutex
|
mov ecx, pg_data.mutex
|
||||||
call mutex_unlock
|
call mutex_unlock
|
||||||
cmp [dir_addr], 0
|
cmp [process], 0
|
||||||
je @f
|
je @f
|
||||||
stdcall destroy_app_space, [dir_addr], 0
|
;; stdcall destroy_app_space, [dir_addr], 0
|
||||||
@@:
|
@@:
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
|
pop edi
|
||||||
|
pop esi
|
||||||
|
pop ebx
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
set_cr3:
|
set_cr3:
|
||||||
|
pushfd
|
||||||
|
cli
|
||||||
mov ebx, [current_slot]
|
mov ebx, [current_slot]
|
||||||
mov [ebx+APPDATA.dir_table], eax
|
mov [current_process], eax
|
||||||
|
mov [ebx+APPDATA.process], eax
|
||||||
|
mov eax, [eax+PROC.pdt_0_phys]
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
|
popfd
|
||||||
ret
|
ret
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
@ -582,6 +597,8 @@ proc destroy_page_table stdcall, pg_tab:dword
|
|||||||
mov eax, [esi]
|
mov eax, [esi]
|
||||||
test eax, 1
|
test eax, 1
|
||||||
jz .next
|
jz .next
|
||||||
|
test eax, 2
|
||||||
|
jz .next
|
||||||
test eax, 1 shl 9
|
test eax, 1 shl 9
|
||||||
jnz .next ;skip shared pages
|
jnz .next ;skip shared pages
|
||||||
call free_page
|
call free_page
|
||||||
@ -594,46 +611,25 @@ proc destroy_page_table stdcall, pg_tab:dword
|
|||||||
endp
|
endp
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword
|
destroy_process: ;fastcall ecx= ptr to process
|
||||||
|
|
||||||
xor edx, edx
|
lea eax, [ecx+PROC.thr_list]
|
||||||
push edx
|
cmp eax, [eax+LHEAD.next]
|
||||||
mov eax, 0x1
|
jne .exit
|
||||||
mov ebx, [pg_dir]
|
|
||||||
.loop:
|
|
||||||
;eax = current slot of process
|
|
||||||
mov ecx, eax
|
|
||||||
shl ecx, 5
|
|
||||||
cmp byte [CURRENT_TASK+ecx+0xa], 9;if process running?
|
|
||||||
jz @f ;skip empty slots
|
|
||||||
shl ecx, 3
|
|
||||||
add ecx, SLOT_BASE
|
|
||||||
cmp [ecx+APPDATA.dir_table], ebx;compare page directory addresses
|
|
||||||
jnz @f
|
|
||||||
mov [ebp-4], ecx
|
|
||||||
inc edx ;thread found
|
|
||||||
@@:
|
|
||||||
inc eax
|
|
||||||
cmp eax, [TASK_COUNT] ;exit loop if we look through all processes
|
|
||||||
jle .loop
|
|
||||||
|
|
||||||
;edx = number of threads
|
align 4
|
||||||
;our process is zombi so it isn't counted
|
.internal:
|
||||||
pop ecx
|
push ecx
|
||||||
cmp edx, 1
|
|
||||||
jg .ret
|
|
||||||
;if there isn't threads then clear memory.
|
|
||||||
mov esi, [dlls_list]
|
|
||||||
call destroy_all_hdlls;ecx=APPDATA
|
|
||||||
|
|
||||||
mov ecx, pg_data.mutex
|
mov esi, [ecx+PROC.dlls_list_ptr]
|
||||||
call mutex_lock
|
call destroy_all_hdlls
|
||||||
|
|
||||||
mov eax, [pg_dir]
|
; mov ecx, pg_data.mutex
|
||||||
and eax, not 0xFFF
|
; call mutex_lock
|
||||||
stdcall map_page, [tmp_task_pdir], eax, PG_SW
|
|
||||||
mov esi, [tmp_task_pdir]
|
mov esi, [esp]
|
||||||
mov edi, (OS_BASE shr 20)/4
|
add esi, PROC.pdt_0
|
||||||
|
mov edi, (0x80000000 shr 20)/4
|
||||||
.destroy:
|
.destroy:
|
||||||
mov eax, [esi]
|
mov eax, [esi]
|
||||||
test eax, 1
|
test eax, 1
|
||||||
@ -648,16 +644,13 @@ proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword
|
|||||||
dec edi
|
dec edi
|
||||||
jnz .destroy
|
jnz .destroy
|
||||||
|
|
||||||
mov eax, [pg_dir]
|
call kernel_free ;ecx still in stack
|
||||||
call free_page
|
|
||||||
.exit:
|
|
||||||
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
|
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
|
||||||
stdcall map_page, [tmp_task_pdir], 0, PG_UNMAP
|
; mov ecx, pg_data.mutex
|
||||||
mov ecx, pg_data.mutex
|
; call mutex_unlock
|
||||||
call mutex_unlock
|
|
||||||
.ret:
|
.exit:
|
||||||
ret
|
ret
|
||||||
endp
|
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
get_pid:
|
get_pid:
|
||||||
@ -708,6 +701,10 @@ check_region:
|
|||||||
;result:
|
;result:
|
||||||
; eax = 1 region lays in app memory
|
; eax = 1 region lays in app memory
|
||||||
; eax = 0 region don't lays in app memory
|
; eax = 0 region don't lays in app memory
|
||||||
|
|
||||||
|
mov eax, 1
|
||||||
|
ret
|
||||||
|
if 0
|
||||||
mov eax, [CURRENT_TASK]
|
mov eax, [CURRENT_TASK]
|
||||||
; jmp check_process_region
|
; jmp check_process_region
|
||||||
;-----------------------------------------------------------------------------
|
;-----------------------------------------------------------------------------
|
||||||
@ -732,57 +729,13 @@ check_region:
|
|||||||
|
|
||||||
mov eax, 1
|
mov eax, 1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
; call MEM_Get_Linear_Address
|
|
||||||
; push ebx
|
|
||||||
; push ecx
|
|
||||||
; push edx
|
|
||||||
; mov edx,ebx
|
|
||||||
; and edx,not (4096-1)
|
|
||||||
; sub ebx,edx
|
|
||||||
; add ecx,ebx
|
|
||||||
; mov ebx,edx
|
|
||||||
; add ecx,(4096-1)
|
|
||||||
; and ecx,not (4096-1)
|
|
||||||
;.loop:
|
|
||||||
;;eax - linear address of page directory
|
|
||||||
;;ebx - current page
|
|
||||||
;;ecx - current size
|
|
||||||
; mov edx,ebx
|
|
||||||
; shr edx,22
|
|
||||||
; mov edx,[eax+4*edx]
|
|
||||||
; and edx,not (4096-1)
|
|
||||||
; test edx,edx
|
|
||||||
; jz .failed1
|
|
||||||
; push eax
|
|
||||||
; mov eax,edx
|
|
||||||
; call MEM_Get_Linear_Address
|
|
||||||
; mov edx,ebx
|
|
||||||
; shr edx,12
|
|
||||||
; and edx,(1024-1)
|
|
||||||
; mov eax,[eax+4*edx]
|
|
||||||
; and eax,not (4096-1)
|
|
||||||
; test eax,eax
|
|
||||||
; pop eax
|
|
||||||
; jz .failed1
|
|
||||||
; add ebx,4096
|
|
||||||
; sub ecx,4096
|
|
||||||
; jg .loop
|
|
||||||
; pop edx
|
|
||||||
; pop ecx
|
|
||||||
; pop ebx
|
|
||||||
.ok:
|
.ok:
|
||||||
mov eax, 1
|
mov eax, 1
|
||||||
ret
|
ret
|
||||||
;
|
|
||||||
;.failed1:
|
|
||||||
; pop edx
|
|
||||||
; pop ecx
|
|
||||||
; pop ebx
|
|
||||||
.failed:
|
.failed:
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
ret
|
ret
|
||||||
|
end if
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
proc read_process_memory
|
proc read_process_memory
|
||||||
@ -954,7 +907,7 @@ proc new_sys_threads
|
|||||||
|
|
||||||
call lock_application_table
|
call lock_application_table
|
||||||
|
|
||||||
call get_new_process_place
|
call alloc_thread_slot
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .failed
|
jz .failed
|
||||||
|
|
||||||
@ -976,20 +929,12 @@ proc new_sys_threads
|
|||||||
mov ecx, 11
|
mov ecx, 11
|
||||||
rep movsb ;copy process name
|
rep movsb ;copy process name
|
||||||
|
|
||||||
mov eax, [ebx+APPDATA.heap_base]
|
mov eax, [ebx+APPDATA.process]
|
||||||
mov [edx+APPDATA.heap_base], eax
|
mov [edx+APPDATA.process], eax
|
||||||
|
|
||||||
mov ecx, [ebx+APPDATA.heap_top]
|
lea ebx, [edx+APPDATA.list]
|
||||||
mov [edx+APPDATA.heap_top], ecx
|
lea ecx, [eax+PROC.thr_list]
|
||||||
|
list_add_tail ebx, ecx ;add thread to process child's list
|
||||||
mov eax, [ebx+APPDATA.mem_size]
|
|
||||||
mov [edx+APPDATA.mem_size], eax
|
|
||||||
|
|
||||||
mov ecx, [ebx+APPDATA.dir_table]
|
|
||||||
mov [edx+APPDATA.dir_table], ecx;copy page directory
|
|
||||||
|
|
||||||
mov eax, [ebx+APPDATA.dlls_list_ptr]
|
|
||||||
mov [edx+APPDATA.dlls_list_ptr], eax
|
|
||||||
|
|
||||||
mov eax, [ebx+APPDATA.tls_base]
|
mov eax, [ebx+APPDATA.tls_base]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -1118,8 +1063,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\
|
|||||||
add eax, 256
|
add eax, 256
|
||||||
jc @f
|
jc @f
|
||||||
|
|
||||||
cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
|
; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
|
||||||
ja @f
|
; ja @f
|
||||||
|
|
||||||
mov eax, [cmd_line]
|
mov eax, [cmd_line]
|
||||||
|
|
||||||
@ -1158,8 +1103,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\
|
|||||||
mov eax, edx
|
mov eax, edx
|
||||||
add eax, 1024
|
add eax, 1024
|
||||||
jc @f
|
jc @f
|
||||||
cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
|
; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
|
||||||
ja @f
|
; ja @f
|
||||||
stdcall strncpy, edx, [app_path], 1024
|
stdcall strncpy, edx, [app_path], 1024
|
||||||
@@:
|
@@:
|
||||||
mov ebx, [slot]
|
mov ebx, [slot]
|
||||||
|
@ -14,9 +14,7 @@ DEBUG_SHOW_IO = 0
|
|||||||
|
|
||||||
struct V86_machine
|
struct V86_machine
|
||||||
; page directory
|
; page directory
|
||||||
pagedir dd ?
|
process dd ?
|
||||||
; translation table: V86 address -> flat linear address
|
|
||||||
pages dd ?
|
|
||||||
; mutex to protect all data from writing by multiple threads at one time
|
; mutex to protect all data from writing by multiple threads at one time
|
||||||
mutex dd ?
|
mutex dd ?
|
||||||
; i/o permission map
|
; i/o permission map
|
||||||
@ -38,91 +36,87 @@ v86_create:
|
|||||||
and dword [eax+V86_machine.mutex], 0
|
and dword [eax+V86_machine.mutex], 0
|
||||||
; allocate tables
|
; allocate tables
|
||||||
mov ebx, eax
|
mov ebx, eax
|
||||||
; We allocate 4 pages.
|
|
||||||
; First is main page directory for V86 mode.
|
stdcall create_process, 4096, OS_BASE, 4096
|
||||||
; Second page:
|
test eax, eax
|
||||||
; first half (0x800 bytes) is page table for addresses 0 - 0x100000,
|
jz .fail2
|
||||||
; second half is for V86-to-linear translation.
|
|
||||||
; Third and fourth are for I/O permission map.
|
mov [eax+PROC.mem_used], 4096
|
||||||
push 8000h ; blocks less than 8 pages are discontinuous
|
mov [ebx+V86_machine.process], eax
|
||||||
|
|
||||||
|
push 2000h
|
||||||
call kernel_alloc
|
call kernel_alloc
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .fail2
|
jz .fail2
|
||||||
mov [ebx+V86_machine.pagedir], eax
|
|
||||||
push edi eax
|
mov [ebx+V86_machine.iopm], eax
|
||||||
mov edi, eax
|
|
||||||
add eax, 1800h
|
|
||||||
mov [ebx+V86_machine.pages], eax
|
|
||||||
; initialize tables
|
; initialize tables
|
||||||
mov ecx, 2000h/4
|
push edi
|
||||||
xor eax, eax
|
|
||||||
rep stosd
|
|
||||||
mov [ebx+V86_machine.iopm], edi
|
|
||||||
dec eax
|
|
||||||
mov ecx, 2000h/4
|
|
||||||
rep stosd
|
|
||||||
pop eax
|
|
||||||
; page directory: first entry is page table...
|
|
||||||
mov edi, eax
|
mov edi, eax
|
||||||
add eax, 1000h
|
mov eax, -1
|
||||||
push eax
|
mov ecx, 2000h/4
|
||||||
call get_pg_addr
|
rep stosd
|
||||||
or al, PG_UW
|
|
||||||
stosd
|
mov eax, [ebx+V86_machine.process]
|
||||||
; ...and also copy system page tables
|
mov eax, [eax+PROC.pdt_0_phys]
|
||||||
; thx to Serge, system is located at high addresses
|
|
||||||
add edi, (OS_BASE shr 20) - 4
|
pushfd
|
||||||
push esi
|
cli
|
||||||
mov esi, (OS_BASE shr 20) + sys_pgdir
|
mov cr3, eax
|
||||||
mov ecx, 0x80000000 shr 22
|
|
||||||
rep movsd
|
|
||||||
|
|
||||||
mov eax, [ebx+V86_machine.pagedir] ;root dir also is
|
|
||||||
call get_pg_addr ;used as page table
|
|
||||||
or al, PG_SW
|
|
||||||
mov [edi-4096+(page_tabs shr 20)], eax
|
|
||||||
|
|
||||||
pop esi
|
|
||||||
; now V86 specific: initialize known addresses in first Mb
|
; now V86 specific: initialize known addresses in first Mb
|
||||||
pop eax
|
|
||||||
; first page - BIOS data (shared between all machines!)
|
; first page - BIOS data (shared between all machines!)
|
||||||
; physical address = 0
|
; physical address = 0
|
||||||
; linear address = OS_BASE
|
; linear address = OS_BASE
|
||||||
mov dword [eax], 111b
|
|
||||||
mov dword [eax+800h], OS_BASE
|
|
||||||
; page before 0xA0000 - Extended BIOS Data Area (shared between all machines!)
|
; page before 0xA0000 - Extended BIOS Data Area (shared between all machines!)
|
||||||
; physical address = 0x9C000
|
; physical address = 0x9C000
|
||||||
; linear address = 0x8009C000
|
; linear address = 0x8009C000
|
||||||
; (I have seen one computer with EBDA segment = 0x9D80,
|
; (I have seen one computer with EBDA segment = 0x9D80,
|
||||||
; all other computers use less memory)
|
; all other computers use less memory)
|
||||||
mov ecx, 4
|
|
||||||
mov edx, 0x9C000
|
mov eax, PG_UW
|
||||||
push eax
|
mov [page_tabs], eax
|
||||||
lea edi, [eax+0x9C*4]
|
invlpg [eax]
|
||||||
|
|
||||||
|
mov byte [0x500], 0xCD
|
||||||
|
mov byte [0x501], 0x13
|
||||||
|
mov byte [0x502], 0xF4
|
||||||
|
mov byte [0x503], 0xCD
|
||||||
|
mov byte [0x504], 0x10
|
||||||
|
mov byte [0x505], 0xF4
|
||||||
|
|
||||||
|
mov eax, 0x99000+PG_UW
|
||||||
|
mov edi, page_tabs+0x99*4
|
||||||
|
mov edx, 0x1000
|
||||||
|
mov ecx, 7
|
||||||
@@:
|
@@:
|
||||||
lea eax, [edx + OS_BASE]
|
|
||||||
mov [edi+800h], eax
|
|
||||||
lea eax, [edx + 111b]
|
|
||||||
stosd
|
stosd
|
||||||
add edx, 0x1000
|
add eax, edx
|
||||||
loop @b
|
loop @b
|
||||||
pop eax
|
|
||||||
pop edi
|
|
||||||
; addresses 0xC0000 - 0xFFFFF - BIOS code (shared between all machines!)
|
; addresses 0xC0000 - 0xFFFFF - BIOS code (shared between all machines!)
|
||||||
; physical address = 0xC0000
|
; physical address = 0xC0000
|
||||||
; linear address = 0x800C0000
|
|
||||||
mov ecx, 0xC0
|
mov eax, 0xC0000+PG_UW
|
||||||
|
mov edi, page_tabs+0xC0*4
|
||||||
|
mov ecx, 64
|
||||||
@@:
|
@@:
|
||||||
mov edx, ecx
|
stosd
|
||||||
shl edx, 12
|
add eax, edx
|
||||||
push edx
|
loop @b
|
||||||
or edx, 111b
|
|
||||||
mov [eax+ecx*4], edx
|
mov eax, sys_proc
|
||||||
pop edx
|
push ebx
|
||||||
add edx, OS_BASE
|
call set_cr3
|
||||||
mov [eax+ecx*4+0x800], edx
|
pop ebx
|
||||||
inc cl
|
popfd
|
||||||
jnz @b
|
|
||||||
|
pop edi
|
||||||
|
|
||||||
mov eax, ebx
|
mov eax, ebx
|
||||||
ret
|
ret
|
||||||
.fail2:
|
.fail2:
|
||||||
@ -132,15 +126,16 @@ v86_create:
|
|||||||
xor eax, eax
|
xor eax, eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;not used
|
||||||
; Destroy V86 machine
|
; Destroy V86 machine
|
||||||
; in: eax = handle
|
; in: eax = handle
|
||||||
; out: nothing
|
; out: nothing
|
||||||
; destroys: eax, ebx, ecx, edx (due to free)
|
; destroys: eax, ebx, ecx, edx (due to free)
|
||||||
v86_destroy:
|
;v86_destroy:
|
||||||
push eax
|
; push eax
|
||||||
stdcall kernel_free, [eax+V86_machine.pagedir]
|
; stdcall kernel_free, [eax+V86_machine.pagedir]
|
||||||
pop eax
|
; pop eax
|
||||||
jmp free
|
; jmp free
|
||||||
|
|
||||||
; Translate V86-address to linear address
|
; Translate V86-address to linear address
|
||||||
; in: eax=V86 address
|
; in: eax=V86 address
|
||||||
@ -150,28 +145,30 @@ v86_destroy:
|
|||||||
v86_get_lin_addr:
|
v86_get_lin_addr:
|
||||||
push ecx edx
|
push ecx edx
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
mov edx, [esi+V86_machine.pages]
|
|
||||||
shr ecx, 12
|
shr ecx, 12
|
||||||
|
mov edx, [page_tabs+ecx*4]
|
||||||
and eax, 0xFFF
|
and eax, 0xFFF
|
||||||
add eax, [edx+ecx*4] ; atomic operation, no mutex needed
|
and edx, 0xFFFFF000
|
||||||
|
or eax, edx
|
||||||
pop edx ecx
|
pop edx ecx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
;not used
|
||||||
; Sets linear address for V86-page
|
; Sets linear address for V86-page
|
||||||
; in: eax=linear address (must be page-aligned)
|
; in: eax=linear address (must be page-aligned)
|
||||||
; ecx=V86 page (NOT address!)
|
; ecx=V86 page (NOT address!)
|
||||||
; esi=handle
|
; esi=handle
|
||||||
; out: nothing
|
; out: nothing
|
||||||
; destroys: nothing
|
; destroys: nothing
|
||||||
v86_set_page:
|
;v86_set_page:
|
||||||
push eax ebx
|
; push eax ebx
|
||||||
mov ebx, [esi+V86_machine.pagedir]
|
; mov ebx, [esi+V86_machine.pagedir]
|
||||||
mov [ebx+ecx*4+0x1800], eax
|
; mov [ebx+ecx*4+0x1800], eax
|
||||||
call get_pg_addr
|
; call get_pg_addr
|
||||||
or al, 111b
|
; or al, 111b
|
||||||
mov [ebx+ecx*4+0x1000], eax
|
; mov [ebx+ecx*4+0x1000], eax
|
||||||
pop ebx eax
|
; pop ebx eax
|
||||||
ret
|
; ret
|
||||||
|
|
||||||
; Allocate memory in V86 machine
|
; Allocate memory in V86 machine
|
||||||
; in: eax=size (in bytes)
|
; in: eax=size (in bytes)
|
||||||
@ -214,21 +211,7 @@ init_sys_v86:
|
|||||||
mov [sys_v86_machine], eax
|
mov [sys_v86_machine], eax
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .ret
|
jz .ret
|
||||||
mov byte [OS_BASE + 0x500], 0xCD
|
|
||||||
mov byte [OS_BASE + 0x501], 0x13
|
|
||||||
mov byte [OS_BASE + 0x502], 0xF4
|
|
||||||
mov byte [OS_BASE + 0x503], 0xCD
|
|
||||||
mov byte [OS_BASE + 0x504], 0x10
|
|
||||||
mov byte [OS_BASE + 0x505], 0xF4
|
|
||||||
mov esi, eax
|
mov esi, eax
|
||||||
mov ebx, [eax+V86_machine.pagedir]
|
|
||||||
; one page for stack, two pages for results (0x2000 bytes = 16 sectors)
|
|
||||||
mov dword [ebx+0x99*4+0x1000], 0x99000 or 111b
|
|
||||||
mov dword [ebx+0x99*4+0x1800], OS_BASE + 0x99000
|
|
||||||
mov dword [ebx+0x9A*4+0x1000], 0x9A000 or 111b
|
|
||||||
mov dword [ebx+0x9A*4+0x1800], OS_BASE + 0x9A000
|
|
||||||
mov dword [ebx+0x9B*4+0x1000], 0x9B000 or 111b
|
|
||||||
mov dword [ebx+0x9B*4+0x1800], OS_BASE + 0x9B000
|
|
||||||
if ~DEBUG_SHOW_IO
|
if ~DEBUG_SHOW_IO
|
||||||
; allow access to all ports
|
; allow access to all ports
|
||||||
mov ecx, [esi+V86_machine.iopm]
|
mov ecx, [esi+V86_machine.iopm]
|
||||||
@ -272,36 +255,38 @@ ends
|
|||||||
; eax = 3 - IRQ is already hooked by another VM
|
; eax = 3 - IRQ is already hooked by another VM
|
||||||
; destroys: nothing
|
; destroys: nothing
|
||||||
v86_start:
|
v86_start:
|
||||||
|
|
||||||
pushad
|
pushad
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
|
||||||
mov ecx, [CURRENT_TASK]
|
mov ecx, [current_slot]
|
||||||
shl ecx, 8
|
|
||||||
add ecx, SLOT_BASE
|
|
||||||
|
|
||||||
mov eax, [esi+V86_machine.iopm]
|
|
||||||
call get_pg_addr
|
|
||||||
inc eax
|
|
||||||
push dword [ecx+APPDATA.io_map]
|
push dword [ecx+APPDATA.io_map]
|
||||||
push dword [ecx+APPDATA.io_map+4]
|
push dword [ecx+APPDATA.io_map+4]
|
||||||
mov dword [ecx+APPDATA.io_map], eax
|
push [ecx+APPDATA.process]
|
||||||
mov dword [page_tabs + (tss._io_map_0 shr 10)], eax
|
|
||||||
add eax, 0x1000
|
|
||||||
mov dword [ecx+APPDATA.io_map+4], eax
|
|
||||||
mov dword [page_tabs + (tss._io_map_1 shr 10)], eax
|
|
||||||
|
|
||||||
push [ecx+APPDATA.dir_table]
|
|
||||||
push [ecx+APPDATA.saved_esp0]
|
push [ecx+APPDATA.saved_esp0]
|
||||||
mov [ecx+APPDATA.saved_esp0], esp
|
mov [ecx+APPDATA.saved_esp0], esp
|
||||||
mov [tss._esp0], esp
|
mov [tss._esp0], esp
|
||||||
|
|
||||||
mov eax, [esi+V86_machine.pagedir]
|
mov eax, [esi+V86_machine.iopm]
|
||||||
call get_pg_addr
|
call get_pg_addr
|
||||||
mov [ecx+APPDATA.dir_table], eax
|
inc eax
|
||||||
mov cr3, eax
|
mov dword [ecx+APPDATA.io_map], eax
|
||||||
|
mov dword [page_tabs + (tss._io_map_0 shr 10)], eax
|
||||||
|
|
||||||
; mov [irq_tab+5*4], my05
|
mov eax, [esi+V86_machine.iopm]
|
||||||
|
add eax, 0x1000
|
||||||
|
call get_pg_addr
|
||||||
|
inc eax
|
||||||
|
mov dword [ecx+APPDATA.io_map+4], eax
|
||||||
|
mov dword [page_tabs + (tss._io_map_1 shr 10)], eax
|
||||||
|
|
||||||
|
mov eax, [esi+V86_machine.process]
|
||||||
|
mov [ecx+APPDATA.process], eax
|
||||||
|
mov [current_process], eax
|
||||||
|
mov eax, [eax+PROC.pdt_0_phys]
|
||||||
|
mov cr3, eax
|
||||||
|
|
||||||
; We do not enable interrupts, because V86 IRQ redirector assumes that
|
; We do not enable interrupts, because V86 IRQ redirector assumes that
|
||||||
; machine is running
|
; machine is running
|
||||||
@ -782,19 +767,21 @@ end if
|
|||||||
mov esp, esi
|
mov esp, esi
|
||||||
|
|
||||||
cli
|
cli
|
||||||
mov ecx, [CURRENT_TASK]
|
mov ecx, [current_slot]
|
||||||
shl ecx, 8
|
|
||||||
pop eax
|
pop eax
|
||||||
mov [SLOT_BASE+ecx+APPDATA.saved_esp0], eax
|
|
||||||
|
mov [ecx+APPDATA.saved_esp0], eax
|
||||||
mov [tss._esp0], eax
|
mov [tss._esp0], eax
|
||||||
pop eax
|
pop eax
|
||||||
mov [SLOT_BASE+ecx+APPDATA.dir_table], eax
|
mov [ecx+APPDATA.process], eax
|
||||||
|
mov [current_process], eax
|
||||||
pop ebx
|
pop ebx
|
||||||
mov dword [SLOT_BASE+ecx+APPDATA.io_map+4], ebx
|
mov dword [ecx+APPDATA.io_map+4], ebx
|
||||||
mov dword [page_tabs + (tss._io_map_1 shr 10)], ebx
|
mov dword [page_tabs + (tss._io_map_1 shr 10)], ebx
|
||||||
pop ebx
|
pop ebx
|
||||||
mov dword [SLOT_BASE+ecx+APPDATA.io_map], ebx
|
mov dword [ecx+APPDATA.io_map], ebx
|
||||||
mov dword [page_tabs + (tss._io_map_0 shr 10)], ebx
|
mov dword [page_tabs + (tss._io_map_0 shr 10)], ebx
|
||||||
|
mov eax, [eax+PROC.pdt_0_phys]
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
sti
|
sti
|
||||||
|
|
||||||
@ -843,11 +830,10 @@ v86_irq:
|
|||||||
pop eax
|
pop eax
|
||||||
v86_irq2:
|
v86_irq2:
|
||||||
mov esi, [v86_irqhooks+edi*8] ; get VM handle
|
mov esi, [v86_irqhooks+edi*8] ; get VM handle
|
||||||
mov eax, [esi+V86_machine.pagedir]
|
mov eax, [esi+V86_machine.process]
|
||||||
call get_pg_addr
|
|
||||||
mov ecx, [CURRENT_TASK]
|
mov ecx, [CURRENT_TASK]
|
||||||
shl ecx, 8
|
shl ecx, 8
|
||||||
cmp [SLOT_BASE+ecx+APPDATA.dir_table], eax
|
cmp [SLOT_BASE+ecx+APPDATA.process], eax
|
||||||
jnz .notcurrent
|
jnz .notcurrent
|
||||||
lea eax, [edi+8]
|
lea eax, [edi+8]
|
||||||
cmp al, 10h
|
cmp al, 10h
|
||||||
@ -860,7 +846,7 @@ v86_irq2:
|
|||||||
mov ebx, SLOT_BASE + 0x100
|
mov ebx, SLOT_BASE + 0x100
|
||||||
mov ecx, [TASK_COUNT]
|
mov ecx, [TASK_COUNT]
|
||||||
.scan:
|
.scan:
|
||||||
cmp [ebx+APPDATA.dir_table], eax
|
cmp [ebx+APPDATA.process], eax
|
||||||
jnz .cont
|
jnz .cont
|
||||||
push ecx
|
push ecx
|
||||||
mov ecx, [ebx+APPDATA.saved_esp0]
|
mov ecx, [ebx+APPDATA.saved_esp0]
|
||||||
@ -895,6 +881,7 @@ v86_irq2:
|
|||||||
popad
|
popad
|
||||||
iretd
|
iretd
|
||||||
.found:
|
.found:
|
||||||
|
mov eax, [eax+PROC.pdt_0_phys]
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
mov esi, [ebx+APPDATA.saved_esp0]
|
mov esi, [ebx+APPDATA.saved_esp0]
|
||||||
sub word [esi-sizeof.v86_regs+v86_regs.esp], 6
|
sub word [esi-sizeof.v86_regs+v86_regs.esp], 6
|
||||||
|
@ -177,7 +177,7 @@ kernel_file_load:
|
|||||||
dd 0 ; subfunction
|
dd 0 ; subfunction
|
||||||
dq 0 ; offset in file
|
dq 0 ; offset in file
|
||||||
dd 0x30000 ; number of bytes to read
|
dd 0x30000 ; number of bytes to read
|
||||||
dd OS_BASE + 0x70000 ; buffer for data
|
dd OS_BASE + 0x71000 ; buffer for data
|
||||||
db '/RD/1/KERNEL.MNT',0
|
db '/RD/1/KERNEL.MNT',0
|
||||||
|
|
||||||
dev_data_path db '/RD/1/DRIVERS/DEVICES.DAT',0
|
dev_data_path db '/RD/1/DRIVERS/DEVICES.DAT',0
|
||||||
@ -345,6 +345,8 @@ mem_block_list rd 64*2
|
|||||||
mem_used_list rd 64*2
|
mem_used_list rd 64*2
|
||||||
mem_hash_cnt rd 64
|
mem_hash_cnt rd 64
|
||||||
|
|
||||||
|
thr_slot_map rd 8
|
||||||
|
|
||||||
cpu_freq rq 1
|
cpu_freq rq 1
|
||||||
|
|
||||||
heap_mutex MUTEX
|
heap_mutex MUTEX
|
||||||
@ -436,14 +438,15 @@ proc_mem_map rd 1
|
|||||||
proc_mem_pdir rd 1
|
proc_mem_pdir rd 1
|
||||||
proc_mem_tab rd 1
|
proc_mem_tab rd 1
|
||||||
|
|
||||||
tmp_task_pdir rd 1
|
|
||||||
tmp_task_ptab rd 1
|
tmp_task_ptab rd 1
|
||||||
|
|
||||||
default_io_map rd 1
|
default_io_map rd 1
|
||||||
|
|
||||||
LFBSize rd 1
|
LFBSize rd 1
|
||||||
|
|
||||||
current_slot rd 1
|
current_process rd 1
|
||||||
|
current_slot rd 1 ; i.e. cureent thread
|
||||||
|
|
||||||
|
|
||||||
; status
|
; status
|
||||||
hd1_status rd 1 ; 0 - free : other - pid
|
hd1_status rd 1 ; 0 - free : other - pid
|
||||||
|
@ -128,12 +128,12 @@ proc init_mem
|
|||||||
mov [pg_data.kernel_tables-OS_BASE], edx
|
mov [pg_data.kernel_tables-OS_BASE], edx
|
||||||
|
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
mov edi, sys_pgdir-OS_BASE
|
mov edi, sys_proc-OS_BASE
|
||||||
mov ecx, 4096/4
|
mov ecx, 8192/4
|
||||||
cld
|
cld
|
||||||
rep stosd
|
rep stosd
|
||||||
|
|
||||||
mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20)
|
mov edx, (sys_proc-OS_BASE+PROC.pdt_0)+ 0x800; (OS_BASE shr 20)
|
||||||
bt [cpu_caps-OS_BASE], CAPS_PSE
|
bt [cpu_caps-OS_BASE], CAPS_PSE
|
||||||
jnc .no_PSE
|
jnc .no_PSE
|
||||||
|
|
||||||
@ -177,9 +177,9 @@ proc init_mem
|
|||||||
dec ecx
|
dec ecx
|
||||||
jnz .map_kernel_tabs
|
jnz .map_kernel_tabs
|
||||||
|
|
||||||
mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
|
mov dword [sys_proc-OS_BASE+PROC.pdt_0+(page_tabs shr 20)], sys_proc+PROC.pdt_0+PG_SW-OS_BASE
|
||||||
|
|
||||||
mov edi, (sys_pgdir-OS_BASE)
|
mov edi, (sys_proc+PROC.pdt_0-OS_BASE)
|
||||||
lea esi, [edi+(OS_BASE shr 20)]
|
lea esi, [edi+(OS_BASE shr 20)]
|
||||||
movsd
|
movsd
|
||||||
movsd
|
movsd
|
||||||
|
@ -291,7 +291,7 @@ B32:
|
|||||||
|
|
||||||
; ENABLE PAGING
|
; ENABLE PAGING
|
||||||
|
|
||||||
mov eax, sys_pgdir-OS_BASE
|
mov eax, sys_proc-OS_BASE+PROC.pdt_0
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
|
|
||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
@ -354,15 +354,15 @@ high_code:
|
|||||||
bt [cpu_caps], CAPS_PGE
|
bt [cpu_caps], CAPS_PGE
|
||||||
jnc @F
|
jnc @F
|
||||||
|
|
||||||
or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
|
or dword [sys_proc+PROC.pdt_0+(OS_BASE shr 20)], PG_GLOBAL
|
||||||
|
|
||||||
mov ebx, cr4
|
mov ebx, cr4
|
||||||
or ebx, CR4_PGE
|
or ebx, CR4_PGE
|
||||||
mov cr4, ebx
|
mov cr4, ebx
|
||||||
@@:
|
@@:
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
mov dword [sys_pgdir], eax
|
mov dword [sys_proc+PROC.pdt_0], eax
|
||||||
mov dword [sys_pgdir+4], eax
|
mov dword [sys_proc+PROC.pdt_0+4], eax
|
||||||
|
|
||||||
mov eax, cr3
|
mov eax, cr3
|
||||||
mov cr3, eax ; flush TLB
|
mov cr3, eax ; flush TLB
|
||||||
@ -597,7 +597,7 @@ no_mode_0x12:
|
|||||||
call init_fpu
|
call init_fpu
|
||||||
call init_malloc
|
call init_malloc
|
||||||
|
|
||||||
stdcall alloc_kernel_space, 0x51000
|
stdcall alloc_kernel_space, 0x50000 ; FIXME check size
|
||||||
mov [default_io_map], eax
|
mov [default_io_map], eax
|
||||||
|
|
||||||
add eax, 0x2000
|
add eax, 0x2000
|
||||||
@ -613,9 +613,6 @@ no_mode_0x12:
|
|||||||
add eax, ebx
|
add eax, ebx
|
||||||
mov [proc_mem_tab], eax
|
mov [proc_mem_tab], eax
|
||||||
|
|
||||||
add eax, ebx
|
|
||||||
mov [tmp_task_pdir], eax
|
|
||||||
|
|
||||||
add eax, ebx
|
add eax, ebx
|
||||||
mov [tmp_task_ptab], eax
|
mov [tmp_task_ptab], eax
|
||||||
|
|
||||||
@ -674,7 +671,26 @@ no_mode_0x12:
|
|||||||
mov esi, boot_setostask
|
mov esi, boot_setostask
|
||||||
call boot_log
|
call boot_log
|
||||||
|
|
||||||
mov edx, SLOT_BASE+256
|
mov edi, sys_proc
|
||||||
|
list_init edi
|
||||||
|
lea ecx, [edi+PROC.thr_list]
|
||||||
|
list_init ecx
|
||||||
|
mov [edi+PROC.pdt_0_phys], sys_proc-OS_BASE+PROC.pdt_0
|
||||||
|
|
||||||
|
mov eax, -1
|
||||||
|
mov edi, thr_slot_map+4
|
||||||
|
mov [edi-4], dword 0xFFFFFFF8
|
||||||
|
stosd
|
||||||
|
stosd
|
||||||
|
stosd
|
||||||
|
stosd
|
||||||
|
stosd
|
||||||
|
stosd
|
||||||
|
stosd
|
||||||
|
|
||||||
|
mov [current_process], sys_proc
|
||||||
|
|
||||||
|
mov edx, SLOT_BASE+256*1
|
||||||
mov ebx, [os_stack_seg]
|
mov ebx, [os_stack_seg]
|
||||||
add ebx, 0x2000
|
add ebx, 0x2000
|
||||||
call setup_os_slot
|
call setup_os_slot
|
||||||
@ -1127,7 +1143,7 @@ ap_init_high:
|
|||||||
mov fs, cx
|
mov fs, cx
|
||||||
mov gs, bx
|
mov gs, bx
|
||||||
xor esp, esp
|
xor esp, esp
|
||||||
mov eax, sys_pgdir-OS_BASE
|
mov eax, sys_proc-OS_BASE+PROC.pdt_0
|
||||||
mov cr3, eax
|
mov cr3, eax
|
||||||
lock inc [ap_initialized]
|
lock inc [ap_initialized]
|
||||||
jmp idle_loop
|
jmp idle_loop
|
||||||
@ -1190,7 +1206,11 @@ proc setup_os_slot
|
|||||||
|
|
||||||
mov dword [edx+APPDATA.cur_dir], sysdir_path
|
mov dword [edx+APPDATA.cur_dir], sysdir_path
|
||||||
|
|
||||||
mov [edx + APPDATA.dir_table], sys_pgdir - OS_BASE
|
mov [edx + APPDATA.process], sys_proc
|
||||||
|
|
||||||
|
lea ebx, [edx+APPDATA.list]
|
||||||
|
lea ecx, [sys_proc+PROC.thr_list]
|
||||||
|
list_add_tail ebx, ecx
|
||||||
|
|
||||||
mov eax, edx
|
mov eax, edx
|
||||||
shr eax, 3
|
shr eax, 3
|
||||||
@ -2070,9 +2090,6 @@ restore_default_cursor_before_killing:
|
|||||||
|
|
||||||
movzx eax, word [MOUSE_Y]
|
movzx eax, word [MOUSE_Y]
|
||||||
movzx ebx, word [MOUSE_X]
|
movzx ebx, word [MOUSE_X]
|
||||||
; mov ecx, [Screen_Max_X]
|
|
||||||
; inc ecx
|
|
||||||
; mul ecx
|
|
||||||
mov eax, [d_width_calc_area + eax*4]
|
mov eax, [d_width_calc_area + eax*4]
|
||||||
|
|
||||||
add eax, [_WinMapAddress]
|
add eax, [_WinMapAddress]
|
||||||
@ -3087,7 +3104,8 @@ sys_cpuusage:
|
|||||||
mov edx, 0x100000*16
|
mov edx, 0x100000*16
|
||||||
cmp ecx, 1 shl 5
|
cmp ecx, 1 shl 5
|
||||||
je .os_mem
|
je .os_mem
|
||||||
mov edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
|
mov edx, [SLOT_BASE+ecx*8+APPDATA.process]
|
||||||
|
mov edx, [edx+PROC.mem_used]
|
||||||
mov eax, std_application_base_address
|
mov eax, std_application_base_address
|
||||||
.os_mem:
|
.os_mem:
|
||||||
stosd
|
stosd
|
||||||
@ -3391,26 +3409,6 @@ modify_pce:
|
|||||||
;---------------------------------------------------------------------------------------------
|
;---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
; check if pixel is allowed to be drawn
|
|
||||||
|
|
||||||
;checkpixel:
|
|
||||||
; push eax edx
|
|
||||||
|
|
||||||
;; mov edx, [Screen_Max_X] ; screen x size
|
|
||||||
;; inc edx
|
|
||||||
;; imul edx, ebx
|
|
||||||
; mov edx, [d_width_calc_area + ebx*4]
|
|
||||||
; add eax, [_WinMapAddress]
|
|
||||||
; mov dl, [eax+edx]; lea eax, [...]
|
|
||||||
|
|
||||||
; xor ecx, ecx
|
|
||||||
; mov eax, [CURRENT_TASK]
|
|
||||||
; cmp al, dl
|
|
||||||
; setne cl
|
|
||||||
|
|
||||||
; pop edx eax
|
|
||||||
; ret
|
|
||||||
|
|
||||||
iglobal
|
iglobal
|
||||||
cpustring db 'CPU',0
|
cpustring db 'CPU',0
|
||||||
endg
|
endg
|
||||||
@ -3579,7 +3577,7 @@ markz:
|
|||||||
cmp [edx+TASKDATA.state], 9
|
cmp [edx+TASKDATA.state], 9
|
||||||
jz .nokill
|
jz .nokill
|
||||||
lea edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
|
lea edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
|
||||||
cmp [edx+APPDATA.dir_table], sys_pgdir - OS_BASE
|
cmp [edx+APPDATA.process], sys_proc
|
||||||
jz .nokill
|
jz .nokill
|
||||||
call request_terminate
|
call request_terminate
|
||||||
jmp .common
|
jmp .common
|
||||||
|
@ -98,17 +98,33 @@ struct DBG_REGS
|
|||||||
dr7 dd ?
|
dr7 dd ?
|
||||||
ends
|
ends
|
||||||
|
|
||||||
|
struct PROC
|
||||||
|
list LHEAD
|
||||||
|
thr_list LHEAD
|
||||||
|
heap_lock MUTEX
|
||||||
|
heap_base rd 1
|
||||||
|
heap_top rd 1
|
||||||
|
mem_used rd 1
|
||||||
|
dlls_list_ptr rd 1
|
||||||
|
pdt_0_phys rd 1
|
||||||
|
pdt_1_phys rd 1
|
||||||
|
io_map_0 rd 1
|
||||||
|
io_map_1 rd 1
|
||||||
|
|
||||||
|
unused rb 4096-$
|
||||||
|
pdt_0 rd 1024
|
||||||
|
ends
|
||||||
|
|
||||||
struct APPDATA
|
struct APPDATA
|
||||||
app_name rb 11
|
app_name rb 11
|
||||||
rb 5
|
rb 5
|
||||||
|
|
||||||
fpu_state dd ? ;+16
|
list LHEAD ;+16
|
||||||
ev_count_ dd ? ;unused ;+20
|
process dd ? ;+24
|
||||||
exc_handler dd ? ;+24
|
fpu_state dd ? ;+28
|
||||||
except_mask dd ? ;+28
|
exc_handler dd ? ;+32
|
||||||
pl0_stack dd ? ;+32
|
except_mask dd ? ;+36
|
||||||
heap_base dd ? ;+36
|
pl0_stack dd ? ;+40
|
||||||
heap_top dd ? ;+40
|
|
||||||
cursor dd ? ;+44
|
cursor dd ? ;+44
|
||||||
fd_ev dd ? ;+48
|
fd_ev dd ? ;+48
|
||||||
bk_ev dd ? ;+52
|
bk_ev dd ? ;+52
|
||||||
@ -124,7 +140,7 @@ struct APPDATA
|
|||||||
wait_test dd ? ;+96 +++
|
wait_test dd ? ;+96 +++
|
||||||
wait_param dd ? ;+100 +++
|
wait_param dd ? ;+100 +++
|
||||||
tls_base dd ? ;+104
|
tls_base dd ? ;+104
|
||||||
dlls_list_ptr dd ? ;+108
|
dd ? ;+108
|
||||||
event_filter dd ? ;+112
|
event_filter dd ? ;+112
|
||||||
draw_bgr_x dd ? ;+116
|
draw_bgr_x dd ? ;+116
|
||||||
draw_bgr_y dd ? ;+120
|
draw_bgr_y dd ? ;+120
|
||||||
@ -133,7 +149,7 @@ struct APPDATA
|
|||||||
wnd_shape dd ? ;+128
|
wnd_shape dd ? ;+128
|
||||||
wnd_shape_scale dd ? ;+132
|
wnd_shape_scale dd ? ;+132
|
||||||
dd ? ;+136
|
dd ? ;+136
|
||||||
mem_size dd ? ;+140
|
dd ? ;+140
|
||||||
saved_box BOX ;+144
|
saved_box BOX ;+144
|
||||||
ipc_start dd ? ;+160
|
ipc_start dd ? ;+160
|
||||||
ipc_size dd ? ;+164
|
ipc_size dd ? ;+164
|
||||||
@ -142,7 +158,7 @@ struct APPDATA
|
|||||||
terminate_protection dd ? ;+176
|
terminate_protection dd ? ;+176
|
||||||
keyboard_mode db ? ;+180
|
keyboard_mode db ? ;+180
|
||||||
rb 3
|
rb 3
|
||||||
dir_table dd ? ;+184
|
dd ? ;+184
|
||||||
dbg_event_mem dd ? ;+188
|
dbg_event_mem dd ? ;+188
|
||||||
dbg_regs DBG_REGS ;+192
|
dbg_regs DBG_REGS ;+192
|
||||||
wnd_caption dd ? ;+212
|
wnd_caption dd ? ;+212
|
||||||
|
@ -89,6 +89,12 @@ macro Mov op1,op2,op3 ; op1 = op2 = op3
|
|||||||
mov op1, op2
|
mov op1, op2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro list_init head
|
||||||
|
{
|
||||||
|
mov [head+LHEAD.next], head
|
||||||
|
mov [head+LHEAD.prev], head
|
||||||
|
}
|
||||||
|
|
||||||
macro __list_add new, prev, next
|
macro __list_add new, prev, next
|
||||||
{
|
{
|
||||||
mov [next+LHEAD.prev], new
|
mov [next+LHEAD.prev], new
|
||||||
@ -111,10 +117,10 @@ macro list_add_tail new, head
|
|||||||
|
|
||||||
macro list_del entry
|
macro list_del entry
|
||||||
{
|
{
|
||||||
mov edx, [entry+list_fd]
|
mov edx, [entry+LHEAD.next]
|
||||||
mov ecx, [entry+list_bk]
|
mov ecx, [entry+LHEAD.prev]
|
||||||
mov [edx+list_bk], ecx
|
mov [edx+LHEAD.prev], ecx
|
||||||
mov [ecx+list_fd], edx
|
mov [ecx+LHEAD.next], edx
|
||||||
}
|
}
|
||||||
|
|
||||||
; MOV Immediate.
|
; MOV Immediate.
|
||||||
|
Loading…
Reference in New Issue
Block a user