Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 9663 → Rev 9666

/programs/develop/ktcc/trunk/libc.obj/linuxtools/LoaderBuild
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/linuxtools/src/LoaderGen.c
File deleted
/programs/develop/ktcc/trunk/libc.obj/linuxtools/src/ExportGen.c
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/linuxtools/src/Makefile
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/libtcc/Makefile
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/source/libtcc/libtcc1.c
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/libtcc/memmove.asm
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/libtcc/memcpy.asm
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/libtcc/memset.asm
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/Makefile
File deleted
/programs/develop/ktcc/trunk/libc.obj/source/Tupfile.lua
2,12 → 2,7
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../../../" or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_gcc.lua")
 
CFLAGS = " -c -w -nostdinc -DGNUC -D_BUILD_LIBC -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie"
CFLAGS = " -c -nostdinc -DGNUC -D_BUILD_LIBC -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie"
INCLUDES = " -I../include"
 
tup.rule("../linuxtools/src/ExportGen.c", "gcc %f -o %o" , "../linuxtools/ExportGen")
tup.rule("../linuxtools/src/LoaderGen.c", "gcc %f -o %o" , "../linuxtools/LoaderGen")
 
tup.rule({"symbols.txt",extra_inputs = {"../linuxtools/ExportGen"}}, "../linuxtools/ExportGen %f %o" , "exports/exports.c")
 
tup.rule({"libc.c",extra_inputs = {"exports/exports.c"}} , "kos32-gcc" .. CFLAGS .. INCLUDES .. " -o %o %f " .. tup.getconfig("KPACK_CMD"), "libc.obj")
tup.rule("libc.c", "kos32-gcc" .. CFLAGS .. INCLUDES .. " -o %o %f " .. tup.getconfig("KPACK_CMD"), "libc.obj")
/programs/develop/ktcc/trunk/libc.obj/source/crt/crt0.asm
1,35 → 1,32
;
; 2021, Edited by Coldy
;
; This module same as original crt0.asm, but cut:
; 1. virtual header block (hparams change to __app_params, hpath change to __app_path)
; 2. init heap of memory - not needed because 68.18 (68.19) init heap implicitly
; (it is does dll.obj)
; 3. loader (he lives in dll.obj)
;
 
format ELF
section '.text' executable
public start
public start as '_start'
;extrn mf_init
 
extrn main
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
include '../../../../../dll.inc'
;include '../../../../../debug.inc'
 
;start_:
virtual at 0
db 'MENUET01' ; 1. Magic number (8 bytes)
dd 0x01 ; 2. Version of executable file
dd start ; 3. Start address
imgsz dd 0x0 ; 4. Size of image
dd 0x100000 ; 5. Size of needed memory
dd 0x100000 ; 6. Pointer to stack
hparams dd 0x0 ; 7. Pointer to program arguments
hpath dd 0x0 ; 8. Pointer to program path
end virtual
include '../../../../../../proc32.inc'
include '../../../../../../macros.inc'
__DEBUG__ = 0
 
__app_params equ 0x1C ; Pointer to program arguments
;__app_path equ 0x20 ; Pointer to program path
 
start:
;DEBUGF 'Start programm\n'
;init heap of memory
mov eax,68
mov ebx,11
int 0x40
 
mov [argc], 0
mov eax, [hparams]
mov eax, [__app_params]
test eax, eax
jz .without_path
mov eax, path
85,7 → 82,6
jmp .parse
 
.run:
call load_imports
push argv
push [argc]
call main
112,101 → 108,9
inc [argc]
.dont_add:
ret
;==============================
 
;==============================
load_imports:
;==============================
;parameters
; none
;description
; imports must be located at end of image (but before BSS sections)
; the address of end of imports (next byte after imports) is located in imgsz
; look at each import from that address up to illegal import
; legal import is such that:
; first pointer points to procedure name
; and is smaller than imgsz
; second pointer points lo library name, starting with 0x55, 0xAA
; and is smaller than imgsz
; each library should be initialized as appropriate, once
; so as library is initialized, its name will be replaced 0x00
mov ebx, [imgsz] ; byte after imports
.handle_next_import:
sub ebx, 4 ; ebx = pointer to pointer to library name
mov esi, dword[ebx] ; esi = pointer to library name
push ebx
push esi
call load_library ; eax = pointer to library exports
pop esi
pop ebx
test eax, eax
jz .done
sub ebx, 4 ; ebx = pointer to pointer to symbol name
push ebx
stdcall dll.GetProcAddress, eax, dword[ebx]
pop ebx
test eax, eax
jz .fail
mov dword[ebx], eax
jmp .handle_next_import
.done:
;DEBUGF 1, "Library: %s not loaded!\n", esi
;mcall -1
ret
.fail:
ret
;==============================
 
