diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-11-20 20:24:18 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-11-20 20:24:18 +0100 |
| commit | 1a6da07e9a6ef7661a58cb6ce22b2874370d6c0d (patch) | |
| tree | 9d13767cfce0fc0c9f78aed42385533673065e98 | |
| parent | 1acde03a7c0f85aca9919e374e3df6cee6f0bd08 (diff) | |
experimenting wih userspace and syscalls
| -rw-r--r-- | userspace/add.c | 42 | ||||
| -rw-r--r-- | userspace/brainfuck.c | 2 | ||||
| -rw-r--r-- | userspace/foolshell.c | 10 | ||||
| -rw-r--r-- | userspace/simple.c | 5 | ||||
| -rw-r--r-- | userspace/syscalls.c | 17 |
5 files changed, 50 insertions, 26 deletions
diff --git a/userspace/add.c b/userspace/add.c index eecb05a..8f1dc56 100644 --- a/userspace/add.c +++ b/userspace/add.c @@ -3,29 +3,59 @@ #include "syscalls.c" #include "../fs/fs.h" - int main(int argc, char **argv) { - FILE *input; - input=fopen(1,"r"); - char *buf=malloc(256); + sbrk(1024); + sbrk(1024); + sbrk(1024); + write(1,"dupa",4); + puts("started ADD"); + while(1); +// FILE *input; +// input=fopen("input2.txt","r"); //stdin +/* int sum=0; int i=0; + while(1); + + char *buf=malloc(256); + //printf("(buf= 0x%08X)\n",buf); + + + + while(1) + { + char *ret=gets(buf); + if(ret==NULL) + { + printf("returned NULL. ABORTING"); + break; + } + printf("entered %s: ",buf); + + //buf[strlen(buf)-1]=0; // remove \n + //process(buf); + } + + + while(1) { printf("enter numer %i: ",i+1); fgets(buf,255,input); + printf("entered %s: ",buf); + if(buf[1]=='x')break; + i++; sum+=atoi(buf); - } - printf("sum = %i \n",sum); printf("avg = %i \n\n",sum/i); +*/ execve(15,0,0); } diff --git a/userspace/brainfuck.c b/userspace/brainfuck.c index f985fb9..fdabb3c 100644 --- a/userspace/brainfuck.c +++ b/userspace/brainfuck.c @@ -75,7 +75,7 @@ int main(int argc, char **argv) */ // added by FOOLOS - input=fopen(1,"r"); + input=fopen("input.txt","r"); char *buf=malloc(256); puts("\n\nbrainfuck: Welcome to the BRAINFUCK INTERPRETER by Felix Oghina"); puts("brainfuck: Licensed under the (brain)fuck licenses!"); diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 77c78dd..36912c8 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -4,8 +4,6 @@ #include "syscalls.c" #include "../fs/fs.h" -char **environ; - void hello() { puts( "Welcome to FoolShell v0.1" @@ -23,7 +21,7 @@ int main(int argc, char **argv) hello(); FILE *input; - input=fopen(1,"r"); + input=fopen("input.txt","r"); char *buf=malloc(256); while(1) @@ -88,7 +86,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]', 'getenv [var]'"); + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'"); } else if(!strcmp(command,"ls")) { @@ -116,12 +114,12 @@ int process(char *buf) else if(!strcmp(command,"malloc")) { uint8_t *mall=malloc(atoi(token[1])); - printf("foolshell: allocated %d bytes at 0x%8x (%i).\n",atoi(token[1]),mall,mall); + printf("foolshell: allocated %d bytes at 0x%08X (%i).\n",atoi(token[1]),mall,mall); } else if(!strcmp(command,"free")) { free(atoi(token[1])); - printf("foolshell: called free(%08x).\n",atoi(token[1])); + printf("foolshell: called free(0x%08X).\n",atoi(token[1])); } else if(!strcmp(command,"getenv")) { diff --git a/userspace/simple.c b/userspace/simple.c index 59bd4f1..e3bca65 100644 --- a/userspace/simple.c +++ b/userspace/simple.c @@ -4,10 +4,11 @@ int main(int argc, char **argv) { int i; - for(i=0;i<10;i++) + for(i=0;i<5;i++) { - write(1,"dupa\n",5); + puts("dupa"); + } // replace with foolshell after finishing! diff --git a/userspace/syscalls.c b/userspace/syscalls.c index 7471418..fd9b5ba 100644 --- a/userspace/syscalls.c +++ b/userspace/syscalls.c @@ -4,14 +4,15 @@ #include "../kernel/syscalls.h" /* -char *__env1[]={0}; -char *__env2[]={"dupa","test"}; -char **environ={__env1,__env2}; +char *__env3[]={0}; +char *__env1[]={"a=10","b=20"}; +char *__env2[]={"dupa=test2"}; +char **environ={__env1,__env2,__env3}; */ void _exit(int ret) { -while(1); + while(1); } // generic syscall interface! @@ -87,14 +88,8 @@ int execve(char *name, char **argv, char **env) return syscall(SYSCALL_EXECVE,name,argv,env); } - -caddr_t sbrk(int incr) +uint32_t sbrk(int incr) { - static int alloc=0x300000; // TODO: implement properly sbrk!!! - int oldalloc=alloc; - alloc+=incr; - return oldalloc; - return syscall(SYSCALL_SBRK,incr,0,0); } |
