1998-07-06 06:40:42 +04:00
|
|
|
/* $NetBSD: kbd.c,v 1.23 1998/07/06 02:40:43 mark Exp $ */
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
/*
|
1997-10-14 23:35:34 +04:00
|
|
|
* Copyright (c) 1994-1997 Mark Brinicombe.
|
1996-02-01 02:14:53 +03:00
|
|
|
* Copyright (c) 1994 Brini.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software written for Brini by Mark Brinicombe
|
|
|
|
*
|
|
|
|
* 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:
|
1997-10-14 23:35:34 +04:00
|
|
|
* This product includes software developed by Mark Brinicombe.
|
1996-02-01 02:14:53 +03:00
|
|
|
* 4. The name of the company nor the name of the author may be used to
|
|
|
|
* endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
1997-10-14 23:35:34 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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,
|
1996-02-01 02:14:53 +03:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* RiscBSD kernel project
|
|
|
|
*
|
|
|
|
* kbd.c
|
|
|
|
*
|
|
|
|
* Keyboard driver functions
|
|
|
|
*
|
|
|
|
* Created : 09/10/94
|
|
|
|
*/
|
1998-07-06 06:40:42 +04:00
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
1998-07-06 06:40:42 +04:00
|
|
|
#include "opt_pmap_debug.h"
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/time.h>
|
1996-10-15 23:47:04 +04:00
|
|
|
#include <sys/poll.h>
|
1996-02-01 02:14:53 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#include <machine/bus.h>
|
1996-02-01 02:14:53 +03:00
|
|
|
#include <machine/kbd.h>
|
1997-01-28 07:55:15 +03:00
|
|
|
#include <machine/conf.h>
|
1997-10-14 23:35:34 +04:00
|
|
|
#include <arm32/dev/kbdvar.h>
|
1996-02-01 02:14:53 +03:00
|
|
|
#include "vt.h"
|
|
|
|
#include "kbd.h"
|
|
|
|
|
|
|
|
/* Special keycodes */
|
|
|
|
|
|
|
|
#define KEYCODE_UP 0x100
|
|
|
|
#define KEYCODE_DOWN 0x101
|
|
|
|
#define KEYCODE_LEFT 0x102
|
|
|
|
#define KEYCODE_RIGHT 0x103
|
|
|
|
#define KEYCODE_PGUP 0x104
|
|
|
|
#define KEYCODE_PGDN 0x105
|
|
|
|
#define KEYCODE_INSERT 0x108
|
|
|
|
#define KEYCODE_DELETE 0x109
|
|
|
|
#define KEYCODE_HOME 0x10a
|
|
|
|
#define KEYCODE_END 0x10b
|
|
|
|
|
|
|
|
/* Key modifiers flags */
|
|
|
|
|
|
|
|
#define MODIFIER_CTRL 0x01
|
|
|
|
#define MODIFIER_SHIFT 0x02
|
|
|
|
#define MODIFIER_ALT 0x04
|
|
|
|
#define MODIFIER_MASK 0x07
|
|
|
|
|
|
|
|
#define MODIFIER_CAPS 0x20
|
|
|
|
#define MODIFIER_NUM 0x10
|
|
|
|
#define MODIFIER_SCROLL 0x08
|
|
|
|
#define MODIFIER_LOCK_MASK 0x38
|
|
|
|
|
|
|
|
#define MODIFIER_CAPSLOCK 0x40
|
|
|
|
#define MODIFIER_NORETURN 0x80
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
/* Keyboard variables */
|
1996-02-01 02:14:53 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
struct kbd_softc *console_kbd = NULL;
|
|
|
|
|
1996-02-01 02:14:53 +03:00
|
|
|
#define RAWKBD_BSIZE 128
|
|
|
|
|
|
|
|
static int autorepeatkey = -1;
|
|
|
|
static struct kbd_autorepeat kbdautorepeat = { 5, 20 };
|
1996-03-08 19:28:54 +03:00
|
|
|
static int rawkbd_device = 0;
|
|
|
|
int modifiers = 0;
|
1996-02-01 02:14:53 +03:00
|
|
|
static int kbd_ack = 0;
|
|
|
|
static int kbd_resend = 0;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#ifdef PMAP_DEBUG
|
1996-02-01 02:14:53 +03:00
|
|
|
extern int pmap_debug_level;
|
1997-10-14 23:35:34 +04:00
|
|
|
#endif
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
#define KBDUNIT(u) (minor(u) / 2)
|
|
|
|
#define KBDFLAG(u) (minor(u) % 2)
|
|
|
|
|
|
|
|
#define KBDFLAG_RAWUNIT 0
|
|
|
|
#define KBDFLAG_CONUNIT 1
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
extern key_struct keys[];
|
|
|
|
extern key_struct E0keys[];
|
1996-05-06 04:35:05 +04:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* Local function prototypes */
|
1996-02-01 02:14:53 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
int kbdreset __P((struct kbd_softc *sc));
|
|
|
|
void kbd_flush_input __P((struct kbd_softc *sc));
|
|
|
|
int kbdcmd __P((struct kbd_softc *sc, u_char cmd));
|
|
|
|
void kbdsetleds __P((struct kbd_softc *sc, int leds));
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
int PollKeyboard __P((int));
|
|
|
|
int kbddecodekey __P((struct kbd_softc *, int));
|
1997-01-28 07:55:15 +03:00
|
|
|
int kbdintr __P((void *arg));
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
void autorepeatstart __P((void *));
|
|
|
|
void autorepeat __P((void *));
|
|
|
|
|
1996-06-04 02:20:32 +04:00
|
|
|
extern int physconkbd __P((int key));
|
|
|
|
extern void console_switch __P((u_int number));
|
1997-10-14 23:35:34 +04:00
|
|
|
/*extern int console_switchdown __P((void));
|
|
|
|
extern int console_switchup __P((void));*/
|
1996-06-04 02:20:32 +04:00
|
|
|
extern int console_unblank __P((void));
|
|
|
|
extern int console_scrollback __P((void));
|
|
|
|
extern int console_scrollforward __P((void));
|
1997-10-14 23:35:34 +04:00
|
|
|
#ifdef PMAP_DEBUG
|
1996-06-04 02:20:32 +04:00
|
|
|
extern void pmap_debug __P((int level));
|
1997-10-14 23:35:34 +04:00
|
|
|
#endif
|
1998-01-18 07:16:06 +03:00
|
|
|
extern void halt __P((void));
|
1996-03-17 04:16:48 +03:00
|
|
|
|
1998-01-13 05:09:58 +03:00
|
|
|
extern struct cfdriver kbd_cd;
|
1996-02-01 02:14:53 +03:00
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
/* keyboard commands */
|
|
|
|
|
|
|
|
#define KBC_RESET 0xFF /* reset the keyboard */
|
|
|
|
#define KBC_RESEND 0xFE /* request the keyboard resend the last byte */
|
|
|
|
#define KBC_SET_TMB 0xFA /* What is this one ? */
|
|
|
|
#define KBC_SETDEFAULT 0xF6 /* resets keyboard to its power-on defaults */
|
|
|
|
#define KBC_DISABLE 0xF5 /* as per KBC_SETDEFAULT, but also disable key scanning */
|
|
|
|
#define KBC_ENABLE 0xF4 /* enable key scanning */
|
|
|
|
#define KBC_TYPEMATIC 0xF3 /* set typematic rate and delay */
|
1997-10-14 23:35:34 +04:00
|
|
|
#define KBD_READID 0xF2 /* Read keyboard ID */
|
1996-05-06 04:35:05 +04:00
|
|
|
#define KBC_SETSCANTBL 0xF0 /* set scancode translation table */
|
|
|
|
#define KBC_SETLEDS 0xED /* set mode indicators (i.e. LEDs) */
|
|
|
|
#define KBC_ECHO 0xEE /* request an echo from the keyboard */
|
|
|
|
|
|
|
|
#define KBD_SETSCAN_2 0x02
|
|
|
|
#define KBD_SETSCAN_3 0x03
|
|
|
|
|
|
|
|
/* keyboard responses */
|
|
|
|
#define KBR_EXTENDED 0xE0 /* extended key sequence */
|
|
|
|
#define KBR_RESEND 0xFE /* needs resend of command */
|
|
|
|
#define KBR_ACK 0xFA /* received a valid command */
|
|
|
|
#define KBR_OVERRUN 0x00 /* flooded */
|
|
|
|
#define KBR_FAILURE 0xFD /* diagnosic failure */
|
|
|
|
#define KBR_BREAK 0xF0 /* break code prefix - sent on key release */
|
|
|
|
#define KBR_RSTDONE 0xAA /* reset complete */
|
|
|
|
#define KBR_ECHO 0xEE /* echo response */
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#define KBD_DATA 0
|
|
|
|
#define KBD_CR 1
|
|
|
|
#define KBD_STATUS 1
|
1996-02-01 02:14:53 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#define KBD_CR_ENABLE 0x08
|
|
|
|
#define KBD_CR_KDATAO 0x02
|
|
|
|
#define KBD_CR_KCLKO 0x01
|
1996-02-01 02:14:53 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#define KBD_ST_TXE 0x80
|
|
|
|
#define KBD_ST_TXB 0x40
|
|
|
|
#define KBD_ST_RXF 0x20
|
|
|
|
#define KBD_ST_RXB 0x10
|
|
|
|
#define KBD_ST_ENABLE 0x08
|
|
|
|
#define KBD_ST_RXPARITY 0x04
|
|
|
|
#define KBD_ST_KDATAI 0x02
|
|
|
|
#define KBD_ST_KCLKI 0x01
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
kbdopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct kbd_softc *sc;
|
|
|
|
int unit = KBDUNIT(dev);
|
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
if (unit >= kbd_cd.cd_ndevs)
|
1996-02-01 02:14:53 +03:00
|
|
|
return(ENXIO);
|
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
sc = kbd_cd.cd_devs[unit];
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
if (!sc) return(ENXIO);
|
|
|
|
|
|
|
|
switch (KBDFLAG(dev)) {
|
|
|
|
case KBDFLAG_RAWUNIT :
|
|
|
|
if (sc->sc_state & RAWKBD_OPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
sc->sc_state |= RAWKBD_OPEN;
|
|
|
|
if (clalloc(&sc->sc_q, RAWKBD_BSIZE, 0) == -1)
|
|
|
|
return(ENOMEM);
|
|
|
|
sc->sc_proc = p;
|
|
|
|
rawkbd_device = 1;
|
|
|
|
break;
|
|
|
|
case KBDFLAG_CONUNIT :
|
|
|
|
if (sc->sc_state & KBD_OPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
sc->sc_state |= KBD_OPEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Kill any active autorepeat */
|
|
|
|
|
|
|
|
untimeout(autorepeatstart, &autorepeatkey);
|
|
|
|
untimeout(autorepeat, &autorepeatkey);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
kbdclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int unit = KBDUNIT(dev);
|
1996-03-17 04:16:48 +03:00
|
|
|
struct kbd_softc *sc = kbd_cd.cd_devs[unit];
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
switch (KBDFLAG(dev)) {
|
|
|
|
case KBDFLAG_RAWUNIT :
|
|
|
|
if (!(sc->sc_state & RAWKBD_OPEN))
|
|
|
|
return(EINVAL);
|
|
|
|
sc->sc_state &= ~RAWKBD_OPEN;
|
|
|
|
clfree(&sc->sc_q);
|
|
|
|
sc->sc_proc = NULL;
|
|
|
|
rawkbd_device = 0;
|
|
|
|
break;
|
|
|
|
case KBDFLAG_CONUNIT :
|
|
|
|
if (!(sc->sc_state & KBD_OPEN))
|
|
|
|
return(EINVAL);
|
|
|
|
sc->sc_state &= ~KBD_OPEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
kbdread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct kbd_softc *sc = kbd_cd.cd_devs[KBDUNIT(dev)];
|
1996-02-01 02:14:53 +03:00
|
|
|
int s;
|
|
|
|
int error = 0;
|
|
|
|
size_t length;
|
|
|
|
u_char buffer[128];
|
|
|
|
|
|
|
|
if (KBDFLAG(dev) == KBDFLAG_CONUNIT)
|
|
|
|
return(ENXIO);
|
|
|
|
|
|
|
|
/* Block until keyboard activity occured. */
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
while (sc->sc_q.c_cc == 0) {
|
|
|
|
if (flag & IO_NDELAY) {
|
|
|
|
splx(s);
|
|
|
|
return EWOULDBLOCK;
|
|
|
|
}
|
|
|
|
sc->sc_state |= RAWKBD_ASLEEP;
|
|
|
|
if ((error = tsleep((caddr_t)sc, PZERO | PCATCH, "kbdread", 0))) {
|
|
|
|
sc->sc_state &= (~RAWKBD_ASLEEP);
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
/* Transfer as many chunks as possible. */
|
|
|
|
|
|
|
|
while (sc->sc_q.c_cc > 0 && uio->uio_resid > 0) {
|
|
|
|
length = min(sc->sc_q.c_cc, uio->uio_resid);
|
|
|
|
if (length > sizeof(buffer))
|
|
|
|
length = sizeof(buffer);
|
|
|
|
|
|
|
|
/* Remove a small chunk from the input queue. */
|
|
|
|
(void) q_to_b(&sc->sc_q, buffer, length);
|
|
|
|
|
|
|
|
/* Copy the data to the user process. */
|
|
|
|
if ((error = (uiomove(buffer, length, uio))))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-10-15 23:47:04 +04:00
|
|
|
int
|
|
|
|
kbdpoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct kbd_softc *sc = kbd_cd.cd_devs[KBDUNIT(dev)];
|
|
|
|
int revents = 0;
|
|
|
|
int s = spltty();
|
|
|
|
|
|
|
|
if (KBDFLAG(dev) == KBDFLAG_CONUNIT)
|
|
|
|
return(ENXIO);
|
|
|
|
|
|
|
|
if (events & (POLLIN | POLLRDNORM))
|
|
|
|
if (sc->sc_q.c_cc > 0)
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
else
|
|
|
|
selrecord(p, &sc->sc_rsel);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (revents);
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
kbdioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1997-01-28 07:55:15 +03:00
|
|
|
u_long cmd;
|
1996-02-01 02:14:53 +03:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1997-10-14 23:35:34 +04:00
|
|
|
struct kbd_softc *sc = kbd_cd.cd_devs[KBDUNIT(dev)];
|
1996-02-01 02:14:53 +03:00
|
|
|
struct kbd_autorepeat *kbdar = (void *)data;
|
|
|
|
int *leds = (int *)data;
|
1996-03-14 00:51:32 +03:00
|
|
|
int s;
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case KBD_GETAUTOREPEAT:
|
|
|
|
/* if (KBDFLAG(dev) == KBDFLAG_RAWUNIT)
|
|
|
|
return(EINVAL);*/
|
|
|
|
|
|
|
|
*kbdar = kbdautorepeat;
|
|
|
|
break;
|
|
|
|
case KBD_SETAUTOREPEAT:
|
|
|
|
/* if (KBDFLAG(dev) == KBDFLAG_RAWUNIT)
|
|
|
|
return(EINVAL);*/
|
1996-03-14 00:51:32 +03:00
|
|
|
s = spltty();
|
1996-02-01 02:14:53 +03:00
|
|
|
kbdautorepeat = *kbdar;
|
|
|
|
if (kbdautorepeat.ka_rate < 1)
|
|
|
|
kbdautorepeat.ka_rate = 1;
|
|
|
|
if (kbdautorepeat.ka_rate > 50)
|
|
|
|
kbdautorepeat.ka_rate = 50;
|
|
|
|
if (kbdautorepeat.ka_delay > 50)
|
|
|
|
kbdautorepeat.ka_delay = 50;
|
|
|
|
if (kbdautorepeat.ka_delay < 1)
|
|
|
|
kbdautorepeat.ka_delay = 1;
|
1996-03-14 00:51:32 +03:00
|
|
|
(void)splx(s);
|
1996-02-01 02:14:53 +03:00
|
|
|
break;
|
|
|
|
case KBD_SETLEDS:
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetleds(sc, *leds);
|
1996-02-01 02:14:53 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return(ENXIO);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
/* Low level keyboard driver functions */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kbdcmd
|
|
|
|
*
|
|
|
|
* Send a command to the keyboard
|
|
|
|
* Returns 0 if command succeeded or 1 if it failed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdcmd(sc, cmd)
|
|
|
|
struct kbd_softc *sc;
|
1996-05-06 04:35:05 +04:00
|
|
|
u_char cmd;
|
1996-02-01 02:14:53 +03:00
|
|
|
{
|
1996-05-06 04:35:05 +04:00
|
|
|
u_char c;
|
|
|
|
int i = 0;
|
|
|
|
int retry;
|
|
|
|
|
|
|
|
for (retry = 7; retry >= 0; --retry) {
|
|
|
|
|
|
|
|
/* Wait for empty kbd transmit register */
|
|
|
|
|
|
|
|
for (i = 1000; i; i--) {
|
1997-10-14 23:35:34 +04:00
|
|
|
if (bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_STATUS) & KBD_ST_TXE)
|
1996-05-06 04:35:05 +04:00
|
|
|
break;
|
|
|
|
delay(200);
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
1996-05-06 04:35:05 +04:00
|
|
|
if (i == 0)
|
1997-10-14 23:35:34 +04:00
|
|
|
printf("%s: transmit not ready\n", sc->sc_device.dv_xname);
|
1996-05-06 04:35:05 +04:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, KBD_DATA, cmd);
|
1996-05-06 04:35:05 +04:00
|
|
|
delay(200);
|
|
|
|
|
|
|
|
/* Wait for full kbd receive register */
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++) {
|
1997-10-14 23:35:34 +04:00
|
|
|
c = bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_STATUS);
|
|
|
|
if ((c & KBD_ST_RXF) == KBD_ST_RXF)
|
1996-05-06 04:35:05 +04:00
|
|
|
break;
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
/* Get byte from kbd receive register */
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
c = bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_DATA);
|
1996-05-06 04:35:05 +04:00
|
|
|
if ((c == KBR_ACK) || (c == KBR_ECHO))
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
/* Failed if we have more reties to go flush kbd */
|
|
|
|
|
|
|
|
if (retry)
|
1997-10-14 23:35:34 +04:00
|
|
|
kbd_flush_input(sc);
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
printf("%s: command failed, cmd = %02x, status = %02x\n", sc->sc_device.dv_xname, cmd, c);
|
1996-05-06 04:35:05 +04:00
|
|
|
return(1);
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
/*
|
|
|
|
* kbd_flush_input()
|
|
|
|
*
|
|
|
|
* Flushes the keyboard input register
|
|
|
|
*/
|
|
|
|
|
1996-02-01 02:14:53 +03:00
|
|
|
void
|
1997-10-14 23:35:34 +04:00
|
|
|
kbd_flush_input(sc)
|
|
|
|
struct kbd_softc *sc;
|
1996-02-01 02:14:53 +03:00
|
|
|
{
|
1996-05-06 04:35:05 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Loop round reading bytes while the receive buffer is not empty */
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++) {
|
1997-10-14 23:35:34 +04:00
|
|
|
if ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_STATUS) & KBD_ST_RXF) == 0)
|
1996-05-06 04:35:05 +04:00
|
|
|
break;
|
|
|
|
delay(100);
|
1997-10-14 23:35:34 +04:00
|
|
|
(void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_DATA);
|
1996-05-06 04:35:05 +04:00
|
|
|
}
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
/*
|
|
|
|
* kbdreset()
|
|
|
|
*
|
|
|
|
* Resets the keyboard.
|
|
|
|
* Returns 0 if successful.
|
|
|
|
* Returns 1 if keyboard could not be enabled.
|
|
|
|
* Returns 2 if keyboard could not be reset.
|
|
|
|
*/
|
|
|
|
|
1996-02-01 02:14:53 +03:00
|
|
|
int
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdreset(sc)
|
|
|
|
struct kbd_softc *sc;
|
1996-02-01 02:14:53 +03:00
|
|
|
{
|
1996-05-06 04:35:05 +04:00
|
|
|
int i;
|
|
|
|
u_char c;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
kbd_flush_input(sc);
|
1996-05-06 04:35:05 +04:00
|
|
|
|
|
|
|
/* Disable, wait then enable the keyboard interface */
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, KBD_CR, 0x00);
|
1996-05-06 04:35:05 +04:00
|
|
|
delay(100);
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, KBD_CR, KBD_CR_ENABLE);
|
1996-05-06 04:35:05 +04:00
|
|
|
|
|
|
|
/* Wait for kdata and kclk to go high */
|
|
|
|
|
|
|
|
for (i = 1000; i; i--) {
|
1997-10-14 23:35:34 +04:00
|
|
|
if ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_STATUS)
|
|
|
|
& (KBD_ST_KDATAI | KBD_ST_KCLKI))
|
|
|
|
== (KBD_ST_KDATAI | KBD_ST_KCLKI))
|
1996-05-06 04:35:05 +04:00
|
|
|
break;
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, KBD_CR,
|
|
|
|
(KBD_CR_KDATAO | KBD_CR_KCLKO));
|
1996-05-06 04:35:05 +04:00
|
|
|
delay(200);
|
1997-10-14 23:35:34 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, KBD_CR, KBD_CR_ENABLE);
|
1996-05-06 04:35:05 +04:00
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
if (i == 0 || (bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_STATUS)
|
|
|
|
& KBD_ST_ENABLE) == 0)
|
1996-05-06 04:35:05 +04:00
|
|
|
return(1);
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
kbd_flush_input(sc);
|
|
|
|
kbdcmd(sc, KBC_DISABLE);
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
retry:
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdcmd(sc, KBC_RESET);
|
|
|
|
delay(500000);
|
|
|
|
for (i = 100; i; i--) {
|
|
|
|
c = bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_DATA);
|
1996-05-06 04:35:05 +04:00
|
|
|
if (c == KBR_RSTDONE)
|
|
|
|
break;
|
1997-10-14 23:35:34 +04:00
|
|
|
delay(100000);
|
|
|
|
if (c == KBR_RESEND) {
|
|
|
|
printf(" [retry]");
|
1996-05-06 04:35:05 +04:00
|
|
|
goto retry;
|
1997-10-14 23:35:34 +04:00
|
|
|
}
|
1996-05-06 04:35:05 +04:00
|
|
|
}
|
|
|
|
if (i == 0)
|
|
|
|
return(2);
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdcmd(sc, KBC_SETSCANTBL);
|
|
|
|
kbdcmd(sc, KBD_SETSCAN_2);
|
|
|
|
kbdcmd(sc, KBC_ENABLE);
|
1996-05-06 04:35:05 +04:00
|
|
|
|
|
|
|
modifiers = MODIFIER_NUM;
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetleds(sc, (modifiers >> 3) & 7);
|
1996-05-06 04:35:05 +04:00
|
|
|
return(0);
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
|
1996-02-01 02:14:53 +03:00
|
|
|
void
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetleds(sc, leds)
|
|
|
|
struct kbd_softc *sc;
|
1996-05-06 04:35:05 +04:00
|
|
|
int leds;
|
1996-02-01 02:14:53 +03:00
|
|
|
{
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdcmd(sc, KBC_SETLEDS);
|
|
|
|
kbdcmd(sc, leds);
|
1996-05-06 04:35:05 +04:00
|
|
|
}
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
#if 0
|
1996-05-06 04:35:05 +04:00
|
|
|
void
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetstate(sc, state)
|
|
|
|
struct kbd_softc *sc;
|
1996-05-06 04:35:05 +04:00
|
|
|
int state;
|
|
|
|
{
|
|
|
|
modifiers = state & MODIFIER_LOCK_MASK;
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetleds(sc, (modifiers >> 3) & 7);
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
int
|
1997-10-14 23:35:34 +04:00
|
|
|
kdbgetstate(sc)
|
|
|
|
struct kbd_softc *sc;
|
1996-05-06 04:35:05 +04:00
|
|
|
{
|
|
|
|
return(modifiers);
|
|
|
|
}
|
1997-10-14 23:35:34 +04:00
|
|
|
#endif
|
1996-05-06 04:35:05 +04:00
|
|
|
|
1996-02-16 02:24:44 +03:00
|
|
|
int
|
|
|
|
getkey_polled()
|
|
|
|
{
|
|
|
|
int code;
|
|
|
|
int key;
|
|
|
|
int up;
|
|
|
|
key_struct *ks;
|
|
|
|
int s;
|
1997-10-14 23:35:34 +04:00
|
|
|
|
|
|
|
if (console_kbd == NULL) {
|
|
|
|
/*
|
|
|
|
* Cannot panic here as that will either call the debugger or
|
|
|
|
* cpu_reboot() which will try and read a key.
|
|
|
|
*/
|
|
|
|
printf("console_kbd = 0\n");
|
|
|
|
halt();
|
|
|
|
}
|
1996-02-16 02:24:44 +03:00
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
|
|
|
key = 0;
|
|
|
|
|
|
|
|
do {
|
1997-10-14 23:35:34 +04:00
|
|
|
while ((bus_space_read_1(console_kbd->sc_iot, console_kbd->sc_ioh, KBD_STATUS) & KBD_ST_RXF) == 0) ;
|
1996-05-06 04:35:05 +04:00
|
|
|
delay(10);
|
1996-02-16 02:24:44 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* Read the IOMD keyboard register and process the key */
|
1996-02-16 02:24:44 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
code = PollKeyboard(bus_space_read_1(console_kbd->sc_iot, console_kbd->sc_ioh, KBD_DATA));
|
1996-02-16 02:24:44 +03:00
|
|
|
|
|
|
|
if (code != 0) {
|
|
|
|
up = (code & 0x100);
|
|
|
|
key = code & 0xff;
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
/* printf("code=%04x mod=%04x\n", code, modifiers);*/
|
1996-02-16 02:24:44 +03:00
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* By default we use the main keycode lookup table */
|
1996-02-16 02:24:44 +03:00
|
|
|
|
|
|
|
ks = keys;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* If we have an E0 or E1 sqeuence we use the extended table */
|
1996-02-16 02:24:44 +03:00
|
|
|
|
|
|
|
if (code > 0x1ff)
|
|
|
|
ks = E0keys;
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
/* Is the key a temporary modifier ? */
|
1996-02-16 02:24:44 +03:00
|
|
|
|
|
|
|
if (ks[key].flags & MODIFIER_MASK) {
|
|
|
|
if (up)
|
|
|
|
modifiers &= ~ks[key].flags;
|
|
|
|
else
|
|
|
|
modifiers |= ks[key].flags;
|
|
|
|
key = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the key a locking modifier ? */
|
|
|
|
|
|
|
|
if (ks[key].flags & MODIFIER_LOCK_MASK) {
|
|
|
|
if (!up) {
|
|
|
|
modifiers ^= ks[key].flags;
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetleds(console_kbd, (modifiers >> 3) & 7);
|
1996-02-16 02:24:44 +03:00
|
|
|
}
|
|
|
|
key = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup the correct key code */
|
|
|
|
|
|
|
|
if (modifiers & 0x01)
|
|
|
|
key = ks[key].ctrl_code;
|
|
|
|
else if (modifiers & 0x02)
|
|
|
|
key = ks[key].shift_code;
|
|
|
|
else if (modifiers & 0x04)
|
|
|
|
key = ks[key].alt_code;
|
|
|
|
else
|
|
|
|
key = ks[key].base_code;
|
|
|
|
|
|
|
|
if (modifiers & MODIFIER_CAPS) {
|
1996-03-14 00:51:32 +03:00
|
|
|
if ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z'))
|
1996-02-16 02:24:44 +03:00
|
|
|
key ^= 0x20;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (up)
|
|
|
|
key = 0;
|
|
|
|
if (!up && key >= 0x200) {
|
|
|
|
|
|
|
|
#if (NVT > 0)
|
|
|
|
if ((key & ~0x0f) == 0x480)
|
|
|
|
console_switch((key & 0x0f) - 1);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
switch (key) {
|
|
|
|
#if (NVT > 0)
|
|
|
|
case 0x201:
|
|
|
|
console_scrollforward();
|
|
|
|
break;
|
|
|
|
case 0x200:
|
|
|
|
console_scrollback();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
key = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (key == 0);
|
|
|
|
|
|
|
|
if (key == '\r')
|
|
|
|
key = '\n';
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-01 02:14:53 +03:00
|
|
|
/* Keyboard IRQ handler */
|
|
|
|
|
|
|
|
int
|
1997-01-28 07:55:15 +03:00
|
|
|
kbdintr(arg)
|
|
|
|
void *arg;
|
1996-02-01 02:14:53 +03:00
|
|
|
{
|
1997-01-28 07:55:15 +03:00
|
|
|
struct kbd_softc *sc = arg;
|
1996-02-01 02:14:53 +03:00
|
|
|
int key;
|
|
|
|
|
|
|
|
/* Read the IOMD keyboard register and process the key */
|
|
|
|
|
1997-10-14 23:35:34 +04:00
|
|
|
key = PollKeyboard(bus_space_read_1(sc->sc_iot, sc->sc_ioh, KBD_DATA));
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
/* If we have a raw keycode convert it to an ASCII code */
|
|
|
|
|
1996-03-08 19:28:54 +03:00
|
|
|
if (key != 0)
|
|
|
|
kbddecodekey(sc, key);
|
1996-10-15 23:47:04 +04:00
|
|
|
|
|
|
|
return(1); /* Claim interrupt */
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Flags used to decode the raw keys */
|
|
|
|
|
|
|
|
#define FLAG_KEYUP 0x01
|
|
|
|
#define FLAG_E0 0x02
|
|
|
|
#define FLAG_E1 0x04
|
|
|
|
|
|
|
|
static int flags = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is now misnamed.
|
|
|
|
* It processes the raw key codes from the keyboard and generates
|
|
|
|
* a unique code that can be decoded with the key translation array.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
PollKeyboard(code)
|
|
|
|
int code;
|
|
|
|
{
|
1996-10-13 07:05:43 +04:00
|
|
|
/* printf("%02x.", code);*/
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the keyup flag if this is the release code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (code == 0xf0) {
|
|
|
|
flags |= FLAG_KEYUP;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is a special code ignore it */
|
|
|
|
|
|
|
|
if (code == 0xff || code == 0x00) {
|
|
|
|
flags = 0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is a resend code note it down */
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
if (code == KBR_RESEND) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("kbd:resend\n");
|
1996-02-01 02:14:53 +03:00
|
|
|
kbd_resend = 1;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it is an ack code note it down */
|
|
|
|
|
1996-05-06 04:35:05 +04:00
|
|
|
if (code == KBR_ACK) {
|
1996-10-13 07:05:43 +04:00
|
|
|
/* printf("kbd:ack\n");*/
|
1996-02-01 02:14:53 +03:00
|
|
|
kbd_ack = 1;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flag the start of an E0 sequence. */
|
|
|
|
|
|
|
|
if (code == 0xe0) {
|
|
|
|
flags |= FLAG_E0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flag the start of an E1 sequence. */
|
|
|
|
|
|
|
|
if (code == 0xe1) {
|
|
|
|
flags |= FLAG_E1;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore any other invalid codes */
|
|
|
|
|
|
|
|
if (code > 0x8f) {
|
|
|
|
flags = 0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
/* printf("%02x:%02x.", code, flags);*/
|
1996-02-01 02:14:53 +03:00
|
|
|
|
|
|
|
/* Mark the code appropriately if it is part of an E0 sequence */
|
|
|
|
|
|
|
|
if (flags & FLAG_E0) {
|
|
|
|
flags &= ~FLAG_E0;
|
|
|
|
if (code == 0x12) {
|
|
|
|
flags &= ~FLAG_KEYUP;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
code |= 0x200;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the key if it is the upcode */
|
|
|
|
|
|
|
|
if (flags & FLAG_KEYUP) {
|
|
|
|
flags &= ~FLAG_KEYUP;
|
|
|
|
code |= 0x100;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the code appropriately if it is part of an E1 sequence */
|
|
|
|
|
|
|
|
if (flags & FLAG_E1) {
|
|
|
|
if ((code & 0xff) == 0x14) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
flags &= ~FLAG_E1;
|
|
|
|
code |= 0x400;
|
|
|
|
flags &= ~FLAG_KEYUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine decodes the unique keycode and generates an ASCII code
|
|
|
|
* if necessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
kbddecodekey(sc, code)
|
|
|
|
struct kbd_softc *sc;
|
|
|
|
int code;
|
|
|
|
{
|
|
|
|
key_struct *ks;
|
|
|
|
int up;
|
|
|
|
int key;
|
|
|
|
|
|
|
|
console_unblank();
|
|
|
|
|
|
|
|
/* Do we have the raw kbd device open ... */
|
|
|
|
|
|
|
|
if (rawkbd_device == 1 && code != 0) {
|
|
|
|
struct kbd_data buffer;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/* Add this event to the queue. */
|
|
|
|
|
|
|
|
buffer.keycode = code;
|
|
|
|
microtime(&buffer.event_time);
|
|
|
|
s=spltty();
|
|
|
|
(void) b_to_q((char *)&buffer, sizeof(buffer), &sc->sc_q);
|
|
|
|
splx(s);
|
|
|
|
selwakeup(&sc->sc_rsel);
|
|
|
|
|
|
|
|
if (sc->sc_state & RAWKBD_ASLEEP) {
|
|
|
|
sc->sc_state &= ~RAWKBD_ASLEEP;
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
psignal(sc->sc_proc, SIGIO);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
up = (code & 0x100);
|
|
|
|
key = code & 0xff;
|
|
|
|
|
|
|
|
/* By default we use the main keycode lookup table */
|
|
|
|
|
|
|
|
ks = keys;
|
|
|
|
|
|
|
|
/* If we have an E0 or E1 sqeuence we use the extended table */
|
|
|
|
|
|
|
|
if (code > 0x1ff)
|
|
|
|
ks = E0keys;
|
|
|
|
|
|
|
|
/* Is the key a temporary modifier ? */
|
|
|
|
|
|
|
|
if (ks[key].flags & MODIFIER_MASK) {
|
|
|
|
if (up)
|
|
|
|
modifiers &= ~ks[key].flags;
|
|
|
|
else
|
|
|
|
modifiers |= ks[key].flags;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the key a locking modifier ? */
|
|
|
|
|
|
|
|
if (ks[key].flags & MODIFIER_LOCK_MASK) {
|
|
|
|
if (!up) {
|
|
|
|
modifiers ^= ks[key].flags;
|
1997-10-14 23:35:34 +04:00
|
|
|
kbdsetleds(sc, (modifiers >> 3) & 7);
|
1996-02-01 02:14:53 +03:00
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup the correct key code */
|
|
|
|
|
|
|
|
if (modifiers & 0x01)
|
|
|
|
key = ks[key].ctrl_code;
|
|
|
|
else if (modifiers & 0x02)
|
|
|
|
key = ks[key].shift_code;
|
|
|
|
else if (modifiers & 0x04)
|
|
|
|
key = ks[key].alt_code;
|
|
|
|
else
|
|
|
|
key = ks[key].base_code;
|
|
|
|
|
|
|
|
if (modifiers & MODIFIER_CAPS) {
|
1996-03-14 00:51:32 +03:00
|
|
|
if ((key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z'))
|
1996-02-01 02:14:53 +03:00
|
|
|
key ^= 0x20;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no valid code the key is not yet mapped so report error */
|
|
|
|
|
|
|
|
#ifdef DEBUG_TERM
|
|
|
|
/* if (key == 0) {
|
|
|
|
char err[80];
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
sprintf(err, "\n\rUnknown keycode %04x\n\r", code);
|
1996-02-01 02:14:53 +03:00
|
|
|
dprintf(err);
|
|
|
|
|
|
|
|
}*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If we have an ASCII code insert it into the keyboard buffer */
|
|
|
|
|
|
|
|
if (!up && key != 0) {
|
|
|
|
if (key >= 0x200) {
|
|
|
|
|
|
|
|
untimeout(autorepeatstart, &autorepeatkey);
|
|
|
|
untimeout(autorepeat, &autorepeatkey);
|
|
|
|
autorepeatkey = -1;
|
|
|
|
#if (NVT > 0)
|
|
|
|
if ((key & ~0x0f) == 0x480)
|
|
|
|
console_switch((key & 0x0f) - 1);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
switch (key) {
|
1997-10-14 23:35:34 +04:00
|
|
|
#ifdef PMAP_DEBUG
|
1996-02-01 02:14:53 +03:00
|
|
|
case 0x22b:
|
|
|
|
pmap_debug(pmap_debug_level + 1);
|
|
|
|
break;
|
|
|
|
case 0x22d:
|
|
|
|
pmap_debug(pmap_debug_level - 1);
|
|
|
|
break;
|
1997-10-14 23:35:34 +04:00
|
|
|
#endif
|
1996-02-01 02:14:53 +03:00
|
|
|
#if (NVT > 0)
|
|
|
|
case 0x201:
|
|
|
|
console_scrollforward();
|
|
|
|
break;
|
|
|
|
case 0x200:
|
|
|
|
console_scrollback();
|
|
|
|
break;
|
1997-10-14 23:35:34 +04:00
|
|
|
/*
|
1996-02-01 02:14:53 +03:00
|
|
|
case 0x202:
|
|
|
|
console_switchdown();
|
|
|
|
break;
|
|
|
|
case 0x203:
|
|
|
|
console_switchup();
|
|
|
|
break;
|
1997-10-14 23:35:34 +04:00
|
|
|
*/
|
1996-02-01 02:14:53 +03:00
|
|
|
#endif
|
|
|
|
case 0x204:
|
|
|
|
--kbdautorepeat.ka_rate;
|
|
|
|
if (kbdautorepeat.ka_rate < 1)
|
|
|
|
kbdautorepeat.ka_rate = 1;
|
|
|
|
break;
|
|
|
|
case 0x205:
|
|
|
|
++kbdautorepeat.ka_rate;
|
|
|
|
if (kbdautorepeat.ka_rate > 50)
|
|
|
|
kbdautorepeat.ka_rate = 50;
|
|
|
|
break;
|
|
|
|
case 0x20a:
|
|
|
|
++kbdautorepeat.ka_delay;
|
|
|
|
if (kbdautorepeat.ka_delay > 50)
|
|
|
|
kbdautorepeat.ka_delay = 50;
|
|
|
|
break;
|
|
|
|
case 0x20b:
|
|
|
|
--kbdautorepeat.ka_delay;
|
|
|
|
if (kbdautorepeat.ka_delay < 1)
|
|
|
|
kbdautorepeat.ka_delay = 1;
|
|
|
|
break;
|
1996-02-16 02:24:44 +03:00
|
|
|
#ifdef DDB
|
1996-03-08 19:28:54 +03:00
|
|
|
case 0x208:
|
1996-02-16 02:24:44 +03:00
|
|
|
Debugger();
|
1996-03-08 19:28:54 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 0x21b:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Kernel interruption\n");
|
1997-03-27 01:42:13 +03:00
|
|
|
cpu_reboot(RB_HALT, NULL);
|
1996-02-01 02:14:53 +03:00
|
|
|
break;
|
|
|
|
case 0x209:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Kernel interruption - nosync\n");
|
1997-03-27 01:42:13 +03:00
|
|
|
cpu_reboot(RB_NOSYNC | RB_HALT, NULL);
|
1996-02-01 02:14:53 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("Special key %04x\n", key);
|
1996-02-01 02:14:53 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
1996-05-06 04:35:05 +04:00
|
|
|
/*
|
|
|
|
* Check rawkbd_device first, in case we stick in the
|
|
|
|
* physconkbd().
|
|
|
|
*/
|
|
|
|
if (rawkbd_device == 0 && physconkbd(key) == 0) {
|
1996-02-01 02:14:53 +03:00
|
|
|
if (autorepeatkey != key) {
|
|
|
|
untimeout(autorepeatstart, &autorepeatkey);
|
|
|
|
untimeout(autorepeat, &autorepeatkey);
|
|
|
|
autorepeatkey = key;
|
|
|
|
timeout(autorepeatstart, &autorepeatkey, hz/kbdautorepeat.ka_delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
untimeout(autorepeatstart, &autorepeatkey);
|
|
|
|
untimeout(autorepeat, &autorepeatkey);
|
|
|
|
autorepeatkey = -1;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
autorepeatstart(key)
|
|
|
|
void *key;
|
|
|
|
{
|
|
|
|
physconkbd(*((int *)key));
|
|
|
|
timeout(autorepeat, key, hz/kbdautorepeat.ka_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
autorepeat(key)
|
|
|
|
void *key;
|
|
|
|
{
|
|
|
|
physconkbd(*((int *)key));
|
|
|
|
timeout(autorepeat, key, hz/kbdautorepeat.ka_rate);
|
|
|
|
}
|
|
|
|
|
1996-03-08 19:28:54 +03:00
|
|
|
/* End of kbd.c */
|