199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Michael Smith (msmith@freebsd.org)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1997 Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Id: probe_keyboard.c,v 1.13 1997/06/09 05:10:55 bde Exp
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int probe_keyboard(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int vidc_init(struct console *cp, int arg);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void vidc_putchar(struct console *cp, int c);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid get_pos(int *x, int *y);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic unsigned keybuf[KEYBUFSZ]; /* keybuf for extended codes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* look for a keyboard */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* XXX for now, always assume we can do BIOS screen output */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Init terminal emulator */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0); /* XXX reinit? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (c == '\t')
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* lame tab expansion */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < 8; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Emulate AH=0eh (teletype output) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get cursor position on the screen. Result is in edx. Sets
199767f8919635c4928607450d9e0abb932109ceToomas Soome * curx and cury appropriately.
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Move cursor to x rows and y cols (0-based). */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* If there is ctrl char at this position, cursor would be invisible.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Make it a space instead.
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define isvisible(c) (((c) >= 32) && ((c) < 255))
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ctl = 0; /* show normal underline cursor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Scroll up the whole window by a number of rows. If rows==0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * clear the window. fg and bg are attributes for the new lines
199767f8919635c4928607450d9e0abb932109ceToomas Soome * inserted in the window.
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Write character and attribute at cursor position. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/**************************************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Screen manipulation functions. They use accumulated data in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * args[] and argc variables.
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Clear line from current position to end of line */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else if (direction == 1) { /* from beginning to cursor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Clear display from current position to end of screen */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Absolute cursor move to args[0] rows and args[1] columns
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (the coordinates are 1-based).
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Home cursor (left top corner) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Clear internal state of the terminal emulation code */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Gracefully exit ESC-sequence processing in case of misunderstanding */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i <= argc; ++i) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Emulate basic capabilities of sun-color terminal */
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (c) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case '\033':
199767f8919635c4928607450d9e0abb932109ceToomas Soome case '\033':
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (c) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (c) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome else if (argc == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (args[0]) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i <= argc; ++i) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (args[i]) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case 0: /* back to normal */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < KEYBUFSZ; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (keybuf[i] != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* extended keys */
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < KEYBUFSZ; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (keybuf[i] != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* selected defines from kbdio.h */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KBD_STATUS_PORT 4 /* status port, read */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KBD_DATA_PORT 0 /* data port, read/write
199767f8919635c4928607450d9e0abb932109ceToomas Soome * also used as keyboard command
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and mouse command port
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* 7 microsec delay necessary for some keyboard controllers */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * I know this is broken, but no timer is available yet at this stage...
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See also comments in `delay1ms()'.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This routine uses an inb to an unused port, the time to execute that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * inb is approximately 1.25uS. This value is pretty constant across
199767f8919635c4928607450d9e0abb932109ceToomas Soome * all CPU's and all buses, with the exception of some PCI implentations
199767f8919635c4928607450d9e0abb932109ceToomas Soome * that do not forward this I/O address to the ISA bus as they know it
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is not a valid ISA bus address, those machines execute this inb in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 60 nS :-(.
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i = 800;
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (--i >= 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We use the presence/absence of a keyboard to determine whether the internal
199767f8919635c4928607450d9e0abb932109ceToomas Soome * console can be used for input.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Perform a simple test on the keyboard; issue the ECHO command and see
199767f8919635c4928607450d9e0abb932109ceToomas Soome * if the right answer is returned. We don't do anything as drastic as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * full keyboard reset; it will be too troublesome and take too much time.
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (--retry >= 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* flush any noise */
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* wait until the controller can accept a command */
199767f8919635c4928607450d9e0abb932109ceToomas Soome & (KBDS_INPUT_BUFFER_FULL | KBDS_ANY_BUFFER_FULL)) == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* send the ECHO command */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* wait for a response */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (inb(IO_KBD + KBD_STATUS_PORT) & KBDS_ANY_BUFFER_FULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* got the right answer */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* KEYBOARD_PROBE */