VirtualBox

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

最後變更 在這個檔案從5999是 5999,由 vboxsync 提交於 17 年 前

The Giant CDDL Dual-License Header Change.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 3.8 KB
 
1/* $Id: logcom.cpp 5999 2007-12-07 15:05:06Z 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.alldomusa.eu.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/** Comport to log to (COM2).
31 * This is also defined in VBox/nasm.mac. */
32//#define UART_BASE 0x2f8 /* COM2 */
33#define UART_BASE 0x3f8 /* COM1 */
34
35
36/*******************************************************************************
37* Header Files *
38*******************************************************************************/
39#include <iprt/log.h>
40#include <iprt/asm.h>
41#include <iprt/stdarg.h>
42#include <iprt/string.h>
43
44
45/*******************************************************************************
46* Internal Functions *
47*******************************************************************************/
48static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars);
49
50
51/**
52 * Prints a formatted string to the serial port used for logging.
53 *
54 * @returns Number of bytes written.
55 * @param pszFormat Format string.
56 * @param ... Optional arguments specified in the format string.
57 */
58RTDECL(size_t) RTLogComPrintf(const char *pszFormat, ...)
59{
60 va_list args;
61 size_t cb;
62 va_start(args, pszFormat);
63 cb = RTLogComPrintfV(pszFormat, args);
64 va_end(args);
65
66 return cb;
67}
68
69
70/**
71 * Prints a formatted string to the serial port used for logging.
72 *
73 * @returns Number of bytes written.
74 * @param pszFormat Format string.
75 * @param args Optional arguments specified in the format string.
76 */
77RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args)
78{
79 return RTLogFormatV(rtLogComOutput, NULL, pszFormat, args);
80}
81
82
83/**
84 * Callback for RTLogFormatV which writes to the com port.
85 * See PFNLOGOUTPUT() for details.
86 */
87static DECLCALLBACK(size_t) rtLogComOutput(void *pv, const char *pachChars, size_t cbChars)
88{
89 if (cbChars)
90 RTLogWriteCom(pachChars, cbChars);
91 return cbChars;
92}
93
94
95/**
96 * Write log buffer to COM port.
97 *
98 * @param pach Pointer to the buffer to write.
99 * @param cb Number of bytes to write.
100 */
101RTDECL(void) RTLogWriteCom(const char *pach, size_t cb)
102{
103 for (const uint8_t *pu8 = (const uint8_t *)pach; cb-- > 0; pu8++)
104 {
105 /* expand \n -> \r\n */
106 if (*pu8 == '\n')
107 RTLogWriteCom("\r", 1);
108
109 /* Check if port is ready. */
110 register unsigned cMaxWait = ~0;
111 register uint8_t u8;
112 do
113 {
114 u8 = ASMInU8(UART_BASE + 5);
115 cMaxWait--;
116 } while (!(u8 & 0x20) && u8 != 0xff && cMaxWait);
117
118 /* write */
119 ASMOutU8(UART_BASE, *pu8);
120 }
121}
122
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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