diff options
Diffstat (limited to 'arch/x86/machine/cga.c')
-rw-r--r-- | arch/x86/machine/cga.c | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/arch/x86/machine/cga.c b/arch/x86/machine/cga.c index c926ec3d..86a661cb 100644 --- a/arch/x86/machine/cga.c +++ b/arch/x86/machine/cga.c @@ -18,6 +18,7 @@ #include <stdint.h> #include <string.h> +#include <kern/console.h> #include <kern/init.h> #include <kern/macros.h> #include <kern/param.h> @@ -69,6 +70,8 @@ static uint8_t *cga_memory __read_mostly; static uint16_t cga_cursor; +static struct console cga_console; + static uint16_t cga_get_cursor_position(void) { @@ -101,33 +104,6 @@ cga_get_cursor_column(void) return cga_cursor % CGA_COLUMNS; } -void __init -cga_setup(void) -{ - uint8_t misc_output_register; - - cga_memory = (void *)vm_page_direct_va(CGA_MEMORY); - - /* - * Check if the Input/Output Address Select bit is set. - */ - misc_output_register = io_read_byte(CGA_MISC_OUTPUT_REGISTER_READ); - - if (!(misc_output_register & 0x1)) { - /* - * Set the I/O AS bit. - */ - misc_output_register |= 0x1; - - /* - * Update the misc output register. - */ - io_write_byte(CGA_MISC_OUTPUT_REGISTER_WRITE, misc_output_register); - } - - cga_cursor = cga_get_cursor_position(); -} - static void cga_scroll_lines(void) { @@ -143,12 +119,12 @@ cga_scroll_lines(void) } } -void -cga_write_byte(uint8_t byte) +static void +cga_write_char(char c) { - if (byte == '\r') { + if (c == '\r') { return; - } else if (byte == '\n') { + } else if (c == '\n') { cga_cursor += CGA_COLUMNS - cga_get_cursor_column(); if (cga_cursor >= (CGA_LINES * CGA_COLUMNS)) { @@ -157,17 +133,17 @@ cga_write_byte(uint8_t byte) } cga_set_cursor_position(cga_cursor); - } else if (byte == '\b') { + } else if (c == '\b') { if (cga_cursor > 0) { cga_cursor--; ((uint16_t *)cga_memory)[cga_cursor] = CGA_BLANK; cga_set_cursor_position(cga_cursor); } - } else if (byte == '\t') { + } else if (c == '\t') { int i; for(i = 0; i < CGA_TABULATION_SPACES; i++) { - cga_write_byte(' '); + cga_write_char(' '); } } else { if ((cga_cursor + 1) >= CGA_COLUMNS * CGA_LINES) { @@ -176,10 +152,45 @@ cga_write_byte(uint8_t byte) } ((uint16_t *)cga_memory)[cga_cursor] = ((CGA_FOREGROUND_COLOR << 8) - | byte); + | c); cga_cursor++; cga_set_cursor_position(cga_cursor); } } -void console_write_byte(char c) __alias("cga_write_byte"); +static void +cga_console_putc(struct console *console, char c) +{ + (void)console; + cga_write_char(c); +} + +void __init +cga_setup(void) +{ + uint8_t misc_output_register; + + cga_memory = (void *)vm_page_direct_va(CGA_MEMORY); + + /* + * Check if the Input/Output Address Select bit is set. + */ + misc_output_register = io_read_byte(CGA_MISC_OUTPUT_REGISTER_READ); + + if (!(misc_output_register & 0x1)) { + /* + * Set the I/O AS bit. + */ + misc_output_register |= 0x1; + + /* + * Update the misc output register. + */ + io_write_byte(CGA_MISC_OUTPUT_REGISTER_WRITE, misc_output_register); + } + + cga_cursor = cga_get_cursor_position(); + + console_init(&cga_console, cga_console_putc); + console_register(&cga_console); +} |