Initialize system console from a central place (don't use cninit()

anymore). This makes the code cleaner (no more bus tag guessing in the
serial console driver) and it allows to share code with KGDB port
initialization.
The console device is now given as string ("pc", "com0".."com3").
Modelled after alpha port.
This commit is contained in:
drochner 1997-08-14 16:21:49 +00:00
parent b426bd9be3
commit 473b4f1222

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.242 1997/08/12 17:28:12 drochner Exp $ */
/* $NetBSD: machdep.c,v 1.243 1997/08/14 16:21:49 drochner Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -163,7 +163,18 @@
extern struct proc *npxproc;
#endif
#ifdef KGDB
#include "pc.h"
#if (NPC > 0)
#include <machine/pccons.h>
#endif
#include "vt.h"
#if (NVT > 0)
#include <i386/isa/pcvt/pcvt_cons.h>
#endif
#include "com.h"
#if (NCOM > 0)
#include <sys/termios.h>
#include <dev/isa/comreg.h>
#include <dev/isa/comvar.h>
@ -199,6 +210,10 @@ int msgbufmapped;
vm_map_t buffer_map;
#ifndef CONSDEVNAME
#define CONSDEVNAME "pc"
#endif
char consdevname[] = CONSDEVNAME;
#ifdef KGDB
#ifndef KGDB_DEVNAME
#define KGDB_DEVNAME "com0"
@ -233,7 +248,13 @@ caddr_t allocsys __P((caddr_t));
void dumpsys __P((void));
void identifycpu __P((void));
void init386 __P((vm_offset_t));
#if (NCOM > 0)
static int initcomport __P((unsigned int, int, int *, bus_space_handle_t *));
#endif
void consinit __P((void));
#ifdef KGDB
void kgdb_port_init __P((void));
#endif
#ifdef COMPAT_NOMID
static int exec_nomid __P((struct proc *, struct exec_package *));
#endif
@ -1496,23 +1517,7 @@ init386(first_avail)
Debugger();
#endif
#ifdef KGDB
com_kgdb_iot = I386_BUS_SPACE_IO;
if(!strcmp(kgdb_devname, "com0"))
com_kgdb_addr = 0x3f8;
else if(!strcmp(kgdb_devname, "com1"))
com_kgdb_addr = 0x2f8;
else
panic("invalid KGDB device %s", kgdb_devname);
if (bus_space_map(com_kgdb_iot, com_kgdb_addr, COM_NPORTS,
0, &com_kgdb_ioh))
panic("can't map KGDB I/O ports");
cominit(com_kgdb_iot, com_kgdb_ioh, KGDBRATE);
kgdb_dev = 123; /* unneeded, only to satisfy some tests */
kgdb_attach(com_kgdb_getc, com_kgdb_putc, NULL);
kgdb_port_init();
if (boothowto & RB_KDB) {
kgdb_debug_init = 1;
kgdb_connect(1);
@ -1689,6 +1694,29 @@ pmap_page_index(pa)
return -1;
}
#if (NCOM > 0)
/* minimal initialization of a com port for use by console or KGDB */
static int initcomport(idx, rate, iobase, handle)
unsigned int idx;
int rate;
int *iobase;
bus_space_handle_t *handle;
{
bus_space_tag_t tag = I386_BUS_SPACE_IO;
static int combases[] = {0x3f8, 0x2f8, 0x3e8, 0x3e8};
if(idx >= sizeof(combases) / sizeof(int))
return(-1);
*iobase = combases[idx];
if (bus_space_map(tag, *iobase, COM_NPORTS, 0, handle))
return(-1);
cominit(tag, *handle, rate);
return(0);
}
#endif
/*
* consinit:
* initialize the system console.
@ -1703,9 +1731,58 @@ consinit()
if (initted)
return;
initted = 1;
cninit();
#if (NPC > 0) || (NVT > 0)
if(!strcmp(consdevname, "pc")) {
static struct consdev pccons = { NULL, NULL,
pccngetc, pccnputc, pccnpollc, NODEV, 1};
pccninit(0);
pccons.cn_dev = makedev(12, 0); /* XXX */
cn_tab = &pccons;
return;
}
#endif
#if (NCOM > 0)
if(!strncmp(consdevname, "com", 3)) {
static struct consdev comcons = { NULL, NULL,
comcngetc, comcnputc, comcnpollc, NODEV, 1};
if(initcomport(consdevname[3] - '0', comconsrate,
&comconsaddr, &comconsioh)) {
panic("can't init console port %s", consdevname);
}
comcons.cn_dev = makedev(8, consdevname[3] - '0'); /* XXX */
cn_tab = &comcons;
comconscflag = (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8;
return;
}
#endif
panic("invalid console device %s", consdevname);
}
#ifdef KGDB
void
kgdb_port_init()
{
if(!strcmp(kgdb_devname, consdevname)) /* must be != console */
return;
#if (NCOM > 0)
if(!strncmp(kgdb_devname, "com", 3)) {
if(initcomport(kgdb_devname[3] - '0', kgdb_rate,
&com_kgdb_addr, &com_kgdb_ioh)) {
panic("can't init KGDB device %s", kgdb_devname);
}
kgdb_dev = 123; /* unneeded, only to satisfy some tests */
kgdb_attach(com_kgdb_getc, com_kgdb_putc, NULL);
}
#endif
}
#endif
void
cpu_reset()
{