interrupts, timer, keyboard, segments, lots of kernel code
[bootcensus] / src / intr.h
1 #ifndef INTR_H_
2 #define INTR_H_
3
4 #include <inttypes.h>
5 #include "asmops.h"
6
7 /* offset used to remap IRQ numbers (+32) */
8 #define IRQ_OFFSET              32
9 /* conversion macros between IRQ and interrupt numbers */
10 #define IRQ_TO_INTR(x)  ((x) + IRQ_OFFSET)
11 #define INTR_TO_IRQ(x)  ((x) - IRQ_OFFSET)
12 /* checks whether a particular interrupt is an remapped IRQ */
13 #define IS_IRQ(n)       ((n) >= IRQ_OFFSET && (n) < IRQ_OFFSET + 16)
14
15 /* general purpose registers as they are pushed by pusha */
16 struct registers {
17         uint32_t edi, esi, ebp, esp;
18         uint32_t ebx, edx, ecx, eax;
19 } __attribute__ ((packed));
20
21 /* structure used to pass the interrupt stack frame from the
22  * entry points to the C dispatch function.
23  */
24 struct intr_frame {
25         /* registers pushed by pusha in intr_entry_* */
26         struct registers regs;
27         /* data segment selectors */
28         /* XXX removed: not needed unless we do dpl3 transitions
29         uint32_t ds, es, fs, gs;
30         */
31         /* interrupt number and error code pushed in intr_entry_* */
32         uint32_t inum, err;
33         /* pushed by CPU during interrupt entry */
34         uint32_t eip, cs, eflags;
35         /* pushed by CPU during interrupt entry from user space */
36         /* XXX removed: again, not doing user space currently
37         uint32_t esp, ss;
38         */
39 } __attribute__ ((packed));
40
41
42
43 typedef void (*intr_func_t)(int);
44
45
46 void init_intr(void);
47
48 struct intr_frame *get_intr_frame(void);
49
50 /* install high level interrupt callback */
51 void interrupt(int intr_num, intr_func_t func);
52
53 /* install low-level interrupt vector in IDT
54  * must be able to handle EOI and return with iret
55  */
56 void set_intr_entry(int num, void (*handler)(void));
57
58 /* defined in intr_asm.S */
59 int get_intr_flag(void);
60 void set_intr_flag(int onoff);
61
62 void intr_ret(struct intr_frame ifrm);
63
64 void end_of_irq(int irq);
65
66 #endif  /* INTR_H_ */