[SOLVED] Ret Triple Faults After Call
Posted: Sun Nov 14, 2010 2:24 pm
Hello,
I'm Having a rather weird problem. Every Time I try to make a call To "NewLine" (Extern) which is declared in another file , the Call Works but when i try to Ret from the procedure . It Just Triple Faults. Also I tried to jump Back to a label Placed after the call instruction and it works. My GDT COnsists of A code segment and data segment both flat and uses data segment as stack.
Calling Procedure
Called Procedure
I compile using Nasm -f Aout -o Caller.o caller.asm
Nasm -f Aout -o Called.o Called.asm
and Link using LD Djgpp
ld -T link.ld -Ttext 0x100000 called.o caller.o ;Wont link properly if caller.o called.o
link.ld
I'm Having a rather weird problem. Every Time I try to make a call To "NewLine" (Extern) which is declared in another file , the Call Works but when i try to Ret from the procedure . It Just Triple Faults. Also I tried to jump Back to a label Placed after the call instruction and it works. My GDT COnsists of A code segment and data segment both flat and uses data segment as stack.
Calling Procedure
Code: Select all
[BITS 32]
[SECTION .text]
[GLOBAL START]
[EXTERN NewLine]
[EXTERN Cursor]
START:
Mov Ebp , String
Call PrintText
Jmp $
PrintText :
Call NewLine ; HERE IS THE CALL
Jmp $
Mov Ebx , [Cursor]
NextChar: Mov Ah , [ Ds:Ebp ]
Cmp Ah , 0
Je StopPrinting
Inc Ebp
Add Ebx , 2
Mov [ Gs:Ebx ] , Ah
Jmp NextChar
StopPrinting: Ret
String: db "Some Stuff Here" , 0
Called Procedure
Code: Select all
[BITS 32]
[GLOBAL NewLine]
[GLOBAL Cursor]
NewLine:
Mov Ax , [Cursor]
Shl Al , 1
Shr Al , 1
Mov Dh , 0
Mov Dl , Al
Mov Ax , 80
Sub Ax , Dx
Mov Dx , [Cursor]
Add Dx , Ax
Mov [Cursor] , Dx
add Ebx , 2
mov ah , "H"
Mov [ Gs:Ebx ] , Ah
Ret ; HERE IS THE PROBLEM
[SECTION .data]
Cursor: dw 0
Nasm -f Aout -o Called.o Called.asm
and Link using LD Djgpp
ld -T link.ld -Ttext 0x100000 called.o caller.o ;Wont link properly if caller.o called.o
link.ld
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(START)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
}
end = .;
}