Guest User

Untitled

a guest
Jun 22nd, 2012
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #ifndef IDT_H
  2. #define IDT_H
  3.  
  4. #include "stdint.h"
  5.  
  6. #define IDT_INTERRUPT_GATE 0x0600
  7. #define IDT_TRAP_GATE      0x0700
  8. #define IDT_TASK_GATE      0x0500
  9.  
  10. #define IDT_DPL_0                    0x0000
  11. #define IDT_DPL_1                    0x1000
  12. #define IDT_DPL_2                    0x2000
  13. #define IDT_DPL_3                    0x3000
  14.  
  15. void load_idt();
  16. void set_idt_entry(int i, uint32_t address, uint16_t selector, uint16_t x);
  17.  
  18. #endif
  19.  
  20. //idt.c:
  21.  
  22. #include "idt.h"
  23.  
  24. #define IDT_ENTRIES 1
  25.  
  26. static uint64_t idt[IDT_ENTRIES];
  27.  
  28. void load_idt() {
  29.     struct {
  30.           unsigned short int limit;
  31.           void* pointer;
  32.     } __attribute__((packed)) idtp = {
  33.           .limit = IDT_ENTRIES * 8 - 1,
  34.           .pointer = idt,
  35.     };
  36.     asm volatile("lidt %0" : : "m" (idtp));
  37. }
  38.  
  39. void set_idt_entry(int i, uint32_t address, uint16_t selector, uint16_t x) {
  40.     idt[i]  = address & 0x0000FFFF;
  41.     idt[i] |= (address & 0xFFFF0000LL) << 32;
  42.     idt[i] |= (selector & 0xFFFFLL) << 16;
  43.  
  44.     x |= 0x8800;
  45.    
  46.     idt[i] |= (x & 0xFFFFLL) << 32;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment