Can't jump to 32 bits, gdt problem?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
Tjaalie
Posts:3
Joined:Sun Oct 11, 2009 1:37 pm
Can't jump to 32 bits, gdt problem?

Post by Tjaalie » Sun Oct 11, 2009 2:32 pm

Dear thread reader,

Seeing that the tutorials have progressed quite far since the last time I checked them I finally began with my own os. Using the tutorials as a guide. I got the bootloader done and I'm working on the second stage right now. But when I try to jump to the 32 bit code my os triple faults. Here is what bochs tells me:
00015706189e[CPU0 ] jump_protected: gate type 0 unsupported
00015706189i[CPU0 ] CPU is in protected mode (active)
....
00015706189i[CPU0 ] >> jmp far 0008:0679 : EA79060800
I searched the web with this error (jump_protected: gate type 0 unsuporrted) and got a bunch of results of people who are trying to jump to 32 bit code, all reactions seem to indicate that its a gdt problem. I tried all the solutions posted on those forms but they didn't solve it.
So here is the code, in the hope that some bright mind can solve my error.

The gdt table:

Code: Select all

;;gdt table
gdt_start:
    dd 0
    dd 0
code equ $-gdt_start
    dw 0xFFFF
    dw 0
    db 0
    db 10011010b
    db 11001111b
    db 0
data equ $-gdt_start
    dw 0xFFFF
    dw 0
    db 0
    db 10010010b
    db 11001111b
    db 0
gdt_table:
    dw gdt_table - gdt_start - 1
    dw gdt_start
The gdt init code:

Code: Select all

;;setup gdt
gdt_init:
    ;;got this from one of the forums. But it doesn't solve anything. It sets the base of the code descriptor to the contents of cs
    ;;mov eax, 0
    ;;mov ax, cs
    ;;and eax, 0xFFFF
    ;;shl eax, 4
    ;;mov word [code+2], ax
    ;;shr eax, 16
    ;;mov byte [code+4], al
    ;;mov byte [code+7], ah

    ;;set gdt
    cli
    pusha
    lgdt [gdt_table]
    popa
    sti
    ret
And finally the pmode code:

Code: Select all

;;the 32 bit setup part
bits 16
bits32_init:
    ;;disable interupts and enable pmode
    cli
    mov eax, cr0
    or  eax, 1
    mov cr0, eax

    ;;jump to the 32 bit part
    jmp code:xboot2_32

;;the 32 bit part
bits 32
xboot2_32:
    jmp $
    ;;set registers
    mov ax, data
    mov ds, ax
    mov ss, ax
    mov es, ax
    mov esp, 0xFFFF

    ;;hang
    jmp $
If I hang the os with 'jmp $' just after I enabled pmode there is no crash. So the jump (just as bochs indicated) is the problem. There is a other thread on this forum regarding a similar problem. Although the fix proposed there doesn't work for me. It keeps giving the exact same error msg.

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Can't jump to 32 bits, gdt problem?

Post by Andyhhp » Sun Oct 11, 2009 3:57 pm

your problem is the GDT descriptor

Code: Select all

gdt_table:
    dw gdt_table - gdt_start - 1
    dw gdt_start

This is wrong because you need a 32bit value for gdt_start, rather than the 16bit value you have got.

To fix it, try

Code: Select all

gdt_table:
    dw gdt_table - gdt_start - 1
    dd gdt_start
~Andrew
Image

Tjaalie
Posts:3
Joined:Sun Oct 11, 2009 1:37 pm

Re: Can't jump to 32 bits, gdt problem?

Post by Tjaalie » Sun Oct 11, 2009 4:42 pm

Thank you very much, that I didn't see that. It works now.

Tjaalie
Posts:3
Joined:Sun Oct 11, 2009 1:37 pm

Re: Can't jump to 32 bits, gdt problem?

Post by Tjaalie » Sun Oct 11, 2009 5:40 pm

Oke now I got one more problem, but I don't know if its related to the gdt. When I try to load the whole floppy disk into memory I can't read past the 1mb boundary. I did set up the a20 line (or at least I think so). Is there anyway to see if the a20 line is enabled in bochs? Here is my init code anyway:

Code: Select all

;;wait till we can set the a20 line
a20_wait:
    in al, 0x64
    test al, 2
    jnz a20_wait
    ret

;;enable a20 line
a20_enable:
    ;;acquire command data
    mov al, 0xD0
    out 0x64, al
    call a20_wait

    ;;get the data
    in al, 0x60
    push ax
    call a20_wait

    ;;tell we want to write
    mov al, 0xD1
    out 0x64, al
    call a20_wait

    ;;modify the data and send it
    pop ax
    or al, 2
    out 0x60, al

    ret

Post Reply