Page 1 of 2
Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 1:05 pm
by Matt
I have some code which is suppose to switch from Pmode to Rmode and back (so I can use interrupts), but when I try to call an interrupt when I switch back into real mode, I get a "prefetch EIP > CS.Limit" error in bochs. here's the code:
push ds ; save protected mode segments
push es
dec ax ; switch back to real mode
mov cr0, eax ; by toggling bit again
sti
mov ax, 13h
int 10h
cli
mov eax, cr0 ; switch to pmode by
inc ax ; toggling last bit
mov cr0, eax
pop ds ;Restore PMode Segments
pop es
BTW, taking out the push and pops didn't make a difference. It switches back to real mode then back into pmode just fine, it just crashes When I try to use an iterrupt. Any ideas on what I'm stupidly doing wrong?
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 1:12 pm
by frank
did you do a far jump after switching to pmode?
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 1:13 pm
by Matt
frank wrote:
did you do a far jump after switching to pmode?
um, no.....
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 1:29 pm
by frank
do that, else it won't set-up cs
(a far jump sets up it automatic)
btw
like this:
jmp placeingdt:main32
bits32
main32: ;switch to realmode
btw you must make a gdt table for that
then it'll work. (if you don't do a far jump its still in 16bit real mode)
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 2:11 pm
by Matt
So would it be re-written something like this:
[bits 32]
jmp placeingdt:damnmain32
damnmain32:
push ds ; save protected mode segments
push es
dec ax ; switch back to real mode
mov cr0, eax ; by toggling bit again
sti
mov ax, 13h
int 10h
cli
mov eax, cr0 ; switch to pmode by
inc ax ; toggling last bit
mov cr0, eax
pop ds ;Restore PMode Segments
pop es
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 2:14 pm
by frank
Try this:
; switching to pmode
jmp codesel:main32
[bits 32]
main32:
push ds ; save protected mode segments
push es
dec ax ; switch back to real mode
mov cr0, eax ; by toggling bit again
sti
mov ax, 13h
int 10h
cli
mov eax, cr0 ; switch to pmode by
inc ax ; toggling last bit
mov cr0, eax
pop ds ;Restore PMode Segments
pop es
gdtr
dw gdt_end-1
dd gdt
gdt
nullsel equ $-gdt
gdt0
dd 0
dd 0
codesel equ $-gdt
dw 0ffffh
dw 0h
db 0h
db 09ah
db 0cfh
db 0h
datasel equ $-gdt
dw 0ffffh
dw 0h
db 0h
db 092h
db 0cfh
db 0h
gdt_end
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 2:56 pm
by Matt
[attachment deleted by admin]
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 2:58 pm
by Matt
BTW, I get that error on this line: dw gdt_end-1
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 3:18 pm
by frank
>NASM says it doesnt support non-32bit relocations
>I'll attach my code. Its a Pmode kernel. My bootloader sets up >pmode, gdt, etc...
yes it does, how else did I switch to pmode?
>BTW, I get that error on this line: dw gdt_end-1
hmm, that's strange..
what error?
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 4:19 pm
by Matt
When nasm tried to compile "dw gdt_end-1" it said "COFF format does not support non-32-bit relocations"
Re:Pmode->Realmode Switching Troubble
Posted: Thu Aug 08, 2002 4:27 pm
by Matt
I removed the line "dw gdt_end-1" and it assembles just fine. It gives me a 3rd exception with no resolution error when I try to call int 10h still though :-\
Re:Pmode->Realmode Switching Troubble
Posted: Fri Aug 09, 2002 1:10 am
by frank
aah now I see....
that format your using does not support 16bit assembly, so that wont work.
Use the flat binary format... -f bin
Re:Pmode->Realmode Switching Troubble
Posted: Fri Aug 09, 2002 8:15 am
by crazybuddha
matt, you can't just switch back to real mode and back because CS will get whacked. In fact, it will get whacked simply from having interrupts enabled (as any interrupts get handled)
You load some random value from ax into cr0. You must preserve all the top bits of cr0 and toggle only the bottom one.
You got your GDT from frank and he may not have been finished sorting it out. Perhaps it is fine, but make sure you know what it all means. Otherwise, you are fighting a losing battle.
There are other issues perhaps, but these are enough to ensure failure.
Re:Pmode->Realmode Switching Troubble
Posted: Fri Aug 09, 2002 9:50 am
by Krom
You only wants to go back to real mode to make a ax=0x13, int 0x10? If this is what you wants dont go back to real more, instead, do the int 0x10 in the boot sector, it is only 5 bytes, i think you have 5 bytes free in the boot sector, isnt it?
Re:Pmode->Realmode Switching Troubble
Posted: Fri Aug 09, 2002 9:54 am
by frank
no he wants to go to vesa....
ves a= > than 320x200 256
( 640 * 480 * 16k,
until somewhere in the 1800x1200 (my resolution
))