Switching to Pmode on real pc results in reboot (works fine on emulator)

Started by Warsocket, March 24, 2006, 07:35:30 PM

Previous topic - Next topic

Warsocket

Hi,
I've made a somple boot sector that displays RM  on the screen in real mode, and after a keystroke it goes to Protected mode ands displays PM (Just tot practice Pmode).

If I run my code in Bochs( x86 Emulator) It runs just fine, but if I worte the code to a boot floppy and boot the pc reboots when I perform the long jump to 'serialize' the Pc with Pmode

ANyone any Idea how to fix this,

Thanks in advance

(btw It's written for Nasm compiler)


bits 16
org 0x07c00             ; Start address 0000:7c00
jmp start               ; Jump to start of boot routine & skip other data

dummy:

.586
.MMX

start:

mov ax, 0003h
int 10h

mov ax,0b800h
mov es, ax

xor bx, bx
mov dword [es:bx], 0f4d0f52h


mov ax, 0
int 16h


cli
lgdt [gdtr]

mov eax, CR0
or eax, 1
mov CR0, eax

jmp codesel:protc


bits 32
protc:

xor ax, ax
mov fs, ax

mov ax, datasel
mov ds, ax
mov es, ax
mov ss, ax

jmp codesel:nxt
nxt:


mov esp, 1024*5     ; at 5 MB

mov ax, videosel
mov gs, ax

mov eax, 2048
mov dword [DS:eax], 0f4d0f50h   ;PM in white
mov ebx, [ES:eax]

mov [gs:0], ebx

p:
jmp p


bits 16
gdtr :
   dw 8*4           ; Length of the gdt
   dd gdt           ; physical address of gdt

gdt:
    dd 0        ;NULL descriptor
    dd 0
   
    codesel equ $-gdt
    dw 0ffffh   ;4gb code section
    dw 0h       ;begin at start adress
    db 0h       ;extra byte to set start offset
    db 09ah     ;wat flags
    db 0cfh     ;nogwat flags
    db 0h

    datasel equ $-gdt
    dw 0ffffh   ;4gb data section
    dw 0h       ;begin at start adress
    db 0h       ;extra byte to set start offset
    db 092h     ;wat flags
    db 0cfh     ;nogwat flags   
    db 0h

    videosel equ $-gdt        ; ie 18h,next gdt entry
    dw 3999        ; Limit 80*25*2-1
    dw 0x8000 ; begin at start adress
    db 0x0b
    db 0x92        ; present,ring 0,data,expand-up,writable
    db 0x00        ; byte granularity 16 bit
    db 0x00

times 510-($-$$)  db 0  ; Fill bytes from present loc to 510 with 0s
              dw 0x0aa55  ; Write aa55 in bytes 511,512 to indicate that


Gustav


Hello Warsocket,

one possible problem might be that "lgdt [gdtr]" silently assumes that DS is 0. I know that for boot code SS:SP and CS:IP have defined values, but is this also true for DS?


Warsocket

Quote from: Gustav on March 24, 2006, 08:28:33 PM

Hello Warsocket,

one possible problem might be that "lgdt [gdtr]" silently assumes that DS is 0. I know that for boot code SS:SP and CS:IP have defined values, but is this also true for DS?



thank you very much, oh stupid me
the emulator initialises DS to 0
but the pc doesn't

so after inserting
xor ax, ax
mov ds, ax

its works just fine
thanks very much.