This commit is contained in:
Mathieu Maret 2018-07-18 01:41:10 +02:00
parent 37d772d1c7
commit 9756f3f3ce
3 changed files with 20 additions and 5 deletions

View File

@ -1,11 +1,13 @@
#include "interrupt.h" #include "interrupt.h"
#include "vga.h" #include "vga.h"
#include "io.h" #include "io.h"
#include "pic.h"
#include "irq.h"
// Need GCC > 6 // Need GCC > 6
__attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame) __attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame)
{ {
printString("Keyboard!", RED, BLACK, 0, 7); EOIIrq(IRQ_KEYBOARD);
char c = 0; char c = 0;
if (inb(0x60) != c) { if (inb(0x60) != c) {
c = inb(0x60); c = inb(0x60);
@ -17,6 +19,8 @@ __attribute__((interrupt)) void keyboard_handler(struct interrupt_frame *frame)
__attribute__((interrupt)) void timer_handler(struct interrupt_frame *frame) __attribute__((interrupt)) void timer_handler(struct interrupt_frame *frame)
{ {
printString("Timer!", RED, BLACK, 0, 9); static int timeCnt = 0;
EOIIrq(IRQ_TIMER);
printInt(timeCnt++, RED, BLACK, 0, 9);
(void)frame; (void)frame;
} }

8
pic.c
View File

@ -42,6 +42,14 @@ void initPic(void)
outb(PIC_SLAVE_DATA, 0xFF); outb(PIC_SLAVE_DATA, 0xFF);
} }
void EOIIrq(int irq)
{
if (irq >= 8)
outb(PIC_SLAVE_CMD, PIC_EOI);
outb(PIC_MASTER_CMD, PIC_EOI);
}
void disableIrq(int irq) void disableIrq(int irq)
{ {
if (irq < 8) { if (irq < 8) {

9
pic.h
View File

@ -1,5 +1,5 @@
#pragma once #pragma once
//2 PIC 8259 are available on x86 // 2 PIC 8259 are available on x86
// //
// Master - command: 0x20, data: 0x21 // Master - command: 0x20, data: 0x21
// Slave - command: 0xA0, data: 0xA1 // Slave - command: 0xA0, data: 0xA1
@ -9,10 +9,13 @@
// http://wiki.osdev.org/PIC // http://wiki.osdev.org/PIC
#define PIC_MASTER_CMD 0x20 #define PIC_MASTER_CMD 0x20
#define PIC_SLAVE_CMD 0xa0 #define PIC_SLAVE_CMD 0xa0
#define PIC_MASTER_DATA 0x21 #define PIC_MASTER_DATA 0x21
#define PIC_SLAVE_DATA 0xa1 #define PIC_SLAVE_DATA 0xa1
#define PIC_EOI 0x20 /* End-of-interrupt command code */
void EOIIrq(int irq);
void initPic(void); void initPic(void);
void enableIrq(int irq); void enableIrq(int irq);
void disableIrq(int irq); void disableIrq(int irq);