Page 1 of 1

page fault?

Posted: Sun Mar 30, 2008 10:33 am
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!

Posted: Sun Mar 30, 2008 10:35 am
by Combuster
The faulting address points where?

Posted: Sun Mar 30, 2008 11:32 am
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.

Posted: Sun Mar 30, 2008 12:14 pm
by AJ
Hi,

In v86 mode, you are always in ring 3.

Cheers,
Adam

Posted: Sun Mar 30, 2008 12:44 pm
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.

Posted: Sun Mar 30, 2008 12:47 pm
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

Posted: Sun Mar 30, 2008 12:59 pm
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!