cynix

x86 UNIX-like OS
git clone git://git.2f30.org/cynix
Log | Files | Refs | README | LICENSE

idt.h (2914B)


      1 #ifndef __IDT_H__
      2 #define __IDT_H__
      3 
      4 #include <stdint.h>
      5 
      6 #define DUMP_STACK_REGS(regs) \
      7 	({ \
      8 		DEBUG_CODE(printf("unroll_esp = 0x%lx\n", regs.unroll_esp);) \
      9 		DEBUG_CODE(printf("ds = 0x%lx\n", regs.ds);) \
     10 		DEBUG_CODE(printf("edi = 0x%lx, esi = 0x%lx, ebp = 0x%lx, esp = 0x%lx, ebx = 0x%lx, edx = 0x%lx, ecx = 0x%lx, eax = 0x%lx\n", \
     11 				  regs.edi, regs.esi, regs.ebp, regs.esp, regs.ebx, regs.edx, regs.ecx, regs.eax);) \
     12 		DEBUG_CODE(printf("int_no = 0x%lx, err_code = 0x%lx\n", regs.int_no, regs.err_code);) \
     13 		DEBUG_CODE(printf("eip = 0x%lx, cs = 0x%lx, eflags = 0x%lx\n", \
     14 				  regs.eip, regs.cs, regs.eflags);) \
     15 	})
     16 
     17 struct trapframe_t {
     18 	uint32_t unroll_esp;
     19 	uint32_t ds;                                      /* Data segment selector */
     20 	uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;  /* Pushed by pusha. */
     21 	uint32_t int_no, err_code;                        /* Interrupt number and error code (if applicable) */
     22 	uint32_t eip, cs, eflags;                         /* Pushed by the processor automatically. I might need to add useresp and ss.*/
     23 } __attribute__ ((packed));
     24 
     25 struct idt_intr_gate {
     26 	uint16_t offset_lo        : 16;
     27 	uint16_t selector         : 16;
     28 	uint8_t  all0             : 8;
     29 	uint8_t  gate_size        : 5; /* 0b0D110 */
     30 	uint8_t  privilege_level  : 2;
     31 	uint8_t  segment_present  : 1;
     32 	uint16_t offset_hi        : 16;
     33 } __attribute__((packed));
     34 
     35 struct idt_selector {
     36 	uint16_t limit;
     37 	uint32_t base;
     38 } __attribute__ ((packed));
     39 
     40 typedef void (*isr_handler)(struct trapframe_t *regs);
     41 
     42 extern void isr0(void);
     43 extern void isr1(void);
     44 extern void isr2(void);
     45 extern void isr3(void);
     46 extern void isr4(void);
     47 extern void isr5(void);
     48 extern void isr6(void);
     49 extern void isr7(void);
     50 extern void isr8(void);
     51 extern void isr9(void);
     52 extern void isr10(void);
     53 extern void isr11(void);
     54 extern void isr12(void);
     55 extern void isr13(void);
     56 extern void isr14(void);
     57 extern void isr15(void);
     58 extern void isr16(void);
     59 extern void isr17(void);
     60 extern void isr18(void);
     61 extern void isr19(void);
     62 extern void isr20(void);
     63 extern void isr21(void);
     64 extern void isr22(void);
     65 extern void isr23(void);
     66 extern void isr24(void);
     67 extern void isr25(void);
     68 extern void isr26(void);
     69 extern void isr27(void);
     70 extern void isr28(void);
     71 extern void isr29(void);
     72 extern void isr30(void);
     73 extern void isr31(void);
     74 extern void isr32(void);
     75 extern void isr33(void);
     76 extern void isr34(void);
     77 extern void isr35(void);
     78 extern void isr36(void);
     79 extern void isr37(void);
     80 extern void isr38(void);
     81 extern void isr39(void);
     82 extern void isr40(void);
     83 extern void isr41(void);
     84 extern void isr42(void);
     85 extern void isr43(void);
     86 extern void isr44(void);
     87 extern void isr45(void);
     88 extern void isr46(void);
     89 extern void isr47(void);
     90 extern void isr128(void);
     91 extern void initialize_idt(void);
     92 extern uint32_t handle_interrupt(struct trapframe_t regs);
     93 extern int register_isr_handler(uint8_t index, isr_handler handler);
     94 
     95 #endif
     96