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:
Sergey Semyonov (Serge) 2014-09-18 07:58:56 +00:00
parent 73dfca6a00
commit 76d618357e
15 changed files with 550 additions and 679 deletions

View File

@ -182,7 +182,7 @@ restart_kernel_4000:
pop es
mov cx, 0x8000
push cx
push 0x7000
push 0x7100
pop ds
xor si, si
xor di, di

View File

@ -219,7 +219,7 @@ TASK_ACTIVATE equ (OS_BASE+0x000FF01)
TMP_STACK_TOP equ 0x006CC00
sys_pgdir equ (OS_BASE+0x006F000)
sys_proc equ (OS_BASE+0x006F000)
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
PAGE_SIZE equ 4096
PG_UNMAP equ 0x000
PG_MAP equ 0x001
PG_WRITE equ 0x002

View File

@ -918,10 +918,9 @@ proc load_library stdcall, file_name:dword
; ignore timestamp
cli
mov esi, [CURRENT_TASK]
shl esi, 8
mov esi, [current_process]
lea edi, [fullname]
mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr]
mov ebx, [esi+PROC.dlls_list_ptr]
test ebx, ebx
jz .not_in_process
mov esi, [ebx+HDLL.fd]
@ -1281,28 +1280,21 @@ endp
; out: eax = APPDATA.dlls_list_ptr if all is OK,
; NULL if memory allocation failed
init_dlls_in_thread:
mov ebx, [current_slot]
mov eax, [ebx+APPDATA.dlls_list_ptr]
mov ebx, [current_process]
mov eax, [ebx+PROC.dlls_list_ptr]
test eax, eax
jnz .ret
push [ebx+APPDATA.dir_table]
mov eax, 8
call malloc
pop edx
call malloc ; FIXME
test eax, eax
jz .ret
mov [eax], eax
mov [eax+4], eax
mov ecx, [TASK_COUNT]
mov ebx, SLOT_BASE+256
.set:
cmp [ebx+APPDATA.dir_table], edx
jnz @f
mov [ebx+APPDATA.dlls_list_ptr], eax
@@:
add ebx, 256
dec ecx
jnz .set
mov ebx, [current_process]
mov [ebx+PROC.dlls_list_ptr], eax
.ret:
ret
@ -1323,59 +1315,10 @@ dereference_dll:
destroy_hdll:
push ebx ecx esi edi
push eax
mov ebx, [eax+HDLL.base]
mov esi, [eax+HDLL.parent]
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
mov esi, [eax+HDLL.parent]
mov eax, [eax+HDLL.refcount]

View File

