1999-04-24 12:01:01 +04:00
|
|
|
/* $NetBSD: dtop.c,v 1.39 1999/04/24 08:01:03 simonb Exp $ */
|
1994-10-27 00:08:38 +03:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*-
|
1994-05-27 12:39:00 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-10-12 06:22:19 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
1994-10-27 00:08:38 +03:00
|
|
|
* @(#)dtop.c 8.2 (Berkeley) 11/30/93
|
1993-10-12 06:22:19 +03:00
|
|
|
*/
|
|
|
|
|
1999-04-24 12:01:01 +04:00
|
|
|
/*
|
1993-10-12 06:22:19 +03:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990,1989 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
1999-04-24 12:01:01 +04:00
|
|
|
*
|
1993-10-12 06:22:19 +03:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
1999-04-24 12:01:01 +04:00
|
|
|
*
|
1999-04-13 00:38:17 +04:00
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
1993-10-12 06:22:19 +03:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1999-04-24 12:01:01 +04:00
|
|
|
*
|
1993-10-12 06:22:19 +03:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
1999-04-24 12:01:01 +04:00
|
|
|
*
|
1993-10-12 06:22:19 +03:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1999-04-24 12:01:01 +04:00
|
|
|
*
|
1993-10-12 06:22:19 +03:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Author: Alessandro Forin, Carnegie Mellon University
|
|
|
|
*
|
|
|
|
* Hardware-level operations for the Desktop serial line
|
|
|
|
* bus (i2c aka ACCESS).
|
|
|
|
*/
|
|
|
|
/************************************************************
|
|
|
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
|
|
|
|
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
1999-04-24 12:01:01 +04:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
1993-10-12 06:22:19 +03:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
1999-04-24 12:01:01 +04:00
|
|
|
both that copyright notice and this permission notice appear in
|
1993-10-12 06:22:19 +03:00
|
|
|
supporting documentation, and that the names of Digital or MIT not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
1999-04-24 12:01:01 +04:00
|
|
|
software without specific, written prior permission.
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
********************************************************/
|
|
|
|
|
1997-11-09 00:55:05 +03:00
|
|
|
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
1999-04-24 12:01:01 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: dtop.c,v 1.39 1999/04/24 08:01:03 simonb Exp $");
|
1997-11-09 00:55:05 +03:00
|
|
|
|
|
|
|
#include "rasterconsole.h"
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/map.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <machine/autoconf.h>
|
1996-05-19 05:12:40 +04:00
|
|
|
#include <machine/conf.h>
|
|
|
|
|
|
|
|
#include <dev/cons.h>
|
1995-08-10 08:21:35 +04:00
|
|
|
|
1996-10-13 17:13:50 +04:00
|
|
|
#include <mips/cpuregs.h> /* mips cached->uncached */
|
1997-05-25 08:58:36 +04:00
|
|
|
#include <machine/dc7085cons.h> /* mdmctl bits same on dtop and dc? */
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
#include <machine/pmioctl.h>
|
1997-05-25 08:58:36 +04:00
|
|
|
#include <machine/fbio.h>
|
|
|
|
#include <machine/fbvar.h>
|
|
|
|
#include <pmax/dev/fbreg.h>
|
1998-03-24 03:23:55 +03:00
|
|
|
#include <pmax/dev/rconsvar.h>
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
#include <pmax/pmax/asic.h>
|
1996-05-19 05:12:40 +04:00
|
|
|
#include <pmax/pmax/maxine.h>
|
1996-05-29 10:15:40 +04:00
|
|
|
#include <dev/tc/tcvar.h>
|
|
|
|
#include <dev/tc/ioasicvar.h>
|
1998-03-22 12:27:07 +03:00
|
|
|
#include <dev/dec/lk201.h>
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
#include <pmax/dev/dtopreg.h>
|
1996-05-19 05:12:40 +04:00
|
|
|
#include <pmax/dev/lk201var.h>
|
|
|
|
#include <pmax/dev/dtopvar.h>
|
1995-09-13 11:46:03 +04:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1998-10-29 07:54:20 +03:00
|
|
|
#define DTOP_MAX_POLL 0x70000 /* about half a sec */
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
typedef volatile unsigned int *data_reg_t; /* uC */
|
|
|
|
#define DTOP_GET_BYTE(data) (((*(data)) >> 8) & 0xff)
|
|
|
|
#define DTOP_PUT_BYTE(data,c) { *(data) = (c) << 8; }
|
|
|
|
|
|
|
|
typedef volatile unsigned int *poll_reg_t; /* SIR */
|
|
|
|
#define DTOP_RX_AVAIL(poll) (*(poll) & 1)
|
|
|
|
#define DTOP_TX_AVAIL(poll) (*(poll) & 2)
|
|
|
|
|
|
|
|
#define GET_SHORT(b0,b1) (((b0)<<8)|(b1))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver status
|
|
|
|
*/
|
|
|
|
struct dtop_softc {
|
1996-02-13 21:23:46 +03:00
|
|
|
struct device sc_dv;
|
|
|
|
struct tty *dtop_tty;
|
1993-10-12 06:22:19 +03:00
|
|
|
data_reg_t data;
|
|
|
|
poll_reg_t poll;
|
|
|
|
char polling_mode;
|
|
|
|
char probed_once;
|
|
|
|
short bad_pkts;
|
|
|
|
|
|
|
|
struct dtop_ds {
|
1997-05-25 06:37:55 +04:00
|
|
|
int (*handler)
|
|
|
|
__P((dtop_device_t, dtop_message_t, int, int));
|
1993-10-12 06:22:19 +03:00
|
|
|
dtop_device status;
|
|
|
|
} device[(DTOP_ADDR_DEFAULT - DTOP_ADDR_FIRST) >> 1];
|
|
|
|
|
|
|
|
# define DTOP_DEVICE_NO(address) (((address)-DTOP_ADDR_FIRST)>>1)
|
|
|
|
|
1996-02-13 21:23:46 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DTOP_TTY(unit) \
|
1996-03-17 04:38:52 +03:00
|
|
|
( ((struct dtop_softc*) dtop_cd.cd_devs[(unit)]) -> dtop_tty)
|
1993-10-12 06:22:19 +03:00
|
|
|
typedef struct dtop_softc *dtop_softc_t;
|
|
|
|
|
1996-05-19 05:12:40 +04:00
|
|
|
/*
|
|
|
|
* Forward/prototyped declarations
|
|
|
|
*/
|
|
|
|
int dtop_get_packet __P((dtop_softc_t dtop, dtop_message_t pkt));
|
|
|
|
int dtop_escape __P((int c));
|
|
|
|
void dtop_keyboard_repeat __P((void *));
|
|
|
|
int dtop_null_device_handler __P((dtop_device_t, dtop_message_t, int, int));
|
|
|
|
int dtop_locator_handler __P((dtop_device_t, dtop_message_t, int, int));
|
|
|
|
int dtop_keyboard_handler __P((dtop_device_t, dtop_message_t, int, int));
|
|
|
|
int dtopparam __P((struct tty *, struct termios *));
|
|
|
|
void dtopstart __P((struct tty *));
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* lk201 keyboard divisions and up/down mode key bitmap.
|
|
|
|
*/
|
|
|
|
#define NUMDIVS 14
|
1998-11-13 04:59:51 +03:00
|
|
|
/*
|
|
|
|
* NOTE: the right shift key was included in division 8 with the up/down
|
|
|
|
* arrow keys for some odd reason. This causes a problem for
|
|
|
|
* the X11R5 server code, as it controls the key modes by divisions.
|
|
|
|
* The fix is to adjust the division table by changing the start
|
|
|
|
* of division 6 (which includes the shift and control keys) to
|
|
|
|
* include the right shift [0xab] and changing the end of division
|
|
|
|
* 8 to be the the up arrow [0xaa]. The initial key mode is also
|
|
|
|
* modified to include the right shift key as up/down.
|
|
|
|
*/
|
|
|
|
static u_char divbeg[NUMDIVS] = {0xbf, 0x91, 0xbc, 0xbd, 0xb0, 0xab, 0xa6,
|
1993-10-12 06:22:19 +03:00
|
|
|
0xa9, 0x88, 0x56, 0x63, 0x6f, 0x7b, 0x7e};
|
|
|
|
static u_char divend[NUMDIVS] = {0xff, 0xa5, 0xbc, 0xbe, 0xb2, 0xaf, 0xa8,
|
1998-11-13 04:59:51 +03:00
|
|
|
0xaa, 0x90, 0x62, 0x6e, 0x7a, 0x7d, 0x87};
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Initial defaults, groups 5 and 6 are up/down
|
|
|
|
*/
|
1998-11-13 04:59:51 +03:00
|
|
|
static u_long keymodes[8] = {0, 0, 0, 0, 0, 0x0003e800, 0, 0};
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
|
|
|
|
|
1996-05-19 05:12:40 +04:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
1995-08-10 08:21:35 +04:00
|
|
|
* Autoconfiguration data for config.new.
|
|
|
|
* Use the statically-allocated softc until old autoconfig code and
|
|
|
|
* config.old are completely gone.
|
1999-04-24 12:01:01 +04:00
|
|
|
*
|
1993-10-12 06:22:19 +03:00
|
|
|
*/
|
1997-07-21 09:39:02 +04:00
|
|
|
int dtopmatch __P((struct device * parent, struct cfdata *match, void *aux));
|
1995-08-10 08:21:35 +04:00
|
|
|
void dtopattach __P((struct device *parent, struct device *self, void *aux));
|
1995-09-26 00:12:33 +03:00
|
|
|
int dtopintr __P((void *sc));
|
1995-08-10 08:21:35 +04:00
|
|
|
|
1996-03-17 04:38:52 +03:00
|
|
|
struct cfattach dtop_ca = {
|
|
|
|
sizeof(struct dtop_softc), dtopmatch, dtopattach
|
|
|
|
};
|
|
|
|
|
1998-01-12 23:04:24 +03:00
|
|
|
extern struct cfdriver dtop_cd;
|
1996-05-19 05:12:40 +04:00
|
|
|
|
1995-08-10 08:21:35 +04:00
|
|
|
/*
|
1996-05-19 05:12:40 +04:00
|
|
|
* Match driver based on name
|
1995-08-10 08:21:35 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
dtopmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
1997-07-21 09:39:02 +04:00
|
|
|
struct cfdata *match;
|
1995-08-10 08:21:35 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
1996-05-29 10:15:40 +04:00
|
|
|
struct ioasicdev_attach_args *d = aux;
|
1995-08-10 08:21:35 +04:00
|
|
|
|
1996-05-29 10:15:40 +04:00
|
|
|
if (badaddr((caddr_t)(d->iada_addr), 2))
|
1996-02-13 21:23:46 +03:00
|
|
|
return (0);
|
1995-08-10 08:21:35 +04:00
|
|
|
|
1996-05-29 10:15:40 +04:00
|
|
|
if (strcmp(d->iada_modname, "dtop") != 0)
|
1995-08-10 08:21:35 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dtopattach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct ioasicdev_attach_args *d = aux;
|
1996-02-13 21:23:46 +03:00
|
|
|
struct dtop_softc *sc = (struct dtop_softc*) self;
|
|
|
|
int i;
|
1995-08-10 08:21:35 +04:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1997-06-22 11:42:25 +04:00
|
|
|
sc->poll = (poll_reg_t)MIPS_PHYS_TO_KSEG1(XINE_REG_INTR);
|
1996-05-29 10:15:40 +04:00
|
|
|
sc->data = (data_reg_t)d->iada_addr;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
for (i = 0; i < DTOP_MAX_DEVICES; i++)
|
1996-02-13 21:23:46 +03:00
|
|
|
sc->device[i].handler = dtop_null_device_handler;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/* a lot more needed here, fornow: */
|
1996-02-13 21:23:46 +03:00
|
|
|
sc->device[DTOP_DEVICE_NO(0x6a)].handler = dtop_locator_handler;
|
|
|
|
sc->device[DTOP_DEVICE_NO(0x6c)].handler = dtop_keyboard_handler;
|
|
|
|
sc->device[DTOP_DEVICE_NO(0x6c)].status.keyboard.k_ar_state =
|
1993-10-12 06:22:19 +03:00
|
|
|
K_AR_IDLE;
|
|
|
|
|
1996-02-13 21:23:46 +03:00
|
|
|
sc->probed_once = 1;
|
|
|
|
|
|
|
|
/* tie pseudo-slot to device */
|
1996-05-29 10:15:40 +04:00
|
|
|
ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_NONE, dtopintr, sc);
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
1996-02-13 21:23:46 +03:00
|
|
|
|
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
dtopopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit;
|
1993-10-12 06:22:19 +03:00
|
|
|
int s, error = 0;
|
1997-11-09 00:55:05 +03:00
|
|
|
int firstopen = 0;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
unit = minor(dev);
|
1996-03-17 04:38:52 +03:00
|
|
|
if (unit >= dtop_cd.cd_ndevs)
|
1993-10-12 06:22:19 +03:00
|
|
|
return (ENXIO);
|
1996-02-13 21:23:46 +03:00
|
|
|
tp = DTOP_TTY(unit);
|
1996-06-16 20:50:56 +04:00
|
|
|
if (tp == NULL) {
|
1996-02-13 21:23:46 +03:00
|
|
|
tp = DTOP_TTY(unit) = ttymalloc();
|
1996-06-16 20:50:56 +04:00
|
|
|
tty_attach(tp);
|
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
tp->t_oproc = dtopstart;
|
|
|
|
tp->t_param = dtopparam;
|
|
|
|
tp->t_dev = dev;
|
1998-03-22 10:04:13 +03:00
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
|
1993-10-12 06:22:19 +03:00
|
|
|
ttychars(tp);
|
1998-03-22 10:04:13 +03:00
|
|
|
firstopen = 1;
|
1993-10-12 06:22:19 +03:00
|
|
|
if (tp->t_ispeed == 0) {
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
|
|
|
|
}
|
|
|
|
(void) dtopparam(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
|
|
|
} else if ((tp->t_state & TS_XCLUDE) && curproc->p_ucred->cr_uid != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
s = spltty();
|
|
|
|
while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) &&
|
|
|
|
!(tp->t_state & TS_CARR_ON)) {
|
1998-03-22 10:04:13 +03:00
|
|
|
tp->t_wopen++;
|
|
|
|
error = ttysleep(tp, (caddr_t)&tp->t_rawq,
|
|
|
|
TTIPRI | PCATCH, ttopen, 0);
|
|
|
|
tp->t_wopen--;
|
|
|
|
if (error != 0)
|
1993-10-12 06:22:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
error = (*linesw[tp->t_line].l_open)(dev, tp);
|
1997-11-09 00:55:05 +03:00
|
|
|
|
1998-03-24 03:23:55 +03:00
|
|
|
#if (RASTERCONSOLE > 0) && defined(RCONS_BRAINDAMAGE)
|
1997-11-09 00:55:05 +03:00
|
|
|
/* handle raster console specially */
|
|
|
|
if (tp == DTOP_TTY(0) && firstopen) {
|
|
|
|
extern struct tty *fbconstty;
|
|
|
|
tp->t_winsize = fbconstty->t_winsize;
|
|
|
|
}
|
1999-04-24 12:01:01 +04:00
|
|
|
#endif /* HAVE_RCONS */
|
1997-11-09 00:55:05 +03:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
dtopclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
unit = minor(dev);
|
1996-02-13 21:23:46 +03:00
|
|
|
tp = DTOP_TTY(unit);
|
1993-10-12 06:22:19 +03:00
|
|
|
(*linesw[tp->t_line].l_close)(tp, flag);
|
|
|
|
return (ttyclose(tp));
|
|
|
|
}
|
|
|
|
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
dtopread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1996-02-13 21:23:46 +03:00
|
|
|
tp = DTOP_TTY(minor(dev));
|
1993-10-12 06:22:19 +03:00
|
|
|
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
dtopwrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1996-02-13 21:23:46 +03:00
|
|
|
tp = DTOP_TTY(minor(dev));
|
1993-10-12 06:22:19 +03:00
|
|
|
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
1995-04-21 05:24:26 +04:00
|
|
|
struct tty *
|
|
|
|
dtoptty(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
1996-02-13 21:23:46 +03:00
|
|
|
struct tty *tp = DTOP_TTY(minor(dev));
|
1995-04-21 05:24:26 +04:00
|
|
|
return (tp);
|
|
|
|
}
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*ARGSUSED*/
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
1994-05-27 12:39:00 +04:00
|
|
|
dtopioctl(dev, cmd, data, flag, p)
|
1993-10-12 06:22:19 +03:00
|
|
|
dev_t dev;
|
1996-05-19 05:12:40 +04:00
|
|
|
u_long cmd;
|
1993-10-12 06:22:19 +03:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
1994-05-27 12:39:00 +04:00
|
|
|
struct proc *p;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit = minor(dev);
|
1993-10-12 06:22:19 +03:00
|
|
|
int error;
|
|
|
|
|
1996-02-13 21:23:46 +03:00
|
|
|
tp = DTOP_TTY(unit);
|
1994-05-27 12:39:00 +04:00
|
|
|
error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (error >= 0)
|
|
|
|
return (error);
|
1994-05-27 12:57:32 +04:00
|
|
|
error = ttioctl(tp, cmd, data, flag, p);
|
1993-10-12 06:22:19 +03:00
|
|
|
if (error >= 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case TIOCSBRK:
|
|
|
|
ttyoutput(0, tp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCCBRK:
|
|
|
|
ttyoutput(0, tp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMGET:
|
|
|
|
*(int *)data = DML_DTR | DML_DSR | DML_CAR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt routine
|
|
|
|
*/
|
1995-09-26 00:12:33 +03:00
|
|
|
int
|
|
|
|
dtopintr(sc)
|
|
|
|
void *sc;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
|
|
|
dtop_message msg;
|
|
|
|
int devno;
|
|
|
|
dtop_softc_t dtop;
|
1998-03-24 03:23:55 +03:00
|
|
|
int s;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1995-09-26 00:12:33 +03:00
|
|
|
dtop = sc;
|
1998-03-24 03:23:55 +03:00
|
|
|
s = spltty();
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
if (dtop_get_packet(dtop, &msg) < 0) {
|
1998-03-24 03:23:55 +03:00
|
|
|
#if defined(DIAGNOSTIC) || defined (DEBUG) || defined(RCONS_DEBUG)
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("dtop: overrun (or stray)\n");
|
1993-10-12 06:22:19 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Ugh! The most common occurrence of a data overrun is upon a
|
|
|
|
* key press and the result is a software generated "stuck key".
|
|
|
|
* All I can think to do is fake an "all keys up" whenever a
|
|
|
|
* data overrun occurs.
|
|
|
|
*/
|
|
|
|
msg.src_address = 0x6c;
|
|
|
|
msg.code.val.len = 1;
|
|
|
|
msg.body[0] = DTOP_KBD_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If not probed yet, just throw the data away.
|
|
|
|
*/
|
|
|
|
if (!dtop->probed_once)
|
1998-03-24 03:23:55 +03:00
|
|
|
goto out;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
devno = DTOP_DEVICE_NO(msg.src_address);
|
|
|
|
if (devno < 0 || devno > 15)
|
1998-03-24 03:23:55 +03:00
|
|
|
goto out;
|
1996-05-19 05:12:40 +04:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
(void) (*dtop->device[devno].handler)
|
|
|
|
(&dtop->device[devno].status, &msg,
|
|
|
|
DTOP_EVENT_RECEIVE_PACKET, 0);
|
1998-03-24 03:23:55 +03:00
|
|
|
out:
|
|
|
|
splx(s);
|
1996-05-19 05:12:40 +04:00
|
|
|
return(0);
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dtopstart(tp)
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
|
|
|
|
goto out;
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
wakeup((caddr_t)&tp->t_outq);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
|
|
|
if (tp->t_outq.c_cc == 0)
|
|
|
|
goto out;
|
1998-03-24 03:23:55 +03:00
|
|
|
#ifdef RCONS_BRAINDAMAGE
|
1993-10-12 06:22:19 +03:00
|
|
|
/* handle console specially */
|
1996-02-13 21:23:46 +03:00
|
|
|
if (tp == DTOP_TTY(0)) {
|
1999-04-24 12:01:01 +04:00
|
|
|
int cc;
|
1998-03-24 03:23:55 +03:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
while (tp->t_outq.c_cc > 0) {
|
|
|
|
cc = getc(&tp->t_outq) & 0x7f;
|
|
|
|
cnputc(cc);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* After we flush the output queue we may need to wake
|
|
|
|
* up the process that made the output.
|
|
|
|
*/
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
tp->t_state &= ~TS_ASLEEP;
|
|
|
|
wakeup((caddr_t)&tp->t_outq);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
|
|
|
}
|
1998-03-24 03:23:55 +03:00
|
|
|
#endif /* RCONS_BRAINDAMAGE */
|
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
out:
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dtopKBDPutc(dev, c)
|
|
|
|
dev_t dev;
|
|
|
|
int c;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
int i;
|
1993-10-12 06:22:19 +03:00
|
|
|
static int param = 0, cmd, mod, typ;
|
|
|
|
static u_char parms[2];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emulate the lk201 command codes.
|
|
|
|
*/
|
|
|
|
if (param == 0) {
|
|
|
|
typ = (c & 0x1);
|
|
|
|
cmd = ((c >> 3) & 0xf);
|
|
|
|
mod = ((c >> 1) & 0x3);
|
|
|
|
} else
|
|
|
|
parms[param - 1] = (c & 0x7f);
|
|
|
|
if (c & 0x80) {
|
|
|
|
if (typ) {
|
|
|
|
/*
|
|
|
|
* A peripheral command code. Someday this driver
|
|
|
|
* should know how to send commands to the lk501,
|
|
|
|
* but until then this is all essentially a no-op.
|
|
|
|
*/
|
|
|
|
;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Set modes. These have to be emulated in software.
|
|
|
|
*/
|
|
|
|
if (cmd > 0 && cmd < 15) {
|
|
|
|
cmd--;
|
|
|
|
if (mod & 0x2)
|
|
|
|
for (i = divbeg[cmd]; i <= divend[cmd]; i++)
|
|
|
|
keymodes[i >> 5] |=
|
|
|
|
(1 << (i & 0x1f));
|
|
|
|
else
|
|
|
|
for (i = divbeg[cmd]; i <= divend[cmd]; i++)
|
|
|
|
keymodes[i >> 5] &=
|
|
|
|
~(1 << (i & 0x1f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
param = 0;
|
|
|
|
} else if (++param > 2)
|
|
|
|
param = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a packet off dtop interface
|
|
|
|
* A packet MUST be there, this is not checked for.
|
|
|
|
*/
|
|
|
|
#define DTOP_ESC_CHAR 0xf8
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
dtop_escape(c)
|
1996-05-19 05:12:40 +04:00
|
|
|
int c;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
|
|
|
/* I donno much about this stuff.. */
|
|
|
|
switch (c) {
|
|
|
|
case 0xe8: return (0xf8);
|
|
|
|
case 0xe9: return (0xf9);
|
|
|
|
case 0xea: return (0xfa);
|
|
|
|
case 0xeb: return (0xfb);
|
1996-10-13 07:39:27 +04:00
|
|
|
default: /* printf("{esc %x}", c); */
|
1993-10-12 06:22:19 +03:00
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
1993-10-12 06:22:19 +03:00
|
|
|
dtop_get_packet(dtop, pkt)
|
|
|
|
dtop_softc_t dtop;
|
|
|
|
dtop_message_t pkt;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
poll_reg_t poll;
|
|
|
|
data_reg_t data;
|
|
|
|
int max, i, len;
|
|
|
|
unsigned char c;
|
1998-10-29 07:54:20 +03:00
|
|
|
int state;
|
|
|
|
int escaped;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
poll = dtop->poll;
|
|
|
|
data = dtop->data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The interface does not handle us the first byte,
|
|
|
|
* which is our address and cannot ever be anything
|
|
|
|
* else but 0x50. This is a good thing, it makes
|
|
|
|
* the average packet exactly one word long, too.
|
|
|
|
*/
|
1998-10-29 07:54:20 +03:00
|
|
|
state = 0; /* input packet state */
|
|
|
|
escaped = 0; /* getting escaped code */
|
|
|
|
len = 0; /* packet data length */
|
|
|
|
i = 0; /* packet data index */
|
|
|
|
while (1) {
|
|
|
|
for (max = 0; (max < DTOP_MAX_POLL) && !DTOP_RX_AVAIL(poll);
|
|
|
|
max++)
|
1993-10-12 06:22:19 +03:00
|
|
|
DELAY(1);
|
1998-10-29 07:54:20 +03:00
|
|
|
if (max == DTOP_MAX_POLL) {
|
|
|
|
++dtop->bad_pkts;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
c = DTOP_GET_BYTE(data);
|
|
|
|
if (escaped) {
|
|
|
|
c = dtop_escape(c);
|
|
|
|
if (c == 'O') {
|
|
|
|
++dtop->bad_pkts;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
escaped = 0;
|
1993-10-12 06:22:19 +03:00
|
|
|
} else {
|
|
|
|
c = DTOP_GET_BYTE(data);
|
1998-10-29 07:54:20 +03:00
|
|
|
if (c == DTOP_ESC_CHAR) {
|
|
|
|
escaped = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state == 0) {
|
|
|
|
pkt->src_address = c;
|
|
|
|
state = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (state == 1) {
|
|
|
|
pkt->code.bits = c;
|
|
|
|
state = 2;
|
|
|
|
len = pkt->code.val.len + 1;
|
|
|
|
continue;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
pkt->body[i] = c;
|
1998-10-29 07:54:20 +03:00
|
|
|
++i;
|
|
|
|
if (i >= len)
|
|
|
|
break;
|
1993-10-12 06:22:19 +03:00
|
|
|
}
|
|
|
|
return (len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a keyboard char for the console
|
|
|
|
*/
|
1996-05-19 05:12:40 +04:00
|
|
|
int
|
|
|
|
dtopKBDGetc(dev)
|
|
|
|
dev_t dev;
|
1993-10-12 06:22:19 +03:00
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
int c;
|
1993-10-12 06:22:19 +03:00
|
|
|
dtop_softc_t dtop;
|
1997-07-19 16:00:10 +04:00
|
|
|
int s;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
1996-03-17 04:38:52 +03:00
|
|
|
dtop = dtop_cd.cd_devs[0];
|
1997-07-19 16:00:10 +04:00
|
|
|
s = spltty();
|
1993-10-12 06:22:19 +03:00
|
|
|
again:
|
|
|
|
c = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now check keyboard
|
|
|
|
*/
|
|
|
|
if (DTOP_RX_AVAIL(dtop->poll)) {
|
|
|
|
|
|
|
|
dtop_message msg;
|
|
|
|
struct dtop_ds *ds;
|
|
|
|
|
|
|
|
if (dtop_get_packet(dtop, &msg) >= 0) {
|
|
|
|
|
|
|
|
ds = &dtop->device[DTOP_DEVICE_NO(msg.src_address)];
|
|
|
|
if (ds->handler == dtop_keyboard_handler) {
|
|
|
|
|
|
|
|
c = dtop_keyboard_handler(
|
|
|
|
&ds->status, &msg,
|
|
|
|
DTOP_EVENT_RECEIVE_PACKET, -1);
|
|
|
|
|
1997-07-19 16:00:10 +04:00
|
|
|
|
|
|
|
if (c > 0) {
|
|
|
|
splx(s);
|
|
|
|
return c;
|
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
c = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == -1) {
|
|
|
|
DELAY(100);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
1997-07-19 16:00:10 +04:00
|
|
|
splx(s);
|
1993-10-12 06:22:19 +03:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dtopparam(tp, t)
|
|
|
|
struct tty *tp;
|
|
|
|
struct termios *t;
|
|
|
|
{
|
|
|
|
if (tp->t_ispeed == 0)
|
|
|
|
ttymodem(tp, 0);
|
|
|
|
else
|
|
|
|
/* called too early to invoke ttymodem, sigh */
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
|
|
|
return (0);
|
|
|
|
}
|
1999-04-24 12:01:01 +04:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Stop output on a line.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
1996-09-02 10:43:16 +04:00
|
|
|
void
|
1993-10-12 06:22:19 +03:00
|
|
|
dtopstop(tp, flag)
|
1999-04-24 12:01:01 +04:00
|
|
|
struct tty *tp;
|
1993-10-12 06:22:19 +03:00
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (tp->t_state & TS_BUSY) {
|
|
|
|
if (!(tp->t_state & TS_TTSTOP))
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default handler function
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dtop_null_device_handler(dev, msg, event, outc)
|
|
|
|
dtop_device_t dev;
|
|
|
|
dtop_message_t msg;
|
|
|
|
int event;
|
|
|
|
int outc;
|
|
|
|
{
|
|
|
|
/* See if the message was to the default address (powerup) */
|
|
|
|
|
|
|
|
/* Uhmm, donno how to handle this. Drop it */
|
|
|
|
if (event == DTOP_EVENT_RECEIVE_PACKET)
|
|
|
|
dev->unknown_report = *msg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handler for locator devices (mice)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dtop_locator_handler(dev, msg, event, outc)
|
|
|
|
dtop_device_t dev;
|
|
|
|
dtop_message_t msg;
|
|
|
|
int event;
|
|
|
|
int outc;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
unsigned short buttons;
|
|
|
|
short coord;
|
|
|
|
int moved = 0;
|
1993-10-12 06:22:19 +03:00
|
|
|
static MouseReport currentRep;
|
1999-04-24 12:01:01 +04:00
|
|
|
MouseReport *mrp = ¤tRep;
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
if (dtopMouseButtons) {
|
|
|
|
mrp->state = 0;
|
|
|
|
/*
|
|
|
|
* Do the position first
|
|
|
|
*/
|
|
|
|
coord = GET_SHORT(msg->body[2], msg->body[3]);
|
|
|
|
if (coord < 0) {
|
|
|
|
coord = -coord;
|
|
|
|
moved = 1;
|
|
|
|
} else if (coord > 0) {
|
|
|
|
mrp->state |= MOUSE_X_SIGN;
|
|
|
|
moved = 1;
|
|
|
|
}
|
|
|
|
mrp->dx = (coord & 0x1f);
|
|
|
|
coord = GET_SHORT(msg->body[4], msg->body[5]);
|
|
|
|
if (coord < 0) {
|
|
|
|
coord = -coord;
|
|
|
|
moved = 1;
|
|
|
|
} else if (coord > 0) {
|
|
|
|
mrp->state |= MOUSE_Y_SIGN;
|
|
|
|
moved = 1;
|
|
|
|
}
|
|
|
|
mrp->dy = (coord & 0x1f);
|
1999-04-24 12:01:01 +04:00
|
|
|
|
1993-10-12 06:22:19 +03:00
|
|
|
/*
|
|
|
|
* Time for the buttons now
|
|
|
|
* Shuffle button bits around to serial mouse order.
|
|
|
|
*/
|
|
|
|
buttons = GET_SHORT(msg->body[0], msg->body[1]);
|
|
|
|
mrp->state |= (((buttons >> 1) & 0x3) | ((buttons << 2) & 0x4));
|
|
|
|
if (moved)
|
|
|
|
(*dtopMouseEvent)(mrp);
|
|
|
|
(*dtopMouseButtons)(mrp);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handler for keyboard devices
|
|
|
|
* Special case: outc set for recv packet means
|
|
|
|
* we are inside the kernel debugger
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
dtop_keyboard_handler(dev, msg, event, outc)
|
|
|
|
dtop_device_t dev;
|
|
|
|
dtop_message_t msg;
|
|
|
|
int event;
|
|
|
|
int outc;
|
|
|
|
{
|
1999-04-24 12:01:01 +04:00
|
|
|
u_char *ls, *le, *ns, *ne;
|
1993-10-12 06:22:19 +03:00
|
|
|
u_char save[11], retc;
|
|
|
|
int msg_len, c, s;
|
1999-03-22 06:25:29 +03:00
|
|
|
char *cp;
|
1998-03-24 03:23:55 +03:00
|
|
|
#ifdef RCONS_BRAINDAMAGE
|
1996-02-13 21:23:46 +03:00
|
|
|
struct tty *tp = DTOP_TTY(0);
|
1998-03-24 03:23:55 +03:00
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fiddle about emulating an lk201 keyboard. The lk501
|
|
|
|
* designers carefully ensured that keyboard handlers could be
|
|
|
|
* stateless, then we turn around and use lots of state to
|
|
|
|
* emulate the stateful lk201, since the X11R5 X servers
|
|
|
|
* only know about the lk201... (oh well)
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Turn off any autorepeat timeout.
|
|
|
|
*/
|
|
|
|
s = splhigh();
|
|
|
|
if (dev->keyboard.k_ar_state != K_AR_IDLE) {
|
|
|
|
dev->keyboard.k_ar_state = K_AR_IDLE;
|
|
|
|
untimeout(dtop_keyboard_repeat, (void *)dev);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
msg_len = msg->code.val.len;
|
|
|
|
|
|
|
|
/* Check for errors */
|
|
|
|
c = msg->body[0];
|
|
|
|
if ((c < DTOP_KBD_KEY_MIN) && (c != DTOP_KBD_EMPTY)) {
|
1996-10-13 07:39:27 +04:00
|
|
|
printf("Keyboard error: %x %x %x..\n", msg_len, c, msg->body[1]);
|
1993-10-12 06:22:19 +03:00
|
|
|
#ifdef notdef
|
|
|
|
if (c != DTOP_KBD_OUT_ERR) return -1;
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Fake an "all ups" to avoid the stuck key syndrome.
|
|
|
|
*/
|
|
|
|
c = msg->body[0] = DTOP_KBD_EMPTY;
|
|
|
|
msg_len = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->keyboard.last_msec = TO_MS(time);
|
|
|
|
/*
|
|
|
|
* To make things readable, do a first pass cancelling out
|
|
|
|
* all keys that are still pressed, and a second one generating
|
|
|
|
* events. While generating events, do the upstrokes first
|
|
|
|
* from oldest to youngest, then the downstrokes from oldest
|
|
|
|
* to youngest. This copes with lost packets and provides
|
|
|
|
* a reasonable model even if scans are too slow.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* make a copy of new state first */
|
|
|
|
if (msg_len == 1)
|
|
|
|
save[0] = msg->body[0];
|
|
|
|
else if (msg_len > 0)
|
|
|
|
bcopy(msg->body, save, msg_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel out any keys in both the last and current message as
|
|
|
|
* they are unchanged.
|
|
|
|
*/
|
|
|
|
if (msg_len > 0 && dev->keyboard.last_codes_count > 0) {
|
|
|
|
ls = dev->keyboard.last_codes;
|
1996-05-19 05:12:40 +04:00
|
|
|
le = &dev->keyboard.last_codes[ ((u_int)dev->keyboard.
|
|
|
|
last_codes_count) ];
|
1993-10-12 06:22:19 +03:00
|
|
|
ne = &msg->body[msg_len];
|
|
|
|
for (; ls < le; ls++) {
|
|
|
|
for (ns = msg->body; ns < ne; ns++)
|
|
|
|
if (*ls == *ns) {
|
|
|
|
*ls = *ns = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now generate all upstrokes
|
|
|
|
*/
|
|
|
|
le = dev->keyboard.last_codes;
|
|
|
|
ls = &dev->keyboard.last_codes[dev->keyboard.last_codes_count - 1];
|
|
|
|
for ( ; ls >= le; ls--)
|
1996-05-19 05:12:40 +04:00
|
|
|
if ((c = *ls) != 0) {
|
1999-04-24 12:01:01 +04:00
|
|
|
(void) kbdMapChar(c);
|
1993-10-12 06:22:19 +03:00
|
|
|
|
|
|
|
if (outc == 0 && dtopDivertXInput &&
|
|
|
|
(keymodes[(c >> 5) & 0x7] & (1 << (c & 0x1f))))
|
|
|
|
(*dtopDivertXInput)(c);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* And finally the downstrokes
|
|
|
|
*/
|
|
|
|
ne = (char*)msg->body;
|
|
|
|
ns = (char*)&msg->body[msg_len - 1];
|
|
|
|
retc = 0;
|
|
|
|
for ( ; ns >= ne; ns--)
|
|
|
|
if (*ns) {
|
1999-03-22 06:25:29 +03:00
|
|
|
cp = kbdMapChar(*ns);
|
1997-11-23 21:20:11 +03:00
|
|
|
#ifdef DDB
|
|
|
|
if (*ns == LK_DO) {
|
|
|
|
spl0();
|
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
if (outc == 0) {
|
|
|
|
if (dtopDivertXInput) {
|
|
|
|
(*dtopDivertXInput)(*ns);
|
|
|
|
c = -1; /* consumed by X */
|
1999-03-22 06:25:29 +03:00
|
|
|
} else if (cp /*&& tp != NULL*/) {
|
|
|
|
for (; *cp; cp++) {
|
1998-03-24 03:23:55 +03:00
|
|
|
#if 0
|
1999-03-22 06:25:29 +03:00
|
|
|
(*linesw[tp->t_line].l_rint)(*cp, tp);
|
1998-03-24 03:23:55 +03:00
|
|
|
#else
|
1999-03-22 06:25:29 +03:00
|
|
|
rcons_input(0, *cp);
|
1998-03-24 03:23:55 +03:00
|
|
|
#endif
|
1999-03-22 06:25:29 +03:00
|
|
|
}
|
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
dev->keyboard.k_ar_state = K_AR_ACTIVE;
|
|
|
|
}
|
1999-04-24 12:01:01 +04:00
|
|
|
/*
|
|
|
|
* return the related keycode anyways
|
1999-03-22 06:25:29 +03:00
|
|
|
* XXX when in debugger, don't return multi-char sequences
|
|
|
|
*/
|
|
|
|
if (cp && (cp[1] == '\0') &&(retc == 0))
|
1993-10-12 06:22:19 +03:00
|
|
|
retc = c;
|
|
|
|
}
|
|
|
|
outc = retc;
|
|
|
|
/* install new scan state */
|
|
|
|
if (msg_len == 1)
|
|
|
|
dev->keyboard.last_codes[0] = save[0];
|
|
|
|
else if (msg_len > 0)
|
|
|
|
bcopy(save, dev->keyboard.last_codes, msg_len);
|
|
|
|
dev->keyboard.last_codes_count = msg_len;
|
|
|
|
if (dev->keyboard.k_ar_state == K_AR_ACTIVE)
|
|
|
|
timeout(dtop_keyboard_repeat, (void *)dev, hz / 2);
|
|
|
|
return (outc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do an autorepeat as required.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dtop_keyboard_repeat(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
dtop_device_t dev = (dtop_device_t)arg;
|
1999-04-24 12:01:01 +04:00
|
|
|
int i, c;
|
1999-03-22 06:25:29 +03:00
|
|
|
char *cp;
|
1999-04-24 12:01:01 +04:00
|
|
|
|
1998-03-24 03:23:55 +03:00
|
|
|
#if 0
|
1996-02-13 21:23:46 +03:00
|
|
|
struct tty *tp = DTOP_TTY(0);
|
1998-03-24 03:23:55 +03:00
|
|
|
#endif
|
1993-10-12 06:22:19 +03:00
|
|
|
int s = spltty(), gotone = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->keyboard.last_codes_count; i++) {
|
|
|
|
c = (int)dev->keyboard.last_codes[i];
|
|
|
|
if (c != DTOP_KBD_EMPTY &&
|
|
|
|
(keymodes[(c >> 5) & 0x7] & (1 << (c & 0x1f))) == 0) {
|
|
|
|
dev->keyboard.k_ar_state = K_AR_TRIGGER;
|
|
|
|
if (dtopDivertXInput) {
|
|
|
|
(*dtopDivertXInput)(KEY_REPEAT);
|
|
|
|
gotone = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-03-22 06:25:29 +03:00
|
|
|
if ((cp = kbdMapChar(KEY_REPEAT)) != NULL) {
|
|
|
|
for (; *cp; cp++) {
|
1998-03-24 03:23:55 +03:00
|
|
|
#if 0
|
1999-03-22 06:25:29 +03:00
|
|
|
(*linesw[tp->t_line].l_rint)(*cp, tp);
|
1998-03-24 03:23:55 +03:00
|
|
|
#else
|
1999-03-22 06:25:29 +03:00
|
|
|
rcons_input(0, *cp);
|
1998-03-24 03:23:55 +03:00
|
|
|
#endif
|
1999-03-22 06:25:29 +03:00
|
|
|
}
|
1993-10-12 06:22:19 +03:00
|
|
|
gotone = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (gotone)
|
|
|
|
timeout(dtop_keyboard_repeat, arg, hz / 20);
|
|
|
|
else
|
|
|
|
dev->keyboard.k_ar_state = K_AR_IDLE;
|
|
|
|
splx(s);
|
|
|
|
}
|