always open COM1 for the sake of KGDB.
This commit is contained in:
parent
ddf9130f5c
commit
2a2cc9f493
@ -1,7 +1,7 @@
|
||||
/* -*-C++-*- $NetBSD: console.cpp,v 1.7 2001/06/19 16:48:49 uch Exp $ */
|
||||
/* -*-C++-*- $NetBSD: console.cpp,v 1.8 2002/03/02 22:01:34 uch Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
@ -47,9 +47,12 @@ Console *Console::_instance = 0;
|
||||
Console *
|
||||
Console::Instance()
|
||||
{
|
||||
if (_instance == 0)
|
||||
|
||||
if (_instance == 0) {
|
||||
_instance = new Console;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
return (_instance);
|
||||
}
|
||||
|
||||
Console::Console()
|
||||
@ -61,6 +64,7 @@ Console::Console()
|
||||
void
|
||||
Console::Destroy()
|
||||
{
|
||||
|
||||
if (_instance)
|
||||
delete _instance;
|
||||
_instance = 0;
|
||||
@ -70,6 +74,7 @@ void
|
||||
Console::print(const TCHAR *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
wvsprintf(_bufw, fmt, ap);
|
||||
va_end(ap);
|
||||
@ -83,6 +88,7 @@ Console::print(const TCHAR *fmt, ...)
|
||||
//
|
||||
SerialConsole::SerialConsole()
|
||||
{
|
||||
|
||||
_handle = INVALID_HANDLE_VALUE;
|
||||
// set default serial console.
|
||||
setBootConsole(BI_CNUSE_SERIAL);
|
||||
@ -93,7 +99,22 @@ SerialConsole::init()
|
||||
{
|
||||
// always open COM1 to supply clock and power for the
|
||||
// sake of kernel serial driver
|
||||
return openCOM1();
|
||||
if (_handle == INVALID_HANDLE_VALUE)
|
||||
_handle = OpenCOM1();
|
||||
|
||||
if (_handle == INVALID_HANDLE_VALUE) {
|
||||
Console::print(TEXT("couldn't open COM1\n"));
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
// Print serial console status on LCD.
|
||||
DCB dcb;
|
||||
GetCommState(_handle, &dcb);
|
||||
Console::print(
|
||||
TEXT("BaudRate %d, ByteSize %#x, Parity %#x, StopBits %#x\n"),
|
||||
dcb.BaudRate, dcb.ByteSize, dcb.Parity, dcb.StopBits);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
BOOL
|
||||
@ -101,6 +122,7 @@ SerialConsole::setupMultibyteBuffer()
|
||||
{
|
||||
size_t len = WideCharToMultiByte(CP_ACP, 0, _bufw, wcslen(_bufw),
|
||||
0, 0, 0, 0);
|
||||
|
||||
if (len + 1 > CONSOLE_BUFSIZE)
|
||||
return FALSE;
|
||||
if (!WideCharToMultiByte(CP_ACP, 0, _bufw, len, _bufm, len, 0, 0))
|
||||
@ -113,6 +135,7 @@ SerialConsole::setupMultibyteBuffer()
|
||||
void
|
||||
SerialConsole::print(const TCHAR *fmt, ...)
|
||||
{
|
||||
|
||||
SETUP_WIDECHAR_BUFFER();
|
||||
|
||||
if (!setupMultibyteBuffer())
|
||||
@ -121,45 +144,41 @@ SerialConsole::print(const TCHAR *fmt, ...)
|
||||
genericPrint(_bufm);
|
||||
}
|
||||
|
||||
BOOL
|
||||
SerialConsole::openCOM1()
|
||||
HANDLE
|
||||
SerialConsole::OpenCOM1()
|
||||
{
|
||||
static HANDLE COM1handle = INVALID_HANDLE_VALUE;
|
||||
const char msg[] = "\r\n--------HPCBOOT--------\r\n";
|
||||
unsigned long wrote;
|
||||
int speed = HPC_PREFERENCE.serial_speed;
|
||||
HANDLE h;
|
||||
|
||||
if (_handle == INVALID_HANDLE_VALUE) {
|
||||
_handle = CreateFile(TEXT("COM1:"),
|
||||
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
|
||||
NULL);
|
||||
if (_handle == INVALID_HANDLE_VALUE) {
|
||||
Console::print(TEXT("couldn't open COM1\n"));
|
||||
return FALSE;
|
||||
}
|
||||
if (COM1handle != INVALID_HANDLE_VALUE)
|
||||
return (COM1handle);
|
||||
|
||||
DCB dcb;
|
||||
if (!GetCommState(_handle, &dcb)) {
|
||||
Console::print(TEXT("couldn't get COM port status.\n"));
|
||||
goto bad;
|
||||
}
|
||||
h = CreateFile(TEXT("COM1:"),
|
||||
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
|
||||
NULL);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
return (h);
|
||||
|
||||
DCB dcb;
|
||||
if (!GetCommState(h, &dcb))
|
||||
goto bad;
|
||||
|
||||
dcb.BaudRate = speed;
|
||||
if (!SetCommState(_handle, &dcb)) {
|
||||
Console::print(TEXT("couldn't set baud rate to %s.\n"),
|
||||
speed);
|
||||
goto bad;
|
||||
}
|
||||
dcb.BaudRate = speed;
|
||||
if (!SetCommState(h, &dcb))
|
||||
goto bad;
|
||||
|
||||
Console::print(TEXT("BaudRate %d, ByteSize %#x, Parity %#x, StopBits %#x\n"),
|
||||
dcb.BaudRate, dcb.ByteSize, dcb.Parity, dcb.StopBits);
|
||||
const char msg[] = "--------HPCBOOT--------\r\n";
|
||||
unsigned long wrote;
|
||||
WriteFile(_handle, msg, sizeof msg, &wrote, 0);
|
||||
}
|
||||
// Print banner on serial console.
|
||||
WriteFile(h, msg, sizeof msg, &wrote, 0);
|
||||
|
||||
return TRUE;
|
||||
COM1handle = h;
|
||||
|
||||
return (h);
|
||||
bad:
|
||||
CloseHandle(_handle);
|
||||
_handle = INVALID_HANDLE_VALUE;
|
||||
return FALSE;
|
||||
CloseHandle(h);
|
||||
return (INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* -*-C++-*- $NetBSD: console.h,v 1.7 2002/02/11 17:08:54 uch Exp $ */
|
||||
/* -*-C++-*- $NetBSD: console.h,v 1.8 2002/03/02 22:01:35 uch Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
@ -78,13 +78,14 @@ protected:
|
||||
protected:
|
||||
SerialConsole(void);
|
||||
~SerialConsole(void) { /* NO-OP */ };
|
||||
BOOL openCOM1(void);
|
||||
BOOL setupMultibyteBuffer(void);
|
||||
|
||||
public:
|
||||
void genericPrint(const char *);
|
||||
virtual BOOL init(void);
|
||||
virtual void print(const TCHAR *fmt, ...);
|
||||
|
||||
static HANDLE OpenCOM1(void);
|
||||
};
|
||||
|
||||
#define SETUP_WIDECHAR_BUFFER() \
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: hpcboot.cpp,v 1.6 2002/02/11 17:05:45 uch Exp $ */
|
||||
/* $NetBSD: hpcboot.cpp,v 1.7 2002/03/02 22:01:35 uch Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
|
||||
@ -50,6 +50,8 @@
|
||||
|
||||
#include <boot.h>
|
||||
|
||||
OSVERSIONINFOW WinCEVersion;
|
||||
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE instance, HINSTANCE prev_instance,
|
||||
LPTSTR cmd_line, int window_show)
|
||||
@ -100,6 +102,9 @@ hpcboot(void *arg)
|
||||
HpcMenuInterface &menu = HPC_MENU;
|
||||
Boot &f = Boot::Instance();
|
||||
|
||||
// Open serial port for kernel KGDB.
|
||||
SerialConsole::OpenCOM1();
|
||||
|
||||
menu.progress();
|
||||
if (!f.setup()) {
|
||||
error_message = TEXT("architecture not supported.\n");
|
||||
@ -143,17 +148,17 @@ hpcboot(void *arg)
|
||||
menu.progress();
|
||||
if (!f._file->open(f.args.fileName)) {
|
||||
error_message = TEXT("couldn't open kernel image.\n");
|
||||
goto failed;
|
||||
goto failed_exit;
|
||||
}
|
||||
|
||||
|
||||
menu.progress();
|
||||
// put kernel to loader.
|
||||
if (!f.attachLoader())
|
||||
goto failed;
|
||||
|
||||
goto file_close_exit;
|
||||
|
||||
if (!f._loader->setFile(f._file)) {
|
||||
error_message = TEXT("couldn't initialize loader.\n");
|
||||
goto failed;
|
||||
goto file_close_exit;
|
||||
}
|
||||
|
||||
menu.progress();
|
||||
@ -162,31 +167,35 @@ hpcboot(void *arg)
|
||||
// allocate required memory.
|
||||
if (!f._arch->allocateMemory(sz)) {
|
||||
error_message = TEXT("couldn't allocate memory.\n");
|
||||
goto failed;
|
||||
goto file_close_exit;
|
||||
}
|
||||
|
||||
menu.progress();
|
||||
// load kernel to memory.
|
||||
if (!f._arch->setupLoader()) {
|
||||
error_message = TEXT("couldn't set up loader.\n");
|
||||
goto failed;
|
||||
goto file_close_exit;
|
||||
}
|
||||
|
||||
menu.progress();
|
||||
if (!f._loader->load()) {
|
||||
error_message = TEXT("couldn't load kernel image to memory.\n");
|
||||
goto failed;
|
||||
goto file_close_exit;
|
||||
}
|
||||
menu.progress();
|
||||
f._file->close();
|
||||
|
||||
// load file system image to memory
|
||||
if (f.args.loadmfs) {
|
||||
f._file->open(f.args.mfsName);
|
||||
if (!f._file->open(f.args.mfsName)) {
|
||||
error_message =
|
||||
TEXT("couldn't open file system image.\n");
|
||||
goto failed_exit;
|
||||
}
|
||||
if (!f._loader->loadExtData()) {
|
||||
error_message =
|
||||
TEXT("couldn't load filesystem image to memory.\n");
|
||||
goto failed;
|
||||
goto file_close_exit;
|
||||
}
|
||||
f._file->close();
|
||||
}
|
||||
@ -203,13 +212,13 @@ hpcboot(void *arg)
|
||||
if (HPC_PREFERENCE.pause_before_boot) {
|
||||
if (MessageBox(menu._root->_window, TEXT("Push OK to boot."),
|
||||
TEXT("Last chance..."), MB_YESNO) != IDYES)
|
||||
goto failed;
|
||||
goto failed_exit;
|
||||
}
|
||||
|
||||
f._arch->jump(p, f._loader->tagStart());
|
||||
// NOTREACHED
|
||||
|
||||
failed:
|
||||
file_close_exit:
|
||||
if (error_message == 0)
|
||||
error_message = TEXT("can't jump to kernel.\n");
|
||||
f._file->close();
|
||||
@ -225,7 +234,7 @@ int
|
||||
HpcBootApp::run(void)
|
||||
{
|
||||
MSG msg;
|
||||
|
||||
|
||||
while (GetMessage(&msg, 0, 0, 0)) {
|
||||
// cancel auto-boot.
|
||||
if (HPC_PREFERENCE.auto_boot > 0 && _root &&
|
||||
|
Loading…
Reference in New Issue
Block a user