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 --- grubiso/boot/grub/grub.cfg | 2 +- kernel/kernel.c | 3 + kernel/scheduler.c | 7 +- kernel/syscalls.c | 19 ++- kernel/syscalls.h | 5 +- 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 ++ 20 files changed, 446 insertions(+), 441 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 diff --git a/grubiso/boot/grub/grub.cfg b/grubiso/boot/grub/grub.cfg index 08f1fe1..9c78bfb 100644 --- a/grubiso/boot/grub/grub.cfg +++ b/grubiso/boot/grub/grub.cfg @@ -1,4 +1,4 @@ -set timeout=0 //seconds +set timeout=1 //seconds menuentry "FoolOS (640x480x32)" { multiboot /boot/foolos.bin diff --git a/kernel/kernel.c b/kernel/kernel.c index 247e978..ab4332a 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -119,6 +119,9 @@ void kernel_main(uint32_t eax,uint32_t ebx) uint32_t addr= ext2_inode_blockstart( VMEM_EXT2_RAMIMAGE,inode,0); vesa_init(cfg_multiboot->vbe_control_info,cfg_multiboot->vbe_mode_info,addr); + // -- STD STREAMS -- // + fd_init_std_streams(0,cfg_multiboot->framebuffer_type!=2); + // -- KB -- // klog("Keyboard init ..."); keyboard_init(0); diff --git a/kernel/scheduler.c b/kernel/scheduler.c index c13fd4e..667abf8 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -82,8 +82,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][0].vmem=dir; task_list[cpu][0].esp = VMEM_CPU_STACK_TOP-0x200; task_list[cpu][0].esp0 = 0; // esp0 not needed by kernel space tasks - fd_init_std_streams(task_list[cpu][0].pid); - + fd_init_std_streams(task_list[cpu][0].pid,0); // this will go to userspace task_list[cpu][1].parent=0; @@ -94,7 +93,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][1].vmem=dir; task_list[cpu][1].esp = kballoc(4)+4*4096-0x200; // 4 pages stack task_list[cpu][1].esp0 =kballoc(4)+4*4096; // esp0 not needed by kernel space tasks - fd_init_std_streams(task_list[cpu][1].pid); + fd_init_std_streams(task_list[cpu][1].pid,0); // sleeper @@ -106,7 +105,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir) task_list[cpu][2].vmem=dir; task_list[cpu][2].esp = kballoc(4)+4*4096-0x200; // 4 pages stack task_list[cpu][2].esp0 =kballoc(4)+4*4096; // esp0 not needed by kernel space tasks - fd_init_std_streams(task_list[cpu][2].pid); + fd_init_std_streams(task_list[cpu][2].pid,0); // stacks task_pusha(task_list[cpu][0].esp); diff --git a/kernel/syscalls.c b/kernel/syscalls.c index edc4751..2952c11 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -30,14 +30,24 @@ static fd fds[MAX_PID][MAX_FD]; static bool open_fd[MAX_PID][MAX_FD]; -void fd_init_std_streams(uint32_t pid) +void fd_init_std_streams(uint32_t pid,bool fb) { - if(pid==0) + static bool first=true; + if(pid==0&&first) { + first=false; //stdin / stdout /stderr fds[0][0]=fd_from_ringbuffer(); - fds[0][1]=fd_from_fb_term(); - fds[0][2]=fd_from_fb_term(); + if(!fb) // ega text mode + { + fds[0][1]=fd_from_term(); + fds[0][2]=fd_from_term(); + } + else + { + fds[0][1]=fd_from_fb_term(); + fds[0][2]=fd_from_fb_term(); + } open_fd[0][0]=true; open_fd[0][1]=true; open_fd[0][2]=true; @@ -52,6 +62,7 @@ void fd_init_std_streams(uint32_t pid) open_fd[pid][2]=true; } } +// /** errno helper */ void set_errno(int no) diff --git a/kernel/syscalls.h b/kernel/syscalls.h index d90e314..7216a46 100644 --- a/kernel/syscalls.h +++ b/kernel/syscalls.h @@ -12,6 +12,9 @@ * */ +#include +#include + #define SYSCALL_EXIT 60 #define SYSCALL_EXECVE 64 #define SYSCALL_FORK 72 @@ -40,7 +43,7 @@ #define SYSCALL_DUP2 86 /** Todo move somewhere else and init per process , think how to make thread safe */ -void fd_init_std_streams(uint32_t pid); +void fd_init_std_streams(uint32_t pid, bool use_framebuffer); /** returns string representation of the syscall from its number */ char* syscall_get_name(uint32_t num); 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