VirtualBox

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

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1/* $Id: logcom.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - Logging to Serial Port.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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/*******************************************************************************
29* Defined Constants And Macros *
30*******************************************************************************/
31#ifndef IPRT_UART_BASE
32/** The port address of the COM port to log to.
33 *
34 * To override the default (COM1) append IPRT_UART_BASE=0xWXYZ to DEFS in your
35 * LocalConfig.kmk. Alternatively you can edit this file, but the don't forget
36 * to also update the default found in VBox/asmdefs.h.
37 *
38 * Standard port assignments are: COM1=0x3f8, COM2=0x2f8, COM3=0x3e8, COM4=0x2e8.
39 */
40# define IPRT_UART_BASE 0x3f8
41#endif
42
43
44/*******************************************************************************
45* Header Files *
46*******************************************************************************/
47#include <iprt/log.h>
48#include "internal/iprt.h"
49
50#include <iprt/asm.h>
51#include <iprt/stdarg.h>
52#include <iprt/string.h>
53
54
55/*******************************************************************************
56* Internal Functions *
57*******************************************************************************/
58static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars);
59
60
61/**
62 * Prints a formatted string to the serial port used for logging.
63 *
64 * @returns Number of bytes written.
65 * @param pszFormat Format string.
66 * @param ... Optional arguments specified in the format string.
67 */
68RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...)
69{
70 va_list args;
71 size_t cb;
72 va_start(args, pszFormat);
73 cb = RTLogComPrintfV(pszFormat, args);
74 va_end(args);
75
76 return cb;
77}
78RT_EXPORT_SYMBOL(RTLogComPrintf);
79
80
81/**
82 * Prints a formatted string to the serial port used for logging.
83 *
84 * @returns Number of bytes written.
85 * @param pszFormat Format string.
86 * @param args Optional arguments specified in the format string.
87 */
88RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args)
89{
90 return RTLogFormatV(rtLogComOutput, NULL, pszFormat, args);
91}
92RT_EXPORT_SYMBOL(RTLogComPrintfV);
93
94
95/**
96 * Callback for RTLogFormatV which writes to the com port.
97 * See PFNLOGOUTPUT() for details.
98 */
99static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars)
100{
101 if (cbChars)
102 RTLogWriteCom(pachChars, cbChars);
103 return cbChars;
104}
105
106
107/**
108 * Write log buffer to COM port.
109 *
110 * @param pach Pointer to the buffer to write.
111 * @param cb Number of bytes to write.
112 */
113RTDECL(void) RTLogWriteCom(const char *pach, size_t cb)
114{
115 const uint8_t *pu8;
116 for (pu8 = (const uint8_t *)pach; cb-- > 0; pu8++)
117 {
118 register unsigned cMaxWait;
119 register uint8_t u8;
120
121 /* expand \n -> \r\n */
122 if (*pu8 == '\n')
123 RTLogWriteCom("\r", 1);
124
125 /* Check if port is ready. */
126 cMaxWait = ~0;
127 do
128 {
129 u8 = ASMInU8(IPRT_UART_BASE + 5);
130 cMaxWait--;
131 } while (!(u8 & 0x20) && u8 != 0xff && cMaxWait);
132
133 /* write */
134 ASMOutU8(IPRT_UART_BASE, *pu8);
135 }
136}
137RT_EXPORT_SYMBOL(RTLogWriteCom);
138
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