summaryrefslogtreecommitdiff
path: root/src/user/lib/libc/tce
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-05-19 11:45:49 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-05-19 11:45:49 +0200
commit499ca6c243b05da176a2d4bd9a2317f0b28afc7f (patch)
treef55ff788632b017ab8de83b71ad02b0998e1dda5 /src/user/lib/libc/tce
parent7b466345af0d3a7dc5622617ce443a90c64e34a4 (diff)
downloadTCE-499ca6c243b05da176a2d4bd9a2317f0b28afc7f.tar.gz
TCE-499ca6c243b05da176a2d4bd9a2317f0b28afc7f.zip
Introducing FWIK, the userland C++ framework. Far from complete.
Diffstat (limited to 'src/user/lib/libc/tce')
-rw-r--r--src/user/lib/libc/tce/syscall.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/user/lib/libc/tce/syscall.c b/src/user/lib/libc/tce/syscall.c
new file mode 100644
index 0000000..80e0e0e
--- /dev/null
+++ b/src/user/lib/libc/tce/syscall.c
@@ -0,0 +1,122 @@
+#include <tce/syscall.h>
+#include <stdlib.h>
+#include <sched.h>
+#include <tce/vfs.h>
+
+static size_t call(size_t a, size_t b, size_t c, size_t d, size_t e, size_t f) {
+ size_t ret;
+ asm volatile("int $64" : "=a"(ret) : "a"(a), "b"(b), "c"(c), "d"(d), "S"(e), "D"(f));
+ return ret;
+}
+
+void thread_exit() {
+ call(SC_THREAD_EXIT, 0, 0, 0, 0, 0);
+}
+
+void schedule() {
+ call(SC_SCHEDULE, 0, 0,0, 0, 0);
+}
+
+void thread_sleep(int time) {
+ call(SC_THREAD_SLEEP, time, 0, 0, 0, 0);
+}
+
+void process_exit(int retval) {
+ call(SC_PROCESS_EXIT, retval, 0, 0, 0, 0);
+}
+
+void printk(char* str) {
+ call(SC_PRINTK, (unsigned)str, 0, 0, 0, 0);
+}
+
+//THREAD CREATION
+struct thread_start_data {
+ void (*entry)(void*);
+ void *data;
+ void *stack;
+};
+void *_stack_to_free = 0;
+uint32_t _stack_freeing_mutex = MUTEX_UNLOCKED;
+
+void thread_start(void *data) {
+ struct thread_start_data *tsd = data;
+ tsd->entry(tsd->data);
+ mutex_lock(&_stack_freeing_mutex);
+ if (_stack_to_free != 0) free(_stack_to_free);
+ _stack_to_free = tsd->stack;
+ asm volatile("movl %%ebx, (_stack_freeing_mutex); int $64;" ::
+ "a"(SC_THREAD_EXIT), "b"(MUTEX_UNLOCKED));
+}
+void thread_new(void (*entry)(void*), void *data) {
+ struct thread_start_data *tsd = malloc(sizeof(struct thread_start_data));
+ tsd->entry = entry;
+ tsd->data = data;
+ tsd->stack = malloc(NEW_STACK_SIZE);
+ call(SC_THREAD_NEW, (unsigned)thread_start, (unsigned)tsd, (unsigned)(tsd->stack + NEW_STACK_SIZE), 0, 0);
+}
+
+void irq_wait(int number) {
+ call(SC_IRQ_WAIT, number, 0, 0, 0, 0);
+}
+
+int proc_priv() {
+ return call(SC_PROC_PRIV, 0, 0, 0, 0, 0);
+}
+
+// ******** memory
+
+void* sbrk(ptrdiff_t s) {
+ return (void*)call(SC_SBRK, s, 0, 0, 0, 0);
+}
+
+void brk(void* ptr) {
+ call (SC_BRK, (size_t)ptr, 0, 0, 0, 0);
+}
+
+// ********** proc
+
+int run(char* filename, char** args, FILE zero_fd) {
+ return call(SC_RUN, (unsigned)filename, (unsigned)args, (unsigned)zero_fd, 0, 0);
+}
+
+int waitpid(int p, int block) {
+ return call(SC_WAITPID, p, block, 0, 0, 0);
+}
+
+// ********** file
+
+FILE open(char* filename, int mode) {
+ return call(SC_OPEN, (unsigned)filename, mode, 0, 0, 0);
+}
+
+FILE open_relative(FILE root, char* filename, int mode) {
+ return call(SC_OPEN_RELATIVE, root, (unsigned) filename, mode, 0, 0);
+}
+
+int stat(char* filename, file_info *info) {
+ return call(SC_STAT, (unsigned) filename, (unsigned) info, 0, 0, 0);
+}
+
+int stat_relative(FILE root, char* filename, file_info *info) {
+ return call(SC_STAT_RELATIVE, root, (unsigned) filename, (unsigned) info, 0, 0);
+}
+
+int statf(FILE file, file_info *info) {
+ return call(SC_STATF, file, (unsigned)info, 0, 0, 0);
+}
+
+void close(FILE file) {
+ call(SC_CLOSE, file, 0, 0, 0, 0);
+}
+
+int read(FILE file, size_t offset, size_t len, char *buffer) {
+ return call(SC_READ, file, offset, len, (unsigned) buffer, 0);
+}
+
+int write(FILE file, size_t offset, size_t len, char* buffer) {
+ return call(SC_WRITE, file, offset, len, (unsigned) buffer, 0);
+}
+
+int link(char* from, char* to, int mode) {
+ return call(SC_LINK, (unsigned) from, (unsigned)to, mode, 0, 0);
+}