From PMode back to RMode

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
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

From PMode back to RMode

Post 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.
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:

Re: From PMode back to RMode

Post 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.
"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 ]
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: From PMode back to RMode

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