1997-02-12 04:07:56 +03:00
|
|
|
/* $NetBSD: zs_kgdb.c,v 1.11 1997/02/12 01:07:56 gwr Exp $ */
|
1996-01-25 01:39:48 +03:00
|
|
|
|
1996-11-20 21:56:49 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
1996-01-25 01:39:48 +03:00
|
|
|
*
|
1996-11-20 21:56:49 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Gordon W. Ross.
|
1996-01-25 01:39:48 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1996-11-20 21:56:49 +03:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1996-01-25 01:39:48 +03:00
|
|
|
*
|
1996-11-20 21:56:49 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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
|
1997-01-27 22:40:46 +03:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-11-20 21:56:49 +03:00
|
|
|
* 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.
|
1996-01-25 01:39:48 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1997-02-12 04:07:56 +03:00
|
|
|
* Hooks for kgdb when attached via the z8530 driver
|
1996-01-31 01:34:52 +03:00
|
|
|
*
|
|
|
|
* To use this, build a kernel with: option KGDB, and
|
|
|
|
* boot that kernel with "-d". (The kernel will call
|
|
|
|
* zs_kgdb_init, kgdb_connect.) When the console prints
|
1997-02-12 04:07:56 +03:00
|
|
|
* "kgdb waiting..." you run "gdb -k kernel" and do:
|
|
|
|
* (gdb) set remotebaud 19200
|
|
|
|
* (gdb) target remote /dev/ttyb
|
1996-01-25 01:39:48 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
1997-02-12 04:07:56 +03:00
|
|
|
#include <sys/kgdb.h>
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
#include <dev/ic/z8530reg.h>
|
|
|
|
#include <machine/z8530var.h>
|
1997-02-12 04:07:56 +03:00
|
|
|
#include <sun3/dev/zs_cons.h>
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
/* The Sun3 provides a 4.9152 MHz clock to the ZS chips. */
|
|
|
|
#define PCLK (9600 * 512) /* PCLK pin input clock rate */
|
1996-06-17 19:40:36 +04:00
|
|
|
#define ZSHARD_PRI 6 /* Wired on the CPU board... */
|
1996-01-25 01:39:48 +03:00
|
|
|
|
1996-02-16 21:00:33 +03:00
|
|
|
#define ZS_DELAY() delay(2)
|
1996-01-31 01:34:52 +03:00
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
/* The layout of this is hardware-dependent (padding, order). */
|
|
|
|
struct zschan {
|
|
|
|
volatile u_char zc_csr; /* ctrl,status, and indirect access */
|
|
|
|
u_char zc_xxx0;
|
|
|
|
volatile u_char zc_data; /* data */
|
|
|
|
u_char zc_xxx1;
|
|
|
|
};
|
|
|
|
|
1997-02-12 04:07:56 +03:00
|
|
|
static void zs_setparam __P((struct zs_chanstate *, int, int));
|
|
|
|
static void zskgdb __P((struct zs_chanstate *));
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
struct zsops zsops_kgdb;
|
|
|
|
|
|
|
|
static u_char zs_kgdb_regs[16] = {
|
|
|
|
0, /* 0: CMD (reset, etc.) */
|
1997-02-12 04:07:56 +03:00
|
|
|
0, /* 1: ~(ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE) */
|
1996-01-25 01:39:48 +03:00
|
|
|
0x18 + ZSHARD_PRI, /* IVECT */
|
|
|
|
ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
|
|
|
|
ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
|
|
|
|
ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
|
|
|
|
0, /* 6: TXSYNC/SYNCLO */
|
|
|
|
0, /* 7: RXSYNC/SYNCHI */
|
|
|
|
0, /* 8: alias for data port */
|
|
|
|
ZSWR9_MASTER_IE,
|
|
|
|
0, /*10: Misc. TX/RX control bits */
|
|
|
|
ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
|
|
|
|
14, /*12: BAUDLO (default=9600) */
|
|
|
|
0, /*13: BAUDHI (default=9600) */
|
|
|
|
ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
|
|
|
|
ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
|
|
|
|
};
|
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
/*
|
|
|
|
* This replaces "zs_reset()" in the sparc driver.
|
|
|
|
*/
|
1996-01-25 01:39:48 +03:00
|
|
|
static void
|
|
|
|
zs_setparam(cs, iena, rate)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
int iena;
|
|
|
|
int rate;
|
|
|
|
{
|
|
|
|
int s, tconst;
|
|
|
|
|
|
|
|
bcopy(zs_kgdb_regs, cs->cs_preg, 16);
|
|
|
|
|
1997-02-12 04:07:56 +03:00
|
|
|
if (iena) {
|
|
|
|
cs->cs_preg[1] = ZSWR1_RIE | ZSWR1_SIE;
|
1996-01-25 01:39:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the speed, etc. */
|
1996-05-17 23:32:06 +04:00
|
|
|
tconst = BPS_TO_TCONST(cs->cs_brg_clk, rate);
|
1996-01-25 01:39:48 +03:00
|
|
|
cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
|
|
|
|
cs->cs_preg[12] = tconst;
|
|
|
|
cs->cs_preg[13] = tconst >> 8;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
zs_loadchannelregs(cs);
|
|
|
|
splx(s);
|
1996-06-17 19:40:36 +04:00
|
|
|
}
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up for kgdb; called at boot time before configuration.
|
|
|
|
* KGDB interrupts will be enabled later when zs0 is configured.
|
1997-02-12 04:07:56 +03:00
|
|
|
* Called after cninit(), so printf() etc. works.
|
1996-01-25 01:39:48 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
zs_kgdb_init()
|
|
|
|
{
|
|
|
|
struct zs_chanstate cs;
|
|
|
|
volatile struct zschan *zc;
|
|
|
|
int channel, zsc_unit;
|
|
|
|
|
1997-02-12 04:07:56 +03:00
|
|
|
/* printf("zs_kgdb_init: kgdb_dev=0x%x\n", kgdb_dev); */
|
|
|
|
if (major(kgdb_dev) != zs_major)
|
1996-01-25 01:39:48 +03:00
|
|
|
return;
|
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
/* Note: (ttya,ttyb) on zsc1, and (ttyc,ttyd) on zsc0 */
|
1997-02-12 04:07:56 +03:00
|
|
|
zsc_unit = (kgdb_dev & 2) ? 0 : 1;
|
|
|
|
channel = kgdb_dev & 1;
|
|
|
|
printf("zs_kgdb_init: attaching tty%c at %d baud\n",
|
|
|
|
'a' + (kgdb_dev & 3), kgdb_rate);
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
/* Setup temporary chanstate. */
|
|
|
|
bzero((caddr_t)&cs, sizeof(cs));
|
|
|
|
zc = zs_get_chan_addr(zsc_unit, channel);
|
1997-02-12 04:07:56 +03:00
|
|
|
if (zc == NULL) {
|
|
|
|
printf("zs_kgdb_init: zs not mapped.\n");
|
|
|
|
kgdb_dev = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
cs.cs_channel = channel;
|
1996-05-17 23:32:06 +04:00
|
|
|
cs.cs_brg_clk = PCLK / 16;
|
1997-02-12 04:07:56 +03:00
|
|
|
cs.cs_reg_csr = &zc->zc_csr;
|
|
|
|
cs.cs_reg_data = &zc->zc_data;
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
/* Now set parameters. (interrupts disabled) */
|
|
|
|
zs_setparam(&cs, 0, kgdb_rate);
|
|
|
|
|
|
|
|
/* Store the getc/putc functions and arg. */
|
|
|
|
kgdb_attach(zs_getc, zs_putc, (void *)zc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a "hook" called by zstty_attach to allow the tty
|
|
|
|
* to be "taken over" for exclusive use by kgdb.
|
|
|
|
* Return non-zero if this is the kgdb port.
|
|
|
|
*
|
|
|
|
* Set the speed to kgdb_rate, CS8, etc.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
zs_check_kgdb(cs, dev)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
int dev;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (dev != kgdb_dev)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
1997-02-12 04:07:56 +03:00
|
|
|
* Yes, this is port in use by kgdb.
|
1996-01-25 01:39:48 +03:00
|
|
|
*/
|
|
|
|
cs->cs_private = NULL;
|
|
|
|
cs->cs_ops = &zsops_kgdb;
|
|
|
|
|
|
|
|
/* Now set parameters. (interrupts enabled) */
|
1997-02-12 04:07:56 +03:00
|
|
|
zs_setparam(cs, 1, kgdb_rate);
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* KGDB framing character received: enter kernel debugger. This probably
|
|
|
|
* should time out after a few seconds to avoid hanging on spurious input.
|
|
|
|
*/
|
1997-02-12 04:07:56 +03:00
|
|
|
static void
|
|
|
|
zskgdb(cs)
|
|
|
|
struct zs_chanstate *cs;
|
1996-01-25 01:39:48 +03:00
|
|
|
{
|
1996-06-17 19:40:36 +04:00
|
|
|
int unit = minor(kgdb_dev);
|
1996-01-25 01:39:48 +03:00
|
|
|
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("zstty%d: kgdb interrupt\n", unit);
|
1996-01-25 01:39:48 +03:00
|
|
|
/* This will trap into the debugger. */
|
|
|
|
kgdb_connect(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Interface to the lower layer (zscc)
|
|
|
|
****************************************************************/
|
|
|
|
|
1997-02-12 04:07:56 +03:00
|
|
|
static void zs_kgdb_rxint __P((struct zs_chanstate *));
|
|
|
|
static void zs_kgdb_txint __P((struct zs_chanstate *));
|
|
|
|
static void zs_kgdb_stint __P((struct zs_chanstate *));
|
|
|
|
static void zs_kgdb_softint __P((struct zs_chanstate *));
|
|
|
|
|
1996-01-25 01:39:48 +03:00
|
|
|
int kgdb_input_lost;
|
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
static void
|
1996-01-25 01:39:48 +03:00
|
|
|
zs_kgdb_rxint(cs)
|
1997-02-12 04:07:56 +03:00
|
|
|
struct zs_chanstate *cs;
|
1996-01-25 01:39:48 +03:00
|
|
|
{
|
|
|
|
register u_char c, rr1;
|
|
|
|
|
|
|
|
/* Read the input data ASAP. */
|
1996-01-31 01:34:52 +03:00
|
|
|
c = zs_read_data(cs);
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
/* Save the status register too. */
|
1996-01-31 01:34:52 +03:00
|
|
|
rr1 = zs_read_reg(cs, 1);
|
1996-01-25 01:39:48 +03:00
|
|
|
|
|
|
|
if (rr1 & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
|
|
|
|
/* Clear the receive error. */
|
1996-01-31 01:34:52 +03:00
|
|
|
zs_write_csr(cs, ZSWR0_RESET_ERRORS);
|
1996-01-25 01:39:48 +03:00
|
|
|
}
|
|
|
|
|
1997-02-12 04:07:56 +03:00
|
|
|
if (c == KGDB_START) {
|
|
|
|
zskgdb(cs);
|
1996-01-25 01:39:48 +03:00
|
|
|
} else {
|
|
|
|
kgdb_input_lost++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
static void
|
1996-01-25 01:39:48 +03:00
|
|
|
zs_kgdb_txint(cs)
|
|
|
|
register struct zs_chanstate *cs;
|
|
|
|
{
|
1996-01-31 01:34:52 +03:00
|
|
|
register int rr0;
|
1996-01-25 01:39:48 +03:00
|
|
|
|
1996-01-31 01:34:52 +03:00
|
|
|
rr0 = zs_read_csr(cs);
|
|
|
|
zs_write_csr(cs, ZSWR0_RESET_TXINT);
|
1996-01-25 01:39:48 +03:00
|
|
|
}
|
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
static void
|
1996-01-25 01:39:48 +03:00
|
|
|
zs_kgdb_stint(cs)
|
|
|
|
register struct zs_chanstate *cs;
|
|
|
|
{
|
|
|
|
register int rr0;
|
|
|
|
|
1996-01-31 01:34:52 +03:00
|
|
|
rr0 = zs_read_csr(cs);
|
|
|
|
zs_write_csr(cs, ZSWR0_RESET_STATUS);
|
1997-02-12 04:07:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check here for console break, so that we can abort
|
|
|
|
* even when interrupts are locking up the machine.
|
|
|
|
*/
|
|
|
|
if (rr0 & ZSRR0_BREAK) {
|
|
|
|
zskgdb(cs);
|
|
|
|
}
|
1996-01-25 01:39:48 +03:00
|
|
|
}
|
|
|
|
|
1996-06-17 19:40:36 +04:00
|
|
|
static void
|
1996-01-25 01:39:48 +03:00
|
|
|
zs_kgdb_softint(cs)
|
|
|
|
struct zs_chanstate *cs;
|
|
|
|
{
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("zs_kgdb_softint?\n");
|
1996-01-25 01:39:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct zsops zsops_kgdb = {
|
|
|
|
zs_kgdb_rxint, /* receive char available */
|
|
|
|
zs_kgdb_stint, /* external/status */
|
|
|
|
zs_kgdb_txint, /* xmit buffer empty */
|
|
|
|
zs_kgdb_softint, /* process software interrupt */
|
|
|
|
};
|