fe6ed4403fb7e11188a08048eb87fa76faa48545
[bootcensus] / src / intr.h
1 /*
2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef INTR_H_
19 #define INTR_H_
20
21 #include <inttypes.h>
22 #include "asmops.h"
23
24 /* offset used to remap IRQ numbers (+32) */
25 #define IRQ_OFFSET              32
26 /* conversion macros between IRQ and interrupt numbers */
27 #define IRQ_TO_INTR(x)  ((x) + IRQ_OFFSET)
28 #define INTR_TO_IRQ(x)  ((x) - IRQ_OFFSET)
29 /* checks whether a particular interrupt is an remapped IRQ */
30 #define IS_IRQ(n)       ((n) >= IRQ_OFFSET && (n) < IRQ_OFFSET + 16)
31
32 /* general purpose registers as they are pushed by pusha */
33 struct registers {
34         uint32_t edi, esi, ebp, esp;
35         uint32_t ebx, edx, ecx, eax;
36 } __attribute__ ((packed));
37
38 /* structure used to pass the interrupt stack frame from the
39  * entry points to the C dispatch function.
40  */
41 struct intr_frame {
42         /* registers pushed by pusha in intr_entry_* */
43         struct registers regs;
44         /* data segment selectors */
45         /* XXX removed: not needed unless we do dpl3 transitions
46         uint32_t ds, es, fs, gs;
47         */
48         /* interrupt number and error code pushed in intr_entry_* */
49         uint32_t inum, err;
50         /* pushed by CPU during interrupt entry */
51         uint32_t eip, cs, eflags;
52         /* pushed by CPU during interrupt entry from user space */
53         /* XXX removed: again, not doing user space currently
54         uint32_t esp, ss;
55         */
56 } __attribute__ ((packed));
57
58
59
60 typedef void (*intr_func_t)(int);
61
62
63 void init_intr(void);
64
65 struct intr_frame *get_intr_frame(void);
66
67 /* install high level interrupt callback */
68 void interrupt(int intr_num, intr_func_t func);
69
70 /* install low-level interrupt vector in IDT
71  * must be able to handle EOI and return with iret
72  */
73 void set_intr_entry(int num, void (*handler)(void));
74
75 void set_pic_mask(int pic, unsigned char mask);
76 unsigned char get_pic_mask(int pic);
77 void mask_irq(int irq);
78 void unmask_irq(int irq);
79
80 /* defined in intr_asm.S */
81 int get_intr_flag(void);
82 void set_intr_flag(int onoff);
83
84 void intr_ret(struct intr_frame ifrm);
85
86 void end_of_irq(int irq);
87
88 #endif  /* INTR_H_ */