page fault?

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.
Post Reply
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

page fault?

Post by neon »

Hey everyone,

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.

Here is the code:

Code: Select all

	;	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();}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

The faulting address points where?
"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 ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

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();}
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

In v86 mode, you are always in ring 3.

Cheers,
Adam
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

AJ wrote:Hi,

In v86 mode, you are always in ring 3.

Cheers,
Adam
Testing it with eflags==100011000000000010b (ring3) creates the same problem; CR2 still points to IRET...

Thanks for the suggestion, though. I will keep the v86 task to run in ring3 as you are correct about that.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

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?

Cheers,
Adam
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

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!
Post Reply