From bedf6a20ba49d7da460de862a58f8eb04bad1514 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 22 Oct 2014 10:39:56 +0200 Subject: migrating shell to "userspace" --- asm/int_syscall_handler.asm | 3 +- kernel/shell.c | 127 -------------------------------------------- kernel/syscalls.c | 7 +-- kernel/vesa.c | 2 +- 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(pos0); - 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 %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;iconsole_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 +#include #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 %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"); + } + + // +} + + + + + -- cgit v1.2.3