1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00

Add functions "pic_enable" and "pic_disable"

This commit is contained in:
Braiden Vasco 2017-11-06 11:49:53 +00:00
parent ebc05296af
commit eb3874fbcd
4 changed files with 46 additions and 1 deletions

View file

@ -52,4 +52,6 @@ void hwint_register_handler(unsigned int int_no, hwint_handler_t handler)
}
handlers[int_no] = handler;
pic_enable(int_no);
}

View file

@ -10,6 +10,7 @@
#define SLAVE_DATA 0xA1
#define IRQS_COUNT 8
#define IRQS_TOTAL 16
static unsigned char master_irq_start = 0;
static unsigned char slave_irq_start = 8;
@ -30,6 +31,45 @@ void pic_disable_all()
outportb(SLAVE_DATA, 0xFF);
}
void pic_enable(const unsigned char line)
{
if (line >= IRQS_TOTAL) {
logger_warn_from("pic", "Invalid line %u.", line);
return;
}
logger_info_from("pic", "Enable line %u.", line);
if (line < IRQS_COUNT) {
const unsigned char mask = inportb(MASTER_DATA);
outportb(MASTER_DATA, mask & ~(1 << line));
}
else {
const unsigned char mask = inportb(SLAVE_DATA);
outportb(SLAVE_DATA, mask & ~(1 << (line - IRQS_COUNT)));
}
}
void pic_disable(const unsigned char line)
{
if (line >= IRQS_TOTAL) {
logger_warn_from("pic", "Invalid line %u.", line);
return;
}
logger_info_from("pic", "Disable line %u.", line);
if (line < IRQS_COUNT) {
const unsigned char mask = inportb(MASTER_DATA);
outportb(MASTER_DATA, mask | (1 << line));
}
else {
const unsigned char mask = inportb(SLAVE_DATA);
outportb(SLAVE_DATA, mask | (1 << (line - IRQS_COUNT)));
}
}
void pic_remap(const unsigned char new_master_irq_start, const unsigned char new_slave_irq_start)
{
logger_info_from("pic", "Remap the IRQ table.");

View file

@ -6,6 +6,9 @@ void pic_remap(unsigned char master_irq_start, unsigned char slave_irq_start);
void pic_enable_all();
void pic_disable_all();
void pic_enable(unsigned char line);
void pic_disable(unsigned char line);
unsigned char pic_end_of_interrupt(unsigned char irq);
#endif

View file

@ -54,7 +54,7 @@ void idt_flush(const struct IdtPointer *pointer);
void protected_initialize(const struct KernelMQ_Info *const kinfo)
{
pic_remap(32, 40);
pic_enable_all();
pic_disable_all();
logger_info_from("protected", "Setup GDT.");