diff options
author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2007-10-21 20:50:07 +0000 |
---|---|---|
committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2007-10-21 20:50:07 +0000 |
commit | 2ed14491290b52c92da6bb0534d1a7c208d80be3 (patch) | |
tree | fb3dcb4d88773765eeac1104d39aa4d7f03e0519 /src/VBox/Runtime/common/log/logcom.cpp | |
parent | c05261631909ed071a17f36eae49fa8bf252835a (diff) | |
download | VirtualBox-svn-2ed14491290b52c92da6bb0534d1a7c208d80be3.tar.gz |
log* -> common/log/
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@5415 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Runtime/common/log/logcom.cpp')
-rw-r--r-- | src/VBox/Runtime/common/log/logcom.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/VBox/Runtime/common/log/logcom.cpp b/src/VBox/Runtime/common/log/logcom.cpp new file mode 100644 index 00000000000..adbcc7d9e6d --- /dev/null +++ b/src/VBox/Runtime/common/log/logcom.cpp @@ -0,0 +1,113 @@ +/* $Id$ */ +/** @file + * innotek Portable Runtime - Logging to Serial Port. + */ + +/* + * Copyright (C) 2006-2007 innotek GmbH + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation, + * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE + * distribution. VirtualBox OSE is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +/******************************************************************************* +* Defined Constants And Macros * +*******************************************************************************/ +/** Comport to log to (COM2). + * This is also defined in VBox/nasm.mac. */ +//#define UART_BASE 0x2f8 /* COM2 */ +#define UART_BASE 0x3f8 /* COM1 */ + + +/******************************************************************************* +* Header Files * +*******************************************************************************/ +#include <iprt/log.h> +#include <iprt/asm.h> +#include <iprt/stdarg.h> +#include <iprt/string.h> + + +/******************************************************************************* +* Internal Functions * +*******************************************************************************/ +static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars); + + +/** + * Prints a formatted string to the serial port used for logging. + * + * @returns Number of bytes written. + * @param pszFormat Format string. + * @param ... Optional arguments specified in the format string. + */ +RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...) +{ + va_list args; + size_t cb; + va_start(args, pszFormat); + cb = RTLogComPrintfV(pszFormat, args); + va_end(args); + + return cb; +} + + +/** + * Prints a formatted string to the serial port used for logging. + * + * @returns Number of bytes written. + * @param pszFormat Format string. + * @param args Optional arguments specified in the format string. + */ +RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args) +{ + return RTLogFormatV(rtLogComOutput, NULL, pszFormat, args); +} + + +/** + * Callback for RTLogFormatV which writes to the com port. + * See PFNLOGOUTPUT() for details. + */ +static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars) +{ + if (cbChars) + RTLogWriteCom(pachChars, cbChars); + return cbChars; +} + + +/** + * Write log buffer to COM port. + * + * @param pach Pointer to the buffer to write. + * @param cb Number of bytes to write. + */ +RTDECL(void) RTLogWriteCom(const char *pach, size_t cb) +{ + for (const uint8_t *pu8 = (const uint8_t *)pach; cb-- > 0; pu8++) + { + /* expand \n -> \r\n */ + if (*pu8 == '\n') + RTLogWriteCom("\r", 1); + + /* Check if port is ready. */ + register unsigned cMaxWait = ~0; + register uint8_t u8; + do + { + u8 = ASMInU8(UART_BASE + 5); + cMaxWait--; + } while (!(u8 & 0x20) && u8 != 0xff && cMaxWait); + + /* write */ + ASMOutU8(UART_BASE, *pu8); + } +} + |