Page 1 of 1
Pmode switching in a CALL procedure
Posted: Fri Jun 13, 2008 1:54 pm
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Ä
Posted: Fri Jun 13, 2008 6:08 pm
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
Posted: Sat Jun 14, 2008 2:32 am
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...
Posted: Sat Jun 14, 2008 6:25 am
by inflater
Well, the only way to do this is a FASM macro... which seems to work! Yay!
Posted: Sat Jun 14, 2008 11:03 am
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.
Posted: Sat Jun 14, 2008 11:14 am
by inflater
Yes, I've saw that when I noticed a X-times increased length of the kernel