/programs/develop/libraries/kolibri-libc/include/stdint.h |
---|
23,6 → 23,10 |
#define INT64_MIN (-9223372036854775807LL-1LL) |
#define INT64_MAX (9223372036854775807LL) |
#define UINT64_MAX (18446744073709551615ULL) |
#else |
#define INT64_MAX 0x7fffffffffffffffLL |
#define INT64_MIN (-INT64_MAX - 1LL) |
#define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL) |
#endif |
#endif /* _STDINT_H_*/ |
/programs/develop/libraries/kolibri-libc/include/stdio.h |
---|
107,11 → 107,12 |
extern int _FUNC(puts)(const char *); |
extern int _FUNC(scanf)(const char *restrict, ...); |
extern char* _FUNC(gets)(char *str); |
//extern int _FUNC(ungetc)(int, FILE *); |
extern int _FUNC(ungetc)(int, FILE *); |
extern int _FUNC(vfprintf)(FILE *restrict, const char *restrict, va_list); |
extern int _FUNC(vfscanf)(FILE *restrict, const char *restrict, va_list); |
extern int _FUNC(vprintf)(const char *restrict, va_list); |
extern int _FUNC(vscanf)(const char *restrict, va_list); |
extern int _FUNC(sscanf)(const char*, const char *restrict, ...); |
extern int _FUNC(vsscanf)(const char *, const char*, va_list); |
extern int _FUNC(remove)(const char *); |
/programs/develop/libraries/kolibri-libc/include/string.h |
---|
29,13 → 29,16 |
area pointed to by s1. If the two areas overlap, behaviour is undefined. |
Returns the value of s1. |
*/ |
extern void* _FUNC(memcpy)(void* s1, const void* s2, size_t n); |
/* Copy a number of n characters from the memory area pointed to by s2 to the |
area pointed to by s1. The two areas may overlap. |
Returns the value of s1. |
*/ |
#ifdef __TINYC__ |
extern void* memcpy(void* s1, const void* s2, size_t n); |
extern void* memset(void* s, int c, size_t n); |
extern void* memmove(void* s1, const void* s2, size_t n); |
#else |
extern void* _FUNC(memcpy)(void* s1, const void* s2, size_t n); |
extern void* _FUNC(memset)(void* s, int c, size_t n); |
extern void* _FUNC(memmove)(void* s1, const void* s2, size_t n); |
#endif |
/* Copy the character array s2 (including terminating '\0' byte) into the |
character array s1. |
160,14 → 163,6 |
*/ |
extern char* _FUNC(strtok)(char* s1, const char* s2); |
/* Miscellaneous functions */ |
/* Write the character c (interpreted as unsigned char) to the first n |
characters of the memory area pointed to by s. |
Returns s. |
*/ |
extern void* _FUNC(memset)(void* s, int c, size_t n); |
/* Map an error number to a (locale-specific) error message string. Error |
numbers are typically errno values, but any number is mapped to a message. |
TODO: PDCLib does not yet support locales. |
/programs/develop/libraries/kolibri-libc/include/sys/ksys.h |
---|
152,7 → 152,7 |
unsigned in_data_size; |
void* out_data_ptr; |
unsigned out_data_size; |
}ksys_drv_ctl_t; |
}ksys_ioctl_t; |
#pragma pack(pop) |
1028,7 → 1028,7 |
} |
static inline |
unsigned _ksys_work_driver(ksys_drv_ctl_t *ioctl) |
unsigned _ksys_work_driver(ksys_ioctl_t *ioctl) |
{ |
unsigned status; |
asm_inline( |
/programs/develop/libraries/kolibri-libc/lib/crt0.o |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/x-object |
/programs/develop/libraries/kolibri-libc/lib/libtcc.a |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/x-archive |
Property changes: |
Added: svn:mime-type |
+application/x-archive |
\ No newline at end of property |
/programs/develop/libraries/kolibri-libc/samples/Makefile |
---|
1,5 → 1,6 |
KTCC=../../../ktcc/trunk/bin/kos32-tcc |
FASM= fasm |
KPACK = kpack |
CFLAGS = -I../include |
LDFLAGS = -nostdlib -L../lib ../lib/crt0.o |
12,14 → 13,17 |
whois.kex \ |
file_io.kex \ |
tmpdisk_work.kex \ |
exp_drv_work.kex |
fasm/sprintf_test.kex |
all: $(BIN) |
%.kex : %.c |
$(KTCC) $(CFLAGS) $(LDFLAGS) $< -o $@ -lnetwork -lc.obj |
$(KTCC) $(CFLAGS) $(LDFLAGS) $< -o $@ -ltcc -lnetwork -lc.obj |
$(KPACK) --nologo $@ |
%.kex : %.asm |
$(FASM) $< $@ |
$(KPACK) --nologo $@ |
clean: |
rm *.kex |
/programs/develop/libraries/kolibri-libc/samples/basic_gui.c |
---|
64,7 → 64,7 |
ksys_pos_t mouse_pos; |
strcpy(statusbar, "Program running...Double click on TEXT for details"); |
_ksys_get_colors(&sys_color_table); |
_ksys_get_system_colors(&sys_color_table); |
_ksys_set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside |
do{ |
/programs/develop/libraries/kolibri-libc/samples/fasm/sprintf_test.asm |
---|
0,0 → 1,81 |
format binary as "kex" |
use32 |
org 0x0 |
db 'MENUET01' |
dd 0x01 |
dd START |
dd IM_END |
dd MEM |
dd MEM |
dd 0 |
dd 0 |
include '../../../../../macros.inc' |
include '../../../../../proc32.inc' |
include '../../../../../KOSfuncs.inc' |
include '../../../../../dll.inc' |
;include '../../../../../debug-fdo.inc' |
;__DEBUG__ = 1 |
;__DEBUG_LEVEL__ = 2 |
START: |
stdcall dll.Load, @IMPORT |
test eax, eax |
jnz exit |
cinvoke libc_strlen, test_str1 |
;DEBUGF 2, "%d", eax |
mcall SF_SYS_MISC, SSF_MEM_ALLOC, eax |
mov [test_str2], eax |
cinvoke libc_sprintf, [test_str2], format_str, str_var, [dec_var], dword [float_var], dword[float_var+4], [hex_var] |
cinvoke libc_puts, test_str1 |
cinvoke libc_puts, [test_str2] |
cinvoke libc_strcmp, test_str1, [test_str2] |
test eax, eax |
jz print_succ |
jmp print_fail |
print_succ: |
cinvoke libc_puts, success_msg |
jmp exit |
print_fail: |
cinvoke libc_puts, failed_msg |
exit: |
mcall SF_SYS_MISC, SSF_MEM_FREE, [test_str2] |
mcall SF_TERMINATE_PROCESS |
; data |
format_str db "%s %d %f 0x%x", 0 |
test_str1 db "Test 463 -26.432100 0x9d81", 0 |
test_str2 dd 0 |
str_var db "Test",0 |
dec_var dd 463 |
float_var dq -26.4321 |
hex_var dd 40321 |
success_msg db "Test successful!", 0 |
failed_msg db "Test failed!", 0 |
align 4 |
@IMPORT: |
library libc, 'libc.obj' |
import libc, \ |
libc_sprintf, 'sprintf', \ |
libc_strcmp, 'strcmp', \ |
libc_strlen, 'strlen', \ |
libc_puts, 'puts' |
IM_END: |
align 4 |
rb 1024 ; stack |
MEM: |
/programs/develop/libraries/kolibri-libc/samples/stdio_test.c |
---|
3,8 → 3,11 |
#include <limits.h> |
char* test_string1 = "Hello world!"; |
int a, b; |
int main(int argc, char** argv){ |
sscanf("43 53","%d %d",&a, &b); |
printf("(43 53) = (%d %d)\n", a, b); |
printf("Hello world! = %s\n", test_string1); |
printf("345.358980 = %f\n", 345.35898); |
printf("345 = %d\n", (int)345.35898); |
/programs/develop/libraries/kolibri-libc/samples/tmpdisk_work.c |
---|
37,7 → 37,7 |
tmpdisk_add.disk_size = TMPDISK_SIZE*1024*1024/512; |
tmpdisk_add.disk_id = 5; |
ksys_drv_ctl_t ioctl; |
ksys_ioctl_t ioctl; |
ioctl.func_num = DEV_ADD_DISK; |
ioctl.handler = tmpdisk_drv; |
ioctl.in_data_ptr = &tmpdisk_add; |
53,4 → 53,4 |
puts(tmpdisk_res_text[6]); |
} |
exit(0); |
} |
} |
/programs/develop/libraries/kolibri-libc/source/Makefile |
---|
19,9 → 19,10 |
$(KPACK) $(LIB) |
../linuxtools/LoaderGen symbols.txt ../loader |
../linuxtools/LoaderBuild ../loader |
$(MAKE) -C libtcc |
rm -rf exports |
install: |
cp -f ../lib/libc.obj ~/.kex/root/RD/1/LIB |
clean: |
rm ../lib/libc.obj |
rm ../lib/* |
/programs/develop/libraries/kolibri-libc/source/crt/proc32.inc |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/crt/dll.inc |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/crt/macros.inc |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/crt/crt0_tiny.asm |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/crt/struct.inc |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/crt/config.inc |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/crt/crt0.asm |
---|
4,11 → 4,10 |
public start as '_start' |
;extrn mf_init |
extrn main |
;include 'debug2.inc' |
include 'proc32.inc' |
include 'macros.inc' |
include 'dll.inc' |
__DEBUG__=0 |
include '../../../../../proc32.inc' |
include '../../../../../macros.inc' |
include '../../../../../dll.inc' |
;include '../../../../../debug.inc' |
;start_: |
virtual at 0 |
151,9 → 150,12 |
mov dword[ebx], eax |
jmp .handle_next_import |
.done: |
;DEBUGF 1, "Library: %s not loaded!\n", esi |
;mcall -1 |
ret |
.fail: |
ret |
;============================== |
;============================== |
200,38 → 202,7 |
.fail: |
mov eax, 0 |
ret |
; ==== memmove for tcc ====== |
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 |
;============================== |
lib_init_str db 'lib_init', 0 |
239,7 → 210,6 |
public argc as '__argc' |
public params as '__argv' |
public path as '__path' |
public memmove |
section '.bss' |
buf_len = 0x400 |
249,5 → 219,3 |
path rb buf_len |
params rb buf_len |
;section '.data' |
;include_debug_strings ; ALWAYS present in data section |
/programs/develop/libraries/kolibri-libc/source/libc.c |
---|
8,7 → 8,6 |
#include "sys/closedir.c" |
#include "stdio/clearerr.c" |
#include "stdio/vscanf.c" |
#include "stdio/gets.c" |
#include "stdio/setbuf.c" |
#include "stdio/fgetc.c" |
21,7 → 20,6 |
#include "stdio/fseek.c" |
#include "stdio/fgetpos.c" |
#include "stdio/fclose.c" |
#include "stdio/vsscanf.c" |
#include "stdio/snprintf.c" |
#include "stdio/rename.c" |
#include "stdio/getchar.c" |
31,7 → 29,6 |
#include "stdio/fputs.c" |
#include "stdio/fputc.c" |
#include "stdio/fgets.c" |
#include "stdio/vfscanf.c" |
#include "stdio/fflush.c" |
#include "stdio/format_scan.c" |
#include "stdio/printf.c" |
93,7 → 90,6 |
#include "stdlib/difftime.c" |
#include "stdlib/realloc.c" |
#include "stdlib/ldiv.c" |
#include "stdlib/libtcc1.c" |
#include "stdlib/abs.c" |
#include "stdlib/div.c" |
#include "stdlib/atol.c" |
138,4 → 134,4 |
#include "stdlib/___chkstk_ms.c" |
#include "exports/exports.c" |
#include "exports/exports.c" |
/programs/develop/libraries/kolibri-libc/source/libtcc/Makefile |
---|
0,0 → 1,17 |
KTCC_DIR=../../../../ktcc/trunk |
KTCC=$(KTCC_DIR)/bin/kos32-tcc |
FASM=fasm |
OBJ= memcpy.o memmove.o memset.o libtcc1.o |
all: $(OBJ) |
ar -crs ../../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/libraries/kolibri-libc/source/libtcc/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/libraries/kolibri-libc/source/libtcc/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/libraries/kolibri-libc/source/libtcc/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/libraries/kolibri-libc/source/libtcc/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 |
/programs/develop/libraries/kolibri-libc/source/stdio/vfscanf.c |
---|
File deleted |
\ No newline at end of file |
/programs/develop/libraries/kolibri-libc/source/stdio/vsscanf.c |
---|
File deleted |
\ No newline at end of file |
/programs/develop/libraries/kolibri-libc/source/stdio/vscanf.c |
---|
File deleted |
/programs/develop/libraries/kolibri-libc/source/stdio/format_scan.c |
---|
13,13 → 13,28 |
-radix point always '.', no LOCALEs |
*/ |
#include <stdio.h> |
#include <ctype.h> |
#include <math.h> |
#include <stdarg.h> |
#include "format_scan.h" |
static int __try_parse_real(long double *real, int ch, const void *src, void *save, virtual_getc vgetc, virtual_ungetc vungetc) |
typedef int (*virtual_getc)(void *sp, const void *obj); |
typedef void (*virtual_ungetc)(void *sp, int c, const void *obj); |
enum flags_t |
{ |
flag_unsigned = 0x02, |
flag_register = 0x04, |
flag_plus = 0x08, |
flag_left_just = 0x10, |
flag_lead_zeros = 0x20, |
flag_space_plus = 0x40, |
flag_hash_sign = 0x80, |
flag_point = 0x100 |
}; |
int try_parse_real(long double *real, int ch, const void *src, void *save, virtual_getc vgetc, virtual_ungetc vungetc) |
// returns 1 if OK, -1 == EOF, -2 parse broken |
{ |
int sign = 1, have_digits = 0; |
133,12 → 148,12 |
} |
} |
div *= sign; |
*real *= pow(10,div); |
*real *= pow(10, div); |
return 1; |
} |
static int __try_parse_int(long long *digit, int ch, const void *src, void *save, virtual_getc vgetc, virtual_ungetc vungetc) |
int try_parse_int(long long *digit, int ch, const void *src, void *save, virtual_getc vgetc, virtual_ungetc vungetc) |
{ |
int sign = 1, base = 10, have_digits = 0; |
208,20 → 223,20 |
int _format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc) |
int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc) |
{ |
int i; |
int length; |
int fmt1, fmt2; // width, precision |
size_t pos, posc; |
const char *fmtc; // first point to %, fmtc points to specifier |
int ch; |
int format_flag; |
int flag_long; // 2 = long double or long long int or wchar |
int *point_to_n = NULL, nread = 0; |
int flags; // parsed flags |
int save = 0; |
char *arg_str; |
int i; |
int length; |
int fmt1, fmt2; // width, precision |
size_t pos, posc; |
const char *fmtc; // first point to %, fmtc points to specifier |
int ch; |
int format_flag; |
int flag_long; // 2 = long double or long long int or wchar |
int *point_to_n = NULL, nread = 0; |
int flags; // parsed flags |
int save = 0; |
char *arg_str; |
int *arg_int; |
long *arg_long; |
long long *arg_longlong; |
363,7 → 378,7 |
break; |
case 's': |
arg_str = va_arg(argp, char*); |
if (fmt1 == 0) length = STDIO_MAX_MEM; // max string scan 4096 |
if (fmt1 == 0) length = 4095; // max string scan 4096 |
else length = fmt1; |
for (i = 0; i < length; i++) |
{ |
375,7 → 390,7 |
break; |
case 'd': case 'i': case 'u': |
case 'o': case 'p': case 'x': |
i = __try_parse_int(&digit, ch, src, &save, vgetc, vungetc); |
i = try_parse_int(&digit, ch, src, &save, vgetc, vungetc); |
if (i < 0) goto exit_me; |
if (flag_long == 0) { arg_int = va_arg(argp, int*); *arg_int = (int)digit; } else |
385,7 → 400,7 |
case 'a': case 'A': case 'f': case 'F': |
case 'e': case 'E': |
case 'g': case 'G': |
i = __try_parse_real(&real, ch, src, &save, vgetc, vungetc); |
i = try_parse_real(&real, ch, src, &save, vgetc, vungetc); |
if (i < 0) goto exit_me; |
if (flag_long == 0) { arg_float = va_arg(argp, float*); *arg_float = (float)real; } else |
/programs/develop/libraries/kolibri-libc/source/stdio/fscanf.c |
---|
1,11 → 1,40 |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdlib.h> |
int fscanf(FILE* stream, const char* format, ...) |
int virtual_getc_file(void *sp, const void *obj) |
// get next chat from file obj, save point is ptr to string char ptr |
{ |
va_list arg; |
int n; |
FILE *f = (FILE *)obj; |
int ch = fgetc(f); |
//printf("getc '%c'[%d];", ch, ch); |
return ch; |
} |
void virtual_ungetc_file(void *sp, int c, const void *obj) |
// if can, one step back savepoint in s |
{ |
FILE *f = (FILE *)obj; |
if (f) ungetc(c, f); |
} |
int vfscanf ( FILE * stream, const char * format, va_list arg ) |
{ |
return format_scan(stream, format, arg, &virtual_getc_file, &virtual_ungetc_file); |
}; |
int fscanf ( FILE * stream, const char * format, ...) |
{ |
va_list arg; |
int n; |
va_start(arg, format); |
n = vfscanf(stream, format, arg); |
va_end(arg); |
return n; |
} |
/programs/develop/libraries/kolibri-libc/source/stdio/scanf.c |
---|
1,15 → 1,59 |
//#include "format_scan.h" |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdlib.h> |
#include <errno.h> |
#include <string.h> |
char *__scanf_buffer = 0; |
int virtual_getc_con(void *sp, const void *obj) |
// get next chat from string obj, save point is ptr to string char ptr |
{ |
int ch; |
const char**spc= (const char**)sp; |
if (!spc) return EOF; // error |
if (!*spc) *spc = __scanf_buffer; // first call, init savepoint |
while (!**spc) // need to read more |
{ |
if(!gets(__scanf_buffer)) return EOF; |
*spc = __scanf_buffer; |
strcat(__scanf_buffer,"\n"); // imitate delimiter |
} |
if (**spc == 26 || **spc == 3) // ^C ^Z end of scan, clear buffer |
{ |
*spc = __scanf_buffer; |
*__scanf_buffer = 0; |
return EOF; // ^C ^Z |
} |
ch = **spc; (*spc)++ ; |
//printf("getc '%c'[%d];", ch, ch); |
return ch; |
} |
void virtual_ungetc_con(void *sp, int c, const void *obj) |
// if can, one step back savepoint in s |
{ |
const char**spc= (const char**)sp; |
if (spc && *spc > __scanf_buffer) (*spc)--; |
//printf("Ungetc '%c'[%d];", c, c); |
} |
int vscanf ( const char * format, va_list arg ) |
{ |
return format_scan(NULL, format, arg, &virtual_getc_con, &virtual_ungetc_con); |
}; |
int scanf ( const char * format, ...) |
{ |
va_list arg; |
va_list arg; |
int n; |
va_start(arg, format); |
if(__scanf_buffer == NULL) __scanf_buffer = malloc(STDIO_MAX_MEM); |
if(__scanf_buffer == NULL) errno = ENOMEM; return ENOMEM; |
if(__scanf_buffer == NULL) __scanf_buffer = malloc(4096); |
if(__scanf_buffer == NULL) return -3; |
*__scanf_buffer = 0; |
n = vscanf(format, arg); |
/programs/develop/libraries/kolibri-libc/source/stdio/sscanf.c |
---|
1,11 → 1,45 |
#include <stdio.h> |
#include <stdarg.h> |
int sscanf(const char * s, const char * format, ...) |
int virtual_getc_str(void *sp, const void *obj) |
// get next chat from string obj, save point is ptr to string char ptr |
{ |
va_list arg; |
int ch; |
const char *s = (const char *)obj; |
const char**spc= (const char**)sp; |
if (!s || !spc) return EOF; // error |
if (!*spc) *spc = s; // first call, init savepoint |
if (!**spc) return EOF; // EOS |
ch = **spc; (*spc)++ ; |
return ch; |
} |
void virtual_ungetc_str(void *sp, int c, const void *obj) |
// if can, one step back savepoint in s |
{ |
const char *s = (const char *)obj; |
const char**spc= (const char**)sp; |
if (s && spc && *spc > s) (*spc)--; |
} |
int vsscanf ( const char * s, const char * format, va_list arg ) |
{ |
return format_scan(s, format, arg, &virtual_getc_str, &virtual_ungetc_str); |
}; |
int sscanf ( const char * s, const char * format, ...) |
{ |
va_list arg; |
int n; |
va_start(arg, format); |
n = vsscanf(s, format, arg); |
va_end(arg); |
return n; |
} |
/programs/develop/libraries/kolibri-libc/source/stdio/ungetc.c |
---|
0,0 → 1,28 |
#include <stdio.h> |
#include <errno.h> |
// non standard realization - support for virtually change ONLY ONE char |
int ungetc(int c, FILE* file) |
{ |
int res; |
if(!file){ |
errno = EBADF; |
return EOF; |
} |
if (file->mode != _STDIO_F_R){ |
errno = EACCES; |
return EOF; |
} |
if (file->position > file->start_size || file->position == 0 || c == EOF || file->__ungetc_emu_buff != EOF) |
{ |
errno = EOF; |
return EOF; |
} |
file->__ungetc_emu_buff = c; |
file->position--; |
return c; |
} |