Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. struct _idt
  2. {
  3.     uint16_t offset_1;/*offset bits 0..15*/
  4.     uint16_t selector;/*kernel code segment offset*/
  5.     uint8_t  ist;     /*bits 0..2  holds interrupt stack table offset*/
  6.     uint8_t  type;    /*type and attributes*/
  7.                       /*0..3 bits - gates*/
  8.                       /*4 bit     - storage segment*/
  9.                       /*5..6 bits - gate call protection*/
  10.                       /*7 bit     - used/unused interrupts*/
  11.     uint16_t offset_2;/*offset bits 16..31*/
  12.     uint32_t offset_3;/*offset bits 32..63*/
  13.     uint32_t reserved;/*unused*/
  14. }__attribute((packed)) idt[256];
  15.  
  16. void set_int_handler(uint8_t index, void* handle, uint8_t type)
  17. {  
  18.     /*at time of work this function may will do interrupt, and result will be undefined. Disable interruption and save all registers*/
  19.     asm volatile("pushf\n\t");
  20.     asm volatile("cli\n\t");
  21.     idt[index].offset_1  = (size_t)handle & 0xFFFF;
  22.     idt[index].offset_2  = ((size_t)handle & 0xFFFF0000) >> 16;
  23.     idt[index].offset_3  = (uint32_t)((size_t)handle >> 32);
  24.     idt[index].ist      = 0x00;
  25.     idt[index].selector = 0x08; /*kernel code segment offset*/
  26.     idt[index].reserved = 0;
  27.     idt[index].type = type;
  28.     /*load all registers. This also activate interruption, because will restore flag register*/
  29.     asm volatile("popf\n\t");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement