summaryrefslogtreecommitdiff
path: root/interface
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-10-15 16:29:50 +0200
committerMiguel <m.i@gmx.at>2018-10-15 16:29:50 +0200
commite3a8099343aac9d94f411638ad84632d4b620132 (patch)
treef0a1f73ab106c17b25fd8a5264a66b6b48e55e48 /interface
parentf35d2124c36f8d39a953b76620e081b79c2faffd (diff)
cleanup sys/ etc
Diffstat (limited to 'interface')
-rw-r--r--interface/README7
-rw-r--r--interface/fs.h36
-rw-r--r--interface/sys/dirent.h26
-rw-r--r--interface/sys/termios.h144
-rw-r--r--interface/syscalls.c345
-rw-r--r--interface/syscalls.h3
6 files changed, 332 insertions, 229 deletions
diff --git a/interface/README b/interface/README
index 199cc8c..b1a1b1f 100644
--- a/interface/README
+++ b/interface/README
@@ -1,7 +1,7 @@
This files are required for compiling newlib for fool os.
-they go into this dir or similar..
+They go into this dir or similar..: ~/Downloads/newlib-foolos/newlib/libc/sys/foolos
-~/Downloads/newlib-foolos/newlib/libc/sys/foolos
+I prefer to just link them and keep here.
configure.in
Makefile.am
@@ -15,5 +15,4 @@ syscalls.c
crt0.h
crt0.s
-this should to /usr/include/sys
-fs.h -> sys/dirent.h !! required by kernel/userspace and maybe clibrary
+sys/
diff --git a/interface/fs.h b/interface/fs.h
deleted file mode 100644
index 25d4253..0000000
--- a/interface/fs.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * @file
- * abstraction layer for filesystems
- */
-
-#ifndef FOOLOS_FS
-#define FOOLOS_FS
-
-#include <stdint.h>
-
-enum FS_FILE_TYPE{
- FS_FILE_TYPE_DIR = 1,
- FS_FILE_TYPE_FILE = 2
-};
-
-typedef struct fs_dirent_struct
-{
- uint32_t mount; //mount identifier
- uint32_t inode; //inode number or similar
- uint8_t type; //FILE OR DIR (FS_FILE_TYPE)
- char name[255];
-
-}fs_dirent;
-
-/*
-typedef struct fs_dirent_struct
-{
- uint32_t inode;
- uint32_t offset;
- uint16_t length;
- uint8_t type;
- char name[256];
-}fs_dirent;
-*/
-
-#endif
diff --git a/interface/sys/dirent.h b/interface/sys/dirent.h
new file mode 100644
index 0000000..bf37746
--- /dev/null
+++ b/interface/sys/dirent.h
@@ -0,0 +1,26 @@
+#ifndef _DIRENT_H
+#define _DIRENT_H
+
+#include <stdint.h>
+
+enum FS_FILE_TYPE
+{
+ FS_FILE_TYPE_DIR = 1,
+ FS_FILE_TYPE_FILE = 2
+};
+
+struct dirent
+{
+ uint32_t d_ino;
+ char d_name[255];
+
+ // rest is optional
+ uint8_t type; //FILE OR DIR (FS_FILE_TYPE)
+
+ int pos; // position of last read!
+ char dirname[255]; // directory name we are traversing TODO: use inode here or similar for other systems!
+};
+
+typedef struct dirent DIR;
+
+#endif
diff --git a/interface/sys/termios.h b/interface/sys/termios.h
new file mode 100644
index 0000000..84ffd8c
--- /dev/null
+++ b/interface/sys/termios.h
@@ -0,0 +1,144 @@
+// https://code.woboq.org/gcc/include/bits/termios.h.html
+
+#define NCCS 32
+
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+typedef unsigned int tcflag_t;
+
+struct termios
+{
+ tcflag_t c_iflag; /* input mode flags */
+ tcflag_t c_oflag; /* output mode flags */
+ tcflag_t c_cflag; /* control mode flags */
+ tcflag_t c_lflag; /* local mode flags */
+ cc_t c_cc[NCCS]; /* control characters */
+
+ cc_t c_line; /* line discipline ?? */
+ speed_t c_ispeed; /* input speed */
+ speed_t c_ospeed; /* output speed */
+};
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK 0000020
+#define ISTRIP 0000040
+#define INLCR 0000100
+#define IGNCR 0000200
+#define ICRNL 0000400
+#define IUCLC 0001000
+#define IXON 0002000
+#define IXANY 0004000
+#define IXOFF 0010000
+#define IMAXBEL 0020000
+#define IUTF8 0040000
+
+/* c_oflag bits */
+#define OPOST 0000001
+#define OLCUC 0000002
+#define ONLCR 0000004
+#define OCRNL 0000010
+#define ONOCR 0000020
+#define ONLRET 0000040
+#define OFILL 0000100
+#define OFDEL 0000200
+
+#define VTDLY 0040000
+#define VT0 0000000
+#define VT1 0040000
+
+/* c_cflag bit meaning */
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+
+#define CSIZE 0000060
+#define CS5 0000000
+#define CS6 0000020
+#define CS7 0000040
+#define CS8 0000060
+#define CSTOPB 0000100
+#define CREAD 0000200
+#define PARENB 0000400
+#define PARODD 0001000
+#define HUPCL 0002000
+#define CLOCAL 0004000
+
+#define B57600 0010001
+#define B115200 0010002
+#define B230400 0010003
+#define B460800 0010004
+#define B500000 0010005
+#define B576000 0010006
+#define B921600 0010007
+#define B1000000 0010010
+#define B1152000 0010011
+#define B1500000 0010012
+#define B2000000 0010013
+#define B2500000 0010014
+#define B3000000 0010015
+#define B3500000 0010016
+#define B4000000 0010017
+#define __MAX_BAUD B4000000
+
+/* c_lflag bits */
+#define ISIG 0000001
+#define ICANON 0000002
+#define ECHO 0000010
+#define ECHOE 0000020
+#define ECHOK 0000040
+#define ECHONL 0000100
+#define NOFLSH 0000200
+#define TOSTOP 0000400
+#define IEXTEN 0100000
+
+/* tcflow() and TCXONC use these */
+#define TCOOFF 0
+#define TCOON 1
+#define TCIOFF 2
+#define TCION 3
+
+/* tcflush() and TCFLSH use these */
+#define TCIFLUSH 0
+#define TCOFLUSH 1
+#define TCIOFLUSH 2
+
+/* tcsetattr uses these */
+#define TCSANOW 0
+#define TCSADRAIN 1
+#define TCSAFLUSH 2
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);
+*/
diff --git a/interface/syscalls.h b/interface/syscalls.h
index 1595c2d..604e150 100644
--- a/interface/syscalls.h
+++ b/interface/syscalls.h
@@ -28,5 +28,6 @@
#define SYSCALL_SELECT 89
#define SYSCALL_TCGETATTR 90
#define SYSCALL_TCSETATTR 91
+#define SYSCALL_OPENDIR 92
-#define SYSCALL_UNIMPLEMENTED 255
+#define SYSCALL_UNIMPLEMENTED 200