VirtualBox

source: vbox/trunk/src/VBox/Runtime/logcom.cpp@ 4968

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

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1/* $Id: logcom.cpp 4071 2007-08-07 17:07:59Z 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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*******************************************************************************
19* Defined Constants And Macros *
20*******************************************************************************/
21/** Comport to log to (COM2).
22 * This is also defined in VBox/nasm.mac. */
23//#define UART_BASE 0x2f8 /* COM2 */
24#define UART_BASE 0x3f8 /* COM1 */
25
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/log.h>
31#include <iprt/asm.h>
32#include <iprt/stdarg.h>
33#include <iprt/string.h>
34
35
36/*******************************************************************************
37* Internal Functions *
38*******************************************************************************/
39static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars);
40
41
42/**
43 * Prints a formatted string to the serial port used for logging.
44 *
45 * @returns Number of bytes written.
46 * @param pszFormat Format string.
47 * @param ... Optional arguments specified in the format string.
48 */
49RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...)
50{
51 va_list args;
52 size_t cb;
53 va_start(args, pszFormat);
54 cb = RTLogComPrintfV(pszFormat, args);
55 va_end(args);
56
57 return cb;
58}
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 args Optional arguments specified in the format string.
67 */
68RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args)
69{
70 return RTLogFormatV(rtLogComOutput, NULL, pszFormat, args);
71}
72
73
74/**
75 * Callback for RTLogFormatV which writes to the com port.
76 * See PFNLOGOUTPUT() for details.
77 */
78static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars)
79{
80 if (cbChars)
81 RTLogWriteCom(pachChars, cbChars);
82 return cbChars;
83}
84
85
86/**
87 * Write log buffer to COM port.
88 *
89 * @param pach Pointer to the buffer to write.
90 * @param cb Number of bytes to write.
91 */
92RTDECL(void) RTLogWriteCom(const char *pach, size_t cb)
93{
94 for (const uint8_t *pu8 = (const uint8_t *)pach; cb-- > 0; pu8++)
95 {
96 /* expand \n -> \r\n */
97 if (*pu8 == '\n')
98 RTLogWriteCom("\r", 1);
99
100 /* Check if port is ready. */
101 register unsigned cMaxWait = ~0;
102 register uint8_t u8;
103 do
104 {
105 u8 = ASMInU8(UART_BASE + 5);
106 cMaxWait--;
107 } while (!(u8 & 0x20) && u8 != 0xff && cMaxWait);
108
109 /* write */
110 ASMOutU8(UART_BASE, *pu8);
111 }
112}
113
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