diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-11-20 04:51:23 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-11-20 04:51:23 +0100 |
| commit | 1acde03a7c0f85aca9919e374e3df6cee6f0bd08 (patch) | |
| tree | 10ae84ce2693bad62e5c7376cd0c3c40a80c93df /userspace | |
| parent | bcab3c0be8ff5fe1db1fac9e01973531cc29f554 (diff) | |
workin on syscall interface etc..
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/Makefile | 6 | ||||
| -rw-r--r-- | userspace/add.c | 1 | ||||
| -rw-r--r-- | userspace/brainfuck.c | 2 | ||||
| -rw-r--r-- | userspace/foolshell.c | 18 | ||||
| -rw-r--r-- | userspace/simple.c | 3 | ||||
| -rw-r--r-- | userspace/syscalls.c | 76 |
6 files changed, 44 insertions, 62 deletions
diff --git a/userspace/Makefile b/userspace/Makefile index d54bfa8..564ffe0 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -3,12 +3,10 @@ CC=i686-elf-gcc LD=i686-elf-ld -CFLAGS=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include +CFLAGS=-I.. -I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include CFLAGS+=--no-builtin-malloc CFLAGS+=--no-builtin-free -LDFLAGS=-L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/newlib/ \ - -L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/libgloss/libnosys/ \ - -lnosys +LDFLAGS=-L/home/miguel/temp/fool-os-stuff/newlib-build-clean-new/i686-elf/newlib ext2.img: shell simple brainfuck add dd if=/dev/zero of=ext2.img bs=512 count=500 diff --git a/userspace/add.c b/userspace/add.c index 17ddb64..eecb05a 100644 --- a/userspace/add.c +++ b/userspace/add.c @@ -6,7 +6,6 @@ int main(int argc, char **argv) { - syscalls_init(); FILE *input; input=fopen(1,"r"); diff --git a/userspace/brainfuck.c b/userspace/brainfuck.c index a54e4e5..f985fb9 100644 --- a/userspace/brainfuck.c +++ b/userspace/brainfuck.c @@ -37,8 +37,6 @@ void usage() { int main(int argc, char **argv) { - //added by FOOLOS - syscalls_init(); // used by the bf program unsigned char *dataptr = malloc(sizeof(char) * DATA_SIZE); diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 3fe7353..77c78dd 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -1,8 +1,11 @@ #include <stdio.h> +#include <assert.h> #include <string.h> #include "syscalls.c" #include "../fs/fs.h" +char **environ; + void hello() { puts( "Welcome to FoolShell v0.1" @@ -17,7 +20,6 @@ void prompt() { int main(int argc, char **argv) { - syscalls_init(); hello(); FILE *input; @@ -86,7 +88,7 @@ int process(char *buf) if(!strcmp(command,"help")) { - puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', exec [inode_nr],'malloc [bytes]', 'free [address]'"); + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]'"); } else if(!strcmp(command,"ls")) { @@ -121,11 +123,23 @@ int process(char *buf) free(atoi(token[1])); printf("foolshell: called free(%08x).\n",atoi(token[1])); } + else if(!strcmp(command,"getenv")) + { + printf("foolshell: %s = %s \n",token[1],getenv(token[1])); + } + else if(!strcmp(command,"putenv")) + { + char buf[256]; + sprintf(buf,"%s=%s",token[1],token[2]); + putenv(buf); + printf("foolshell: %s = %s \n",token[1],getenv(token[1])); + } else { puts("foolshell: command not found"); } + // } diff --git a/userspace/simple.c b/userspace/simple.c index 36f0580..59bd4f1 100644 --- a/userspace/simple.c +++ b/userspace/simple.c @@ -2,12 +2,11 @@ int main(int argc, char **argv) { - syscalls_init(); - int i; for(i=0;i<10;i++) { + write(1,"dupa\n",5); } diff --git a/userspace/syscalls.c b/userspace/syscalls.c index b5959eb..7471418 100644 --- a/userspace/syscalls.c +++ b/userspace/syscalls.c @@ -1,20 +1,17 @@ -//printf needs following syscalls: sbrk write close fstat isatty lseek read -// - #include <sys/stat.h> #include <string.h> #include <stdint.h> -#include "../fs/fs.h" +#include "../kernel/syscalls.h" -static int preread; -static int alloc; -easywrite(char *c); +/* +char *__env1[]={0}; +char *__env2[]={"dupa","test"}; +char **environ={__env1,__env2}; +*/ -// init syscalls -void syscalls_init() +void _exit(int ret) { - // TODO dynamic! - alloc=0x300000; +while(1); } // generic syscall interface! @@ -43,85 +40,62 @@ int syscall(int call, int p1, int p2, int p3) return ebx; } -// int close(int file) { - return -1; + return syscall(SYSCALL_CLOSE,file,0,0); } int fstat(int file, struct stat *st) { - st->st_mode = S_IFCHR; - return 0; + return syscall(SYSCALL_FSTAT,file,st,0); } int isatty(int file) { - return 1; + return syscall(SYSCALL_ISATTY,file,0,0); } int lseek(int file, int ptr, int dir) { - if(dir==0)preread=ptr; - else{ puts("other modes unsupported sorry"); while(1);} - return preread; + return syscall(SYSCALL_LSEEK,file,ptr,dir); } int read(int file, char *ptr, int len) { - return syscall(62,file,ptr,len); + + return syscall(SYSCALL_READ,file,ptr,len); } int readdir(const char *name,fs_dirent *dirs,int max) { - return syscall(63,name,dirs,max); + return syscall(SYSCALL_READDIR,name,dirs,max); } int open(const char *name, int flags, int mode) { - return name; + return syscall(SYSCALL_OPEN,name,flags,mode); } int write(int file, char *ptr, int len) { - return syscall(61,file,ptr,len); + return syscall(SYSCALL_WRITE,file,ptr,len); } int execve(char *name, char **argv, char **env) { - - return syscall(64,name,argv,env); + return syscall(SYSCALL_EXECVE,name,argv,env); } - caddr_t sbrk(int incr) { -// easywrite("syscall: sbrk!!\n"); - 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; - */ + static int alloc=0x300000; // TODO: implement properly sbrk!!! + int oldalloc=alloc; + alloc+=incr; + return oldalloc; + + return syscall(SYSCALL_SBRK,incr,0,0); } -// + |
