Page 1 of 1

From PMode back to RMode

Posted: Tue Nov 11, 2008 9:33 am
by FlashBurn
I want to go from pmode back to rmode and have read the intel manuals, but my code is not working and I don´t know where the problem is.

I have this GDT:

Code: Select all

GDT:
	;null descriptor
	dw 0
	dw 0
	dw 0
	dw 0

	;code descriptor
	dw 0ffffh
	dw 0
	dw 9a00h
	dw 0cfh

	;data descriptor
	dw 0ffffh
	dw 0
	dw 9200h
	dw 0cfh
	
	;code 16bit descriptor
	dw 0xffff
	dw 0
	dw 0x9801
	dw 0
My code is some where behind 0x10000 and this is the code where I try to jump back:

Code: Select all

        mov eax,.rmode
	mov [.offset],ax

	mov eax,cr0
	and al,~1
	mov cr0,eax

	db 0xea
	dw 0x1000
.offset:
	dw 0
;----------------------------
;	rmode
align 16
.rmode:
use16
	jmp $
I do not jump to the 16bit segment, because this also doesn´t work.

Re: From PMode back to RMode

Posted: Tue Nov 11, 2008 9:37 am
by Combuster
You must jump to a 16-bit code segment before disabling PE to not screw over the CPU. Better show us that version so we can find the bugs in an algorithm that isn't dead upon arrival.

Re: From PMode back to RMode

Posted: Tue Nov 11, 2008 11:27 am
by FlashBurn
Yeah now it works, the problem was the address where I jumped to.

This is the working code:

Code: Select all

mov eax,.rmode
	mov [.offset],ax
	
	jmp 0x18:.pmode16b - 0x10000
;----------------------------
align 16
.pmode16b:
use16
	mov eax,cr0
	and al,~1
	mov cr0,eax

	db 0xea
.offset:
	dw 0
	dw 0x1000
;----------------------------
;	rmode
align 16
.rmode: