diff options
Diffstat (limited to 'devices')
-rw-r--r-- | devices/i8042.c | 4 | ||||
-rw-r--r-- | devices/pic_8259.c | 18 | ||||
-rw-r--r-- | devices/uart.h | 2 | ||||
-rw-r--r-- | devices/uart/uart_16550.c | 14 | ||||
-rw-r--r-- | devices/uart/uart_16550.h | 6 | ||||
-rw-r--r-- | devices/vga.c | 12 | ||||
-rw-r--r-- | devices/vga.h | 2 |
7 files changed, 34 insertions, 24 deletions
diff --git a/devices/i8042.c b/devices/i8042.c index 4805529..cfd96a8 100644 --- a/devices/i8042.c +++ b/devices/i8042.c @@ -26,11 +26,11 @@ void ps2_ctrl_init() { int i; + uint8_t test, conf; /* eat all previous keystrikes */ while (inb(comm_port) & 0x1) inb(data_port); - uint8_t test; outb(0xaa, comm_port); test = inb(data_port); printf("i8042: self test 0xaa:%x %s\n", test, test == 0x55 ? "ok" : "failed"); @@ -63,7 +63,7 @@ ps2_ctrl_init() printf("\n"); outb(comm_read_ctrl_config, comm_port); - uint8_t conf = (inb(data_port) | 1) & ~0x10; + conf = (uint8_t)((inb(data_port) | 1) & ~0x10); conf |= 0x22; /* mouse */ outb(comm_write_ctrl_config, comm_port); diff --git a/devices/pic_8259.c b/devices/pic_8259.c index 7b4807c..75aaf6d 100644 --- a/devices/pic_8259.c +++ b/devices/pic_8259.c @@ -33,17 +33,25 @@ pic_init() outb(0xff, PIC2 + DATA); } +static unsigned char +irq_mask(unsigned char irq) +{ + unsigned char mask = (unsigned char)~(1u << irq); + return 0xff & mask; +} + void pic_enable() { unsigned char mask1 = 0xff; - mask1 &= ~(1 << 0); /* irq0 timer */ - mask1 &= ~(1 << 1); /* irq1 keyboard */ - mask1 &= ~(1 << 2); /* irq1 cascade */ + unsigned char mask2 = 0xff; + + mask1 &= irq_mask(0); /* irq0 timer */ + mask1 &= irq_mask(1); /* irq1 keyboard */ + mask1 &= irq_mask(2); /* irq2 cascade */ outb(mask1, PIC1 + DATA); - unsigned char mask2 = 0xff; - mask2 &= ~(1 << 4); /* irq12 mouse */ + mask2 &= irq_mask(12 - 8); /* irq12 mouse */ outb(mask2, PIC2 + DATA); enable_interrupts(); diff --git a/devices/uart.h b/devices/uart.h index 3349042..53a4f41 100644 --- a/devices/uart.h +++ b/devices/uart.h @@ -29,4 +29,4 @@ enum UART { }; #endif -FILE *uart_init(enum UART port); +FILE *uart_init(unsigned short port); diff --git a/devices/uart/uart_16550.c b/devices/uart/uart_16550.c index 0e19842..4697cf3 100644 --- a/devices/uart/uart_16550.c +++ b/devices/uart/uart_16550.c @@ -2,7 +2,7 @@ #include <stddef.h> int -uart_thre(enum UART port) +uart_thre(unsigned short port) { return inb(port + LineStatus) & THRE; } @@ -10,12 +10,14 @@ uart_thre(enum UART port) void uart_putc(const FILE *self, char a) { - while (uart_thre((enum UART)self->id) == 0) {} - outb(a, self->id); + const unsigned short port = (unsigned short)self->id; + + while (uart_thre(port) == 0) {} + outb((unsigned char)a, port); if (a == '\n') { - while (uart_thre((enum UART)self->id) == 0) {} - outb('\r', self->id); + while (uart_thre(port) == 0) {} + outb('\r', port); } } @@ -49,7 +51,7 @@ uart_flush(__attribute__((unused)) const FILE *self) FILE uart_stream; FILE * -uart_init(enum UART port) +uart_init(unsigned short port) { outb(0x00, port + 1); /* Disable all interrupts */ outb(0x80, port + 3); /* Enable DLAB (set baud rate divisor) */ diff --git a/devices/uart/uart_16550.h b/devices/uart/uart_16550.h index 176dea2..d4f470e 100644 --- a/devices/uart/uart_16550.h +++ b/devices/uart/uart_16550.h @@ -2,7 +2,7 @@ #include "../uart.h" -int uart_thre(enum UART port); +int uart_thre(unsigned short port); void uart_putc(const FILE *self, char a); int uart_puts(const FILE *self, const char *string, int length); void uart_flush(__attribute__((unused)) const FILE *self); @@ -15,7 +15,7 @@ enum uart_16550_offset { ModemControl = 4, LineStatus = 5, ModemStatus = 6, - Scratch = 7, + Scratch = 7 }; /* Line Control @@ -45,5 +45,5 @@ enum LineStatus { BI = (1 << 4), /* break indicator: see if there is a break in data input */ THRE = (1 << 5), /* transmitter holding register empty: see if transmission buffer is empty */ TEMT = (1 << 6), /* transmitter empty: see if transmitter is not doing anything */ - ERRO = (1 << 7), /* impending error: see if there is an error with a word in the input buffer */ + ERRO = (1 << 7) /* impending error: see if there is an error with a word in the input buffer */ }; diff --git a/devices/vga.c b/devices/vga.c index b2a6da4..51f860f 100644 --- a/devices/vga.c +++ b/devices/vga.c @@ -12,9 +12,9 @@ #define cursor_hide 0x20 struct __attribute__((packed)) VGAEntry { - unsigned char text; - uint8_t foreground : 4; - uint8_t background : 4; + char text; + unsigned foreground : 4; + unsigned background : 4; }; /* TODO _Static_assert(sizeof(struct VGAEntry) == 2, "sizeof VGAEntry"); */ @@ -46,13 +46,13 @@ vga_disable_cursor() void vga_update_cursor(void) { - const uint16_t pos = row * width + col; + const uint16_t pos = (uint16_t)(row * width + col); outb(cursor_addr_l, cga_idx_port); - outb(pos & 0xff, cga_dat_port); + outb((unsigned char)pos & 0xff, cga_dat_port); outb(cursor_addr_h, cga_idx_port); - outb((pos >> 8) & 0xff, cga_dat_port); + outb((unsigned char)(pos >> 8) & 0xff, cga_dat_port); } /* *** Text Mode Output *** */ diff --git a/devices/vga.h b/devices/vga.h index cd3a272..df0d921 100644 --- a/devices/vga.h +++ b/devices/vga.h @@ -19,7 +19,7 @@ enum vga_color { VGA_COLOR_LIGHT_RED = 12, VGA_COLOR_LIGHT_MAGENTA = 13, VGA_COLOR_LIGHT_BROWN = 14, - VGA_COLOR_WHITE = 15, + VGA_COLOR_WHITE = 15 }; FILE *vga_init(void *addr); |