Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6067 → Rev 6068

/contrib/sdk/sources/newlib/libc/crt/crt_amz.S
File deleted
/contrib/sdk/sources/newlib/libc/crt/console.asm
0,0 → 1,271
include '../proc32.inc'
 
format MS COFF
 
public _load_libconsole
 
public _con_init@20
public _con_exit@4
public _con_get_flags
public _con_set_flags@4
public _con_cls
public _con_write_string@8
 
section '.text' align 16
 
 
;void* __fastcall getprocaddr(export, name)
align 4
getprocaddress:
push esi
push edi
 
xor eax, eax
test ecx, ecx ; If hlib = 0 then goto .end
jz .end
.next:
cmp [ecx], dword 0 ; If end of export table then goto .end
jz .end
 
xor eax, eax
mov esi, [ecx]
mov edi, edx ; name
.next_:
lodsb
scasb
jne .fail
or al, al
jnz .next_
jmp .ok
.fail:
add ecx, 8
jmp .next
.ok:
mov eax, [ecx + 4] ; return address
.end:
pop edi
pop esi
ret
 
 
;void fastcall dll_link(export, import)
 
align 4
dll_link:
push esi
push ecx
mov esi, edx
test esi, esi
jz .done
.next:
mov edx, [esi]
test edx, edx
jz .done
mov ecx, [esp]
call getprocaddress
test eax, eax
jz .done
mov [esi], eax
add esi, 4
jmp .next
.done:
pop ecx
pop esi
ret
 
align 4
dll_load:
push ebp
push ebx
push esi
push edi
 
mov ebp, [esp+20]
.next_lib:
mov edx, [ebp]
test edx, edx
jz .exit
 
mov esi, [ebp+4]
mov edi, s_libdir.fname
@@:
lodsb
stosb
test al, al
jnz @b
 
mov eax, 68
mov ebx, 19
mov ecx, s_libdir
int 0x40
test eax, eax
jz .fail
 
mov ecx, eax
call dll_link
mov eax, [ecx]
cmp dword[eax], 'lib_'
jnz @f
 
mov esi, [ecx+4]
 
pushad
mov eax, mem.Alloc
mov ebx, mem.Free
mov ecx, mem.ReAlloc
mov edx, dll_load
call esi
popad
@@:
add ebp, 8
jmp .next_lib
.exit:
pop edi
pop esi
pop ebx
pop ebp
xor eax, eax
ret 4
.fail:
pop edi
pop esi
pop ebx
pop ebp
inc eax
ret 4
 
align 4
_load_libconsole:
push ebx
mov eax, 40
mov ebx, 1 shl 8
int 0x40
pop ebx
 
push @IMPORT
call dll_load
test eax, eax
jnz .fail
push 1
call [con_start]
xor eax, eax
.fail:
ret
 
align 4
_con_init@20:
jmp [con_init]
 
align 4
_con_exit@4:
jmp [con_exit]
 
align 4
_con_write_string@8:
jmp [con_write_string]
 
_con_get_flags:
_con_set_flags@4:
_con_cls:
ret
 
 
proc mem.Alloc, size
push ebx ecx
mov ecx, [size]
mov eax, 68
mov ebx, 12
int 0x40
pop ecx ebx
ret
endp
;-----------------------------------------------------------------------------
proc mem.ReAlloc, mptr, size
push ebx ecx edx
mov ecx, [size]
test ecx, ecx
jz @f
@@:
mov edx, [mptr]
test edx, edx
jz @f
@@:
mov eax, 68
mov ebx, 20
int 0x40
test eax, eax
jz @f
@@:
pop edx ecx ebx
ret
endp
;-----------------------------------------------------------------------------
proc mem.Free, mptr
push ebx ecx
mov ecx,[mptr]
test ecx,ecx
jz @f
@@:
mov eax, 68
mov ebx, 13
int 0x40
pop ecx ebx
ret
endp
 
;section '.ctors' align 4
;align 4
;dd _load_libconsole
 
section '.data' align 16
 
; -------------------------
macro library [lname,fname]
{
forward
dd __#lname#_library_table__,__#lname#_library_name__
common
dd 0
forward
align 4
__#lname#_library_name__ db fname,0
}
 
macro import lname,[name,sname]
{
common
align 4
__#lname#_library_table__:
forward
if used name
name dd __#name#_import_name__
end if
common
dd 0
forward
if used name
align 4
__#name#_import_name__ db sname,0
end if
}
 
align 4
@IMPORT:
 
library console, 'console.obj'
 
import console, \
con_start, 'START', \
con_init, 'con_init', \
con_exit, 'con_exit', \
con_gets, 'con_gets', \
con_cls, 'con_cls', \
con_getch2, 'con_getch2', \
con_set_cursor_pos, 'con_set_cursor_pos',\
con_write_string, 'con_write_string',\
con_get_flags, 'con_get_flags', \
con_set_flags, 'con_set_flags'
 
s_libdir:
db '/sys/lib/'
.fname rb 32
/contrib/sdk/sources/newlib/libc/crt/crt1.c
19,8 → 19,19
#include <stdio.h>
#include <sys/kos_io.h>
 
#include "cpu_features.h"
struct app_hdr
{
char banner[8];
int version;
int start;
int iend;
int memsize;
int stacktop;
char *cmdline;
char *path;
};
 
extern int main (int, char **, char **);
 
/* NOTE: The code for initializing the _argv, _argc, and environ variables
* has been moved to a separate .c file which is included in both
28,100 → 39,163
* be manually synchronized, but it does lead to this not-generally-
* a-good-idea use of include. */
 
char* __appenv;
int __appenv_size;
 
extern char __cmdline[];
extern char __pgmname[];
extern char _tls_map[128];
 
