flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > OS Construction > [solved] Triple fault when jumping to 32 bit code

Author
Thread Post new topic Reply to topic
Szustarol



Joined: 11 Jul 2016
Posts: 9
[solved] Triple fault when jumping to 32 bit code
As in tittle, this is my code
stage1

Code:

use16
org 0x7c00

jmp far 0x0000:start

start:
        mov ax0x2000
        mov esax
        xor bxbx 

        ;preparing to read stage 2 sectors
        mov ah2
        mov al1 ;read 3 sectors
        mov ch0
        mov cl2
        mov dh0
        ;dl set


        int 0x13

        jmp far 0x2000:0x0000


times 510 - ($ - $$db 0
dw 0xAA55



stage2

Code:

use16
org 0x0000


start:
        mov ax0x2000
        mov dsax
        mov esax

        mov ax0x1f00
        mov ssax
        xor spsp
        cli
        lgdt [GDT_32_STRUCT]
        mov eaxcr0
        or eax1
        mov cr0eax
;if i put jmp $ here no faults happen
        jmp 0x8:code_32 ; triple fault somewhere, i guess here


;;32 bit code starts here

code_32:
;if i put jmp $ here faults still happen
        use32
        mov ax0x10
        mov dsax
        mov esax
        mov ssax
        jmp $
;       lea eax, [0xb8000]
;       mov dword [eax], 0x41414141

;;GLOBAL DESCRIPTOR TABLE;;

GDT_32_STRUCT:
dw GDT_32_END-GDT_32_BEGIN-1
dd GDT_32_BEGIN

GDT_32_BEGIN:
;null segment
dq 0

;code segment
dd 0xffff
dd 00000000100110101100111100000000b

;data segment
dd 0xffff
dd 00000000100100101100111100000000b
GDT_32_END:

;;END OF 32 BIT GDT;;




Can anyone help? I have no idea why i keep getting triple fault [/code]
Post 26 Jan 2017, 12:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
At least one problem is that your base address is 0x0 but the code resides at 0x20000 and you jmp to 0x0+code_32 which is in the interrupt table.

I suspect there are other problems with your GDT also, so it would pay to check it thoroughly.
Post 26 Jan 2017, 12:59
View user's profile Send private message Visit poster's website Reply with quote
Szustarol



Joined: 11 Jul 2016
Posts: 9
I was actually aware of this, but when i try to jump to 0x20000+code32 i get this error:
stage2.asm [18]:
jmp far 0x08:(0x20000+code_32)
processed: jmp far 0x08:(0x20000+code_32)


Code:

use16
org 0x0000


start:
        mov ax0x2000
        mov dsax
        mov esax

        mov ax0x1f00
        mov ssax
        xor spsp
        cli
        lgdt [GDT_32_STRUCT]
        mov eaxcr0
        or eax1
        mov cr0eax
        jmp far 0x08:(0x20000+code_32)


;;32 bit code starts here

code_32:
        use32
        mov ax0x10
        mov dsax
        mov esax
        mov ssax
        jmp $
;       lea eax, [0xb8000]
;       mov dword [eax], 0x41414141

;;GLOBAL DESCRIPTOR TABLE;;

GDT_32_STRUCT:
dw GDT_32_END-GDT_32_BEGIN-1
dd 0x20000+GDT_32_BEGIN

GDT_32_BEGIN:
;null segment
dq 0

;code segment
dd 0xffff
dd 00000000100110101100111100000000b

;data segment
dd 0xffff
dd 00000000100100101100111100000000b
GDT_32_END:

;;END OF 32 BIT GDT;;



Post 26 Jan 2017, 13:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
You need a 32-bit version of the far jmp.

Code:
jmp pword 0x08:(0x20000+code_32)

Post 26 Jan 2017, 13:26
View user's profile Send private message Visit poster's website Reply with quote
Szustarol



Joined: 11 Jul 2016
Posts: 9

Code:

use16
org 0x0000


start:
        mov ax0x2000
        mov dsax
        mov esax

        mov ax0x1f00
        mov ssax
        xor spsp
        cli
        lgdt [GDT_32_STRUCT]
        mov eaxcr0
        or eax1
        mov cr0eax
        jmp pword 0x08Sad0x20000+code_32)


;;32 bit code starts here

code_32:
        use32
        mov ax0x10
        mov dsax
        mov esax
        mov ssax
        jmp $
;       lea eax, [0xb8000]
;       mov dword [eax], 0x41414141

;;GLOBAL DESCRIPTOR TABLE;;

GDT_32_STRUCT:
dw GDT_32_END-GDT_32_BEGIN-1
dd 0x20000+GDT_32_BEGIN

GDT_32_BEGIN:
;null segment
dq 0

;code segment
dd 0xffff
dd 00000000100110101100111100000000b

;data segment
dd 0xffff
dd 00000000100100101100111100000000b
GDT_32_END:

;;END OF 32 BIT GDT;;



This is my code now, sadly still not working
The jump in bochsdbg looks like this:

Code:

(0) [0x00000002001e2000:000000000000001e (unk. ctxt): jmpf 0x0008:00020026      ; 66ea260002000800
<bochs:14s
(0).[153783717] [0x00000002001e2000:000000000000001e (unk. ctxt): jmpf 0x0008:00020026      ; 66ea260002000800
Next at t=153783718
(0) [0x0000fffffff0f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
<bochs:15



any ideas?
Post 26 Jan 2017, 13:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
I suspect you have other problems in your GDT. Map out the fields and check what exactly is being defined for each setting.
Post 26 Jan 2017, 13:49
View user's profile Send private message Visit poster's website Reply with quote
Szustarol



Joined: 11 Jul 2016
Posts: 9
Problem fixed, I have actually reversed bytes and had acces byte instead flags&limit and vice versa, now its working. Thanks for pointing me to the GDT
Post 26 Jan 2017, 14:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.