It's really a great tutorial
I've finished all chapters.
But things break down when i add a new system call to it.
I'm adding syscall_fork(). but child task's stack always break down.
After some debuggings, i notice that there lacks something in tutorial's fork() (http://www.jamesmolloy.co.uk/tutorial_h ... sking.html)
inside its fork(),
Code: Select all
// We could be the parent or the child here - check.
if (current_task == parent_task)
{
// We are the parent, so set up the esp/ebp/eip for our child.
u32int esp; asm volatile("mov %%esp, %0" : "=r"(esp));
u32int ebp; asm volatile("mov %%ebp, %0" : "=r"(ebp));
new_task->esp = esp;
new_task->ebp = ebp;
new_task->eip = eip;
// All finished: Reenable interrupts.
asm volatile("sti");
return new_task->id;
}
since new_task still using parent_task's stack after such code.
they should point to somewhere inside new_stack->kernel_stack.
we need to first copy_kernel_stack from parent task to child, and fix the ebp,
then write:
Code: Select all
u32int offset = new_task->kernel_stack - parent_task->kernel_stack;
new_task->esp = esp + offset;
new_task->ebp = ebp + offset;
http://www.jamesmolloy.co.uk/tutorial_h ... 0Mode.html
btw, is this forum's moderator "JamesM" the author of the tutorial, you're my idol!