Hello.
Please tell me very well how can I make Interrupt Descriptor Table with C language (and then load it).
IDT with C
Re:IDT with C
You do something like this:
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
struct idt_entry
{
uint16 addr_l;
uint16 sel;
uint8 nulls;
uint8 attrib;
uint16 addr_h;
};
struct idt_entry idt[49];
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>
Re:IDT with C
It is important to not forget __attribute__((__packed__)):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; };
Code: Select all
struct idt_entry
{
uint16 addr_l;
uint16 sel;
uint8 nulls;
uint8 attrib;
uint16 addr_h;
} __attribute__((packed));
Re:IDT with C
Isn't it also neccessary to add
?
AFAIK, the descriptor structures need to be aligned on a 32-bit border.
cheers Joe
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
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:IDT with C
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.