diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2013-11-29 12:14:34 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2013-12-04 10:34:17 -0500 |
commit | 4cd522e673426e68a96e8d2a026b99e58a821ca0 (patch) | |
tree | f3b15a6389c4eeca46ae8358ce910f4e22ca1cf9 /src/output.c | |
parent | 3ecdc492ce1f2b7308dde85f1aba6a582a68f3cc (diff) | |
download | seabios-4cd522e673426e68a96e8d2a026b99e58a821ca0.tar.gz |
Move low-level hardware writing from output.c to new file hw/serialio.c.
Avoid hardware specific code in output.c. This will reduce the amount
of change needed to output.c as support for more serial hardware is
added.
This patch also renames some functions to improve the naming scheme.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/output.c')
-rw-r--r-- | src/output.c | 101 |
1 files changed, 30 insertions, 71 deletions
diff --git a/src/output.c b/src/output.c index b47625f1..1d882fa6 100644 --- a/src/output.c +++ b/src/output.c @@ -1,6 +1,6 @@ // Raw screen writing and debug output code. // -// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net> +// Copyright (C) 2008-2013 Kevin O'Connor <kevin@koconnor.net> // // This file may be distributed under the terms of the GNU LGPLv3 license. @@ -10,8 +10,7 @@ #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL -#include "fw/paravirt.h" // PlatformRunningOn -#include "hw/serialio.h" // SEROFF_IER +#include "hw/serialio.h" // serial_debug_putc #include "malloc.h" // malloc_tmp #include "output.h" // dprintf #include "stacks.h" // call16_int @@ -27,81 +26,41 @@ struct putcinfo { * Debug output ****************************************************************/ -#define DEBUG_TIMEOUT 100000 - -u16 DebugOutputPort VARFSEG = 0x402; - +// Setup debugging port(s). void -debug_serial_preinit(void) +debug_preinit(void) { - if (!CONFIG_DEBUG_SERIAL) - return; - // setup for serial logging: 8N1 - u8 oldparam, newparam = 0x03; - oldparam = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR); - outb(newparam, CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR); - // Disable irqs - u8 oldier, newier = 0; - oldier = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER); - outb(newier, CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER); - - if (oldparam != newparam || oldier != newier) - dprintf(1, "Changing serial settings was %x/%x now %x/%x\n" - , oldparam, oldier, newparam, newier); -} - -// Write a character to the serial port. -static void -debug_serial(char c) -{ - if (!CONFIG_DEBUG_SERIAL) - return; - int timeout = DEBUG_TIMEOUT; - while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x20) != 0x20) - if (!timeout--) - // Ran out of time. - return; - outb(c, CONFIG_DEBUG_SERIAL_PORT+SEROFF_DATA); + serial_debug_preinit(); } -// Make sure all serial port writes have been completely sent. +// Write a character to debug port(s). static void -debug_serial_flush(void) +debug_putc(struct putcinfo *action, char c) { - if (!CONFIG_DEBUG_SERIAL) + if (! CONFIG_DEBUG_LEVEL) return; - int timeout = DEBUG_TIMEOUT; - while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x60) != 0x60) - if (!timeout--) - // Ran out of time. - return; + qemu_debug_putc(c); + if (!MODESEGMENT) + coreboot_debug_putc(c); + serial_debug_putc(c); } -// Write a character to debug port(s). +// Flush any pending output to debug port(s). static void -putc_debug(struct putcinfo *action, char c) +debug_flush(void) { - if (! CONFIG_DEBUG_LEVEL) - return; - if (CONFIG_DEBUG_IO && runningOnQEMU()) - // Send character to debug port. - outb(c, GET_GLOBAL(DebugOutputPort)); - if (!MODESEGMENT) - debug_cbmem(c); - if (c == '\n') - debug_serial('\r'); - debug_serial(c); + serial_debug_flush(); } -// In segmented mode just need a dummy variable (putc_debug is always +// In segmented mode just need a dummy variable (debug_putc is always // used anyway), and in 32bit flat mode need a pointer to the 32bit -// instance of putc_debug(). +// instance of debug_putc(). #if MODE16 static struct putcinfo debuginfo VAR16; #elif MODESEGMENT static struct putcinfo debuginfo VAR32SEG; #else -static struct putcinfo debuginfo = { putc_debug }; +static struct putcinfo debuginfo = { debug_putc }; #endif @@ -123,16 +82,16 @@ screenc(char c) // Handle a character from a printf request. static void -putc_screen(struct putcinfo *action, char c) +screen_putc(struct putcinfo *action, char c) { if (ScreenAndDebug) - putc_debug(&debuginfo, c); + debug_putc(&debuginfo, c); if (c == '\n') screenc('\r'); screenc(c); } -static struct putcinfo screeninfo = { putc_screen }; +static struct putcinfo screeninfo = { screen_putc }; /**************************************************************** @@ -145,7 +104,7 @@ putc(struct putcinfo *action, char c) { if (MODESEGMENT) { // Only debugging output supported in segmented mode. - putc_debug(action, c); + debug_putc(action, c); return; } @@ -348,7 +307,7 @@ panic(const char *fmt, ...) va_start(args, fmt); bvprintf(&debuginfo, fmt, args); va_end(args); - debug_serial_flush(); + debug_flush(); } // XXX - use PANIC PORT. @@ -365,10 +324,10 @@ __dprintf(const char *fmt, ...) struct thread_info *cur = getCurThread(); if (cur != &MainThread) { // Show "thread id" for this debug message. - putc_debug(&debuginfo, '|'); + debug_putc(&debuginfo, '|'); puthex(&debuginfo, (u32)cur, 8); - putc_debug(&debuginfo, '|'); - putc_debug(&debuginfo, ' '); + debug_putc(&debuginfo, '|'); + debug_putc(&debuginfo, ' '); } } @@ -376,7 +335,7 @@ __dprintf(const char *fmt, ...) va_start(args, fmt); bvprintf(&debuginfo, fmt, args); va_end(args); - debug_serial_flush(); + debug_flush(); } void @@ -388,7 +347,7 @@ printf(const char *fmt, ...) bvprintf(&screeninfo, fmt, args); va_end(args); if (ScreenAndDebug) - debug_serial_flush(); + debug_flush(); } @@ -479,7 +438,7 @@ hexdump(const void *d, int len) d+=4; } putc(&debuginfo, '\n'); - debug_serial_flush(); + debug_flush(); } static void @@ -503,7 +462,7 @@ __debug_isr(const char *fname) { puts_cs(&debuginfo, fname); putc(&debuginfo, '\n'); - debug_serial_flush(); + debug_flush(); } // Function called on handler startup. |