Subject: Re: 2.1 Kernels do not boot whenbootedwithbootloaderotherthannetbsd
To: None <port-cobalt@NetBSD.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-cobalt
Date: 11/23/2005 16:24:53
In article <43841337.2090302@broadcom.com>
alexp@broadcom.com wrote:

> > I'll try to build INSTALL-like kernel on 2.x and check how it goes
> > on my RaQ2. If it works, I'll send a pullup request for netbsd-2 branch.
> Thanks for that.

Okay, it looks there is a problem around console initialization.
(consinit() called more than once?)
Please try the attached patch (for netbsd-2) or this kernel:
http://www.ceres.dti.ne.jp/~tsutsui/netbsd/netbsd-cobalt-INSTALL-2.1_STABLE.gz

> > I see, maybe the way to go is to add kloader(4) support to
> > cobalt kernels. It should be trivial though I have no idea
> > how much work is needed for now.
> 
> I will look in to that, I am curious about that too.

Maybe src/sys/arch/hpcmips/hpcmips/kloader* files would be a good start.

> I did use complete 2.1 userland that I downloaded from netbsd torrent. I 
> downloaded iso image and used that to install 2.1
> The config crashes like this - when I try to run it with or without 
> parameters it dumps core with following message:
> Bus error (core dumped)

Hmm, does it always crash with the same error?
What is the kernel version (uname -a)?
What do ktrace(1)/kdump(1) say on the command?
---
Izumi Tsutsui


--- sys/arch/cobalt/cobalt/console.c.orig	2004-01-07 21:43:43.000000000 +0900
+++ sys/arch/cobalt/cobalt/console.c	2005-11-23 15:16:47.000000000 +0900
@@ -29,15 +29,9 @@
 __KERNEL_RCSID(0, "$NetBSD: console.c,v 1.7 2004/01/07 12:43:43 cdi Exp $");
 
 #include <sys/param.h>
-#include <sys/user.h>
-#include <sys/uio.h>
 #include <sys/systm.h>
-#include <sys/kernel.h>
 #include <sys/device.h>
 #include <sys/conf.h>
-#include <sys/proc.h>
-#include <sys/tty.h>
-#include <sys/termios.h>
 
 #include <machine/bus.h>
 #include <machine/nvram.h>
@@ -45,71 +39,33 @@
 
 #include <dev/cons.h>
 
-#include <dev/ic/comreg.h>
-#include <dev/ic/comvar.h>
+#include <cobalt/dev/com_mainbusvar.h>
 
-#include "com.h"
+#include "com_mainbus.h"
 #include "nullcons.h"
 
-dev_type_cnprobe(comcnprobe);
-dev_type_cninit(comcninit);
-
 int	console_present = 0;	/* Do we have a console? */
 
 struct	consdev	constab[] = {
-#if NCOM > 0
-	{ comcnprobe, comcninit, },
+#if NCOM_MAINBUS > 0
+	{ com_mainbus_cnprobe, com_mainbus_cninit,
+	    NULL, NULL, NULL, NULL, NULL, NULL, 0, CN_DEAD },
 #endif
 #if NNULLCONS > 0
-	{ nullcnprobe, nullcninit },
+	{ nullcnprobe, nullcninit,
+	    NULL, NULL, NULL, NULL, NULL, NULL, 0, CN_DEAD },
 #endif
-	{ 0 }
+	{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, CN_DEAD }
 };
 
