kernel support for loading compressed apps - part 2

git-svn-id: svn://kolibrios.org@269 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2007-01-10 21:25:55 +00:00
parent 62f0273742
commit 2f3e0a30ee
3 changed files with 88 additions and 66 deletions

View File

@ -544,6 +544,16 @@ proc load_file stdcall, file_name:dword
mov eax, [file2] mov eax, [file2]
mov ebx, [file_size] mov ebx, [file_size]
.exit: .exit:
push eax
lea edi, [eax+ebx] ;cleanup remain space
mov ecx, ebx ;from file end
add ecx, 4095
and ecx, not 4095
sub ecx, ebx
xor eax, eax
cld
rep stosb
pop eax
ret ret
.cleanup: .cleanup:
stdcall kernel_free, [file] stdcall kernel_free, [file]

View File

@ -72,7 +72,7 @@ macro _clear_ op
} }
align 4 align 4
proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword proc fs_exec stdcall file_name:dword, cmd_line:dword, flags:dword
locals locals
save_cr3 dd ? save_cr3 dd ?
slot dd ? slot dd ?
@ -85,6 +85,7 @@ proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
app_eip dd ? ;0x08 app_eip dd ? ;0x08
app_esp dd ? ;0x0C app_esp dd ? ;0x0C
app_mem dd ? ;0x10 app_mem dd ? ;0x10
app_i_end dd ? ;0x14
endl endl
stdcall load_file,[file_name] stdcall load_file,[file_name]
@ -95,9 +96,6 @@ proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
mov [file_base], eax mov [file_base], eax
mov [file_size], ebx mov [file_size], ebx
pushfd
cli
lea ebx, [app_cmdline] lea ebx, [app_cmdline]
call test_app_header call test_app_header
mov ecx, -0x1F mov ecx, -0x1F
@ -119,12 +117,15 @@ proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
cmp eax, 0 cmp eax, 0
jne .wait_lock jne .wait_lock
pushfd
cli
call set_application_table_status call set_application_table_status
call get_new_process_place call get_new_process_place
test eax, eax test eax, eax
mov ecx, -0x20 ; too many processes mov ecx, -0x20 ; too many processes
jz .err_hdr jz .err
mov [slot], eax mov [slot], eax
shl eax, 8 shl eax, 8
@ -157,11 +158,8 @@ proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
mov ebx, cr3 mov ebx, cr3
mov [save_cr3], ebx mov [save_cr3], ebx
if GREEDY_KERNEL
stdcall create_app_space,[app_mem],[file_size] stdcall create_app_space,[app_mem],[file_base],[file_size]
else
stdcall create_app_space,[app_mem],[app_mem]
end if
test eax, eax test eax, eax
jz .failed jz .failed
@ -170,19 +168,24 @@ proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
mov eax,[app_mem] mov eax,[app_mem]
mov [ebx+APPDATA.mem_size],eax mov [ebx+APPDATA.mem_size],eax
mov ecx, [file_size] if not GREEDY_KERNEL
mov eax, ecx mov ecx, [app_i_end]
shr ecx, 2 mov edi, [file_size]
mov esi, [file_base] add edi, 4095
mov edi, new_app_base and edi, not 4095
sub ecx, edi
jna @F
xor eax, eax
add edi, new_app_base
cld cld
rep movsd rep stosb
and eax, 3
jz @F
mov ecx, eax
rep movsb
@@: @@:
stdcall kernel_free, [file_base] end if
; release only virtual space, not phisical memory
stdcall free_kernel_space, [file_base]
lea eax, [app_cmdline] lea eax, [app_cmdline]
stdcall set_app_params ,[slot],eax,[cmd_line],\ stdcall set_app_params ,[slot],eax,[cmd_line],\
[file_name], [flags] [file_name], [flags]
@ -198,9 +201,10 @@ proc fs_exec_EX stdcall file_name:dword, cmd_line:dword, flags:dword
.failed: .failed:
mov eax, [save_cr3] mov eax, [save_cr3]
call set_cr3 call set_cr3
.err:
popfd
.err_hdr: .err_hdr:
stdcall kernel_free,[file_base] stdcall kernel_free,[file_base]
popfd
.err_file: .err_file:
xor eax, eax xor eax, eax
mov [application_table_status],eax mov [application_table_status],eax
@ -234,6 +238,8 @@ test_app_header:
mov ecx,[APP_HEADER_00.i_param] mov ecx,[APP_HEADER_00.i_param]
mov [ebx], ecx ;app_cmdline mov [ebx], ecx ;app_cmdline
mov [ebx+4], dword 0 ;app_path mov [ebx+4], dword 0 ;app_path
mov edx, [APP_HEADER_00.i_end]
mov [ebx+0x14], edx
ret ret
.check_01_header: .check_01_header:
@ -251,6 +257,8 @@ test_app_header:
mov [ebx], edx ;app_cmdline mov [ebx], edx ;app_cmdline
mov ecx,[APP_HEADER_01.i_icon] mov ecx,[APP_HEADER_01.i_icon]
mov [ebx+4], ecx ;app_path mov [ebx+4], ecx ;app_path
mov edx, [APP_HEADER_01.i_end]
mov [ebx+0x14], edx
ret ret
.fail: .fail:
xor eax, eax xor eax, eax
@ -292,8 +300,9 @@ proc get_new_process_place
ret ret
endp endp
align 4 align 4
proc create_app_space stdcall, app_size:dword,img_size:dword proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
locals locals
app_pages dd ? app_pages dd ?
img_pages dd ? img_pages dd ?
@ -379,12 +388,44 @@ proc create_app_space stdcall, app_size:dword,img_size:dword
mov edi, new_app_base mov edi, new_app_base
shr edi, 10 shr edi, 10
add edi, pages_tab add edi, pages_tab
mov ecx, [app_tabs] mov ecx, [app_tabs]
shl ecx, 10 shl ecx, 10
xor eax, eax xor eax, eax
rep stosd rep stosd
mov ecx, [img_pages]
mov ebx, PG_UW
mov edx, new_app_base mov edx, new_app_base
mov esi, [img_base]
mov edi, new_app_base
shr esi, 10
shr edi, 10
add esi, pages_tab
add edi, pages_tab
.remap:
lodsd
or eax, ebx ; force user level r/w access
stosd
add edx, 0x1000
dec [app_pages]
dec ecx
jnz .remap
mov ecx, [app_pages]
test ecx, ecx
jz .done
if GREEDY_KERNEL
mov eax, 0x02
.reserve:
stosd
invlpg [edx]
add edx, 4096
dec ecx
jnz .reserve
else
.alloc: .alloc:
call alloc_page call alloc_page
test eax, eax test eax, eax
@ -392,30 +433,12 @@ proc create_app_space stdcall, app_size:dword,img_size:dword
stdcall map_page,edx,eax,dword PG_UW stdcall map_page,edx,eax,dword PG_UW
add edx, 0x1000 add edx, 0x1000
sub [app_pages], 1 dec [app_pages]
sub [img_pages], 1
jnz .alloc jnz .alloc
mov ecx, [app_pages] end if
and ecx, ecx
jz .next
mov ebx, edx
shr edx, 12
.reserve:
mov dword [pages_tab+edx*4], 0x02
invlpg [ebx]
inc edx
dec ecx
jnz .reserve
.next:
mov edi, new_app_base
mov ecx, [img_size]
shr ecx, 2
xor eax, eax
cld
rep stosd
.done:
stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP
dec [pg_data.pg_mutex] dec [pg_data.pg_mutex]
@ -431,6 +454,8 @@ proc create_app_space stdcall, app_size:dword,img_size:dword
ret ret
endp endp
align 4 align 4
set_cr3: set_cr3:
mov esi, [CURRENT_TASK] mov esi, [CURRENT_TASK]
@ -549,39 +574,26 @@ proc fs_execute
stdcall wait_mutex, pg_data.tmp_task_mutex stdcall wait_mutex, pg_data.tmp_task_mutex
mov edi, [tmp_task_data] mov edi, [tmp_task_data]
mov ecx, (2048+256)/4 mov ecx, (1024+256)/4
xor eax, eax xor eax, eax
rep stosd rep stosd
mov esi, [filename] mov esi, [filename]
mov edi, [tmp_task_data] mov edi, [tmp_task_data]
add edi, TMP_FILE_NAME
mov ecx, 1024
rep movsb
mov esi, [filename]
mov edi, [tmp_task_data]
add edi, TMP_ICON_OFFS
mov ecx, 1024 mov ecx, 1024
rep movsb rep movsb
mov esi, [cmdline] mov esi, [cmdline]
test esi, esi test esi, esi
jz @f jz @f
mov edi, [tmp_task_data]
add edi, TMP_CMD_LINE
mov ecx, 256 mov ecx, 256
rep movsb rep movsb
@@: @@:
mov eax, TMP_FILE_NAME mov eax, [tmp_task_data]
add eax, [tmp_task_data] lea ebx, [eax+1024] ;cmd line
mov ebx, [tmp_task_data] ;cmd line
add ebx, TMP_CMD_LINE
stdcall fs_exec_EX, eax, ebx, [flags] stdcall fs_exec, eax, ebx, [flags]
; stdcall fs_exec, eax, ebx, [flags], [ebp+8],\
; [ebp+12], [ebp+16],[ebp+20]
mov [retval], eax mov [retval], eax
popad popad
mov [pg_data.tmp_task_mutex], 0 mov [pg_data.tmp_task_mutex], 0
@ -1068,7 +1080,7 @@ proc set_app_params stdcall,slot:dword, params:dword,\
mov [edi+TSS._eip],eax ;set eip in TSS mov [edi+TSS._eip],eax ;set eip in TSS
mov eax, [esi+0x0C] ;app_esp mov eax, [esi+0x0C] ;app_esp
mov [edi+TSS._esp],eax ;set stack in TSS mov [edi+TSS._esp],eax ;set stack in TSS
mov [edi+TSS._eflags],dword 0x1202 mov [edi+TSS._eflags],dword 0x3202
mov [edi+TSS._cs],app_code ;selector of code segment mov [edi+TSS._cs],app_code ;selector of code segment
mov [edi+TSS._ss],app_data mov [edi+TSS._ss],app_data

