diff options
Diffstat (limited to 'src/library/gc')
-rw-r--r-- | src/library/gc/syscall.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/library/gc/syscall.c b/src/library/gc/syscall.c index e7d77a0..b16881e 100644 --- a/src/library/gc/syscall.c +++ b/src/library/gc/syscall.c @@ -1,4 +1,5 @@ #include <gc/syscall.h> +#include <gc/mem.h> static int call(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f) { unsigned ret; @@ -26,8 +27,24 @@ void printk(char* str) { call(4, (unsigned)str, 0, 0, 0, 0); } +//THREAD CREATION +struct thread_start_data { + void (*entry)(void*); + void *data; + void *stack; +}; +void thread_start(void *data) { + struct thread_start_data *tsd = data; + tsd->entry(tsd->data); + free(tsd->stack); + thread_exit(); +} void thread_new(void (*entry)(void*), void *data) { - call(5, (unsigned)entry, (unsigned)data, 0, 0, 0); + struct thread_start_data *tsd = malloc(sizeof(struct thread_start_data)); + tsd->entry = entry; + tsd->data = data; + tsd->stack = malloc(NEW_STACK_SIZE); + call(5, (unsigned)thread_start, (unsigned)tsd, (unsigned)(tsd->stack + NEW_STACK_SIZE), 0, 0); } void irq_wait(int number) { |