| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /* 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 <https://www.gnu.org/licenses/>.
- */
- #include <kernel/init.h>
- #include <kernel/errno.h>
- #include <kernel/types.h>
- #include <kernel/console.h>
- #include <kernel/int.h>
- #include <kernel/schk.h>
- #include <arch/x86/int.h>
- #include <arch/io.h>
- #include <arch/sys.h>
- 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 {
- /* enable slave-irq */
- mask = inb(0x21) & ~(1 << 2);
- outb(mask, 0x21);
- 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;
- }
|