Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1906 → Rev 1907

/programs/develop/libraries/newlib/Makefile
327,7 → 327,7
 
 
 
shared: $(NAME).dll libamz.a
shared: $(NAME).dll libamz.a libc.obj
 
 
$(NAME).dll: $(LIB_OBJS) $(SRC_DEP) Makefile
337,7 → 337,10
libamz.a: $(AMZ_OBJS) Makefile
ar rc libamz.a $(AMZ_OBJS)
 
libc.obj: $(NAME).dll
fasm pe/libc.asm ./libc.obj
 
 
static: $(NAME).a
 
$(NAME).a: $(LIB_OBJS) $(SRC_DEP) Makefile
/programs/develop/libraries/newlib/pe/libc.asm
0,0 → 1,284
 
struc APP_HEADER_02
{ .banner dq ?
.version dd ? ;+8
.start dd ? ;+12
.i_end dd ? ;+16
.mem_size dd ? ;+20
.stack_top dd ? ;+24
.cmdline dd ? ;+28
.path dd ? ;+32
}
 
virtual at 0
app_hdr APP_HEADER_02
end virtual
 
format MS COFF
 
public EXPORTS
 
section '.flat' code readable align 16
 
EXPORTS:
dd szStart, START
dd szVersion, 0x00010001
dd szExec, exec
dd 0
 
check dd 0
 
szStart db 'START',0
szVersion db 'version',0
szExec db 'exec',0
 
START:
xor eax, eax
cmp [app_hdr.path], 0
je .ret
not eax
.ret:
mov [check], eax
ret 4
 
align 4
exec:
cmp [check], 0
lea ebp, [esp+4]
je .fail
 
mov eax, [ebp+8]
test eax, eax
jz .fail
 
mov ecx, [ebp]
mov edx, [ebp+4]
call validate_pe
test eax, eax
jz .fail
 
mov eax, 68
mov ebx, [ebp]
mov ecx, [ebx+60]
mov ecx, [ecx+96+ebx] ; app stack size
add ecx, 4095
and ecx, -4096
mov ebx, 12
 
int 0x40
test eax, eax
jz .fail
 
add ecx, eax
mov [fs:4], eax ;stack base
mov [fs:8], ecx ;stack top
 
mov esp, ecx
 
sub esp, 1024
mov eax, 9
mov ebx, esp
mov ecx, -1
int 0x40
mov eax, [ebx+30]
mov [fs:0], eax ; save pid
add esp, 1024
 
mov ecx, my_libc
call create_image
test eax, eax
jz .fail
 
mov ebx, [eax+60]
mov ebx, [ebx+40+eax]
add ebx, eax
push ebp
push EXPORTS
push eax
call ebx
 
ret
 
.fail:
ret 4
 
align 4
 
validate_pe:
test ecx, ecx
je .L2
cmp edx, 63
jbe .L2
cmp [ecx], word 23117
je .L10
.L2:
xor eax, eax
ret
 
align 4
.L10:
mov eax, [ecx+60]
test eax, eax
je .L2
add ecx, eax
jb .L2
cmp [ecx], dword 17744
jne .L2
cmp [ecx+4], word 332
jne .L2
test [ecx+23], byte 32
jne .L2
cmp [ecx+24], word 267
jne .L2
mov eax, [ecx+56]
cmp eax, 4095
ja .L3
cmp eax, [ecx+60]
jne .L2
test eax, eax
je .L2
.L5:
lea edx, [eax-1]
test edx, eax
jne .L2
mov eax, [ecx+60]
test eax, eax
je .L2
lea edx, [eax-1]
test edx, eax
jne .L2
xor eax, eax
cmp [ecx+6], word 96
setbe al
ret
.L3:
cmp eax, [ecx+60]
jae .L5
jmp .L2
 
align 4
create_image:
push ebp
push edi
push esi
push ebx
sub esp, 20
mov [esp+16], ecx
mov eax, [ecx+60]
add eax, ecx
mov [esp], eax
mov ecx, [eax+80]
mov ebx, 12
mov eax, 68
int 0x40
test eax, eax
je .L16
 
mov edx, [esp]
mov ecx, [edx+84]
mov esi, [esp+16]
mov edi, eax
shr ecx, 2
rep movsd
mov cx, [edx+6]
test cx, cx
je .L17
add edx, 248
movzx ecx, cx
lea ebp, [ecx-1]
xor bl, bl
jmp .L19
 
