TinyC upgrade (#6593)

This commit is contained in:
Dmitry Atamanov 2017-10-28 10:25:56 +03:00 • committed by Andreas Rumpf
commit d2c7d391c8
395 changed files with 68184 additions and 32394 deletions

View file

@ -1,29 +1,191 @@
// =================================================
// chkstk.s
/* ---------------------------------------------- */
/* chkstk86.s */
/* ---------------------------------------------- */
#ifndef __x86_64__
/* ---------------------------------------------- */
.text
.globl __chkstk
__chkstk:
xchg (%esp), %ebp // store ebp, get ret.addr
push %ebp // push ret.addr
lea 4(%esp), %ebp // setup frame ptr
push %ecx // save ecx
mov %ebp, %ecx
xchg (%esp),%ebp /* store ebp, get ret.addr */
push %ebp /* push ret.addr */
lea 4(%esp),%ebp /* setup frame ptr */
push %ecx /* save ecx */
mov %ebp,%ecx
P0:
sub $4096,%ecx
test %eax,(%ecx)
sub $4096,%eax
cmp $4096,%eax
jge P0
sub $4096,%ecx
test %eax,(%ecx)
sub $4096,%eax
cmp $4096,%eax
jge P0
sub %eax,%ecx
test %eax,(%ecx)
sub %eax,%ecx
mov %esp,%eax
test %eax,(%ecx)
mov %ecx,%esp
mov %esp,%eax
mov %ecx,%esp
mov (%eax),%ecx /* restore ecx */
jmp *4(%eax)
mov (%eax),%ecx // restore ecx
mov 4(%eax),%eax
push %eax
ret
/* ---------------------------------------------- */
#else
/* ---------------------------------------------- */
.globl __chkstk
__chkstk:
xchg (%rsp),%rbp /* store ebp, get ret.addr */
push %rbp /* push ret.addr */
lea 8(%rsp),%rbp /* setup frame ptr */
push %rcx /* save ecx */
mov %rbp,%rcx
movslq %eax,%rax
P0:
sub $4096,%rcx
test %rax,(%rcx)
sub $4096,%rax
cmp $4096,%rax
jge P0
sub %rax,%rcx
test %rax,(%rcx)
mov %rsp,%rax
mov %rcx,%rsp
mov (%rax),%rcx /* restore ecx */
jmp *8(%rax)
/* ---------------------------------------------- */
/* setjmp/longjmp support */
.globl tinyc_getbp
tinyc_getbp:
mov %rbp,%rax
ret
/* ---------------------------------------------- */
#endif
/* ---------------------------------------------- */
/* ---------------------------------------------- */
#ifndef __x86_64__
/* ---------------------------------------------- */
/*
int _except_handler3(
PEXCEPTION_RECORD exception_record,
PEXCEPTION_REGISTRATION registration,
PCONTEXT context,
PEXCEPTION_REGISTRATION dispatcher
);
int __cdecl _XcptFilter(
unsigned long xcptnum,
PEXCEPTION_POINTERS pxcptinfoptrs
);
struct _sehrec {
void *esp; // 0
void *exception_pointers; // 1
void *prev; // 2
void *handler; // 3
void *scopetable; // 4
int trylevel; // 5
void *ebp // 6
};
// this is what the assembler code below means:
__try
{
// ...
}
__except (_XcptFilter(GetExceptionCode(), GetExceptionInformation()))
{
exit(GetExceptionCode());
}
*/
.globl _exception_info
_exception_info:
mov 1*4-24(%ebp),%eax
ret
.globl _exception_code
_exception_code:
call _exception_info
mov (%eax),%eax
mov (%eax),%eax
ret
seh_filter:
call _exception_info
push %eax
call _exception_code
push %eax
call _XcptFilter
add $ 8,%esp
ret
seh_except:
mov 0*4-24(%ebp),%esp
call _exception_code
push %eax
call _exit
// msvcrt wants scopetables aligned and in read-only segment (using .text)
.align 4
seh_scopetable:
.long -1
.long seh_filter
.long seh_except
seh_handler:
jmp _except_handler3
.globl ___try__
___try__:
.globl __try__
__try__:
push %ebp
mov 8(%esp),%ebp
// void *esp;
lea 12(%esp),%eax
mov %eax,0*4(%ebp)
// void *exception_pointers;
xor %eax,%eax
mov %eax,1*4(%ebp)
// void *prev;
mov %fs:0,%eax
mov %eax,2*4(%ebp)
// void *handler;
mov $ seh_handler,%eax
mov %eax,3*4(%ebp)
// void *scopetable;
mov $ seh_scopetable,%eax
mov %eax,4*4(%ebp)
// int trylevel;
xor %eax,%eax
mov %eax,5*4(%ebp)
// register new SEH
lea 2*4(%ebp),%eax
mov %eax,%fs:0
pop %ebp
ret
/* ---------------------------------------------- */
#else
/* ---------------------------------------------- */
/* SEH on x86-64 not implemented */
/* ---------------------------------------------- */
#endif
/* ---------------------------------------------- */

View file

@ -1,35 +1,79 @@
// =============================================
// crt1.c
// _UNICODE for tchar.h, UNICODE for API
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#define __UNKNOWN_APP 0
#define __CONSOLE_APP 1
#define __GUI_APP 2
void __set_app_type(int);
void _controlfp(unsigned a, unsigned b);
#define _UNKNOWN_APP 0
#define _CONSOLE_APP 1
#define _GUI_APP 2
typedef struct
#define _MCW_PC 0x00030000 // Precision Control
#define _PC_24 0x00020000 // 24 bits
#define _PC_53 0x00010000 // 53 bits
#define _PC_64 0x00000000 // 64 bits
#ifdef _UNICODE
#define __tgetmainargs __wgetmainargs
#define _tstart _wstart
#define _tmain wmain
#define _runtmain _runwmain
#else
#define __tgetmainargs __getmainargs
#define _tstart _start
#define _tmain main
#define _runtmain _runmain
#endif
typedef struct { int newmode; } _startupinfo;
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
void __cdecl __set_app_type(int apptype);
unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
/* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
int _dowildcard;
void _tstart(void)
{
int newmode;
} _startupinfo;
__TRY__
_startupinfo start_info = {0};
void __getmainargs(int *pargc, char ***pargv, char ***penv, int globb, _startupinfo*);
// Sets the current application type
__set_app_type(_CONSOLE_APP);
int main(int argc, char **argv, char **env);
// Set default FP precision to 53 bits (8-byte double)
// _MCW_PC (Precision control) is not supported on ARM
#if defined __i386__ || defined __x86_64__
_controlfp(_PC_53, _MCW_PC);
#endif
int _start(void)
__tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
exit(_tmain(__argc, __targv, _tenviron));
}
int _runtmain(int argc, /* as tcc passed in */ char **argv)
{
int argc; char **argv; char **env; int ret;
_startupinfo start_info = {0};
#ifdef UNICODE
_startupinfo start_info = {0};
_controlfp(0x10000, 0x30000);
__set_app_type(__CONSOLE_APP);
__getmainargs(&argc, &argv, &env, 0, &start_info);
ret = main(argc, argv, env);
exit(ret);
__tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info);
/* may be wrong when tcc has received wildcards (*.c) */
if (argc < __argc) {
__targv += __argc - argc;
__argc = argc;
}
#else
__argc = argc;
__targv = argv;
#endif
#if defined __i386__ || defined __x86_64__
_controlfp(_PC_53, _MCW_PC);
#endif
return _tmain(__argc, __targv, _tenviron);
}
// =============================================

3
tinyc/win32/lib/crt1w.c Normal file
View file

@ -0,0 +1,3 @@
#define _UNICODE 1
#define UNICODE 1
#include "crt1.c"

View file

@ -2,9 +2,9 @@
#include <windows.h>
BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved);
BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved);
BOOL WINAPI _dllstart(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
BOOL WINAPI _dllstart(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
{
BOOL bRet;
bRet = DllMain (hDll, dwReason, lpReserved);

View file

@ -2,7 +2,7 @@
#include <windows.h>
BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}

View file

@ -288,6 +288,8 @@ GetModuleFileNameA
GetModuleFileNameW
GetModuleHandleA
GetModuleHandleW
GetModuleHandleExA
GetModuleHandleExW
GetNamedPipeHandleStateA
GetNamedPipeHandleStateW
GetNamedPipeInfo
@ -549,9 +551,13 @@ ResetEvent
ResetNLSUserInfoCache
ResetWriteWatch
ResumeThread
RtlAddFunctionTable
RtlDeleteFunctionTable
RtlFillMemory
RtlInstallFunctionTableCallback
RtlMoveMemory
RtlUnwind
RtlUnwindEx
RtlZeroMemory
SMapLS
SMapLS_IP_EBP_12
@ -614,6 +620,7 @@ SetFileApisToOEM
SetFileAttributesA
SetFileAttributesW
SetFilePointer
SetFilePointerEx
SetFileTime
SetHandleContext
SetHandleCount

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -336,6 +336,10 @@ GetWindow
GetWindowContextHelpId
GetWindowDC
GetWindowInfo
GetWindowLongPtrA
GetWindowLongPtrW
SetWindowLongPtrA
SetWindowLongPtrW
GetWindowLongA
GetWindowLongW
GetWindowModuleFileNameA

View file

@ -1,6 +1,10 @@
//+---------------------------------------------------------------------------
// _UNICODE for tchar.h, UNICODE for API
#include <tchar.h>
#include <windows.h>
#include <stdlib.h>
#define __UNKNOWN_APP 0
#define __CONSOLE_APP 1
@ -8,42 +12,64 @@
void __set_app_type(int);
void _controlfp(unsigned a, unsigned b);
int _winstart(void)
#ifdef _UNICODE
#define __tgetmainargs __wgetmainargs
#define _twinstart _wwinstart
#define _runtwinmain _runwwinmain
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
#else
#define __tgetmainargs __getmainargs
#define _twinstart _winstart
#define _runtwinmain _runwinmain
#endif
typedef struct { int newmode; } _startupinfo;
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
static int go_winmain(TCHAR *arg1)
{
char *szCmd; STARTUPINFO startinfo;
STARTUPINFO si;
_TCHAR *szCmd, *p;
int fShow;
__set_app_type(__GUI_APP);
_controlfp(0x10000, 0x30000);
GetStartupInfo(&si);
if (si.dwFlags & STARTF_USESHOWWINDOW)
fShow = si.wShowWindow;
else
fShow = SW_SHOWDEFAULT;
szCmd = GetCommandLine();
if (szCmd)
{
while (' ' == *szCmd) szCmd++;
if ('\"' == *szCmd)
{
while (*++szCmd)
if ('\"' == *szCmd) { szCmd++; break; }
}
else
{
while (*szCmd && ' ' != *szCmd) szCmd++;
}
while (' ' == *szCmd) szCmd++;
}
GetStartupInfo(&startinfo);
exit(WinMain(GetModuleHandle(NULL), NULL, szCmd,
(startinfo.dwFlags & STARTF_USESHOWWINDOW) ?
startinfo.wShowWindow : SW_SHOWDEFAULT));
szCmd = NULL, p = GetCommandLine();
if (arg1)
szCmd = _tcsstr(p, arg1);
if (NULL == szCmd)
szCmd = _tcsdup(__T(""));
else if (szCmd > p && szCmd[-1] == __T('"'))
--szCmd;
#if defined __i386__ || defined __x86_64__
_controlfp(0x10000, 0x30000);
#endif
return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
}
int _runwinmain(int argc, char **argv)
int _twinstart(void)
{
char *szCmd = NULL;
char *p = GetCommandLine();
if (argc > 1) szCmd = strstr(p, argv[1]);
if (NULL == szCmd) szCmd = "";
else if (szCmd > p && szCmd[-1] == '\"') --szCmd;
return WinMain(GetModuleHandle(NULL), NULL, szCmd, SW_SHOWDEFAULT);
__TRY__
_startupinfo start_info_con = {0};
__set_app_type(__GUI_APP);
__tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
exit(go_winmain(__argc > 1 ? __targv[1] : NULL));
}
int _runtwinmain(int argc, /* as tcc passed in */ char **argv)
{
#ifdef UNICODE
_startupinfo start_info = {0};
__tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info);
/* may be wrong when tcc has received wildcards (*.c) */
if (argc < __argc)
__targv += __argc - argc, __argc = argc;
#else
__argc = argc, __targv = argv;
#endif
return go_winmain(__argc > 1 ? __targv[1] : NULL);
}

View file

@ -0,0 +1,3 @@
#define _UNICODE 1
#define UNICODE 1
#include "wincrt1.c"