Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I have a quick question. I am writing the 3rd revision of my bootloader and am attempting to task switch to v86 mode. However, it always seems to page fault when executing the task. I do not understand why, though.
; go into v8086 mode
push dword 0x0 ; real mode gs
push dword 0x0 ; real mode fs
push dword 0x0 ; real mode ds
push dword 0x0 ; real mode es
push dword 0x0 ; real mode ss
push dword 0xffff ; real mode esp
push dword 0x20002 ; real mode eflags
push dword 0x0 ; real mode cs
push dword stage3 ; real mode eip
iret
bits 16
stage3:
hlt
jmp $
Running it through bochs debugger, we get to the hlt instruction. The very next instruction is my page fault exception handler being executed.
It seems to work fine with or without paging (Even when I add alot more code); I only get a page fault when I switch to v86 mode. (ie, if I comment out the IRET, everything will work fine even with paging.)
Does anyone have any suggestions on where to look next?
Thanks!
Last edited by neon on Sun Mar 30, 2008 10:35 am, edited 2 times in total.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
CR2 points to the HLT instruction in the v86 task. The error code is 101b. With regards to what the intel manuals state reguarding the error code bits; I am not seeing how this error code is possible to get as I am in ring 0 and the error code says Im in user mode (Bit 2) :/
In interesting note is, if the eflags image is 0x20202 instead of 0x20002 when pushing the information on the stack for the task switch, I get a double fault.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Have you set the u/s bit of the page of the code which is running. If not, you will get a PFE. Could you run in Bochs and show the final register dump, please?
neon wrote:In interesting note is, if the eflags image is 0x20202 instead of 0x20002 when pushing the information on the stack for the task switch, I get a double fault.
Argh. Never mind about this, I know what it was happening. (0x20202 sets IF. And because I dont have the PIT remapped, IRQ0 still fires my double fault exception handler.)
I might also know what the cause of the initil problem is. I will post again to let everyone know if I find the problem. I am still looking for suggestions though!