align 4
.L31:
add edx, 40
inc ebx
.L19:
mov ecx, [edx+16]
test ecx, ecx
je .L18
mov esi, [edx+20]
test esi, esi
je .L18
add esi, [esp+16]
mov edi, [edx+12]
add edi, eax
 
shr ecx, 2
rep movsd
 
.L18:
cmp ebx, ebp
jne .L31
.L17:
mov edx, [esp]
mov ecx, [edx+164]
test ecx, ecx
je .L16
 
mov ebp, eax
sub ebp, [edx+52]
mov ebx, [edx+160]
add ebx, eax
mov esi, [ebx+4]
test esi, esi
je .L16
 
mov edi, ebp
shr edi, 16
mov [esp], di
 
align 4
.L26:
lea edi, [esi-8]
shr edi, 1
je .L20
xor ecx, ecx
jmp .L25
 
align 4
.L32:
cmp si, 3
je .L24
dec si
jne .L21
mov esi, [esp]
add [eax+edx], si
.L21:
inc ecx
cmp ecx, edi
je .L20
.L25:
mov si, [ebx+8+ecx*2]
mov edx, esi
and edx, 4095
add edx, [ebx]
shr si, 12
cmp si, 2
jne .L32
add [eax+edx], bp
inc ecx
cmp ecx, edi
jne .L25
.L20:
add ebx, [ebx+4]
mov esi, [ebx+4]
test esi, esi
jne .L26
.L16:
add esp, 20
pop ebx
pop esi
pop edi
pop ebp
ret
 
align 4
.L24:
add [eax+edx], ebp
jmp .L21
 
 
align 16
my_libc:
file '../libc.dll'
/programs/develop/libraries/newlib/pe/loader.c
523,7 → 523,7
}
else if (minn == maxn)
{
printf(" unresolved\n",imp_name->Name);
printf(" unresolved %s\n",imp_name->Name);
warn=1;
break;
}
/programs/develop/libraries/newlib/tests/pe_demo.asm
0,0 → 1,133
 
use32
 
LIBC_VERSION = 1
DLL_ENTRY = 1
 
db 'MENUET02'
dd 1
dd start
dd i_end
dd mem
dd mem
dd cmdline
dd path
dd 0
 
align 4
start:
mov eax, LIBC_VERSION
mov ecx, sz_libc
mov edx, libc
call load_library
test eax, eax
jz .fail
 
push dword 0 ; no environment
push cmdline
push path
push (my_app_end - my_app)
push my_app
call [libc.imp_exec]
 
ret
.fail:
or eax, -1
int 0x40
 
align 4
load_library: ;eax=VERSION ecx=library path edx=import section
 
sub esp, 16
mov [esp+8], edx
mov [esp+12], eax
 
mov eax, 68
mov ebx, 19
int 0x40
test eax, eax
jz .fail
 
mov [esp+4], eax
mov esi, edx ;import section
mov edx, eax ;export section
.import_loop:
lodsd
test eax, eax
jz .import_done
.import_find:
mov ebx, [edx]
test ebx, ebx
jz .fail ;import_not_found
 
mov [esp], eax ;import name
@@:
mov cl, [eax]
cmp cl, [ebx]
jnz .import_find_next
 
test cl, cl
jz .import_found
 
inc eax
inc ebx
jmp @b
 
.import_find_next:
mov eax, [esp]
add edx, 8
jmp .import_find
 
.import_found:
mov eax, [edx+4]
mov [esi-4], eax
mov edx, [esp+4]
jmp .import_loop
.import_done:
 
mov edx, [esp+8]
mov eax, [esp+12]
 
cmp word [edx+4], ax
jb .fail
cmp word [edx+6], ax
ja .fail
 
push DLL_ENTRY
call dword [edx]
.fail:
add esp, 16
ret
 
 
sz_libc db '/sys/lib/libc.obj',0
 
szStart db 'START',0
szVersion db 'version',0
szExec db 'exec',0
 
libc:
 
.imp_start dd szStart
.imp_ver dd szVersion
.imp_exec dd szExec
dd 0
 
; keep this aligned
align 16
my_app:
file 'myapp.exe'
my_app_end:
 
 
; keep this aligned
align 4
i_end:
 
path rb 1024
cmdline rb 256
rb 128 ;required stack
; keep this aligned
align 4096
mem: