Why this is happening I don't understand. I'm betting it's something to do with my C code, if anything. Seeing as it's a kernel that's doing the pagefaulting, but most likely resulting from bad code, I figured asking here would be a good idea.
Here is my command interpreter function command_interpret(). The first parameter is contains whatever the user has typed in and is called from the keyboard driver.
Code: Select all
char echocmd[] = "echo ";
...
// here we have a few other commands as well as the echocmd variable
// and a few functions to be called when some commands are executed
// pay no mind to this area, it's unimportant to the issue at hand
...
int command_interpret(char *buffer) {
// debug code, comment out if you don't need it
//putln(buffer);
kbdisable();
if (strcmp(buffer,hello) == 0) {
putln("Hello World!");
} else if (strcmp(buffer,ver) == 0) {
putln("Emerald kernel-0.1.5 (generic)");
} else if (strcmp(buffer,halt) == 0) {
puts("System halted, it is now safe to turn off the computer.");
for(;;);
} else if (strcmp(buffer,uptimecmd) == 0) {
getuptime();
} else {
// Here, we have the invalid command error, and we also have
// space to check for commands that require substrings.
if (strncmp(buffer,echocmd,5) == 0) {
putln(strtrun(buffer,strlen(echocmd))); /////////////////////////////////////// I believe this is the problematic line. //////////////////
} else {
putln("Invalid command."); // I'll probably change this later. Let's get filesystem support in first.
}
}
putln(" ");
prompt();
kbenable();
return 0;
}
You're probably wondering what strtrun() does. Basically it returns the value of the first parameter NOT INCLUDING the first few characters (defined by the second parameter). strtrun means String Truncate. Here's the code for it:
Code: Select all
char *strtrun(char *trn, int s) {
int l;
char *tr;
for(l=0; l < s; l++) {
tr[l] = trn[l];
}
return tr;
}
Code: Select all
size_t strlen(const char *str)
{
size_t retval;
for(retval = 0; *str != '\0'; str++) retval++;
return retval;
}
Exactly what did I do wrong here, and why would it be page faulting? And before you ask, NO, I do not have a proper stack-trace function in my panic() to show where the pagefault occured. I probably should, but at this point I can't provide the information, and as stated earlier I'm fairly certain that it was a mistake in my C code.
Any ideas on what's triggering the pagefault?