Home | History | Annotate | Line # | Download | only in dev
zs_kgdb.c revision 1.1
      1 
      2 /*
      3  * Copyright (c) 1994 Gordon W. Ross
      4  * Copyright (c) 1992, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This software was developed by the Computer Systems Engineering group
      8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  * contributed to Berkeley.
     10  *
     11  * All advertising materials mentioning features or use of this software
     12  * must display the following acknowledgement:
     13  *	This product includes software developed by the University of
     14  *	California, Lawrence Berkeley Laboratory.
     15  *
     16  * Redistribution and use in source and binary forms, with or without
     17  * modification, are permitted provided that the following conditions
     18  * are met:
     19  * 1. Redistributions of source code must retain the above copyright
     20  *    notice, this list of conditions and the following disclaimer.
     21  * 2. Redistributions in binary form must reproduce the above copyright
     22  *    notice, this list of conditions and the following disclaimer in the
     23  *    documentation and/or other materials provided with the distribution.
     24  * 3. All advertising materials mentioning features or use of this software
     25  *    must display the following acknowledgement:
     26  *	This product includes software developed by the University of
     27  *	California, Berkeley and its contributors.
     28  * 4. Neither the name of the University nor the names of its contributors
     29  *    may be used to endorse or promote products derived from this software
     30  *    without specific prior written permission.
     31  *
     32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42  * SUCH DAMAGE.
     43  *
     44  *	@(#)zs.c	8.1 (Berkeley) 7/19/93
     45  */
     46 
     47 /*
     48  * Hooks for kgdb when attached vi the z8530 driver
     49  * XXX - not tested yet...
     50  */
     51 
     52 #include <sys/param.h>
     53 #include <sys/systm.h>
     54 #include <sys/proc.h>
     55 #include <sys/device.h>
     56 #include <sys/conf.h>
     57 #include <sys/ioctl.h>
     58 #include <sys/kernel.h>
     59 #include <sys/syslog.h>
     60 
     61 #include <dev/ic/z8530reg.h>
     62 #include <machine/z8530var.h>
     63 
     64 #include <machine/remote-sl.h>
     65 
     66 /* The Sun3 provides a 4.9152 MHz clock to the ZS chips. */
     67 #define PCLK	(9600 * 512)	/* PCLK pin input clock rate */
     68 
     69 extern int kgdb_dev;
     70 extern int kgdb_rate;
     71 
     72 struct zschan * zs_get_chan_addr __P((int zsc_unit, int channel));
     73 
     74 extern int  zs_getc __P((void *arg));
     75 extern void zs_putc __P((void *arg,	int c));
     76 
     77 struct zsops zsops_kgdb;
     78 
     79 static u_char zs_kgdb_regs[16] = {
     80 	0,	/* 0: CMD (reset, etc.) */
     81 	ZSWR1_RIE,	/* NOT: (ZSWR1_TIE | ZSWR1_SIE) */
     82 	0x18 + ZSHARD_PRI,	/* IVECT */
     83 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
     84 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
     85 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
     86 	0,	/* 6: TXSYNC/SYNCLO */
     87 	0,	/* 7: RXSYNC/SYNCHI */
     88 	0,	/* 8: alias for data port */
     89 	ZSWR9_MASTER_IE,
     90 	0,	/*10: Misc. TX/RX control bits */
     91 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
     92 	14,	/*12: BAUDLO (default=9600) */
     93 	0,	/*13: BAUDHI (default=9600) */
     94 	ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
     95 	ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
     96 };
     97 
     98 static void
     99 zs_setparam(cs, iena, rate)
    100 	struct zs_chanstate *cs;
    101 	int iena;
    102 	int rate;
    103 {
    104 	int s, tconst;
    105 
    106 	bcopy(zs_kgdb_regs, cs->cs_preg, 16);
    107 
    108 	if (iena == 0) {
    109 		cs->cs_preg[1] = 0;
    110 	}
    111 
    112 	/* Initialize the speed, etc. */
    113 	tconst = BPS_TO_TCONST(cs->cs_pclk_div16, rate);
    114 	cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
    115 	cs->cs_preg[12] = tconst;
    116 	cs->cs_preg[13] = tconst >> 8;
    117 
    118 	s = splhigh();
    119 	zs_loadchannelregs(cs);
    120 	splx(s);
    121 
    122 
    123 /*
    124  * Set up for kgdb; called at boot time before configuration.
    125  * KGDB interrupts will be enabled later when zs0 is configured.
    126  */
    127 void
    128 zs_kgdb_init()
    129 {
    130 	struct zs_chanstate cs;
    131 	volatile struct zschan *zc;
    132 	int channel, zsc_unit;
    133 
    134 	if (major(kgdb_dev) != ZSMAJOR)
    135 		return;
    136 
    137 	zsc_unit = 1;	/* XXX */
    138 	channel = minor(kgdb_dev) & 1;
    139 	printf("zs_kgdb_init: attaching zstty%d at %d baud\n",
    140 		   channel, kgdb_rate);
    141 
    142 	/* Setup temporary chanstate. */
    143 	bzero((caddr_t)&cs, sizeof(cs));
    144 	zc = zs_get_chan_addr(zsc_unit, channel);
    145 	cs.cs_reg_csr  = &zc->zc_csr;
    146 	cs.cs_reg_data = &zc->zc_data;
    147 	cs.cs_channel = channel;
    148 	cs.cs_pclk_div16 = PCLK / 16;
    149 
    150 	/* Now set parameters. (interrupts disabled) */
    151 	zs_setparam(&cs, 0, kgdb_rate);
    152 
    153 	/* Store the getc/putc functions and arg. */
    154 	kgdb_attach(zs_getc, zs_putc, (void *)zc);
    155 }
    156 
    157 /*
    158  * This is a "hook" called by zstty_attach to allow the tty
    159  * to be "taken over" for exclusive use by kgdb.
    160  * Return non-zero if this is the kgdb port.
    161  *
    162  * Set the speed to kgdb_rate, CS8, etc.
    163  */
    164 int
    165 zs_check_kgdb(cs, dev)
    166 	struct zs_chanstate *cs;
    167 	int dev;
    168 {
    169 	int tconst;
    170 
    171 	if (dev != kgdb_dev)
    172 		return (0);
    173 
    174 	/*
    175 	 * Yes, this is the kgdb port.  Finish the autoconfig
    176 	 * message and set up the port for our exclusive use.
    177 	 */
    178 	printf(" (kgdb,%d)\n", kgdb_rate);
    179 
    180 	cs->cs_private = NULL;
    181 	cs->cs_ops = &zsops_kgdb;
    182 
    183 	/* Now set parameters. (interrupts enabled) */
    184 	zs_setparam(&cs, 1, kgdb_rate);
    185 
    186 	return (1);
    187 }
    188 
    189 /*
    190  * KGDB framing character received: enter kernel debugger.  This probably
    191  * should time out after a few seconds to avoid hanging on spurious input.
    192  */
    193 zskgdb()
    194 {
    195 	unit = minor(kgdb_dev);
    196 
    197 	printf("zstty%d: kgdb interrupt\n", unit);
    198 	/* This will trap into the debugger. */
    199 	kgdb_connect(1);
    200 }
    201 
    202 
    203 /****************************************************************
    204  * Interface to the lower layer (zscc)
    205  ****************************************************************/
    206 
    207 int kgdb_input_lost;
    208 
    209 static int
    210 zs_kgdb_rxint(cs)
    211 	register struct zs_chanstate *cs;
    212 {
    213 	register u_char c, rr1;
    214 
    215 	/* Read the input data ASAP. */
    216 	c = *(cs->cs_reg_data);
    217 	ZS_DELAY();
    218 
    219 	/* Save the status register too. */
    220 	rr1 = ZS_READ(cs, 1);
    221 
    222 	if (rr1 & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
    223 		/* Clear the receive error. */
    224 		*(cs->cs_reg_csr) = ZSWR0_RESET_ERRORS;
    225 		ZS_DELAY();
    226 	}
    227 
    228 	if (c == FRAME_START) {
    229 		zskgdb();
    230 	} else {
    231 		kgdb_input_lost++;
    232 	}
    233 
    234 	return(0);
    235 }
    236 
    237 static int
    238 zs_kgdb_txint(cs)
    239 	register struct zs_chanstate *cs;
    240 {
    241 	register int count, rval;
    242 
    243 	*(cs->cs_reg_csr) = ZSWR0_RESET_TXINT;
    244 	ZS_DELAY();
    245 
    246 	return (0);
    247 }
    248 
    249 static int
    250 zs_kgdb_stint(cs)
    251 	register struct zs_chanstate *cs;
    252 {
    253 	register int rr0;
    254 
    255 	rr0 = *(cs->cs_reg_csr);
    256 	ZS_DELAY();
    257 
    258 	*(cs->cs_reg_csr) = ZSWR0_RESET_STATUS;
    259 	ZS_DELAY();
    260 
    261 	return (0);
    262 }
    263 
    264 static int
    265 zs_kgdb_softint(cs)
    266 	struct zs_chanstate *cs;
    267 {
    268 	printf("zs_kgdb_softint?\n");
    269 	return (0);
    270 }
    271 
    272 struct zsops zsops_kgdb = {
    273 	zs_kgdb_rxint,	/* receive char available */
    274 	zs_kgdb_stint,	/* external/status */
    275 	zs_kgdb_txint,	/* xmit buffer empty */
    276 	zs_kgdb_softint,	/* process software interrupt */
    277 };
    278