summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-18 00:14:14 +0200
committerMiguel <m.i@gmx.at>2018-08-18 00:14:14 +0200
commit17fd357bad5f6c3362cfdab1d807aa463c69a4e9 (patch)
tree5baff9fcdbe52f122ec11042f119a4855001a733 /kernel
parentc15925a24efe14f437d8a2699500241a58fdc8f9 (diff)
going for fifo switch
Diffstat (limited to 'kernel')
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/fifo.c1
-rw-r--r--kernel/syscalls.c29
3 files changed, 25 insertions, 7 deletions
diff --git a/kernel/config.h b/kernel/config.h
index 2d64db1..9297a99 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -10,6 +10,8 @@
#define KERNEL_VERSION "FoolOS 0.3.2"
#define FIFO_MAX_RINGBUFFERS 20
+#define MAX_FIFOS 20
+#define MAX_FD 20
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
diff --git a/kernel/fifo.c b/kernel/fifo.c
index eb477be..8eb2273 100644
--- a/kernel/fifo.c
+++ b/kernel/fifo.c
@@ -32,6 +32,7 @@ fifo fifo_create_buffered(uint8_t size)
fifo f;
fifo_ringbuffers[ringbuffer_c]=ringbuffer_init(size);
f.data=&fifo_ringbuffers[ringbuffer_c];
+ ringbuffer_c++;
f.put=ringbuffer_put;
f.get=ringbuffer_get;
f.has=ringbuffer_has;
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 9f10d20..621880a 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -5,6 +5,8 @@
#include "fs/ext2.h"
#include "kernel/kernel.h"
#include "kernel/config.h"
+#include "fifo.h"
+#include "fd.h"
#include <sys/stat.h>
#include <sys/time.h>
#include <stdbool.h>
@@ -13,6 +15,12 @@
// TODO: use includes!!!
uint64_t timer_get_ms();
+static fd fds[MAX_FD];
+static uint32_t next_fd=0;
+
+static fifo fifos[MAX_FIFOS];
+static uint32_t next_fifo=0;
+
int syscall_unhandled(int nr)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr);
@@ -77,6 +85,8 @@ int syscall_read(int file, char *buf, int len)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len);
#endif
+ // file 1 = stdin , file 2 = stdout
+
// stdin TODO: other descroptiors!
if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall: read (only stdin)");
@@ -225,16 +235,22 @@ int syscall_execve(char *name, char **argv, char **env)
// this is never reached!
}
-
// TODO: support other files too (not only fifo 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
- //panic(FOOLOS_MODULE_NAME,"unhandled syscall: open");
-}
+ if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)panic(FOOLOS_MODULE_NAME,"we ran out of fd's or fifo's");
+
+ fifos[next_fifo]=fifo_create_buffered(1);
+ fds[next_fd]=fd_from_fifo(&fifos[next_fifo]);
+ next_fifo++;
+ next_fd++;
+
+ return next_fd-1;
+}
//newcomers
//
@@ -244,9 +260,9 @@ int syscall_close(int file,int none1,int none2)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"close (file=%d)", file);
#endif
- if(file!=0&&file!=1&&file!=2)
- panic(FOOLOS_MODULE_NAME,"unhandled syscall: close");
-
+ //if(file!=0&&file!=1&&file!=2)
+ // panic(FOOLOS_MODULE_NAME,"unhandled syscall: close");
+
return -1;
}
@@ -278,7 +294,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
return oldalloc;
}
-
// stat, fstat, lstat
int syscall_stat(const char *path, struct stat *st,int none)
{