So, I've recently picked up OS development again, and decided to add basic command functionality to my OS.
Here is the code I have so far:
Code:
char buf[1024];
short index;
/* initialize the above variables w/ memset, index=0 */
void kb_irq_handler(struct regs *r) {
uint8_t scancode = inb(0x60);
char c = scanToAscii(scancode);
putchar(c);
if(index == 1023) {
print("Buffer overflow!");
memset(&buf, '\0', 1024);
index = 0;
return;
} else if(c == '\n') {
buf[index] = '\0';
test();
index = 0;
memset(&buf, '\0', 1024);
} else {
buf[index] = c;
index++;
}
}
void test() {
char* str = &buf;
writestring(buf);
writestring("\n$ ");
}
This code is meant to read a line and print that out again, but it doesn't work that way, and I'm reasonably sure it's not actually reading a line. Using the QEMU monitor, I printed out the data at buf; it seems to be just junk data. I'm quite sure there's a dumb mistake in my code, but not sure where it is. Could someone help point out where I'm blundering?