From 2a6690e9fd53a02613796764248006e06ac482d6 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 14 Oct 2018 22:36:16 +0200 Subject: ported vim et al --- kernel/kernel.c | 2 ++ kernel/syscalls.c | 82 +++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 18 deletions(-) (limited to 'kernel') diff --git a/kernel/kernel.c b/kernel/kernel.c index 7f92a25..3692b17 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -158,11 +158,13 @@ void kernel_main(uint32_t eax,uint32_t ebx) mouse_init(); // -- E1000 DRIVER --/ + #ifndef DISABLE_E1000 if(e1000_addr) { klog("E1000 init ..."); e1000_init(e1000_addr); } + #endif // we wait until the end since the time will only start ticking once // we enable interrupts. diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 228b70a..1c1d2c7 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -12,6 +12,7 @@ #include "driver/screen.h" #include #include +#include #include #include #include "syscalls.h" @@ -120,8 +121,10 @@ char* syscall_get_name(uint32_t num) return "SYSCALL_GUI_WIN"; case SYSCALL_SELECT: return "SYSCALL_SELECT"; + case SYSCALL_UNIMPLEMENTED: + return "SYSCALL_UNKNOWN"; } - kpanic("UNKNOWN SYSCALL NUM"); + kpanic("UNKNOWN SYSCALL NUM: %d",num); } int syscall_gettimeofday(struct timeval *tv, struct timezone *tz,uint32_t none1, uint32_t pid) @@ -183,13 +186,26 @@ int syscall_read(int file, char *buf, int len,uint32_t pid) int syscall_select(int maxxfd,struct timeval *tv, fd_set **fd_sets, uint32_t pid, bool test) { int ret=0; + + if(test&&tv!=NULL) // check if time did not run out already + { + if(tv->tv_sec==0&&tv->tv_usec==0)return 1; + + uint64_t t=timer_get_ms(); // current time in milliseconds (10^-3) + + uint64_t t0=0; + t0+=tv->tv_sec*1000; // seconds * 10^3 + t0+=tv->tv_usec/1000; // microseconds * 10^-3 + + if(t>t0)return 1; // ready to fire! + } // TODO: wake when timeout runs out! if(!test) { - if(tv==NULL)klog("select with infinite timeout"); - else klog ("select with timeout: sec=%d, usec=%d",tv->tv_sec,tv->tv_usec); + // if(tv==NULL)klog("select with infinite timeout"); +// else klog ("select with timeout: sec=%d, usec=%d",tv->tv_sec,tv->tv_usec); } for(int i=0;itv_sec*1000; // seconds * 10^3 - t0+=tv->tv_usec/1000; // microseconds * 10^-3 - - if(t>t0)return 1; // ready to fire! - } return ret; @@ -439,7 +445,6 @@ int syscall_stat(const char *path, struct stat *st,int none,uint32_t pid) return 0; } - uint32_t syscall_pipe(uint32_t *addr,int none1, int none2, uint32_t pid) { fd pipfds[2]; @@ -462,11 +467,46 @@ uint32_t syscall_pipe(uint32_t *addr,int none1, int none2, uint32_t pid) uint32_t syscall_dup2(uint32_t oldfd,int newfd, int none2, uint32_t pid) { - if(newfd==0xffffffff)klog("dup mode not supported yet !!!"); + if(newfd==0xffffffff)kpanic("dup mode not supported yet !!!"); fds[pid][newfd]=fd_dupl(&fds[pid][oldfd]); return newfd; } + + /// testing TODO: + struct termios tty1; + bool termios_init=false; + +uint32_t syscall_tcgetattr(int fd, struct termios *termios_p, uint32_t none, uint32_t pid) +{ + if(!termios_init) + { + tty1.c_cc[VMIN]=1; // reading from terminal returns after each byte + termios_init=true; + } + klog("pid %d calls tcgetattr on %d",pid,fd); + *termios_p=tty1; + return 0; +} + +uint32_t syscall_tcsetattr(int fd, struct termios *termios_p, uint32_t none, uint32_t pid) +{ + klog("pid %d calls tcsetattr on %d",pid,fd); + klog("c_iflag=%08X",termios_p->c_iflag); + klog("c_oflag=%08X",termios_p->c_oflag); + klog("c_cflag=%08X",termios_p->c_cflag); + klog("c_lflag=%08X",termios_p->c_lflag); + for(int i=0;ic_cc[i]!=0) + { + klog("set c_cc[%d]=%d",i,termios_p->c_cc[i]); + } + } + tty1=*termios_p; + return 0; +} + uint32_t syscall_gui_rect(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) { compositor_wake(); @@ -492,7 +532,7 @@ uint32_t syscall_generic_prep(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, case SYSCALL_SELECT : // change to absolute time for easier timout - if(tv!=NULL) + if(tv!=NULL&&(tv->tv_sec!=0||tv->tv_usec!=0)) { uint64_t t=timer_get_ms(); // current time in milliseconds (10^-3) t+=tv->tv_sec*1000; // seconds * 10^3 @@ -500,7 +540,6 @@ uint32_t syscall_generic_prep(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, tv->tv_sec=t/1000; tv->tv_usec=(t%1000)*1000; - } break; @@ -528,6 +567,9 @@ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, /** Generics */ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) { + +// klog("processing syscall [%s] for pid:%d",syscall_get_name(nr),pid); + switch(nr){ case SYSCALL_EXIT : return syscall_exit(p1,p2,p3,pid); @@ -588,8 +630,12 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint return syscall_gui_rect(p1,p2,p3,pid); case SYSCALL_GUI_WIN : return syscall_gui_win(p1,p2,p3,pid); + case SYSCALL_TCGETATTR: + return syscall_tcgetattr(p1,p2,p3,pid); + case SYSCALL_TCSETATTR: + return syscall_tcsetattr(p1,p2,p3,pid); } - klog("unknown syscall %s / %d",p1,nr); + klog("unknown syscall %s / %d we just return 0",p1,nr); return 0; } -- cgit v1.2.3