From 4e4a78fb2dda468c8ba68ce0c90794c8eacf3e4b Mon Sep 17 00:00:00 2001 From: turbocat Date: Mon, 26 Apr 2021 21:12:04 +0000 Subject: [PATCH] ktcc: - Added files for developing programs with kolibri-libc git-svn-id: svn://kolibrios.org@8685 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../develop/ktcc/trunk/kolibri-libc/crt0.o | Bin 0 -> 1404 bytes .../kolibri-libc/include/clayer/network.h | 54 + .../ktcc/trunk/kolibri-libc/include/ctype.h | 45 + .../ktcc/trunk/kolibri-libc/include/errno.h | 144 +++ .../ktcc/trunk/kolibri-libc/include/float.h | 65 ++ .../ktcc/trunk/kolibri-libc/include/limits.h | 21 + .../ktcc/trunk/kolibri-libc/include/math.h | 171 +++ .../ktcc/trunk/kolibri-libc/include/setjmp.h | 17 + .../ktcc/trunk/kolibri-libc/include/stdarg.h | 77 ++ .../ktcc/trunk/kolibri-libc/include/stdbool.h | 11 + .../ktcc/trunk/kolibri-libc/include/stddef.h | 37 + .../ktcc/trunk/kolibri-libc/include/stdint.h | 28 + .../ktcc/trunk/kolibri-libc/include/stdio.h | 146 +++ .../ktcc/trunk/kolibri-libc/include/stdlib.h | 40 + .../ktcc/trunk/kolibri-libc/include/string.h | 186 +++ .../trunk/kolibri-libc/include/sys/dirent.h | 34 + .../trunk/kolibri-libc/include/sys/ksys.h | 1006 +++++++++++++++++ .../trunk/kolibri-libc/include/sys/socket.h | 244 ++++ .../ktcc/trunk/kolibri-libc/include/time.h | 30 + .../ktcc/trunk/kolibri-libc/libc.obj.a | Bin 0 -> 61504 bytes 20 files changed, 2356 insertions(+) create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/crt0.o create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/clayer/network.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/ctype.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/errno.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/float.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/limits.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/math.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/setjmp.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/stdarg.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/stdbool.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/stddef.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/stdint.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/stdio.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/stdlib.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/string.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/sys/dirent.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/sys/ksys.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/sys/socket.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/include/time.h create mode 100644 programs/develop/ktcc/trunk/kolibri-libc/libc.obj.a diff --git a/programs/develop/ktcc/trunk/kolibri-libc/crt0.o b/programs/develop/ktcc/trunk/kolibri-libc/crt0.o new file mode 100644 index 0000000000000000000000000000000000000000..fbd17a270a1746904389943663564a3b80a42ae4 GIT binary patch literal 1404 zcma)5O=uHA6rN2sajTKG{#5)Wh^SO;NVQ-!U{D)9*fut%R)xg0L>nJwh&uW@eKCYl)rMNHF_WktL<6Zkl%VDnsJq*{~vaS5oC~`JKQUpAW+r zik7`~DqYj#*P0>XSIC9U$7B8BK3QU?L=CB-)P$rzaI2+)NK#Kkx9Y_iY~WX9$H-T@ zVsu2Mi~UTNv^JoFnl05HBjQw@2x8Kxt-nfss9kX`_Ogg>!2bn&de~ zWYPv;*sWy%aGJ(^8YV|BY<5{?+mT7)60#H8F$g_Mi-fqR$KY~EF0In`^t8OfV;)($iMW%?_%L(Z;+`{7iBp{Q{SD*x!FzE4W3bEQCZ%A30+h+26{DQg$_Z<3n3C<8~xh8pNwI^ zmbL0Hi^a;;Hsqh)mh%MVEjiC!xeW@JEu+P*-(8mdRQ68TN!BL}zOq1zY4soi8g{?- z_6K8%PblU=gcRW=;7L0hMoP2^T1y$0+J92Vxmm)L@S>~x$LBkha7gKpN=0nY*ohd0 zMUC)b7q8}cnd4QCH#pwrr~p@hDz0;Uz)^%4#%FV^2eiPQIJv)`V=Koih_Lo=TUZmo zzjWyzzLhw^ALi@kK_2U_^*7Y;@oHPSk8jin|2;lCwh2n0??oTJs=o{7_n|g4)F&;; zvvC^f2c!uD6Vc->GUJWMf<>k%dR@E#GX5=(%W#sIgf9 + +#define EAI_ADDRFAMILY 1 +#define EAI_AGAIN 2 +#define EAI_BADFLAGS 3 +#define EAI_FAIL 4 +#define EAI_FAMILY 5 +#define EAI_MEMORY 6 +#define EAI_NONAME 8 +#define EAI_SERVICE 9 +#define EAI_SOCKTYPE 10 +#define EAI_BADHINTS 12 +#define EAI_PROTOCOL 13 +#define EAI_OVERFLOW 14 + +// Flags for addrinfo +#define AI_PASSIVE 1 +#define AI_CANONNAME 2 +#define AI_NUMERICHOST 4 +#define AI_NUMERICSERV 8 +#define AI_ADDRCONFIG 0x400 + +#pragma pack(push, 1) +struct ARP_entry{ +unsigned int IP; +unsigned char MAC[6]; +unsigned short status; +unsigned short TTL; +}; +#pragma pack(pop) + +#pragma pack(push, 1) +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + int ai_addrlen; + char *ai_canonname; + struct sockaddr *ai_addr; + struct addrinfo *ai_next; +}; +#pragma pack(pop) + +extern int networklib_init (); +extern int (*inet_addr __attribute__ ((stdcall)))(const char* hostname); +extern char* (*inet_ntoa __attribute__ ((stdcall)))(int ip_addr); +extern int (*getaddrinfo __attribute__ ((stdcall)))(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res); +extern void (*freeaddrinfo __attribute__ ((stdcall)))(struct addrinfo* ai); + +#endif diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/ctype.h b/programs/develop/ktcc/trunk/kolibri-libc/include/ctype.h new file mode 100644 index 0000000000..5f87ebe292 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/ctype.h @@ -0,0 +1,45 @@ +#ifndef _CTYPE_H_ +#define _CTYPE_H_ +/* +** All character classification functions except isascii(). +** Integer argument (c) must be in ASCII range (0-127) for +** dependable answers. +*/ + +#define __ALNUM 1 +#define __ALPHA 2 +#define __CNTRL 4 +#define __DIGIT 8 +#define __GRAPH 16 +#define __LOWER 32 +#define __PRINT 64 +#define __PUNCT 128 +#define __BLANK 256 +#define __UPPER 512 +#define __XDIGIT 1024 + +#ifdef _KOLIBRI_LIBC_OBJ +extern unsigned short __is[129]; +#else +extern unsigned short *__is; +#endif + +#define isalnum(c)(__is[c+1] & __ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */ +#define isalpha(c)(__is[c+1] & __ALPHA ) /* 'a'-'z', 'A'-'Z' */ +#define iscntrl(c)(__is[c+1] & __CNTRL ) /* 0-31, 127 */ +#define isdigit(c)(__is[c+1] & __DIGIT ) /* '0'-'9' */ +#define isgraph(c)(__is[c+1] & __GRAPH ) /* '!'-'~' */ +#define islower(c)(__is[c+1] & __LOWER ) /* 'a'-'z' */ +#define isprint(c)(__is[c+1] & __PRINT ) /* ' '-'~' */ +#define ispunct(c)(__is[c+1] & __PUNCT ) /* !alnum && !cntrl && !space */ +#define isspace(c)(__is[c+1] & __BLANK ) /* HT, LF, VT, FF, CR, ' ' */ +#define isupper(c)(__is[c+1] & __UPPER ) /* 'A'-'Z' */ +#define isxdigit(c)(__is[c+1] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */ + +#define isascii(c) (!((c)&(~0x7f))) +#define toascii(c) ((c)&0x7f) + +extern unsigned char tolower(unsigned char c); +extern unsigned char toupper(unsigned char c); + +#endif \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/errno.h b/programs/develop/ktcc/trunk/kolibri-libc/include/errno.h new file mode 100644 index 0000000000..4735f0edb7 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/errno.h @@ -0,0 +1,144 @@ +#ifndef _ERRNO_H_ +#define _ERRNO_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern int errno; + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EDEADLK 11 /* Resource deadlock avoided */ +/* 11 was EAGAIN */ +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device / Resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +/* math software */ +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EAGAIN 35 /* Resource temporarily unavailable */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ + +/* ipc/network software -- argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define ENOTSUP 45 /* Operation not supported */ +#define EOPNOTSUPP ENOTSUP /* Operation not supported on socket */ +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + +/* ipc/network software -- operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#define ETIMEDOUT 60 /* Operation timed out */ +#define ECONNREFUSED 61 /* Connection refused */ +#define ELOOP 62 /* Too many levels of symbolic links */ +#define ENAMETOOLONG 63 /* File name too long */ + +/* should be rearranged */ +#define EHOSTDOWN 64 /* Host is down */ +#define EHOSTUNREACH 65 /* No route to host */ +#define ENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#define EDQUOT 69 /* Disc quota exceeded */ + +/* Network File System */ +#define ESTALE 70 /* Stale NFS file handle */ +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC prog. not avail */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ +#define EFTYPE 79 /* Inappropriate file type or format */ +#define EAUTH 80 /* Authentication error */ +#define ENEEDAUTH 81 /* Need authenticator */ + +/* Intelligent device errors */ +#define EPWROFF 82 /* Device power is off */ +#define EDEVERR 83 /* Device error, e.g. paper out */ +#define EOVERFLOW 84 /* Value too large to be stored in data type */ + +/* Program loading errors */ +#define EBADEXEC 85 /* Bad executable */ +#define EBADARCH 86 /* Bad CPU type in executable */ +#define ESHLIBVERS 87 /* Shared library version mismatch */ +#define EBADMACHO 88 /* Malformed Macho file */ +#define ECANCELED 89 /* Operation canceled */ +#define EIDRM 90 /* Identifier removed */ +#define ENOMSG 91 /* No message of desired type */ +#define EILSEQ 92 /* Illegal byte sequence */ +#define ENOATTR 93 /* Attribute not found */ +#define EBADMSG 94 /* Bad message */ +#define EMULTIHOP 95 /* Reserved */ +#define ENODATA 96 /* No message available on STREAM */ +#define ENOLINK 97 /* Reserved */ +#define ENOSR 98 /* No STREAM resources */ +#define ENOSTR 99 /* Not a STREAM */ +#define EPROTO 100 /* Protocol error */ +#define ETIME 101 /* STREAM ioctl timeout */ +#define ENOPOLICY 103 /* No such policy registered */ +#define ENOTRECOVERABLE 104 /* State not recoverable */ +#define EOWNERDEAD 105 /* Previous owner died */ +#define EQFULL 106 /* Interface output queue is full */ +#define ELAST 106 /* Must be equal largest errno */ + +#ifdef __cplusplus +} +#endif + +#endif // _ERRNO_H_ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/float.h b/programs/develop/ktcc/trunk/kolibri-libc/include/float.h new file mode 100644 index 0000000000..a2b4ed26a0 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/float.h @@ -0,0 +1,65 @@ +#ifndef _FLOAT_H_ +#define _FLOAT_H_ + +#define FLT_RADIX 2 + +/* IEEE float */ +#define FLT_MANT_DIG 24 +#define FLT_DIG 6 +#define FLT_ROUNDS 1 +#define FLT_EPSILON 1.19209290e-07F +#define FLT_MIN_EXP (-125) +#define FLT_MIN 1.17549435e-38F +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_EXP 128 +#define FLT_MAX 3.40282347e+38F +#define FLT_MAX_10_EXP 38 + +/* IEEE double */ +#define DBL_MANT_DIG 53 +#define DBL_DIG 15 +#define DBL_EPSILON 2.2204460492503131e-16 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN 2.2250738585072014e-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_EXP 1024 +#define DBL_MAX 1.7976931348623157e+308 +#define DBL_MAX_10_EXP 308 + +/* horrible intel long double */ +#if defined __i386__ || defined __x86_64__ + +#define LDBL_MANT_DIG 64 +#define LDBL_DIG 18 +#define LDBL_EPSILON 1.08420217248550443401e-19L +#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN 3.36210314311209350626e-4932L +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_EXP 16384 +#define LDBL_MAX 1.18973149535723176502e+4932L +#define LDBL_MAX_10_EXP 4932 + +#else + +/* same as IEEE double */ +#define LDBL_MANT_DIG 53 +#define LDBL_DIG 15 +#define LDBL_EPSILON 2.2204460492503131e-16 +#define LDBL_MIN_EXP (-1021) +#define LDBL_MIN 2.2250738585072014e-308 +#define LDBL_MIN_10_EXP (-307) +#define LDBL_MAX_EXP 1024 +#define LDBL_MAX 1.7976931348623157e+308 +#define LDBL_MAX_10_EXP 308 + +#endif + +#ifndef NAN +# define NAN (__nan__) +#endif + +#ifndef INFINITY +# define INFINITY (__inf__) +#endif + +#endif /* _FLOAT_H_ */ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/limits.h b/programs/develop/ktcc/trunk/kolibri-libc/include/limits.h new file mode 100644 index 0000000000..9bdcba4695 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/limits.h @@ -0,0 +1,21 @@ +#ifndef _LIMITS_H_ +#define _LIMITS_H_ + + +#define INT_MAX 2147483647 +#define UINT_MAX (INT_MAX * 2U + 1) + + +#ifndef ARG_MAX +#define ARG_MAX 4096 +#endif + +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef STDIO_MAX_MEM +#define STDIO_MAX_MEM 4096 +#endif + +#endif /* _LIMITS_H_ */ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/math.h b/programs/develop/ktcc/trunk/kolibri-libc/include/math.h new file mode 100644 index 0000000000..b1749dc50b --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/math.h @@ -0,0 +1,171 @@ +/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ +/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ +#ifndef _MATH_H_ +#define _MATH_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern double _FUNC(acos)(double _x); +extern double _FUNC(asin)(double _x); +extern double _FUNC(atan)(double _x); +extern double _FUNC(atan2)(double _y, double _x); +extern double _FUNC(ceil)(double _x); +extern double _FUNC(cos)(double _x); +extern double _FUNC(cosh)(double _x); +extern double _FUNC(exp)(double _x); +extern double _FUNC(fabs)(double _x); +extern double _FUNC(floor)(double _x); +extern double _FUNC(fmod)(double _x, double _y); +extern double _FUNC(frexp)(double _x, int *_pexp); +extern double _FUNC(ldexp)(double _x, int _exp); +extern double _FUNC(log)(double _y); +extern double _FUNC(log10)(double _x); +extern double _FUNC(modf)(double _x, double *_pint); +extern double _FUNC(pow)(double _x, double _y); +extern double _FUNC(sin)(double _x); +extern double _FUNC(sinh)(double _x); +extern double _FUNC(sqrt)(double _x); +extern double _FUNC(tan)(double _x); +extern double _FUNC(tanh)(double _x); + +#define M_E 2.7182818284590452354 +#define M_LOG2E 1.4426950408889634074 +#define M_LOG10E 0.43429448190325182765 +#define M_LN2 0.69314718055994530942 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT1_2 0.70710678118654752440 +#define PI M_PI +#define PI2 M_PI_2 + +extern double _FUNC(acosh)(double); +extern double _FUNC(asinh)(double); +extern double _FUNC(atanh)(double); +extern double _FUNC(cbrt)(double); +extern double _FUNC(exp10)(double _x); +extern double _FUNC(exp2)(double _x); +extern double _FUNC(expm1)(double); +extern double _FUNC(hypot)(double, double); +extern double _FUNC(log1p)(double); +extern double _FUNC(log2)(double _x); +extern long double _FUNC(modfl)(long double _x, long double *_pint); +extern double _FUNC(pow10)(double _x); +extern double _FUNC(pow2)(double _x); +extern double _FUNC(powi)(double, int); +extern void _FUNC(sincos)(double, double *, double *); + +/* These are in libm.a (Cygnus). You must link -lm to get these */ +/* See libm/math.h for comments */ + +#ifndef __cplusplus +struct exception { + int type; + const char *name; + double arg1; + double arg2; + double retval; + int err; +}; +#endif + +extern double _FUNC(erf)(double); +extern double _FUNC(erfc)(double); +extern double _FUNC(gamma)(double); +extern int _FUNC(isinf)(double); +extern int _FUNC(isnan)(double); +extern int _FUNC(finite)(double); +extern double _FUNC(j0)(double); +extern double _FUNC(j1)(double); +extern double _FUNC(jn)(int, double); +extern double _FUNC(lgamma)(double); +extern double _FUNC(nan)(const char*); +extern double _FUNC(y0)(double); +extern double _FUNC(y1)(double); +extern double _FUNC(yn)(int, double); +extern double _FUNC(logb)(double); +extern double _FUNC(nextafter)(double, double); +extern double _FUNC(remainder)(double, double); +extern double _FUNC(scalb)(double, double); +#ifndef __cplusplus +extern int _FUNC(matherr)(struct exception *); +#endif +extern double _FUNC(significand)(double); +extern double _FUNC(copysign)(double, double); +extern int _FUNC(ilogb)(double); +extern double _FUNC(rint)(double); +extern double _FUNC(scalbn)(double, int); +extern double _FUNC(drem)(double, double); +extern double _FUNC(gamma_r)(double, int *); +extern double _FUNC(lgamma_r)(double, int *); +extern float _FUNC(acosf)(float); +extern float _FUNC(asinf)(float); +extern float _FUNC(atanf)(float); +extern float _FUNC(atan2f)(float, float); +extern float _FUNC(cosf)(float); +extern float _FUNC(sinf)(float); +extern float _FUNC(tanf)(float); +extern float _FUNC(coshf)(float); +extern float _FUNC(sinhf)(float); +extern float _FUNC(tanhf)(float); +extern float _FUNC(expf)(float); +extern float _FUNC(frexpf)(float, int *); +extern float _FUNC(ldexpf)(float, int); +extern float _FUNC(logf)(float); +extern float _FUNC(log10f)(float); +extern float _FUNC(modff)(float, float *); +extern float _FUNC(powf)(float, float); +extern float _FUNC(sqrtf)(float); +extern float _FUNC(ceilf)(float); +extern float _FUNC(fabsf)(float); +extern float _FUNC(floorf)(float); +extern float _FUNC(fmodf)(float, float); +extern float _FUNC(erff)(float); +extern float _FUNC(erfcf)(float); +extern float _FUNC(gammaf)(float); +extern float _FUNC(hypotf)(float, float); +extern int _FUNC(isinff)(float); +extern int _FUNC(isnanf)(float); +extern int _FUNC(finitef)(float); +extern float _FUNC(j0f)(float); +extern float _FUNC(j1f)(float); +extern float _FUNC(jnf)(int, float); +extern float _FUNC(lgammaf)(float); +extern float _FUNC(nanf)(const char*); +extern float _FUNC(y0f)(float); +extern float _FUNC(y1f)(float); +extern float _FUNC(ynf)(int, float); +extern float _FUNC(acoshf)(float); +extern float _FUNC(asinhf)(float); +extern float _FUNC(atanhf)(float); +extern float _FUNC(cbrtf)(float); +extern float _FUNC(logbf)(float); +extern float _FUNC(nextafterf)(float, float); +extern float _FUNC(remainderf)(float, float); +extern float _FUNC(scalbf)(float, float); +extern float _FUNC(significandf)(float); +extern float _FUNC(copysignf)(float, float); +extern int _FUNC(ilogbf)(float); +extern float _FUNC(rintf)(float); +extern float _FUNC(scalbnf)(float, int); +extern float _FUNC(dremf)(float, float); +extern float _FUNC(expm1f)(float); +extern float _FUNC(log1pf)(float); +extern float _FUNC(gammaf_r)(float, int *); +extern float _FUNC(lgammaf_r)(float, int *); + +#ifdef __cplusplus +} +#endif + +#endif /* _MATH_H_ */ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/setjmp.h b/programs/develop/ktcc/trunk/kolibri-libc/include/setjmp.h new file mode 100644 index 0000000000..aa1993680e --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/setjmp.h @@ -0,0 +1,17 @@ +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +#include + +typedef unsigned long __jmp_buf[6]; + +typedef struct __jmp_buf_tag { + __jmp_buf __jb; + unsigned long __fl; + unsigned long __ss[128/sizeof(long)]; +} jmp_buf[1]; + +extern int _FUNC(setjmp)(jmp_buf env); +extern void _FUNC(longjmp)(jmp_buf env, int val); + +#endif // _SETJMP_H_ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/stdarg.h b/programs/develop/ktcc/trunk/kolibri-libc/include/stdarg.h new file mode 100644 index 0000000000..bd0928d891 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/stdarg.h @@ -0,0 +1,77 @@ +#ifndef _STDARG_H_ +#define _STDARG_H_ + +#include + +#ifdef __x86_64__ +#ifndef _WIN64 + +//This should be in sync with the declaration on our lib/libtcc1.c +/* 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; + +typedef __va_list_struct va_list[1]; + +extern void _FUNC(__va_start)(__va_list_struct *ap, void *fp); +extern void* _FUNC(__va_arg)(__va_list_struct *ap, int arg_type, int size, int align); + +#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0)) +#define va_arg(ap, type) \ + (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) +#define va_copy(dest, src) (*(dest) = *(src)) +#define va_end(ap) + +#else /* _WIN64 */ +typedef char *va_list; +#define va_start(ap,last) __builtin_va_start(ap,last) +#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap) +#define va_copy(dest, src) ((dest) = (src)) +#define va_end(ap) +#endif + +#elif __arm__ +typedef char *va_list; +#define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x) +#define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \ + & ~(_tcc_alignof(type) - 1)) +#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) +#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ + &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) +#define va_copy(dest, src) (dest) = (src) +#define va_end(ap) + +#elif defined(__aarch64__) +typedef struct { + void *__stack; + void *__gr_top; + void *__vr_top; + int __gr_offs; + int __vr_offs; +} va_list; +#define va_start(ap, last) __va_start(ap, last) +#define va_arg(ap, type) __va_arg(ap, type) +#define va_end(ap) +#define va_copy(dest, src) ((dest) = (src)) + +#else /* __i386__ */ +typedef char *va_list; +/* only correct for i386 */ +#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) +#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) +#define va_copy(dest, src) (dest) = (src) +#define va_end(ap) +#endif + +/* fix a buggy dependency on GCC in libio.h */ +typedef va_list __gnuc_va_list; +#define _VA_LIST_DEFINED + +#endif /* _STDARG_H */ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/stdbool.h b/programs/develop/ktcc/trunk/kolibri-libc/include/stdbool.h new file mode 100644 index 0000000000..0af22124ae --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/stdbool.h @@ -0,0 +1,11 @@ +#ifndef _STDBOOL_H_ +#define _STDBOOL_H_ + +/* ISOC99 boolean */ + +#define bool _Bool +#define true 1 +#define false 0 +#define __bool_true_false_are_defined 1 + +#endif /* _STDBOOL_H */ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/stddef.h b/programs/develop/ktcc/trunk/kolibri-libc/include/stddef.h new file mode 100644 index 0000000000..bea97027f1 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/stddef.h @@ -0,0 +1,37 @@ +#ifndef _STDDEF_H_ +#define _STDDEF_H_ + +typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ssize_t; +typedef __WCHAR_TYPE__ wchar_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; +typedef __PTRDIFF_TYPE__ intptr_t; +typedef __SIZE_TYPE__ uintptr_t; + +#ifndef __int8_t_defined +#define __int8_t_defined +typedef signed char int8_t; +typedef signed short int int16_t; +typedef signed int int32_t; +typedef signed long long int int64_t; +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long int uint64_t; +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; +#endif + +#ifndef NULL + #define NULL ((void*)0) +#endif + +#ifdef _KOLIBRI_LIBC_OBJ + #define _FUNC(func) func +#else + #define _FUNC(func) (*func) +#endif + +#define offsetof(type, field) ((size_t)&((type *)0)->field) + +#endif /* _STDDEF_H_ */ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/stdint.h b/programs/develop/ktcc/trunk/kolibri-libc/include/stdint.h new file mode 100644 index 0000000000..916e999f6f --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/stdint.h @@ -0,0 +1,28 @@ +#ifndef _STDINT_H_ +#define _STDINT_H_ + +#include + +#define INT8_MIN (-128) +#define INT8_MAX (127) +#define UINT8_MAX (255) + +#define INT16_MIN (-32768) +#define INT16_MAX (32767) +#define UINT16_MAX (65535) + +#define INT32_MIN (-2147483647L-1) +#define INT32_MAX (2147483647L) +#define UINT32_MAX (4294967295UL) + +#if __have_long64 +#define INT64_MIN (-9223372036854775807L-1L) +#define INT64_MAX (9223372036854775807L) +#define UINT64_MAX (18446744073709551615U) +#elif __have_longlong64 +#define INT64_MIN (-9223372036854775807LL-1LL) +#define INT64_MAX (9223372036854775807LL) +#define UINT64_MAX (18446744073709551615ULL) +#endif + +#endif /* _STDINT_H_*/ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/stdio.h b/programs/develop/ktcc/trunk/kolibri-libc/include/stdio.h new file mode 100644 index 0000000000..fb97057b33 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/stdio.h @@ -0,0 +1,146 @@ +/////////////////////////////////////////////////////////////////////////////// +// \author (c) Marco Paland (info@paland.com) +// 2014-2019, PALANDesign Hannover, Germany +// +// \license The MIT License (MIT) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. +// Use this instead of bloated standard/newlib printf. +// These routines are thread safe and reentrant. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include +#include +#include + +extern int _FUNC(puts)(const char *str); +extern int _FUNC(printf)(const char* format, ...); +extern int _FUNC(sprintf)(char* buffer, const char* format, ...); +extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); +extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); +extern int _FUNC(vprintf)(const char* format, va_list va); + +extern void _FUNC(debug_printf)(const char* format, ...); + +typedef size_t fpos_t; + +#define _STDIO_F_R 1 << 0 // Read +#define _STDIO_F_W 1 << 1 // Write +#define _STDIO_F_A 1 << 2 // Append +#define _STDIO_F_X 1 << 3 // eXclusive +#define _STDIO_F_B 1 << 4 // Binary + +typedef struct FILE_s { + char *name; + fpos_t position; + int error; + int eof; + int kind; // 0 - undiefned, 1 - text, 2 - binary + int orientation; // 0 - undiefned, 1 - byte, 2 - wide + int mode; // flags _STDIO_F_* + int append_offset; // do not seek before this point ("a" mode) + int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!) + int start_size; +} FILE; + +#define _IOFBF 0 +#define _IOLBF 1 +#define _IONBF 2 + +#define BUFSIZ 1024 + +#define EOF -1 + +#define FOPEN_MAX 0xffffffff + +#define FILENAME_MAX 255 + +#define L_tmpnam FILENAME_MAX + +#define SEEK_CUR 0 +#define SEEK_END 1 +#define SEEK_SET 2 + +#define TMP_MAX FOPEN_MAX + +#define stderr (FILE*)3 +#define stdin (FILE*)1 +#define stdout (FILE*)2 + +extern int _FUNC(fgetc)(FILE *); +extern char* _FUNC(fgets)(char *restrict, int, FILE *restrict); +extern int _FUNC(fprintf)(FILE *restrict, const char *restrict, ...); +extern int _FUNC(fputc)(int, FILE *); +extern int _FUNC(fputs)(const char *restrict, FILE *restrict); +extern size_t _FUNC(fread)(void *restrict, size_t size, size_t count, FILE *restrict); +extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...); +extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict); +extern int _FUNC(getc)(FILE *); +#define getc _FUNC(fgetc) +extern int _FUNC(getchar)(void); +extern int _FUNC(printf)(const char *restrict, ...); +extern int _FUNC(putc)(int, FILE *); +extern int _FUNC(putchar)(int); +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(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(vsscanf)(const char *, const char*, va_list); + +extern int _FUNC(remove)(const char *); +extern int _FUNC(rename)(const char *, const char *); +extern FILE* _FUNC(tmpfile)(void); +extern char* _FUNC(tmpnam)(char *); + +extern int _FUNC(fclose)(FILE *); +extern int _FUNC(fflush)(FILE *); +extern FILE* _FUNC(fopen)(const char *restrict, const char *restrict); +extern FILE* _FUNC(freopen)(const char *restrict, const char *restrict, FILE *restrict); +extern void _FUNC(setbuf)(FILE *restrict, char *restrict); +extern int _FUNC(setvbuf)(FILE *restrict, char *restrict, int, size_t); + +extern int _FUNC(fgetpos)(FILE *restrict, fpos_t *restrict); +extern int _FUNC(fseek)(FILE *, long, int); +extern int _FUNC(fsetpos)(FILE *, const fpos_t *); +extern long _FUNC(ftell)(FILE *); +extern void _FUNC(rewind)(FILE *); + +extern void _FUNC(clearerr)(FILE *); +extern int _FUNC(feof)(FILE *); +extern int _FUNC(ferror)(FILE *); +extern void _FUNC(perror)(const char *); + +extern size_t _FUNC(fread)(void *restrict, size_t, size_t, FILE *restrict); + +extern int _FUNC(getchar)(void); + +extern void _FUNC(con_set_title)(const char*); + +#endif // _STDIO_H_ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/stdlib.h b/programs/develop/ktcc/trunk/kolibri-libc/include/stdlib.h new file mode 100644 index 0000000000..8ea389bfe7 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/stdlib.h @@ -0,0 +1,40 @@ +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include + +#define RAND_MAX 65535 +#ifndef NULL +# define NULL ((void*)0) +#endif + +#define min(a, b) ((a)<(b) ? (a) : (b)) +#define max(a, b) ((a)>(b) ? (a) : (b)) + +extern int _FUNC(atoi)(const char *s); +extern long _FUNC(atol)(const char *); +extern long long _FUNC(atoll)(const char *); +extern void _FUNC(itoa)(int n, char* s); + +extern int _FUNC(abs)(int); +extern long _FUNC(labs)(long); +extern long long _FUNC(llabs)(long long); + +typedef struct { int quot, rem; } div_t; +typedef struct { long quot, rem; } ldiv_t; +typedef struct { long long quot, rem; } lldiv_t; + +extern div_t _FUNC(div)(int, int); +extern ldiv_t _FUNC(ldiv)(long, long); +extern lldiv_t _FUNC(lldiv)(long long, long long); + +extern void* _FUNC(malloc)(size_t size); +extern void* _FUNC(calloc)(size_t num, size_t size); +extern void* _FUNC(realloc)(void *ptr, size_t newsize); +extern void _FUNC(free)(void *ptr); + +extern long int _FUNC(strtol)(const char* str, char** endptr, int base); + +extern void _FUNC(exit)(int status); + +#endif \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/string.h b/programs/develop/ktcc/trunk/kolibri-libc/include/string.h new file mode 100644 index 0000000000..33bcf99133 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/string.h @@ -0,0 +1,186 @@ +/* String handling + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* String function conventions */ + +/* + In any of the following functions taking a size_t n to specify the length of + an array or size of a memory region, n may be 0, but the pointer arguments to + the call shall still be valid unless otherwise stated. +*/ + +/* Copying functions */ + +extern void* _FUNC(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n); + +/* Copy a number of n characters from the memory area pointed to by s2 to the + 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. +*/ +extern void* memmove(void* s1, const void* s2, size_t n); + +/* Copy the character array s2 (including terminating '\0' byte) into the + character array s1. + Returns the value of s1. +*/ +extern char* _FUNC(strcpy)(char* s1, const char* s2); + +/* Copy a maximum of n characters from the character array s2 into the character + array s1. If s2 is shorter than n characters, '\0' bytes will be appended to + the copy in s1 until n characters have been written. If s2 is longer than n + characters, NO terminating '\0' will be written to s1. If the arrays overlap, + behaviour is undefined. + Returns the value of s1. +*/ +extern char* _FUNC(strncpy)(char* s1, const char* s2, size_t n); + +/* Concatenation functions */ + +/* Append the contents of the character array s2 (including terminating '\0') to + the character array s1 (first character of s2 overwriting the '\0' of s1). If + the arrays overlap, behaviour is undefined. + Returns the value of s1. +*/ +extern char* _FUNC(strcat)(char* s1, const char* s2); + +/* Append a maximum of n characters from the character array s2 to the character + array s1 (first character of s2 overwriting the '\0' of s1). A terminating + '\0' is ALWAYS appended, even if the full n characters have already been + written. If the arrays overlap, behaviour is undefined. + Returns the value of s1. +*/ +extern char* _FUNC(strncat)(char* s1, const char* s2, size_t n); + +/* Comparison functions */ + +/* Compare the first n characters of the memory areas pointed to by s1 and s2. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. +*/ +extern int _FUNC(memcmp)(const void * s1, const void* s2, size_t n); + +/* Compare the character arrays s1 and s2. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. +*/ +extern int _FUNC(strcmp)(const char * s1, const char* s2); + +/* Compare the character arrays s1 and s2, interpreted as specified by the + LC_COLLATE category of the current locale. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. + TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support + locales. +*/ +extern int _FUNC(strcoll)(const char* s1, const char* s2); + +/* Compare no more than the first n characters of the character arrays s1 and + s2. + Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if + s1 > s2. +*/ +extern int _FUNC(strncmp)(const char* s1, const char* s2, size_t n); + +/* Transform the character array s2 as appropriate for the LC_COLLATE setting of + the current locale. If length of resulting string is less than n, store it in + the character array pointed to by s1. Return the length of the resulting + string. +*/ +extern size_t _FUNC(strxfrm)(char* s1, const char* s2, size_t n); + +/* Search functions */ + +/* Search the first n characters in the memory area pointed to by s for the + character c (interpreted as unsigned char). + Returns a pointer to the first instance found, or NULL. +*/ +extern void* _FUNC(memchr)(const void* s, int c, size_t n); + +/* Search the character array s (including terminating '\0') for the character c + (interpreted as char). + Returns a pointer to the first instance found, or NULL. +*/ +extern char* _FUNC(strchr)(const char* s, int c); + +/* Determine the length of the initial substring of character array s1 which + consists only of characters not from the character array s2. + Returns the length of that substring. +*/ +extern size_t _FUNC(strcspn)(const char* s1, const char* s2); + +/* Search the character array s1 for any character from the character array s2. + Returns a pointer to the first occurrence, or NULL. +*/ +extern char* _FUNC(strpbrk)(const char* s1, const char* s2); + +/* Search the character array s (including terminating '\0') for the character c + (interpreted as char). + Returns a pointer to the last instance found, or NULL. +*/ +extern char* _FUNC(strrchr)(const char * s, int c ); + +/* Determine the length of the initial substring of character array s1 which + consists only of characters from the character array s2. + Returns the length of that substring. +*/ +extern size_t _FUNC(strspn)(const char * s1, const char * s2); + +/* Search the character array s1 for the substring in character array s2. + Returns a pointer to that sbstring, or NULL. If s2 is of length zero, + returns s1. +*/ +extern char* _FUNC(strstr)(const char * s1, const char * s2); + +/* In a series of subsequent calls, parse a C string into tokens. + On the first call to strtok(), the first argument is a pointer to the to-be- + parsed C string. On subsequent calls, the first argument is NULL unless you + want to start parsing a new string. s2 holds an array of separator characters + which can differ from call to call. Leading separators are skipped, the first + trailing separator overwritten with '\0'. + Returns a pointer to the next token. + WARNING: This function uses static storage, and as such is not reentrant. +*/ +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. +*/ +extern char* _FUNC(strerror)(int errnum); + +/* Returns the length of the string s (excluding terminating '\0').*/ +extern size_t _FUNC(strlen)(const char * s); + +/* The function reverses the sequence of characters in the string pointed to by str. */ +extern char* _FUNC(strrev)(char *str); + +/* The strdup function executes the function pointed to by the str argument. */ +extern char* _FUNC(strdup)(const char *str); + +#endif diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/sys/dirent.h b/programs/develop/ktcc/trunk/kolibri-libc/include/sys/dirent.h new file mode 100644 index 0000000000..584adbea1c --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/sys/dirent.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2021 Logaev Maxim (turbocat2001), GPLv2 */ + +#ifndef _DIRENT_H_ +#define _DIRENT_H_ + +#include +#include + +#define IS_FOLDER 16 +#define IS_FILE 0 + +typedef unsigned ino_t; + +struct dirent{ + ino_t d_ino; //File serial number. + char d_name[PATH_MAX]; // Name of entry. + unsigned d_type; +}; + +typedef struct{ + struct dirent* objs; + ino_t pos; + ino_t num_objs; +}DIR; + + +int _FUNC(closedir)(DIR *dir); +DIR* _FUNC(opendir)(const char *path); +struct dirent* _FUNC(readdir)(DIR *); +void _FUNC(rewinddir)(DIR *dir); +void _FUNC(seekdir)(DIR *dir, unsigned pos); +unsigned _FUNC(telldir)(DIR *dir); + +#endif // _DIRENT_H_ \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/sys/ksys.h b/programs/develop/ktcc/trunk/kolibri-libc/include/sys/ksys.h new file mode 100644 index 0000000000..88f23db9a3 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/sys/ksys.h @@ -0,0 +1,1006 @@ +#ifndef _KSYS_H_ +#define _KSYS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define asm_inline __asm__ __volatile__ + +#define KSYS_FS_ERR_SUCCESS 0 // Success +#define KSYS_FS_ERR_1 1 // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8) +#define KSYS_FS_ERR_2 2 // Function is not supported for the given file system +#define KSYS_FS_ERR_3 3 // Unknown file system +#define KSYS_FS_ERR_4 4 // Reserved, is never returned in the current implementation +#define KSYS_FS_ERR_5 5 // File not found +#define KSYS_FS_ERR_EOF 6 // End of file, EOF +#define KSYS_FS_ERR_7 7 // Pointer lies outside of application memory +#define KSYS_FS_ERR_8 8 // Disk is full +#define KSYS_FS_ERR_9 9 // FAT table is destroyed +#define KSYS_FS_ERR_10 10 // Access denied +#define KSYS_FS_ERR_11 11 // Device error + +typedef void ksys_panic(char *func_name); + +typedef struct { + unsigned char blue; + unsigned char green; + unsigned char red; +}rgb_t; + +#pragma pack(push,1) +typedef union{ + unsigned val; + struct{ + short x; + short y; + }; +}ksys_pos_t; + +typedef union ksys_oskey_t{ + unsigned val; + struct{ + unsigned char state; + unsigned char code; + unsigned char ctrl_key; + }; +}ksys_oskey_t; + +typedef struct{ + unsigned handle; + unsigned io_code; + unsigned *input; + int inp_size; + void *output; + int out_size; +}ksys_ioctl_t; + +typedef struct{ + void *data; + size_t size; +}ksys_ufile_t; + + +typedef struct{ + unsigned p00; + union{ + uint64_t p04; + struct { + unsigned p04dw; + unsigned p08dw; + }; + }; + unsigned p12; + union { + unsigned p16; + const char *new_name; + void *bdfe; + void *buf16; + const void *cbuf16; + }; + char p20; + const char *p21; +}ksys70_t; + + +typedef struct { + unsigned attributes; + unsigned name_cp; + char creation_time[4]; + char creation_date[4]; + char last_access_time[4]; + char last_access_date[4]; + char last_modification_time[4]; + char last_modification_date[4]; + unsigned long long size; + char name[0]; +}ksys_bdfe_t; + +typedef struct { + int cpu_usage; //+0 + int window_pos_info; //+4 + short int reserved1; //+8 + char name[12]; //+10 + int memstart; //+22 + int memused; //+26 + int pid; //+30 + int winx_start; //+34 + int winy_start; //+38 + int winx_size; //+42 + int winy_size; //+46 + short int slot_info; //+50 + short int reserved2; //+52 + int clientx; //+54 + int clienty; //+58 + int clientwidth; //+62 + int clientheight; //+66 + unsigned char window_state;//+70 + char reserved3[1024-71]; //+71 +}ksys_proc_table_t; + +typedef unsigned int ksys_color_t; + +typedef struct{ + ksys_color_t frame_area; + ksys_color_t grab_bar; + ksys_color_t grab_bar_button; + ksys_color_t grab_button_text; + ksys_color_t grab_text; + ksys_color_t work_area; + ksys_color_t work_button; + ksys_color_t work_button_text; + ksys_color_t work_text; + ksys_color_t work_graph; +}ksys_colors_table_t; + +typedef struct{ + unsigned pid; // PID of sending thread + unsigned datalen; // data bytes + char *data; // data begin +}ksys_ipc_msg; + +typedef struct{ + unsigned lock; // nonzero is locked + unsigned used; // used bytes in buffer + ksys_ipc_msg *data; // data begin +}ksys_ipc_buffer; + +typedef struct { + char* func_name; + void* func_ptr; +}ksys_coff_etable_t; + +#pragma pack(pop) + +enum KSYS_EVENTS { + KSYS_EVENT_NONE = 0, /* Event queue is empty */ + KSYS_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */ + KSYS_EVENT_KEY = 2, /* A key on the keyboard was pressed */ + KSYS_EVENT_BUTTON = 3, /* A button was clicked with the mouse */ + KSYS_EVENT_DESKTOP = 5, /* Desktop redraw finished */ + KSYS_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */ + KSYS_EVENT_IPC = 7, /* Interprocess communication notify */ + KSYS_EVENT_NETWORK = 8, /* Network event */ + KSYS_EVENT_DEBUG = 9, /* Debug subsystem event */ + KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ +}; + +enum KSYS_FILE_ENCODING{ + KSYS_FILE_CP866 =1, + KSYS_FILE_UTF16LE = 2, + KSYS_FILE_UTF8 = 3 +}; + +enum KSYS_CLIP_ENCODING{ + KSYS_CLIP_UTF8 = 0, + KSYS_CLIP_CP866 = 1, + KSYS_CLIP_CP1251 = 2 +}; + +enum KSYS_CLIP_TYPES{ + KSYS_CLIP_TEXT = 0, + KSYS_CLIP_IMAGE = 1, + KSYS_CLIP_RAW = 2 +}; + +enum KSYS_MOUSE_POS{ + KSYS_MOUSE_SCREEN_POS = 0, + KSYS_MOUSE_WINDOW_POS = 1 +}; + +enum KSYS_SHM_MODE{ + KSYS_SHM_OPEN = 0x00, + KSYS_SHM_OPEN_ALWAYS = 0x04, + KSYS_SHM_CREATE = 0x08, + KSYS_SHM_READ = 0x00, + KSYS_SHM_WRITE = 0x01, +}; + +static inline +int _ksys_strcmp(const char * s1, const char * s2 ) +{ + while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; } + return(*(unsigned char*)s1 - *(unsigned char *)s2); +} + +// Functions for working with the graphical interface + +static inline +void _ksys_start_draw() +{ + asm_inline("int $0x40"::"a"(12),"b"(1)); +} + +static inline +void _ksys_end_draw() +{ + asm_inline("int $0x40" ::"a"(12),"b"(2)); +} + +static inline +void _ksys_create_window(int x, int y, int w, int h, const char *name, ksys_color_t workcolor, unsigned style) +{ + asm_inline( + "int $0x40" + ::"a"(0), + "b"((x << 16) | ((w-1) & 0xFFFF)), + "c"((y << 16) | ((h-1) & 0xFFFF)), + "d"((style << 24) | (workcolor & 0xFFFFFF)), + "D"(name), + "S"(0) + :"memory" + ); +}; + +static inline +void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) +{ + asm_inline( + "int $0x40" + ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) + ); +} + +static inline +void _ksys_define_button(unsigned x, unsigned y, unsigned w, unsigned h, unsigned id, ksys_color_t color) +{ + asm_inline( + "int $0x40" + ::"a"(8), + "b"((x<<16)+w), + "c"((y<<16)+h), + "d"(id), + "S"(color) + ); +}; + +static inline +void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color) +{ + asm_inline( + "int $0x40" + ::"a"(38), "d"(color), + "b"((xs << 16) | xe), + "c"((ys << 16) | ye) + ); +} + +static inline +void _ksys_draw_bar(int x, int y, int w, int h, ksys_color_t color) +{ + asm_inline( + "int $0x40" + ::"a"(13), "d"(color), + "b"((x << 16) | w), + "c"((y << 16) | h) + ); +} + +static inline +void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h) +{ + asm_inline( + "int $0x40" + ::"a"(7), "b"(bitmap), + "c"((w << 16) | h), + "d"((x << 16) | y) + :"memory" + ); +} + +static inline +void _ksys_draw_text(const char *text, int x, int y, int len, ksys_color_t color) +{ + asm_inline( + "int $0x40" + ::"a"(4),"d"(text), + "b"((x << 16) | y), + "S"(len),"c"(color) + :"memory" + ); +} + +static inline +void _ksys_draw_text_bg(const char *text, int x, int y, int len, ksys_color_t color, ksys_color_t bg) +{ + asm_inline( + "int $0x40" + ::"a"(4),"d"(text), + "b"((x << 16) | y), + "S"(len),"c"(color), "D"(bg) + :"memory" + ); +} + +static inline +void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){ + unsigned fmt; + fmt = len << 16 | 0x80000000; // no leading zeros + width + asm_inline( + "int $0x40" + ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color) + ); +} + +static inline +void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){ + unsigned fmt; + fmt = len << 16 | 0x80000000; // no leading zeros + width + asm_inline( + "int $0x40" + ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg) + ); +} + +static inline +unsigned _ksys_get_skin_height() +{ + unsigned height; + asm_inline( + "int $0x40 \n\t" + :"=a"(height) + :"a"(48),"b"(4) + ); + return height; +} + +static inline +void _ksys_get_colors(ksys_colors_table_t *color_table) +{ + asm_inline( + "int $0x40" + ::"a"(48),"b"(3),"c"(color_table),"d"(40) + ); +} + +/* Functions for working with a screen. */ + +static inline +ksys_pos_t _ksys_screen_size() +{ + ksys_pos_t size; + ksys_pos_t size_tmp; + asm_inline( + "int $0x40" + :"=a"(size_tmp) + :"a"(14) + ); + size.x = size_tmp.y; + size.y = size_tmp.x; + return size; +} + + +/* Functions for working with a mouse and cursors. */ + +static inline +ksys_pos_t _ksys_get_mouse_pos(int origin) +{ + ksys_pos_t pos; + asm_inline( + "int $0x40 \n\t" + "rol $16, %%eax" + :"=a"(pos) + :"a"(37),"b"(origin) + ); + return pos; +} + +static inline +unsigned _ksys_get_mouse_buttons() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(37),"b"(2) + ); + return val; +} + +static inline +unsigned _ksys_get_mouse_wheels() +{ + unsigned val; + asm_inline( + "int $0x40 \n\t" + :"=a"(val) + :"a"(37),"b"(7) + ); + return val; +} + +static inline +unsigned _ksys_load_cursor(void *path, unsigned flags) +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(37), "b"(4), "c"(path), "d"(flags) + :"memory" + ); + return val; +} + +static inline +unsigned _ksys_set_cursor(unsigned cursor) +{ + unsigned old; + asm_inline( + "int $0x40" + :"=a"(old) + :"a"(37), "b"(5), "c"(cursor) + ); + return old; +} + +static inline +int _ksys_destroy_cursor(unsigned cursor) +{ + int ret; + asm_inline( + "int $0x40" + :"=a"(ret) + :"a"(37), "b"(6), "c"(cursor) + :"memory" + ); + return ret; +} + +static inline +unsigned _ksys_get_mouse_eventstate() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(37),"b"(3) + ); + return val; +} + + +/* Functions for working with events and buttons. */ + +static inline +unsigned _ksys_set_event_mask(unsigned mask) +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(40), "b"(mask) + ); + return val; +} + +static inline +unsigned _ksys_wait_event(unsigned time) +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(23), "b"(time) + ); + return val; +} + +static inline +unsigned _ksys_check_event() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(11) + ); + return val; +} + +static inline +unsigned _ksys_get_event() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(10) + ); + return val; +} + +static inline +unsigned _ksys_get_button() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(17) + ); + return val>>8; +} + +static inline +ksys_oskey_t _ksys_get_key(void) +{ + ksys_oskey_t val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(2) + ); + return val; +} + +/* Functions for working with the clipboard */ + +static inline +int _ksys_clip_num() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(54), "b"(0) + ); + return val; +} + +static inline +char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free() +{ + char* val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(54), "b"(1), "c"(n) + ); + return val; +} + +static inline +int _ksys_clip_set(int n, char *buffer) +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(54), "b"(2), "c"(n), "d"(buffer) + :"memory" + ); + return val; +} + +static inline +int _ksys_clip_pop() +{ + unsigned val; + asm_inline ( + "int $0x40" + :"=a"(val) + :"a"(54), "b"(3) + ); + return val; +} + +static inline +int _ksys_clip_unlock() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(54), "b"(4) + ); + return val; +} + + +/* Working with time */ + +static inline +unsigned _ksys_get_tick_count() +{ + unsigned val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(26),"b"(9) + ); + return val; +} + +static inline +uint64_t _ksys_get_ns_count() +{ + uint64_t val; + asm_inline( + "int $0x40" + :"=A"(val) + :"a"(26), "b"(10) + ); + return val; +} + +static inline +void _ksys_delay(unsigned time) +{ + asm_inline( + "int $0x40" + ::"a"(5), "b"(time) + :"memory" + ); +} + +static inline +unsigned _ksys_get_date() +{ + unsigned val; + asm_inline("int $0x40":"=a"(val):"a"(29)); + return val; +} + +static inline +unsigned _ksys_get_clock() +{ + unsigned val; + asm_inline("int $0x40":"=a"(val):"a"(3)); + return val; +} + + +/* Working with memory allocation */ + +static inline +void* _ksys_alloc(size_t size){ + void *val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(68),"b"(12),"c"(size) + ); + return val; +} + +static inline +int _ksys_free(void *mem) +{ + int val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(68),"b"(13),"c"(mem) + ); + return val; +} + +static inline +void* _ksys_realloc(void *mem, size_t size) +{ + void *val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(68),"b"(20),"c"(size),"d"(mem) + :"memory" + ); + return val; +} + +static inline +int* _ksys_unmap(void *base, size_t offset, size_t size) +{ + int *val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size) + ); + return val; +} + + +/* Loading the dynamic coff library */ + +static inline +ksys_coff_etable_t* _ksys_load_coff(const char* path) +{ + ksys_coff_etable_t *table; + asm_inline( + "int $0x40" + :"=a"(table) + :"a"(68),"b"(19), "c"(path) + :"memory" + ); + return table; +} + +static inline +void* _ksys_get_coff_func(ksys_coff_etable_t *table, const char* fun_name, ksys_panic* panic) +{ + unsigned i=0; + while (1){ + if (NULL == (table+i)->func_name){ + break; + }else{ + if (!_ksys_strcmp(fun_name, (table+i)->func_name)){ + return (table+i)->func_ptr; + } + } + i++; + } + panic((char*)fun_name); + return NULL; +} + + +/* Debug board functions */ + +static inline +void _ksys_debug_putc(char c) +{ + asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c)); +} + +static inline +void _ksys_debug_puts(char *s) +{ + unsigned i=0; + while (*(s+i)){ + asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i))); + i++; + } +} + + +/* Working with threads and process */ + +static inline +int _ksys_start_thread(void* proc, char* stack_top) +{ + int val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(51), "b"(1), "c"(proc), "d"(stack_top) + ); + return val; +} + +static inline +void _ksys_focus_window(int slot){ + asm_inline( + "int $0x40" + ::"a"(18), "b"(3), "c"(slot) + ); +} + +static inline +int _ksys_get_thread_slot(int tid){ + int val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(18), "b"(21), "c"(tid) + ); + return val; +} + +static inline +int _ksys_process_info(ksys_proc_table_t* table, int pid) +{ + int val; + asm_inline( + "int $0x40" + :"=a"(val) + :"a"(9), "b"(table), "c"(pid) + :"memory" + ); + return val; +} + +static inline +void _ksys_exit() +{ + asm_inline("int $0x40"::"a"(-1)); +} + + +/* Working with files and directories */ + +static inline +void _ksys_setcwd(char* dir){ + asm_inline( + "int $0x40" + ::"a"(30), "b"(1), "c"(dir) + ); +} + +static inline +int _ksys_getcwd(char* buf, int bufsize){ + register int val; + asm_inline( + "int $0x40" + :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize) + ); + return val; +} + +static inline +ksys_ufile_t _ksys_load_file(const char *path) +{ + ksys_ufile_t uf; + asm_inline( + "int $0x40" + :"=a"(uf.data), "=d"(uf.size) + :"a"(68), "b"(27),"c"(path) + :"memory" + ); + return uf; +} + +static inline +ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding) +{ + ksys_ufile_t uf; + asm_inline( + "int $0x40" + :"=a"(uf.data), "=d"(uf.size) + :"a"(68), "b"(28),"c"(path), "d"(file_encoding) + :"memory" + ); + return uf; +} + +static inline +int _ksys_work_files(const ksys70_t *k) +{ + int status; + asm_inline( + "int $0x40" + :"=a"(status) + :"a"(70), "b"(k) + :"memory" + ); + return status; +} + +static inline +int _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read) +{ + ksys70_t k; + k.p00 = 0; + k.p04 = offset; + k.p12 = size; + k.buf16 = buf; + k.p20 = 0; + k.p21 = name; + int status; + unsigned bytes_read_v; + _ksys_work_files(&k); + if (!status) { + *bytes_read = bytes_read_v; + } + return status; +} + +static inline +int _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written) +{ + ksys70_t k; + k.p00 = 3; + k.p04 = offset; + k.p12 = size; + k.cbuf16 = buf; + k.p20 = 0; + k.p21 = name; + int status; + unsigned bytes_written_v; + asm_inline( + "int $0x40" + :"=a"(status), "=b"(bytes_written_v) + :"a"(70), "b"(&k) + :"memory" + ); + if (!status) { + *bytes_written = bytes_written_v; + } + return status; +} + +static inline +int _ksys_file_create(const char* name){ + ksys70_t k; + k.p00 = 2; + k.p12 = 0; + k.p21 = name; + return _ksys_work_files(&k); +} + +static inline +int _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe) +{ + ksys70_t k; + k.p00 = 5; + k.bdfe = bdfe; + k.p20 = 0; + k.p21 = name; + return _ksys_work_files(&k); +} + +static inline +int _ksys_file_delete(const char *name) +{ + ksys70_t k; + k.p00 = 8; + k.p20 = 0; + k.p21 = name; + return _ksys_work_files(&k); +} + +static inline +int _ksys_file_rename(const char *name, const char *new_name) +{ + ksys70_t k; + k.p00 = 10; + k.new_name = new_name; + k.p20 = 0; + k.p21 = name; + return _ksys_work_files(&k); +} + + +static inline +int _ksys_exec(char *app_name, char *args) +{ + ksys70_t file_opt; + file_opt.p00 = 7; + file_opt.p04dw = 0; + file_opt.p08dw = (unsigned)args; + file_opt.p21 = app_name; + return _ksys_work_files(&file_opt); +} + +static inline +int _ksys_mkdir(const char *path) +{ + ksys70_t dir_opt; + dir_opt.p00 = 9; + dir_opt.p21 = path; + return _ksys_work_files(&dir_opt); +} + +/* Working with a named shared memory area. */ + +static inline +int _ksys_shm_open(char *name, int mode, int size, char **new_shm) +{ + int error; + asm_inline( + "int $0x40" + :"=a"(*new_shm), "=d"(error) + :"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode) + ); + return error; +} + + +static inline +void _ksys_shm_close(char *shm_name) +{ + asm_inline( + "int $0x40": + :"a"(68), "b"(23), "c"(shm_name) + ); +} + +#ifdef __cplusplus +} +#endif + +#endif // _KSYS_H_ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/sys/socket.h b/programs/develop/ktcc/trunk/kolibri-libc/include/sys/socket.h new file mode 100644 index 0000000000..ad25469785 --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/sys/socket.h @@ -0,0 +1,244 @@ +/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv2 */ + +#ifndef _SOCKET_H_ +#define _SOCKET_H_ + +#include +#include +#include + +// Socket Types +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 + +// IP protocols +#define IPPROTO_IP 0 +#define IPPROTO_ICMP 1 +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#define IPPROTO_RAW 255 + +// IP options +#define IP_TTL 2 + +// Address families +#define AF_UNSPEC 0 +#define AF_LOCAL 1 +#define AF_INET 2 // Default INET=IPv4 +#define AF_INET4 2 // IPv4 +#define AF_INET6 10 // IPv6 + +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_INET4 AF_INET4 +#define PF_INET6 AF_INET6 + +// internal definition +#define AI_SUPPORTED 0x40F + +// for system function 76 +#define API_ETH (0<<16) +#define API_IPv4 (1<<16) +#define API_ICMP (2<<16) +#define API_UDP (3<<16) +#define API_TCP (4<<16) +#define API_ARP (5<<16) +#define API_PPPOE (6<<16) + +// Socket flags for user calls +#define MSG_NOFLAG 0 +#define MSG_PEEK 0x02 +#define MSG_DONTWAIT 0x40 + +// Socket levels +#define SOL_SOCKET 0xffff + +//Socket options +#define SO_BINDTODEVICE (1<<9) +#define SO_NONBLOCK (1<<31) + +#define PORT(X) (X<<8) + +#pragma pack(push,1) +struct sockaddr{ + unsigned short sin_family; + unsigned short sin_port; + unsigned int sin_addr; + unsigned long long sin_zero; +}; + +typedef struct{ + unsigned int level; + unsigned int optionname; + unsigned int optlenght; + unsigned char options; +}optstruct; +#pragma pack(pop) + +static inline +void _conv_socket_err(){ + switch(errno){ + case 1: errno = ENOBUFS; break; + case 2: errno = EINPROGRESS; break; + case 4: errno = EOPNOTSUPP; break; + case 6: errno = EWOULDBLOCK; break; + case 9: errno = ENOTCONN; break; + case 10: errno = EALREADY; break; + case 11: errno = EINVAL; break; + case 12: errno = EMSGSIZE; break; + case 18: errno = ENOMEM; break; + case 20: errno = EADDRINUSE; break; + case 61: errno = ECONNREFUSED; break; + case 52: errno = ECONNRESET; break; + case 56: errno = EISCONN; break; + case 60: errno = ETIMEDOUT; break; + case 54: errno = ECONNABORTED; break; + default: errno = 0; break; + } +} + +static inline +int socket(int domain, int type, int protocol) +{ + int socket; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(socket) + :"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol) + ); + _conv_socket_err(); + return socket; +} + +static inline +int close(int socket) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(1), "c"(socket) + ); + _conv_socket_err(); + return status; +} + +static inline +int bind(int socket, const struct sockaddr *addres, int addres_len) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len) + ); + _conv_socket_err(); + return status; +} + +static inline +int listen(int socket, int backlog) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(3), "c"(socket), "d"(backlog) + ); + _conv_socket_err(); + return status; +} + +static inline +int connect(int socket, const struct sockaddr* address, int socket_len) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len) + ); + _conv_socket_err(); + return status; +} + +static inline int +accept(int socket, const struct sockaddr *address, int address_len) +{ + int new_socket; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(new_socket) + :"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len) + ); + _conv_socket_err(); + return new_socket; +} + +static inline +int send(int socket, const void *message, size_t msg_len, int flag) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag) + ); + _conv_socket_err(); + return status; +} + +static inline +int recv(int socket, void *buffer, size_t buff_len, int flag) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag) + ); + _conv_socket_err(); + return status; +} + +static inline +int setsockopt(int socket,const optstruct* opt) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(8), "c"(socket),"d"(opt) + ); + _conv_socket_err(); + return status; +} + +static inline +int getsockopt(int socket, optstruct* opt) +{ + int status; + asm_inline( + "int $0x40" + :"=b"(errno), "=a"(status) + :"a"(75), "b"(9), "c"(socket),"d"(opt) + ); + _conv_socket_err(); + return status; +} + +static inline +int socketpair(int *socket1, int *socket2) +{ + asm_inline( + "int $0x40" + :"=b"(*socket2), "=a"(*socket1) + :"a"(75), "b"(10) + ); + errno=*socket2; + _conv_socket_err(); + return *socket1; +} + +#endif //_SOCKET_H_ diff --git a/programs/develop/ktcc/trunk/kolibri-libc/include/time.h b/programs/develop/ktcc/trunk/kolibri-libc/include/time.h new file mode 100644 index 0000000000..dbf15294fc --- /dev/null +++ b/programs/develop/ktcc/trunk/kolibri-libc/include/time.h @@ -0,0 +1,30 @@ +#ifndef _TIME_H_ +#define _TIME_H_ + +#include + +typedef unsigned long int clock_t; +typedef unsigned long int time_t; +#define clock() _ksys_get_clock() +#define CLOCKS_PER_SEC 100 + +struct tm { + int tm_sec; /* seconds after the minute 0-61*/ + int tm_min; /* minutes after the hour 0-59 */ + int tm_hour; /* hours since midnight 0-23 */ + int tm_mday; /* day of the month 1-31 */ + int tm_mon; /* months since January 0-11 */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday 0-6 */ + int tm_yday; /* days since January 1 0-365 */ + int tm_isdst; /* Daylight Saving Time flag */ +}; + +extern time_t _FUNC(mktime)(struct tm * timeptr); +extern time_t _FUNC(time)(time_t* timer); +extern struct tm * _FUNC(localtime)(const time_t * timer); /* non-standard! ignore parameter and return just time now, not generate tm_isdst, tm_yday, tm_wday == -1 */ +extern double _FUNC(difftime)(time_t end, time_t beginning); + +extern struct tm buffertime; + +#endif \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/kolibri-libc/libc.obj.a b/programs/develop/ktcc/trunk/kolibri-libc/libc.obj.a new file mode 100644 index 0000000000000000000000000000000000000000..147e198a48c7cd75e50971645530bda04940629d GIT binary patch literal 61504 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