Page 4 of 9

Re:Some IDT Code...in C

Posted: Mon Dec 16, 2002 5:26 pm
by jrfritz
Still tripple faults...it doesn't reboot...i'm in bochs.

Re:Some IDT Code...in C

Posted: Mon Dec 16, 2002 5:30 pm
by jrfritz
!!!!!!!!!!!!!!!!!!!!!!!!!!


:) :D ;D ;) :o 8)

IT WORKS!!! IT WORKS!!! IT WORKS!! THE PROBLEM WAS THAT I SET THE IDT.BASE AND I JUST GOT RID OF IT AND I WORKS

Ok..calm down...but I have been working on this for months!

THANK you!

Re:Some IDT Code...in C

Posted: Mon Dec 16, 2002 6:04 pm
by jrfritz
Well, I get a double fault ( error 8 ) and this is what I found on the internet:

double fault
possible for 386+ in real mode if INT vector exceeds IDT limit

What does this mean?

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 8:09 am
by Pype.Clicker
i guess this means that if you return to real mode and leave the pmode IDT installed (and mainly, not restoring the limit to 256*4-1), and that you invoke INT n (or rise up and IRQ to vector n) with n>[IDT.limit / 4], the processor will issue a "double fault" exception. How this exception will be handled is quite mysterious, but if the appropriate GDT and IDT base are still set up, it could possibly deliver it to the 32 bits handler (turning back to pmode).

I'm not sure of it, but i've seen some unreal-mode TSR programs that used some similar trick (hooking SEGFAULTS generated from realmode when attemp is made to go over the 16bits limit of a segment due to a GDT reset by some external program and restoring a clean unreal mode ... impressive, isn't it ? :-) )

In normal conditions, that "double fault" will probably not be handled correctly because you didn't expected such a scenario and leads to a 3rd exception (and reboot).

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 11:18 am
by jrfritz
Well....I don't go to realmode...I just enable interrupts after setting up my IDT and my IDT fires a excep 8.

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 11:31 am
by whyme_t
Tom wrote: THE PROBLEM WAS THAT I SET THE IDT.BASE AND I JUST GOT RID OF IT
Have I misunderstood, or do you mean that you're not setting the base of the idt?

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 11:34 am
by Slasher
hi,
did you make those changes to the err() function? And i hope you didn't iret from it as you did handle the interrupt! if you still have problems, kindly post full relevant source code to be examined!

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 11:49 am
by jrfritz
What should I set the base of the IDT?

I did make the changes too...

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 12:07 pm
by whyme_t
I'm going to try and help you, but my GDT and IDT are in C++, but I'll attempt to translate.

From looking at your kernel32.c file, you've not made an IDT. I couldn't see anywhere

Code: Select all

idt_entry IDT[IDTSIZE] ;
Your descriptor_reg idt, isn't that just your idtr? so you need to point

Code: Select all

idtr.base = (unsigned long int) IDT ;
So IDT is an array of idt_entry's, the idtr is what you pass to lidt, and must therefore point to the base of your IDT.

I hope this makes sense, and I got it correct.

-Edit-
And for your int set_idt_entry, you could do this,

Code: Select all

int set_idt_entry(unsigned long num,void (*funct)(void))
{
    IDT[num].offset_low =(unsigned short) (((unsigned long)funct & 0xffff));
    ...
    ...
    ...
    IDT[num].offset_high=(unsigned short)(((unsigned long)funct >> 16));
}
-Edit-

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 12:22 pm
by jrfritz
Well, my kernel is C++...but I like C also so i'll try that code.

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 1:34 pm
by Slasher
hi,
what is the memory layout for your kernel?
i.e this is mine( at the moment)

0 - 0400h --> bios
....
....
0600h - (0600h+256*8 - 1) --> IDT

paste the update kernel and idt code (part concerning IDT setup) that you are using now.

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 1:54 pm
by jrfritz
My C++ kernel is loaded at 9000h...

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 2:30 pm
by jrfritz
If my kernel is loaded at 9000h, what should my IDT be at?

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 3:35 pm
by Slasher
let's say you want to place it before your kernel at 9000h
you can put it at any address that will leave enough memory for 256 enties for example
256*8 =2,048 bytes so
9000h - 2,048 bytes = 8800h
so any address from 8800h to 0400h (bios)

Re:Some IDT Code...in C

Posted: Tue Dec 17, 2002 3:42 pm
by Unexpected
Cool my IDT works too!!!
But why when I press I key, I have 13th exeption: "General protection fault". Why? I think my handler in C is wrong.

In posted codes you need to set idt base address, why you don't use IDT[256] (not pointer), and set IDTR.offset = (unsigned long)IDT