My Kernel v0.1.0
interrupts.h
Go to the documentation of this file.
1
35#ifndef KERNEL_INTERRUPTS_H
36#error <kernel/arch/i686/interrupts.h> must not be used as a standalone header. Please include <kernel/interrupts.h> instead.
37#endif
38
39#ifndef KERNEL_ARCH_I686_INTERRUPTS_H
40#define KERNEL_ARCH_I686_INTERRUPTS_H
41
42#include <kernel/types.h>
43
44#include <kernel/arch/i686/gdt.h>
45
46#include <utils/compiler.h>
47
48#define IDT_LENGTH 256
49#define IDT_SIZE (IDT_LENGTH * sizeof(idt_descriptor))
50#define IDT_BASE_ADDRESS 0x00000000UL
51
57typedef enum {
58 DIVISION_ERROR = 0x0,
59 DEBUG,
60 NON_MASKABLE,
61 BREAKPOINT,
62 OVERFLOW,
63 BOUND_RANGE_EXCEEDED,
64 INVALID_OPCODE,
65 DEVICE_NOT_AVAILABLE,
66 DOUBLE_FAULT,
67 COPROCESSOR_SEGMENT_OVERRUN,
68 INVALID_TSS,
69 SEGMENT_NOT_PRESENT,
70 STACK_SEGMENT_FAULT,
71 GENERAL_PROTECTION_FAULT,
72 PAGE_FAULT,
73 X87_FPE = 0x10,
74 ALIGNMENT_CHECK,
75 SIMD_FPE,
76 VIRTUALIZATTION_EXCEPTION,
77 CONTROL_PROTECTION_EXCEPTION,
78 HYPERVISOR_INJECTION_EXCEPTION = 0x1C,
79 VMM_COMMUNICATION_EXCEPTION,
80 SECURITY_EXCEPTION,
82
88typedef enum idt_gate_type {
89 TASK_GATE = 0x5,
90 INTERRUPT_GATE = 0x6,
91 TRAP_GATE = 0x7,
92 INTERRUPT_GATE_32B = 0xE,
93 TRAP_GATE_32B = 0xF,
95
99typedef struct idtr idtr;
100struct PACKED idtr {
102 u16 size;
105};
106
108typedef struct PACKED idt_descriptor {
113 u8 _reserved;
119
122
128 u32 edi, esi, ebp, esp;
129 u32 ebx, edx, ecx, eax;
130 } stub;
131
133 u32 nr;
135 u32 error;
136
142 u32 eip;
143 u32 cs;
144 u32 flags;
145 u32 esp;
146 u32 ss;
147 } state;
148};
149
151void idt_log(void);
152
153static ALWAYS_INLINE void arch_interrupts_disable(void)
154{
155 ASM("cli");
156}
157
158static ALWAYS_INLINE void arch_interrupts_enable(void)
159{
160 ASM("sti");
161}
162
163static ALWAYS_INLINE bool arch_interrupts_test_and_disable(void)
164{
165 u32 eflags;
166 ASM("pushf; cli; popl %0" : "=r"(eflags)::"memory");
167 return boolean(eflags & 0x200); // flag: IF
168}
169
170#endif /* KERNEL_I686_INTERRUPTS_H */
u32 offset
Linear address of the IDT
Definition: interrupts.h:104
u32 error
Error code for this exception (pushed by our stub)
Definition: interrupts.h:135
u16 size
Size of the IDT.
Definition: interrupts.h:102
u16 offset_low
16 lower bits of the handler function's address
Definition: interrupts.h:110
u16 offset_high
16 higher bits of the handler function's address
Definition: interrupts.h:117
void idt_log(void)
Print the content of the IDT and IDTR.
Definition: interrupts.c:153
x86_exceptions
List of all x86 CPU exceptions Intel developper manual, Table 6-1.
Definition: interrupts.h:57
u8 access
Acess restriction flags for this interrupt
Definition: interrupts.h:115
segment_selector segment
Selector for the segment inside which we want to run the handler.
Definition: interrupts.h:112
u32 nr
Interrupt number (pushed by our stub)
Definition: interrupts.h:133
idt_gate_type
The different types of interrupt gates Intel developper manual, section 6-11.
Definition: interrupts.h:88
Structure of the page fault's error code https://wiki.osdev.org/Exceptions#Page_Fault.
Definition: mmu.c:587
inside the IDT
Definition: interrupts.h:108
The location of the IDT is kept inside the IDTR (IDT register).
Definition: interrupts.h:100
Default x86 interrupt frame pushed by the cpu Intel developper manual, figure 6-4.
Definition: interrupts.h:141
Dump of the process's registers.
Definition: interrupts.h:127
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:121
Identifies a segment inside the GDT or LDT.
Definition: gdt.h:124