Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 1692 → Rev 1693

/programs/develop/libraries/newlib/crt/chkstk.S
0,0 → 1,29
 
.global ___chkstk
.global __alloca
 
.section .text
 
.align 4
___chkstk:
__alloca:
pushl %ecx /* save temp */
leal 8(%esp), %ecx /* point past return addr */
subl %eax, %ecx
cmpl %fs:4, %ecx # check low stack limit
jb 1f
 
movl %esp, %eax /* save old stack pointer */
movl %ecx, %esp /* decrement stack */
movl (%eax), %ecx /* recover saved temp */
movl 4(%eax), %eax /* recover return address */
 
/* Push the return value back. Doing this instead of just
jumping to %eax preserves the cached call-return stack
used by most modern processors. */
pushl %eax
ret
1:
int3 #trap to debugger
.ascii "Stack overflow"
 
/programs/develop/libraries/newlib/crt/cpu_features.c
0,0 → 1,72
 
#include "cpu_features.h"
 
/* level 1 edx bits */
#define EDX_CX8 (1 << 8) /* CMPXCHG8B */
#define EDX_CMOV (1 << 15)
#define EDX_MMX (1 << 23)
#define EDX_FXSR (1 << 24) /* FXSAVE and FXRSTOR */
#define EDX_SSE (1 << 25)
#define EDX_SSE2 (1 << 26)
 
/* level 1 ecx bits */
#define ECX_SSE3 (1 << 0)
#define ECX_CX16 (1 << 13) /* CMPXCHG16B */
 
/* extended level 0x80000001 edx bits */
#define EDX_3DNOW (1 << 31)
#define EDX_3DNOWP (1 << 30)
#define EDX_LM (1 << 29) /*LONG MODE */
 
#define __cpuid(level,a,b,c,d) \
__asm__ __volatile__ ("cpuid;" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d)\
: "0" (level))
 
/* Combine the different cpuid flags into a single bitmap. */
 
unsigned int __cpu_features = 0;
 
void __cpu_features_init (void)
{
unsigned int eax, ebx, ecx, edx;
 
__cpuid (0, eax, ebx, ecx, edx);
if (eax == 0)
return;
 
__cpuid (1, eax, ebx, ecx, edx);
 
if (edx & EDX_CX8)
__cpu_features |= _CRT_CMPXCHG8B;
if (edx & EDX_CMOV)
__cpu_features |= _CRT_CMOV;
 
if (edx & EDX_MMX)
__cpu_features |= _CRT_MMX;
if (edx & EDX_FXSR)
__cpu_features |= _CRT_FXSR;
if (edx & EDX_SSE)
__cpu_features |= _CRT_SSE;
if (edx & EDX_SSE2)
__cpu_features |= _CRT_SSE2;
 
 
if (ecx & ECX_SSE3)
__cpu_features |= _CRT_SSE3;
if (ecx & ECX_CX16)
__cpu_features |= _CRT_CMPXCHG16B;
 
__cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001)
return;
__cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & EDX_3DNOW)
__cpu_features |= _CRT_3DNOW;
if (edx & EDX_3DNOWP)
__cpu_features |= _CRT_3DNOWP;
 
return;
}
 
 
/programs/develop/libraries/newlib/crt/cpu_features.h
0,0 → 1,21
#ifndef _CPU_FEATURES_H
#define _CPU_FEATURES_H
 
#define _CRT_CMPXCHG8B 0x0001
#define _CRT_CMOV 0x0002
#define _CRT_MMX 0x0004
#define _CRT_FXSR 0x0008
#define _CRT_SSE 0x0010
#define _CRT_SSE2 0x0020
#define _CRT_SSE3 0x0040
#define _CRT_CMPXCHG16B 0x0080
#define _CRT_3DNOW 0x0100
#define _CRT_3DNOWP 0x0200
 
extern unsigned int __cpu_features;
 
/* Currently we use this in fpenv functions */
#define __HAS_SSE __cpu_features & _CRT_SSE
 
 
#endif
/programs/develop/libraries/newlib/crt/crt1.c
0,0 → 1,126
/*
* crt1.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 startup proceedures used by all programs. This code
* is compiled to make crt1.o, which should be located in the library path.
*
*/
 
/* Hide the declaration of _fmode with dllimport attribute in stdlib.h to
avoid problems with older GCC. */
 