extern int main (int, char **, char **);
char * __libc_getenv(const char *name)
{
return NULL;
}
 
int _errno;
int _fmode;
static int split_cmdline(char *cmdline, char **argv)
{
enum quote_state
{
QUOTE_NONE, /* no " active in current parm */
QUOTE_DELIMITER, /* " was first char and must be last */
QUOTE_STARTED /* " was seen, look for a match */
};
 
int _argc;
char **_argv;
enum quote_state state;
unsigned int argc;
char *p = cmdline;
char *new_arg, *start;
 
static char *arg[2];
argc = 0;
 
void _exit(int __status) __attribute__((noreturn));
for(;;)
{
/* skip over spaces and tabs */
if ( *p )
{
while (*p == ' ' || *p == '\t')
++p;
}
 
if (*p == '\0')
break;
 
char * __libc_getenv(const char *name)
state = QUOTE_NONE;
if( *p == '\"' )
{
return NULL;
p++;
state = QUOTE_DELIMITER;
}
new_arg = start = p;
for (;;)
{
if( *p == '\"' )
{
p++;
if( state == QUOTE_NONE )
{
state = QUOTE_STARTED;
}
else
{
state = QUOTE_NONE;
}
continue;
}
 
void __main (){};
 
struct app_hdr
if( *p == ' ' || *p == '\t' )
{
char banner[8];
int version;
int start;
int iend;
int memsize;
int stacktop;
char *cmdline;
char *path;
};
if( state == QUOTE_NONE )
{
break;
}
}
 
typedef void (*ctp)();
static void __do_global_ctors ()
if( *p == '\0' )
break;
 
if( *p == '\\' )
{
extern int __CTOR_LIST__;
int *c = &__CTOR_LIST__;
c++;
while (*c)
if( p[1] == '\"' )
{
ctp d = (ctp)*c;
(d)();
c++;
++p;
if( p[-2] == '\\' )
{
continue;
}
}
}
if( argv )
{
*(new_arg++) = *p;
}
++p;
};
 
void __attribute__((noreturn))
__crt_startup (void)
if( argv )
{
int nRet;
struct app_hdr *header;
argv[ argc ] = start;
++argc;
 
 
init_global_reent();
 
/*
* Initialize floating point unit.
The *new = '\0' is req'd in case there was a \" to "
translation. It must be after the *p check against
'\0' because new and p could point to the same char
in which case the scan would be terminated too soon.
*/
__cpu_features_init (); /* Do we have SSE, etc.*/
// _fpreset (); /* Supplied by the runtime library. */
 
__do_global_ctors();
if( *p == '\0' )
{
*new_arg = '\0';
break;
}
*new_arg = '\0';
++p;
}
else
{
++argc;
if( *p == '\0' )
{
break;
}
++p;
}
}
 
arg[0] = &__pgmname[0];
return argc;
};
 
if( __cmdline[0] != 0)
void __attribute__((noreturn))
__crt_startup (void)
{
_argc = 2;
arg[1] = &__cmdline[0];
} else _argc = 1;
struct app_hdr *header = NULL;
int retval = 0;
 
_argv = arg;
char **argv;
int argc;
 
/*
* Sets the default file mode.
* If _CRT_fmode is set, also set mode for stdin, stdout
* and stderr, as well
* NOTE: DLLs don't do this because that would be rude!
*/
// _mingw32_init_fmode ();
memset(_tls_map, 0xFF, 32*4);
_tls_map[0] = 0xE0;
init_reent();
init_stdio();
 
 
nRet = main (_argc, _argv, NULL);
if( header->cmdline[0] != 0)
{
argc = split_cmdline(header->cmdline, NULL) + 1;
argv = alloca((argc+1)*sizeof(char*));
argv[0] = header->path;
 
/*
* Perform exit processing for the C library. This means
* flushing output and calling 'atexit' registered functions.
*/
exit (nRet);
split_cmdline(header->cmdline, argv + 1);
}
else
{
argc = 1;
argv = alloca((argc+1)*sizeof(char*));
argv[0] = header->path;
}
argv[argc] = NULL;
 
retval = main(argc, argv, NULL);
done:
exit (retval);
}
 
 
/contrib/sdk/sources/newlib/libc/crt/crt2.c
2,6 → 2,8
 
void init_reent();
 
void _exit(int __status) __attribute__((noreturn));
 
void __attribute__((noreturn))
__thread_startup (int (*entry)(void*), void *param,
void *stacklow, void *stackhigh)
/contrib/sdk/sources/newlib/libc/crt/crtdll.c
1,3 → 1,13
/*
* crtdll.c
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Source code for the shared libc startup proceedures. This code is compiled
* to make libc.dll, which should be located in the library path.
*
*/
 
#include <_ansi.h>
#include <reent.h>
38,26 → 48,6
 
extern char _tls_map[128];
 
void __attribute__((noreturn))
__thread_startup (int (*entry)(void*), void *param,
void *stacklow, void *stackhigh)
{
int retval;
 
// asm volatile ( "xchgw %bx, %bx");
 
__asm__ __volatile__( // save stack limits
"movl %0, %%fs:8 \n\t" // use TLS
"movl %1, %%fs:12 \n\t"
::"r"(stacklow), "r"(stackhigh));
 
init_reent(); // initialize thread reentry structure
 
retval = entry(param); // call user thread function
 
_exit(retval);
};
 
char * __libc_getenv(const char *name)
{
return NULL;
192,6 → 182,7
_tls_map[0] = 0xE0;
init_reent();
init_stdio();
__do_global_ctors();
 
// __appenv = load_file("/sys/system.env", &__appenv_size);
 
221,4 → 212,3
exit (retval);
}