-#if NCOM > 0
-#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
-
-void
-comcnprobe(cn)
-	struct consdev *cn;
-{
-	struct btinfo_flags *bi_flags;
-
-	/*
-	 * Linux code has a comment that serial console must be probed
-	 * early, otherwise the value which allows to detect serial port
-	 * could be overwritten. Okay, probe here and record the result
-	 * for the future use.
-	 *
-	 * Note that if the kernel was booted with a boot loader,
-	 * the latter *has* to provide a flag indicating whether console
-	 * is present or not due to the reasons outlined above.
-	 */
-	if ( (bi_flags = lookup_bootinfo(BTINFO_FLAGS)) == NULL) {
-		/* No boot information, probe console now */
-		console_present = *(volatile u_int32_t *)
-					MIPS_PHYS_TO_KSEG1(0x0020001c);
-	} else {
-		/* Get the value determined by the boot loader. */
-		console_present = bi_flags->bi_flags & BI_SERIAL_CONSOLE;
-	}
-
-	cn->cn_pri = (console_present != 0) ? CN_NORMAL : CN_DEAD;
-}
-
-void
-comcninit(cn)
-	struct consdev *cn;
-{
-
-	comcnattach(0, 0x1c800000, 115200, COM_FREQ * 10, COM_TYPE_NORMAL,
-	    CONMODE);
-}
-#endif
-
 void
 consinit()
 {
+	static int initted;
+
+	if (initted)
+		return;
+	initted = 1;
 
 	cninit();
 }
--- sys/arch/cobalt/conf/files.cobalt.orig	2003-10-18 03:20:10.000000000 +0900
+++ sys/arch/cobalt/conf/files.cobalt	2005-11-23 15:16:43.000000000 +0900
@@ -13,7 +13,7 @@
 file arch/cobalt/cobalt/cpu.c		cpu
 
 attach com at mainbus with com_mainbus
-file arch/cobalt/dev/com_mainbus.c	com_mainbus
+file arch/cobalt/dev/com_mainbus.c	com_mainbus	needs-flag
 
 device panel: hd44780
 attach panel at mainbus
--- /dev/null	2005-11-23 15:04:16.000000000 +0900
+++ sys/arch/cobalt/conf/INSTALL	2005-11-23 14:56:35.000000000 +0900
@@ -0,0 +1,320 @@
+# $NetBSD$
+#
+# INSTALL -- installation and rescue kernel.
+#
+# This kernel should be derived from GENERIC with most features
+# commented out to shoehorn into Cobalt kernel size limitations.
+# 
+
+include 	"arch/cobalt/conf/std.cobalt"
+
+options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
+
+#ident 		"INSTALL-$Revision$"
+
+makeoptions	COPTS="-Os -mmemcpy"
+
+maxusers	32
+
+# Standard system options
+options 	KTRACE		# system call tracing support
+options 	SYSTRACE	# system call vetting via systrace(1)
+options 	SYSVMSG		# System V message queues
+options 	SYSVSEM		# System V semaphores
+#options 	SEMMNI=10	# number of semaphore identifiers
+#options 	SEMMNS=60	# number of semaphores in system
+#options 	SEMUME=10	# max number of undo entries per process
+#options 	SEMMNU=30	# number of undo structures in system
+options 	SYSVSHM		# System V shared memory
+#options 	SHMMAXPGS=1024	# 1024 pages is the default
+options 	P1003_1B_SEMAPHORE # p1003.1b semaphore support
+#options 	LKM		# loadable kernel modules
+#options 	NTP		# network time protocol
+options 	USERCONF	# userconf(4) support
+#options	PIPE_SOCKETPAIR	# smaller, but slower pipe(2)
+#options 	SYSCTL_INCLUDE_DESCR	# Include sysctl descriptions in kernel
+
+# Enable experimental buffer queue strategy for better responsiveness under 
+# high disk I/O load. Use it with caution - it's not proven to be stable yet.
+#options 	NEW_BUFQ_STRATEGY
+
+# Debugging options
+#options 	DIAGNOSTIC	# extra kernel sanity checking
+#options 	DEBUG		# extra kernel debugging support
+#options 	KMEMSTATS	# kernel memory statistics (vmstat -m)
+options 	DDB		# kernel dynamic debugger
+#options 	DDB_HISTORY_SIZE=100 # enable history editing in DDB
+#makeoptions	DEBUG="-g"	# compile full symbol table
+
+# Compatibility options
+options 	COMPAT_43	# compatibility with 4.3BSD binaries
+#options 	COMPAT_09	# NetBSD 0.9 binary compatibility
+#options 	COMPAT_10	# NetBSD 1.0 binary compatibility
+#options 	COMPAT_11	# NetBSD 1.1 binary compatibility
+#options 	COMPAT_12	# NetBSD 1.2 binary compatibility
+#options 	COMPAT_13	# NetBSD 1.3 binary compatibility
+#options 	COMPAT_14	# NetBSD 1.4 binary compatibility
+options 	COMPAT_16	# NetBSD 1.6 binary compatibility
+#options 	EXEC_ECOFF	# exec ECOFF binaries
+#options 	COMPAT_ULTRIX	# binary compatibility with Ultrix
+#options 	TCP_COMPAT_42	# 4.2BSD TCP/IP bug compat. Not recommended.
+
+# File systems
+file-system	FFS		# Berkeley Fast Filesystem
+file-system 	EXT2FS		# second extended file system (linux)
+file-system	NFS		# Sun NFS-compatible filesystem client
+#file-system	KERNFS		# kernel data-structure filesystem
+#file-system	NULLFS		# NULL layered filesystem
+#file-system 	OVERLAY		# overlay file system
+file-system	MFS		# memory-based filesystem
+file-system	FDESC		# user file descriptor filesystem
+#file-system	UMAPFS		# uid/gid remapping filesystem
+#file-system	LFS		# Log-based filesystem (still experimental)
+#file-system	PORTAL		# portal filesystem (still experimental)
+#file-system	PROCFS		# /proc
+#file-system	CD9660		# ISO 9660 + Rock Ridge file system
+#file-system	UNION		# union file system
+#file-system	MSDOSFS		# MS-DOS FAT filesystem(s).
+#file-system 	CODA		# Coda File System; also needs vcoda (below)
+
+# File system options
+#options 	NFSSERVER	# Sun NFS-compatible filesystem server
+#options 	QUOTA		# FFS quotas
+#options 	FFS_EI		# FFS Endian Independant support
+#options 	SOFTDEP		# FFS soft updates support.
+#options 	EXT2FS_SYSTEM_FLAGS # makes ext2fs file flags (append and
+				# immutable) behave as system flags.
+
+# Networking options
+#options 	GATEWAY		# IP packet forwarding
+options 	INET		# Internet protocols
+#options 	INET6		# IPV6
+#options 	IPSEC		# IP security
+#options 	IPSEC_ESP	# IP security (encryption part; define w/IPSEC)
+#options 	IPSEC_DEBUG	# debug for IP security
+#options 	MROUTING	# packet forwarding of multicast packets
+#options 	NS		# Xerox NS networking
+#options 	NSIP		# Xerox NS tunneling over IP
+#options 	ISO,TPIP	# OSI networking
+#options 	EON		# OSI tunneling over IP
+#options 	CCITT,LLC,HDLC	# X.25
+#options 	NETATALK	# AppleTalk (over Ethernet) protocol
+#options 	PPP_BSDCOMP	# BSD-Compress compression support for PPP
+#options 	PPP_DEFLATE	# Deflate compression support for PPP
+#options 	PPP_FILTER	# Active filter support for PPP (requires bpf)
+#options 	PFIL_HOOKS	# pfil(9) packet filter hooks
+#options 	IPFILTER_LOG	# ipmon(8) log support
+#options 	IPFILTER_DEFAULT_BLOCK	# block all packets by default
+#options 	TCP_DEBUG	# Record last TCP_NDEBUG packets with SO_DEBUG
+
+#options 	ALTQ		# Manipulate network interfaces' output queues
+#options 	ALTQ_BLUE	# Stochastic Fair Blue
+#options 	ALTQ_CBQ	# Class-Based Queueing
+#options 	ALTQ_CDNR	# Diffserv Traffic Conditioner
+#options 	ALTQ_FIFOQ	# First-In First-Out Queue
+#options 	ALTQ_FLOWVALVE	# RED/flow-valve (red-penalty-box)
+#options 	ALTQ_HFSC	# Hierarchical Fair Service Curve
+#options 	ALTQ_LOCALQ	# Local queueing discipline
+#options 	ALTQ_PRIQ	# Priority Queueing
+#options 	ALTQ_RED	# Random Early Detection
+#options 	ALTQ_RIO	# RED with IN/OUT
+#options 	ALTQ_WFQ	# Weighted Fair Queueing
+
+# These options enable verbose messages for several subsystems.
+# Warning, these may compile large string tables into the kernel!
+#options 	PCIVERBOSE	# verbose PCI device autoconfig messages
+#options 	PCI_CONFIG_DUMP	# verbosely dump PCI config space
+#options 	SCSIVERBOSE	# human readable SCSI error messages
+#options 	MIIVERBOSE	# verbose PHY autoconfig messages
+
+options 	NFS_BOOT_DHCP
+
+config		netbsd	root on ? type ?
+
+mainbus0 	at root
+
+cpu0 		at mainbus?
+
+com0		at mainbus? addr 0x1c800000 level 3
+options 	COM16650
+
+panel0 		at mainbus? addr 0x1f000000
+
+gt0 		at mainbus? addr 0x14000000
+
+pci* 		at gt0
+pchb* 		at pci? dev ? function ?
+pcib* 		at pci? dev ? function ?
+
+# Cryptographic Devices
+
+# PCI cryptographic devices
+#hifn*	at pci? dev ? function ?	# Hifn 7755/7811/795x
+#ubsec*	at pci? dev ? function ?	# Broadcom 5501/5601/580x/582x
+
+# PCI serial/parallel interfaces
+#puc* 		at pci? dev ? function ? 	# PCI "universal" comm. cards
+#com* 		at puc? port ?
+#lpt* 		at puc? port ?
+#cy* 		at pci? dev ? function ?	# Cyclades Cyclom-Y serial cards
+
+# PCI SCSI controllers
+#adv*		at pci? dev ? function ?	# AdvanSys 1200[A,B], 9xx[U,UA]
+#adw*		at pci? dev ? function ?	# AdvanSys 9xxUW SCSI
+#ahc*		at pci? dev ? function ?	# Adaptec [23]94x, aic78x0 SCSI
+#bha*		at pci? dev ? function ?	# BusLogic 9xx SCSI
+#dpt*		at pci? dev ? function ?	# DPT SmartCache/SmartRAID
+#isp*		at pci? dev ? function ?	# Qlogic ISP [12]0x0 SCSI/FC
+#siop*		at pci? dev ? function ?	# NCR 53c8xx SCSI
+#esiop*		at pci? dev ? function ?	# NCR 53c82s75xx SCSI and newer
+#pcscp*		at pci? dev ? function ?	# AMD 53c974 PCscsi-PCI SCSI
+
+# SCSI bus support
+#scsibus* 	at adv?
+#scsibus* 	at adw?
+#scsibus* 	at ahc?
+#scsibus* 	at bha?
+#scsibus* 	at dpt?
+#scsibus* 	at isp?
+#scsibus* 	at siop?
+#scsibus* 	at esiop?
+#scsibus* 	at pcscp?
+
+# SCSI devices
+#sd*		at scsibus? target ? lun ?	# SCSI disk drives
+#st*		at scsibus? target ? lun ?	# SCSI tape drives
+#cd*		at scsibus? target ? lun ?	# SCSI CD-ROM drives
+#ch*		at scsibus? target ? lun ?	# SCSI autochangers
+#ss*		at scsibus? target ? lun ?	# SCSI scanners
+#uk*		at scsibus? target ? lun ?	# SCSI unknown
+
+# RAID controllers and devices
+#cac*		at pci? dev ? function ?	# Compaq array controller
+#ca*		at cac? unit ?			# Compaq array disk device
+
+# IDE and related devices
+# PCI IDE controllers - see pciide(4) for supported hardware.
+# The 0x0001 flag force the driver to use DMA, even if the driver doesn't know
+# how to set up DMA modes for this chip. This may work, or may cause
+# a machine hang with some controllers.
+pciide* 	at pci? dev ? function ? flags 0x0000	# GENERIC pciide driver
+acardide*	at pci? dev ? function ?	# Acard IDE controllers
+aceride* 	at pci? dev ? function ?	# Acer Lab IDE controllers
+artsata*	at pci? dev ? function ?	# Intel i31244 SATA controller
+cmdide* 	at pci? dev ? function ?	# CMD tech IDE controllers
+cypide* 	at pci? dev ? function ?	# Cypress IDE controllers
+hptide* 	at pci? dev ? function ?	# Triones/HighPoint IDE controllers
+optiide* 	at pci? dev ? function ?	# Opti IDE controllers
+#piixide* 	at pci? dev ? function ?	# Intel IDE controllers
+pdcide* 	at pci? dev ? function ?	# Promise IDE controllers
+pdcsata* 	at pci? dev ? function ?	# Promise SATA150 controllers
+satalink*	at pci? dev ? function ?	# SiI SATALink controllers
+siside* 	at pci? dev ? function ?	# SiS IDE controllers
+slide*  	at pci? dev ? function ?	# Symphony Labs IDE controllers
+viaide* 	at pci? dev ? function ?	# VIA/AMD/Nvidia IDE controllers
+
+# ATA bus
+atabus* 	at ata?
+
+# IDE drives
+# Flags are used only with controllers that support DMA operations
+# and mode settings (e.g. some pciide controllers)
+# The lowest order four bits (rightmost digit) of the flags define the PIO
+# mode to use, the next set of four bits the DMA mode and the third set the
+# UltraDMA mode. For each set of four bits, the 3 lower bits define the mode
+# to use, and the last bit must be 1 for this setting to be used.
+# For DMA and UDMA, 0xf (1111) means 'disable'.
+# 0x0fac means 'use PIO mode 4, DMA mode 2, disable UltraDMA'.
+# (0xc=1100, 0xa=1010, 0xf=1111)
+# 0x0000 means "use whatever the drive claims to support".
+wd* 		at atabus? drive ? flags 0x0000
+
+# PCI network interfaces
+#en*		at pci? dev ? function ?	# ENI/Adaptec ATM
+#ep*		at pci? dev ? function ?	# 3Com 3c59x
+#ex*		at pci? dev ? function ?	# 3Com 90x[BC]
+#epic*		at pci? dev ? function ?	# SMC EPIC/100 Ethernet
+#esh*		at pci? dev ? function ?	# Essential HIPPI card
+#fpa*		at pci? dev ? function ?	# DEC DEFPA FDDI
+#fxp*		at pci? dev ? function ?	# Intel EtherExpress PRO10+/100B
+#le*		at pci? dev ? function ?	# PCnet-PCI Ethernet
+#ne*		at pci? dev ? function ?	# NE2000-compatible Ethernet
+#ntwoc*		at pci? dev ? function ?	# Riscom/N2 PCI Sync Serial
+#sip*		at pci? dev ? function ?	# SiS 900 Ethernet
+#tl*		at pci? dev ? function ?	# ThunderLAN-based Ethernet
+tlp*		at pci? dev ? function ?	# DECchip 21x4x and clones
+#vr*		at pci? dev ? function ?	# VIA Rhine Fast Ethernet
+#lmc*		at pci? dev ? function ?	# Lan Media Corp SSI/HSSI/DS3
+#rtk*		at pci? dev ? function ?	# Realtek 8129/8139
+
+# MII/PHY support
+#exphy*		at mii? phy ?			# 3Com internal PHYs
+#icsphy*		at mii? phy ?			# ICS189x PHYs
+#inphy*		at mii? phy ?			# Intel 82555 PHYs
+#iophy*		at mii? phy ?			# Intel 82553 PHYs
+lxtphy*		at mii? phy ?			# Level One LXT-970 PHYs
+#nsphy*		at mii? phy ?			# NS83840 PHYs
+#nsphyter* 	at mii? phy ?			# NS83843 PHYs
+#qsphy*		at mii? phy ?			# Quality Semiconductor QS6612
+#sqphy*		at mii? phy ?			# Seeq 80220/80221/80223 PHYs
+#tlphy*		at mii? phy ?			# ThunderLAN PHYs
+#tqphy*		at mii? phy ?			# TDK Semiconductor PHYs
+#ukphy*		at mii? phy ?			# generic unknown PHYs
+
+# PCI audio devices
+#clcs*		at pci? dev ? function ?	# Cirrus Logic CS4280
+#eap*		at pci? dev ? function ?	# Ensoniq AudioPCI
+#eso*		at pci? dev ? function ?	# ESS Solo-1 PCI AudioDrive
+#fms*		at pci? dev ? function ?	# Forte Media FM801
+#sbl*		at pci? dev ? function ?	# SoundBlaster Live!
+#sv*		at pci? dev ? function ?	# S3 SonicVibes
+
+# Pseudo-devices
+
+#pseudo-device 	crypto				# opencrypto framework
+
+# Disk/mass storage pseudo-devices
+#pseudo-device	ccd		4		# concatenated disk devices
+#pseudo-device	cgd		4		# cryptographic disk devices
+#pseudo-device	raid		8		# RAIDframe disk driver
+#options 	RAID_AUTOCONFIG			# auto-configuration of RAID
+# Options to enable various other RAIDframe RAID types.
+# options	RF_INCLUDE_EVENODD=1
+# options	RF_INCLUDE_RAID5_RS=1
+# options	RF_INCLUDE_PARITYLOGGING=1
+# options	RF_INCLUDE_CHAINDECLUSTER=1
+# options	RF_INCLUDE_INTERDECLUSTER=1
+# options 	RF_INCLUDE_PARITY_DECLUSTERING=1
+# options	RF_INCLUDE_PARITY_DECLUSTERING_DS=1
+#pseudo-device	md		1		# memory disk device (ramdisk)
+#pseudo-device	vnd		4		# disk-like interface to files
+
+# Network pseudo-devices
+pseudo-device	bpfilter	8		# Berkeley packet filter
+#pseudo-device	ipfilter			# IP filter (firewall) and NAT
+pseudo-device	loop				# network loopback
+#pseudo-device	ppp		2		# Point-to-Point Protocol
+#pseudo-device	pppoe				# PPP over Ethernet (RFC 2516)
+#pseudo-device	sl		2		# Serial Line IP
+#pseudo-device	strip		2		# Starmode Radio IP (Metricom)
+#pseudo-device	tun		2		# network tunneling over tty
+#pseudo-device	gre		2		# generic L3 over IP tunnel
+#pseudo-device	gif		4		# RFC1933 tunnel
+#pseudo-device	faith		1		# IPv[46] tcp relay translation
+#pseudo-device	stf		1		# 6to4 IPv6 over IPv4 encapsulation
+#pseudo-device	vlan			# IEEE 802.1q encapsulation
+#pseudo-device	bridge			# simple inter-network bridging
+#options	BRIDGE_IPF		# bridge uses IP/IPv6 pfil hooks too
+
+# Miscellaneous pseudo-devices
+pseudo-device	pty				# pseudo-terminals
+#pseudo-device	tb		1		# tablet line discipline
+#pseudo-device	sequencer	1		# MIDI sequencer
+pseudo-device	rnd				# /dev/random & kernel generator
+#options 	RND_COM				# use "com" randomness (BROKEN)
+pseudo-device	clockctl		# user control of clock subsystem
+pseudo-device	nullcons			# no-op console
+
+# A pseudo device needed for Coda		# also needs CODA (above)
+#pseudo-device	vcoda		4		# coda minicache <-> venus comm.
+#pseudo-device	ksyms				# /dev/ksyms
--- sys/arch/cobalt/dev/com_mainbus.c.orig	2003-10-18 03:20:10.000000000 +0900
+++ sys/arch/cobalt/dev/com_mainbus.c	2005-11-23 15:16:37.000000000 +0900
@@ -30,27 +30,19 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/ioctl.h>
-#include <sys/select.h>
-#include <sys/tty.h>
-#include <sys/proc.h>
-#include <sys/user.h>
-#include <sys/conf.h>
-#include <sys/file.h>
-#include <sys/uio.h>
-#include <sys/kernel.h>
-#include <sys/syslog.h>
-#include <sys/types.h>
 #include <sys/device.h>
