VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/log/logcom.cpp@ 6525

Last change on this file since 6525 was 6525, checked in by vboxsync, 17 years ago

UART_BASE -> IPRT_UART_BASE so it can safely be overrided by a DEFS += IPRT_UART_BASE=0xd800 statement in LocalConfig.kmk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1/* $Id: logcom.cpp 6525 2008-01-28 12:52:23Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Logging to Serial Port.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Defined Constants And Macros *
29*******************************************************************************/
30#ifndef IPRT_UART_BASE
31/** The port address of the COM port to log to.
32 *
33 * To override the default (COM1) append IPRT_UART_BASE=0xWXYZ to DEFS in your
34 * LocalConfig.kmk. Alternatively you can edit this file, but the don't forget
35 * to also update the default found in VBox/asmdefs.h.
36 *
37 * Standard port assignments are: COM1=0x3f8, COM2=0x2f8, COM3=0x3e8, COM4=0x2e8.
38 */
39# define IPRT_UART_BASE 0x3f8
40#endif
41
42
43/*******************************************************************************
44* Header Files *
45*******************************************************************************/
46#include <iprt/log.h>
47#include <iprt/asm.h>
48#include <iprt/stdarg.h>
49#include <iprt/string.h>
50
51
52/*******************************************************************************
53* Internal Functions *
54*******************************************************************************/
55static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars);
56
57
58/**
59 * Prints a formatted string to the serial port used for logging.
60 *
61 * @returns Number of bytes written.
62 * @param pszFormat Format string.
63 * @param ... Optional arguments specified in the format string.
64 */
65RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...)
66{
67 va_list args;
68 size_t cb;
69 va_start(args, pszFormat);
70 cb = RTLogComPrintfV(pszFormat, args);
71 va_end(args);
72
73 return cb;
74}
75
76
77/**
78 * Prints a formatted string to the serial port used for logging.
79 *
80 * @returns Number of bytes written.
81 * @param pszFormat Format string.
82 * @param args Optional arguments specified in the format string.
83 */
84RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args)
85{
86 return RTLogFormatV(rtLogComOutput, NULL, pszFormat, args);
87}
88
89
90/**
91 * Callback for RTLogFormatV which writes to the com port.
92 * See PFNLOGOUTPUT() for details.
93 */
94static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars)
95{
96 if (cbChars)
97 RTLogWriteCom(pachChars, cbChars);
98 return cbChars;
99}
100
101
102/**
103 * Write log buffer to COM port.
104 *
105 * @param pach Pointer to the buffer to write.
106 * @param cb Number of bytes to write.
107 */
108RTDECL(void) RTLogWriteCom(const char *pach, size_t cb)
109{
110 const uint8_t *pu8;
111 for (pu8 = (const uint8_t *)pach; cb-- > 0; pu8++)
112 {
113 /* expand \n -> \r\n */
114 if (*pu8 == '\n')
115 RTLogWriteCom("\r", 1);
116
117 /* Check if port is ready. */
118 register unsigned cMaxWait = ~0;
119 register uint8_t u8;
120 do
121 {
122 u8 = ASMInU8(IPRT_UART_BASE + 5);
123 cMaxWait--;
124 } while (!(u8 & 0x20) && u8 != 0xff && cMaxWait);
125
126 /* write */
127 ASMOutU8(IPRT_UART_BASE, *pu8);
128 }
129}
130
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette