1 /* -*-C++-*- $NetBSD: console.cpp,v 1.10 2005/12/11 12:17:28 christos Exp $ */
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 Console
*Console::_instance
= 0;
45 _instance
= new Console
;
53 // set default builtin console. (bicons)
54 setBootConsole(BI_CNUSE_BUILTIN
);
67 Console::print(const TCHAR
*fmt
, ...)
72 wvsprintf(_bufw
, fmt
, ap
);
75 // print to `Console Tab Window'
76 HPC_MENU
.print(_bufw
);
82 SerialConsole::SerialConsole()
85 _handle
= INVALID_HANDLE_VALUE
;
86 // set default serial console.
87 setBootConsole(BI_CNUSE_SERIAL
);
93 // always open COM1 to supply clock and power for the
94 // sake of kernel serial driver
95 if (_handle
== INVALID_HANDLE_VALUE
)
98 if (_handle
== INVALID_HANDLE_VALUE
) {
99 Console::print(TEXT("couldn't open COM1\n"));
103 // Print serial console status on LCD.
105 GetCommState(_handle
, &dcb
);
107 TEXT("BaudRate %d, ByteSize %#x, Parity %#x, StopBits %#x\n"),
108 dcb
.BaudRate
, dcb
.ByteSize
, dcb
.Parity
, dcb
.StopBits
);
114 SerialConsole::setupMultibyteBuffer()
116 size_t len
= WideCharToMultiByte(CP_ACP
, 0, _bufw
, wcslen(_bufw
),
119 if (len
+ 1 > CONSOLE_BUFSIZE
)
121 if (!WideCharToMultiByte(CP_ACP
, 0, _bufw
, len
, _bufm
, len
, 0, 0))
129 SerialConsole::print(const TCHAR
*fmt
, ...)
132 SETUP_WIDECHAR_BUFFER();
134 if (!setupMultibyteBuffer())
141 SerialConsole::OpenCOM1()
143 static HANDLE COM1handle
= INVALID_HANDLE_VALUE
;
144 const char msg
[] = "\r\n--------HPCBOOT--------\r\n";
146 int speed
= HPC_PREFERENCE
.serial_speed
;
149 if (COM1handle
!= INVALID_HANDLE_VALUE
)
152 h
= CreateFile(TEXT("COM1:"),
153 GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0,
155 if (h
== INVALID_HANDLE_VALUE
)
159 if (!GetCommState(h
, &dcb
))
162 dcb
.BaudRate
= speed
;
163 if (!SetCommState(h
, &dcb
))
166 // Print banner on serial console.
167 WriteFile(h
, msg
, sizeof msg
, &wrote
, 0);
174 return (INVALID_HANDLE_VALUE
);
178 SerialConsole::genericPrint(const char *buf
)
183 for (i
= 0; *buf
!= '\0'; buf
++) {
186 WriteFile(_handle
, "\r", 1, &wrote
, 0);
187 WriteFile(_handle
, &c
, 1, &wrote
, 0);