1 // Low-level serial (and serial-like) device access.
3 // Copyright (C) 2008-1013 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "config.h" // CONFIG_DEBUG_SERIAL
8 #include "fw/paravirt.h" // RunningOnQEMU
9 #include "output.h" // dprintf
10 #include "serialio.h" // serial_debug_preinit
11 #include "x86.h" // outb
14 /****************************************************************
15 * Serial port debug output
16 ****************************************************************/
18 #define DEBUG_TIMEOUT 100000
20 // Setup the debug serial port for output.
22 serial_debug_preinit(void)
24 if (!CONFIG_DEBUG_SERIAL)
26 // setup for serial logging: 8N1
27 u8 oldparam, newparam = 0x03;
28 oldparam = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR);
29 outb(newparam, CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR);
31 u8 oldier, newier = 0;
32 oldier = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER);
33 outb(newier, CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER);
35 if (oldparam != newparam || oldier != newier)
36 dprintf(1, "Changing serial settings was %x/%x now %x/%x\n"
37 , oldparam, oldier, newparam, newier);
40 // Write a character to the serial port.
44 if (!CONFIG_DEBUG_SERIAL)
46 int timeout = DEBUG_TIMEOUT;
47 while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x20) != 0x20)
51 outb(c, CONFIG_DEBUG_SERIAL_PORT+SEROFF_DATA);
55 serial_debug_putc(char c)
62 // Make sure all serial port writes have been completely sent.
64 serial_debug_flush(void)
66 if (!CONFIG_DEBUG_SERIAL)
68 int timeout = DEBUG_TIMEOUT;
69 while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x60) != 0x60)
76 /****************************************************************
78 ****************************************************************/
80 u16 DebugOutputPort VARFSEG = 0x402;
82 // Write a character to the special debugging port.
84 qemu_debug_putc(char c)
86 if (CONFIG_DEBUG_IO && runningOnQEMU())
87 // Send character to debug port.
88 outb(c, GET_GLOBAL(DebugOutputPort));