;==============================
load_library:
;==============================
;parameters
; ebx: library name address
;description
; each library should be initialized as appropriate, once
; so as library is initialized, its name will be replaced 0x00
; and 4 next bytes will be set to address of library
; first two bytes of library name must be 0x55, 0xAA (is like a magic)
cld ; move esi further, not back
cmp esi, [imgsz]
ja .fail
lodsb ; al = first byte of library name
cmp al, 0x55
jne .fail
lodsb ; al = second byte of library name
cmp al, 0xAA
jne .fail
lodsb ; al = third byte of library name (0x00 if the library is already loaded)
test al, al
jnz .load
lodsd ; if we here, then third byte is 0x00 => address of library is in next 4 bytes
; now eax contains address of library
ret
.load:
dec esi ; we checked on 0 before, let's go back
mov eax, 68
mov ebx, 19
mov ecx, esi
int 0x40 ; eax = address of exports
mov byte[esi], 0 ; library is loaded, let's place 0 in first byte of name
mov [esi + 1], eax ; now next 4 bytes of library name are replaced by address of library
; call lib_init
stdcall dll.GetProcAddress, eax, lib_init_str ; eax = address of lib_init
test eax, eax
jz .ret
stdcall dll.Init, eax
.ret:
mov eax, [esi + 1] ; put address of library into eax
ret
.fail:
mov eax, 0
ret
 
;==============================
 
lib_init_str db 'lib_init', 0
 
public argc as '__argc'
public params as '__argv'
public path as '__path'
219,3 → 123,5
path rb buf_len
params rb buf_len
 
;section '.data'
;include_debug_strings ; ALWAYS present in data section
/programs/develop/ktcc/trunk/libc.obj/source/libc.c
1,3 → 1,5
#include <setjmp.h>
 
#include "ctype/is.c"
#include "ctype/tolower.c"
#include "ctype/toupper.c"
146,6 → 148,174
".include \"setjmp/setjmp.s\""
);
 
