/* Copyright (C) 2021 Rain */ /* This file is part of XNIX. */ /* XNIX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) and later version. */ /* XNIX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License along with XNIX. If not, see . */ #include #include #include #include #include #include #include #include #include struct irq_entry irq_table[MAX_IRQ_NR]; void register_irq(int nr, void *entry, const void *handler) { schk_init(); __uint8_t mask; if (nr < 8) { mask = inb(0x21) & ~(1 << nr); outb(mask, 0x21); } else { mask = inb(0xa1) & ~(1 << (nr-8)); outb(mask, 0xa1); } irq_table[nr].handler = handler; /* IRQ nr starts at 0x20 */ set_int_gate(idt_table + 0x20 + nr, 0, entry); schk_leave(); return; } void unregister_irq(int nr) { schk_init(); __uint8_t mask; irq_table[nr].handler = NULL; if (nr < 8) { mask = inb(0x21) | 1 << nr; outb(mask, 0x21); } else { mask = inb(0xa1) | 1 << (nr - 8); outb(mask, 0xa1); } schk_leave(); return; } void do_irq(const __uint64_t *rsp, __uint64_t nr) { schk_init(); void (*fn) (void) = irq_table[nr - 0x20].handler; if (fn) fn(); else printk(red, "unknow irq %x\n", nr - 0x20); outb(0x20, 0x20); schk_leave(); return; }