io refactor

master
E. Almqvist 3 years ago
parent 7f90abb200
commit da65e49c60
  1. 4
      drivers/vga.c
  2. 33
      kernel/io.c
  3. 15
      kernel/io.h
  4. 21
      kernel/pic.c
  5. 2
      kernel/pic.h

@ -11,8 +11,8 @@ static uint cursor_col = 0;
void vga_init() { void vga_init() {
// Disable cursor // Disable cursor
port_outb(0x3d4, 0x0a); outb(0x3d4, 0x0a);
port_outb(0x3d5, 0x20); outb(0x3d5, 0x20);
// Clear screen // Clear screen
// clear_row(0); // clear_row(0);

@ -1,5 +1,5 @@
// Function to read a byte from port // Function to read a byte from port
unsigned char port_inb(unsigned short port) { unsigned char inb(unsigned short port) {
unsigned char res; unsigned char res;
__asm__("in %%dx, %%al" : "=a" (res) : "d" (port)); __asm__("in %%dx, %%al" : "=a" (res) : "d" (port));
@ -7,13 +7,13 @@ unsigned char port_inb(unsigned short port) {
} }
// to write a byte to port // to write a byte to port
void port_outb(unsigned short port, unsigned char data) { void outb(unsigned short port, unsigned char data) {
__asm__("out %%al, %%dx" : :"a" (data), "d" (port)); __asm__("out %%al, %%dx" : :"a" (data), "d" (port));
} }
// Read word from port // Read word from port
unsigned short port_inw(unsigned short port) { unsigned short inw(unsigned short port) {
unsigned short res; unsigned short res;
__asm__("in %%dx, %%ax" : "=a" (res) : "d" (port)); __asm__("in %%dx, %%ax" : "=a" (res) : "d" (port));
@ -21,9 +21,32 @@ unsigned short port_inw(unsigned short port) {
} }
// write word to port // write word to port
void port_outw(unsigned short port, unsigned short data) { void outw(unsigned short port, unsigned short data) {
__asm__("out %%ax, %%dx" : :"a" (data), "d" (port)); __asm__("out %%ax, %%dx" : :"a" (data), "d" (port));
} }
static inline void io_wait() { port_outb(0x80, 0); } static inline void io_wait() {
outb(0x80, 0);
}
unsigned char inb_w(unsigned short port) {
inb(port);
io_wait();
}
void outb_w(unsigned short port, unsigned char data) {
outb(port, data);
io_wait();
}
unsigned short inw_w(unsigned short port) {
inw(port);
io_wait();
}
void outw_w(unsigned short port, unsigned short data) {
outw(port, data);
io_wait();
}

@ -1,7 +1,14 @@
unsigned char port_inb(); unsigned char inb(unsigned short);
void port_outb(); void outb(unsigned short, unsigned char);
unsigned short port_inw(); unsigned short inw(unsigned short);
void port_outw(); void outw(unsigned short, unsigned short);
static inline void io_wait(); static inline void io_wait();
// wrappers but with io_wait
unsigned char inb_w(unsigned short);
void outb_w(unsigned short, unsigned char);
unsigned short inw_w(unsigned short);
void outw_w(unsigned short, unsigned short);

@ -1,8 +1,25 @@
#include "pic.h" #include "pic.h"
#include "io.h"
void PIC_sendEOI(uint8 irq) { void PIC_sendEOI(uint8 irq) {
if( irq >= 8 ) if( irq >= 8 )
port_outb(PIC2_CMD, PIC_EOI); outb(PIC2_CMD, PIC_EOI);
port_outb(PIC1_CMD, PIC_EOI); outb(PIC1_CMD, PIC_EOI);
} }
void PIC_remap(uint offset_1, uint offset_2) {
uint8 a1, a2;
a1 = inb(PIC1_DATA);
a2 = inb(PIC2_DATA);
// Start the init sequance
outb_w( PIC1_CMD, ICW_INIT_MASK );
outb_w(PIC2_CMD, ICW_INIT_MASK );
outb_w(PIC1_DATA, offset_1); // ICW2 master offset
outb_w(PIC2_DATA, offset_2); // ICW2 slave offset
outb_w(PIC1_DATA, 0x4);
outb_w(PIC2_DATA, 0x2);
}

@ -23,6 +23,8 @@
#define ICW4_BUF_MASTER 0x0C #define ICW4_BUF_MASTER 0x0C
#define ICW4_SFNM 0x10 #define ICW4_SFNM 0x10
#define ICW_INIT_MASK (ICW1_INIT | ICW1_ICW4)
// Ints // Ints
#define PIC_EOI 0x20 // End-of-interupt #define PIC_EOI 0x20 // End-of-interupt

Loading…
Cancel
Save