#include "libtcc/libtcc1.c"
#include "libtcc1/libtcc1.c"
#include "stdlib/___chkstk_ms.c"
#include "exports/exports.c"
 
 
ksys_dll_t EXPORTS[] = {
{"clearerr", &clearerr},
{"debug_printf", &debug_printf},
{"fclose", &fclose},
{"feof", &feof},
{"ferror", &ferror},
{"fflush", &fflush},
{"fgetc", &fgetc},
{"fgetpos", &fgetpos},
{"fgets", &fgets},
{"fopen", &fopen},
{"fprintf", &fprintf},
{"fputc", &fputc},
{"fputs", &fputs},
{"fread", &fread},
{"freopen", &freopen},
{"fscanf", &fscanf},
{"fseek", &fseek},
{"fsetpos", &fsetpos},
{"ftell", &ftell},
{"fwrite", &fwrite},
{"getchar", &getchar},
{"gets", &gets},
{"perror", &perror},
{"printf", &printf},
{"puts", &puts},
{"remove", &remove},
{"rename", &rename},
{"rewind", &rewind},
{"scanf", &scanf},
{"setbuf", &setbuf},
{"setvbuf", &setvbuf},
{"snprintf", &snprintf},
{"sprintf", &sprintf},
{"sscanf", &sscanf},
{"tmpfile", &tmpfile},
{"tmpnam", &tmpnam},
{"vfscanf", &vfscanf},
{"vprintf", &vprintf},
{"vfscanf", &vfscanf},
{"vsprintf", &vsprintf},
{"vsnprintf", &vsnprintf},
{"vsscanf", &vsscanf},
{"ungetc", &ungetc},
{"abs", &abs},
{"atoi", &atoi},
{"atol", &atol},
{"atoll", &atoll},
{"atof", &atof},
{"calloc", &calloc},
{"exit", &exit},
{"free", &free},
{"itoa", &itoa},
{"labs", &labs},
{"llabs", &llabs},
{"malloc", &malloc},
{"realloc", &realloc},
{"strtol", &strtol},
{"srand", &srand},
{"rand", &rand},
{"qsort", &qsort},
{"strtod", &strtod},
{"__assert_fail", &__assert_fail},
{"memchr", &memchr},
{"memcmp", &memcmp},
{"strncat", &strncat},
{"strchr", &strchr},
{"strcat", &strcat},
{"strcmp", &strcmp},
{"strcoll", &strcoll},
{"strcpy", &strcpy},
{"strcspn", &strcspn},
{"strdup", &strdup},
{"strerror", &strerror},
{"strlen", &strlen},
{"strncat", &strncat},
{"strncmp", &strncmp},
{"strncpy", &strncpy},
{"strrchr", &strrchr},
{"strrev", &strrev},
{"strspn", &strspn},
{"strstr", &strstr},
{"strtok", &strtok},
{"strxfrm", &strxfrm},
{"_errno", &_errno},
{"closedir", &closedir},
{"opendir", &opendir},
{"readdir", &readdir},
{"rewinddir", &rewinddir},
{"seekdir", &seekdir},
{"telldir", &telldir},
{"getcwd", &getcwd},
{"mkdir", &mkdir},
{"rmdir", &rmdir},
{"setcwd", &setcwd},
{"getcwd", &getcwd},
{"socket", &socket},
{"close", &close},
{"bind", &bind},
{"listen", &listen},
{"connect", &connect},
{"accept", &accept},
{"send", &send},
{"recv", &recv},
{"setsockopt", &setsockopt},
{"socketpair", &socketpair},
{"acosh", &acosh},
{"asinh", &asinh},
{"atanh", &atanh},
{"acosh", &acosh},
{"frexp", &frexp},
{"hypot", &hypot},
{"ldexp", &ldexp},
{"sinh", &sinh},
{"tanh", &tanh},
{"acos", &acos},
{"asin", &asin},
{"atan", &atan},
{"atan2", &atan2},
{"ceil", &ceil},
{"cos", &cos},
{"sin", &sin},
{"tan", &tan},
{"exp", &exp},
{"fabs", &fabs},
{"floor", &floor},
{"fmod", &fmod},
{"log", &log},
{"modf", &modf},
{"modfl", &modfl},
{"pow", &pow},
{"pow2", &pow2},
{"pow10", &pow10},
{"longjmp", &longjmp},
{"setjmp", &setjmp},
{"__is", &__is},
{"tolower", &tolower},
{"toupper", &toupper},
{"con_set_title", &con_set_title},
{"con_init", &con_init},
{"con_init_opt", &con_init_opt},
{"con_write_asciiz", &con_write_asciiz},
{"con_write_string", &con_write_string},
{"con_printf", &con_printf},
{"con_exit", &con_exit},
{"con_get_flags", &con_get_flags},
{"con_set_flags", &con_set_flags},
{"con_kbhit", &con_kbhit},
{"con_getch", &con_getch},
{"con_getch2", &con_getch2},
{"con_gets", &con_gets},
{"con_gets2", &con_gets2},
{"con_get_font_height", &con_get_font_height},
{"con_get_cursor_height", &con_get_cursor_height},
{"con_set_cursor_height", &con_set_cursor_height},
{"con_cls", &con_cls},
{"con_get_cursor_pos", &con_get_cursor_pos},
{"con_set_cursor_pos", &con_set_cursor_pos},
{"mktime", &mktime},
{"time", &time},
{"localtime", &localtime},
{"asctime", &asctime},
{"difftime", &difftime},
{"basename", &basename},
{"dirname", &dirname},
NULL,
};
/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/Makefile
0,0 → 1,16
KTCC=kos32-tcc
 
FASM=fasm
 
OBJ= memcpy.o memmove.o memset.o libtcc1.o
 
all: $(OBJ)
ar -crs ../../../bin/lib/libtcc.a $(OBJ)
rm -f *.o
 
%.o : %.c
$(KTCC) -c $< -o $@
 
%.o : %.asm
$(FASM) $< $@
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/libtcc1.c
0,0 → 1,763
/* TCC runtime library.
Parts of this code are (c) 2002 Fabrice Bellard
 
Copyright (C) 1987, 1988, 1992, 1994, 1995 Free Software Foundation, Inc.
 
This file is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
 
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
 
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
 
//#include <stdint.h>
#define TCC_TARGET_I386
 
#define W_TYPE_SIZE 32
#define BITS_PER_UNIT 8
 
typedef int Wtype;
typedef unsigned int UWtype;
typedef unsigned int USItype;
typedef long long DWtype;
typedef unsigned long long UDWtype;
 
struct DWstruct {
Wtype low, high;
};
 
typedef union
{
struct DWstruct s;
DWtype ll;
} DWunion;
 
typedef long double XFtype;
#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
 
/* the following deal with IEEE single-precision numbers */
#define EXCESS 126
#define SIGNBIT 0x80000000
#define HIDDEN (1 << 23)
#define SIGN(fp) ((fp) & SIGNBIT)
#define EXP(fp) (((fp) >> 23) & 0xFF)
#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN)
#define PACK(s,e,m) ((s) | ((e) << 23) | (m))
 
/* the following deal with IEEE double-precision numbers */
#define EXCESSD 1022
#define HIDDEND (1 << 20)
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \
(fp.l.lower >> 22))
#define HIDDEND_LL ((long long)1 << 52)
#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m))
 
/* the following deal with x86 long double-precision numbers */
#define EXCESSLD 16382
#define EXPLD(fp) (fp.l.upper & 0x7fff)
#define SIGNLD(fp) ((fp.l.upper) & 0x8000)
 
/* only for x86 */
union ldouble_long {
long double ld;
struct {
unsigned long long lower;
unsigned short upper;
} l;
};
 
union double_long {
double d;
#if 1
struct {
unsigned int lower;
int upper;
} l;
#else
struct {
int upper;
unsigned int lower;
} l;
#endif
long long ll;
};
 
union float_long {
float f;
unsigned int l;
};
 
/* XXX: we don't support several builtin supports for now */
#if !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM)
 
