I have a simple memory system in place for my 64 bit OS and I'm trying to get context switching working. I have written a routine switch_tasks() which saves and restores the rsp, rbp and rflags register. The context switch is done implicitly by switching the kernel stacks.
To test this code, I'm trying to run it with two functions f1() and f2() in the kernel which voluntarily call the switch_tasks() function to yield processor. I'm setting up their initial pcbs and adding them to the process list and invoking the switch_tasks() method.
I'm getting some sort of context switching. What is happening is this --
My two functions are --
Code: Select all
void f1()
{
int x = 0;
while(x<10)
{
kernel_print("foo! %d\n", x++);
switch_tasks();
}
}
void f2()
{
int y = 0;
while(y<10)
{
kernel_print("bar! %d\n", y++);
switch_tasks();
}
}
Code: Select all
foo! 0
bar! 0
foo! 2
bar! 2
foo! 4
bar! 4
.
.
.
Thanks,
DrSL.