diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-10-22 10:39:56 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-10-22 10:39:56 +0200 |
| commit | bedf6a20ba49d7da460de862a58f8eb04bad1514 (patch) | |
| tree | ca9721c76c847137de2b518cbb8f7230de697019 | |
| parent | 430112c8d7224bf9d1e192adfc9fb55e7a044f83 (diff) | |
migrating shell to "userspace"
| -rw-r--r-- | asm/int_syscall_handler.asm | 3 | ||||
| -rw-r--r-- | kernel/shell.c | 127 | ||||
| -rw-r--r-- | kernel/syscalls.c | 7 | ||||
| -rw-r--r-- | kernel/vesa.c | 2 | ||||
| -rw-r--r-- | userspace/foolshell.c | 87 |
5 files changed, 93 insertions, 133 deletions
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm index bd787de..550ebb3 100644 --- a/asm/int_syscall_handler.asm +++ b/asm/int_syscall_handler.asm @@ -35,8 +35,8 @@ done: out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts mov eax,ebx + nop - sti done_blocking: @@ -46,6 +46,7 @@ done_blocking: mov ebx,eax + sti iret ;Interrupt-Return diff --git a/kernel/shell.c b/kernel/shell.c index 2e00bd0..b28b04f 100644 --- a/kernel/shell.c +++ b/kernel/shell.c @@ -1,130 +1,3 @@ -#include "interrupts.h" -#include "time.h" -#include "smp.h" -#include "lib/logger/log.h" // logger facilities -#include "lib/bool/bool.h" -#include "lib/int/stdint.h" - -#define FOOLOS_MODULE_NAME "shell" - -#define COMMAND_LENGTH 255 - -uint32_t cpu_counter[SMP_MAX_PROC]; -static char command[COMMAND_LENGTH]; -static int pos=0; -uint32_t c1,c2,c3; - -// in timer: -uint16_t timer16; - -void shell_init() -{ - pos=0; - command[0]=0; -} - -void shell_put(char x) -{ - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"char:%c",x); - - if(pos<COMMAND_LENGTH-2); - - command[pos]=x; - pos++; - - command[pos]=0; - -} - -void shell_backspace() -{ - if(pos>0); - pos--; - command[pos]=0; - -} - - -// TODO: EXECUTE LATER not inside INTERRUPT !!! -void shell_execute() -{ - //scr_nextline(); - //scr_put_string(" processing command: "); - //scr_put_string_nl(command); - - if(1==strcmp(command,"TIME",0)) - { - uint32_t time=task_system_clock; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d seconds passed since system start.",(time/25)); - } - else if(1==strcmp(command,"MEM",0)) - { - mmap_show_free(); - } - else if(1==strcmp(command,"PROC",0)) - { - for(int i=0;i<SMP_MAX_PROC;i++) - { - if(cpu_counter[i]!=0) - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cpu: %d => %d.",i,cpu_counter[i]); - } - } - else if(1==strcmp(command,"TASKS",0)) - { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d %d %d",c1,c2,c2); - } - else if(1==strcmp(command,"ALLOC",0)) - { - uint32_t *malloc= pmmngr_alloc_block(); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"allocated 4KB block at: %08x.",malloc); - } - else if(1==strcmp(command,"READ",0)) - { -// uint8_t *read= flpydsk_read_sector (10); - } - else if(1==strcmp(command,"SYSCALL",0)) - { - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call 10"); - uint32_t ebx; // will hold return value; - // system call - asm("pusha"); - asm("mov $10,%eax"); // select syscall 10 (example_syscall) - asm("mov $666,%edx"); - asm("mov $333,%ecx"); - asm("int $0x80"); // actual syscall ! interrupt - asm("mov %%ebx, %0": "=b" (ebx)); - asm("popa"); - // - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call returned %d",ebx); - - } - else if(1==strcmp(command,"TWO",0)) - { - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call 20"); - uint32_t ebx; // will hold return value; - // system call - asm("pusha"); - asm("mov $20,%eax"); // select syscall2 20 (example_syscall) - asm("mov $566,%edx"); - asm("mov $233,%ecx"); - asm("int $0x80"); // actual syscall ! interrupt - asm("mov %%ebx, %0": "=b" (ebx)); - asm("popa"); - // - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"system call returned %d",ebx); - - } - else - { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"command unknown"); - } - - pos=0; -} diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 470939c..1eca490 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -6,8 +6,9 @@ int syscall_write(int file, char *buf, int len) { for(int i=0;i<len;i++) + { PutConsoleChar(buf[i],0b1111111111000000); - + } return len; } @@ -37,14 +38,14 @@ int syscall_read(int file, char *buf, int len) int example_syscall(int x,int y) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall called with %d + %d",x,y); +// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall called with %d + %d",x,y); return x+y; } int example_syscall_2(int x,int y) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall 2 called with %d - %d",x,y); + // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"example syscall 2 called with %d - %d",x,y); return x-y; } diff --git a/kernel/vesa.c b/kernel/vesa.c index b0e9885..25c92a1 100644 --- a/kernel/vesa.c +++ b/kernel/vesa.c @@ -182,7 +182,7 @@ void PutConsoleChar(char c, int color) #ifdef FOOLOS_CONSOLE_AUTOBREAK - if(console_x>console_cols)PutConsoleNL(); + if(console_x>=console_cols)PutConsoleNL(); #endif } diff --git a/userspace/foolshell.c b/userspace/foolshell.c index bc02102..7a029ef 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <string.h> #include "syscalls.c" void hello() { @@ -12,6 +13,7 @@ void prompt() { "$ " ); } + int main(int argc, char **argv) { syscalls_init(); @@ -26,9 +28,92 @@ int main(int argc, char **argv) prompt(); fgets(buf,255,input); buf[strlen(buf)-1]=0; - puts(buf); +// puts(buf); + process(buf); + } return 0; } + +int process(char *command) +{ + // copied from trottelshell + + if(!strcmp(command,"HELP")) + { + puts("foolshell: supported built-in commands: HELP, ECHO, TIME, MEM, PROC, TASKS, ALLOC, READ, SYSCALL."); + } + else if(!strcmp(command,"TIME")) + { +// uint32_t time=task_system_clock; +// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d seconds passed since system start.",(time/25)); + puts("foolshell: TIME not supported now."); + } + else if(!strcmp(command,"MEM")) + { + //mmap_show_free(); + puts("foolshell: MEM not supported now."); + } + else if(!strcmp(command,"PROC")) + { + /* + for(int i=0;i<SMP_MAX_PROC;i++) + { + if(cpu_counter[i]!=0) + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cpu: %d => %d.",i,cpu_counter[i]); + } + */ + puts("foolshell: PROC not supported now."); + } + else if(!strcmp(command,"TASKS")) + { + //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d %d %d",c1,c2,c2); + puts("foolshell: TASKS not supported now."); + } + else if(!strcmp(command,"ALLOC")) + { + /* + uint32_t *malloc= pmmngr_alloc_block(); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"allocated 4KB block at: %08x.",malloc); + */ + puts("foolshell: ALLOC not supported now."); + } + else if(!strcmp(command,"SYSCALL")) + { + + puts("system call 10"); + unsigned int ebx; // will hold return value; + + // system call + asm("pusha"); + asm("mov $10,%eax"); // select syscall 10 (example_syscall) + asm("mov $666,%edx"); + asm("mov $333,%ecx"); + asm("int $0x80"); // actual syscall ! interrupt + asm("mov %%ebx, %0": "=b" (ebx)); + asm("popa"); + // + + printf("system call returned %i\n",ebx); + + } + else if(!strcmp(command,"ECHO")) + { + + printf("%s\n",command); + + } + else + { + puts("foolshell: command not found"); + } + + // +} + + + + + |
