Some IDT Code...in C

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.
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

Still tripple faults...it doesn't reboot...i'm in bochs.
jrfritz

Re:Some IDT Code...in C

Post 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!
jrfritz

Re:Some IDT Code...in C

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Some IDT Code...in C

Post 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).
jrfritz

Re:Some IDT Code...in C

Post 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.
whyme_t

Re:Some IDT Code...in C

Post 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?
Slasher

Re:Some IDT Code...in C

Post 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!
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

What should I set the base of the IDT?

I did make the changes too...
whyme_t

Re:Some IDT Code...in C

Post 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-
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

Well, my kernel is C++...but I like C also so i'll try that code.
Slasher

Re:Some IDT Code...in C

Post 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.
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

My C++ kernel is loaded at 9000h...
jrfritz

Re:Some IDT Code...in C

Post by jrfritz »

If my kernel is loaded at 9000h, what should my IDT be at?
Slasher

Re:Some IDT Code...in C

Post 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)
Unexpected

Re:Some IDT Code...in C

Post 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
Post Reply