aboutsummaryrefslogtreecommitdiff
path: root/src/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc')
-rw-r--r--src/lib/libc/errno.c6
-rw-r--r--src/lib/libc/locale.c22
-rw-r--r--src/lib/libc/malloc.c4
-rw-r--r--src/lib/libc/math.c151
-rw-r--r--src/lib/libc/setjmp.s53
-rw-r--r--src/lib/libc/signal.c8
-rw-r--r--src/lib/libc/stdio.c152
-rw-r--r--src/lib/libc/stdlib.c80
-rw-r--r--src/lib/libc/time.c50
9 files changed, 526 insertions, 0 deletions
diff --git a/src/lib/libc/errno.c b/src/lib/libc/errno.c
new file mode 100644
index 0000000..b5865fa
--- /dev/null
+++ b/src/lib/libc/errno.c
@@ -0,0 +1,6 @@
+#include <errno.h>
+
+int errno = 0;
+
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/locale.c b/src/lib/libc/locale.c
new file mode 100644
index 0000000..3c7db9e
--- /dev/null
+++ b/src/lib/libc/locale.c
@@ -0,0 +1,22 @@
+#include <locale.h>
+#include <stddef.h>
+#include <limits.h>
+
+struct lconv c_locale_lconv = {
+ ".", "", "", "", "", "", "", "",
+ "", "", CHAR_MAX, CHAR_MAX, CHAR_MAX,
+ CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
+ CHAR_MAX
+};
+
+struct lconv *localeconv() {
+ // TODO
+ return &c_locale_lconv;
+}
+
+char* setlocale(int catebory, const char* locale) {
+ // TODO
+ return NULL;
+}
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/malloc.c b/src/lib/libc/malloc.c
index cb983fd..2d43656 100644
--- a/src/lib/libc/malloc.c
+++ b/src/lib/libc/malloc.c
@@ -63,6 +63,10 @@ void* calloc(size_t nmemb, size_t sz) {
return r;
}
+void* realloc(void* ptr, size_t sz) {
+ return slab_realloc(mem_allocator, ptr, sz);
+}
+
void free(void* ptr) {
slab_free(mem_allocator, ptr);
}
diff --git a/src/lib/libc/math.c b/src/lib/libc/math.c
new file mode 100644
index 0000000..b859f04
--- /dev/null
+++ b/src/lib/libc/math.c
@@ -0,0 +1,151 @@
+#include <math.h>
+
+float fabsf(float x) {
+ // TODO
+ return 0;
+}
+
+float cosf(float x) {
+ // TODO
+ return 0;
+}
+float sinf(float x) {
+ // TODO
+ return 0;
+}
+float tanf(float x) {
+ // TODO
+ return 0;
+}
+
+float acosf(float x) {
+ // TODO
+ return 0;
+}
+float asinf(float x) {
+ // TODO
+ return 0;
+}
+float atan2f(float y, float x) {
+ // TODO
+ return 0;
+}
+
+float floorf(float x) {
+ // TODO
+ return 0;
+}
+float ceilf(float x) {
+ // TODO
+ return 0;
+}
+float fmodf(float x, float y) {
+ // TODO
+ return 0;
+}
+
+float sqrtf(float x) {
+ // TODO
+ return 0;
+}
+float logf(float x) {
+ // TODO
+ return 0;
+}
+float log2f(float x) {
+ // TODO
+ return 0;
+}
+float log10f(float x) {
+ // TODO
+ return 0;
+}
+float expf(float x) {
+ // TODO
+ return 0;
+}
+float frexpf(float x, int *exp) {
+ // TODO
+ return 0;
+}
+float powf(float x, float y) {
+ // TODO
+ return 0;
+}
+
+
+
+double fabs(double x) {
+ // TODO
+ return 0;
+}
+
+double cos(double x) {
+ // TODO
+ return 0;
+}
+double sin(double x) {
+ // TODO
+ return 0;
+}
+double tan(double x) {
+ // TODO
+ return 0;
+}
+
+double acos(double x) {
+ // TODO
+ return 0;
+}
+double asin(double x) {
+ // TODO
+ return 0;
+}
+double atan2(double y, double x) {
+ // TODO
+ return 0;
+}
+
+double floor(double x) {
+ // TODO
+ return 0;
+}
+double ceil(double x) {
+ // TODO
+ return 0;
+}
+double fmod(double x, double y) {
+ // TODO
+ return 0;
+}
+
+double sqrt(double x) {
+ // TODO
+ return 0;
+}
+double log(double x) {
+ // TODO
+ return 0;
+}
+double log2(double x) {
+ // TODO
+ return 0;
+}
+double log10(double x) {
+ // TODO
+ return 0;
+}
+double exp(double x) {
+ // TODO
+ return 0;
+}
+double frexp(double x, int *exp) {
+ // TODO
+ return 0;
+}
+double pow(double x, double y) {
+ // TODO
+ return 0;
+}
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/setjmp.s b/src/lib/libc/setjmp.s
new file mode 100644
index 0000000..164cc5b
--- /dev/null
+++ b/src/lib/libc/setjmp.s
@@ -0,0 +1,53 @@
+[GLOBAL setjmp]
+setjmp:
+ ; Store general purpose registers
+ ; (in new stack frame)
+ mov [esp+4], eax
+ mov [esp+8], ebx
+ mov [esp+12], ecx
+ mov [esp+16], edx
+ mov [esp+20], edi
+ mov [esp+24], esi
+ mov [esp+28], ebp
+ mov [esp+32], esp
+
+ ; Store flags
+ pushf
+ pop eax
+ mov [esp+36], eax
+
+ ; Store return address
+ mov eax, [esp]
+ mov [esp+40], eax
+
+ ; return 0
+ xor eax, eax
+ ret
+
+
+[GLOBAL longjmp]
+longjmp:
+ ; on previous stack, resume return address
+ mov eax, [esp+32]
+ mov ebx, [esp+40]
+ mov [eax], ebx
+
+ ; resume flags
+ mov eax, [esp+36]
+ push eax
+ popf
+
+ ; load return value in eax
+ mov eax, [esp+44]
+ ; resume geneal purpose registers, except eax/esp
+ mov ebx, [esp+8]
+ mov ecx, [esp+12]
+ mov edx, [esp+16]
+ mov edi, [esp+20]
+ mov esi, [esp+24]
+ mov ebp, [esp+28]
+
+ ; resume previous esp
+ mov esp, [esp+32]
+ ; return as if we were the setjmp call
+ ret
diff --git a/src/lib/libc/signal.c b/src/lib/libc/signal.c
new file mode 100644
index 0000000..e9037c1
--- /dev/null
+++ b/src/lib/libc/signal.c
@@ -0,0 +1,8 @@
+#include <signal.h>
+
+void (*signal(int sig, void (*func)(int)))(int) {
+ // TODO
+ return 0;
+}
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/stdio.c b/src/lib/libc/stdio.c
index 22be78e..bd6c35b 100644
--- a/src/lib/libc/stdio.c
+++ b/src/lib/libc/stdio.c
@@ -60,4 +60,156 @@ int printf(const char* fmt, ...) {
return puts(buffer);
}
+// ==================
+// BELOW IS TODO
+// ==================
+
+
+int fgetc(FILE *stream) {
+ // TODO
+ return 0;
+}
+char *fgets(char *s, int size, FILE *stream) {
+ // TODO
+ return 0;
+}
+int getc(FILE *stream) {
+ // TODO
+ return 0;
+}
+int ungetc(int c, FILE *stream) {
+ // TODO
+ return 0;
+}
+
+int fputc(int c, FILE *stream) {
+ // TODO
+ return 0;
+}
+int fputs(const char *s, FILE *stream) {
+ // TODO
+ return 0;
+}
+int putc(int c, FILE *stream) {
+ // TODO
+ return 0;
+}
+
+FILE *fopen(const char *path, const char *mode) {
+ // TODO
+ return 0;
+}
+FILE *freopen(const char *path, const char *mode, FILE *stream) {
+ // TODO
+ return 0;
+}
+
+void clearerr(FILE *stream) {
+ // TODO
+}
+int feof(FILE *stream) {
+ // TODO
+ return 0;
+}
+int ferror(FILE *stream) {
+ // TODO
+ return 0;
+}
+int fileno(FILE *stream) {
+ // TODO
+ return 0;
+}
+
+
+size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
+ // TODO
+ return 0;
+}
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
+ // TODO
+ return 0;
+}
+
+int fflush(FILE* f) {
+ // TODO
+ return 0;
+}
+int fclose(FILE* f) {
+ // TODO
+ return 0;
+}
+
+FILE *stdin = 0;
+FILE *stdout = 0;
+FILE *stderr = 0;
+
+void setbuf(FILE *stream, char *buf) {
+ // TODO
+}
+void setbuffer(FILE *stream, char *buf, size_t size) {
+ // TODO
+}
+void setlinebuf(FILE *stream) {
+ // TODO
+}
+int setvbuf(FILE *stream, char *buf, int mode, size_t size) {
+ // TODO
+ return 0;
+}
+
+
+int fseek(FILE *stream, long offset, int whence) {
+ // TODO
+ return 0;
+}
+long ftell(FILE *stream) {
+ // TODO
+ return 0;
+}
+void rewind(FILE *stream) {
+ // TODO
+}
+int fgetpos(FILE *stream, fpos_t *pos) {
+ // TODO
+ return 0;
+}
+int fsetpos(FILE *stream, const fpos_t *pos) {
+ // TODO
+ return 0;
+}
+
+FILE *tmpfile(void) {
+ // TODO
+ return 0;
+}
+char *tmpnam(char *s) {
+ // TODO
+ return 0;
+}
+
+int rename(const char *old, const char *new) {
+ // TODO
+ return 0;
+}
+int remove(const char *pathname) {
+ // TODO
+ return 0;
+}
+
+
+
+int fprintf(FILE *stream, const char *format, ...) {
+ // TODO
+ return 0;
+}
+int dprintf(int fd, const char *format, ...) {
+ // TODO
+ return 0;
+}
+int sprintf(char *str, const char *format, ...) {
+ // TODO
+ return 0;
+}
+
+
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/stdlib.c b/src/lib/libc/stdlib.c
new file mode 100644
index 0000000..d8598dd
--- /dev/null
+++ b/src/lib/libc/stdlib.c
@@ -0,0 +1,80 @@
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <kogata/debug.h>
+
+int rand(void) {
+ return 0; // TODO
+}
+
+void srand(unsigned int seed) {
+ //TODO
+}
+
+void abort() {
+ PANIC("Aborted.");
+}
+
+float strtof(const char *nptr, const char **endptr) {
+ return (float)strtod(nptr, endptr);
+}
+double strtod(const char *nptr, const char **endptr) {
+ // TODO: better (inf, nan, ...)
+
+ const char* p = nptr;
+ while (isspace(*p)) p++;
+
+ double val = 0;
+ double sign = 1;
+ if (*p == '-') sign = -1;
+ if (*p == '-' || *p == '+') p++;
+ while (isdigit(*p)) {
+ val = val*10. + (double)((int)*p - '0');
+ p++;
+ }
+ if (*p == '.') {
+ p++;
+ double fac = 0.1;
+ while (isdigit(*p)) {
+ val += fac * (double)((int)*p - '0');
+ fac /= 10.;
+ p++;
+ }
+ }
+ if (*p == 'e' || *p == 'E') {
+ p++;
+ int exp = 0;
+ int sexp = 1;
+ if (*p == '-') sexp = -1;
+ if (*p == '-' || *p =='+') p++;
+ while (isdigit(*p)) {
+ exp = exp * 10 + (*p - '0');
+ p++;
+ }
+ if (sexp == 1) {
+ for (int i = 0; i < exp; i++) val *= 10;
+ } else {
+ for (int i = 0; i < exp; i++) val /= 10;
+ }
+ }
+ if (endptr != NULL) *endptr = p-1;
+
+ return val * sign;
+}
+
+char *getenv(const char *name) {
+ // TODO
+ return 0;
+}
+
+int system(const char *command) {
+ // TODO
+ return -1;
+}
+
+int abs(int j) {
+ if (j < 0) return -j;
+ return j;
+}
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/time.c b/src/lib/libc/time.c
new file mode 100644
index 0000000..c10d071
--- /dev/null
+++ b/src/lib/libc/time.c
@@ -0,0 +1,50 @@
+#include <time.h>
+
+time_t time(time_t* t) {
+ // TODO
+ return 0;
+}
+double difftime(time_t time1, time_t time0) {
+ // TODO
+ return 0;
+}
+
+char *asctime(const struct tm *tm) {
+ // TODO --
+ return 0;
+}
+
+char *ctime(const time_t *timep) {
+ // TODO --
+ return 0;
+}
+
+struct tm *gmtime(const time_t *timep) {
+ // TODO
+ return 0;
+}
+
+struct tm *localtime(const time_t *timep) {
+ // TODO
+ return 0;
+}
+
+time_t mktime(struct tm *tm) {
+ // TODO
+ return 0;
+}
+
+size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) {
+ // TODO
+ return 0;
+}
+
+
+clock_t clock(void) {
+ // TODO
+ return 0;
+}
+
+
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/