xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/sh3/sh_console.cpp (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /* -*-C++-*-	$NetBSD: sh_console.cpp,v 1.12 2008/04/28 20:23:20 martin Exp $	*/
29173eae7Such 
39173eae7Such /*-
42e968e7eSuch  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
59173eae7Such  * All rights reserved.
69173eae7Such  *
79173eae7Such  * This code is derived from software contributed to The NetBSD Foundation
89173eae7Such  * by UCHIYAMA Yasushi.
99173eae7Such  *
109173eae7Such  * Redistribution and use in source and binary forms, with or without
119173eae7Such  * modification, are permitted provided that the following conditions
129173eae7Such  * are met:
139173eae7Such  * 1. Redistributions of source code must retain the above copyright
149173eae7Such  *    notice, this list of conditions and the following disclaimer.
159173eae7Such  * 2. Redistributions in binary form must reproduce the above copyright
169173eae7Such  *    notice, this list of conditions and the following disclaimer in the
179173eae7Such  *    documentation and/or other materials provided with the distribution.
189173eae7Such  *
199173eae7Such  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
209173eae7Such  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
219173eae7Such  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
229173eae7Such  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
239173eae7Such  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
249173eae7Such  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
259173eae7Such  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269173eae7Such  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279173eae7Such  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
289173eae7Such  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
299173eae7Such  * POSSIBILITY OF SUCH DAMAGE.
309173eae7Such  */
319173eae7Such 
322e79fe1eSuch #include <hpcmenu.h>
339173eae7Such #include <sh3/sh_console.h>
34acb09f98Such #include <sh3/dev/sh.h>
35acb09f98Such #include <sh3/dev/hd64461.h>
36acb09f98Such #include <sh3/dev/hd64465.h>
379173eae7Such 
38acb09f98Such // console switch
39acb09f98Such #include "../../../../hpcsh/include/console.h"
40106c0aeeSuch 
41acb09f98Such const struct SHConsole::console_info
422e79fe1eSuch SHConsole::_console_info[] = {
43ed95b7ebSuch 	{ PLATID_CPU_SH_3        , PLATID_MACH_HP                          , SCIFPrint       , BI_CNUSE_SCIF       , BI_CNUSE_HD64461VIDEO },
44ed95b7ebSuch 	{ PLATID_CPU_SH_3_7709   , PLATID_MACH_HITACHI                     , HD64461COMPrint , BI_CNUSE_HD64461COM , BI_CNUSE_HD64461VIDEO },
45ed95b7ebSuch 	{ PLATID_CPU_SH_3_7709   , PLATID_MACH_CASIO_CASSIOPEIAA_A55V      , 0               , BI_CNUSE_BUILTIN    , BI_CNUSE_BUILTIN },
46acb09f98Such 	{ PLATID_CPU_SH_4_7750   , PLATID_MACH_HITACHI_PERSONA_HPW650PA    , HD64465COMPrint , BI_CNUSE_HD64465COM , BI_CNUSE_BUILTIN },
472e79fe1eSuch 	{ 0, 0, 0 } // terminator.
482e79fe1eSuch };
492e79fe1eSuch 
50acb09f98Such const struct SHConsole::console_info *
selectBootConsole(Console & cons,enum consoleSelect select)51ed95b7ebSuch SHConsole::selectBootConsole(Console &cons, enum consoleSelect select)
52ed95b7ebSuch {
53acb09f98Such 	const struct console_info *tab = _console_info;
54ed95b7ebSuch 	platid_mask_t target, entry;
55ed95b7ebSuch 
56ed95b7ebSuch 	target.dw.dw0 = HPC_PREFERENCE.platid_hi;
57ed95b7ebSuch 	target.dw.dw1 = HPC_PREFERENCE.platid_lo;
58ed95b7ebSuch 
59ed95b7ebSuch 	// search apriori setting if any.
60ed95b7ebSuch 	for (; tab->cpu; tab++) {
61ed95b7ebSuch 		entry.dw.dw0 = tab->cpu;
62ed95b7ebSuch 		entry.dw.dw1 = tab->machine;
63ed95b7ebSuch 		if (platid_match(&target, &entry)) {
64ed95b7ebSuch 			switch (select) {
65ed95b7ebSuch 			case SERIAL:
66ed95b7ebSuch 				cons.setBootConsole(tab->serial_console);
672e968e7eSuch 				return tab;
68ed95b7ebSuch 			case VIDEO:
69ed95b7ebSuch 				cons.setBootConsole(tab->video_console);
702e968e7eSuch 				return tab;
71ed95b7ebSuch 			}
72ed95b7ebSuch 		}
73ed95b7ebSuch 	}
74ed95b7ebSuch 
752e968e7eSuch 	return NULL;
76ed95b7ebSuch }
77ed95b7ebSuch 
SHConsole()782e79fe1eSuch SHConsole::SHConsole()
792e79fe1eSuch {
802e968e7eSuch 
812e79fe1eSuch 	_print = 0;
822e79fe1eSuch }
832e79fe1eSuch 
~SHConsole()842e79fe1eSuch SHConsole::~SHConsole()
852e79fe1eSuch {
86ed95b7ebSuch 	// NO-OP
872e79fe1eSuch }
882e79fe1eSuch 
892e79fe1eSuch BOOL
init()902e79fe1eSuch SHConsole::init()
912e79fe1eSuch {
922e79fe1eSuch 
93bd926f64Such 	if (!super::init())
94bd926f64Such 		return FALSE;
95bd926f64Such 
96acb09f98Such 	const struct console_info *tab = selectBootConsole(*this, SERIAL);
97acb09f98Such 	if (tab != 0) {
98acb09f98Such 		SetKMode(1);	// Native method access P4.
992e79fe1eSuch 		_print = tab->print;
100acb09f98Such 	}
101acb09f98Such 
102acb09f98Such 	// override default instance.
103acb09f98Such 	Console::_instance = this;
1042e79fe1eSuch 
105bd926f64Such 	return TRUE;
1062e79fe1eSuch }
1072e79fe1eSuch 
1089173eae7Such void
print(const TCHAR * fmt,...)1099173eae7Such SHConsole::print(const TCHAR *fmt, ...)
1109173eae7Such {
1112e968e7eSuch 
112bd926f64Such 	SETUP_WIDECHAR_BUFFER();
1139173eae7Such 
114bd926f64Such 	if (!setupMultibyteBuffer())
1159173eae7Such 		return;
1169173eae7Such 
1174e6c980fSuch 	if (_print == 0)
118bd926f64Such 		super::genericPrint(_bufm);
1194e6c980fSuch 	else
1202e79fe1eSuch 		_print(_bufm);
1219173eae7Such }
1222e79fe1eSuch 
1232e79fe1eSuch void
SCIPrint(const char * buf)1244e6c980fSuch SHConsole::SCIPrint(const char *buf)
1254e6c980fSuch {
1262e968e7eSuch 
127acb09f98Such 	SH3_SCI_PRINT(buf);
1284e6c980fSuch }
1294e6c980fSuch 
1304e6c980fSuch void
SCIFPrint(const char * buf)1312e79fe1eSuch SHConsole::SCIFPrint(const char *buf)
1322e79fe1eSuch {
1332e968e7eSuch 
134acb09f98Such 	SH3_SCIF_PRINT(buf);
1352e79fe1eSuch }
1362e79fe1eSuch 
1374e6c980fSuch void
HD64461COMPrint(const char * buf)1384e6c980fSuch SHConsole::HD64461COMPrint(const char *buf)
1394e6c980fSuch {
1402e968e7eSuch 
1414e6c980fSuch 	HD64461COM_PRINT(buf);
1424e6c980fSuch }
1432e968e7eSuch 
1442e968e7eSuch void
HD64465COMPrint(const char * buf)1452e968e7eSuch SHConsole::HD64465COMPrint(const char *buf)
1462e968e7eSuch {
1472e968e7eSuch 
1482e968e7eSuch 	HD64465COM_PRINT(buf);
1492e968e7eSuch }
150