diff options
Diffstat (limited to 'kernel/syscalls.c')
| -rw-r--r-- | kernel/syscalls.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 9f10d20..621880a 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -5,6 +5,8 @@ #include "fs/ext2.h" #include "kernel/kernel.h" #include "kernel/config.h" +#include "fifo.h" +#include "fd.h" #include <sys/stat.h> #include <sys/time.h> #include <stdbool.h> @@ -13,6 +15,12 @@ // TODO: use includes!!! uint64_t timer_get_ms(); +static fd fds[MAX_FD]; +static uint32_t next_fd=0; + +static fifo fifos[MAX_FIFOS]; +static uint32_t next_fifo=0; + int syscall_unhandled(int nr) { log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr); @@ -77,6 +85,8 @@ int syscall_read(int file, char *buf, int len) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len); #endif + // file 1 = stdin , file 2 = stdout + // stdin TODO: other descroptiors! if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall: read (only stdin)"); @@ -225,16 +235,22 @@ int syscall_execve(char *name, char **argv, char **env) // this is never reached! } - // TODO: support other files too (not only fifo pipes) int syscall_open(char *name, int flags, int mode) { #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"open (name=0x%08X(\"%s\"), flags=%d, mode=%d)",name, name,flags,mode); #endif - //panic(FOOLOS_MODULE_NAME,"unhandled syscall: open"); -} + if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)panic(FOOLOS_MODULE_NAME,"we ran out of fd's or fifo's"); + + fifos[next_fifo]=fifo_create_buffered(1); + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + next_fifo++; + next_fd++; + + return next_fd-1; +} //newcomers // @@ -244,9 +260,9 @@ int syscall_close(int file,int none1,int none2) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"close (file=%d)", file); #endif - if(file!=0&&file!=1&&file!=2) - panic(FOOLOS_MODULE_NAME,"unhandled syscall: close"); - + //if(file!=0&&file!=1&&file!=2) + // panic(FOOLOS_MODULE_NAME,"unhandled syscall: close"); + return -1; } @@ -278,7 +294,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2) return oldalloc; } - // stat, fstat, lstat int syscall_stat(const char *path, struct stat *st,int none) { |
