From d00e64542cb58b25cd67e8c3b682d0e07312f441 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Tue, 8 Jul 2014 23:19:51 +0200 Subject: added basic shell with one command. --- Makefile | 5 +++- kernel/console.c | 9 +++++- kernel/console.h | 1 + kernel/kernel.c | 10 ++++--- kernel/kernel.h | 1 + kernel/keyboard.c | 59 ++++++++++++++++++++++++++++++--------- kernel/shell.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/timer.c | 11 ++++++++ 8 files changed, 159 insertions(+), 19 deletions(-) create mode 100644 kernel/shell.c diff --git a/Makefile b/Makefile index 4bb9b25..98f0f66 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,11 @@ keyboard.o: kernel/keyboard.c timer.o: kernel/timer.c gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0 + +shell.o: kernel/shell.c + gcc -ffreestanding -m32 -o $@ -c $< -fno-asynchronous-unwind-tables -O0 -kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o +kernel.bin: kernel_entry.o kernel.o console.o interrupts.o keyboard.o timer.o shell.o ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0 diff --git a/kernel/console.c b/kernel/console.c index 8ca7ae2..27b21e5 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -77,7 +77,7 @@ void scr_nextline() for(i=1;i //needed for uint16_t #define KERNEL_HELLO_MESSAGE "FoolOs 0.0.1" +// #define DEBUG #endif diff --git a/kernel/keyboard.c b/kernel/keyboard.c index f7887f2..d412c84 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -1,21 +1,22 @@ - #include "kernel.h" #include "console.h" /// keyboard driver //// -static uint8_t kb_in; -static int cursor=0; -static char last_code=0; -void int0(uint8_t in) +//static int cursor=0; +//static char last_code=0; + +void keyboard_handle(uint8_t in) { +#ifdef DEBUG // test interrupt 88 // whenver A is pressed if(in==0x1e) { int_generate88(); } +#endif int i=0; // @@ -25,7 +26,7 @@ void int0(uint8_t in) 0x1e, // A 0x30, // B 0x2e, // C - 0x20, // D + 0x20, // s/OSDev19.htmlD 0x12, // E 0x21, // F 0x22, // G @@ -50,7 +51,7 @@ void int0(uint8_t in) 0x2c, // Z }; - uint8_t break_codes[]={ + uint8_t break_alpha[]={ 0x9e, // A 0xb0, // B 0xae, // C @@ -79,30 +80,62 @@ void int0(uint8_t in) 0xac, // Z }; - //if(last_code==*int_count)return; + uint8_t break_key_enter=0x9c; + uint8_t break_key_space=0xb9; + uint8_t break_key_backspace=0x8e; + //if(last_code==*int_count)return; +/* for(i=0;i<26;i++) { if(make_codes[i]==in) { - print_char_col(cursor,20,'A'+i,0xf); +// print_char_col(cursor,20,'A'+i,0xf); +// scr_put_char('A'+i); } } + */ + + if(break_key_space==in) + { + scr_put_char(' '); + shell_put(' '); + return; + } + + if(break_key_backspace==in) + { + scr_backspace(); + shell_backspace(); + return; + } + + if(break_key_enter==in) + { + scr_nextline(); + shell_execute(); + return; + } for(i=0;i<26;i++) { - if(break_codes[i]==in) + if(break_alpha[i]==in) { - print_char_col(cursor++,20,'a'+i,SCR_RED); + //print_char_col(cursor++,20,'a'+i,SCR_RED); + scr_put_char('A'+i); + shell_put('A'+i); + return; } } - last_code=in; +// last_code=in; } void int_kb_handler() { + static uint8_t kb_in; + __asm__("pusha"); __asm__("in $0x60, %al"); @@ -112,7 +145,7 @@ void int_kb_handler() //scr_put_string("irq 1 -> kb scancodes : "); //scr_put_hex(kb_in); - int0(kb_in); //TODO!! + keyboard_handle(kb_in); //TODO!! __asm__("mov $0x20, %al"); __asm__("out %al, $0x20"); diff --git a/kernel/shell.c b/kernel/shell.c new file mode 100644 index 0000000..837a4c3 --- /dev/null +++ b/kernel/shell.c @@ -0,0 +1,82 @@ +#include "kernel.h" + +#define COMMAND_LENGTH 255 + +static char command[COMMAND_LENGTH]; +static int pos=0; + +// in timer: +uint16_t timer16; + +void shell_init() +{ + pos=0; + command[0]=0; + + scr_nextline(); + scr_put_string_nl("***********************"); + scr_put_string_nl("Fools Shell v 0.0.0.1 *"); + scr_put_string_nl("***********************"); + scr_nextline(); + scr_put_string("Command> "); +} + +void shell_put(char x) +{ + if(pos0); + pos--; + command[pos]=0; + +} + + +int strcmp(char *b1, char *b2) +{ + int i=0; + while(b1[i]==b2[i]&&b1[i]!=0&&b2[i]!=0) i++; + + if(b1[i]==0&&b2[i]==0)return 1; + + return 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")) + { + scr_put_string_nl(" getting sys time from kernel"); + scr_put_string(" "); + scr_put_hex(timer16); + scr_put_string_nl(" seconds passed since system start."); + } + else + { + scr_put_string_nl(" unsupported command, sorry!"); + } + + pos=0; + + scr_nextline(); + scr_put_string("Command> "); + +} + + + diff --git a/kernel/timer.c b/kernel/timer.c index 1f97c92..ee78bd5 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -35,6 +35,7 @@ static uint64_t timer64=0; static uint8_t timer8=0; +uint16_t timer16=0; // clock handler void int_clock_handler() @@ -43,6 +44,9 @@ void int_clock_handler() timer64++; + + +#ifdef DEBUG timer8++; // show point once every 1 second @@ -51,7 +55,14 @@ void int_clock_handler() scr_put_string("."); timer8=0; } +#endif + timer8++; + if(timer8==25) + { + timer16++; + timer8=0; + } // todo also the other pic!// TODO __asm__("mov $0x20, %al"); -- cgit v1.2.3