Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct _idt
- {
- uint16_t offset_1;/*offset bits 0..15*/
- uint16_t selector;/*kernel code segment offset*/
- uint8_t ist; /*bits 0..2 holds interrupt stack table offset*/
- uint8_t type; /*type and attributes*/
- /*0..3 bits - gates*/
- /*4 bit - storage segment*/
- /*5..6 bits - gate call protection*/
- /*7 bit - used/unused interrupts*/
- uint16_t offset_2;/*offset bits 16..31*/
- uint32_t offset_3;/*offset bits 32..63*/
- uint32_t reserved;/*unused*/
- }__attribute((packed)) idt[256];
- void set_int_handler(uint8_t index, void* handle, uint8_t type)
- {
- /*at time of work this function may will do interrupt, and result will be undefined. Disable interruption and save all registers*/
- asm volatile("pushf\n\t");
- asm volatile("cli\n\t");
- idt[index].offset_1 = (size_t)handle & 0xFFFF;
- idt[index].offset_2 = ((size_t)handle & 0xFFFF0000) >> 16;
- idt[index].offset_3 = (uint32_t)((size_t)handle >> 32);
- idt[index].ist = 0x00;
- idt[index].selector = 0x08; /*kernel code segment offset*/
- idt[index].reserved = 0;
- idt[index].type = type;
- /*load all registers. This also activate interruption, because will restore flag register*/
- asm volatile("popf\n\t");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement