I was having a problem at the initial stages of multitasking where initially transferring control to a user process. Here's the flow of things real quick:
Initial "process" (pre-multitasking)
Multitasking init, spawns a new task and keeps initial task as the idle task (pid=0).
The new task (pid=1) is used to initialize the last of the kernel level things (loading drivers, and things of that sort).
The new task is forked (pid=2), and the initial user process is executed (ATM it is just a basic shell, but that irrelevant)
The other task (pid=1) is killed, therefore only the user process and the idle task are alive.
Now, my problem comes in when forking the first multitasking task. This task is a kernel task, and is therefore using a kernel stack. This kernel stack is located in shared memory (kernel heap). When forking the task, I cannot simply copy the contents of that stack, as all kernel stacks are not located in the same positions. The EBP values are all screwy on the new kernel stack. I did this to rectify it:
Code: Select all
// the EBP values on the stack need to be fixed for the new stack! This risks clobbering good data, but its the best I can do at the moment...
for(u32 i = 0; i < (child->kernel_stack_size/4); ++i){
if( ((u32*)parent->kernel_stack)[i] >= ((u32)parent->kernel_stack) && ((u32*)parent->kernel_stack)[i] < ((u32)parent->kernel_stack +parent->kernel_stack_size) )
((u32*)child->kernel_stack)[i] += -((u32)parent->kernel_stack) + ((u32)child->kernel_stack);
}
This works, but I'm afraid I might accidentally clobber good data (this would have to be a coincidence of data lining up in that area, but it is possible).
My Question: Is this a large flaw in my design or is this predicament normal?
Thanks for all your help; you guys are great.
-Caleb