Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <string.h> // Include headers for int types and memset()
- struct idt_entryStruct { // Struct for an entry into the IDT
- uint16_t base1; // L.O. bits of ISR address
- uint16_t select; // Code segment offset into the GDT
- uint8_t always0;
- uint8_t flags; // Flags specifying ring etc.
- uint16_t base2; // H.O. bits of ISR address
- } __attribute__((packed));
- struct idtrStruct { // Struct for what will be loaded into idtr
- uint16_t limit; // Size of the IDT
- uint32_t base; // Base address of IDT
- } __attribute__((packed));
- struct idt_entryStruct idt[256]; // Let's have 256 entries
- struct idtrStruct idtr;
- void idt_setgate (uint8_t id, uint32_t base, uint16_t select, uint8_t flags) { // Function to set ISRs, called by loadisr() in isr.c
- idt[id].base1 = (base & 0xffff); // Get the L.O. bits of base address
- idt[id].select = select;
- idt[id].always0 = 0;
- idt[id].flags = flags;
- idt[id].base2 = (base >> 16) & 0xffff; // Get the H.O. bits of base address
- }
- void loadidt (void) { // Function to load an empty IDT, called by kernel
- idtr.limit = (sizeof(struct idt_entryStruct) * 256) - 1; // Size of our IDT - 1
- idtr.base = (uint32_t) &idt; // Base address. TODO: does this need a cast?
- memset (&idt, 0, sizeof(struct idt_entryStruct) * 256); // Clear out the IDT.
- extern void idt_init(); // Call a function defined in asm to lidt our IDT
- }
Advertisement
Add Comment
Please, Sign In to add comment