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#include <kernel/arch/i686/cpu.h>
46
47#include <utils/compiler.h>
48
54typedef enum {
55 DIVISION_ERROR = 0x0,
56 DEBUG,
57 NON_MASKABLE,
58 BREAKPOINT,
59 OVERFLOW,
60 BOUND_RANGE_EXCEEDED,
61 INVALID_OPCODE,
62 DEVICE_NOT_AVAILABLE,
63 DOUBLE_FAULT,
64 COPROCESSOR_SEGMENT_OVERRUN,
65 INVALID_TSS,
66 SEGMENT_NOT_PRESENT,
67 STACK_SEGMENT_FAULT,
68 GENERAL_PROTECTION_FAULT,
69 PAGE_FAULT,
70 X87_FPE = 0x10,
71 ALIGNMENT_CHECK,
72 SIMD_FPE,
73 VIRTUALIZATTION_EXCEPTION,
74 CONTROL_PROTECTION_EXCEPTION,
75 HYPERVISOR_INJECTION_EXCEPTION = 0x1C,
76 VMM_COMMUNICATION_EXCEPTION,
77 SECURITY_EXCEPTION,
79
85typedef enum idt_gate_type {
86 TASK_GATE = 0x5,
87 INTERRUPT_GATE = 0x6,
88 TRAP_GATE = 0x7,
89 INTERRUPT_GATE_32B = 0xE,
90 TRAP_GATE_32B = 0xF,
92
96typedef struct idtr idtr;
97struct PACKED idtr {
99 u16 size;
102};
103
105typedef struct PACKED idt_descriptor {
110 u8 _reserved;
116
119
121 struct x86_regs regs;
122
124 u32 nr;
125 u32 error;
126
127 /*
128 * The interrupt frame pushed by the hardware starts here.
129 */
130 struct x86_interrupt_frame frame;
131};
132
133static ALWAYS_INLINE void arch_interrupts_disable(void)
134{
135 ASM("cli");
136}
137
138static ALWAYS_INLINE void arch_interrupts_enable(void)
139{
140 ASM("sti");
141}
142
143static ALWAYS_INLINE bool arch_interrupts_test_and_disable(void)
144{
145 u32 eflags;
146 ASM("pushf; cli; popl %0" : "=r"(eflags)::"memory");
147 return boolean(eflags & 0x200); // flag: IF
148}
149
150static ALWAYS_INLINE bool arch_interrupts_enabled(void)
151{
152 u32 eflags;
153 ASM("pushf; popl %0" : "=r"(eflags)::"memory");
154 return boolean(eflags & 0x200); // flag: IF
155}
156
157#endif /* KERNEL_I686_INTERRUPTS_H */
error
All the error types used in ths project.
Definition: error.h:28
u32 offset
Linear address of the IDT
Definition: interrupts.h:101
u16 size
Size of the IDT.
Definition: interrupts.h:99
u16 offset_low
16 lower bits of the handler function's address
Definition: interrupts.h:107
u16 offset_high
16 higher bits of the handler function's address
Definition: interrupts.h:114
struct x86_regs regs
Snapshot of the registers at the time the interrupt happened.
Definition: interrupts.h:121
x86_exceptions
List of all x86 CPU exceptions Intel developper manual, Table 6-1.
Definition: interrupts.h:54
u8 access
Acess restriction flags for this interrupt
Definition: interrupts.h:112
segment_selector segment
Selector for the segment inside which we want to run the handler.
Definition: interrupts.h:109
u32 nr
Error code and interrupt number (pushed by our stub)
Definition: interrupts.h:124
idt_gate_type
The different types of interrupt gates Intel developper manual, section 6-11.
Definition: interrupts.h:85
Structure of the page fault's error code https://wiki.osdev.org/Exceptions#Page_Fault.
Definition: mmu.c:762
inside the IDT
Definition: interrupts.h:105
The location of the IDT is kept inside the IDTR (IDT register).
Definition: interrupts.h:97
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:118
Identifies a segment inside the GDT or LDT.
Definition: gdt.h:124