/* XXX: use gcc/tcc intrinsic ? */
#if defined(TCC_TARGET_I386)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
__asm__ ("subl %5,%1\n\tsbbl %3,%0" \
: "=r" ((USItype) (sh)), \
"=&r" ((USItype) (sl)) \
: "0" ((USItype) (ah)), \
"g" ((USItype) (bh)), \
"1" ((USItype) (al)), \
"g" ((USItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
__asm__ ("mull %3" \
: "=a" ((USItype) (w0)), \
"=d" ((USItype) (w1)) \
: "%0" ((USItype) (u)), \
"rm" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
__asm__ ("divl %4" \
: "=a" ((USItype) (q)), \
"=d" ((USItype) (r)) \
: "0" ((USItype) (n0)), \
"1" ((USItype) (n1)), \
"rm" ((USItype) (dv)))
#define count_leading_zeros(count, x) \
do { \
USItype __cbtmp; \
__asm__ ("bsrl %1,%0" \
: "=r" (__cbtmp) : "rm" ((USItype) (x))); \
(count) = __cbtmp ^ 31; \
} while (0)
#else
#error unsupported CPU type
#endif
 
/* most of this code is taken from libgcc2.c from gcc */
UDWtype __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
{
DWunion ww;
DWunion nn, dd;
DWunion rr;
UWtype d0, d1, n0, n1, n2;
UWtype q0, q1;
UWtype b, bm;
 
nn.ll = n;
dd.ll = d;
 
d0 = dd.s.low;
d1 = dd.s.high;
n0 = nn.s.low;
n1 = nn.s.high;
 
#if !defined(UDIV_NEEDS_NORMALIZATION)
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
 
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
 
/* Remainder in n0. */
}
else
{
/* qq = NN / 0d */
 
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
 
udiv_qrnnd (q1, n1, 0, n1, d0);
udiv_qrnnd (q0, n0, n1, n0, d0);
 
/* Remainder in n0. */
}
 
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = 0;
*rp = rr.ll;
}
}
 
#else /* UDIV_NEEDS_NORMALIZATION */
 
if (d1 == 0)
{
if (d0 > n1)
{
/* 0q = nn / 0D */
 
count_leading_zeros (bm, d0);
 
if (bm != 0)
{
/* Normalize, i.e. make the most significant bit of the
denominator set. */
 
d0 = d0 << bm;
n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
n0 = n0 << bm;
}
 
udiv_qrnnd (q0, n0, n1, n0, d0);
q1 = 0;
 
/* Remainder in n0 >> bm. */
}
else
{
/* qq = NN / 0d */
 
if (d0 == 0)
d0 = 1 / d0; /* Divide intentionally by zero. */
 
count_leading_zeros (bm, d0);
 
if (bm == 0)
{
/* From (n1 >= d0) /\ (the most significant bit of d0 is set),
conclude (the most significant bit of n1 is set) /\ (the
leading quotient digit q1 = 1).
 
This special case is necessary, not an optimization.
(Shifts counts of W_TYPE_SIZE are undefined.) */
 
n1 -= d0;
q1 = 1;
}
else
{
/* Normalize. */
 
b = W_TYPE_SIZE - bm;
 
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
 
udiv_qrnnd (q1, n1, n2, n1, d0);
}
 
/* n1 != d0... */
 
udiv_qrnnd (q0, n0, n1, n0, d0);
 
/* Remainder in n0 >> bm. */
}
 
if (rp != 0)
{
rr.s.low = n0 >> bm;
rr.s.high = 0;
*rp = rr.ll;
}
}
#endif /* UDIV_NEEDS_NORMALIZATION */
 
else
{
if (d1 > n1)
{
/* 00 = nn / DD */
 
q0 = 0;
q1 = 0;
 
/* Remainder in n1n0. */
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
/* 0q = NN / dd */
 
count_leading_zeros (bm, d1);
if (bm == 0)
{
/* From (n1 >= d1) /\ (the most significant bit of d1 is set),
conclude (the most significant bit of n1 is set) /\ (the
quotient digit q0 = 0 or 1).
 
This special case is necessary, not an optimization. */
 
/* The condition on the next line takes advantage of that
n1 >= d1 (true due to program flow). */
if (n1 > d1 || n0 >= d0)
{
q0 = 1;
sub_ddmmss (n1, n0, n1, n0, d1, d0);
}
else
q0 = 0;
 
q1 = 0;
 
if (rp != 0)
{
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
UWtype m1, m0;
/* Normalize. */
 
b = W_TYPE_SIZE - bm;
 
d1 = (d1 << bm) | (d0 >> b);
d0 = d0 << bm;
n2 = n1 >> b;
n1 = (n1 << bm) | (n0 >> b);
n0 = n0 << bm;
 
udiv_qrnnd (q0, n1, n2, n1, d1);
umul_ppmm (m1, m0, q0, d0);
 
if (m1 > n1 || (m1 == n1 && m0 > n0))
{
q0--;
sub_ddmmss (m1, m0, m1, m0, d1, d0);
}
 
q1 = 0;
 
/* Remainder in (n1n0 - m1m0) >> bm. */
if (rp != 0)
{
sub_ddmmss (n1, n0, n1, n0, m1, m0);
rr.s.low = (n1 << b) | (n0 >> bm);
rr.s.high = n1 >> bm;
*rp = rr.ll;
}
}
}
}
 
ww.s.low = q0;
ww.s.high = q1;
return ww.ll;
}
 
#define __negdi2(a) (-(a))
 
long long __divdi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0) {
c = ~c;
vv.ll = __negdi2 (vv.ll);
}
w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
if (c)
w = __negdi2 (w);
return w;
}
 
// https://github.com/KaMeHb-UA/UE4m/blob/1d9ad5bfead06520570c7f24dad062f9f8717c1a/\
Engine/Extras/ThirdPartyNotUE/emsdk/emscripten/incoming/system/lib/compiler-rt/lib/\
builtins/divmoddi4.c
long long __divmoddi4(long long a, long long b, long long* rem)
{
long long d = __divdi3(a, b);
*rem = a - (d * b);
return d;
}
 
long long __moddi3(long long u, long long v)
{
int c = 0;
DWunion uu, vv;
DWtype w;
uu.ll = u;
vv.ll = v;
if (uu.s.high < 0) {
c = ~c;
uu.ll = __negdi2 (uu.ll);
}
if (vv.s.high < 0)
vv.ll = __negdi2 (vv.ll);
__udivmoddi4 (uu.ll, vv.ll, (UDWtype *) &w);
if (c)
w = __negdi2 (w);
return w;
}
 
unsigned long long __udivdi3(unsigned long long u, unsigned long long v)
{
return __udivmoddi4 (u, v, (UDWtype *) 0);
}
 
