Added very basic interactive shell.

This commit is contained in:
2018-11-11 17:20:04 -06:00
parent a061366ff2
commit f76c5071ec
6 changed files with 80 additions and 4 deletions
+8
View File
@@ -0,0 +1,8 @@
#ifndef __SHELL_H
#define __SHELL_H
void run_shell();
void key_pressed(unsigned char* character);
void execmd();
#endif
+1
View File
@@ -9,6 +9,7 @@ extern unsigned short *memsetw(unsigned short *dest, unsigned short val, int cou
extern int strlen(const char *str); extern int strlen(const char *str);
extern unsigned char inportb (unsigned short _port); extern unsigned char inportb (unsigned short _port);
extern void outportb (unsigned short _port, unsigned char _data); extern void outportb (unsigned short _port, unsigned char _data);
extern bool strcmp(char* str1, char* str2);
/* ISRS.C */ /* ISRS.C */
void isrs_install(); void isrs_install();
/* This defines what the stack looks like after an ISR was running */ /* This defines what the stack looks like after an ISR was running */
+3 -2
View File
@@ -12,7 +12,8 @@ objects = obj/start.o \
obj/isrs.o \ obj/isrs.o \
obj/irq.o \ obj/irq.o \
obj/timer.o \ obj/timer.o \
obj/kb.o obj/kb.o \
obj/shell.o
run: kernel.iso run: kernel.iso
qemu-system-x86_64 -cdrom kernel.iso & qemu-system-x86_64 -cdrom kernel.iso &
@@ -26,7 +27,7 @@ obj/%.o: src/%.asm
nasm $(ASPARAMS) -o $@ $< nasm $(ASPARAMS) -o $@ $<
kernel.bin: linker.ld $(objects) kernel.bin: linker.ld $(objects)
mkdir obj/bin mkdir -p obj/bin
ld $(LDPARAMS) -T $< -o obj/bin/$@ $(objects) ld $(LDPARAMS) -T $< -o obj/bin/$@ $(objects)
#https://www.linuxjournal.com/content/add-auto-incrementing-build-number-your-build-process #https://www.linuxjournal.com/content/add-auto-incrementing-build-number-your-build-process
#include buildnumber.mak #include buildnumber.mak
+9 -2
View File
@@ -1,4 +1,5 @@
#include "../include/system.h" #include "../include/system.h"
#include "../include/shell.h"
//http://www.osdever.net/bkerndev/Docs/keyboard.htm //http://www.osdever.net/bkerndev/Docs/keyboard.htm
/* KBDUS means US Keyboard Layout. This is a scancode table /* KBDUS means US Keyboard Layout. This is a scancode table
* used to layout a standard US keyboard. I have left some * used to layout a standard US keyboard. I have left some
@@ -51,10 +52,15 @@ bool shift = false;
void keyboard_handler(struct regs *r) void keyboard_handler(struct regs *r)
{ {
unsigned char scancode; unsigned char scancode;
/* Read from the keyboard's data buffer */ /* Read from the keyboard's data buffer */
scancode = inportb(0x60); scancode = inportb(0x60);
if(scancode == 0x1C)
{
execmd();
return;
}
/* If the top bit of the byte we read from the keyboard is /* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */ * set, that means that a key has just been released */
if (scancode & 0x80) if (scancode & 0x80)
@@ -89,7 +95,8 @@ void keyboard_handler(struct regs *r)
{ {
letter = letter - 32; letter = letter - 32;
} }
putch(letter); //putch(letter);
key_pressed(letter);
} }
} }
+20
View File
@@ -2,6 +2,7 @@
#include "../include/gdt.h" #include "../include/gdt.h"
#include "../include/idt.h" #include "../include/idt.h"
#include "../include/scrn.h" #include "../include/scrn.h"
#include "../include/shell.h"
unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count) unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count)
{ {
@@ -44,6 +45,24 @@ int strlen(const char *str)
return retval; 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 /* 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 * from devices such as the keyboard. We are using what is called
* 'inline assembly' in these routines to actually do the work */ * 'inline assembly' in these routines to actually do the work */
@@ -87,6 +106,7 @@ void main()
kb_install(); kb_install();
puts("Keyboard installed.\n"); puts("Keyboard installed.\n");
puts("SDOS version 0.0.0.1 initialized.\n"); puts("SDOS version 0.0.0.1 initialized.\n");
run_shell();
//puts(&__BUILD_DATE); //puts(&__BUILD_DATE);
//puts(&__BUILD_NUMBER); //puts(&__BUILD_NUMBER);
//puts("Divide by zero check:\n"); //puts("Divide by zero check:\n");
+39
View File
@@ -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';
}