diff options
| author | Miguel <m.i@gmx.at> | 2018-10-15 16:29:50 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-15 16:29:50 +0200 |
| commit | e3a8099343aac9d94f411638ad84632d4b620132 (patch) | |
| tree | f0a1f73ab106c17b25fd8a5264a66b6b48e55e48 /interface/syscalls.c | |
| parent | f35d2124c36f8d39a953b76620e081b79c2faffd (diff) | |
cleanup sys/ etc
Diffstat (limited to 'interface/syscalls.c')
| -rw-r--r-- | interface/syscalls.c | 345 |
1 files changed, 157 insertions, 188 deletions
diff --git a/interface/syscalls.c b/interface/syscalls.c index 06846bb..c9964fd 100644 --- a/interface/syscalls.c +++ b/interface/syscalls.c @@ -8,9 +8,13 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/termios.h> +#include <sys/dirent.h> #include <errno.h> +// TODO ? all funct not preceeded with underscore should go as #defines +// inside headers! for newlib we define both here now ... // + // BASICS // // everybody is root @@ -25,7 +29,20 @@ uid_t getgid(void) return 0; } -// no sync needed for our ram-image so far (DMA?) +// everybody is root +char *getlogin(void) +{ + return "root"; +} + +// the hostname is hard +int gethostname(char *name, size_t len) +{ + strcpy(name,"foolcomp"); + return 0; //success +} + +// no sync needed for our ram-image so far (maye once w use DMA?) void sync(void) { } @@ -33,6 +50,7 @@ void sync(void) // set working directory - we simply save this in PWD environment var int chdir(const char *path) { + char buf[256]; sprintf(buf,"PWD=%s",path); putenv(buf); return 0; // assume success @@ -41,12 +59,19 @@ int chdir(const char *path) // get working dir (see chdir) char* getwd(char *buf) { - return getenv("PWD"); + return strcpy(buf,getenv("PWD")); +} + +// HELPER for flushing stdout down the toilet when main exits // +// newlib does not do this ? TODO: check what the standard says. // +void _flushing() +{ + fflush(stdout); } // C NEWLIB // -// first of all we have a few posix syscalls required by newlib +// here we have a few posix syscalls required by newlib // (we use version newlib-3.0.0.20180802) // https://sourceware.org/newlib/libc.html#Syscalls // just check liunx man-pages, how they SHOULD work. @@ -216,191 +241,75 @@ int write(int file, char *ptr, int len) return syscall(SYSCALL_WRITE,file,ptr,len); } -////////////////////////////////////////////////////////////////////// - - -int _readdir(const char *name,void *dirs,int max) +int _gettimeofday(struct timeval *tv, void *tz) { - return syscall(SYSCALL_READDIR,name,dirs,max); + return syscall(SYSCALL_GETTIMEOFDAY,tv,tz,0); } - -int _poll(int file) -{ - return syscall(SYSCALL_POLL,file,0,0); -} - -int _gettimeofday(struct timeval *tv, void *tz) +int gettimeofday(struct timeval *tv, void *tz) { return syscall(SYSCALL_GETTIMEOFDAY,tv,tz,0); } +// not sure if required by newlib ? /// int _lstat(const char *file, struct stat *st) { return syscall(SYSCALL_LSTAT,file,st,0); } +int lstat(const char *file, struct stat *st) +{ + return syscall(SYSCALL_LSTAT,file,st,0); +} -// termios - - int tcgetattr(int fd, struct termios *termios_p) - { - return syscall(SYSCALL_TCGETATTR,fd,termios_p,0); - } - - int tcsetattr(int fd, int optional_actions, const struct termios *termios_p) - { - return syscall(SYSCALL_TCSETATTR,fd,termios_p,0); - } - -/* - - int tcsendbreak(int fd, int duration); - - int tcdrain(int fd); - - - int tcflow(int fd, int action); -*/ - -// void cfmakeraw(struct termios *termios_p); - - /* - speed_t cfgetispeed(const struct termios *termios_p); - - */ - - speed_t cfgetospeed(const struct termios *termios_p) - { - syscall(SYSCALL_UNIMPLEMENTED,"cfgetospeed",0,0); - return B230400; - } - - long fpathconf(int fd, int name) - { - return syscall(SYSCALL_UNIMPLEMENTED,"fpathconf",0,0); - } - - int tcflush(int fd, int queue_selector) - { - return syscall(SYSCALL_UNIMPLEMENTED,"tcflush",0,0); - } - - /* - int cfsetispeed(struct termios *termios_p, speed_t speed); - - int cfsetospeed(struct termios *termios_p, speed_t speed); - - int cfsetspeed(struct termios *termios_p, speed_t speed); - */ +// like fork but keeps runin' on same memory so we have multithreading +int _clone(void) +{ + return syscall(SYSCALL_CLONE,0,0,0); +} -////////////////////////////////////////// move along /// +// DIRENT // - int access(const char *pathname, int mode) - { - return syscall(SYSCALL_UNIMPLEMENTED,"access",0,0); - } +DIR *opendir(const char *name) +{ + DIR *dir=malloc(sizeof(struct dirent)); + return syscall(SYSCALL_OPENDIR,name,dir,0); +} - #include <sys/types.h> - #include <sys/stat.h> +struct dirent *readdir(DIR *dirp) +{ + return syscall(SYSCALL_READDIR,dirp,0,0); +} - mode_t umask(mode_t mask) - { - return syscall(SYSCALL_UNIMPLEMENTED,"umask",0,0); - } +// TERMIOS // - int mkdir(const char *pathname, mode_t mode) - { - return syscall(SYSCALL_UNIMPLEMENTED,"mkdir",0,0); - } +int tcgetattr(int fd, struct termios *termios_p) +{ + return syscall(SYSCALL_TCGETATTR,fd,termios_p,0); +} +int tcsetattr(int fd, int optional_actions, const struct termios *termios_p) +{ + return syscall(SYSCALL_TCSETATTR,fd,termios_p,0); +} - char *ttyname(int fd) - { - return syscall(SYSCALL_UNIMPLEMENTED,"ttyname",0,0); - } +speed_t cfgetospeed(const struct termios *termios_p) +{ + return B230400; +} -// +// I/O STUFF - Pipes et al // - struct void *readdir(DIR *dirp) // returns dirent - { - return syscall(SYSCALL_UNIMPLEMENTED,"readdir",0,0); - } - - DIR *opendir(const char *name) - { - errno=EACCES; - return syscall(SYSCALL_UNIMPLEMENTED,"opendir",name,0); - } - - int closedir(DIR *dirp) - { - return syscall(SYSCALL_UNIMPLEMENTED,"closedir",0,0); - } - - - unsigned int sleep(unsigned int seconds) - { - return syscall(SYSCALL_UNIMPLEMENTED,"sleep",0,0); - } - - char *getlogin(void) - { - return syscall(SYSCALL_UNIMPLEMENTED,"getlogin",0,0); - } - - - /** - * Monitor multiple descriptors - * ============================ - * - * nfds is the MAX file descriptor number +1. - * - * It is possible to provide 3 different sets of filedescriptors - * (they can be NULL as well) - * - * - readfds - reading - * - writefds - writing - * - exceptfds - exceptions (all cleared unless exception occurs) - * - * The call returns the total number of descriptors contained in all - * sets after returning. - * - * This call will block until time (timeout) runs out - * OR a file descriptor becomes ready. - */ - - int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) - { - // pack all our sets togehter - fd_set *fd_sets[3]; - - fd_sets[0]=readfds; - fd_sets[1]=writefds; - fd_sets[2]=exceptfds; - - return syscall(SYSCALL_SELECT,nfds,timeout,fd_sets); - } - - int pclose(FILE *stream) - { - return syscall(SYSCALL_UNIMPLEMENTED,"pclose",0,0); - } - - FILE *popen(const char *command, const char *type) - { - return syscall(SYSCALL_UNIMPLEMENTED,"popen",0,0); - } - - // call dup2 in dup emulation mode - int dup(int oldfd) - { - return _dup2(oldfd,0xffffffff); // dup emulation mode - } +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +{ + // pack all our sets togehter + fd_set *fd_sets[3]; + fd_sets[0]=readfds; + fd_sets[1]=writefds; + fd_sets[2]=exceptfds; -int _clone(void) -{ - return syscall(SYSCALL_CLONE,0,0,0); + return syscall(SYSCALL_SELECT,nfds,timeout,fd_sets); } + int _pipe(uint32_t fds[2]) { return syscall(SYSCALL_PIPE,fds,0,0); @@ -417,19 +326,81 @@ int dup2(uint32_t oldfd,uint32_t newfd) { return syscall(SYSCALL_DUP2,oldfd,newfd,0); } -int _gui_rect() +int dup(int oldfd) { - return syscall(SYSCALL_GUI_RECT,0,0,0); + return _dup2(oldfd,0xffffffff); // dup emulation mode } + +// PRIMITIVE GUI SYSCALLS // + +// create window for running process int _gui_win() { return syscall(SYSCALL_GUI_WIN,0,0,0); } -int gethostname(char *name, size_t len) +// swap buffers +int _gui_rect() { - strcpy(name,"foolcomp"); - return 0; //success + return syscall(SYSCALL_GUI_RECT,0,0,0); +} + +////////////////////////////////////////// move along fool /////////// +// +// ALL calls under this lines are just stubs to let some 3rd party stuff +// compile and fail silently on runtime where applicable. +// +///// + + +long fpathconf(int fd, int name) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"fpathconf",0,0); +} + +int tcflush(int fd, int queue_selector) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"tcflush",0,0); +} + +int access(const char *pathname, int mode) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"access",0,0); +} + +mode_t umask(mode_t mask) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"umask",0,0); +} + +int mkdir(const char *pathname, mode_t mode) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"mkdir",0,0); +} + +char *ttyname(int fd) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"ttyname",0,0); +} + +int closedir(DIR *dirp) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"closedir",0,0); +} + +unsigned int sleep(unsigned int seconds) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"sleep",0,0); +} + +int pclose(FILE *stream) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"pclose",0,0); +} + +FILE *popen(const char *command, const char *type) +{ + return syscall(SYSCALL_UNIMPLEMENTED,"popen",0,0); } ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) @@ -439,48 +410,46 @@ ssize_t readlink(const char *pathname, char *buf, size_t bufsiz) int rmdir(const char *pathname) { - syscall(SYSCALL_UNIMPLEMENTED,"rmdir",0,0); - return 0; + return syscall(SYSCALL_UNIMPLEMENTED,"rmdir",0,0); } int fcntl(int fd, int cmd, ... /* arg */ ) { - syscall(SYSCALL_UNIMPLEMENTED,"fcntl",0,0); - return 0; + return syscall(SYSCALL_UNIMPLEMENTED,"fcntl",0,0); } pid_t waitpid(pid_t pid, int *wstatus, int options) { - syscall(SYSCALL_UNIMPLEMENTED,"waitpid",0,0); - return 0; + return syscall(SYSCALL_UNIMPLEMENTED,"waitpid",0,0); } int execl(const char *path, const char *arg, ...) { - syscall(SYSCALL_UNIMPLEMENTED,"execl",0,0); - return 0; + return syscall(SYSCALL_UNIMPLEMENTED,"execl",0,0); } int execvp(const char *file, char *const argv[]) { - syscall(SYSCALL_UNIMPLEMENTED,"execvp",0,0); - return 0; + return syscall(SYSCALL_UNIMPLEMENTED,"execvp",0,0); } long sysconf(int name) { return syscall(SYSCALL_UNIMPLEMENTED,"sysconf",name,0); - return 0; } int chmod(const char *pathname, mode_t mode) { - syscall(SYSCALL_UNIMPLEMENTED,"chmod",0,0); - return 0; -} - -void _flushing() -{ - fflush(stdout); + return syscall(SYSCALL_UNIMPLEMENTED,"chmod",pathname,mode); } +/* +int tcsendbreak(int fd, int duration); +int tcdrain(int fd); +int tcflow(int fd, int action); +void cfmakeraw(struct termios *termios_p); +speed_t cfgetispeed(const struct termios *termios_p); +int cfsetispeed(struct termios *termios_p, speed_t speed); +int cfsetospeed(struct termios *termios_p, speed_t speed); +int cfsetspeed(struct termios *termios_p, speed_t speed); +*/ |
