Pmode switching in a CALL procedure

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
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Pmode switching in a CALL procedure

Post by inflater »

Hello,
I have a little problem with the on-the-fly pmode-realmode switching.

This is a function I use to switch from real mode to protected:

Code: Select all

SwitchToPmode:						;Prepni do pmode
	pushad
	cli						;Zakáž prerušenia
	lgdt [gdtr]					;NaÄ
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

When you do the call you are in real mode, it push ip containing the offset of the instruction following the call, dec the stack by 2, inserts the offset of the called proc into the ip (plus flushes the processor's prefech instruction queue).

Now on the ret it reverser's the above, can you not see a problem
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

I tried omitting mov ss,ax from the SwitchToPmode function and then after the RET it returns where it should, but in Bochs debugger the instrunctions are corrupted.

This is my code

Code: Select all

call SwitchToPmode

mov ax,10h
sub ax,6
div ax
jmp $
but Bochs debugger shows this:

Code: Select all

(after the RET from SwitchToPmode)
mov eax, 0xe8830010 (should be mov eax,0x10)
push es
div eax, eax
jmp .+0xfffffffe (jmp $)
The funny thing is, that in function SwitchToPmode are calls to "call unmask_irqs" etc., which works and returns properly, but the return from SwitchToPmode seems to be bad.

I tried to put "align 4" in the KERNEL.ASM and change the stack to 0x5F:0xF000 which seems to be free but still no luck...
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Well, the only way to do this is a FASM macro... which seems to work! Yay! 8)
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

A macro place the macro code where you put the name of the macro.
So using a macro is no differant than placing the code where you put the macro name.
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

Yes, I've saw that when I noticed a X-times increased length of the kernel :)
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
Post Reply