unsigned long long __umoddi3(unsigned long long u, unsigned long long v)
{
UDWtype w;
__udivmoddi4 (u, v, &w);
return w;
}
 
/* XXX: fix tcc's code generator to do this instead */
long long __ashrdi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = u.s.high >> (b - 32);
u.s.high = u.s.high >> 31;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
 
/* XXX: fix tcc's code generator to do this instead */
unsigned long long __lshrdi3(unsigned long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.low = (unsigned)u.s.high >> (b - 32);
u.s.high = 0;
} else if (b != 0) {
u.s.low = ((unsigned)u.s.low >> b) | (u.s.high << (32 - b));
u.s.high = (unsigned)u.s.high >> b;
}
return u.ll;
#else
return a >> b;
#endif
}
 
/* XXX: fix tcc's code generator to do this instead */
long long __ashldi3(long long a, int b)
{
#ifdef __TINYC__
DWunion u;
u.ll = a;
if (b >= 32) {
u.s.high = (unsigned)u.s.low << (b - 32);
u.s.low = 0;
} else if (b != 0) {
u.s.high = ((unsigned)u.s.high << b) | ((unsigned)u.s.low >> (32 - b));
u.s.low = (unsigned)u.s.low << b;
}
return u.ll;
#else
return a << b;
#endif
}
 
#ifndef COMMIT_4ad186c5ef61_IS_FIXED
long long __tcc_cvt_ftol(long double x)
{
unsigned c0, c1;
long long ret;
__asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
c1 = c0 | 0x0C00;
__asm__ __volatile__ ("fldcw %0" : : "m" (c1));
__asm__ __volatile__ ("fistpll %0" : "=m" (ret));
__asm__ __volatile__ ("fldcw %0" : : "m" (c0));
return ret;
}
#endif
 
#endif /* !__x86_64__ */
 
/* XXX: fix tcc's code generator to do this instead */
float __floatundisf(unsigned long long a)
{
DWunion uu;
XFtype r;
 
uu.ll = a;
if (uu.s.high >= 0) {
return (float)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (float)r;
}
}
 
double __floatundidf(unsigned long long a)
{
DWunion uu;
XFtype r;
 
uu.ll = a;
if (uu.s.high >= 0) {
return (double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (double)r;
}
}
 
long double __floatundixf(unsigned long long a)
{
DWunion uu;
XFtype r;
 
uu.ll = a;
if (uu.s.high >= 0) {
return (long double)uu.ll;
} else {
r = (XFtype)uu.ll;
r += 18446744073709551616.0;
return (long double)r;
}
}
 
unsigned long long __fixunssfdi (float a1)
{
register union float_long fl1;
register int exp;
register unsigned long l;
 
fl1.f = a1;
 
if (fl1.l == 0)
return (0);
 
exp = EXP (fl1.l) - EXCESS - 24;
 
l = MANT(fl1.l);
if (exp >= 41)
return (unsigned long long)-1;
else if (exp >= 0)
return (unsigned long long)l << exp;
else if (exp >= -23)
return l >> -exp;
else
return 0;
}
 
unsigned long long __fixunsdfdi (double a1)
{
register union double_long dl1;
register int exp;
register unsigned long long l;
 
dl1.d = a1;
 
if (dl1.ll == 0)
return (0);
 
exp = EXPD (dl1) - EXCESSD - 53;
 
l = MANTD_LL(dl1);
 
if (exp >= 12)
return (unsigned long long)-1;
else if (exp >= 0)
return l << exp;
else if (exp >= -52)
return l >> -exp;
else
return 0;
}
 
unsigned long long __fixunsxfdi (long double a1)
{
register union ldouble_long dl1;
register int exp;
register unsigned long long l;
 
dl1.ld = a1;
 
if (dl1.l.lower == 0 && dl1.l.upper == 0)
return (0);
 
exp = EXPLD (dl1) - EXCESSLD - 64;
 
l = dl1.l.lower;
 
if (exp > 0)
return (unsigned long long)-1;
else if (exp >= -63)
return l >> -exp;
else
return 0;
}
 
long long __fixsfdi (float a1)
{
long long ret; int s;
ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
 
long long __fixdfdi (double a1)
{
long long ret; int s;
ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
 
long long __fixxfdi (long double a1)
{
long long ret; int s;
ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
 
#if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
 
#ifndef __TINYC__
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#else
/* Avoid including stdlib.h because it is not easily available when
cross compiling */
#include <stddef.h> /* size_t definition is needed for a x86_64-tcc to parse memset() */
void *malloc(unsigned long long);
void *memset(void *s, int c, size_t n);
void free(void*);
void abort(void);
#endif
 
enum __va_arg_type {
__va_gen_reg, __va_float_reg, __va_stack
};
 
//This should be in sync with the declaration on our include/stdarg.h
/* GCC compatible definition of va_list. */
typedef struct {
unsigned int gp_offset;
unsigned int fp_offset;
union {
unsigned int overflow_offset;
char *overflow_arg_area;
};
char *reg_save_area;
} __va_list_struct;
 
#undef __va_start
#undef __va_arg
#undef __va_copy
#undef __va_end
 
void __va_start(__va_list_struct *ap, void *fp)
{
memset(ap, 0, sizeof(__va_list_struct));
*ap = *(__va_list_struct *)((char *)fp - 16);
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
ap->reg_save_area = (char *)fp - 176 - 16;
}
 
void *__va_arg(__va_list_struct *ap,
enum __va_arg_type arg_type,
int size, int align)
{
size = (size + 7) & ~7;
align = (align + 7) & ~7;
switch (arg_type) {
case __va_gen_reg:
if (ap->gp_offset + size <= 48) {
ap->gp_offset += size;
return ap->reg_save_area + ap->gp_offset - size;
}
goto use_overflow_area;
 
case __va_float_reg:
if (ap->fp_offset < 128 + 48) {
ap->fp_offset += 16;
return ap->reg_save_area + ap->fp_offset - 16;
}
size = 8;
goto use_overflow_area;
 
case __va_stack:
use_overflow_area:
ap->overflow_arg_area += size;
ap->overflow_arg_area = (char*)((intptr_t)(ap->overflow_arg_area + align - 1) & -(intptr_t)align);
return ap->overflow_arg_area - size;
 
default:
#ifndef __TINYC__
fprintf(stderr, "unknown ABI type for __va_arg\n");
#endif
abort();
}
}
 
#endif /* __x86_64__ */
 
/* Flushing for tccrun */
#if defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_I386)
 
void __clear_cache(void *beginning, void *end)
{
}
 
#elif defined(TCC_TARGET_ARM)
 
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
 
void __clear_cache(void *beginning, void *end)
{
/* __ARM_NR_cacheflush is kernel private and should not be used in user space.
* However, there is no ARM asm parser in tcc so we use it for now */
#if 1
syscall(__ARM_NR_cacheflush, beginning, end, 0);
#else
__asm__ ("push {r7}\n\t"
"mov r7, #0xf0002\n\t"
"mov r2, #0\n\t"
"swi 0\n\t"
"pop {r7}\n\t"
"ret");
#endif
}
 
#else
#warning __clear_cache not defined for this architecture, avoid using tcc -run
#endif
/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/memcpy.asm
0,0 → 1,24
format ELF
 
section '.text' executable
include '../../../../../../proc32.inc'
 
public memcpy
 
proc memcpy c, to:dword,from:dword,count:dword
push esi
push edi
mov ecx,[count]
test ecx,ecx
jz no_copy_block
mov esi,[from]
mov edi,[to]
cld
rep movsb
no_copy_block:
 
pop edi
pop esi
mov eax, [to]
ret
endp
/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/memmove.asm
0,0 → 1,34
format ELF
 
section '.text' executable
include '../../../../../../proc32.inc'
 
public memmove
 
proc memmove c, to:dword,from:dword,count:dword
 
push esi
push edi
mov ecx,[count]
test ecx,ecx
jz no_copy_block_
mov esi,[from]
mov edi,[to]
cmp esi, edi
je no_copy_block_
jg copy_
add esi, ecx
add edi, ecx
dec esi
dec edi
std
copy_:
rep movsb
cld
no_copy_block_:
 
pop edi
pop esi
mov eax,[to]
ret
endp
/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/memset.asm
0,0 → 1,16
format ELF
section '.text' executable
public memset
 
memset:
push edi
mov edi,[esp+8]
mov eax,[esp+12]
mov ecx,[esp+16]
jecxz .no_set
cld
rep stosb
.no_set:
mov eax, [esp+8]
pop edi
ret