Skip to content

Commit

Permalink
Brand-new interpreter for an ASM-esque language. Removed some shell f…
Browse files Browse the repository at this point in the history
…unctionality to make space.
  • Loading branch information
kevinsa5 committed Sep 7, 2014
1 parent 53017be commit 74a9dd5
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 221 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ KevinOS Notes:
Compilation:
------------

+ `$ ./compile.sh` overwrites the filesystem of `/dev/sdb` -- be careful!
+ `$ ./compile.sh write` overwrites the filesystem of `/dev/sdb` -- be careful!

+ `$ qemu-system-i386 os-image` can be used for quicker testing.
+ `$ qemu-system-i386 os-image` can be used for quicker testing, if recompilation is not necessary.

+ Testing is done with Oracle Virtualbox, QEMU, and a Lenovo T430. Development done on 64-bit Linux Mint 15 with a standard GNU toolchain (GCC, LD, etc).
+ Testing is done with QEMU on a Lenovo T430. Development done on 64-bit Linux Mint Debian Edition with the standard GNU toolchain (GCC, LD, etc).

Features:
---------

KevinOS currently loads a 32-bit C kernel in Protected Mode. It detects all interrupt calls and has preliminary PIT-handling code. Keypress detection for a standard laptop keyboard is complete and the OS boots into a _very_ basic shell. Pseudorandom number generation implemented the same as the C standard document. A custom file system (KFS) is under development, just to learn more about low-level coding.
KevinOS currently loads a 32-bit C kernel in Protected Mode. It detects all interrupt calls and has preliminary PIT-handling code. Keypress detection for a standard laptop keyboard is complete and the OS boots into a _very_ basic shell. A basic text-buffer editor is available with `edit`, and Pseudorandom number generation implemented the same as the C standard document. A custom file system (KFS) is under development, just to learn more about low-level coding.

Unlicense:
----------
Expand Down
2 changes: 1 addition & 1 deletion bootloader_stage2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

;BIOS_DATA_AREA equ 0x400
KERNEL_ADDRESS equ 0x200
NUM_SECTORS equ 53
NUM_SECTORS equ 55

; GDT definitions
gdt_start:
Expand Down
11 changes: 11 additions & 0 deletions files/first.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
seti 0 0;
seti 1 10;
setcmp2 1;
# line 3
inc 0;
printi 0;
setcmp1 0;
jlt 3;
setc 0 !;
printc 0;
status;
12 changes: 5 additions & 7 deletions kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int ttx;
int tty;
char prompt;
int promptColor;
int modifier[6];
char modifier[6];
volatile unsigned long int ticks;
int commandLength;
char counter;
Expand All @@ -77,10 +77,10 @@ void main(){
int i = 0;
commandLength = 0;
counter = '0';
while(modifier[i] != 0){
modifier[i] = 0;
i++;
}

memFill(modifier, 0, 5);
memFill(fileBuffer, 0, height*width);

modifier[INSERT] = 1;
modifier[CAPSLOCK] = 0;
terminalMode = TERMINAL;
Expand Down Expand Up @@ -228,8 +228,6 @@ void editor_keyPressed(unsigned char code, char c){
}
}
ttprintChar(c);


}
void interpreter_keyPressed(unsigned char code, char c){}

Expand Down
206 changes: 206 additions & 0 deletions sh_exec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
#include "stdio.h"
#include "util.c"
#define width 80
#define height 18
*/

int iregisters[10];
char cregisters[10];
int cmp1, cmp2;

void exec_seti(char*);
void exec_setc(char*);
void exec_printi(char*);
void exec_printc(char*);
void exec_addi(char*);
void exec_multi(char*);
void exec_null(char*);
void exec_randi(char*);
void exec_inc(char*);
void exec_dec(char*);
void exec_setcmp1(char*);
void exec_setcmp2(char*);
void exec_status(char*);

char *execCommandList[] = { "seti", "setc", "printi", "printc", "addi", "multi", "randi", "inc", "dec", "setcmp1", "setcmp2", "status" , ""};
void (*execFunctionList[])(char*) = {exec_seti, exec_setc, exec_printi, exec_printc, exec_addi, exec_multi, exec_randi, exec_inc, exec_dec, exec_setcmp1, exec_setcmp2, exec_status, exec_null};

