IDT with 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.
Post Reply
OSMAN

IDT with C

Post by OSMAN »

Hello.

Please tell me very well how can I make Interrupt Descriptor Table with C language (and then load it).
QuiTeVexat

Re:IDT with C

Post by QuiTeVexat »

You do something like this:

Code: Select all

struct idt_entry
{
   uint16 addr_l;
   uint16 sel;
   uint8  nulls;
   uint8  attrib;
   uint16 addr_h;
};

struct idt_entry idt[49];
And then you write a couple of functions to fill the table in with the right values. It's hard to make this one generated at compile/link-time because of the division between the low parts of the address and the high parts, and linkers won't usually do bitmasks and shifts for you.

As for loading, it works like LGDT, you need a pointer structure, so set up a temporary location for that, load it up (like you would for a GDT pointer), and use some inline assembly like so:

Code: Select all

asm("lidt (%0)" ... <fill in the rest here>
GLneo

Re:IDT with C

Post by GLneo »

AR

Re:IDT with C

Post by AR »

QuiTeVexat wrote: You do something like this:

Code: Select all

struct idt_entry
{
   uint16 addr_l;
   uint16 sel;
   uint8  nulls;
   uint8  attrib;
   uint16 addr_h;
};
It is important to not forget __attribute__((__packed__)):

Code: Select all

struct idt_entry
{
   uint16 addr_l;
   uint16 sel;
   uint8  nulls;
   uint8  attrib;
   uint16 addr_h;
} __attribute__((packed));
Otherwise each one of those variables will be uint32 regardless of the type.
JoeKayzA

Re:IDT with C

Post by JoeKayzA »

Isn't it also neccessary to add

Code: Select all

struct idt_entry idt[49] __attribute__((aligned(4)));
?

AFAIK, the descriptor structures need to be aligned on a 32-bit border.

cheers Joe
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:IDT with C

Post by Pype.Clicker »

the compiler is much likely to align *anything* on a 32bits boundary, btw. it even happen to align strings of characters on 32bits boundaries some days.
Post Reply