multitasking problems
multitasking problems
Hi.
I already have implemented stack-based multitasking in my kernel and it works fine. The problem I am having is that when i do anything big like call the context creation function, when a task switch occurs i get sent to eip=0 instead of the proper location. For some reason my whole stack turns to 0! I don't think this is a problem with my page allocator because the pages are all different. So what else could be going wrong?
I already have implemented stack-based multitasking in my kernel and it works fine. The problem I am having is that when i do anything big like call the context creation function, when a task switch occurs i get sent to eip=0 instead of the proper location. For some reason my whole stack turns to 0! I don't think this is a problem with my page allocator because the pages are all different. So what else could be going wrong?
Hi,
When I had this problem it was, indeed, my page allocator in Bochs. I have a few questions that may help:
* What happens on real hardware?
* What does your new task's stack look like before it runs for the first time? Is it all just zero's even after you have just created it (try reading it back)?
* Is your stack aligned? (eg, you are reading a value in to eip that you actually wanted in eax, or similar)
*
* Is the first task switch ok or does eip look wrong even at this point?
* Do you have the correct values in ss0 and esp0 in your tss if you are mixing privileges?
* Are you using different CR3 values? If so, is your new page directory valid?
Cheers,
Adam
When I had this problem it was, indeed, my page allocator in Bochs. I have a few questions that may help:
* What happens on real hardware?
* What does your new task's stack look like before it runs for the first time? Is it all just zero's even after you have just created it (try reading it back)?
* Is your stack aligned? (eg, you are reading a value in to eip that you actually wanted in eax, or similar)
*
* Is the first task switch ok or does eip look wrong even at this point?
* Do you have the correct values in ss0 and esp0 in your tss if you are mixing privileges?
* Are you using different CR3 values? If so, is your new page directory valid?
Cheers,
Adam
Also check what happens if you double your stack size. It could be that you are simply recursing too far, or allocating too much local variables, and run out of stack space, hence overwriting some stuff.
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Try disabling the multitasker when you create a new process. I had a problem that whenever I was trying to create a new process and the process creating that process got preempted, the system would crash because of an invalid process table. Moral of the story is, make sure that there is NO access of the process table during creation ![Very Happy :D](./images/smilies/icon_biggrin.gif)
![Very Happy :D](./images/smilies/icon_biggrin.gif)
I think the problem actually might be that my scheduler function is trying to execute the new thread while it is still being created. This would explain eip being 0 as qemu sets all memory to 0, i think. Anyway, I think if I disable the scheduler whilst i am creating the new thread it will work.
I don't think the stack size is an issue because as i said before, i get a page fault. If my stack was too small my os should triple fault because my page fault handler uses the stack.
[EDIT]
pcmattman, yeah I just realized that I had disabled the scheduler in my previous thread creations.
I don't think the stack size is an issue because as i said before, i get a page fault. If my stack was too small my os should triple fault because my page fault handler uses the stack.
[EDIT]
pcmattman, yeah I just realized that I had disabled the scheduler in my previous thread creations.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
What I actually meant was that in my OS I do something like this:
It just means that your process creation doesn't get preempted and you don't get left with a corrupted process table. Good to hear you got it working, though.
Code: Select all
void CreateProcess( ... )
{
disablemt();
...
enablemt();
}
This was about THE stupidest mistake ever.
I set the page tables wrong.
I set the last entry of the pdt to point to itself so i can access the page tables at 0xFFC00000 and the pdt at 0xFFFFF000. However, in my newly created set of page tables for the new thread, i never set the page tables to the correct physical address. I set it to the old address. But now everything works perfectly.
I set the page tables wrong.
I set the last entry of the pdt to point to itself so i can access the page tables at 0xFFC00000 and the pdt at 0xFFFFF000. However, in my newly created set of page tables for the new thread, i never set the page tables to the correct physical address. I set it to the old address. But now everything works perfectly.