#include <newlib.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "cpu_features.h"
 
 
/* NOTE: The code for initializing the _argv, _argc, and environ variables
* has been moved to a separate .c file which is included in both
* crt1.c and dllcrt1.c. This means changes in the code don't have to
* be manually synchronized, but it does lead to this not-generally-
* a-good-idea use of include. */
 
 
extern char __cmdline;
extern char __pgmname;
 
extern int main (int, char **, char **);
 
int _errno;
int _fmode;
 
char __appcwd[1024];
int __appcwdlen;
 
int _argc;
char **_argv;
 
static char *arg[2];
 
void _exit(int __status) __attribute__((noreturn));
 
 
char * __libc_getenv(const char *name)
{
return NULL;
}
 
void __main (){};
 
 
void init_reent();
 
void __attribute__((noreturn))
__thread_startup (int (*entry)(void*), void *param,
void *stacklow, void *stackhigh)
{
int retval;
 
__asm__ __volatile__( // save stack limits
"movl %0, %%fs:4 \n\t" // use TLS
"movl %1, %%fs:8 \n\t"
::"r"(stacklow), "r"(stackhigh));
 
init_reent(); // initialize thread reentry structure
 
retval = entry(param); // call user thread function
 
_exit(retval);
};
 
void __attribute__((noreturn))
__crt_startup (void)
{
int nRet;
 
init_reent();
 
/*
* Initialize floating point unit.
*/
__cpu_features_init (); /* Do we have SSE, etc.*/
// _fpreset (); /* Supplied by the runtime library. */
 
__initPOSIXHandles();
 
__appcwdlen = strrchr(&__pgmname, '/') - &__pgmname + 1;
 
__appcwdlen = __appcwdlen > 1023 ? 1023 : __appcwdlen;
 
strncpy(__appcwd, &__pgmname, __appcwdlen);
__appcwd[__appcwdlen] = 0;
 
arg[0] = &__pgmname;
 
if( __cmdline != 0)
{
_argc = 2;
arg[1] = &__cmdline;
} else _argc = 1;
 
_argv = arg;
 
/*
* 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 ();
 
nRet = main (_argc, _argv, NULL);
 
/*
* Perform exit processing for the C library. This means
* flushing output and calling 'atexit' registered functions.
*/
_exit (nRet);
}
 
 
 
/programs/develop/libraries/newlib/crt/start.S
0,0 → 1,40
 
.section .init
 
.global __start
.global __exit
.global __Exit
 
.align 4
__start:
movl $68, %eax
movl $12, %ebx
lea __size_of_stack_reserve__, %ecx
addl $4095, %ecx #load stack size
andl $-4096, %ecx #align to page granularity
int $0x40 #and allocate
testl %eax, %eax
jz 1f
 
addl %eax, %ecx
movl %eax, %fs:4
movl %ecx, %fs:8 #save stack base - low limit
#save stack top - high limit
movl %ecx, %esp
jmp ___crt_startup #reload stack
1:
int3 #trap to debugger
 
.ascii "No enough memory for stack allocation"
 
.align 4
__exit:
__Exit:
movl 4(%esp), %edx #store exit code
movl $68, %eax
movl $13, %ebx
movl %fs:4, %ecx
int $0x40 #destroy stack
 
movl $-1, %eax
int $0x40 #terminate thread
/programs/develop/libraries/newlib/crt/thread.S
0,0 → 1,46
 
.global _create_thread
.global ___thread_startup
 
.section .text
 
.align 4
_create_thread:
#.thr_proc equ esp+8
#.param equ esp+12
#.stack_size equ esp+16
 
pushl %ebx
 
movl $68, %eax
movl $12, %ebx
movl 16(%esp), %ecx #[.stack_size]
addl $4095, %ecx
andl $-4096, %ecx
movl %ecx, 16(%esp) #save stack size
int $0x40
testl %eax, %eax
jz 1f
 
leal -20(%eax,%ecx), %edx
 
movl 8(%esp), %ebx #[.thr_proc]
mov %ebx, 4(%edx)
 
movl 12(%esp), %ebx #[.param]
movl %ebx, 8(%edx)
 
addl %eax, %ecx
movl %eax, 12(%edx) #stack low limit
movl %ecx, 16(%edx) #stack high limit
 
movl $51, %eax
movl $1, %ebx
lea ___thread_startup , %ecx
int $0x40
popl %ebx
ret
1:
notl %eax
popl %ebx
ret
/programs/develop/libraries/newlib/crt/.
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property