From ec0ba7bc40854eab6a1cdb41364f41f9c11407e1 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Sun, 23 Nov 2014 23:26:26 +0100 Subject: foolshell and syscalls improvememets --- userspace/Makefile | 16 ++--- userspace/foolshell.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++ userspace/ls.c | 8 ++- userspace/shell.c | 158 -------------------------------------------------- 4 files changed, 167 insertions(+), 166 deletions(-) create mode 100644 userspace/foolshell.c delete mode 100644 userspace/shell.c (limited to 'userspace') diff --git a/userspace/Makefile b/userspace/Makefile index 55e78bc..3327375 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -4,7 +4,7 @@ CFLAGS= CFLAGS+=-w CFLAGS+=-std=gnu11 -PROGS=shell simple brainfuck add checker ls clear +PROGS=foolshell simple brainfuck add checker ls clear ext2.img: $(PROGS) dd if=/dev/zero of=ext2.img bs=512 count=5000 @@ -12,17 +12,19 @@ ext2.img: $(PROGS) mkdir mnt sudo mount ext2.img mnt sudo chown miguel mnt - mkdir mnt/miguel - echo "hello one" > mnt/miguel/test1.txt - echo "hello two" > mnt/test2.txt - cp $^ mnt - cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt + mkdir -p mnt/home/miguel + echo "hello one" > mnt/home/miguel/test1.txt + mkdir -p mnt/bin + cp $^ mnt/bin + cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin + mkdir -p mnt/etc + echo "127.0.0.1 localhost" > mnt/etc/hosts sync sudo umount mnt rm mnt -rf brainfuck: brainfuck.o -shell: shell.o +foolshell: foolshell.o simple: simple.o add: add.o checker: checker.o diff --git a/userspace/foolshell.c b/userspace/foolshell.c new file mode 100644 index 0000000..819c5d6 --- /dev/null +++ b/userspace/foolshell.c @@ -0,0 +1,151 @@ +#include +#include +#include +#include + +// +void hello() +{ + // ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS + puts( + + " ______ __ ____ _____ \n" + " / ____/___ ____ / / / __ \\/ ___/ \n" + " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n" + " / __/ / /_/ / /_/ / / / /_/ /___/ / \n" + " /_/ \\____/\\____/_/ \\____//____/ \n" + " \n" + "Welcome to FoolShell v0.2 (Compiled on " __DATE__ " at " __TIME__ "\n" + "--------------------------------------------------------------------\n\n" + "type 'help' anytime to show shell built-ins\n" + "or execute user programms that are in the '/bin' directory (e.g. ls)\n" + ); +} + +void prompt() +{ + printf( + "$ " + ); +} + +int main(int argc, char **argv) +{ + + bool silent=false; + for(int i=0;i\n",c, token[c]); + c++; + token[c]=NULL; + + } + + return token; + +} + +int process(char *buf) +{ + + char **token=tokenize(buf); + char *command=token[0]; + // puts(command); + // copied from trottelshell + + if(!strcmp(command,"help")) + { + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'"); + } + else if(!strcmp(command,"echo")) + { + printf("\"%s\"\n",token[1]); + + } + else if(!strcmp(command,"malloc")) + { + uint8_t *mall=malloc(atoi(token[1])); + printf("allocated %d bytes at 0x%08X (%i).\n",atoi(token[1]),mall,mall); + } + else if(!strcmp(command,"free")) + { + free(atoi(token[1])); + printf("called free(0x%08X).\n",atoi(token[1])); + } + else if(!strcmp(command,"getenv")) + { + printf("%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("set: %s = %s \n",token[1],getenv(token[1])); + } + else + { + execve(token[0],token,0); + char buf[256]; + sprintf(buf,"/bin/%s",token[0]); + execve(buf,token,0); + puts("foolshell: command not found"); + } + +} + + + + + diff --git a/userspace/ls.c b/userspace/ls.c index 50c733b..5b5034b 100644 --- a/userspace/ls.c +++ b/userspace/ls.c @@ -15,7 +15,13 @@ int main(int argc, char **argv) return 0; } - int ls=readdir(atoi(argv[1]),dirs,25); + char *dir=argv[1]; + int ls=readdir(dir,dirs,25); + if(ls==-1) + { + printf("%s: file or directory '%s' not found.\n",argv[0],dir); + return 0; + } int i; diff --git a/userspace/shell.c b/userspace/shell.c deleted file mode 100644 index bb8b873..0000000 --- a/userspace/shell.c +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include -#include -#include - -// ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS -// -void hello() -{ - puts( - - " ______ __ ____ _____\n" - " / ____/___ ____ / / / __ \\/ ___/\n" - " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n" - " / __/ / /_/ / /_/ / / / /_/ /___/ / \n" - " /_/ \\____/\\____/_/ \\____//____/ \n" - "\n" - - - - - - - "Welcome to FoolShell v0.2 (Compiled on " __DATE__ " at " __TIME__ "\n" - "--------------------------------------------------------------------\n\n" - "type 'help' anytime to show shell built-ins\n" - "or execute programms/commands that are on your $PATH (e.g. ls)\n" - ); -} - -void prompt() -{ - printf( - "$ " - ); -} - -int main(int argc, char **argv) -{ - - bool silent=false; - for(int i=0;i\n",c, token[c]); - c++; - token[c]=NULL; - - } - - return token; - -} - -int process(char *buf) -{ - - char **token=tokenize(buf); - char *command=token[0]; - // puts(command); - // copied from trottelshell - - if(!strcmp(command,"help")) - { - puts("foolshell: supported built-in commands: 'help', 'echo [string]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'"); - } - else if(!strcmp(command,"exec")) - { - execve(atoi(token[1]),token,0); - - } - else if(!strcmp(command,"echo")) - { - printf("\"%s\"\n",token[1]); - - } - else if(!strcmp(command,"malloc")) - { - uint8_t *mall=malloc(atoi(token[1])); - printf("allocated %d bytes at 0x%08X (%i).\n",atoi(token[1]),mall,mall); - } - else if(!strcmp(command,"free")) - { - free(atoi(token[1])); - printf("called free(0x%08X).\n",atoi(token[1])); - } - else if(!strcmp(command,"getenv")) - { - printf("%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("set: %s = %s \n",token[1],getenv(token[1])); - } - else - { - puts("foolshell: command not found"); - } - -} - - - - - -- cgit v1.2.3