Page 1 of 1

IDT(nobody is answering in the old thread)

Posted: Thu Dec 26, 2002 2:37 am
by hanoi
ok, i have following problem:
i want to write my IDT in C
but i get:
-when paging is on 3rd(14) in bochs
-when it's off 3rd(13) in bochs
- __attribute__ ((packed)) doesn't change anything
-i used the part union because the shitfting and logical operations look ugly(imho)

so here is the code, look at it
typedef struct {
   unsigned short int Offset1;
   unsigned short int Segment;
   unsigned short int t;
   unsigned short int Offset2;
} intdes;
typedef struct
{
   unsigned short limit;
   intdes *lIDT;
} IDTR;

typedef union
{
   void *p;
   unsigned short a;
   unsigned short b;
} part;

extern void unhandled();
void setVector(int nr, void *function);
void LIDT();

intdes IDT[256];
IDTR sysreg;

void main()
{
...
   for(i=0; i <256; i++)
   {
   setVector(i, (void *)(unhandled));
   }
   LIDT();
   asm("sti");
...
}

void setVector(int nr, void *function)
{
   intdes n;
   part p;
   p.p = function;
   n.Offset1 = p.a;
   n.Offset2 = p.b;
   n.Segment = 0x8;
   n.t = 0x8e00;
   IDT[nr] = n;
   return;
}


void LIDT()
{
   sysreg.limit = 1024;
   sysreg.lIDT = IDT;
   asm volatile ("lidt _sysreg");
   return;
}

thanks

Re:IDT(nobody is answering in the old thread)

Posted: Thu Dec 26, 2002 3:48 am
by hanoi
works

Re:IDT(nobody is answering in the old thread)

Posted: Thu Dec 26, 2002 5:55 am
by Ozguxxx
Hi people, why are you all trying to write all your idts in c? Is older work not working in your implementations? Or is it more robust or something? ???

Re:IDT(nobody is answering in the old thread)

Posted: Thu Dec 26, 2002 12:33 pm
by jrfritz
It's easier...but I will have to make my IRQ functions in Asm :-\

Re:IDT(nobody is answering in the old thread)

Posted: Thu Dec 26, 2002 5:58 pm
by Pype.Clicker
nah. Just the saving/restoring stub need to be written in ASM. Then, you're free to call [C_exception_handlers+eax*4] -- provided that eax is the interrupt number :)