diff --git a/include/shell.h b/include/shell.h new file mode 100644 index 0000000..43086ac --- /dev/null +++ b/include/shell.h @@ -0,0 +1,8 @@ +#ifndef __SHELL_H +#define __SHELL_H + +void run_shell(); +void key_pressed(unsigned char* character); +void execmd(); + +#endif \ No newline at end of file diff --git a/include/system.h b/include/system.h index 41f87a4..f564faf 100644 --- a/include/system.h +++ b/include/system.h @@ -9,6 +9,7 @@ extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int cou extern int strlen(const char *str); extern unsigned char inportb (unsigned short _port); extern void outportb (unsigned short _port, unsigned char _data); +extern bool strcmp(char* str1, char* str2); /* ISRS.C */ void isrs_install(); /* This defines what the stack looks like after an ISR was running */ diff --git a/makefile b/makefile index e9dac62..e1b751a 100644 --- a/makefile +++ b/makefile @@ -12,7 +12,8 @@ objects = obj/start.o \ obj/isrs.o \ obj/irq.o \ obj/timer.o \ - obj/kb.o + obj/kb.o \ + obj/shell.o run: kernel.iso qemu-system-x86_64 -cdrom kernel.iso & @@ -26,7 +27,7 @@ obj/%.o: src/%.asm nasm $(ASPARAMS) -o $@ $< kernel.bin: linker.ld $(objects) - mkdir obj/bin + mkdir -p obj/bin ld $(LDPARAMS) -T $< -o obj/bin/$@ $(objects) #https://www.linuxjournal.com/content/add-auto-incrementing-build-number-your-build-process #include buildnumber.mak diff --git a/src/kb.c b/src/kb.c index eae88cb..b86820c 100644 --- a/src/kb.c +++ b/src/kb.c @@ -1,4 +1,5 @@ #include "../include/system.h" +#include "../include/shell.h" //http://www.osdever.net/bkerndev/Docs/keyboard.htm /* KBDUS means US Keyboard Layout. This is a scancode table * used to layout a standard US keyboard. I have left some @@ -51,10 +52,15 @@ bool shift = false; void keyboard_handler(struct regs *r) { unsigned char scancode; - /* Read from the keyboard's data buffer */ scancode = inportb(0x60); + if(scancode == 0x1C) + { + execmd(); + return; + } + /* If the top bit of the byte we read from the keyboard is * set, that means that a key has just been released */ if (scancode & 0x80) @@ -89,7 +95,8 @@ void keyboard_handler(struct regs *r) { letter = letter - 32; } - putch(letter); + //putch(letter); + key_pressed(letter); } } diff --git a/src/main.c b/src/main.c index a16f1fb..1c0c2e0 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include "../include/gdt.h" #include "../include/idt.h" #include "../include/scrn.h" +#include "../include/shell.h" unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count) { @@ -44,6 +45,24 @@ int strlen(const char *str) return retval; } +bool strcmp(char* str1, char* str2) +{ + int len1 = strlen(str1); + int len2 = strlen(str2); + + if(len1 != len2) + { + puts("Lengths different!\n"); + return false; + } + for(int i = len1; i >= 0; i--) + { + if(str1[i] != str2[i]) return false; + } + + return true; +} + /* We will use this later on for reading from the I/O ports to get data * from devices such as the keyboard. We are using what is called * 'inline assembly' in these routines to actually do the work */ @@ -87,6 +106,7 @@ void main() kb_install(); puts("Keyboard installed.\n"); puts("SDOS version 0.0.0.1 initialized.\n"); + run_shell(); //puts(&__BUILD_DATE); //puts(&__BUILD_NUMBER); //puts("Divide by zero check:\n"); diff --git a/src/shell.c b/src/shell.c new file mode 100644 index 0000000..447e768 --- /dev/null +++ b/src/shell.c @@ -0,0 +1,39 @@ +#include "../include/shell.h" +#include "../include/scrn.h" +#include "../include/system.h" + +unsigned char* commandbuffer; + +void run_shell() +{ + puts("Starting interactive shell...\n"); + commandbuffer[0] = '\0'; + puts("#>"); + for(;;); +} + +void key_pressed(unsigned char* character) +{ + int len = strlen(commandbuffer); + commandbuffer[len] = character; + commandbuffer[len + 1] = '\0'; + putch(character); +} + +void execmd() +{ + if(strcmp(commandbuffer, "version")) + { + puts("\nInteractive Shell Version 0.0.0.1\n"); + } + else if(strcmp(commandbuffer,"cls")) + { + cls(); + } + else + { + puts("\nUnknown command\n"); + } + puts("#>"); + commandbuffer[0] = '\0'; +} \ No newline at end of file