I've now implemented my multitasking so far, that it works with a single process running in userspace, but once I add another one I get a page fault.
My initial page directory is set up like this:
- 0x00000000 - 0x000100000 the lower memory, mapped for kernel access
- 0xC0000000 - 0xFFC000000 the kernel memory area, mapped with kernel access. I'm already creating all tables here to make sure any change to the kernel area happens in all contexts.
- 0xFFC00000 - end, the recursively mapped directory
Now, I'm setting up two processes doing the following
- Cloning all kernel-access dir entries to a new directory entry, and set entry 1023 to the new dir
- Creating a kernel stack in that new directory at 0xBFFFF000, putting the initial registers on it
- Creating a user stack at 0xBFFFE000, for the process itself
- Creating some test loop at 0x60000000, and setting EIP to this location
That all works fine so far, but only if I have just one process. The problem occurs in my scheduler:
Code: Select all
Context* Scheduler::handle(Context* context) {
if (current == 0) {
current = first;
} else {
current->context = context;
current = current->next;
if (current == 0) {
current = first;
}
}
Logger::println("preparing switch from context: %h to context: %h", context,
current->context);
Logger::println(" setting page directory: %h", current->pageDirectory);
PagingUtil::switchToDirectory(current->pageDirectory);
Logger::println(" setting ESP0: %h", current->esp0);
GDTInitializer::setTssEsp0(current->esp0);
return current->context;
}
Code: Select all
preparing switch from context: 0xC0007F78 to context: 0xBFFFFFB8
setting page directory: 0x3FFF3000
setting ESP0: 0xC0000000
returning to POPs and IRET // this message comes from the request dispatcher
preparing switch from context: 0xBFFFFFB8 to context: 0xBFFFFFB8
setting page directory: 0x3FFF9000
[panic] exception: page fault
eip: 0x00000001 eflags: 0x00000046
eax: 0x3FFF9000 ebx: 0x00000000
ecx: 0x00000000 edx: 0x00000000
intr: 0x0000000E error: 0x00000000
Does one of you have an idea what might be going wrong?
Thanks in advance
Greets, Max