diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-07-08 23:19:51 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-07-08 23:19:51 +0200 |
| commit | d00e64542cb58b25cd67e8c3b682d0e07312f441 (patch) | |
| tree | 725231947c9425e0aae45fb674f8c02a955e7632 | |
| parent | 1d5e33d5cc2c68dbe63d9a889432316a514a6fd6 (diff) | |
added basic shell with one command.
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | kernel/console.c | 9 | ||||
| -rw-r--r-- | kernel/console.h | 1 | ||||
| -rw-r--r-- | kernel/kernel.c | 10 | ||||
| -rw-r--r-- | kernel/kernel.h | 1 | ||||
| -rw-r--r-- | kernel/keyboard.c | 59 | ||||
| -rw-r--r-- | kernel/shell.c | 82 | ||||
| -rw-r--r-- | kernel/timer.c | 11 |
8 files changed, 159 insertions, 19 deletions
@@ -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<SCR_HEIGHT-1;i++) { - for(x=1;x<SCR_WIDTH;x++) + for(x=0;x<SCR_WIDTH;x++) { char* video_mem=(char *)SCR_VIDEOMEM+((x)+(i-1)*SCR_REAL_WIDTH)*2; char* video_mem2=(char *)SCR_VIDEOMEM+((x)+i*SCR_REAL_WIDTH)*2; @@ -129,3 +129,10 @@ void scr_put_string(char *str) } } +void scr_backspace() +{ + if(posx==0)return; + print_char_col(posx-1,posy,'@',SCR_LGREEN); + posx--; + +} diff --git a/kernel/console.h b/kernel/console.h index c1920b8..8c547db 100644 --- a/kernel/console.h +++ b/kernel/console.h @@ -34,6 +34,7 @@ //autoscroll void scr_clear(); void scr_nextline(); +void scr_backspace(); void scr_put_string(char *str); void scr_put_string_nl(char *str); void scr_put_hex(uint16_t val); diff --git a/kernel/kernel.c b/kernel/kernel.c index 3c7b578..7118706 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -17,7 +17,6 @@ void int_test_handler() scr_put_string("inside software interrupt handler 88"); - __asm__("popa"); __asm__("leave"); __asm__("iret"); @@ -48,19 +47,22 @@ void kernel_main() // keyboard = 22 (irq 1) // etc.. - // install pit handler (programmable timer interrupt channel0) + // install PIT interrupt handler int_install_ir(32, 0b10001110, 0x08,&int_clock_handler); - // install keyboard handler + // install keyboard interrupt handler int_install_ir(33, 0b10001110, 0x08,&int_kb_handler); - // install test handler + // install test software interrupt handler int_install_ir(88, 0b10001110, 0x08,&int_test_handler); // now we can enable interrupts back again int_enable(); scr_put_string_nl("Interrupts are up and running"); + //init shell + shell_init(); + // kernel main loop while(1) { diff --git a/kernel/kernel.h b/kernel/kernel.h index 0dc7306..c7ebfd4 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -4,5 +4,6 @@ #include <stdint.h> //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(pos<COMMAND_LENGTH-2); + + command[pos]=x; + pos++; + + command[pos]=0; + +} + +void shell_backspace() +{ + if(pos>0); + 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"); |
