Switching threads causing triple fault.
Posted: Wed Apr 24, 2013 5:49 pm
Ive been trying to implement very simple kernel threads as per the JamesM multitasking tutorial. Just to get a basic understanding of the concept before jumping into anything more complicated like full processes.
Obviously, my "multitasking" code is pretty much based off the code from the tutorial.
Unfortunately once tasking is initialized (but nothing yet forked), the second call to kthread_switch causes a triple fault.
The code for kthread_switch: http://pastebin.com/zf7YRJfX
Upon stepping through the code in GDB (Qemu), it is apparent that in the second call to kthread_switch() the if statement is the problem.
Looking at things more closely stepping through instruction my instruction in Bochs Debugger, the if statement is disassembled as:
Everything appears to run as expected until the JZ instruction, at which point the ESP reg gets trashed and always has the value: 0x5244C5B. The next step jumps to 0xFFFFFFF0 and causes a triple fault (No exception).
I find it odd that it is only at the JZ instruction, the "mov ebx, esp" never executes, but somehow ESP is being trashed?
Its always at the second call to kthread_switch and I cant understand why the jump would cause this?
Anyone notice something I dont? I would very much appreciate any input or advice.
Obviously, my "multitasking" code is pretty much based off the code from the tutorial.
Unfortunately once tasking is initialized (but nothing yet forked), the second call to kthread_switch causes a triple fault.
The code for kthread_switch: http://pastebin.com/zf7YRJfX
Upon stepping through the code in GDB (Qemu), it is apparent that in the second call to kthread_switch() the if statement is the problem.
Code: Select all
if(!current_thread) return;
Code: Select all
mov eax, dword ptr ds:0xC002101C
test eax, eax
jz 0xC000172B
mov ebx, esp
mov dword ptr ss:[ebp-12],ebx
I find it odd that it is only at the JZ instruction, the "mov ebx, esp" never executes, but somehow ESP is being trashed?
Its always at the second call to kthread_switch and I cant understand why the jump would cause this?
Anyone notice something I dont? I would very much appreciate any input or advice.