From c298ca7e6beaad0bcc32af6d4cf50d41b79f13b7 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 21 Sep 2018 12:56:51 +0200 Subject: fix framebufffer/ textmode and clean userspace a little bit more --- userspace/date.c | 19 +++ userspace/fd.c | 8 -- userspace/foolshell.c | 297 -------------------------------------------- userspace/fsh.c | 320 ++++++++++++++++++++++++++++++++++++++++++++++++ userspace/init.c | 16 ++- userspace/newcalls.h | 2 +- userspace/nonl.c | 15 --- userspace/piper.c | 27 ---- userspace/simple.c | 31 ----- userspace/sysfs_write.c | 9 -- userspace/task1.c | 1 - userspace/test-math.c | 33 ----- userspace/test_env.c | 31 +++++ userspace/test_math.c | 33 +++++ userspace/test_sysfs.c | 9 ++ 15 files changed, 420 insertions(+), 431 deletions(-) create mode 100644 userspace/date.c delete mode 100644 userspace/fd.c delete mode 100644 userspace/foolshell.c create mode 100644 userspace/fsh.c delete mode 100644 userspace/nonl.c delete mode 100644 userspace/piper.c delete mode 100644 userspace/simple.c delete mode 100644 userspace/sysfs_write.c delete mode 100644 userspace/test-math.c create mode 100644 userspace/test_env.c create mode 100644 userspace/test_math.c create mode 100644 userspace/test_sysfs.c (limited to 'userspace') diff --git a/userspace/date.c b/userspace/date.c new file mode 100644 index 0000000..64b8dfc --- /dev/null +++ b/userspace/date.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + time_t ltime; + time(<ime); + printf("%s", ctime(<ime)); + return 0; +} + + + + + diff --git a/userspace/fd.c b/userspace/fd.c deleted file mode 100644 index 80ffd20..0000000 --- a/userspace/fd.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int main() -{ -// dup(stdout); - printf("dup\n"); -} diff --git a/userspace/foolshell.c b/userspace/foolshell.c deleted file mode 100644 index 4d011da..0000000 --- a/userspace/foolshell.c +++ /dev/null @@ -1,297 +0,0 @@ -/** - * @file - * - * Fool's Shell - * ========= - * - * A minimalsitic and naive shell developed along the Fool OS kernel. - * TODO: Free tokenizer / dynamic size! - */ - -#include -#include -#include -#include -#include -#include - - -#include "newcalls.h" - -extern char **environ; - -bool process(char *buf); -bool metaprocess(char *buf); -bool cd(char *path); - -void version() -{ - puts("Fool's Shell version git-commit:" GIT_REVISION "\ncompiled on " __DATE__ " at " __TIME__); -} -void help() -{ - puts( "\nfoolshell: supported built-in commands/functions:\n\n" - - "'env' - show all environment variables\n" - "'getenv [var]' - show environment variable\n" - "'setenv [var] [val]' - set environemnet variable\n" - - "'cd [dir]' - change directory (set $PWD)\n" - "'[binary] [params...]' - run a binary\n" - "'[binary] [params...] &' - run a binary in background\n" - " TODO - pipes\n" - - "'help' - show this message\n" - "'exit' - exit running foolshell\n\n"); - -} - -void prompt() -{ - printf("\033[36mfool\033[37m@\033[32mhill\033[33m:%s%s\033[37m",getenv("PWD"),getenv("PS1")); -} - -int main(int argc, char **argv) -{ - for(int i=0;i\n",c, token[c]); - c++; - token[c]=NULL; - - } - return token; -} - -bool metaprocess2(char *buf); -bool metaprocess(char *buf) -{ - char **token=tokenize(buf,'|'); - if(token[0]==0 || token[1]==0)return process(buf); // no pipes - - int pid=_fork(); - - if(pid==0) - { - metaprocess2(buf); - exit(1); - } - - _wait(pid); - return true; -} - -bool metaprocess2(char *buf) -{ - char **token=tokenize(buf,'|'); - if(token[0]==0 || token[1]==0)return process(buf); // no pipes - - int fds[2]; - _pipe(fds); - - int pid=_fork(); - - if(pid==0) - { - // first child shall write to the pipe - _close(fds[0]); - _dup2(fds[1],1); // replace stdout with the write-end of our pipe - process(token[0]); - exit(1); - } - - _close(fds[1]); // and we read from it - _dup2(fds[0],0); - metaprocess2(strchr(buf,'|')+1); - - _wait(pid); - - return true; -} - -bool process(char *buf) -{ - char **token=tokenize(buf,' '); - char *command=token[0]; - - if(!strcmp(command,"help"))help(); - else if(!strcmp(command,"cd"))cd(token[1]); - else if(!strcmp(command,"exit")) return false; - //else if(!strcmp(command,"getenv"))printf("(0x%08X) get: '%s' = '%s'(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1])); - else if(!strcmp(command,"getenv"))printf("%s\n",getenv(token[1])); - else if(!strcmp(command,"setenv")) - { - sprintf(buf,"%s=%s",token[1],token[2]); - putenv(buf); - //printf("(0x%08X) set: '%s' = '%s' \n",environ,token[1],getenv(token[1])); - } - else if(!strcmp(command,"env")) - { - int i=0; -// printf("env: 0x%08X\n",environ); - while(environ[i]!=NULL) - { -// printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); - printf("%s\n" ,environ[i]); - i++; - } - } - else // otherwise treat command as exectutable and send to execve - { - int pid=_fork(); - - if(pid==0) - { - if(token[0][0]=='/')sprintf(buf,"%s",token[0]); - else sprintf(buf,"%s/%s",getenv("PATH"),token[0]); - _execve(buf,token,environ); - printf("foolshell: %s (errno: %d)\n",strerror(errno),errno); - exit(1); - } - - if(token[1]==NULL||strcmp(token[1],"&"))_wait(pid); - - } - return true; -} - -bool setpwd(char *path) -{ - if(!strcmp(path,"/")) - { - putenv("PWD=/"); - return true; - } - char buf[255]; - buf[0]=0; - strcat(buf,"PWD="); - - char **t=tokenize(path,'/'); - - char *p[100]; - int pp=0; - - while(*t!=NULL) - { - if(!strcmp(*t,"..")){ - pp--; - t++; - if(pp<0)pp=0; - continue; - } - if(!strcmp(*t,".")){t++; continue;} - if(**t!=0) - { - p[pp]=*t; - //printf("> %s\n",p[pp]); - pp++; - } - t++; - } - - if(pp==0) - { - strcat(buf,"/"); - } - - for(int i=0;i < + */ + +#include +#include +#include +#include +#include +#include +#include "interface/fs.h" + +#include "newcalls.h" + +extern char **environ; + +bool process(char *buf); +bool metaprocess(char *buf); +bool cd(char *path); + +void version() +{ + puts("Fool's Shell version git-commit:" GIT_REVISION "\ncompiled on " __DATE__ " at " __TIME__); +} +void help() +{ + puts( "\nfoolshell: supported built-in commands/functions:\n\n" + + "'env' - show all environment variables\n" + "'getenv [var]' - show environment variable\n" + "'setenv [var] [val]' - set environemnet variable\n" + + "'cd [dir]' - change directory (set $PWD)\n" + "'[binary] [params...]' - run a binary\n" + "'[binary] [params...] &' - run a binary in background\n" + " | - pipes\n" + + "'help' - show this message\n" + "'exit' - exit running foolshell\n\n"); + +} + +void prompt() +{ + printf("\033[36mfool\033[37m@\033[32mhill\033[33m:%s%s\033[37m",getenv("PWD"),getenv("PS1")); +} + +int main(int argc, char **argv) +{ + for(int i=0;i\n",c, token[c]); + c++; + token[c]=NULL; + + } + return token; +} + +bool metaprocess2(char *buf); +bool metaprocess(char *buf) +{ + char **token=tokenize(buf,'|'); + if(token[0]==0 || token[1]==0)return process(buf); // no pipes + + int pid=_fork(); + + if(pid==0) + { + metaprocess2(buf); + exit(1); + } + + _wait(pid); + return true; +} + +bool metaprocess2(char *buf) +{ + char **token=tokenize(buf,'|'); + if(token[0]==0 || token[1]==0)return process(buf); // no pipes + + int fds[2]; + _pipe(fds); + + int pid=_fork(); + + if(pid==0) + { + // first child shall write to the pipe + _close(fds[0]); + _dup2(fds[1],1); // replace stdout with the write-end of our pipe + process(token[0]); + exit(1); + } + + _close(fds[1]); // and we read from it + _dup2(fds[0],0); + metaprocess2(strchr(buf,'|')+1); + + _wait(pid); + + return true; +} + +bool process(char *buf) +{ + char **token=tokenize(buf,' '); + char *command=token[0]; + + if(!strcmp(command,"help"))help(); + else if(!strcmp(command,"cd"))cd(token[1]); + else if(!strcmp(command,"exit")) return false; + //else if(!strcmp(command,"getenv"))printf("(0x%08X) get: '%s' = '%s'(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1])); + else if(!strcmp(command,"getenv"))printf("%s\n",getenv(token[1])); + else if(!strcmp(command,"setenv")) + { + sprintf(buf,"%s=%s",token[1],token[2]); + putenv(buf); + //printf("(0x%08X) set: '%s' = '%s' \n",environ,token[1],getenv(token[1])); + } + else if(!strcmp(command,"env")) + { + int i=0; +// printf("env: 0x%08X\n",environ); + while(environ[i]!=NULL) + { +// printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); + printf("%s\n" ,environ[i]); + i++; + } + } + else // otherwise treat command as exectutable and send to execve + { + int pid=_fork(); + + if(pid==0) + { + if(token[0][0]=='/')sprintf(buf,"%s",token[0]); + else sprintf(buf,"%s/%s",getenv("PATH"),token[0]); + _execve(buf,token,environ); + printf("foolshell: %s (errno: %d)\n",strerror(errno),errno); + exit(1); + } + + if(token[1]==NULL||strcmp(token[1],"&"))_wait(pid); + + } + return true; +} + +bool setpwd(char *path) +{ + if(!strcmp(path,"/")) + { + putenv("PWD=/"); + return true; + } + char buf[255]; + buf[0]=0; + strcat(buf,"PWD="); + + char **t=tokenize(path,'/'); + + char *p[100]; + int pp=0; + + while(*t!=NULL) + { + if(!strcmp(*t,"..")){ + pp--; + t++; + if(pp<0)pp=0; + continue; + } + if(!strcmp(*t,".")){t++; continue;} + if(**t!=0) + { + p[pp]=*t; + //printf("> %s\n",p[pp]); + pp++; + } + t++; + } + + if(pp==0) + { + strcat(buf,"/"); + } + + for(int i=0;i -#include - -void atex() -{ - printf("atex\n"); -} -int main() -{ - printf("nonextline"); -// fflush(stdout); - -// atexit(&atex); - return EXIT_SUCCESS; -} diff --git a/userspace/piper.c b/userspace/piper.c deleted file mode 100644 index 80cbd27..0000000 --- a/userspace/piper.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include "newcalls.h" - -extern **environ; - -int main() -{ - int fds[2]; - _pipe(fds); - - int pid=_fork(); - - if(pid) - { - _close(fds[1]); - _dup2(fds[0],0); // replace stdin with the read-end of pipe - char *args[]={"grep",NULL}; - _execve("/bin/grep",args,environ); - } - else - { - _close(fds[0]); - _dup2(fds[1],1); // replace stdout with the write-end of our pipe - char *args[]={"cat","hello.txt",0}; - _execve("/bin/cat",args,environ); - } -} diff --git a/userspace/simple.c b/userspace/simple.c deleted file mode 100644 index 0a04791..0000000 --- a/userspace/simple.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -extern char **environ; - -int main(int argc, char **argv) -{ - - printf("argv: 0x%08X\n",argv); - printf("env: 0x%08X\n",environ); - - int i=0; - while(environ[i]!=NULL) - { - printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); - i++; - } - - putenv("supa=dupa"); - printf("env: 0x%08X\n",environ); - - i=0; - while(environ[i]!=NULL) - { - printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); - i++; - } - - return 0; -} - - diff --git a/userspace/sysfs_write.c b/userspace/sysfs_write.c deleted file mode 100644 index 9f91632..0000000 --- a/userspace/sysfs_write.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -int main() -{ - FILE *f=fopen("/sys/mem","w"); - uint32_t data=0xaabbccdd; - fwrite(&data,4,1,f); -// fclose(f); // not automatically by newlib? -// fflush(f); -} diff --git a/userspace/task1.c b/userspace/task1.c index 793b7f8..e220424 100644 --- a/userspace/task1.c +++ b/userspace/task1.c @@ -7,7 +7,6 @@ static ULL fib1_cached_value=0; static ULL fib2_cached_index=1; static ULL fib2_cached_value=1; - ULL fib(ULL i) { if(i==0)return 0; diff --git a/userspace/test-math.c b/userspace/test-math.c deleted file mode 100644 index 9327c19..0000000 --- a/userspace/test-math.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - time_t ltime; - time(<ime); - printf("the time is %s", ctime(<ime)); - - unsigned int seed=time(NULL); - printf("seed = %u\n",seed); - - srand(seed); - - for(int i=0;i<10;i++) - { - int r=rand()%100; - printf ("the random number is %i",r); - printf("sin(%i) = %f \n",r,sin(r)); - } - - - return 0; -} - - - - - diff --git a/userspace/test_env.c b/userspace/test_env.c new file mode 100644 index 0000000..0a04791 --- /dev/null +++ b/userspace/test_env.c @@ -0,0 +1,31 @@ +#include + +extern char **environ; + +int main(int argc, char **argv) +{ + + printf("argv: 0x%08X\n",argv); + printf("env: 0x%08X\n",environ); + + int i=0; + while(environ[i]!=NULL) + { + printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); + i++; + } + + putenv("supa=dupa"); + printf("env: 0x%08X\n",environ); + + i=0; + while(environ[i]!=NULL) + { + printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); + i++; + } + + return 0; +} + + diff --git a/userspace/test_math.c b/userspace/test_math.c new file mode 100644 index 0000000..9327c19 --- /dev/null +++ b/userspace/test_math.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + time_t ltime; + time(<ime); + printf("the time is %s", ctime(<ime)); + + unsigned int seed=time(NULL); + printf("seed = %u\n",seed); + + srand(seed); + + for(int i=0;i<10;i++) + { + int r=rand()%100; + printf ("the random number is %i",r); + printf("sin(%i) = %f \n",r,sin(r)); + } + + + return 0; +} + + + + + diff --git a/userspace/test_sysfs.c b/userspace/test_sysfs.c new file mode 100644 index 0000000..9f91632 --- /dev/null +++ b/userspace/test_sysfs.c @@ -0,0 +1,9 @@ +#include +int main() +{ + FILE *f=fopen("/sys/mem","w"); + uint32_t data=0xaabbccdd; + fwrite(&data,4,1,f); +// fclose(f); // not automatically by newlib? +// fflush(f); +} -- cgit v1.2.3