@ -558,33 +558,36 @@ restore block_base
restore block_size
restore block_flags
;;;;;;;;;;;;;; USER ;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;; USER HEAP ;;;;;;;;;;;;;;;;;
HEAP_TOP equ 0x80000000
align 4
proc init_heap
mov ebx, [current_slot]
mov eax, [ebx+APPDATA.heap_top]
mov ebx, [current_process]
mov eax, [ebx+PROC.heap_top]
test eax, eax
jz @F
sub eax, [ebx+APPDATA.heap_base]
sub eax, 4096
sub eax, [ebx+PROC.heap_base]
sub eax, PAGE_SIZE
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
and esi, not 4095
mov [ebx+APPDATA.mem_size], esi
mov [ebx+PROC.mem_used], esi
mov eax, HEAP_TOP
mov [ebx+APPDATA.heap_base], esi
mov [ebx+APPDATA.heap_top], eax
mov [ebx+PROC.heap_base], esi
mov [ebx+PROC.heap_top], eax
sub eax, esi
shr esi, 10
mov ecx, eax
sub eax, 4096
sub eax, PAGE_SIZE
or ecx, FREE_BLOCK
mov [page_tabs+esi], ecx
ret
@ -597,25 +600,28 @@ proc user_alloc stdcall, alloc_size:dword
push esi
push edi
mov ebx, [current_process]
lea ecx, [ebx+PROC.heap_lock]
call mutex_lock
mov ecx, [alloc_size]
add ecx, (4095+4096)
add ecx, (4095+PAGE_SIZE)
and ecx, not 4095
mov ebx, [current_slot]
mov esi, dword [ebx+APPDATA.heap_base] ; heap_base
mov edi, dword [ebx+APPDATA.heap_top] ; heap_top
l_0:
mov esi, dword [ebx+PROC.heap_base] ; heap_base
mov edi, dword [ebx+PROC.heap_top] ; heap_top
.scan:
cmp esi, edi
jae m_exit
jae .m_exit
mov ebx, esi
shr ebx, 12
mov eax, [page_tabs+ebx*4]
test al, FREE_BLOCK
jz test_used
jz .test_used
and eax, 0xFFFFF000
cmp eax, ecx ;alloc_size
jb m_next
jb .m_next
jz @f
lea edx, [esi+ecx]
@ -637,12 +643,14 @@ l_0:
jnz @B
.no:
mov edx, [current_slot]
mov edx, [current_process]
mov ebx, [alloc_size]
add ebx, 0xFFF
and ebx, not 0xFFF
add ebx, [edx+APPDATA.mem_size]
call update_mem_size
add [edx+PROC.mem_used], ebx
lea ecx, [edx+PROC.heap_lock]
call mutex_unlock
lea eax, [esi+4096]
@ -650,15 +658,19 @@ l_0:
pop esi
pop ebx
ret
test_used:
.test_used:
test al, USED_BLOCK
jz m_exit
jz .m_exit
and eax, 0xFFFFF000
m_next:
.m_next:
add esi, eax
jmp l_0
m_exit:
jmp .scan
.m_exit:
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_unlock
xor eax, eax
pop edi
pop esi
@ -673,14 +685,17 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
push esi
push edi
mov ebx, [current_slot]
mov ebx, [current_process]
lea ecx, [ebx+PROC.heap_lock]
call mutex_lock
mov edx, [address]
and edx, not 0xFFF
mov [address], edx
sub edx, 0x1000
jb .error
mov esi, [ebx+APPDATA.heap_base]
mov edi, [ebx+APPDATA.heap_top]
mov esi, [ebx+PROC.heap_base]
mov edi, [ebx+PROC.heap_top]
cmp edx, esi
jb .error
.scan:
@ -697,6 +712,10 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
mov esi, ecx
jmp .scan
.error:
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_unlock
xor eax, eax
pop edi
pop esi
@ -748,13 +767,14 @@ proc user_alloc_at stdcall, address:dword, alloc_size:dword
mov [page_tabs+ebx*4], ecx
.nothird:
mov edx, [current_slot]
mov edx, [current_process]
mov ebx, [alloc_size]
add ebx, 0xFFF
and ebx, not 0xFFF
add ebx, [edx+APPDATA.mem_size]
call update_mem_size
add [edx+PROC.mem_used], ebx
lea ecx, [edx+PROC.heap_lock]
call mutex_unlock
mov eax, [address]
@ -771,10 +791,14 @@ proc user_free stdcall, base:dword
mov esi, [base]
test esi, esi
jz .exit
jz .fail
push ebx
mov ebx, [current_process]
lea ecx, [ebx+PROC.heap_lock]
call mutex_lock
xor ebx, ebx
shr esi, 12
mov eax, [page_tabs+(esi-1)*4]
@ -810,25 +834,30 @@ proc user_free stdcall, base:dword
.released:
push edi
mov edx, [current_slot]
mov esi, dword [edx+APPDATA.heap_base]
mov edi, dword [edx+APPDATA.heap_top]
sub ebx, [edx+APPDATA.mem_size]
mov edx, [current_process]
lea ecx, [edx+PROC.heap_lock]
mov esi, dword [edx+PROC.heap_base]
mov edi, dword [edx+PROC.heap_top]
sub ebx, [edx+PROC.mem_used]
neg ebx
call update_mem_size
mov [edx+PROC.mem_used], ebx
call user_normalize
pop edi
pop ebx
pop esi
ret
.exit:
call mutex_unlock
xor eax, eax
inc eax
pop ebx
pop esi
ret
.cantfree:
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
jmp .exit
.fail:
xor eax, eax
pop ebx
pop esi
ret
endp
@ -957,6 +986,13 @@ user_realloc:
ret
@@:
push ecx edx
push eax
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_lock
pop eax
lea ecx, [eax - 0x1000]
shr ecx, 12
mov edx, [page_tabs+ecx*4]
@ -964,6 +1000,10 @@ user_realloc:
jnz @f
; attempt to realloc invalid pointer
.ret0:
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_unlock
pop edx ecx
xor eax, eax
ret
@ -998,16 +1038,16 @@ user_realloc:
jnz .nofreeall
mov eax, [page_tabs+ecx*4]
and eax, not 0xFFF
mov edx, [current_slot]
mov ebx, [APPDATA.mem_size+edx]
mov edx, [current_process]
mov ebx, [edx+PROC.mem_used]
sub ebx, eax
add ebx, 0x1000
or al, FREE_BLOCK
mov [page_tabs+ecx*4], eax
push esi edi
mov esi, [APPDATA.heap_base+edx]
mov edi, [APPDATA.heap_top+edx]
call update_mem_size
mov esi, [edx+PROC.heap_base]
mov edi, [edx+PROC.heap_top]
mov [edx+PROC.mem_used], ebx
call user_normalize
pop edi esi
jmp .ret0 ; all freed
@ -1019,11 +1059,11 @@ user_realloc:
shr ebx, 12
sub ebx, edx
push ebx ecx edx
mov edx, [current_slot]
mov edx, [current_process]
shl ebx, 12
sub ebx, [APPDATA.mem_size+edx]
sub ebx, [edx+PROC.mem_used]
neg ebx
call update_mem_size
mov [edx+PROC.mem_used], ebx
pop edx ecx ebx
lea eax, [ecx+1]
shl eax, 12
@ -1033,8 +1073,8 @@ user_realloc:
shl ebx, 12
jz .ret
push esi
mov esi, [current_slot]
mov esi, [APPDATA.heap_top+esi]
mov esi, [current_process]
mov esi, [esi+PROC.heap_top]
shr esi, 12
@@:
cmp edx, esi
@ -1053,12 +1093,16 @@ user_realloc:
or ebx, FREE_BLOCK
mov [page_tabs+ecx*4], ebx
.ret:
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_unlock
pop eax edx ecx
ret
.realloc_add:
; get some additional memory
mov eax, [current_slot]
mov eax, [APPDATA.heap_top+eax]
mov eax, [current_process]
mov eax, [eax+PROC.heap_top]
shr eax, 12
cmp edx, eax
jae .cant_inplace
@ -1090,17 +1134,21 @@ user_realloc:
cld
rep stosd
pop edi
mov edx, [current_slot]
mov edx, [current_process]
shl ebx, 12
add ebx, [APPDATA.mem_size+edx]
call update_mem_size
add [edx+PROC.mem_used], ebx
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_unlock
pop eax edx ecx
ret
.cant_inplace:
push esi edi
mov eax, [current_slot]
mov esi, [APPDATA.heap_base+eax]
mov edi, [APPDATA.heap_top+eax]
mov eax, [current_process]
mov esi, [eax+PROC.heap_base]
mov edi, [eax+PROC.heap_top]
shr esi, 12
shr edi, 12
sub ebx, ecx
@ -1163,58 +1211,25 @@ user_realloc:
jnz @b
.no:
push ebx
mov edx, [current_slot]
mov edx, [current_process]
shl ebx, 12
add ebx, [APPDATA.mem_size+edx]
call update_mem_size
add [edx+PROC.mem_used], ebx
pop ebx
@@:
mov dword [page_tabs+esi*4], 2
inc esi
dec ebx
jnz @b
mov ecx, [current_process]
lea ecx, [ecx+PROC.heap_lock]
call mutex_unlock
pop eax edi esi edx ecx
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

View File

@ -448,7 +448,7 @@ proc init_LFB
bt [cpu_caps], CAPS_PSE
jnc .map_page_tables
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
add edx, 4
@ -458,7 +458,7 @@ proc init_LFB
bt [cpu_caps], CAPS_PGE
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 eax, cr3 ;flush TLB
@ -500,7 +500,9 @@ proc new_mem_resize stdcall, new_size:dword
push edi
mov edx, [current_slot]
cmp [edx+APPDATA.heap_base], 0
mov ebx, [edx+APPDATA.process]
cmp [ebx+PROC.heap_base], 0
jne .exit
mov edi, [new_size]
@ -508,7 +510,7 @@ proc new_mem_resize stdcall, new_size:dword
and edi, not 4095
mov [new_size], edi
mov esi, [edx+APPDATA.mem_size]
mov esi, [ebx+PROC.mem_used]
add esi, 4095
and esi, not 4095
@ -543,7 +545,8 @@ proc new_mem_resize stdcall, new_size:dword
.update_size:
mov edx, [current_slot]
mov ebx, [new_size]
call update_mem_size
mov edx, [edx+APPDATA.process]
mov [edx+PROC.mem_used], ebx
.exit:
pop edi
pop esi
@ -619,38 +622,6 @@ proc new_mem_resize stdcall, new_size:dword
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
; eax= linear address
;
@ -707,11 +678,6 @@ end if
pop ebx ;restore exception number (#PF)
ret
; xchg bx, bx
; add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller
; restore_ring3_context
; iretd
.user_space:
test eax, PG_MAP
jnz .err_access ;Страница присутствует
@ -751,9 +717,8 @@ end if
; access denied? this may be a result of copy-on-write protection for DLL
; check list of HDLLs
and ebx, not 0xFFF
mov eax, [CURRENT_TASK]
shl eax, 8
mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
mov eax, [current_process]
mov eax, [eax+PROC.dlls_list_ptr]
test eax, eax
jz .fail
mov esi, [eax+HDLL.fd]
@ -829,120 +794,129 @@ end if
endp
; 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
push 0 ; initialize number of mapped bytes
locals
count dd ?
process dd ?
endl
mov [count], 0
cmp [buf_size], 0
jz .exit
mov eax, [slot]
shl eax, 8
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
and eax, 0xFFFFF000
mov eax, [SLOT_BASE+eax+APPDATA.process]
test eax, eax
jz .exit
stdcall map_page, [ipc_pdir], eax, PG_UW
mov [process], eax
mov ebx, [ofs]
shr ebx, 22
mov esi, [ipc_pdir]
mov edi, [ipc_ptab]
mov eax, [esi+ebx*4]
mov eax, [eax+PROC.pdt_0+ebx*4] ;get page table
mov esi, [ipc_ptab]
and eax, 0xFFFFF000
jz .exit
stdcall map_page, edi, eax, PG_UW
; inc ebx
; add edi, 0x1000
; mov eax, [esi+ebx*4]
; test eax, eax
; jz @f
; and eax, 0xFFFFF000
; stdcall map_page, edi, eax
stdcall map_page, esi, eax, PG_SW
@@:
mov edi, [lin_addr]
and edi, 0xFFFFF000
mov ecx, [buf_size]
add ecx, 4095
shr ecx, 12
inc ecx
inc ecx ; ???????????
mov edx, [ofs]
shr edx, 12
and edx, 0x3FF
mov esi, [ipc_ptab]
.map:
stdcall safe_map_page, [slot], [req_access], [ofs]
jnc .exit
add dword [ebp-4], 4096
add [ofs], 4096
add [count], PAGE_SIZE
add [ofs], PAGE_SIZE
dec ecx
jz .exit
add edi, 0x1000
add edi, PAGE_SIZE
inc edx
cmp edx, 0x400
cmp edx, 1024
jnz .map
inc ebx
mov eax, [ipc_pdir]
mov eax, [eax+ebx*4]
mov eax, [process]
mov eax, [eax+PROC.pdt_0+ebx*4]
and eax, 0xFFFFF000
jz .exit
stdcall map_page, esi, eax, PG_UW
stdcall map_page, esi, eax, PG_SW
xor edx, edx
jmp .map
.exit:
pop eax
mov eax, [count]
ret
endp
proc map_memEx stdcall, lin_addr:dword,slot: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
jz .exit
mov eax, [slot]
shl eax, 8
mov eax, [SLOT_BASE+eax+APPDATA.dir_table]
and eax, 0xFFFFF000
stdcall map_page, [proc_mem_pdir], eax, PG_UW
mov ebx, [ofs]
shr ebx, 22
mov esi, [proc_mem_pdir]
mov edi, [proc_mem_tab]
mov eax, [esi+ebx*4]
and eax, 0xFFFFF000
mov eax, [SLOT_BASE+eax+APPDATA.process]
test eax, eax
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]
and edi, 0xFFFFF000
mov ecx, [buf_size]
add ecx, 4095
shr ecx, 12
inc ecx
inc ecx ; ???????????
mov edx, [ofs]
shr edx, 12
and edx, 0x3FF
mov esi, [proc_mem_tab]
.map:
stdcall safe_map_page, [slot], [req_access], [ofs]
jnc .exit
add dword [ebp-4], 0x1000
add edi, 0x1000
add [ofs], 0x1000
inc edx
add [count], PAGE_SIZE
add [ofs], PAGE_SIZE
dec ecx
jz .exit
add edi, PAGE_SIZE
inc edx
cmp edx, 1024
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:
pop eax
mov eax, [count]
ret
endp
@ -988,7 +962,8 @@ proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword
push ebx ecx
mov eax, [slot]
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
jz .no_hdll
mov ecx, [eax+HDLL.fd]
@ -1075,29 +1050,6 @@ sys_IPC:
mov [esp+32], eax
ret
;align 4
;proc set_ipc_buff
; mov eax,[current_slot]
; pushf
; cli
; mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area
; mov [eax+APPDATA.ipc_size],ecx
;
; add ecx, ebx
; add ecx, 4095
; and ecx, not 4095
;
;.touch: mov eax, [ebx]
; add ebx, 0x1000
; cmp ebx, ecx
; jb .touch
;
; popf
; xor eax, eax
; ret
;endp
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
locals
dst_slot dd ?
@ -1116,7 +1068,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
mov [dst_slot], eax
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
jz .no_ipc_area
@ -1124,7 +1076,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
and ebx, 0xFFF
mov [dst_offset], ebx
mov esi, [eax+SLOT_BASE+0xa4]
mov esi, [eax+SLOT_BASE+APPDATA.ipc_size]
mov [buf_size], esi
mov ecx, [ipc_tmp]
@ -1137,7 +1089,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
pop edi esi
@@:
mov [used_buf], ecx
stdcall map_mem, ecx, [dst_slot], \
stdcall map_mem_ipc, ecx, [dst_slot], \
edi, esi, PG_SW
mov edi, [dst_offset]
@ -1208,7 +1160,7 @@ proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
.ret:
mov eax, [used_buf]
cmp eax, [ipc_tmp]
jz @f
je @f
stdcall free_kernel_space, eax
@@:
pop eax

