Page 1 of 1

PMODE HELP

Posted: Mon Jan 14, 2002 12:00 am
by crazysurfmonkey
hey i need some help! I am writing a boot sector and my computer resets when I try to change it to pmode Can anyone help! Here is the block of code i used to switch:
cli
o32 LGDT[gdtr]
mov eax, cr0
or al,1
mov cr0,eax
jmp go_pm

[bits 32]
go_pm:
mov ax,data_selector
mov ds,ax
mov es,ax
mov ax,video_selector
mov gs,ax
mov word[GS:0], 0x641
What is the problem? Is it the way i setup the GDT?
Thanks!

RE:PMODE HELP

Posted: Tue Jan 15, 2002 12:00 am
by Kernel Panic
...
> mov eax, cr0
> or al,1
> mov cr0,eax
> jmp go_pm
You need a far jump here instead of a near one.
Something like this:
db 0EAh ; a far jump opcode
dd go_pm ; EIP
dw 8 ; Selector; change to
whatever you code selector is.
>
>[bits 32]
>go_pm:
> mov ax,data_selector
...

RE:PMODEĀ HELP

Posted: Tue Jan 15, 2002 12:00 am
by Guest
Ok thnaks i will try that

i need help again

Posted: Tue Jan 15, 2002 12:00 am
by crazysurfmonkey
Ok i did what you said but my computer still reset this is the code now after i changed it:

; Enter Proctected Mode
cli
o32 LGDT[gdtr]
mov eax, cr0
or al,1
mov cr0,eax
;This is what i did i changed the jmp go_pm to this:
db 0EAh ; a far jump opcode
dd go_pm ; EIP
dw code_selector ; Selector; change to whatever you code selector is.

[bits 32]
go_pm:
mov ax,data_selector
mov ds,ax
mov es,ax
mov ax,video_selector
mov gs,ax
mov word[GS:0], 0x641
; Halt system
repeat:
jmp repeat
Thanks

RE:i need help again

Posted: Tue Jan 15, 2002 12:00 am
by J. Weeks
>On 2002-01-15 06:53:34, crazysurfmonkey wrote:
>Ok i did what you said but my computer still reset this is the code now after i changed it:

99.9% of the time, it's a problem with your
GDT, LDT or IDT.

Jeff

RE:i need help again

Posted: Wed Jan 16, 2002 12:00 am
by Guest
>On 2002-01-15 06:53:34, crazysurfmonkey wrote:
>Ok i did what you said but my computer still reset
>this is the code now after i changed it:
Make sure you have right permissions set for the selectors in your IDT. The code selector should have the execute permission and the video_selector should have read and write permissions.
You could try running your code under a PC emulator to see where the exception happens.

RE:i need help again

Posted: Wed Jan 16, 2002 12:00 am
by Kernel Panic
>Make sure you have right permissions set for the
>selectors in your IDT.
In your GDT, I mean..

RE:i need help again

Posted: Thu Jan 17, 2002 12:00 am
by Kernel Panic
Well, I've just found out one more thing. After the
bit 0 of cr0 is set, you are running in pmode, but
still in a 16-bit code segment. So, in order to do
a far 32-bit jump, you have to add a 66h before a
jump. Here is how I did this (hope, you understand
the AT&T syntax =) ):
...
lgdt GdtPtr /* Load GDT */
movl %cr0,%eax
orb $1,%al
movl %eax,%cr0 /* Switch to the protected mode */

.byte 0x66 /* We are still 16-bit */
.byte 0xEA /* Far jump */
.int IntoProtMode
.short 0x8 /* Selector */

.code32 /* Our code segment is 32-bit now */
IntoProtMode:

movw $0x10,%ax /* Set up all segment registers */
...
Now if you have your GDT set up properly, it
will work.