Weird Triple fault

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
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Weird Triple fault

Post by osdf_1 »

I had this code to set up my GDT:

Code: Select all

global _gdtFlush
extern _gdtPtr
_gdtFlush:
    lgdt[_gdtPtr]
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    jmp 0x08:flush2
flush2:
    ret
and decided to change the "flush2" label for "return". When I ran my kernel I got a Triple fault. So I changed it back to the way it was before, but I still get the Triple fault. What could be going wrong? I tested it on two emulators and got the same in both.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Weird Triple fault

Post by 01000101 »

you should replace the 'ret' with a 'hlt' or something else, you should not be returning from a jump.
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Re: Weird Triple fault

Post by osdf_1 »

_gdtFlush is called from C, and you should be returning to C.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Weird Triple fault

Post by 01000101 »

oh wow, my bad. I thought that it was all asm stuff and I don't know why lol.
#-o
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Re: Weird Triple fault

Post by JJeronimo »

osdf_1 wrote:I had this code to set up my GDT [.......] and decided to change the "flush2" label for "return". When I ran my kernel I got a Triple fault. So I changed it back to the way it was before, but I still get the Triple fault. What could be going wrong? I tested it on two emulators and got the same in both.
Didn't understand exactly your problem. The above code was working normally, you changed the label "flush2" to "return", it crashed, then changed it back to "flush2" and crashed too?
Looks like you forgot to compile the crowd somewhere in-between the experiments. Perhaps your makefile has some problem, who knows... You didn't give us much information, after all!

Perhaps the GDT would be valuable, too. And what does the symbol _gdtPtr point to? It points to the descriptor required for loading the GDT, I suppose (i.e. not to the GDT itself).

JJ
osdf_1
Posts: 20
Joined: Sun Nov 25, 2007 7:55 pm

Re: Weird Triple fault

Post by osdf_1 »

Ok, I figured it out. In between the label experiments I also modified the gdt entry struct, which originally was:

Code: Select all

struct gdtEntry
{
    unsigned short limitLow;
    unsigned short baseLow;
    unsigned char baseMiddle;
    unsigned char access;
    unsigned char granularity;
    unsigned char baseHigh;
} __attribute__((packed));
What I did was move the "unsigned char baseHigh;" up two places (below baseMiddle). Later I realized that this struct must be this way.

Thanks
Post Reply