I've been messing around with some bugs for weeks now and I think I found out what is causing it. However I need some help in solving it, I have no idea how to...
Right now all my processes are represented by a function (which is the program it runs). Most things seems to work, hard to say when a big flaw is in the program... but I found out that the local variables of the program functions aren't saved when context switching. I'm fairly sure that it has something to do with the stack, everything else seems ok. It's just that the local variables aren't preserved.
Here's an example of a process:
Code: Select all
Process A(char *arg_str) {
char str[5];
int i;
for (i=0;i<5;i++) str[i] = arg_str[i];
while (1) {
// ...
printString(str);
// ...
}
}
So how can I save all local variables so I can use them like normal the next time it switches to this process? The interrupt handler is ok, I save all hardware registers and restore them. The thing i'm a little unsure about is when creating a process. This is how I initialize the regs for a PCB when creating a PCB.
...
PCB.REGS.EPC = Function pointer;
PCB.REGS.SP = Stack;
Where Stack is a char[0x9000]. I'm using MIPS by the way.
Thankful for help.