2009-09-17 13:55:38 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-04-02 17:18:46 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2009-09-17 13:55:38 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2012-04-02 17:18:46 +02:00
|
|
|
$Revision $
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
include 'export.inc'
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
|
|
|
proc load_PE stdcall, file_name:dword
|
|
|
|
locals
|
|
|
|
image dd ?
|
|
|
|
entry dd ?
|
|
|
|
base dd ?
|
|
|
|
endl
|
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
stdcall load_file, [file_name]
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
mov [image], eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
mov edx, [eax+60]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
stdcall kernel_alloc, [eax+80+edx]
|
|
|
|
test eax, eax
|
|
|
|
jz .cleanup
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
mov [base], eax
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
stdcall map_PE, eax, [image]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
mov [entry], eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .cleanup
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
stdcall kernel_free, [base]
|
2009-09-17 13:55:38 +02:00
|
|
|
.cleanup:
|
2012-02-22 17:06:05 +01:00
|
|
|
stdcall kernel_free, [image]
|
|
|
|
mov eax, [entry]
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
.fail:
|
2012-02-22 17:06:05 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2009-09-17 13:55:38 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
DWORD equ dword
|
|
|
|
PTR equ
|
|
|
|
|
|
|
|
align 4
|
|
|
|
map_PE: ;stdcall base:dword, image:dword
|
2012-02-22 17:06:05 +01:00
|
|
|
cld
|
2009-09-17 13:55:38 +02:00
|
|
|
push ebp
|
2012-02-22 17:06:05 +01:00
|
|
|
push edi
|
|
|
|
push esi
|
|
|
|
push ebx
|
|
|
|
sub esp, 60
|
|
|
|
mov ebx, DWORD PTR [esp+84]
|
|
|
|
mov ebp, DWORD PTR [esp+80]
|
|
|
|
mov edx, ebx
|
|
|
|
mov esi, ebx
|
|
|
|
add edx, DWORD PTR [ebx+60]
|
|
|
|
mov edi, ebp
|
|
|
|
mov DWORD PTR [esp+32], edx
|
|
|
|
mov ecx, DWORD PTR [edx+84]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
movzx eax, WORD PTR [edx+6]
|
|
|
|
mov DWORD PTR [esp+36], 0
|
|
|
|
mov DWORD PTR [esp+16], eax
|
|
|
|
jmp L2
|
2009-09-17 13:55:38 +02:00
|
|
|
L3:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov eax, DWORD PTR [edx+264]
|
|
|
|
test eax, eax
|
|
|
|
je L4
|
|
|
|
mov esi, ebx
|
|
|
|
mov edi, ebp
|
|
|
|
add esi, DWORD PTR [edx+268]
|
|
|
|
mov ecx, eax
|
|
|
|
add edi, DWORD PTR [edx+260]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
L4:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov ecx, DWORD PTR [edx+256]
|
|
|
|
add ecx, 4095
|
|
|
|
and ecx, -4096
|
|
|
|
cmp ecx, eax
|
|
|
|
jbe L6
|
|
|
|
sub ecx, eax
|
|
|
|
add eax, DWORD PTR [edx+260]
|
|
|
|
lea edi, [eax+ebp]
|
2009-09-17 13:55:38 +02:00
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
xor eax, eax
|
|
|
|
rep stosb
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
L6:
|
2012-02-22 17:06:05 +01:00
|
|
|
inc DWORD PTR [esp+36]
|
|
|
|
add edx, 40
|
2009-09-17 13:55:38 +02:00
|
|
|
L2:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov esi, DWORD PTR [esp+16]
|
|
|
|
cmp DWORD PTR [esp+36], esi
|
|
|
|
jne L3
|
|
|
|
mov edi, DWORD PTR [esp+32]
|
|
|
|
cmp DWORD PTR [edi+164], 0
|
|
|
|
je L9
|
|
|
|
mov esi, ebp
|
|
|
|
mov ecx, ebp
|
|
|
|
sub esi, DWORD PTR [edi+52]
|
|
|
|
add ecx, DWORD PTR [edi+160]
|
|
|
|
mov eax, esi
|
|
|
|
shr eax, 16
|
|
|
|
mov DWORD PTR [esp+12], eax
|
|
|
|
jmp L11
|
2009-09-17 13:55:38 +02:00
|
|
|
L12:
|
2012-02-22 17:06:05 +01:00
|
|
|
lea ebx, [eax-8]
|
|
|
|
xor edi, edi
|
|
|
|
shr ebx, 1
|
|
|
|
jmp L13
|
2009-09-17 13:55:38 +02:00
|
|
|
L14:
|
2012-02-22 17:06:05 +01:00
|
|
|
movzx eax, WORD PTR [ecx+8+edi*2]
|
|
|
|
mov edx, eax
|
|
|
|
shr eax, 12
|
|
|
|
and edx, 4095
|
|
|
|
add edx, DWORD PTR [ecx]
|
|
|
|
cmp ax, 2
|
|
|
|
je L17
|
|
|
|
cmp ax, 3
|
|
|
|
je L18
|
|
|
|
dec ax
|
|
|
|
jne L15
|
|
|
|
mov eax, DWORD PTR [esp+12]
|
|
|
|
add WORD PTR [edx+ebp], ax
|
2009-09-17 13:55:38 +02:00
|
|
|
L17:
|
2012-02-22 17:06:05 +01:00
|
|
|
add WORD PTR [edx+ebp], si
|
2009-09-17 13:55:38 +02:00
|
|
|
L18:
|
2012-02-22 17:06:05 +01:00
|
|
|
add DWORD PTR [edx+ebp], esi
|
2009-09-17 13:55:38 +02:00
|
|
|
L15:
|
2012-02-22 17:06:05 +01:00
|
|
|
inc edi
|
2009-09-17 13:55:38 +02:00
|
|
|
L13:
|
2012-02-22 17:06:05 +01:00
|
|
|
cmp edi, ebx
|
|
|
|
jne L14
|
|
|
|
add ecx, DWORD PTR [ecx+4]
|
2009-09-17 13:55:38 +02:00
|
|
|
L11:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov eax, DWORD PTR [ecx+4]
|
|
|
|
test eax, eax
|
|
|
|
jne L12
|
2009-09-17 13:55:38 +02:00
|
|
|
L9:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov edx, DWORD PTR [esp+32]
|
|
|
|
cmp DWORD PTR [edx+132], 0
|
|
|
|
je L20
|
|
|
|
mov eax, ebp
|
|
|
|
add eax, DWORD PTR [edx+128]
|
|
|
|
mov DWORD PTR [esp+40], 0
|
|
|
|
add eax, 20
|
|
|
|
mov DWORD PTR [esp+56], eax
|
2009-09-17 13:55:38 +02:00
|
|
|
L22:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov ecx, DWORD PTR [esp+56]
|
|
|
|
cmp DWORD PTR [ecx-16], 0
|
|
|
|
jne L23
|
|
|
|
cmp DWORD PTR [ecx-8], 0
|
|
|
|
je L25
|
2009-09-17 13:55:38 +02:00
|
|
|
L23:
|
|
|
|
mov edi, DWORD PTR [__exports+32]
|
|
|
|
mov esi, DWORD PTR [__exports+28]
|
2012-02-22 17:06:05 +01:00
|
|
|
mov eax, DWORD PTR [esp+56]
|
|
|
|
mov DWORD PTR [esp+20], edi
|
2009-09-17 13:55:38 +02:00
|
|
|
add edi, OS_BASE
|
|
|
|
add esi, OS_BASE
|
2012-02-22 17:06:05 +01:00
|
|
|
mov DWORD PTR [esp+44], esi
|
|
|
|
mov ecx, DWORD PTR [eax-4]
|
|
|
|
mov DWORD PTR [esp+48], edi
|
|
|
|
mov edx, DWORD PTR [eax-20]
|
|
|
|
mov DWORD PTR [esp+52], 0
|
|
|
|
add ecx, ebp
|
|
|
|
add edx, ebp
|
|
|
|
mov DWORD PTR [esp+24], edx
|
|
|
|
mov DWORD PTR [esp+28], ecx
|
2009-09-17 13:55:38 +02:00
|
|
|
L26:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov esi, DWORD PTR [esp+52]
|
|
|
|
mov edi, DWORD PTR [esp+24]
|
|
|
|
mov eax, DWORD PTR [edi+esi*4]
|
|
|
|
test eax, eax
|
|
|
|
je L27
|
|
|
|
test eax, eax
|
|
|
|
js L27
|
|
|
|
lea edi, [ebp+eax]
|
|
|
|
mov eax, DWORD PTR [esp+28]
|
|
|
|
mov DWORD PTR [eax+esi*4], 0
|
|
|
|
lea esi, [edi+2]
|
|
|
|
push eax
|
|
|
|
push 32
|
|
|
|
movzx eax, WORD PTR [edi]
|
|
|
|
mov edx, DWORD PTR [esp+56]
|
|
|
|
mov eax, DWORD PTR [edx+eax*4]
|
2009-09-17 13:55:38 +02:00
|
|
|
add eax, OS_BASE
|
2012-02-22 17:06:05 +01:00
|
|
|
push eax
|
|
|
|
push esi
|
|
|
|
call strncmp
|
|
|
|
pop ebx
|
|
|
|
xor ebx, ebx
|
|
|
|
test eax, eax
|
|
|
|
jne L32
|
|
|
|
jmp L30
|
2009-09-17 13:55:38 +02:00
|
|
|
L33:
|
2012-02-22 17:06:05 +01:00
|
|
|
push ecx
|
|
|
|
push 32
|
|
|
|
mov ecx, DWORD PTR [esp+28]
|
2009-09-17 13:55:38 +02:00
|
|
|
mov eax, DWORD PTR [ecx+OS_BASE+ebx*4]
|
|
|
|
add eax, OS_BASE
|
2012-02-22 17:06:05 +01:00
|
|
|
push eax
|
|
|
|
push esi
|
|
|
|
call strncmp
|
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jne L34
|
|
|
|
mov esi, DWORD PTR [esp+44]
|
|
|
|
mov edx, DWORD PTR [esp+52]
|
|
|
|
mov ecx, DWORD PTR [esp+28]
|
|
|
|
mov eax, DWORD PTR [esi+ebx*4]
|
2009-09-17 13:55:38 +02:00
|
|
|
add eax, OS_BASE
|
2012-02-22 17:06:05 +01:00
|
|
|
mov DWORD PTR [ecx+edx*4], eax
|
|
|
|
jmp L36
|
2009-09-17 13:55:38 +02:00
|
|
|
L34:
|
2012-02-22 17:06:05 +01:00
|
|
|
inc ebx
|
2009-09-17 13:55:38 +02:00
|
|
|
L32:
|
|
|
|
cmp ebx, DWORD PTR [__exports+24]
|
2012-02-22 17:06:05 +01:00
|
|
|
jb L33
|
2009-09-17 13:55:38 +02:00
|
|
|
L36:
|
|
|
|
cmp ebx, DWORD PTR [__exports+24]
|
2012-02-22 17:06:05 +01:00
|
|
|
jne L37
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
mov esi, msg_unresolved
|
|
|
|
call sys_msg_board_str
|
2012-02-22 17:06:05 +01:00
|
|
|
lea esi, [edi+2]
|
2009-09-17 13:55:38 +02:00
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
|
2012-02-22 17:06:05 +01:00
|
|
|
mov DWORD PTR [esp+40], 1
|
|
|
|
jmp L37
|
2009-09-17 13:55:38 +02:00
|
|
|
L30:
|
2012-02-22 17:06:05 +01:00
|
|
|
movzx eax, WORD PTR [edi]
|
|
|
|
mov esi, DWORD PTR [esp+44]
|
|
|
|
mov edi, DWORD PTR [esp+52]
|
|
|
|
mov edx, DWORD PTR [esp+28]
|
|
|
|
mov eax, DWORD PTR [esi+eax*4]
|
2009-09-17 13:55:38 +02:00
|
|
|
add eax, OS_BASE
|
2012-02-22 17:06:05 +01:00
|
|
|
mov DWORD PTR [edx+edi*4], eax
|
2009-09-17 13:55:38 +02:00
|
|
|
L37:
|
2012-02-22 17:06:05 +01:00
|
|
|
inc DWORD PTR [esp+52]
|
|
|
|
jmp L26
|
2009-09-17 13:55:38 +02:00
|
|
|
L27:
|
2012-02-22 17:06:05 +01:00
|
|
|
add DWORD PTR [esp+56], 20
|
|
|
|
jmp L22
|
2009-09-17 13:55:38 +02:00
|
|
|
L25:
|
2012-02-22 17:06:05 +01:00
|
|
|
xor eax, eax
|
|
|
|
cmp DWORD PTR [esp+40], 0
|
|
|
|
jne L40
|
2009-09-17 13:55:38 +02:00
|
|
|
L20:
|
2012-02-22 17:06:05 +01:00
|
|
|
mov ecx, DWORD PTR [esp+32]
|
|
|
|
mov eax, ebp
|
|
|
|
add eax, DWORD PTR [ecx+40]
|
2009-09-17 13:55:38 +02:00
|
|
|
L40:
|
2012-02-22 17:06:05 +01:00
|
|
|
add esp, 60
|
|
|
|
pop ebx
|
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebp
|
2009-09-17 13:55:38 +02:00
|
|
|
ret 8
|
|
|
|
|
|
|
|
align 16
|
|
|
|
__exports:
|
|
|
|
export 'KERNEL', \
|
|
|
|
alloc_kernel_space, 'AllocKernelSpace', \ ; stdcall
|
2010-01-15 12:54:11 +01:00
|
|
|
alloc_page, 'AllocPage', \ ; gcc ABI
|
|
|
|
alloc_pages, 'AllocPages', \ ; stdcall
|
2009-09-17 13:55:38 +02:00
|
|
|
commit_pages, 'CommitPages', \ ; eax, ebx, ecx
|
2012-02-22 17:06:05 +01:00
|
|
|
\
|
|
|
|
create_event, 'CreateEvent', \ ; ecx, esi
|
|
|
|
destroy_event, 'DestroyEvent', \ ;
|
|
|
|
raise_event, 'RaiseEvent', \ ; eax, ebx, edx, esi
|
|
|
|
wait_event, 'WaitEvent', \ ; eax, ebx
|
|
|
|
get_event_ex, 'GetEvent', \ ; edi
|
|
|
|
\
|
2009-09-17 13:55:38 +02:00
|
|
|
create_kernel_object, 'CreateObject', \
|
|
|
|
create_ring_buffer, 'CreateRingBuffer', \ ; stdcall
|
|
|
|
destroy_kernel_object, 'DestroyObject', \
|
|
|
|
free_kernel_space, 'FreeKernelSpace', \ ; stdcall
|
2012-02-22 17:06:05 +01:00
|
|
|
free_page, 'FreePage', \ ; eax
|
2009-09-17 13:55:38 +02:00
|
|
|
kernel_alloc, 'KernelAlloc', \ ; stdcall
|
|
|
|
kernel_free, 'KernelFree', \ ; stdcall
|
2013-03-10 13:28:37 +01:00
|
|
|
malloc, 'Kmalloc', \
|
|
|
|
free, 'Kfree', \
|
|
|
|
map_io_mem, 'MapIoMem', \ ; stdcall
|
|
|
|
map_page, 'MapPage', \ ; stdcall
|
|
|
|
get_pg_addr, 'GetPgAddr', \ ; eax
|
|
|
|
\
|
|
|
|
mutex_init, 'MutexInit', \ ; gcc fastcall
|
2012-02-22 17:06:05 +01:00
|
|
|
mutex_lock, 'MutexLock', \ ; gcc fastcall
|
|
|
|
mutex_unlock, 'MutexUnlock', \ ; gcc fastcall
|
2009-09-17 13:55:38 +02:00
|
|
|
\
|
2010-01-15 12:54:11 +01:00
|
|
|
get_display, 'GetDisplay', \
|
2009-09-17 13:55:38 +02:00
|
|
|
set_screen, 'SetScreen', \
|
2012-02-22 17:06:05 +01:00
|
|
|
window._.get_rect, 'GetWindowRect', \ ; gcc fastcall
|
|
|
|
pci_api_drv, 'PciApi', \
|
2009-09-17 13:55:38 +02:00
|
|
|
pci_read8, 'PciRead8', \ ; stdcall
|
|
|
|
pci_read16, 'PciRead16', \ ; stdcall
|
|
|
|
pci_read32, 'PciRead32', \ ; stdcall
|
|
|
|
pci_write8, 'PciWrite8', \ ; stdcall
|
|
|
|
pci_write16, 'PciWrite16', \ ; stdcall
|
|
|
|
pci_write32, 'PciWrite32', \ ; stdcall
|
|
|
|
\
|
2012-02-22 17:06:05 +01:00
|
|
|
get_pid, 'GetPid', \
|
2010-01-15 12:54:11 +01:00
|
|
|
get_service, 'GetService', \ ;
|
2009-09-17 13:55:38 +02:00
|
|
|
reg_service, 'RegService', \ ; stdcall
|
|
|
|
attach_int_handler, 'AttachIntHandler', \ ; stdcall
|
|
|
|
user_alloc, 'UserAlloc', \ ; stdcall
|
|
|
|
user_free, 'UserFree', \ ; stdcall
|
|
|
|
unmap_pages, 'UnmapPages', \ ; eax, ecx
|
|
|
|
sys_msg_board_str, 'SysMsgBoardStr', \
|
2012-02-22 17:06:05 +01:00
|
|
|
get_timer_ticks, 'GetTimerTicks', \
|
|
|
|
get_stack_base, 'GetStackBase', \
|
2009-09-17 13:55:38 +02:00
|
|
|
delay_hs, 'Delay', \ ; ebx
|
2012-02-22 17:06:05 +01:00
|
|
|
set_mouse_data, 'SetMouseData', \ ;
|
|
|
|
set_keyboard_data, 'SetKeyboardData', \ ; gcc fastcall
|
|
|
|
timer_hs, 'TimerHs' ; stdcall
|
2009-09-17 13:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|