PMODE HELP

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
crazysurfmonkey

PMODE HELP

Post 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!
Kernel Panic

RE:PMODE HELP

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

RE:PMODE HELP

Post by Guest »

Ok thnaks i will try that
crazysurfmonkey

i need help again

Post 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
J. Weeks

RE:i need help again

Post 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
Guest

RE:i need help again

Post 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.
Kernel Panic

RE:i need help again

Post by Kernel Panic »

>Make sure you have right permissions set for the
>selectors in your IDT.
In your GDT, I mean..
Kernel Panic

RE:i need help again

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