diff options
Diffstat (limited to 'kernel/syscalls.c')
| -rw-r--r-- | kernel/syscalls.c | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 621880a..0be0602 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -1,12 +1,14 @@ #define FOOLOS_MODULE_NAME "syscalls" #include "lib/logger/log.h" +#include "lib/string/string.h" #include "fs/fs.h" #include "fs/ext2.h" -#include "kernel/kernel.h" -#include "kernel/config.h" +#include "kernel.h" #include "fifo.h" #include "fd.h" +#include "terminal/terminal.h" +#include "driver/screen.h" #include <sys/stat.h> #include <sys/time.h> #include <stdbool.h> @@ -21,10 +23,15 @@ static uint32_t next_fd=0; static fifo fifos[MAX_FIFOS]; static uint32_t next_fifo=0; +// screen / terminal +term_out screen; +terminal_tty tty1; + int syscall_unhandled(int nr) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr); - panic(FOOLOS_MODULE_NAME,"unhandled syscall (generic handler)"); + char msg[256]; + tfp_sprintf(msg, "unhandled syscall : %d",nr); + panic(FOOLOS_MODULE_NAME,msg); } int syscall_gettimeofday(struct timeval *tv, struct timezone *tz) @@ -59,23 +66,15 @@ int syscall_lseek(int file,int ptr,int dir) // TODO: /dev/console or /dev/tty1 - /dev/ttyN int syscall_write(int file, char *buf, int len) { - lock_spin(2); - - //x86_int_disable(); #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] write(file=%d, buf=0x%08X, len=%d)", task_get_current_pid(),file,buf,len); #endif - if(file!=1&&file!=2) panic(FOOLOS_MODULE_NAME,"unhandled syscall: write (only stdout and stderr)"); - - //stderr and stdout go to console for(int i=0;i<len;i++) { - fifo_put(&get_fool()->std_out,buf[i]); + fd_write(&fds[file],buf[i]); } - lock_release(2); - //x86_int_enable(); return len; } @@ -84,22 +83,20 @@ int syscall_read(int file, char *buf, int len) #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len); #endif + //file 0 = stdin , file 1 = stdout , file 2 = stderr - // file 1 = stdin , file 2 = stdout - - // stdin TODO: other descroptiors! - if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall: read (only stdin)"); - char c; int l=0; while(1) { - while(!fifo_has(&get_fool()->std_in)); - c=fifo_get(&get_fool()->std_in); + while(!fd_has(&fds[file])); + c=fd_read(&fds[file]); + *buf=c; buf++; l++; + if(l==len)return l; if(c=='\n')return l; } @@ -116,21 +113,25 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max) } // for non blocking io? -int syscall_has_data_waiting(int file) +int syscall_poll(int file) { + file=2; //workaround #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"has data waiting?"); #endif - return fifo_has(&get_fool()->std_in); + return fd_has(&fds[file]); } +// TODO: DELETE THIS SHIT! int syscall_tune(int v1,int v2, int v3) { #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"tuning request"); #endif + // osbolete + /* if(v1==0) // regular tty mode { get_fool()->tty->set_buff=true; @@ -141,7 +142,7 @@ int syscall_tune(int v1,int v2, int v3) get_fool()->tty->set_buff=false; get_fool()->tty->set_echo=false; } - + */ return 0; } @@ -235,17 +236,39 @@ int syscall_execve(char *name, char **argv, char **env) // this is never reached! } +// minihack +int get_max_fd() +{ + return next_fd-1; +} + // TODO: support other files too (not only fifo pipes) +// TODO: allow opening existing files/named 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 - + if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)panic(FOOLOS_MODULE_NAME,"we ran out of fd's or fifo's"); + + if(0!=strcmp(name,"term")) + { + fifos[next_fifo]=fifo_create_buffered(1); + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } + else + { + screen.put_char=console_put_char; + screen.update_cursor=update_cursor; + tty1=terminal_init(&screen,NULL); + + fifos[next_fifo].data=&tty1; + fifos[next_fifo].put=terminal_put; + + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } - fifos[next_fifo]=fifo_create_buffered(1); - fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); next_fifo++; next_fd++; @@ -304,24 +327,3 @@ int syscall_stat(const char *path, struct stat *st,int none) st->st_mode = S_IFCHR; return 0; } - -int syscall_fstat(int file, struct stat *st,int none) -{ - #ifdef LOG_SYSCALLS - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fstat (file=%d,stat=0x%08X)", file,st); - #endif - - st->st_mode = S_IFCHR; - return 0; -} - - -int syscall_lstat(const char *path, struct stat *st,int none) -{ - #ifdef LOG_SYSCALLS - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lstat (path=0x%08X,stat=0x%08X)", path,st); - #endif - - st->st_mode = S_IFCHR; - return 0; -} |
