summaryrefslogtreecommitdiff
path: root/interface
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-10-14 23:08:07 +0200
committerMiguel <m.i@gmx.at>2018-10-14 23:08:07 +0200
commitf35d2124c36f8d39a953b76620e081b79c2faffd (patch)
tree216e3a75841acc69672bf5640cc2f86e93e1ba37 /interface
parent2a6690e9fd53a02613796764248006e06ac482d6 (diff)
moved newlib specific stuff and similar into ./interface/
Diffstat (limited to 'interface')
-rw-r--r--interface/README19
-rw-r--r--interface/crt0.s8
-rw-r--r--interface/fs.h4
-rw-r--r--interface/syscall.h2
-rw-r--r--interface/syscalls.c63
-rw-r--r--interface/syscalls.h2
6 files changed, 63 insertions, 35 deletions
diff --git a/interface/README b/interface/README
new file mode 100644
index 0000000..199cc8c
--- /dev/null
+++ b/interface/README
@@ -0,0 +1,19 @@
+This files are required for compiling newlib for fool os.
+they go into this dir or similar..
+
+~/Downloads/newlib-foolos/newlib/libc/sys/foolos
+
+configure.in
+Makefile.am
+
+syscall.h
+syscall.s
+
+syscalls.h
+syscalls.c
+
+crt0.h
+crt0.s
+
+this should to /usr/include/sys
+fs.h -> sys/dirent.h !! required by kernel/userspace and maybe clibrary
diff --git a/interface/crt0.s b/interface/crt0.s
index 935e5bd..337d51b 100644
--- a/interface/crt0.s
+++ b/interface/crt0.s
@@ -79,9 +79,12 @@ call main
and $-16,%esp
sub $4,%esp
-push %eax
+push %eax // preserve main return value
+
call _fini //desctructors from .dtors
+call _flushing // force stdout flushin
+
// pop programmm return value
pop %eax
@@ -89,9 +92,6 @@ pop %eax
and $-16,%esp
sub $4,%esp
-push stdout
-call fflush
-
# push exit code and pass to _exit syscall
push %eax
call exit
diff --git a/interface/fs.h b/interface/fs.h
index a6168ae..25d4253 100644
--- a/interface/fs.h
+++ b/interface/fs.h
@@ -13,7 +13,6 @@ enum FS_FILE_TYPE{
FS_FILE_TYPE_FILE = 2
};
-/*
typedef struct fs_dirent_struct
{
uint32_t mount; //mount identifier
@@ -22,8 +21,8 @@ typedef struct fs_dirent_struct
char name[255];
}fs_dirent;
-*/
+/*
typedef struct fs_dirent_struct
{
uint32_t inode;
@@ -32,5 +31,6 @@ typedef struct fs_dirent_struct
uint8_t type;
char name[256];
}fs_dirent;
+*/
#endif
diff --git a/interface/syscall.h b/interface/syscall.h
index 43a06fd..2cadce4 100644
--- a/interface/syscall.h
+++ b/interface/syscall.h
@@ -1,7 +1,7 @@
/*
* Issue a System Call from Ring 3 / User Space
*
- * Syscalls Have up to 3 parameters. Unused Parameters are just ignored.
+ * Accepts up to 3 parameters.
* Check syscalls.h for details.
*/
diff --git a/interface/syscalls.c b/interface/syscalls.c
index 7d12002..06846bb 100644
--- a/interface/syscalls.c
+++ b/interface/syscalls.c
@@ -1,3 +1,5 @@
+#include "syscalls.h"
+
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -7,8 +9,9 @@
#include <sys/stat.h>
#include <sys/termios.h>
-#include "fs.h"
-#include "syscalls.h"
+#include <errno.h>
+
+// BASICS //
// everybody is root
uid_t getuid(void)
@@ -27,6 +30,20 @@ void sync(void)
{
}
+// set working directory - we simply save this in PWD environment var
+int chdir(const char *path)
+{
+ sprintf(buf,"PWD=%s",path);
+ putenv(buf);
+ return 0; // assume success
+}
+
+// get working dir (see chdir)
+char* getwd(char *buf)
+{
+ return getenv("PWD");
+}
+
// C NEWLIB //
// first of all we have a few posix syscalls required by newlib
@@ -202,7 +219,7 @@ int write(int file, char *ptr, int len)
//////////////////////////////////////////////////////////////////////
-int _readdir(const char *name,fs_dirent *dirs,int max)
+int _readdir(const char *name,void *dirs,int max)
{
return syscall(SYSCALL_READDIR,name,dirs,max);
}
@@ -222,23 +239,16 @@ int _lstat(const char *file, struct stat *st)
return syscall(SYSCALL_LSTAT,file,st,0);
}
-// EXTRA STUFF
-
- static struct termios tty1; // only one global terminal managed here... more might/should follow
- //TODO : implement this properly
+// termios
- int tcgetattr(int fd, struct termios *termios_p)
+ int tcgetattr(int fd, struct termios *termios_p)
{
- syscall(SYSCALL_UNIMPLEMENTED,"tcgetattr",0,0);
- *termios_p=tty1;
- return 0;
+ return syscall(SYSCALL_TCGETATTR,fd,termios_p,0);
}
int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
{
- syscall(SYSCALL_UNIMPLEMENTED,"tcsetattr",0,0);
- tty1=*termios_p;
- return 0;
+ return syscall(SYSCALL_TCSETATTR,fd,termios_p,0);
}
/*
@@ -302,15 +312,6 @@ int _lstat(const char *file, struct stat *st)
return syscall(SYSCALL_UNIMPLEMENTED,"mkdir",0,0);
}
- int chdir(const char *path)
- {
- return syscall(SYSCALL_UNIMPLEMENTED,"chdir",0,0);
- }
-
- char* getwd(char *buf)
- {
- return syscall(SYSCALL_UNIMPLEMENTED,"getwd",0,0);
- }
char *ttyname(int fd)
{
@@ -319,14 +320,15 @@ int _lstat(const char *file, struct stat *st)
//
- struct dirent *readdir(DIR *dirp)
+ struct void *readdir(DIR *dirp) // returns dirent
{
return syscall(SYSCALL_UNIMPLEMENTED,"readdir",0,0);
}
DIR *opendir(const char *name)
{
- return syscall(SYSCALL_UNIMPLEMENTED,"opendir",0,0);
+ errno=EACCES;
+ return syscall(SYSCALL_UNIMPLEMENTED,"opendir",name,0);
}
int closedir(DIR *dirp)
@@ -432,8 +434,7 @@ int gethostname(char *name, size_t len)
ssize_t readlink(const char *pathname, char *buf, size_t bufsiz)
{
- syscall(SYSCALL_UNIMPLEMENTED,"readlink",0,0);
- return 0;
+ return syscall(SYSCALL_UNIMPLEMENTED,"readlink",pathname,0);
}
int rmdir(const char *pathname)
@@ -468,7 +469,7 @@ int execvp(const char *file, char *const argv[])
long sysconf(int name)
{
- syscall(SYSCALL_UNIMPLEMENTED,"sysconf",0,0);
+ return syscall(SYSCALL_UNIMPLEMENTED,"sysconf",name,0);
return 0;
}
@@ -477,3 +478,9 @@ int chmod(const char *pathname, mode_t mode)
syscall(SYSCALL_UNIMPLEMENTED,"chmod",0,0);
return 0;
}
+
+void _flushing()
+{
+ fflush(stdout);
+}
+
diff --git a/interface/syscalls.h b/interface/syscalls.h
index e758fd9..1595c2d 100644
--- a/interface/syscalls.h
+++ b/interface/syscalls.h
@@ -26,5 +26,7 @@
#define SYSCALL_GUI_RECT 87
#define SYSCALL_GUI_WIN 88
#define SYSCALL_SELECT 89
+#define SYSCALL_TCGETATTR 90
+#define SYSCALL_TCSETATTR 91
#define SYSCALL_UNIMPLEMENTED 255