Protected Mode Question

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
vbbrett

Protected Mode Question

Post 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




Dex4u

Re:Protected Mode Question

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

Re:Protected Mode Question

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

Re:Protected Mode Question

Post by vbbrett »

Well, I made those changes and I'm still getting the same error.... any ideas?
Thanks so far!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Protected Mode Question

Post 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)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Protected Mode Question

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply