Skip to content

Commit 74a9dd5

Browse files
committed
Brand-new interpreter for an ASM-esque language. Removed some shell functionality to make space.
1 parent 53017be commit 74a9dd5

File tree

7 files changed

+279
-221
lines changed

7 files changed

+279
-221
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ KevinOS Notes:
44
Compilation:
55
------------
66

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

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

11-
+ 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).
11+
+ 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).
1212

1313
Features:
1414
---------
1515

16-
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.
16+
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.
1717

1818
Unlicense:
1919
----------

bootloader_stage2.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
;BIOS_DATA_AREA equ 0x400
1010
KERNEL_ADDRESS equ 0x200
11-
NUM_SECTORS equ 53
11+
NUM_SECTORS equ 55
1212

1313
; GDT definitions
1414
gdt_start:

files/first.exe

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
seti 0 0;
2+
seti 1 10;
3+
setcmp2 1;
4+
# line 3
5+
inc 0;
6+
printi 0;
7+
setcmp1 0;
8+
jlt 3;
9+
setc 0 !;
10+
printc 0;
11+
status;

kernel.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int ttx;
5050
int tty;
5151
char prompt;
5252
int promptColor;
53-
int modifier[6];
53+
char modifier[6];
5454
volatile unsigned long int ticks;
5555
int commandLength;
5656
char counter;
@@ -77,10 +77,10 @@ void main(){
7777
int i = 0;
7878
commandLength = 0;
7979
counter = '0';
80-
while(modifier[i] != 0){
81-
modifier[i] = 0;
82-
i++;
83-
}
80+
81+
memFill(modifier, 0, 5);
82+
memFill(fileBuffer, 0, height*width);
83+
8484
modifier[INSERT] = 1;
8585
modifier[CAPSLOCK] = 0;
8686
terminalMode = TERMINAL;
@@ -228,8 +228,6 @@ void editor_keyPressed(unsigned char code, char c){
228228
}
229229
}
230230
ttprintChar(c);
231-
232-
233231
}
234232
void interpreter_keyPressed(unsigned char code, char c){}
235233

sh_exec.c

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
#include "stdio.h"
3+
#include "util.c"
4+
5+
#define width 80
6+
#define height 18
7+
*/
8+
9+
int iregisters[10];
10+
char cregisters[10];
11+
int cmp1, cmp2;
12+
13+
void exec_seti(char*);
14+
void exec_setc(char*);
15+
void exec_printi(char*);
16+
void exec_printc(char*);
17+
void exec_addi(char*);
18+
void exec_multi(char*);
19+
void exec_null(char*);
20+
void exec_randi(char*);
21+
void exec_inc(char*);
22+
void exec_dec(char*);
23+
void exec_setcmp1(char*);
24+
void exec_setcmp2(char*);
25+
void exec_status(char*);
26+
27+
char *execCommandList[] = { "seti", "setc", "printi", "printc", "addi", "multi", "randi", "inc", "dec", "setcmp1", "setcmp2", "status" , ""};
28+
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};
29+
30+
void sh_exec(char* params){
31+
terminalMode = INTERPRETER;
32+
char line[width+1];
33+
line[width] = 0;
34+
int index = 0;
35+
for(index = 0; index < 10; index++){
36+
iregisters[index] = 0;
37+
cregisters[index] = 0;
38+
}
39+
40+
//iterate through the buffer
41+
int lineNum;
42+
for(lineNum = 0; lineNum < height; lineNum++){
43+
// read line, removing null chars along the way:
44+
int i = 0;
45+
index = lineNum * width;
46+
// lines must not have the first char blank
47+
// also don't read comments
48+
if(fileBuffer[index] == ' ' || fileBuffer[index] == 0 || fileBuffer[index] == '#')
49+
continue;
50+
memFill(line,0,width);
51+
while(fileBuffer[index] != ';' && i < 80){
52+
if(fileBuffer[index] != 0){
53+
line[i] = fileBuffer[index];
54+
i++;
55+
}
56+
index++;
57+
}
58+
if(strEquals(line,"")) continue;
59+
// now `line` contains the command (function + args) to be interpreted
60+
// isolate out the function part by splitting on the first space
61+
int j = 0;
62+
while(line[j] != ' ' && j < width) j++;
63+
char function[j+1];
64+
char params[width-j];
65+
memCopy(line, function, j);
66+
function[j] = 0;
67+
memCopy((line + j+1), params, (width-j));
68+
// macros:
69+
if(strEquals(function, "jeq")){
70+
if(cmp1 == cmp2) lineNum = strToInt(params) - 1;
71+
continue;
72+
}
73+
if(strEquals(function, "jne")){
74+
if(cmp1 != cmp2) lineNum = strToInt(params) - 1;
75+
continue;
76+
}
77+
if(strEquals(function, "jge")){
78+
if(cmp1 >= cmp2) lineNum = strToInt(params) - 1;
79+
continue;
80+
}
81+
if(strEquals(function, "jle")){
82+
if(cmp1 <= cmp2) lineNum = strToInt(params) - 1;
83+
continue;
84+
}
85+
if(strEquals(function, "jlt")){
86+
if(cmp1 < cmp2) lineNum = strToInt(params) - 1;
87+
continue;
88+
}
89+
if(strEquals(function, "jgt")){
90+
if(cmp1 > cmp2) lineNum = strToInt(params) - 1;
91+
continue;
92+
}
93+
j = 0;
94+
while(!strEquals(execCommandList[j],function) && !strEquals(execCommandList[j],"")) j++;
95+
if(!strEquals(execCommandList[j],"")) (*execFunctionList[j])(params);
96+
else {
97+
ttprint("err: no such function: `");
98+
ttprint(function);
99+
ttprint("` of length:");
100+
ttprintIntln(strLen(function));
101+
break;
102+
}
103+
}
104+
terminalMode = TERMINAL;
105+
return;
106+
}
107+
108+
// `seti registerIndex value`
109+
void exec_seti(char* params){
110+
int index = params[0] - '0';
111+
iregisters[index] = strToInt( (params + 2) );
112+
}
113+
114+
// `setc registerIndex value`
115+
void exec_setc(char* params){
116+
int index = params[0] - '0';
117+
cregisters[index] = params[2];
118+
}
119+
120+
// `printi registerIndex`
121+
void exec_printi(char* params){
122+
//printf("%d\n", iregisters[params[0] - '0']);
123+
ttprintIntln(iregisters[params[0] - '0']);
124+
}
125+
126+
// `printc registerIndex`
127+
void exec_printc(char* params){
128+
//printf("%c\n", cregisters[params[0] - '0']);
129+
ttprintChar(cregisters[params[0] - '0']);
130+
ttprintChar('\n');
131+
}
132+
133+
// `addi operand operand destination
134+
void exec_addi(char* params){
135+
char a = params[0] - '0';
136+
char b = params[2] - '0';
137+
char c = params[4] - '0';
138+
iregisters[c] = iregisters[a] + iregisters[b];
139+
}
140+
141+
// `multi operand operand destination
142+
void exec_multi(char* params){
143+
char a = params[0] - '0';
144+
char b = params[2] - '0';
145+
char c = params[4] - '0';
146+
iregisters[c] = iregisters[a] * iregisters[b];
147+
}
148+
149+
// `randi limit destination
150+
void exec_randi(char* params){
151+
int i;
152+
int limit = 10;
153+
char index = 0;
154+
for(i = 0; i < strLen(params); i++){
155+
if(params[i] == ' '){
156+
params[i] = 0;
157+
limit = strToInt(params);
158+
params[i] = ' ';
159+
index = params[i+1] - '0';
160+
break;
161+
}
162+
}
163+
iregisters[index] = rand(limit);
164+
}
165+
166+
void exec_inc(char* params){
167+
iregisters[params[0] - '0'] += 1;
168+
}
169+
170+
void exec_dec(char* params){
171+
iregisters[params[0] - '0'] -= 1;
172+
}
173+
174+
void exec_setcmp1(char* params){
175+
cmp1 = iregisters[params[0] - '0'];
176+
}
177+
void exec_setcmp2(char* params){
178+
cmp2 = iregisters[params[0] - '0'];
179+
}
180+
181+
void exec_status(char* params){
182+
int i;
183+
ttprint("ireg:");
184+
for(i = 0; i < 10; i++){
185+
ttprintInt(iregisters[i]);
186+
ttprintChar(',');
187+
}
188+
ttprintln("");
189+
ttprint("creg:");
190+
for(i = 0; i < 10; i++){
191+
ttprintChar(cregisters[i]);
192+
ttprintChar(',');
193+
}
194+
ttprintln("");
195+
ttprint("cmp:");
196+
ttprintInt(cmp1);
197+
ttprintChar(',');
198+
ttprintInt(cmp2);
199+
ttprintln("");
200+
}
201+
202+
203+
void exec_null(char * params){
204+
205+
}
206+

0 commit comments

Comments
 (0)