--- qemu/roms/seabios/src/output.c 2018/04/24 18:27:31 1.1.1.3 +++ qemu/roms/seabios/src/output.c 2018/04/24 19:24:01 1.1.1.5 @@ -21,7 +21,6 @@ struct putcinfo { * Debug output ****************************************************************/ -#define DEBUG_PORT PORT_SERIAL1 #define DEBUG_TIMEOUT 100000 void @@ -31,12 +30,12 @@ debug_serial_setup(void) return; // setup for serial logging: 8N1 u8 oldparam, newparam = 0x03; - oldparam = inb(DEBUG_PORT+SEROFF_LCR); - outb(newparam, DEBUG_PORT+SEROFF_LCR); + oldparam = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR); + outb(newparam, CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR); // Disable irqs u8 oldier, newier = 0; - oldier = inb(DEBUG_PORT+SEROFF_IER); - outb(newier, DEBUG_PORT+SEROFF_IER); + 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" @@ -50,11 +49,11 @@ debug_serial(char c) if (!CONFIG_DEBUG_SERIAL) return; int timeout = DEBUG_TIMEOUT; - while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x60) != 0x60) + while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x20) != 0x20) if (!timeout--) // Ran out of time. return; - outb(c, DEBUG_PORT+SEROFF_DATA); + outb(c, CONFIG_DEBUG_SERIAL_PORT+SEROFF_DATA); } // Make sure all serial port writes have been completely sent. @@ -64,7 +63,7 @@ debug_serial_flush(void) if (!CONFIG_DEBUG_SERIAL) return; int timeout = DEBUG_TIMEOUT; - while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x40) != 0x40) + while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x60) != 0x60) if (!timeout--) // Ran out of time. return; @@ -116,7 +115,7 @@ screenc(char c) static void putc_screen(struct putcinfo *action, char c) { - if (CONFIG_SCREEN_AND_DEBUG) + if (ScreenAndDebug) putc_debug(&debuginfo, c); if (c == '\n') screenc('\r'); @@ -148,6 +147,8 @@ putc(struct putcinfo *action, char c) static void puts(struct putcinfo *action, const char *s) { + if (!MODESEGMENT && !s) + s = "(NULL)"; for (; *s; s++) putc(action, *s); } @@ -362,7 +363,7 @@ printf(const char *fmt, ...) va_start(args, fmt); bvprintf(&screeninfo, fmt, args); va_end(args); - if (CONFIG_SCREEN_AND_DEBUG) + if (ScreenAndDebug) debug_serial_flush(); } @@ -407,6 +408,30 @@ snprintf(char *str, size_t size, const c return end - str; } +// Build a formatted string - malloc'ing the memory. +char * +znprintf(size_t size, const char *fmt, ...) +{ + ASSERT32FLAT(); + if (!size) + return NULL; + char *str = malloc_tmp(size); + if (!str) { + warn_noalloc(); + return NULL; + } + struct snprintfinfo sinfo = { { putc_str }, str, str + size }; + va_list args; + va_start(args, fmt); + bvprintf(&sinfo.info, fmt, args); + va_end(args); + char *end = sinfo.str; + if (end >= sinfo.end) + end = sinfo.end - 1; + *end = '\0'; + return str; +} + /**************************************************************** * Misc helpers