View File

@ -847,7 +847,7 @@ proc mtrr_validate
dec eax
; LFB is mapped to virtual address LFB_BASE,
; 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
jnz @f
mov ebx, [page_tabs+(LFB_BASE shr 10)]

View File

@ -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_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4]
; set new thread memory-map
mov ecx, APPDATA.dir_table
mov eax, [ebx+ecx] ;offset>0x7F
cmp eax, [esi+ecx] ;offset>0x7F
mov eax, [ebx+APPDATA.process]
cmp eax, [current_process]
je @f
mov [current_process], eax
mov eax, [eax+PROC.pdt_0_phys]
mov cr3, eax
@@:
; set tss.esp0
@ -142,7 +143,7 @@ do_change_task:
jz @f
xor eax, eax
mov dr6, eax
lea esi, [ebx+ecx+APPDATA.dbg_regs-APPDATA.dir_table];offset>0x7F
lea esi, [ebx+APPDATA.dbg_regs]
cld
macro lodsReg [reg] {
lodsd

View File

@ -413,23 +413,26 @@ endg
align 4
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
shl esi, 8
cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
jne @F
mov edx, [SLOT_BASE+esi+APPDATA.process]
test edx, edx
jnz @F
pop esi
shl esi, 5
mov [CURRENT_TASK+esi+TASKDATA.state], 9
ret
@@:
push edx ;save .process
lea edx, [SLOT_BASE+esi]
call scheduler_remove_thread
;mov esi,process_terminating
;call sys_msg_board_str
call lock_application_table
; if the process is in V86 mode...
@ -442,14 +445,14 @@ terminate: ; terminate application
; ...it has page directory for V86 mode
mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
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
mov ecx, [esi+12]
mov [eax+SLOT_BASE+APPDATA.io_map], ecx
mov ecx, [esi+8]
mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx
.nov86:
;destroy per-thread kernel objects
mov esi, [.slot]
shl esi, 8
add esi, SLOT_BASE+APP_OBJ_OFFSET
@ -467,11 +470,6 @@ terminate: ; terminate application
pop esi
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]
cmp [fpu_owner], esi ; if user fpu last -> fpu user = 2
jne @F
@ -630,6 +628,9 @@ terminate: ; terminate application
je @F
call free_page
@@:
lea ebx, [edi+APPDATA.list]
list_del ebx ;destroys edx, ecx
mov eax, 0x20202020
stosd
stosd
@ -745,7 +746,17 @@ terminate: ; terminate application
add ecx, 0x100
jmp .xd0
.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
mov eax, [draw_limits.left]
@ -760,18 +771,10 @@ terminate: ; terminate application
call unlock_application_table
;mov esi,process_terminated
;call sys_msg_board_str
add esp, 4
add esp, 8
ret
restore .slot
;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
restore .process
; Three following procedures are used to guarantee that
; some part of kernel code will not be terminated from outside

View File

