Page 1 of 1

Protected Mode Question

Posted: Thu Feb 03, 2005 8:31 pm
by vbbrett
I have another Pmode problem for you guys. Bochs is giving me some of this: 3rd (13) unhandled exception ect... I think I'm having trouble before or on my far jump. I have a two stage loader. The first just basically loads number 2 into 9000h. Is this even a good place? So, why can't I get successfully into Protected Mode. Heres the Code: Thanks.

Code: Select all

; Stage 2

[BITS 16]
[ORG 9000]

; **************************************************
;   Program begins here
; **************************************************

;mov ax, cs
;mov ds, ax
;mov es, ax


        cli                     ; Disable interrupts, we want to be alone

        xor ax, ax
        mov ds, ax              ; Set DS-register to 0 - used by lgdt

        lgdt [gdt_desc]      ; Load the GDT descriptor
 
     cli

        mov eax, cr0            ; CR0 into EAX
        or eax, 1
        mov cr0, eax            ; EAX into CR0

        cli
        jmp 0x10:clear_pipe      ; Jump to code segment, offset clear_pipe

[BITS 32]                       ; We now need 32-bit instructions
clear_pipe:
        mov ax, 08h             ; Save data segment identifyer
        mov ds, ax              ; Move a valid data segment into the data segment register
        mov ss, ax              ; Move a valid data segment into the stack segment register
        mov esp, 090000h        ; Move the stack pointer to 090000h

; Prove that we are in Protected Mode

;mov 0B8000, 'P'
;mov 0B8001, 1Bh

 mov byte [ds:0B8000h], 'P'     ;  Move the ASCII-code of 'P' into first video memory
 mov byte [ds:0B8001h], 0Fh     ;  Assign a color code
 mov byte [ds:0B8002h], 'M'
 mov byte [ds:0B8003h], 0Fh



; Hang for testing purposes
hang:
jmp hang

gdt:                    ; Address for the GDT

gdt_null:               ; Null Segment
        dw 0
        dw 0

gdt_code:               ; Code segment, read/execute, nonconforming
        dw 0FFFFh
        dw 0
        db 0
        db 10011010b
        db 11001111b
        db 0

gdt_data:               ; Data segment, read/write, expand down
        dw 0FFFFh
        dw 0
        db 0
        db 10010010b
        db 11001111b
        db 0

gdt_end:                ; Used to calculate the size of the GDT



gdt_desc:                       ; The GDT descriptor
        db gdt_end - gdt - 1    ; Limit (size) Why minus 1?
        dw gdt                  ; Address of the GDT





Re:Protected Mode Question

Posted: Thu Feb 03, 2005 10:00 pm
by Dex4u
I think this:

Code: Select all

jmp   0x10:clear_pipe
Should be this:

Code: Select all

jmp   0x08:clear_pipe
And this:

Code: Select all

mov   ax,08h
Should be this:

Code: Select all

mov   ax,10h
Dex4u

Re:Protected Mode Question

Posted: Fri Feb 04, 2005 5:48 am
by XStream

Code: Select all

gdt:                    ; Address for the GDT

gdt_null:              ; Null Segment
        dw 0
        dw 0

gdt_code:              ; Code segment, read/execute, nonconforming
        dw 0FFFFh
        dw 0
        db 0
        db 10011010b
        db 11001111b
        db 0

gdt_data:              ; Data segment, read/write, expand down
        dw 0FFFFh
        dw 0
        db 0
        db 10010010b
        db 11001111b
        db 0

gdt_end:                ; Used to calculate the size of the GDT
Your null descriptor is missing 4 bytes?? Each GDT entry is 8 bytes long, your current null descriptor is only 4 bytes long. Change the 2 dw's to dd's and do what Dex4u said and it should work.

Cheers.

Re:Protected Mode Question

Posted: Fri Feb 04, 2005 6:57 am
by vbbrett
Well, I made those changes and I'm still getting the same error.... any ideas?
Thanks so far!

Re:Protected Mode Question

Posted: Fri Feb 04, 2005 7:57 am
by Pype.Clicker
using a debugging-able bochs, i suggest that you:
1. get a dump_cpu of the error
2. figure out which instruction raises the error (e.g. decoding eip)
3. check that the memory under GDTR.base *is* your GDT (looking up memory content)

Re:Protected Mode Question

Posted: Fri Feb 04, 2005 8:31 am
by Brendan
Hi,

Just wondering if "[ORG 9000]" is meant to be "[ORG 0x9000]" (or perhaps "[ORG 0x90000]"). IMHO if it is right you should use hex for addresses rather than decimal.


Cheers,

Brendan