void sh_exec(char* params){
terminalMode = INTERPRETER;
char line[width+1];
line[width] = 0;
int index = 0;
for(index = 0; index < 10; index++){
iregisters[index] = 0;
cregisters[index] = 0;
}

//iterate through the buffer
int lineNum;
for(lineNum = 0; lineNum < height; lineNum++){
// read line, removing null chars along the way:
int i = 0;
index = lineNum * width;
// lines must not have the first char blank
// also don't read comments
if(fileBuffer[index] == ' ' || fileBuffer[index] == 0 || fileBuffer[index] == '#')
continue;
memFill(line,0,width);
while(fileBuffer[index] != ';' && i < 80){
if(fileBuffer[index] != 0){
line[i] = fileBuffer[index];
i++;
}
index++;
}
if(strEquals(line,"")) continue;
// now `line` contains the command (function + args) to be interpreted
// isolate out the function part by splitting on the first space
int j = 0;
while(line[j] != ' ' && j < width) j++;
char function[j+1];
char params[width-j];
memCopy(line, function, j);
function[j] = 0;
memCopy((line + j+1), params, (width-j));
// macros:
if(strEquals(function, "jeq")){
if(cmp1 == cmp2) lineNum = strToInt(params) - 1;
continue;
}
if(strEquals(function, "jne")){
if(cmp1 != cmp2) lineNum = strToInt(params) - 1;
continue;
}
if(strEquals(function, "jge")){
if(cmp1 >= cmp2) lineNum = strToInt(params) - 1;
continue;
}
if(strEquals(function, "jle")){
if(cmp1 <= cmp2) lineNum = strToInt(params) - 1;
continue;
}
if(strEquals(function, "jlt")){
if(cmp1 < cmp2) lineNum = strToInt(params) - 1;
continue;
}
if(strEquals(function, "jgt")){
if(cmp1 > cmp2) lineNum = strToInt(params) - 1;
continue;
}
j = 0;
while(!strEquals(execCommandList[j],function) && !strEquals(execCommandList[j],"")) j++;
if(!strEquals(execCommandList[j],"")) (*execFunctionList[j])(params);
else {
ttprint("err: no such function: `");
ttprint(function);
ttprint("` of length:");
ttprintIntln(strLen(function));
break;
}
}
terminalMode = TERMINAL;
return;
}

// `seti registerIndex value`
void exec_seti(char* params){
int index = params[0] - '0';
iregisters[index] = strToInt( (params + 2) );
}

// `setc registerIndex value`
void exec_setc(char* params){
int index = params[0] - '0';
cregisters[index] = params[2];
}

// `printi registerIndex`
void exec_printi(char* params){
//printf("%d\n", iregisters[params[0] - '0']);
ttprintIntln(iregisters[params[0] - '0']);
}

// `printc registerIndex`
void exec_printc(char* params){
//printf("%c\n", cregisters[params[0] - '0']);
ttprintChar(cregisters[params[0] - '0']);
ttprintChar('\n');
}

// `addi operand operand destination
void exec_addi(char* params){
char a = params[0] - '0';
char b = params[2] - '0';
char c = params[4] - '0';
iregisters[c] = iregisters[a] + iregisters[b];
}

// `multi operand operand destination
void exec_multi(char* params){
char a = params[0] - '0';
char b = params[2] - '0';
char c = params[4] - '0';
iregisters[c] = iregisters[a] * iregisters[b];
}

// `randi limit destination
void exec_randi(char* params){
int i;
int limit = 10;
char index = 0;
for(i = 0; i < strLen(params); i++){
if(params[i] == ' '){
params[i] = 0;
limit = strToInt(params);
params[i] = ' ';
index = params[i+1] - '0';
break;
}
}
iregisters[index] = rand(limit);
}

void exec_inc(char* params){
iregisters[params[0] - '0'] += 1;
}

void exec_dec(char* params){
iregisters[params[0] - '0'] -= 1;
}

void exec_setcmp1(char* params){
cmp1 = iregisters[params[0] - '0'];
}
void exec_setcmp2(char* params){
cmp2 = iregisters[params[0] - '0'];
}

void exec_status(char* params){
int i;
ttprint("ireg:");
for(i = 0; i < 10; i++){
ttprintInt(iregisters[i]);
ttprintChar(',');
}
ttprintln("");
ttprint("creg:");
for(i = 0; i < 10; i++){
ttprintChar(cregisters[i]);
ttprintChar(',');
}
ttprintln("");
ttprint("cmp:");
ttprintInt(cmp1);
ttprintChar(',');
ttprintInt(cmp2);
ttprintln("");
}


void exec_null(char * params){

}

Loading

0 comments on commit 74a9dd5

Please sign in to comment.