@ -70,7 +70,7 @@ proc fs_execute
filename rd 256 ;1024/4
flags dd ?
save_cr3 dd ?
save_proc dd ?
slot dd ?
slot_base dd ?
file_base dd ?
@ -215,7 +215,7 @@ proc fs_execute
call lock_application_table
call get_new_process_place
call alloc_thread_slot
test eax, eax
mov esi, -0x20 ; too many processes
jz .err
@ -248,18 +248,23 @@ proc fs_execute
loop .copy_process_name_loop
.copy_process_name_done:
mov ebx, cr3
mov [save_cr3], ebx
mov ebx, [current_process]
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
test eax, eax
jz .failed
mov ebx, [hdr_mem]
mov [eax+PROC.mem_used], ebx
mov ebx, [slot_base]
mov [ebx+APPDATA.dir_table], eax
mov eax, [hdr_mem]
mov [ebx+APPDATA.mem_size], eax
mov [ebx+APPDATA.process], eax
lea edx, [ebx+APPDATA.list]
lea ecx, [eax+PROC.thr_list]
list_add_tail edx, ecx
xor edx, edx
cmp word [6], '02'
@ -292,7 +297,7 @@ end if
lea ecx, [filename]
stdcall set_app_params , [slot], eax, ebx, ecx, [flags]
mov eax, [save_cr3]
mov eax, [save_proc]
call set_cr3
mov eax, [process_number];set result
@ -301,7 +306,7 @@ end if
jmp .final
.failed:
mov eax, [save_cr3]
mov eax, [save_proc]
call set_cr3
.err:
.err_hdr:
@ -385,53 +390,55 @@ test_app_header:
ret
align 4
proc get_new_process_place
alloc_thread_slot:
;input:
; none
;result:
; eax=[new_process_place]<>0 - ok
; eax=[new_thread_slot]<>0 - ok
; 0 - failed.
;This function find least empty slot.
;It doesn't increase [TASK_COUNT]!
mov eax, CURRENT_TASK
mov ebx, [TASK_COUNT]
inc ebx
shl ebx, 5
add ebx, eax ;ebx - address of process information for (last+1) slot
.newprocessplace:
;eax = address of process information for current slot
cmp eax, ebx
jz .endnewprocessplace ;empty slot after high boundary
add eax, 0x20
cmp word [eax+0xa], 9;check process state, 9 means that process slot is empty
jnz .newprocessplace
.endnewprocessplace:
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:
mov edx, thr_slot_map
pushfd
cli
.l1:
bsf eax, [edx]
jnz .found
add edx, 4
cmp edx, thr_slot_map+32
jb .l1
popfd
xor eax, eax
ret
endp
.found:
btr [edx], eax
sub edx, thr_slot_map
lea eax, [eax+edx*8]
popfd
ret
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
app_pages dd ?
img_pages dd ?
dir_addr dd ?
process dd ?
app_tabs dd ?
endl
push ebx
push esi
push edi
mov ecx, pg_data.mutex
call mutex_lock
xor eax, eax
mov [dir_addr], eax
mov [process], eax
mov eax, [app_size]
add eax, 4095
@ -454,39 +461,48 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
shr ecx, 12
mov [img_pages], ecx
if GREEDY_KERNEL
lea eax, [ecx+ebx+2];only image size
else
lea eax, [eax+ebx+2];all requested memory
end if
cmp eax, [pg_data.pages_free]
ja .fail
call alloc_page
stdcall kernel_alloc, 0x2000
test eax, eax
jz .fail
mov [dir_addr], eax
stdcall map_page, [tmp_task_pdir], eax, dword PG_SW
mov [process], eax
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
cld
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 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
mov eax, [dir_addr]
mov eax, [edi-8192+PROC.pdt_0_phys]
or eax, PG_SW
mov [edi-4096+(page_tabs shr 20)], eax
and eax, -4096
lea eax, [edi-8192]
call set_cr3
mov edx, [app_tabs]
mov edi, new_app_base
xor edi, edi
@@:
call alloc_page
test eax, eax
@ -497,9 +513,7 @@ end if
dec edx
jnz @B
mov edi, new_app_base
shr edi, 10
add edi, page_tabs
mov edi, page_tabs
mov ecx, [app_tabs]
shl ecx, 10
@ -508,13 +522,11 @@ end if
mov ecx, [img_pages]
mov ebx, PG_UW
mov edx, new_app_base
xor edx, edx
mov esi, [img_base]
mov edi, new_app_base
shr esi, 10
shr edi, 10
add esi, page_tabs
add edi, page_tabs
mov edi, page_tabs
.remap:
lodsd
and eax, 0xFFFFF000
@ -529,11 +541,6 @@ end if
test ecx, ecx
jz .done
if GREEDY_KERNEL
mov eax, 0x02
rep stosd
else
.alloc:
call alloc_page
test eax, eax
@ -543,32 +550,40 @@ else
add edx, 0x1000
dec [app_pages]
jnz .alloc
end if
.done:
stdcall map_page, [tmp_task_pdir], dword 0, dword PG_UNMAP
mov ecx, pg_data.mutex
call mutex_unlock
mov eax, [dir_addr]
mov eax, [process]
pop edi
pop esi
pop ebx
ret
.fail:
mov ecx, pg_data.mutex
call mutex_unlock
cmp [dir_addr], 0
cmp [process], 0
je @f
stdcall destroy_app_space, [dir_addr], 0
;; stdcall destroy_app_space, [dir_addr], 0
@@:
xor eax, eax
pop edi
pop esi
pop ebx
ret
endp
align 4
set_cr3:
pushfd
cli
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
popfd
ret
align 4
@ -582,6 +597,8 @@ proc destroy_page_table stdcall, pg_tab:dword
mov eax, [esi]
test eax, 1
jz .next
test eax, 2
jz .next
test eax, 1 shl 9
jnz .next ;skip shared pages
call free_page
@ -594,46 +611,25 @@ proc destroy_page_table stdcall, pg_tab:dword
endp
align 4
proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword
destroy_process: ;fastcall ecx= ptr to process
xor edx, edx
push edx
mov eax, 0x1
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
lea eax, [ecx+PROC.thr_list]
cmp eax, [eax+LHEAD.next]
jne .exit
;edx = number of threads
;our process is zombi so it isn't counted
pop ecx
cmp edx, 1
jg .ret
;if there isn't threads then clear memory.
mov esi, [dlls_list]
call destroy_all_hdlls;ecx=APPDATA
align 4
.internal:
push ecx
mov ecx, pg_data.mutex
call mutex_lock
mov esi, [ecx+PROC.dlls_list_ptr]
call destroy_all_hdlls
mov eax, [pg_dir]
and eax, not 0xFFF
stdcall map_page, [tmp_task_pdir], eax, PG_SW
mov esi, [tmp_task_pdir]
mov edi, (OS_BASE shr 20)/4
; mov ecx, pg_data.mutex
; call mutex_lock
mov esi, [esp]
add esi, PROC.pdt_0
mov edi, (0x80000000 shr 20)/4
.destroy:
mov eax, [esi]
test eax, 1
@ -648,16 +644,13 @@ proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword
dec edi
jnz .destroy
mov eax, [pg_dir]
call free_page
.exit:
call kernel_free ;ecx still in stack
stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP
stdcall map_page, [tmp_task_pdir], 0, PG_UNMAP
mov ecx, pg_data.mutex
call mutex_unlock
.ret:
; mov ecx, pg_data.mutex
; call mutex_unlock
.exit:
ret
endp
align 4
get_pid:
@ -708,6 +701,10 @@ check_region:
;result:
; eax = 1 region lays in app memory
; eax = 0 region don't lays in app memory
mov eax, 1
ret
if 0
mov eax, [CURRENT_TASK]
; jmp check_process_region
;-----------------------------------------------------------------------------
@ -732,57 +729,13 @@ check_region:
mov eax, 1
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:
mov eax, 1
ret
;
;.failed1:
; pop edx
; pop ecx
; pop ebx
.failed:
xor eax, eax
ret
end if
align 4
proc read_process_memory
@ -954,7 +907,7 @@ proc new_sys_threads
call lock_application_table
call get_new_process_place
call alloc_thread_slot
test eax, eax
jz .failed
@ -976,20 +929,12 @@ proc new_sys_threads
mov ecx, 11
rep movsb ;copy process name
mov eax, [ebx+APPDATA.heap_base]
mov [edx+APPDATA.heap_base], eax
mov eax, [ebx+APPDATA.process]
mov [edx+APPDATA.process], eax
mov ecx, [ebx+APPDATA.heap_top]
mov [edx+APPDATA.heap_top], ecx
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
lea ebx, [edx+APPDATA.list]
lea ecx, [eax+PROC.thr_list]
list_add_tail ebx, ecx ;add thread to process child's list
mov eax, [ebx+APPDATA.tls_base]
test eax, eax
@ -1118,8 +1063,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\
add eax, 256
jc @f
cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
ja @f
; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
; ja @f
mov eax, [cmd_line]
@ -1158,8 +1103,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\
mov eax, edx
add eax, 1024
jc @f
cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
ja @f
; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
; ja @f
stdcall strncpy, edx, [app_path], 1024
@@:
mov ebx, [slot]

