summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/config.h1
-rw-r--r--kernel/kernel.c2
-rw-r--r--kernel/syscalls.c108
-rw-r--r--kernel/syscalls.h21
4 files changed, 130 insertions, 2 deletions
diff --git a/kernel/config.h b/kernel/config.h
index 039ced7..ef0fa71 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -10,4 +10,5 @@
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
+#define LOG_SYSCALLS
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 2f7cfc3..6058480 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -108,7 +108,7 @@ void kernel_main(uint32_t initial_stack, int mp)
//
// Activate Virtual Memory (paging)
//
- vmem_init();
+ // vmem_init();
//
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index b5a581d..1de5d3a 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -5,11 +5,20 @@
#include "fs/fs.h"
#include "fs/ext2.h"
#include "kernel/console.h"
+#include "kernel/config.h"
+#include <sys/stat.h>
-//
+static int preread;
+static int alloc=0x600000; // TODO: implement properly sbrk!!!
+
int syscall_write(int file, char *buf, int len)
{
+
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"write(file=%d, buf=0x%08X, len=%d)", file,buf,len);
+ #endif
+
// ALL output to stdout
for(int i=0;i<len;i++)
{
@@ -22,6 +31,10 @@ int syscall_write(int file, char *buf, int len)
int syscall_read(int file, char *buf, int len)
{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len);
+ #endif
+
// stdin
if(file==1)
{
@@ -48,14 +61,107 @@ int syscall_read(int file, char *buf, int len)
int syscall_readdir(const char *name,fs_dirent *dirs,int max)
{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"readdir(name=0x%08X, dirs=0x%08X, %d)", name,dirs,max);
+ #endif
+
return fs_readdir(name,dirs,max);
}
int syscall_execve(char *name, char **argv, char **env)
{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X, argvs=0x%08X, env=0x%08X)", name,argv,env);
+ #endif
+
ext2_inode_content(EXT2_RAM_ADDRESS,name,0x800000,0x100000);
// autorun "user-space" prog
asm("push $0x800000");
asm("ret");
}
+
+int syscall_open(char *name, int flags, int len)
+{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"open (name=0x%08X, flags=%d, len=%d)", name,flags,len);
+ #endif
+
+ return 1;
+
+}
+
+//newcomers
+//
+int syscall_close(int file,int none1,int none2)
+{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"close (file=%d)", file);
+ #endif
+
+ return -1;
+}
+
+int syscall_fstat(int file, struct stat *st,int none)
+{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fstat (file=%d,stat=0x%08X)", file,st);
+ #endif
+
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+int syscall_isatty(int file,int none1,int none2)
+{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"isatty (file=%d)", file);
+ #endif
+
+ return 1;
+}
+
+int syscall_lseek(int file,int ptr,int dir)
+{
+
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
+ #endif
+
+ if(dir==0)preread=ptr;
+ else{ while(1);}
+ return preread;
+}
+
+caddr_t syscall_sbrk(int incr, int none1, int none2)
+{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sbrk (incr=%d)", incr);
+ #endif
+
+ int oldalloc=alloc;
+ alloc+=incr;
+ return oldalloc;
+
+ /*
+
+ extern char end;
+// char _end;
+ static char *heap_end;
+ char *prev_heap_end;
+
+ if (heap_end == 0) {
+ heap_end = &end;
+ }
+ prev_heap_end = heap_end;
+
+ if (heap_end + incr > stack_ptr) {
+ write (1, "Heap and stack collision\n", 25);
+ abort ();
+ }
+
+ heap_end += incr;
+ return (caddr_t) prev_heap_end;
+ */
+}
+
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index 6569aa6..63aafc4 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -1,6 +1,27 @@
#include "fs/fs.h"
+#define SYSCALL_WRITE 61
+#define SYSCALL_READ 62
+#define SYSCALL_READDIR 63
+#define SYSCALL_EXECVE 64
+#define SYSCALL_OPEN 65
+#define SYSCALL_CLOSE 66
+#define SYSCALL_FSTAT 67
+#define SYSCALL_ISATTY 68
+#define SYSCALL_LSEEK 69
+#define SYSCALL_SBRK 70
+
+
+int syscall_open(char *name, int flags, int len);
int syscall_write(int file, char *buf, int len);
int syscall_read(int file, char *buf, int len);
int syscall_readdir(const char *name,fs_dirent *dirs,int max);
int syscall_execve(char *name, char **argv, char **env);
+
+int syscall_close(int file,int none1,int none2);
+int syscall_fstat(int file, struct stat *st,int none);
+int syscall_isatty(int file,int none1,int none2);
+int syscall_lseek(int file,int ptr,int dir);
+int syscall_sbrk(int incr, int none1, int none2);
+
+// missing: _exit, environ, fork, getpid, kill, link, stat, times, unlink, wait;