summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--ports/lua20
-rw-r--r--src/user/app/init/driver/initctl.c2
-rw-r--r--src/user/app/init/driver/ps2.c2
-rw-r--r--src/user/app/init/driver/termcook.c1
-rw-r--r--src/user/app/tests/kernel/misc.c1
-rw-r--r--src/user/app/tests/stress.c1
-rw-r--r--src/user/app/tests/tests.h2
-rw-r--r--src/user/bootstrap/main.c1
-rw-r--r--src/user/bootstrap/tar.c2
-rw-r--r--src/user/lib/fs/misc.h4
-rw-r--r--src/user/lib/include/ctype.h4
-rw-r--r--src/user/lib/include/locale.h70
-rw-r--r--src/user/lib/include/math.h29
-rw-r--r--src/user/lib/include/setjmp.h16
-rw-r--r--src/user/lib/include/signal.h5
-rw-r--r--src/user/lib/include/stdio.h12
-rw-r--r--src/user/lib/include/stdlib.h4
-rw-r--r--src/user/lib/include/string.h9
-rw-r--r--src/user/lib/include/sys/types.h3
-rw-r--r--src/user/lib/include/time.h29
-rw-r--r--src/user/lib/include/unistd.h1
22 files changed, 211 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 0dd1610..37caf0d 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ endef
.PHONY: all boot debug lint check clean
-all: out/boot.iso check
+all: out/boot.iso out/libm.a check
boot: all out/hdd
qemu-system-x86_64 -drive file=out/boot.iso,format=raw,media=disk $(QFLAGS) -serial stdio
@@ -84,6 +84,10 @@ out/libc.a: $(call from_sources, src/user/lib/) \
@mkdir -p $(@D)
@$(AR) rcs $@ $^
+out/libm.a:
+ @mkdir -p $(@D)
+ @$(AR) rcs $@ $^
+
out/bootstrap: src/user/bootstrap/linker.ld $(call from_sources, src/user/bootstrap/) out/libc.a
@mkdir -p $(@D)
@$(CC) $(LFLAGS) -Wl,-Map=% -T $^ -o $@
diff --git a/ports/lua b/ports/lua
new file mode 100644
index 0000000..fc8e8a7
--- /dev/null
+++ b/ports/lua
@@ -0,0 +1,20 @@
+set -eu
+camellia_path_check
+
+VERSION=lua-5.4.4
+
+fetch() {
+ wget http://www.lua.org/ftp/${VERSION}.tar.gz
+ tar xf ${VERSION}.tar.gz
+}
+
+prep() {
+ [ -d ${VERSION} ] || (fetch)
+ cd ${VERSION}
+}
+
+case $1 in
+ install) (prep; make generic "CC=cc" "MYCFLAGS=-Werror") ;;
+ clean) (prep; make clean) ;;
+ *) echo "usage: $0 install|clean"; false ;;
+esac \ No newline at end of file
diff --git a/src/user/app/init/driver/initctl.c b/src/user/app/init/driver/initctl.c
index 34171de..7f5fc20 100644
--- a/src/user/app/init/driver/initctl.c
+++ b/src/user/app/init/driver/initctl.c
@@ -2,8 +2,8 @@
#include <camellia/syscalls.h>
#include <ctype.h>
#include <errno.h>
+#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <user/lib/compat.h>
void initctl_drv(handle_t killswitch) {
diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c
index 85b83b7..0d344ed 100644
--- a/src/user/app/init/driver/ps2.c
+++ b/src/user/app/init/driver/ps2.c
@@ -2,7 +2,7 @@
#include <camellia/syscalls.h>
#include <shared/container/ring.h>
#include <stdbool.h>
-#include <unistd.h>
+#include <stdlib.h>
#include <user/lib/compat.h>
diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c
index 83b46be..c23d76f 100644
--- a/src/user/app/init/driver/termcook.c
+++ b/src/user/app/init/driver/termcook.c
@@ -1,6 +1,7 @@
#include "driver.h"
#include <camellia/syscalls.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
static void w_output(handle_t output, const char *buf, size_t len) {
diff --git a/src/user/app/tests/kernel/misc.c b/src/user/app/tests/kernel/misc.c
index 01e041d..e22cba2 100644
--- a/src/user/app/tests/kernel/misc.c
+++ b/src/user/app/tests/kernel/misc.c
@@ -3,6 +3,7 @@
#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <string.h>
+#include <unistd.h>
static void test_fault_kill(void) {
if (!fork()) { /* invalid memory access */
diff --git a/src/user/app/tests/stress.c b/src/user/app/tests/stress.c
index 9db752f..1df462a 100644
--- a/src/user/app/tests/stress.c
+++ b/src/user/app/tests/stress.c
@@ -1,6 +1,7 @@
#include "tests.h"
#include <camellia/flags.h>
#include <camellia/syscalls.h>
+#include <stdlib.h>
#include <unistd.h>
static void run_forked(void (*fn)()) {
diff --git a/src/user/app/tests/tests.h b/src/user/app/tests/tests.h
index d092115..b47e9b9 100644
--- a/src/user/app/tests/tests.h
+++ b/src/user/app/tests/tests.h
@@ -1,7 +1,7 @@
#pragma once
#include <camellia/syscalls.h>
#include <stdio.h>
-#include <unistd.h>
+#include <stdlib.h>
#define TMPFILEPATH "/tmp/.test_internal"
diff --git a/src/user/bootstrap/main.c b/src/user/bootstrap/main.c
index 9a9a922..ea92af6 100644
--- a/src/user/bootstrap/main.c
+++ b/src/user/bootstrap/main.c
@@ -1,6 +1,7 @@
#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <shared/mem.h>
+#include <stdio.h>
#include <user/lib/elfload.h>
#include <user/lib/fs/misc.h>
diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c
index 0a6a8a9..752c86e 100644
--- a/src/user/bootstrap/tar.c
+++ b/src/user/bootstrap/tar.c
@@ -4,8 +4,8 @@
#include <camellia/syscalls.h>
#include <shared/mem.h>
#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <user/lib/compat.h>
#include <user/lib/fs/dir.h>
diff --git a/src/user/lib/fs/misc.h b/src/user/lib/fs/misc.h
index 1dfe5cb..87e1be2 100644
--- a/src/user/lib/fs/misc.h
+++ b/src/user/lib/fs/misc.h
@@ -1,8 +1,6 @@
#pragma once
#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
+#include <stdlib.h>
bool fork2_n_mount(const char *path);
diff --git a/src/user/lib/include/ctype.h b/src/user/lib/include/ctype.h
index cbba529..02d7179 100644
--- a/src/user/lib/include/ctype.h
+++ b/src/user/lib/include/ctype.h
@@ -2,10 +2,14 @@
int isalnum(int c);
int isalpha(int c);
+int iscntrl(int c);
int isdigit(int c);
+int isgraph(int c);
int islower(int c);
+int ispunct(int c);
int isspace(int c);
int isupper(int c);
+int isxdigit(int c);
int tolower(int c);
int toupper(int c);
diff --git a/src/user/lib/include/locale.h b/src/user/lib/include/locale.h
new file mode 100644
index 0000000..263dfb5
--- /dev/null
+++ b/src/user/lib/include/locale.h
@@ -0,0 +1,70 @@
+#pragma once
+#include <limits.h>
+
+#define LC_ALL 0
+#define LC_COLLATE 1
+#define LC_CTYPE 2
+#define LC_MESSAGES 3
+#define LC_MONETARY 4
+#define LC_NUMERIC 5
+#define LC_TIME 6
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char *currency_symbol;
+ char frac_digits;
+ char p_cs_precedes;
+ char n_cs_precedes;
+ char p_sep_by_space;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char *int_curr_symbol;
+ char int_frac_digits;
+ char int_p_cs_precedes;
+ char int_n_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+
+static inline struct lconv *localeconv(void) {
+ /* per Linux's lconv(3) */
+ static struct lconv locale = (struct lconv){
+ .decimal_point = ".",
+ .thousands_sep = "",
+ .grouping = "",
+ .mon_decimal_point = "",
+ .mon_thousands_sep = "",
+ .mon_grouping = "",
+ .positive_sign = "",
+ .negative_sign = "",
+ .currency_symbol = "",
+ .frac_digits = CHAR_MAX,
+ .p_cs_precedes = CHAR_MAX,
+ .n_cs_precedes = CHAR_MAX,
+ .p_sep_by_space = CHAR_MAX,
+ .n_sep_by_space = CHAR_MAX,
+ .p_sign_posn = CHAR_MAX,
+ .n_sign_posn = CHAR_MAX,
+ .int_curr_symbol = "",
+ .int_frac_digits = CHAR_MAX,
+ .int_p_cs_precedes = CHAR_MAX,
+ .int_n_cs_precedes = CHAR_MAX,
+ .int_p_sep_by_space = CHAR_MAX,
+ .int_n_sep_by_space = CHAR_MAX,
+ .int_p_sign_posn = CHAR_MAX,
+ .int_n_sign_posn = CHAR_MAX,
+ };
+ return &locale;
+}
+
+char *setlocale(int category, const char *locale);
diff --git a/src/user/lib/include/math.h b/src/user/lib/include/math.h
new file mode 100644
index 0000000..07ff81d
--- /dev/null
+++ b/src/user/lib/include/math.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#define INFINITY __builtin_inff()
+#define HUGE_VAL ((double)INFINITY)
+
+int abs(int i);
+
+double acos(double x);
+double asin(double x);
+double atan2(double x, double y);
+double cos(double x);
+double cosh(double x);
+double sin(double x);
+double sinh(double x);
+double tan(double x);
+double tanh(double x);
+
+double fabs(double x);
+double floor(double x);
+double ceil(double x);
+double log(double x);
+double log2(double x);
+double log10(double x);
+double exp(double x);
+double fmod(double x, double y);
+double frexp(double num, int *exp);
+double ldexp(double x, int exp);
+double pow(double x, double y);
+double sqrt(double x);
diff --git a/src/user/lib/include/setjmp.h b/src/user/lib/include/setjmp.h
index f90bae9..51c7fd2 100644
--- a/src/user/lib/include/setjmp.h
+++ b/src/user/lib/include/setjmp.h
@@ -1,13 +1,25 @@
#pragma once
#include <user/lib/panic.h>
-typedef char sigjmp_buf;
+typedef char jmp_buf[1];
+typedef char sigjmp_buf[1];
+
+static inline int setjmp(jmp_buf env) {
+ (void)env;
+ return 0;
+}
+
static inline int sigsetjmp(sigjmp_buf env, int savemask) {
(void)env; (void)savemask;
return 0;
}
-static inline void siglongjmp(sigjmp_buf env, int val) {
+static inline _Noreturn void longjmp(jmp_buf env, int val) {
+ (void)env; (void)val;
+ __libc_panic("unimplemented");
+}
+
+static inline _Noreturn void siglongjmp(sigjmp_buf env, int val) {
(void)env; (void)val;
__libc_panic("unimplemented");
}
diff --git a/src/user/lib/include/signal.h b/src/user/lib/include/signal.h
index c279beb..b6e9677 100644
--- a/src/user/lib/include/signal.h
+++ b/src/user/lib/include/signal.h
@@ -3,10 +3,11 @@
#define SIGHUP 0
#define SIGINT 0
-#define SIGWINCH 0
#define SIGQUIT 0
-#define SIG_IGN 0
+#define SIGWINCH 0
+#define SIG_DFL 0
#define SIG_ERR 0
+#define SIG_IGN 0
typedef int sig_atomic_t;
diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h
index 5ad07e0..84fb515 100644
--- a/src/user/lib/include/stdio.h
+++ b/src/user/lib/include/stdio.h
@@ -14,8 +14,12 @@
#define SEEK_END 3
#define _IONBF 0
+#define _IOFBF 0
#define _IOLBF 1
+/* size of file buffers. not that we have any */
+#define BUFSIZ 1024
+
/* stop fread() from trying to fill the entire buffer before returning
* i.e. it will call _syscall_read() exactly once */
#define FEXT_NOFILL 1
@@ -37,6 +41,7 @@ FILE *fdopen(int fd, const char *mode);
FILE *file_clone(const FILE *, const char *mode);
FILE *popen(const char *cmd, const char *mode);
int pclose(FILE *f);
+FILE *tmpfile(void);
int fextflags(FILE *, int extflags);
int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size);
@@ -51,6 +56,7 @@ int fgetc(FILE *f);
int getc(FILE *f);
int fputc(int c, FILE *f);
int putc(int c, FILE *f);
+int ungetc(int c, FILE *stream);
int fseek(FILE *f, long offset, int whence);
int fseeko(FILE *f, off_t offset, int whence);
@@ -67,3 +73,9 @@ int getchar(void);
int putchar(int c);
off_t lseek(int fd, off_t off, int whence);
+
+int remove(const char *path);
+int rename(const char *old, const char *new);
+
+#define L_tmpnam (5 + 16 + 1)
+char *tmpnam(char *s);
diff --git a/src/user/lib/include/stdlib.h b/src/user/lib/include/stdlib.h
index e2e3996..8c827e3 100644
--- a/src/user/lib/include/stdlib.h
+++ b/src/user/lib/include/stdlib.h
@@ -6,7 +6,11 @@
#include <user/lib/vendor/dlmalloc/malloc.h>
#endif
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+
_Noreturn void abort(void);
+_Noreturn void exit(int);
int mkstemp(char *template);
char *getenv(const char *name);
diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h
index 7235da9..cf621d5 100644
--- a/src/user/lib/include/string.h
+++ b/src/user/lib/include/string.h
@@ -2,12 +2,21 @@
#include <shared/mem.h>
long strtol(const char *restrict s, char **restrict end, int base);
+double strtod(const char *restrict s, char **restrict end);
char *strchr(const char *s, int c);
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
+char *strpbrk(const char *s1, const char *s2);
char *strtok(char *restrict s, const char *restrict sep);
char *strtok_r(char *restrict s, const char *restrict sep, char **restrict state);
int strncmp(const char *s1, const char *s2, size_t n);
+int strcoll(const char *s1, const char *s2);
+
+char *strstr(const char *s1, const char *s2);
+
+char *strcpy(char *restrict s1, const char *restrict s2);
+
+char *strerror(int errnum);
diff --git a/src/user/lib/include/sys/types.h b/src/user/lib/include/sys/types.h
index 3bc3f7f..3b1772b 100644
--- a/src/user/lib/include/sys/types.h
+++ b/src/user/lib/include/sys/types.h
@@ -1,4 +1,7 @@
#pragma once
#include <stddef.h>
+#include <stdint.h>
typedef long long off_t;
+typedef int64_t time_t;
+typedef uint64_t clock_t;
diff --git a/src/user/lib/include/time.h b/src/user/lib/include/time.h
new file mode 100644
index 0000000..067c35f
--- /dev/null
+++ b/src/user/lib/include/time.h
@@ -0,0 +1,29 @@
+#pragma once
+#include <sys/types.h>
+
+#define CLOCKS_PER_SEC 1000000
+
+struct tm {
+ int tm_sec; /* Seconds [0,60]. */
+ int tm_min; /* Minutes [0,59]. */
+ int tm_hour; /* Hour [0,23]. */
+ int tm_mday; /* Day of month [1,31]. */
+ int tm_mon; /* Month of year [0,11]. */
+ int tm_year; /* Years since 1900. */
+ int tm_wday; /* Day of week [0,6] (Sunday =0). */
+ int tm_yday; /* Day of year [0,365]. */
+ int tm_isdst; /* Daylight Savings flag. */
+};
+
+time_t time(time_t *tloc);
+clock_t clock(void);
+
+struct tm *gmtime(const time_t *timer);
+struct tm *localtime(const time_t *timer);
+time_t mktime(struct tm *timeptr);
+
+double difftime(time_t time1, time_t time0);
+
+size_t strftime(
+ char *restrict s, size_t maxsize,
+ const char *restrict format, const struct tm *restrict timeptr);
diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h
index 59af24b..f49c337 100644
--- a/src/user/lib/include/unistd.h
+++ b/src/user/lib/include/unistd.h
@@ -4,7 +4,6 @@
int fork(void);
int close(handle_t h);
-_Noreturn void exit(int);
_Noreturn void _exit(int);
int unlink(const char *path);