+#include <sys/termios.h>
 
 #include <machine/autoconf.h>
 #include <machine/intr.h>
 #include <machine/bus.h>
 #include <machine/nvram.h>
+#include <machine/bootinfo.h>
 
 #include <dev/ic/comreg.h>
 #include <dev/ic/comvar.h>
 
+#include <cobalt/dev/com_mainbusvar.h>
 
 extern int console_present;
 
@@ -59,6 +51,9 @@
 	void *sc_ih;
 };
 
+#define COM_MAINBUS_FREQ	(COM_FREQ * 10)
+#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
+
 static int	com_mainbus_probe(struct device *, struct cfdata *, void *);
 static void	com_mainbus_attach(struct device *, struct device *, void *);
 
@@ -66,35 +61,34 @@
     com_mainbus_probe, com_mainbus_attach, NULL, NULL);
 
 int
-com_mainbus_probe(parent, match, aux)
-	struct device *parent;
-	struct cfdata *match;
-	void *aux;
+com_mainbus_probe(struct device *parent, struct cfdata *match, void *aux)
 {
 
-	return (console_present != 0);
+	return console_present != 0;
 }
 
-struct com_softc *com0; /* XXX */
-
 void
-com_mainbus_attach(parent, self, aux)
-	struct device *parent;
-	struct device *self;
-	void *aux;
+com_mainbus_attach(struct device *parent, struct device *self, void *aux)
 {
 	struct com_mainbus_softc *msc = (void *)self;
 	struct com_softc *sc = &msc->sc_com;
 	struct mainbus_attach_args *maa = aux;
 
-	sc->sc_ioh = maa->ma_ioh;
 	sc->sc_iot = maa->ma_iot;
 	sc->sc_iobase = maa->ma_addr;
 
-	sc->sc_frequency = COM_FREQ * 10;
+#if 0	/* XXX */
+	if (!com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) &&
+	    bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS, 0,
+	    &sc->sc_ioh)) {
+		printf(": can't map i/o space\n");
+		return;
+	}
+#else
+	sc->sc_ioh = maa->ma_ioh;
+#endif
 
