Page 1 of 1
Weird Triple fault
Posted: Sun Aug 03, 2008 9:13 am
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.
Re: Weird Triple fault
Posted: Sun Aug 03, 2008 9:59 am
by 01000101
you should replace the 'ret' with a 'hlt' or something else, you should not be returning from a jump.
Re: Weird Triple fault
Posted: Sun Aug 03, 2008 2:42 pm
by osdf_1
_gdtFlush is called from C, and you should be returning to C.
Re: Weird Triple fault
Posted: Sun Aug 03, 2008 4:30 pm
by 01000101
oh wow, my bad. I thought that it was all asm stuff and I don't know why lol.

Re: Weird Triple fault
Posted: Sun Aug 03, 2008 7:39 pm
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
Re: Weird Triple fault
Posted: Sun Aug 03, 2008 11:01 pm
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