Added very basic interactive shell.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#ifndef __SHELL_H
|
||||
#define __SHELL_H
|
||||
|
||||
void run_shell();
|
||||
void key_pressed(unsigned char* character);
|
||||
void execmd();
|
||||
|
||||
#endif
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -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");
|
||||
|
||||
+39
@@ -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';
|
||||
}
|
||||
Reference in New Issue
Block a user