summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--fs/fd.c58
-rw-r--r--fs/fd.h1
-rw-r--r--fs/pipe.c4
-rw-r--r--kernel/syscalls.c32
-rw-r--r--kernel/syscalls.h3
-rw-r--r--userspace/fd.c3
-rw-r--r--userspace/newcalls.h (renamed from userspace/snake2.h)5
-rw-r--r--userspace/piper.c48
-rw-r--r--userspace/snake2.c2
10 files changed, 110 insertions, 51 deletions
diff --git a/README.md b/README.md
index 8b39ab2..74a9b53 100644
--- a/README.md
+++ b/README.md
@@ -87,6 +87,11 @@ Todos
-----
+* duplicate fds on fork
+* dup2 syscall
+* pipes
+* threads! semaphores
+
* Newlib errno / return value / argv / env
* pipe\_syscall / execve: support hashbangs
* DMA where possible!
diff --git a/fs/fd.c b/fs/fd.c
index fe34003..1936f37 100644
--- a/fs/fd.c
+++ b/fs/fd.c
@@ -149,25 +149,57 @@ fd fd_from_fifo(fifo* fif)
return f;
}
-fd fd_from_pipe()
+uint8_t pipe_get(uint32_t *data)
{
- fd f;
- f.type=FD_TYPE_PIPE;
- f.data=kballoc(1);
+ return ringbuffer_get(data);
+}
+
+void pipe_put(void* data,uint8_t b)
+{
+ ringbuffer_put(data,b);
+}
+
+bool pipe_has(uint32_t *data)
+{
+ return ringbuffer_has(data);
+}
+
+bool pipe_eof(uint32_t *data)
+{
+ return 0;
+}
+
+int fds_from_pipe(fd pipefds[2])
+{
+ fd read;
+ fd wrt;
+
+ read.type=FD_TYPE_PIPE;
+ wrt.type=FD_TYPE_PIPE;
+
+ read.data=kballoc(1);
+ wrt.data=read.type;
+
ringbuffer r=ringbuffer_init(1);
- memcpy(f.data,&r,sizeof(ringbuffer));
+ memcpy(read.data,&r,sizeof(ringbuffer));
+
+ read.read=pipe_get;
+ wrt.write=pipe_put;
- /*
- f.read=sysfs_get;
- f.write=0;
- f.has=sysfs_has;
- f.eof=sysfs_eof;
- */
+ read.has=pipe_has;
+ wrt.has=pipe_has;
- f.close=pipe_close;
+ read.eof=pipe_eof;
+ wrt.eof=pipe_eof;
+
+ read.close=0;
+ wrt.close=0;
+
+ pipefds[0]=read;
+ pipefds[1]=wrt;
- return f;
+ return 0;
}
fd fd_from_path(char* path)
diff --git a/fs/fd.h b/fs/fd.h
index c9b7fd8..64a53ed 100644
--- a/fs/fd.h
+++ b/fs/fd.h
@@ -38,5 +38,6 @@ bool fd_close(fd*);
fd fd_from_fifo(fifo* f);
fd fd_from_path(char *path);
fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...)),void(*h)(uint32_t in));
+int fds_from_pipe(fd pipefds[2]);
#endif
diff --git a/fs/pipe.c b/fs/pipe.c
index cbba7a9..3802851 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -5,8 +5,10 @@
#include "lib/string/string.h"
-/* mount interface */
+#define MAX_PIPES 100
+
+/* mount interface */
fd pipe_file_open(mount *m,char *path)
{
fd a;
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 3b599c0..b5dd6df 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -21,6 +21,7 @@
#include "reent.h"
#include "errno.h"
+/** errno helper */
void set_errno(int no)
{
struct _reent *impure_ptr=VMEM_USER_NEWLIB;
@@ -85,9 +86,9 @@ char* syscall_get_name(uint32_t num)
case 73:
return "SYSCALL_KILL";
case 80:
- return "SYSCALL_POLL";
- case 83:
return "SYSCALL_CLONE";
+ case 84:
+ return "SYSCALL_PIPE";
}
return "UNKNOWN SYSCALL NUM";
}
@@ -392,6 +393,27 @@ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3,
return 1;
}
+uint32_t syscall_pipe(uint32_t *addr)
+{
+ if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)kpanic("we ran out of fd's or fifo's");
+ fd pipfds[2];
+ int ret=fds_from_pipe(pipfds);
+
+ fds[next_fd]=pipfds[0] ;
+ *addr=next_fd;
+ addr++;
+
+ next_fd++;
+ if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)kpanic("we ran out of fd's or fifo's");
+
+ fds[next_fd]=pipfds[1] ;
+ *addr=next_fd;
+ next_fd++;
+
+ return ret;
+
+}
+
uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid)
{
switch(nr){
@@ -444,8 +466,8 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint
case SYSCALL_KILL :
// return task_kill(p1,p2,p3);
return -1;
- case SYSCALL_POLL :
- return syscall_poll(p1);
+ case SYSCALL_PIPE :
+ return syscall_pipe(p1);
}
- return -1;
+ kpanic("unknown syscall");
}
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index b736519..b7422af 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -23,7 +23,8 @@
#define SYSCALL_KILL 73
#define SYSCALL_POLL 80 //shit!?
#define SYSCALL_CLONE 83
-#define SYSCALL_PIPE 84 // TODO! unnamed and named pipes (fifos) SYSCALL_MKNOD
+#define SYSCALL_PIPE 84
+// TODO! SYSCALL_MKNOD?
char* syscall_get_name(uint32_t num);
uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid);
diff --git a/userspace/fd.c b/userspace/fd.c
index 09cb28e..80ffd20 100644
--- a/userspace/fd.c
+++ b/userspace/fd.c
@@ -3,7 +3,6 @@
int main()
{
- dup(stdout);
+// dup(stdout);
printf("dup\n");
-
}
diff --git a/userspace/snake2.h b/userspace/newcalls.h
index d4c47a8..9bc55a5 100644
--- a/userspace/snake2.h
+++ b/userspace/newcalls.h
@@ -2,9 +2,14 @@
// this syscall will be moved to newlib later!
#define SYSCALL_CLONE 83
+#define SYSCALL_PIPE 84
int _clone(void)
{
return syscall(SYSCALL_CLONE,0,0,0);
}
+int _pipe(uint32_t fds[2])
+{
+ return syscall(SYSCALL_PIPE,fds,0,0);
+}
//
diff --git a/userspace/piper.c b/userspace/piper.c
index 73b9516..e433a5c 100644
--- a/userspace/piper.c
+++ b/userspace/piper.c
@@ -1,42 +1,34 @@
#include <stdio.h>
+#include "newcalls.h"
int main()
{
- setvbuf(stdout,NULL,_IONBF,0);
- /*
- FILE *f=fopen("~testpipe","rw");
+ int fds[2];
+ _pipe(fds);
+
+ printf("opened pipe / in fd=%d,out fd=%d\n",fds[0],fds[1]);
int pid=_fork();
- if(pid==0)
+ if(pid)
{
- char buf[2];
- fread(buf,1,1,f);
- printf("[%c]\n",buf[0]);
- while(1);
- }
+ while(1) // read forever from our pipe and echo to stdout
+ {
+ char buf[256];
+ int len=fread(buf,1,255,fds[0]);
+ printf("%s",buf);
+ }
- else
- {
- char buf[]="666";
- fwrite(buf,1,1,f);
- printf("written\n");
- while(1);
}
- */
- int f=_open("~testpipe","RW");
- int pid=_fork();
- if(pid==0)
- {
- char buf[2];
- while(_read(f,buf,1))printf("%c",buf[0]);
- }
-
else
{
- char buf[]="666 the number of the beast";
- _write(f,buf,27);
- printf("written\n");
+
+ // write to our pipe
+ fwrite("Hello\n",1,6,fds[1]);
+ fwrite("Bello\n",1,6,fds[1]);
+ fwrite("Gello\n",1,6,fds[1]);
+
+ // hang forever
+ while(1);
}
-
}
diff --git a/userspace/snake2.c b/userspace/snake2.c
index 3b179ac..6fbd092 100644
--- a/userspace/snake2.c
+++ b/userspace/snake2.c
@@ -1,5 +1,5 @@
#include <stdio.h>
-#include "snake2.h"
+#include "newcalls.h"
static char lastc='d';