View File

@ -14,9 +14,7 @@ DEBUG_SHOW_IO = 0
struct V86_machine
; page directory
pagedir dd ?
; translation table: V86 address -> flat linear address
pages dd ?
process dd ?
; mutex to protect all data from writing by multiple threads at one time
mutex dd ?
; i/o permission map
@ -38,91 +36,87 @@ v86_create:
and dword [eax+V86_machine.mutex], 0
; allocate tables
mov ebx, eax
; We allocate 4 pages.
; First is main page directory for V86 mode.
; Second page:
; first half (0x800 bytes) is page table for addresses 0 - 0x100000,
; second half is for V86-to-linear translation.
; Third and fourth are for I/O permission map.
push 8000h ; blocks less than 8 pages are discontinuous
stdcall create_process, 4096, OS_BASE, 4096
test eax, eax
jz .fail2
mov [eax+PROC.mem_used], 4096
mov [ebx+V86_machine.process], eax
push 2000h
call kernel_alloc
test eax, eax
jz .fail2
mov [ebx+V86_machine.pagedir], eax
push edi eax
mov edi, eax
add eax, 1800h
mov [ebx+V86_machine.pages], eax
mov [ebx+V86_machine.iopm], eax
; initialize tables
mov ecx, 2000h/4
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...
push edi
mov edi, eax
add eax, 1000h
push eax
call get_pg_addr
or al, PG_UW
stosd
; ...and also copy system page tables
; thx to Serge, system is located at high addresses
add edi, (OS_BASE shr 20) - 4
push esi
mov esi, (OS_BASE shr 20) + sys_pgdir
mov ecx, 0x80000000 shr 22
rep movsd
mov eax, -1
mov ecx, 2000h/4
rep stosd
mov eax, [ebx+V86_machine.process]
mov eax, [eax+PROC.pdt_0_phys]
pushfd
cli
mov cr3, eax
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
pop eax
; first page - BIOS data (shared between all machines!)
; physical address = 0
; 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!)
; physical address = 0x9C000
; linear address = 0x8009C000
; (I have seen one computer with EBDA segment = 0x9D80,
; all other computers use less memory)
mov ecx, 4
mov edx, 0x9C000
push eax
lea edi, [eax+0x9C*4]
mov eax, PG_UW
mov [page_tabs], eax
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
add edx, 0x1000
add eax, edx
loop @b
pop eax
pop edi
; addresses 0xC0000 - 0xFFFFF - BIOS code (shared between all machines!)
; 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
shl edx, 12
push edx
or edx, 111b
mov [eax+ecx*4], edx
pop edx
add edx, OS_BASE
mov [eax+ecx*4+0x800], edx
inc cl
jnz @b
stosd
add eax, edx
loop @b
mov eax, sys_proc
push ebx
call set_cr3
pop ebx
popfd
pop edi
mov eax, ebx
ret
.fail2:
@ -132,15 +126,16 @@ v86_create:
xor eax, eax
ret
;not used
; Destroy V86 machine
; in: eax = handle
; out: nothing
; destroys: eax, ebx, ecx, edx (due to free)
v86_destroy:
push eax
stdcall kernel_free, [eax+V86_machine.pagedir]
pop eax
jmp free
;v86_destroy:
; push eax
; stdcall kernel_free, [eax+V86_machine.pagedir]
; pop eax
; jmp free
; Translate V86-address to linear address
; in: eax=V86 address
@ -150,28 +145,30 @@ v86_destroy:
v86_get_lin_addr:
push ecx edx
mov ecx, eax
mov edx, [esi+V86_machine.pages]
shr ecx, 12
mov edx, [page_tabs+ecx*4]
and eax, 0xFFF
add eax, [edx+ecx*4] ; atomic operation, no mutex needed
and edx, 0xFFFFF000
or eax, edx
pop edx ecx
ret
;not used
; Sets linear address for V86-page
; in: eax=linear address (must be page-aligned)
; ecx=V86 page (NOT address!)
; esi=handle
; out: nothing
; destroys: nothing
v86_set_page:
push eax ebx
mov ebx, [esi+V86_machine.pagedir]
mov [ebx+ecx*4+0x1800], eax
call get_pg_addr
or al, 111b
mov [ebx+ecx*4+0x1000], eax
pop ebx eax
ret
;v86_set_page:
; push eax ebx
; mov ebx, [esi+V86_machine.pagedir]
; mov [ebx+ecx*4+0x1800], eax
; call get_pg_addr
; or al, 111b
; mov [ebx+ecx*4+0x1000], eax
; pop ebx eax
; ret
; Allocate memory in V86 machine
; in: eax=size (in bytes)
@ -214,21 +211,7 @@ init_sys_v86:
mov [sys_v86_machine], eax
test eax, eax
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 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
; allow access to all ports
mov ecx, [esi+V86_machine.iopm]
@ -272,36 +255,38 @@ ends
; eax = 3 - IRQ is already hooked by another VM
; destroys: nothing
v86_start:
pushad
cli
mov ecx, [CURRENT_TASK]
shl ecx, 8
add ecx, SLOT_BASE
mov ecx, [current_slot]
mov eax, [esi+V86_machine.iopm]
call get_pg_addr
inc eax
push dword [ecx+APPDATA.io_map]
push dword [ecx+APPDATA.io_map+4]
mov dword [ecx+APPDATA.io_map], eax
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.process]
push [ecx+APPDATA.saved_esp0]
mov [ecx+APPDATA.saved_esp0], esp
mov [tss._esp0], esp
mov eax, [esi+V86_machine.pagedir]
mov eax, [esi+V86_machine.iopm]
call get_pg_addr
mov [ecx+APPDATA.dir_table], eax
mov cr3, eax
inc 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
; machine is running
@ -782,19 +767,21 @@ end if
mov esp, esi
cli
mov ecx, [CURRENT_TASK]
shl ecx, 8
mov ecx, [current_slot]
pop eax
mov [SLOT_BASE+ecx+APPDATA.saved_esp0], eax
mov [ecx+APPDATA.saved_esp0], eax
mov [tss._esp0], eax
pop eax
mov [SLOT_BASE+ecx+APPDATA.dir_table], eax
mov [ecx+APPDATA.process], eax
mov [current_process], eax
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
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 eax, [eax+PROC.pdt_0_phys]
mov cr3, eax
sti
@ -843,11 +830,10 @@ v86_irq:
pop eax
v86_irq2:
mov esi, [v86_irqhooks+edi*8] ; get VM handle
mov eax, [esi+V86_machine.pagedir]
call get_pg_addr
mov eax, [esi+V86_machine.process]
mov ecx, [CURRENT_TASK]
shl ecx, 8
cmp [SLOT_BASE+ecx+APPDATA.dir_table], eax
cmp [SLOT_BASE+ecx+APPDATA.process], eax
jnz .notcurrent
lea eax, [edi+8]
cmp al, 10h
@ -860,7 +846,7 @@ v86_irq2:
mov ebx, SLOT_BASE + 0x100
mov ecx, [TASK_COUNT]
.scan:
cmp [ebx+APPDATA.dir_table], eax
cmp [ebx+APPDATA.process], eax
jnz .cont
push ecx
mov ecx, [ebx+APPDATA.saved_esp0]
@ -895,6 +881,7 @@ v86_irq2:
popad
iretd
.found:
mov eax, [eax+PROC.pdt_0_phys]
mov cr3, eax
mov esi, [ebx+APPDATA.saved_esp0]
sub word [esi-sizeof.v86_regs+v86_regs.esp], 6