-	/* XXX console check */
-	/* XXX map */
+	sc->sc_frequency = COM_MAINBUS_FREQ;
 
 	com_attach_subr(sc);
 
@@ -102,3 +96,39 @@
 
 	return;
 }
+
+void
+com_mainbus_cnprobe(struct consdev *cn)
+{
+	struct btinfo_flags *bi_flags;
+
+	/*
+	 * Linux code has a comment that serial console must be probed
+	 * early, otherwise the value which allows to detect serial port
+	 * could be overwritten. Okay, probe here and record the result
+	 * for the future use.
+	 *
+	 * Note that if the kernel was booted with a boot loader,
+	 * the latter *has* to provide a flag indicating whether console
+	 * is present or not because the value might be overwritten by
+	 * the loaded kernel.
+	 */
+	if ((bi_flags = lookup_bootinfo(BTINFO_FLAGS)) == NULL) {
+		/* No boot information, probe console now */
+		console_present = *(volatile u_int32_t *)
+					MIPS_PHYS_TO_KSEG1(0x0020001c);
+	} else {
+		/* Get the value determined by the boot loader. */
+		console_present = bi_flags->bi_flags & BI_SERIAL_CONSOLE;
+	}
+
+	cn->cn_pri = (console_present != 0) ? CN_NORMAL : CN_DEAD;
+}
+
+void
+com_mainbus_cninit(struct consdev *cn)
+{
+
+	comcnattach(0, 0x1c800000, 115200, COM_MAINBUS_FREQ, COM_TYPE_NORMAL,
+	    CONMODE);
+}
--- /dev/null	2005-11-23 15:04:16.000000000 +0900
+++ sys/arch/cobalt/dev/com_mainbusvar.h	2005-11-23 15:15:15.000000000 +0900
@@ -0,0 +1,31 @@
+/*	$NetBSD$	*/
+
+/*
+ * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <dev/cons.h>
+
+dev_type_cnprobe(com_mainbus_cnprobe);
+dev_type_cninit(com_mainbus_cninit);