View File

@ -697,12 +697,12 @@ include 'vmodeld.inc'
cmp byte [0x2f0000+0x9030],1 cmp byte [0x2f0000+0x9030],1
jne no_load_vrr_m jne no_load_vrr_m
stdcall fs_exec_EX, vrr_m, dword 0, dword 0 stdcall fs_exec, vrr_m, 0, 0
cmp eax,2 ; if vrr_m app found (PID=2) cmp eax,2 ; if vrr_m app found (PID=2)
je first_app_found je first_app_found
no_load_vrr_m: no_load_vrr_m:
stdcall fs_exec_EX, firstapp, dword 0, dword 0 stdcall fs_exec, firstapp, 0, 0
cmp eax,2 ; continue if a process has been loaded cmp eax,2 ; continue if a process has been loaded
je first_app_found je first_app_found
mov eax, 0xDEADBEEF ; otherwise halt mov eax, 0xDEADBEEF ; otherwise halt
@ -905,14 +905,14 @@ reserve_irqs_ports:
mov [0x2d0000+edi+0],dword 1 mov [0x2d0000+edi+0],dword 1
mov [0x2d0000+edi+4],dword 0x0 mov [0x2d0000+edi+4],dword 0x0
mov [0x2d0000+edi+8],dword 0x2d mov [0x2d0000+edi+8],dword 0x2d
inc dword [0x2d0000] ; 0x30-0x4d inc dword [0x2d0000] ; 0x30-0x4d
mov edi,[0x2d0000] mov edi,[0x2d0000]
shl edi,4 shl edi,4
mov [0x2d0000+edi+0],dword 1 mov [0x2d0000+edi+0],dword 1
mov [0x2d0000+edi+4],dword 0x30 mov [0x2d0000+edi+4],dword 0x30
mov [0x2d0000+edi+8],dword 0x4d mov [0x2d0000+edi+8],dword 0x4d
inc dword [0x2d0000] ; 0x50-0xdf inc dword [0x2d0000] ; 0x50-0xdf
mov edi,[0x2d0000] mov edi,[0x2d0000]
shl edi,4 shl edi,4