View File

@ -177,7 +177,7 @@ kernel_file_load:
dd 0 ; subfunction
dq 0 ; offset in file
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
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_hash_cnt rd 64
thr_slot_map rd 8
cpu_freq rq 1
heap_mutex MUTEX
@ -436,14 +438,15 @@ proc_mem_map rd 1
proc_mem_pdir rd 1
proc_mem_tab rd 1
tmp_task_pdir rd 1
tmp_task_ptab rd 1
default_io_map rd 1
LFBSize rd 1
current_slot rd 1
current_process rd 1
current_slot rd 1 ; i.e. cureent thread
; status
hd1_status rd 1 ; 0 - free : other - pid

View File

@ -128,12 +128,12 @@ proc init_mem
mov [pg_data.kernel_tables-OS_BASE], edx
xor eax, eax
mov edi, sys_pgdir-OS_BASE
mov ecx, 4096/4
mov edi, sys_proc-OS_BASE
mov ecx, 8192/4
cld
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
jnc .no_PSE
@ -177,9 +177,9 @@ proc init_mem
dec ecx
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)]
movsd
movsd

View File

@ -291,7 +291,7 @@ B32:
; ENABLE PAGING
mov eax, sys_pgdir-OS_BASE
mov eax, sys_proc-OS_BASE+PROC.pdt_0
mov cr3, eax
mov eax, cr0
@ -354,15 +354,15 @@ high_code:
bt [cpu_caps], CAPS_PGE
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
or ebx, CR4_PGE
mov cr4, ebx
@@:
xor eax, eax
mov dword [sys_pgdir], eax
mov dword [sys_pgdir+4], eax
mov dword [sys_proc+PROC.pdt_0], eax
mov dword [sys_proc+PROC.pdt_0+4], eax
mov eax, cr3
mov cr3, eax ; flush TLB
@ -597,7 +597,7 @@ no_mode_0x12:
call init_fpu
call init_malloc
stdcall alloc_kernel_space, 0x51000
stdcall alloc_kernel_space, 0x50000 ; FIXME check size
mov [default_io_map], eax
add eax, 0x2000
@ -613,9 +613,6 @@ no_mode_0x12:
add eax, ebx
mov [proc_mem_tab], eax
add eax, ebx
mov [tmp_task_pdir], eax
add eax, ebx
mov [tmp_task_ptab], eax
@ -674,7 +671,26 @@ no_mode_0x12:
mov esi, boot_setostask
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]
add ebx, 0x2000
call setup_os_slot
@ -1127,7 +1143,7 @@ ap_init_high:
mov fs, cx
mov gs, bx
xor esp, esp
mov eax, sys_pgdir-OS_BASE
mov eax, sys_proc-OS_BASE+PROC.pdt_0
mov cr3, eax
lock inc [ap_initialized]
jmp idle_loop
@ -1190,7 +1206,11 @@ proc setup_os_slot
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
shr eax, 3
@ -2070,9 +2090,6 @@ restore_default_cursor_before_killing:
movzx eax, word [MOUSE_Y]
movzx ebx, word [MOUSE_X]
; mov ecx, [Screen_Max_X]
; inc ecx
; mul ecx
mov eax, [d_width_calc_area + eax*4]
add eax, [_WinMapAddress]
@ -3087,7 +3104,8 @@ sys_cpuusage:
mov edx, 0x100000*16
cmp ecx, 1 shl 5
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
.os_mem:
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
cpustring db 'CPU',0
endg
@ -3579,7 +3577,7 @@ markz:
cmp [edx+TASKDATA.state], 9
jz .nokill
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
call request_terminate
jmp .common

View File

@ -98,17 +98,33 @@ struct DBG_REGS
dr7 dd ?
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
app_name rb 11
rb 5
fpu_state dd ? ;+16
ev_count_ dd ? ;unused ;+20
exc_handler dd ? ;+24
except_mask dd ? ;+28
pl0_stack dd ? ;+32
heap_base dd ? ;+36
heap_top dd ? ;+40
list LHEAD ;+16
process dd ? ;+24
fpu_state dd ? ;+28
exc_handler dd ? ;+32
except_mask dd ? ;+36
pl0_stack dd ? ;+40
cursor dd ? ;+44
fd_ev dd ? ;+48
bk_ev dd ? ;+52
@ -124,7 +140,7 @@ struct APPDATA
wait_test dd ? ;+96 +++
wait_param dd ? ;+100 +++
tls_base dd ? ;+104
dlls_list_ptr dd ? ;+108
dd ? ;+108
event_filter dd ? ;+112
draw_bgr_x dd ? ;+116
draw_bgr_y dd ? ;+120
@ -133,7 +149,7 @@ struct APPDATA
wnd_shape dd ? ;+128
wnd_shape_scale dd ? ;+132
dd ? ;+136
mem_size dd ? ;+140
dd ? ;+140
saved_box BOX ;+144
ipc_start dd ? ;+160
ipc_size dd ? ;+164
@ -142,7 +158,7 @@ struct APPDATA
terminate_protection dd ? ;+176
keyboard_mode db ? ;+180
rb 3
dir_table dd ? ;+184
dd ? ;+184
dbg_event_mem dd ? ;+188
dbg_regs DBG_REGS ;+192
wnd_caption dd ? ;+212

View File

@ -89,6 +89,12 @@ macro Mov op1,op2,op3 ; op1 = op2 = op3
mov op1, op2
}
macro list_init head
{
mov [head+LHEAD.next], head
mov [head+LHEAD.prev], head
}
macro __list_add new, prev, next
{
mov [next+LHEAD.prev], new
@ -111,10 +117,10 @@ macro list_add_tail new, head
macro list_del entry
{
mov edx, [entry+list_fd]
mov ecx, [entry+list_bk]
mov [edx+list_bk], ecx
mov [ecx+list_fd], edx
mov edx, [entry+LHEAD.next]
mov ecx, [entry+LHEAD.prev]
mov [edx+LHEAD.prev], ecx
mov [ecx+LHEAD.next], edx
}
; MOV Immediate.