PIT/Serial irq refactoring

Serial IRQ still wip
This commit is contained in:
Mathieu Maret 2018-11-08 21:37:38 +01:00
parent e4200782ac
commit 00d7004815
6 changed files with 14 additions and 11 deletions

View File

@ -9,3 +9,4 @@ void print_handler(struct interrupt_frame *frame, ulong error_code);
//IRQ //IRQ
void keyboard_handler(struct interrupt_frame *frame); void keyboard_handler(struct interrupt_frame *frame);
void timer_handler(struct interrupt_frame *frame); void timer_handler(struct interrupt_frame *frame);
void serial_handler(struct interrupt_frame *frame);

View File

@ -25,5 +25,5 @@ __attribute__((interrupt)) void timer_handler(struct interrupt_frame *frame)
__attribute__((interrupt)) void serial_handler(struct interrupt_frame *frame) __attribute__((interrupt)) void serial_handler(struct interrupt_frame *frame)
{ {
EOIIrq(IRQ_COM1); EOIIrq(IRQ_COM1);
serial_do_irq((int)frame); serial_do_irq(frame);
} }

View File

@ -57,7 +57,6 @@ void kmain(unsigned long magic, unsigned long addr)
printf("Setting up IRQ handlers\n"); printf("Setting up IRQ handlers\n");
irqSetRoutine(IRQ_KEYBOARD, keyboard_handler); irqSetRoutine(IRQ_KEYBOARD, keyboard_handler);
irqSetRoutine(IRQ_TIMER, timer_handler);
printf("Enabling HW interrupts\n"); printf("Enabling HW interrupts\n");
exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler); exceptionSetRoutine(EXCEPTION_DOUBLE_FAULT, print_handler);
// Enabling the HW interrupts // Enabling the HW interrupts

View File

@ -1,5 +1,6 @@
#include "pit.h" #include "pit.h"
#include "io.h" #include "io.h"
#include "irq.h"
int initPit(unsigned int freq) int initPit(unsigned int freq)
{ {
@ -10,5 +11,6 @@ int initPit(unsigned int freq)
outb(PIT_CHAN_0, divisor & 0xFF); outb(PIT_CHAN_0, divisor & 0xFF);
outb(PIT_CHAN_0, divisor >> 8u); outb(PIT_CHAN_0, divisor >> 8u);
irqSetRoutine(IRQ_TIMER, timer_handler);
return 0; return 0;
} }

View File

@ -1,6 +1,7 @@
#include "serial.h" #include "serial.h"
#include "io.h" #include "io.h"
#include "irq.h" #include "irq.h"
#include "vga.h"
#define PORT 0x3f8 /* COM1 */ #define PORT 0x3f8 /* COM1 */
#define SERIAL_MAX_SPEED 115200 #define SERIAL_MAX_SPEED 115200
@ -31,11 +32,12 @@ void initSerial(int speed)
UART_NO_PARITY | UART_8BITS_WORD | UART_1_STOP_BIT); // 8 bits, no parity, one stop bit UART_NO_PARITY | UART_8BITS_WORD | UART_1_STOP_BIT); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
irqSetRoutine(IRQ_COM1, serial_handler);
} }
int isTransmitEmpty() int isTransmitEmpty()
{ {
return inb(PORT + 5) & 0x20; return (inb(PORT + 5) & 0x20);
} }
void writeSerial(char a) void writeSerial(char a)
@ -46,10 +48,9 @@ void writeSerial(char a)
outb(PORT, a); outb(PORT, a);
} }
void serial_do_irq(int level){ void serial_do_irq(struct interrupt_frame *level)
if(level == IRQ_COM1){ {
char c = inb(PORT + 5) & 1; (void)level;
char c = inb(PORT);
writeSerial(c); writeSerial(c);
}
return;
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "irq.h"
void initSerial(int speed); void initSerial(int speed);
void writeSerial(char a); void writeSerial(char a);
void serial_do_irq(int level); void serial_do_irq(struct interrupt_frame *frame);