x86: add irq support
This commit is contained in:
parent
89f3393b8b
commit
4679b7cee5
14 changed files with 433 additions and 14 deletions
83
kernel/irq.c
Normal file
83
kernel/irq.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/* See the end of this file for copyright and license terms. */
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include <gay/config.h>
|
||||
#include <gay/errno.h>
|
||||
#include <gay/irq.h>
|
||||
#include <gay/kprintf.h>
|
||||
|
||||
void (*irq_table[NUM_IRQ])(void);
|
||||
|
||||
#if CFG_DEBUG_IRQ
|
||||
/*
|
||||
* If CFG_DEBUG_IRQ is set, the IRQ entry points pass the IRQ number
|
||||
* as an argument to the IRQ handler (see arch/<arch>/sys/irq.S).
|
||||
*/
|
||||
static void do_unknown_irq(unsigned int number)
|
||||
{
|
||||
kprintf("Unknown IRQ %d encountered!\n", number);
|
||||
}
|
||||
# define UNKNOWN_IRQ_HANDLER ((void (*)(void))do_unknown_irq)
|
||||
#else
|
||||
static void do_unknown_irq(void)
|
||||
{
|
||||
kprintf("Unknown IRQ encountered!\n");
|
||||
}
|
||||
# define UNKNOWN_IRQ_HANDLER (do_unknown_irq)
|
||||
#endif
|
||||
|
||||
void irq_init(void)
|
||||
{
|
||||
for (unsigned int i = 0; i < NUM_IRQ; i++)
|
||||
irq_table[i] = UNKNOWN_IRQ_HANDLER;
|
||||
arch_irq_init();
|
||||
}
|
||||
|
||||
int irq_enable(unsigned int number)
|
||||
{
|
||||
if (number >= NUM_IRQ)
|
||||
return -ERANGE;
|
||||
if (irq_table[number] == UNKNOWN_IRQ_HANDLER)
|
||||
return -ENOENT;
|
||||
|
||||
arch_irq_enable(number);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void irq_disable(unsigned int number)
|
||||
{
|
||||
if (number < NUM_IRQ)
|
||||
arch_irq_disable(number);
|
||||
}
|
||||
|
||||
int irq_attach(unsigned int number, void (*handler)(void))
|
||||
{
|
||||
if (number >= NUM_IRQ)
|
||||
return -ERANGE;
|
||||
if (irq_table[number] != UNKNOWN_IRQ_HANDLER)
|
||||
return -EEXIST;
|
||||
|
||||
irq_table[number] = handler;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void irq_detach(unsigned int number)
|
||||
{
|
||||
if (number < NUM_IRQ)
|
||||
irq_table[number] = UNKNOWN_IRQ_HANDLER;
|
||||
}
|
||||
|
||||
/*
|
||||
* This file is part of GayBSD.
|
||||
* Copyright (c) 2021 fef <owo@fef.moe>.
|
||||
*
|
||||
* GayBSD is nonviolent software: you may only use, redistribute, and/or
|
||||
* modify it under the terms of the Cooperative Nonviolent Public License
|
||||
* (CNPL) as found in the LICENSE file in the source code root directory
|
||||
* or at <https://git.pixie.town/thufie/npl-builder>; either version 7
|
||||
* of the license, or (at your option) any later version.
|
||||
*
|
||||
* GayBSD comes with ABSOLUTELY NO WARRANTY, to the extent
|
||||
* permitted by applicable law. See the CNPL for details.
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue