| 1 |
/* |
| 2 |
* Mach Operating System |
| 3 |
* Copyright (c) 1991,1990,1989 Carnegie Mellon University |
| 4 |
* All Rights Reserved. |
| 5 |
* |
| 6 |
* Permission to use, copy, modify and distribute this software and its |
| 7 |
* documentation is hereby granted, provided that both the copyright |
| 8 |
* notice and this permission notice appear in all copies of the |
| 9 |
* software, derivative works or modified versions, and any portions |
| 10 |
* thereof, and that both notices appear in supporting documentation. |
| 11 |
* |
| 12 |
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 13 |
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
| 14 |
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 15 |
* |
| 16 |
* Carnegie Mellon requests users of this software to return to |
| 17 |
* |
| 18 |
* Software Distribution Coordinator or [email protected] |
| 19 |
* School of Computer Science |
| 20 |
* Carnegie Mellon University |
| 21 |
* Pittsburgh PA 15213-3890 |
| 22 |
* |
| 23 |
* any improvements or extensions that they make and grant Carnegie Mellon |
| 24 |
* the rights to redistribute these changes. |
| 25 |
*/ |
| 26 |
/* |
| 27 |
* Olivetti Mach Console driver v0.0 |
| 28 |
* Copyright Ing. C. Olivetti & C. S.p.A. 1988, 1989 |
| 29 |
* All rights reserved. |
| 30 |
* |
| 31 |
*/ |
| 32 |
/* |
| 33 |
Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc., |
| 34 |
Cupertino, California. |
| 35 |
|
| 36 |
All Rights Reserved |
| 37 |
|
| 38 |
Permission to use, copy, modify, and distribute this software and |
| 39 |
its documentation for any purpose and without fee is hereby |
| 40 |
granted, provided that the above copyright notice appears in all |
| 41 |
copies and that both the copyright notice and this permission notice |
| 42 |
appear in supporting documentation, and that the name of Olivetti |
| 43 |
not be used in advertising or publicity pertaining to distribution |
| 44 |
of the software without specific, written prior permission. |
| 45 |
|
| 46 |
OLIVETTI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE |
| 47 |
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, |
| 48 |
IN NO EVENT SHALL OLIVETTI BE LIABLE FOR ANY SPECIAL, INDIRECT, OR |
| 49 |
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 50 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, |
| 51 |
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION |
| 52 |
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 53 |
*/ |
| 54 |
|
| 55 |
/* |
| 56 |
Copyright 1988, 1989 by Intel Corporation, Santa Clara, California. |
| 57 |
|
| 58 |
All Rights Reserved |
| 59 |
|
| 60 |
Permission to use, copy, modify, and distribute this software and |
| 61 |
its documentation for any purpose and without fee is hereby |
| 62 |
granted, provided that the above copyright notice appears in all |
| 63 |
copies and that both the copyright notice and this permission notice |
| 64 |
appear in supporting documentation, and that the name of Intel |
| 65 |
not be used in advertising or publicity pertaining to distribution |
| 66 |
of the software without specific, written prior permission. |
| 67 |
|
| 68 |
INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE |
| 69 |
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, |
| 70 |
IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR |
| 71 |
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 72 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, |
| 73 |
NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
| 74 |
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 75 |
*/ |
| 76 |
|
| 77 |
/* $ Header: $ */ |
| 78 |
|
| 79 |
#include <sys/types.h> |
| 80 |
#include <kern/debug.h> |
| 81 |
#include <kern/mach_clock.h> |
| 82 |
#include <kern/printf.h> |
| 83 |
#include <device/conf.h> |
| 84 |
#include <device/tty.h> |
| 85 |
#include <device/io_req.h> |
| 86 |
#include <device/buf.h> |
| 87 |
#include <vm/vm_kern.h> |
| 88 |
#include <i386/db_interface.h> |
| 89 |
#include <i386/irq.h> |
| 90 |
#include <i386/locore.h> |
| 91 |
#include <i386/loose_ends.h> |
| 92 |
#include <i386/vm_param.h> |
| 93 |
#include <i386/spl.h> |
| 94 |
#include <i386/pio.h> |
| 95 |
#include <i386at/cram.h> |
| 96 |
#include <i386at/kd.h> |
| 97 |
#include <i386at/kd_event.h> |
| 98 |
#include <i386at/kd_mouse.h> |
| 99 |
#include <i386at/kdsoft.h> |
| 100 |
#include <device/cons.h> |
| 101 |
#include <util/atoi.h> |
| 102 |
|
| 103 |
#if 0 |
| 104 |
#define BROKEN_KEYBOARD_RESET |
| 105 |
#endif |
| 106 |
|
| 107 |
struct tty kd_tty; |
| 108 |
extern boolean_t rebootflag; |
| 109 |
|
| 110 |
static void charput(csrpos_t pos, char ch, char chattr); |
| 111 |
static void charmvup(csrpos_t from, csrpos_t to, int count); |
| 112 |
static void charmvdown(csrpos_t from, csrpos_t to, int count); |
| 113 |
static void charclear(csrpos_t to, int count, char chattr); |
| 114 |
static void charsetcursor(csrpos_t newpos); |
| 115 |
static void kd_noopreset(void); |
| 116 |
|
| 117 |
/* |
| 118 |
* These routines define the interface to the device-specific layer. |
| 119 |
* See kdsoft.h for a more complete description of what each routine does. |
| 120 |
*/ |
| 121 |
void (*kd_dput)(csrpos_t, char, char) = charput; /* put attributed char */ |
| 122 |
void (*kd_dmvup)(csrpos_t, csrpos_t, int) = charmvup; /* block move up */ |
| 123 |
void (*kd_dmvdown)(csrpos_t, csrpos_t, int) = charmvdown; /* block move down */ |
| 124 |
void (*kd_dclear)(csrpos_t, int, char) = charclear; /* block clear */ |
| 125 |
void (*kd_dsetcursor)(csrpos_t) = charsetcursor; |
| 126 |
/* set cursor position on displayed page */ |
| 127 |
void (*kd_dreset)(void) = kd_noopreset; /* prepare for reboot */ |
| 128 |
|
| 129 |
/* |
| 130 |
* Globals used for both character-based controllers and bitmap-based |
| 131 |
* controllers. Default is EGA. |
| 132 |
*/ |
| 133 |
|
| 134 |
vm_offset_t kd_bitmap_start = (vm_offset_t)0xa0000; /* XXX - put in kd.h */ |
| 135 |
u_char *vid_start = (u_char *)EGA_START; |
| 136 |
/* VM start of video RAM or frame buffer */ |
| 137 |
csrpos_t kd_curpos = 0; /* set indirectly by kd_setpos--see kdsoft.h */ |
| 138 |
short kd_lines = 25; |
| 139 |
short kd_cols = 80; |
| 140 |
char kd_attr = KA_NORMAL; /* current attribute */ |
| 141 |
char kd_color = KA_NORMAL; |
| 142 |
char kd_attrflags = 0; /* Not reverse, underline, blink */ |
| 143 |
|
| 144 |
/* |
| 145 |
* kd_state shows the state of the modifier keys (ctrl, caps lock, |
| 146 |
* etc.) It should normally be changed by calling set_kd_state(), so |
| 147 |
* that the keyboard status LEDs are updated correctly. |
| 148 |
*/ |
| 149 |
int kd_state = KS_NORMAL; |
| 150 |
int kb_mode = KB_ASCII; /* event/ascii */ |
| 151 |
|
| 152 |
/* |
| 153 |
* State for the keyboard "mouse". |
| 154 |
*/ |
| 155 |
int kd_kbd_mouse = 0; |
| 156 |
int kd_kbd_magic_scale = 6; |
| 157 |
int kd_kbd_magic_button = 0; |
| 158 |
|
| 159 |
/* |
| 160 |
* Some keyboard commands work by sending a command, waiting for an |
| 161 |
* ack (handled by kdintr), then sending data, which generates a |
| 162 |
* second ack. If we are in the middle of such a sequence, kd_ack |
| 163 |
* shows what the ack is for. |
| 164 |
* |
| 165 |
* When a byte is sent to the keyboard, it is kept around in last_sent |
| 166 |
* in case it needs to be resent. |
| 167 |
* |
| 168 |
* The rest of the variables here hold the data required to complete |
| 169 |
* the sequence. |
| 170 |
* |
| 171 |
* XXX - the System V driver keeps a command queue, I guess in case we |
| 172 |
* want to start a command while another is in progress. Is this |
| 173 |
* something we should worry about? |
| 174 |
*/ |
| 175 |
enum why_ack {NOT_WAITING, SET_LEDS, DATA_ACK}; |
| 176 |
enum why_ack kd_ack = NOT_WAITING; |
| 177 |
|
| 178 |
u_char last_sent = 0; |
| 179 |
|
| 180 |
u_char kd_nextled = 0; |
| 181 |
|
| 182 |
/* |
| 183 |
* We don't provide any mutex protection for this flag because we know |
| 184 |
* that this module will have been initialized by the time multiple |
| 185 |
* threads are running. |
| 186 |
*/ |
| 187 |
boolean_t kd_initialized = FALSE; /* driver initialized? */ |
| 188 |
boolean_t kd_extended = FALSE; |
| 189 |
|
| 190 |
/* Array for processing escape sequences. */ |
| 191 |
#define K_MAXESC 32 |
| 192 |
u_char esc_seq[K_MAXESC]; |
| 193 |
u_char *esc_spt = (u_char *)0; |
| 194 |
|
| 195 |
/* |
| 196 |
* This array maps scancodes to Ascii characters (or character |
| 197 |
* sequences). |
| 198 |
* Each row corresponds to one key. There are NUMOUTPUT bytes per key |
| 199 |
* state. The states are ordered: Normal, SHIFT, CTRL, ALT, |
| 200 |
* SHIFT/ALT. |
| 201 |
*/ |
| 202 |
|
| 203 |
/* This new keymap from Tudor Hulubei ([email protected]) makes the |
| 204 |
following changes to the keyboard driver: |
| 205 |
|
| 206 |
- Alt + key (m-key) returns `ESC key' instead of `ESC N key'. |
| 207 |
- Backspace returns 0x7f instead of 0x08. |
| 208 |
- Delete returns `ESC [ 9' instead of 0x7f. |
| 209 |
- Alt + function keys return key sequences that are different |
| 210 |
from the key sequences returned by the function keys alone. |
| 211 |
This is done with the idea of allowing a terminal server to |
| 212 |
implement multiple virtual consoles mapped on Alt+F1, Alt+F2, |
| 213 |
etc, as in Linux. |
| 214 |
|
| 215 |
-- Derek Upham 1997/06/25 */ |
| 216 |
|
| 217 |
unsigned char key_map[NUMKEYS][WIDTH_KMAP] = { |
| 218 |
{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, |
| 219 |
{K_ESC,NC,NC, K_ESC,NC,NC, K_ESC,NC,NC, 0x1b,K_ESC,NC, K_ESC,NC,NC}, |
| 220 |
{K_ONE,NC,NC, K_BANG,NC,NC, K_ONE,NC,NC, 0x1b,K_ONE,NC, 0x1b,0x4e,K_BANG}, |
| 221 |
{K_TWO,NC,NC, K_ATSN,NC,NC, K_NUL,NC,NC, 0x1b,K_TWO,NC, 0x1b,0x4e,K_ATSN}, |
| 222 |
{K_THREE,NC,NC, K_POUND,NC,NC, K_THREE,NC,NC, 0x1b,K_THREE,NC, 0x1b,0x4e,K_POUND}, |
| 223 |
{K_FOUR,NC,NC, K_DOLLAR,NC,NC, K_FOUR,NC,NC, 0x1b,K_FOUR,NC, 0x1b,0x4e,K_DOLLAR}, |
| 224 |
{K_FIVE,NC,NC, K_PERC,NC,NC, K_FIVE,NC,NC, 0x1b,K_FIVE,NC, 0x1b,0x4e,K_PERC}, |
| 225 |
{K_SIX,NC,NC, K_CARET,NC,NC, K_RS,NC,NC, 0x1b,K_SIX,NC, 0x1b,0x4e,K_CARET}, |
| 226 |
{K_SEVEN,NC,NC, K_AMPER,NC,NC, K_SEVEN,NC,NC, 0x1b,K_SEVEN,NC, 0x1b,0x4e,K_AMPER}, |
| 227 |
{K_EIGHT,NC,NC, K_ASTER,NC,NC, K_EIGHT,NC,NC, 0x1b,K_EIGHT,NC, 0x1b,0x4e,K_ASTER}, |
| 228 |
{K_NINE,NC,NC, K_LPAREN,NC,NC, K_NINE,NC,NC, 0x1b,K_NINE,NC, 0x1b,0x4e,K_LPAREN}, |
| 229 |
{K_ZERO,NC,NC, K_RPAREN,NC,NC, K_ZERO,NC,NC, 0x1b,K_ZERO,NC, 0x1b,0x4e,K_RPAREN}, |
| 230 |
{K_MINUS,NC,NC, K_UNDSC,NC,NC, K_US,NC,NC, 0x1b,K_MINUS,NC, 0x1b,0x4e,K_UNDSC}, |
| 231 |
{K_EQL,NC,NC, K_PLUS,NC,NC, K_EQL,NC,NC, 0x1b,K_EQL,NC, 0x1b,0x4e,K_PLUS}, |
| 232 |
{K_DEL,NC,NC, K_DEL,NC,NC, K_DEL,NC,NC, 0x1b,K_DEL,NC, K_DEL,NC,NC}, |
| 233 |
{K_HT,NC,NC, K_GS,NC,NC, K_HT,NC,NC, 0x1b,K_HT,NC, K_GS,NC,NC}, |
| 234 |
{K_q,NC,NC, K_Q,NC,NC, K_DC1,NC,NC, 0x1b,K_q,NC, 0x1b,0x4e,K_Q}, |
| 235 |
{K_w,NC,NC, K_W,NC,NC, K_ETB,NC,NC, 0x1b,K_w,NC, 0x1b,0x4e,K_W}, |
| 236 |
{K_e,NC,NC, K_E,NC,NC, K_ENQ,NC,NC, 0x1b,K_e,NC, 0x1b,0x4e,K_E}, |
| 237 |
{K_r,NC,NC, K_R,NC,NC, K_DC2,NC,NC, 0x1b,K_r,NC, 0x1b,0x4e,K_R}, |
| 238 |
{K_t,NC,NC, K_T,NC,NC, K_DC4,NC,NC, 0x1b,K_t,NC, 0x1b,0x4e,K_T}, |
| 239 |
{K_y,NC,NC, K_Y,NC,NC, K_EM,NC,NC, 0x1b,K_y,NC, 0x1b,0x4e,K_Y}, |
| 240 |
{K_u,NC,NC, K_U,NC,NC, K_NAK,NC,NC, 0x1b,K_u,NC, 0x1b,0x4e,K_U}, |
| 241 |
{K_i,NC,NC, K_I,NC,NC, K_HT,NC,NC, 0x1b,K_i,NC, 0x1b,0x4e,K_I}, |
| 242 |
{K_o,NC,NC, K_O,NC,NC, K_SI,NC,NC, 0x1b,K_o,NC, 0x1b,0x4e,K_O}, |
| 243 |
{K_p,NC,NC, K_P,NC,NC, K_DLE,NC,NC, 0x1b,K_p,NC, 0x1b,0x4e,K_P}, |
| 244 |
{K_LBRKT,NC,NC, K_LBRACE,NC,NC, K_ESC,NC,NC, 0x1b,K_LBRKT,NC, 0x1b,0x4e,K_LBRACE}, |
| 245 |
{K_RBRKT,NC,NC, K_RBRACE,NC,NC, K_GS,NC,NC, 0x1b,K_RBRKT,NC, 0x1b,0x4e,K_RBRACE}, |
| 246 |
{K_CR,NC,NC, K_CR,NC,NC, K_CR,NC,NC, 0x1b,K_CR,NC, K_CR,NC,NC}, |
| 247 |
{K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC, K_SCAN,K_CTLSC,NC}, |
| 248 |
{K_a,NC,NC, K_A,NC,NC, K_SOH,NC,NC, 0x1b,K_a,NC, 0x1b,0x4e,K_A}, |
| 249 |
{K_s,NC,NC, K_S,NC,NC, K_DC3,NC,NC, 0x1b,K_s,NC, 0x1b,0x4e,K_S}, |
| 250 |
{K_d,NC,NC, K_D,NC,NC, K_EOT,NC,NC, 0x1b,K_d,NC, 0x1b,0x4e,K_D}, |
| 251 |
{K_f,NC,NC, K_F,NC,NC, K_ACK,NC,NC, 0x1b,K_f,NC, 0x1b,0x4e,K_F}, |
| 252 |
{K_g,NC,NC, K_G,NC,NC, K_BEL,NC,NC, 0x1b,K_g,NC, 0x1b,0x4e,K_G}, |
| 253 |
{K_h,NC,NC, K_H,NC,NC, K_BS,NC,NC, 0x1b,K_h,NC, 0x1b,0x4e,K_H}, |
| 254 |
{K_j,NC,NC, K_J,NC,NC, K_LF,NC,NC, 0x1b,K_j,NC, 0x1b,0x4e,K_J}, |
| 255 |
{K_k,NC,NC, K_K,NC,NC, K_VT,NC,NC, 0x1b,K_k,NC, 0x1b,0x4e,K_K}, |
| 256 |
{K_l,NC,NC, K_L,NC,NC, K_FF,NC,NC, 0x1b,K_l,NC, 0x1b,0x4e,K_L}, |
| 257 |
{K_SEMI,NC,NC, K_COLON,NC,NC, K_SEMI,NC,NC, 0x1b,K_SEMI,NC, 0x1b,0x4e,K_COLON}, |
| 258 |
{K_SQUOTE,NC,NC,K_DQUOTE,NC,NC, K_SQUOTE,NC,NC,0x1b,K_SQUOTE,NC, 0x1b,0x4e,K_DQUOTE}, |
| 259 |
{K_GRAV,NC,NC, K_TILDE,NC,NC, K_RS,NC,NC, 0x1b,K_GRAV,NC, 0x1b,0x4e,K_TILDE}, |
| 260 |
{K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC, K_SCAN,K_LSHSC,NC}, |
| 261 |
{K_BSLSH,NC,NC, K_PIPE,NC,NC, K_FS,NC,NC, 0x1b,K_BSLSH,NC, 0x1b,0x4e,K_PIPE}, |
| 262 |
{K_z,NC,NC, K_Z,NC,NC, K_SUB,NC,NC, 0x1b,K_z,NC, 0x1b,0x4e,K_Z}, |
| 263 |
{K_x,NC,NC, K_X,NC,NC, K_CAN,NC,NC, 0x1b,K_x,NC, 0x1b,0x4e,K_X}, |
| 264 |
{K_c,NC,NC, K_C,NC,NC, K_ETX,NC,NC, 0x1b,K_c,NC, 0x1b,0x4e,K_C}, |
| 265 |
{K_v,NC,NC, K_V,NC,NC, K_SYN,NC,NC, 0x1b,K_v,NC, 0x1b,0x4e,K_V}, |
| 266 |
{K_b,NC,NC, K_B,NC,NC, K_STX,NC,NC, 0x1b,K_b,NC, 0x1b,0x4e,K_B}, |
| 267 |
{K_n,NC,NC, K_N,NC,NC, K_SO,NC,NC, 0x1b,K_n,NC, 0x1b,0x4e,K_N}, |
| 268 |
{K_m,NC,NC, K_M,NC,NC, K_CR,NC,NC, 0x1b,K_m,NC, 0x1b,0x4e,K_M}, |
| 269 |
{K_COMMA,NC,NC, K_LTHN,NC,NC, K_COMMA,NC,NC, 0x1b,K_COMMA,NC, 0x1b,0x4e,K_LTHN}, |
| 270 |
{K_PERIOD,NC,NC,K_GTHN,NC,NC, K_PERIOD,NC,NC,0x1b,K_PERIOD,NC, 0x1b,0x4e,K_GTHN}, |
| 271 |
{K_SLASH,NC,NC, K_QUES,NC,NC, K_SLASH,NC,NC, 0x1b,K_SLASH,NC, 0x1b,0x4e,K_QUES}, |
| 272 |
{K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC, K_SCAN,K_RSHSC,NC}, |
| 273 |
{K_ASTER,NC,NC, K_ASTER,NC,NC, K_ASTER,NC,NC, 0x1b,K_ASTER,NC, 0x1b,0x4e,K_ASTER}, |
| 274 |
{K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC, K_SCAN,K_ALTSC,NC}, |
| 275 |
{K_SPACE,NC,NC, K_SPACE,NC,NC, K_NUL,NC,NC, 0x1b,K_SPACE,NC, K_SPACE,NC,NC}, |
| 276 |
{K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC, K_SCAN,K_CLCKSC,NC}, |
| 277 |
{K_F1, K_F1S, K_F1, K_F1A, K_F1S}, |
| 278 |
{K_F2, K_F2S, K_F2, K_F2A, K_F2S}, |
| 279 |
{K_F3, K_F3S, K_F3, K_F3A, K_F3S}, |
| 280 |
{K_F4, K_F4S, K_F4, K_F4A, K_F4S}, |
| 281 |
{K_F5, K_F5S, K_F5, K_F5A, K_F5S}, |
| 282 |
{K_F6, K_F6S, K_F6, K_F6A, K_F6S}, |
| 283 |
{K_F7, K_F7S, K_F7, K_F7A, K_F7S}, |
| 284 |
{K_F8, K_F8S, K_F8, K_F8A, K_F8S}, |
| 285 |
{K_F9, K_F9S, K_F9, K_F9A, K_F9S}, |
| 286 |
{K_F10, K_F10S, K_F10, K_F10A, K_F10S}, |
| 287 |
{K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC, K_SCAN,K_NLCKSC,NC}, |
| 288 |
{K_SCRL, K_NUL,NC,NC, K_SCRL, K_SCRL, K_NUL,NC,NC}, |
| 289 |
{K_HOME, K_SEVEN,NC,NC, K_HOME, K_HOME, 0x1b,0x4e,K_SEVEN}, |
| 290 |
{K_UA, K_EIGHT,NC,NC, K_UA, K_UA, 0x1b,0x4e,K_EIGHT}, |
| 291 |
{K_PUP, K_NINE,NC,NC, K_PUP, K_PUP, 0x1b,0x4e,K_NINE}, |
| 292 |
{0x1b,0x5b,0x53, K_MINUS,NC,NC, 0x1b,0x5b,0x53, 0x1b,0x5b,0x53, 0x1b,0x4e,0x2d}, |
| 293 |
{K_LA, K_FOUR,NC,NC, K_LA, K_LA, 0x1b,0x4e,K_FOUR}, |
| 294 |
{0x1b,0x5b,0x47, K_FIVE,NC,NC, 0x1b,0x5b,0x47, 0x1b,0x5b,0x47, 0x1b,0x4e,0x35}, |
| 295 |
{K_RA, K_SIX,NC,NC, K_RA, K_RA, 0x1b,0x4e,K_SIX}, |
| 296 |
{0x1b,0x5b,0x54, K_PLUS,NC,NC, 0x1b,0x5b,0x54, 0x1b,0x5b,0x54, 0x1b,0x4e,0x2b}, |
| 297 |
{K_END, K_ONE,NC,NC, K_END, K_END, 0x1b,0x4e,K_ONE}, |
| 298 |
{K_DA, K_TWO,NC,NC, K_DA, K_DA, 0x1b,0x4e,K_TWO}, |
| 299 |
{K_PDN, K_THREE,NC,NC, K_PDN, K_PDN, 0x1b,0x4e,K_THREE}, |
| 300 |
{K_INS, K_ZERO,NC,NC, K_INS, K_INS, 0x1b,0x4e,K_ZERO}, |
| 301 |
{0x1b,0x5b,0x39, K_PERIOD,NC,NC, K_DEL,NC,NC, K_DEL,NC,NC, 0x1b,0x4e,K_PERIOD}, |
| 302 |
{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, |
| 303 |
{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, |
| 304 |
{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, |
| 305 |
{K_F11, K_F11S, K_F11, K_F11A, K_F11S}, |
| 306 |
{K_F12, K_F12S, K_F12, K_F12A, K_F12S} |
| 307 |
}; |
| 308 |
|
| 309 |
|
| 310 |
/* |
| 311 |
* Globals used only for character-based controllers. |
| 312 |
*/ |
| 313 |
|
| 314 |
short kd_index_reg = EGA_IDX_REG; |
| 315 |
short kd_io_reg = EGA_IO_REG; |
| 316 |
|
| 317 |
|
| 318 |
/* |
| 319 |
* Globals used only for bitmap-based controllers. See kdsoft.h for |
| 320 |
* an explanation of what some of these variables are used for. |
| 321 |
*/ |
| 322 |
|
| 323 |
u_char *font_start = 0; /* starting addr of font */ |
| 324 |
|
| 325 |
short fb_width = 0; /* bits in frame buffer scan line */ |
| 326 |
short fb_height = 0; /* scan lines in frame buffer*/ |
| 327 |
short char_width = 0; /* bit width of 1 char */ |
| 328 |
short char_height = 0; /* bit height of 1 char */ |
| 329 |
short chars_in_font = 0; |
| 330 |
short cursor_height = 0; /* bit height of cursor */ |
| 331 |
|
| 332 |
/* These initial values are simply guesses. */ |
| 333 |
u_char char_black = 0; |
| 334 |
u_char char_white = 0xff; |
| 335 |
|
| 336 |
short xstart = 0; |
| 337 |
short ystart = 0; |
| 338 |
|
| 339 |
short char_byte_width = 0; /* char_width/NBBY */ |
| 340 |
short fb_byte_width = 0; /* fb_width/NBBY */ |
| 341 |
short font_byte_width = 0; /* num bytes in 1 scan line of font */ |
| 342 |
|
| 343 |
/* |
| 344 |
* Switch for poll vs. interrupt. |
| 345 |
*/ |
| 346 |
int kd_pollc = 0; |
| 347 |
|
| 348 |
#if MACH_KDB |
| 349 |
static void |
| 350 |
pause(void) |
| 351 |
{ |
| 352 |
int i; |
| 353 |
|
| 354 |
for (i = 0; i < 50000; ++i) |
| 355 |
; |
| 356 |
} |
| 357 |
|
| 358 |
/* |
| 359 |
* feep: |
| 360 |
* |
| 361 |
* Ring the bell for a short time. |
| 362 |
* Warning: uses outb(). You may prefer to use kd_debug_put. |
| 363 |
*/ |
| 364 |
void |
| 365 |
feep(void) |
| 366 |
{ |
| 367 |
kd_bellon(); |
| 368 |
pause(); |
| 369 |
kd_belloff(NULL); |
| 370 |
} |
| 371 |
|
| 372 |
/* |
| 373 |
* Put a debugging character on the screen. |
| 374 |
* LOC=0 means put it in the bottom right corner, LOC=1 means put it |
| 375 |
* one column to the left, etc. |
| 376 |
*/ |
| 377 |
void |
| 378 |
kd_debug_put( |
| 379 |
int loc, |
| 380 |
char c) |
| 381 |
{ |
| 382 |
csrpos_t pos = ONE_PAGE - (loc+1) * ONE_SPACE; |
| 383 |
|
| 384 |
(*kd_dput)(pos, c, KA_NORMAL); |
| 385 |
} |
| 386 |
#endif /* MACH_KDB */ |
| 387 |
|
| 388 |
|
| 389 |
extern boolean_t mouse_in_use; |
| 390 |
int old_kb_mode; |
| 391 |
|
| 392 |
void |
| 393 |
cnpollc(boolean_t on) |
| 394 |
{ |
| 395 |
if (mouse_in_use) { |
| 396 |
if (on) { |
| 397 |
/* switch into X */ |
| 398 |
old_kb_mode = kb_mode; |
| 399 |
kb_mode = KB_ASCII; |
| 400 |
X_kdb_enter(); |
| 401 |
|
| 402 |
kd_pollc++; |
| 403 |
} else { |
| 404 |
--kd_pollc; |
| 405 |
|
| 406 |
/* switch out of X */ |
| 407 |
X_kdb_exit(); |
| 408 |
kb_mode = old_kb_mode; |
| 409 |
} |
| 410 |
} else { |
| 411 |
if (on) { |
| 412 |
kd_pollc++; |
| 413 |
} else { |
| 414 |
--kd_pollc; |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
/* |
| 422 |
* kdopen: |
| 423 |
* |
| 424 |
* This opens the console driver and sets up the tty and other |
| 425 |
* rudimentary stuff including calling the line discipline for |
| 426 |
* setting up the device independent stuff for a tty driver. |
| 427 |
* |
| 428 |
* input: device number 'dev', and flag |
| 429 |
* |
| 430 |
* output: device is opened and setup |
| 431 |
* |
| 432 |
*/ |
| 433 |
int |
| 434 |
kdopen( |
| 435 |
dev_t dev, |
| 436 |
int flag, |
| 437 |
io_req_t ior) |
| 438 |
{ |
| 439 |
struct tty *tp; |
| 440 |
spl_t o_pri; |
| 441 |
|
| 442 |
tp = &kd_tty; |
| 443 |
o_pri = simple_lock_irq(&tp->t_lock); |
| 444 |
if (!(tp->t_state & (TS_ISOPEN|TS_WOPEN))) { |
| 445 |
/* XXX ttychars allocates memory */ |
| 446 |
simple_unlock_nocheck(&tp->t_lock.slock); |
| 447 |
ttychars(tp); |
| 448 |
simple_lock_nocheck(&tp->t_lock.slock); |
| 449 |
/* |
| 450 |
* Special support for boot-time rc scripts, which don't |
| 451 |
* stty the console. |
| 452 |
*/ |
| 453 |
tp->t_oproc = kdstart; |
| 454 |
tp->t_stop = kdstop; |
| 455 |
tp->t_ospeed = tp->t_ispeed = B115200; |
| 456 |
tp->t_flags = ODDP|EVENP|ECHO|CRMOD|XTABS|LITOUT; |
| 457 |
kdinit(); |
| 458 |
} |
| 459 |
tp->t_state |= TS_CARR_ON; |
| 460 |
simple_unlock_irq(o_pri, &tp->t_lock); |
| 461 |
return (char_open(dev, tp, flag, ior)); |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
/* |
| 466 |
* kdclose: |
| 467 |
* |
| 468 |
* This function merely executes the device independent code for |
| 469 |
* closing the line discipline. |
| 470 |
* |
| 471 |
* input: device number 'dev', and flag |
| 472 |
* |
| 473 |
* output: device is closed |
| 474 |
* |
| 475 |
*/ |
| 476 |
/*ARGSUSED*/ |
| 477 |
void |
| 478 |
kdclose(dev_t dev, int flag) |
| 479 |
{ |
| 480 |
struct tty *tp; |
| 481 |
|
| 482 |
tp = &kd_tty; |
| 483 |
{ |
| 484 |
spl_t s; |
| 485 |
s = simple_lock_irq(&tp->t_lock); |
| 486 |
ttyclose(tp); |
| 487 |
simple_unlock_irq(s, &tp->t_lock); |
| 488 |
} |
| 489 |
|
| 490 |
return; |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
/* |
| 495 |
* kdread: |
| 496 |
* |
| 497 |
* This function executes the device independent code to read from |
| 498 |
* the tty. |
| 499 |
* |
| 500 |
* input: device number 'dev' |
| 501 |
* |
| 502 |
* output: characters are read from tty clists |
| 503 |
* |
| 504 |
*/ |
| 505 |
/*ARGSUSED*/ |
| 506 |
int |
| 507 |
kdread(dev_t dev, io_req_t uio) |
| 508 |
{ |
| 509 |
struct tty *tp; |
| 510 |
|
| 511 |
tp = &kd_tty; |
| 512 |
tp->t_state |= TS_CARR_ON; |
| 513 |
return((*linesw[kd_tty.t_line].l_read)(tp, uio)); |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
/* |
| 518 |
* kdwrite: |
| 519 |
* |
| 520 |
* This function does the device independent write action for this |
| 521 |
* console (tty) driver. |
| 522 |
* |
| 523 |
* input: device number 'dev' |
| 524 |
* |
| 525 |
* output: characters are written to tty clists |
| 526 |
* |
| 527 |
*/ |
| 528 |
/*ARGSUSED*/ |
| 529 |
int |
| 530 |
kdwrite(dev_t dev, io_req_t uio) |
| 531 |
{ |
| 532 |
return((*linesw[kd_tty.t_line].l_write)(&kd_tty, uio)); |
| 533 |
} |
| 534 |
|
| 535 |
/* |
| 536 |
* Mmap. |
| 537 |
*/ |
| 538 |
|
| 539 |
/*ARGSUSED*/ |
| 540 |
vm_offset_t |
| 541 |
kdmmap(dev_t dev, vm_offset_t off, vm_prot_t prot) |
| 542 |
{ |
| 543 |
if (off >= (128*1024)) |
| 544 |
return(-1); |
| 545 |
|
| 546 |
/* Get page frame number for the page to be mapped. */ |
| 547 |
return(i386_btop(kd_bitmap_start+off)); |
| 548 |
} |
| 549 |
|
| 550 |
int |
| 551 |
kdportdeath( |
| 552 |
dev_t dev, |
| 553 |
mach_port_t port) |
| 554 |
{ |
| 555 |
return (tty_portdeath(&kd_tty, (ipc_port_t)port)); |
| 556 |
} |
| 557 |
|
| 558 |
/*ARGSUSED*/ |
| 559 |
io_return_t kdgetstat( |
| 560 |
dev_t dev, |
| 561 |
dev_flavor_t flavor, |
| 562 |
dev_status_t data, /* pointer to OUT array */ |
| 563 |
mach_msg_type_number_t *count) /* OUT */ |
| 564 |
{ |
| 565 |
io_return_t result; |
| 566 |
|
| 567 |
switch (flavor) { |
| 568 |
case KDGSTATE: |
| 569 |
if (*count < 1) |
| 570 |
return (D_INVALID_OPERATION); |
| 571 |
*data = kd_state; |
| 572 |
*count = 1; |
| 573 |
result = D_SUCCESS; |
| 574 |
break; |
| 575 |
|
| 576 |
case KDGKBENT: |
| 577 |
result = kdgetkbent((struct kbentry *)data); |
| 578 |
*count = sizeof(struct kbentry)/sizeof(int); |
| 579 |
break; |
| 580 |
|
| 581 |
default: |
| 582 |
result = tty_get_status(&kd_tty, flavor, data, count); |
| 583 |
break; |
| 584 |
} |
| 585 |
return (result); |
| 586 |
} |
| 587 |
|
| 588 |
/*ARGSUSED*/ |
| 589 |
io_return_t kdsetstat( |
| 590 |
dev_t dev, |
| 591 |
dev_flavor_t flavor, |
| 592 |
dev_status_t data, |
| 593 |
mach_msg_type_number_t count) |
| 594 |
{ |
| 595 |
io_return_t result; |
| 596 |
|
| 597 |
switch (flavor) { |
| 598 |
case KDSKBENT: |
| 599 |
if (count < sizeof(struct kbentry)/sizeof(int)) { |
| 600 |
return (D_INVALID_OPERATION); |
| 601 |
} |
| 602 |
result = kdsetkbent((struct kbentry *)data, 0); |
| 603 |
break; |
| 604 |
|
| 605 |
case KDSETBELL: |
| 606 |
if (count < 1) |
| 607 |
return (D_INVALID_OPERATION); |
| 608 |
result = kdsetbell(*data, 0); |
| 609 |
break; |
| 610 |
|
| 611 |
default: |
| 612 |
result = tty_set_status(&kd_tty, flavor, data, count); |
| 613 |
} |
| 614 |
return (result); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
/* |
| 620 |
* kdsetbell: |
| 621 |
* |
| 622 |
* Turn the bell on or off. Returns error code, if given bogus |
| 623 |
* on/off value. |
| 624 |
*/ |
| 625 |
int |
| 626 |
kdsetbell( |
| 627 |
int val, /* on or off */ |
| 628 |
int flags) /* flags set for console */ |
| 629 |
{ |
| 630 |
int err = 0; |
| 631 |
|
| 632 |
if (val == KD_BELLON) |
| 633 |
kd_bellon(); |
| 634 |
else if (val == KD_BELLOFF) |
| 635 |
kd_belloff(NULL); |
| 636 |
else |
| 637 |
err = D_INVALID_OPERATION; |
| 638 |
|
| 639 |
return(err); |
| 640 |
} |
| 641 |
|
| 642 |
/* |
| 643 |
* kdgetkbent: |
| 644 |
* |
| 645 |
* Get entry from key mapping table. Returns error code, if any. |
| 646 |
*/ |
| 647 |
int |
| 648 |
kdgetkbent(struct kbentry *kbent) |
| 649 |
{ |
| 650 |
u_char *cp; |
| 651 |
spl_t o_pri = SPLKD(); /* probably superfluous */ |
| 652 |
|
| 653 |
cp = &key_map[kbent->kb_index][CHARIDX(kbent->kb_state)]; |
| 654 |
kbent->kb_value[0] = *cp++; |
| 655 |
kbent->kb_value[1] = *cp++; |
| 656 |
kbent->kb_value[2] = *cp; |
| 657 |
(void)splx(o_pri); |
| 658 |
return(0); |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
/* |
| 663 |
* kdsetkbent: |
| 664 |
* |
| 665 |
* Set entry in key mapping table. Return error code, if any. |
| 666 |
*/ |
| 667 |
int |
| 668 |
kdsetkbent( |
| 669 |
struct kbentry *kbent, |
| 670 |
int flags) /* flags set for console */ |
| 671 |
{ |
| 672 |
u_char *cp; |
| 673 |
spl_t o_pri; |
| 674 |
|
| 675 |
o_pri = SPLKD(); |
| 676 |
cp = &key_map[kbent->kb_index][CHARIDX(kbent->kb_state)]; |
| 677 |
*cp++ = kbent->kb_value[0]; |
| 678 |
*cp++ = kbent->kb_value[1]; |
| 679 |
*cp = kbent->kb_value[2]; |
| 680 |
(void)splx(o_pri); |
| 681 |
return(0); |
| 682 |
} |
| 683 |
|
| 684 |
/* |
| 685 |
* kdintr: |
| 686 |
* |
| 687 |
* This function is the interrupt code for the driver. Since this is |
| 688 |
* a special tty (console), interrupts are only for input, so we read in |
| 689 |
* the character. If in ascii mode, we then do the mapping translation |
| 690 |
* from the keyboard switch table and place the characters on the tty's |
| 691 |
* input switch table. If in event mode, we create and queue a kd_event. |
| 692 |
* |
| 693 |
* input: interrupt vector 'vec' |
| 694 |
* |
| 695 |
* output: character or sequence is placed on appropriate queue |
| 696 |
* |
| 697 |
*/ |
| 698 |
/*ARGSUSED*/ |
| 699 |
void |
| 700 |
kdintr(int vec) |
| 701 |
{ |
| 702 |
struct tty *tp; |
| 703 |
unsigned char c; |
| 704 |
unsigned char scancode; |
| 705 |
unsigned int char_idx; |
| 706 |
boolean_t up = FALSE; /* key-up event */ |
| 707 |
|
| 708 |
if (kd_pollc) |
| 709 |
return; /* kdb polling kbd */ |
| 710 |
|
| 711 |
if (!kd_initialized) |
| 712 |
return; |
| 713 |
|
| 714 |
tp = &kd_tty; |
| 715 |
#ifdef old |
| 716 |
while ((inb(K_STATUS) & K_OBUF_FUL) == 0) |
| 717 |
; /* this should never loop */ |
| 718 |
#else /* old */ |
| 719 |
{ |
| 720 |
/* |
| 721 |
* Allow for keyboards that raise interrupt before |
| 722 |
* the character gets to the buffer. But don't wait |
| 723 |
* forever if grabbing the character by polling leaves |
| 724 |
* the interrupt on but buffer empty. |
| 725 |
*/ |
| 726 |
/* |
| 727 |
* Micronics VLB motherboard with 486DX2 can report keyboard |
| 728 |
* interrupt before K_STATUS register indicates that the |
| 729 |
* output buffer is full. Moreover, the bus won't settle w |
| 730 |
* while we poll K_STATUS at speed. Temporary fix is to break |
| 731 |
* out after safety runs out and pick up keyboard event. This |
| 732 |
* should be fixed eventually by putting a 1us timout between |
| 733 |
* inb's to K_STATUS and fix the pic initialization order to |
| 734 |
* avoid bootup keyboard wedging (ie make kd a real device) |
| 735 |
*/ |
| 736 |
int safety = 1000; |
| 737 |
while ((inb(K_STATUS) & K_OBUF_FUL) == 0) |
| 738 |
if (!safety--) break; /* XXX */ |
| 739 |
} |
| 740 |
#endif /* old */ |
| 741 |
/* |
| 742 |
* We may have seen a mouse event. |
| 743 |
*/ |
| 744 |
if ((inb(K_STATUS) & 0x20) == 0x20) { |
| 745 |
if (mouse_in_use) { |
| 746 |
mouse_handle_byte((u_char)inb(K_RDWR)); |
| 747 |
return; |
| 748 |
} else { |
| 749 |
printf("M%xI", inb(K_RDWR)); |
| 750 |
return; |
| 751 |
} |
| 752 |
} |
| 753 |
|
| 754 |
scancode = inb(K_RDWR); |
| 755 |
if (scancode == K_EXTEND && kb_mode != KB_EVENT) { |
| 756 |
kd_extended = TRUE; |
| 757 |
goto done; |
| 758 |
} else if (scancode == K_RESEND) { |
| 759 |
kd_resend(); |
| 760 |
goto done; |
| 761 |
} else if (scancode == K_ACKSC) { |
| 762 |
kd_handle_ack(); |
| 763 |
goto done; |
| 764 |
} else if (kd_kbd_mouse && kd_kbd_magic(scancode)) { |
| 765 |
goto done; |
| 766 |
} else if (kdcheckmagic(scancode)) { |
| 767 |
goto done; |
| 768 |
} else if (kb_mode == KB_EVENT) { |
| 769 |
kd_enqsc(scancode); |
| 770 |
goto done; |
| 771 |
} /* else... */ |
| 772 |
|
| 773 |
if (scancode & K_UP) { |
| 774 |
up = TRUE; |
| 775 |
scancode &= ~K_UP; |
| 776 |
} |
| 777 |
if (scancode < NUMKEYS) { |
| 778 |
/* Lookup in map, then process. */ |
| 779 |
char_idx = kdstate2idx(kd_state, kd_extended); |
| 780 |
c = key_map[scancode][char_idx]; |
| 781 |
if (c == K_SCAN) { |
| 782 |
c = key_map[scancode][++char_idx]; |
| 783 |
set_kd_state(do_modifier(kd_state, c, up)); |
| 784 |
} else if (!up) { |
| 785 |
/* regular key-down */ |
| 786 |
unsigned int max; /* max index for char sequence */ |
| 787 |
|
| 788 |
max = char_idx + NUMOUTPUT; |
| 789 |
char_idx++; |
| 790 |
if (!kd_extended) { |
| 791 |
if (kd_state&KS_CLKED) { |
| 792 |
if (kd_isupper(c)) { |
| 793 |
c += ('a' - 'A'); |
| 794 |
max = char_idx; |
| 795 |
} |
| 796 |
else if (kd_islower(c)) { |
| 797 |
c -= ('a' - 'A'); |
| 798 |
max = char_idx; |
| 799 |
} |
| 800 |
} |
| 801 |
/* |
| 802 |
* Notice that even if the keypad is remapped, |
| 803 |
* NumLock only effects the keys that are |
| 804 |
* physically part of the keypad. Is this |
| 805 |
* The Right Thing? |
| 806 |
*/ |
| 807 |
if ((kd_state&KS_NLKED) && |
| 808 |
(((K_HOMESC) <= scancode) && |
| 809 |
(scancode <= (K_DELSC)))) { |
| 810 |
char_idx = CHARIDX(SHIFT_STATE); |
| 811 |
c = key_map[scancode][char_idx]; |
| 812 |
max = char_idx + NUMOUTPUT; |
| 813 |
char_idx++; |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
/* |
| 818 |
* here's where we actually put the char (or |
| 819 |
* char sequence, for function keys) onto the |
| 820 |
* input queue. |
| 821 |
*/ |
| 822 |
for ( ; (c != K_DONE) && (char_idx <= max); |
| 823 |
c = key_map[scancode][char_idx++]) { |
| 824 |
(*linesw[tp->t_line].l_rint)(c, tp); |
| 825 |
} |
| 826 |
kd_extended = FALSE; |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
done: |
| 831 |
return; |
| 832 |
} |
| 833 |
|
| 834 |
/* |
| 835 |
* kd_handle_ack: |
| 836 |
* |
| 837 |
* For pending commands, complete the command. For data bytes, |
| 838 |
* drop the ack on the floor. |
| 839 |
*/ |
| 840 |
void |
| 841 |
kd_handle_ack(void) |
| 842 |
{ |
| 843 |
switch (kd_ack) { |
| 844 |
case SET_LEDS: |
| 845 |
kd_setleds2(); |
| 846 |
kd_ack = DATA_ACK; |
| 847 |
break; |
| 848 |
case DATA_ACK: |
| 849 |
kd_ack = NOT_WAITING; |
| 850 |
break; |
| 851 |
case NOT_WAITING: |
| 852 |
printf("unexpected ACK from keyboard\n"); |
| 853 |
break; |
| 854 |
default: |
| 855 |
panic("bogus kd_ack\n"); |
| 856 |
break; |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
/* |
| 861 |
* kd_resend: |
| 862 |
* |
| 863 |
* Resend a missed keyboard command or data byte. |
| 864 |
*/ |
| 865 |
void |
| 866 |
kd_resend(void) |
| 867 |
{ |
| 868 |
if (kd_ack == NOT_WAITING) |
| 869 |
printf("unexpected RESEND from keyboard\n"); |
| 870 |
else |
| 871 |
kd_senddata(last_sent); |
| 872 |
} |
| 873 |
|
| 874 |
|
| 875 |
/* |
| 876 |
* do_modifier: |
| 877 |
* |
| 878 |
* Change keyboard state according to which modifier key and |
| 879 |
* whether it went down or up. |
| 880 |
* |
| 881 |
* input: the current state, the key, and the key's direction. |
| 882 |
* The key can be any key, not just a modifier key. |
| 883 |
* |
| 884 |
* output: the new state |
| 885 |
*/ |
| 886 |
int |
| 887 |
do_modifier( |
| 888 |
int state, |
| 889 |
Scancode c, |
| 890 |
boolean_t up) |
| 891 |
{ |
| 892 |
switch (c) { |
| 893 |
case (K_ALTSC): |
| 894 |
if (up) |
| 895 |
state &= ~KS_ALTED; |
| 896 |
else |
| 897 |
state |= KS_ALTED; |
| 898 |
kd_extended = FALSE; |
| 899 |
break; |
| 900 |
#ifndef ORC |
| 901 |
case (K_CLCKSC): |
| 902 |
#endif /* ORC */ |
| 903 |
case (K_CTLSC): |
| 904 |
if (up) |
| 905 |
state &= ~KS_CTLED; |
| 906 |
else |
| 907 |
state |= KS_CTLED; |
| 908 |
kd_extended = FALSE; |
| 909 |
break; |
| 910 |
#ifdef ORC |
| 911 |
case (K_CLCKSC): |
| 912 |
if (!up) |
| 913 |
state ^= KS_CLKED; |
| 914 |
break; |
| 915 |
#endif /* ORC */ |
| 916 |
case (K_NLCKSC): |
| 917 |
if (!up) |
| 918 |
state ^= KS_NLKED; |
| 919 |
break; |
| 920 |
case (K_LSHSC): |
| 921 |
case (K_RSHSC): |
| 922 |
if (up) |
| 923 |
state &= ~KS_SHIFTED; |
| 924 |
else |
| 925 |
state |= KS_SHIFTED; |
| 926 |
kd_extended = FALSE; |
| 927 |
break; |
| 928 |
} |
| 929 |
|
| 930 |
return(state); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
/* |
| 935 |
* kdcheckmagic: |
| 936 |
* |
| 937 |
* Check for magic keystrokes for invoking the debugger or |
| 938 |
* rebooting or ... |
| 939 |
* |
| 940 |
* input: an unprocessed scancode |
| 941 |
* |
| 942 |
* output: TRUE if a magic key combination was recognized and |
| 943 |
* processed. FALSE otherwise. |
| 944 |
* |
| 945 |
* side effects: |
| 946 |
* various actions possible, depending on which keys are |
| 947 |
* pressed. If the debugger is called, steps are taken |
| 948 |
* to ensure that the system doesn't think the magic keys |
| 949 |
* are still held down. |
| 950 |
*/ |
| 951 |
boolean_t |
| 952 |
kdcheckmagic(Scancode scancode) |
| 953 |
{ |
| 954 |
static int magic_state = KS_NORMAL; /* like kd_state */ |
| 955 |
boolean_t up = FALSE; |
| 956 |
|
| 957 |
if (scancode == 0x46) /* scroll lock */ |
| 958 |
/* if (scancode == 0x52) ** insert key */ |
| 959 |
{ |
| 960 |
kd_kbd_mouse = !kd_kbd_mouse; |
| 961 |
kd_kbd_magic_button = 0; |
| 962 |
return(TRUE); |
| 963 |
} |
| 964 |
if (scancode & K_UP) { |
| 965 |
up = TRUE; |
| 966 |
scancode &= ~K_UP; |
| 967 |
} |
| 968 |
magic_state = do_modifier(magic_state, scancode, up); |
| 969 |
|
| 970 |
if ((magic_state&(KS_CTLED|KS_ALTED)) == (KS_CTLED|KS_ALTED)) { |
| 971 |
switch (scancode) { |
| 972 |
#if MACH_KDB |
| 973 |
case K_dSC: /* ctl-alt-d */ |
| 974 |
kdb_kintr(); /* invoke debugger */ |
| 975 |
/* Returned from debugger, so reset kbd state. */ |
| 976 |
(void)SPLKD(); |
| 977 |
magic_state = KS_NORMAL; |
| 978 |
if (kb_mode == KB_ASCII) |
| 979 |
kd_state = KS_NORMAL; |
| 980 |
/* setting leds kills kbd */ |
| 981 |
else { |
| 982 |
kd_enqsc(K_ALTSC | K_UP); |
| 983 |
kd_enqsc(K_CTLSC | K_UP); |
| 984 |
kd_enqsc(K_dSC | K_UP); |
| 985 |
} |
| 986 |
return(TRUE); |
| 987 |
break; |
| 988 |
#endif /* MACH_KDB */ |
| 989 |
case K_DELSC: /* ctl-alt-del */ |
| 990 |
/* if rebootflag is on, reboot the system */ |
| 991 |
if (rebootflag) |
| 992 |
kdreboot(); |
| 993 |
break; |
| 994 |
} |
| 995 |
} |
| 996 |
return(FALSE); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
/* |
| 1001 |
* kdstate2idx: |
| 1002 |
* |
| 1003 |
* Return the value for the 2nd index into key_map that |
| 1004 |
* corresponds to the given state. |
| 1005 |
*/ |
| 1006 |
unsigned int |
| 1007 |
kdstate2idx(unsigned int state, /* bit vector, not a state index */ |
| 1008 |
boolean_t extended) |
| 1009 |
{ |
| 1010 |
int state_idx = NORM_STATE; |
| 1011 |
|
| 1012 |
if ((!extended) && state != KS_NORMAL) { |
| 1013 |
if ((state&(KS_SHIFTED|KS_ALTED)) == (KS_SHIFTED|KS_ALTED)) |
| 1014 |
state_idx = SHIFT_ALT; |
| 1015 |
/* CTRL should have higher priority than SHIFT. That |
| 1016 |
way, CTRL-SHIFT-2 and CTRL-2 produce the same keycode. |
| 1017 |
--Derek Upham 1997/06/25 */ |
| 1018 |
else if (state&KS_CTLED) |
| 1019 |
state_idx = CTRL_STATE; |
| 1020 |
else if (state&KS_SHIFTED) |
| 1021 |
state_idx = SHIFT_STATE; |
| 1022 |
else if (state&KS_ALTED) |
| 1023 |
state_idx = ALT_STATE; |
| 1024 |
} |
| 1025 |
|
| 1026 |
return (CHARIDX(state_idx)); |
| 1027 |
} |
| 1028 |
|
| 1029 |
/* |
| 1030 |
* kdstart: |
| 1031 |
* |
| 1032 |
* This function does the general processing of characters and other |
| 1033 |
* operations for the device driver. The device independent portion of |
| 1034 |
* the tty driver calls this routine (it's setup in kdinit) with a |
| 1035 |
* given command. That command is then processed, and control is passed |
| 1036 |
* back to the kernel. |
| 1037 |
* |
| 1038 |
* input: tty pointer 'tp', and command to execute 'cmd' |
| 1039 |
* |
| 1040 |
* output: command is executed |
| 1041 |
* |
| 1042 |
* Entered and left at spltty. Drops priority to spl0 to display character. |
| 1043 |
* ASSUMES that it is never called from interrupt-driven code. |
| 1044 |
*/ |
| 1045 |
void |
| 1046 |
kdstart(struct tty *tp) |
| 1047 |
{ |
| 1048 |
spl_t o_pri; |
| 1049 |
int ch; |
| 1050 |
|
| 1051 |
if (tp->t_state & TS_TTSTOP) |
| 1052 |
return; |
| 1053 |
for ( ; ; ) { |
| 1054 |
tp->t_state &= ~TS_BUSY; |
| 1055 |
if (tp->t_state & TS_TTSTOP) |
| 1056 |
break; |
| 1057 |
if ((tp->t_outq.c_cc <= 0) || (ch = getc(&tp->t_outq)) == -1) |
| 1058 |
break; |
| 1059 |
/* |
| 1060 |
* Drop priority for long screen updates. ttstart() calls us at |
| 1061 |
* spltty. |
| 1062 |
*/ |
| 1063 |
o_pri = splsoftclock(); /* block timeout */ |
| 1064 |
kd_putc_esc(ch); |
| 1065 |
splx(o_pri); |
| 1066 |
} |
| 1067 |
if (tp->t_outq.c_cc <= TTLOWAT(tp)) { |
| 1068 |
tt_write_wakeup(tp); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
/*ARGSUSED*/ |
| 1073 |
void |
| 1074 |
kdstop( |
| 1075 |
struct tty *tp, |
| 1076 |
int flags) |
| 1077 |
{ |
| 1078 |
/* |
| 1079 |
* do nothing - all characters are output by one call to |
| 1080 |
* kdstart. |
| 1081 |
*/ |
| 1082 |
} |
| 1083 |
|
| 1084 |
/* |
| 1085 |
* kdinit: |
| 1086 |
* |
| 1087 |
* This code initializes the structures and sets up the port registers |
| 1088 |
* for the console driver. |
| 1089 |
* |
| 1090 |
* Each bitmap-based graphics card is likely to require a unique |
| 1091 |
* way to determine the card's presence. The driver runs through |
| 1092 |
* each "special" card that it knows about and uses the first one |
| 1093 |
* that it finds. If it doesn't find any, it assumes that an |
| 1094 |
* EGA-like card is installed. |
| 1095 |
* |
| 1096 |
* input : None. Interrupts are assumed to be disabled |
| 1097 |
* output : Driver is initialized |
| 1098 |
* |
| 1099 |
*/ |
| 1100 |
void |
| 1101 |
kdinit(void) |
| 1102 |
{ |
| 1103 |
unsigned char k_comm; /* keyboard command byte */ |
| 1104 |
|
| 1105 |
if (kd_initialized) |
| 1106 |
return; |
| 1107 |
|
| 1108 |
esc_spt = esc_seq; |
| 1109 |
kd_attr = KA_NORMAL; |
| 1110 |
|
| 1111 |
kd_attrflags = 0; |
| 1112 |
kd_color = KA_NORMAL; |
| 1113 |
/* |
| 1114 |
* board specific initialization: set up globals and kd_dxxx |
| 1115 |
* pointers, and synch displayed cursor with logical cursor. |
| 1116 |
*/ |
| 1117 |
kd_xga_init(); |
| 1118 |
|
| 1119 |
/* get rid of any garbage in output buffer */ |
| 1120 |
if (inb(K_STATUS) & K_OBUF_FUL) |
| 1121 |
(void)inb(K_RDWR); |
| 1122 |
|
| 1123 |
kd_sendcmd(KC_CMD_READ); /* ask for the ctlr command byte */ |
| 1124 |
k_comm = kd_getdata(); |
| 1125 |
k_comm &= ~K_CB_DISBLE; /* clear keyboard disable bit */ |
| 1126 |
k_comm |= K_CB_ENBLIRQ; /* enable interrupt */ |
| 1127 |
kd_sendcmd(KC_CMD_WRITE); /* write new ctlr command byte */ |
| 1128 |
kd_senddata(k_comm); |
| 1129 |
unmask_irq(KBD_IRQ); |
| 1130 |
kd_initialized = TRUE; |
| 1131 |
|
| 1132 |
#if ENABLE_IMMEDIATE_CONSOLE |
| 1133 |
/* Now that we're set up, we no longer need or want the |
| 1134 |
immediate console. */ |
| 1135 |
{ |
| 1136 |
extern boolean_t immediate_console_enable; |
| 1137 |
immediate_console_enable = FALSE; |
| 1138 |
} |
| 1139 |
|
| 1140 |
/* The immediate console printed stuff at the bottom of the |
| 1141 |
screen rather than at the cursor position, so that's where |
| 1142 |
we should start. */ |
| 1143 |
kd_setpos(ONE_PAGE - ONE_LINE); printf("\n"); |
| 1144 |
#endif /* ENABLE_IMMEDIATE_CONSOLE */ |
| 1145 |
|
| 1146 |
cnsetleds(kd_state = KS_NORMAL); |
| 1147 |
/* clear the LEDs AFTER we |
| 1148 |
enable the keyboard controller. |
| 1149 |
This keeps NUM-LOCK from being |
| 1150 |
set on the NEC Versa. */ |
| 1151 |
|
| 1152 |
/* Allocate the input buffer. */ |
| 1153 |
ttychars(&kd_tty); |
| 1154 |
} |
| 1155 |
|
| 1156 |
/* |
| 1157 |
* kd_belloff: |
| 1158 |
* |
| 1159 |
* This routine shuts the bell off, by sending the appropriate code |
| 1160 |
* to the speaker port. |
| 1161 |
* |
| 1162 |
* input : None |
| 1163 |
* output : bell is turned off |
| 1164 |
* |
| 1165 |
*/ |
| 1166 |
static boolean_t kd_bellstate = FALSE; |
| 1167 |
|
| 1168 |
void |
| 1169 |
kd_belloff(void * param) |
| 1170 |
{ |
| 1171 |
unsigned char status; |
| 1172 |
|
| 1173 |
status = (inb(K_PORTB) & ~(K_SPKRDATA | K_ENABLETMR2)); |
| 1174 |
outb(K_PORTB, status); |
| 1175 |
kd_bellstate = FALSE; |
| 1176 |
return; |
| 1177 |
} |
| 1178 |
|
| 1179 |
|
| 1180 |
/* |
| 1181 |
* kd_bellon: |
| 1182 |
* |
| 1183 |
* This routine turns the bell on. |
| 1184 |
* |
| 1185 |
* input : None |
| 1186 |
* output : bell is turned on |
| 1187 |
* |
| 1188 |
*/ |
| 1189 |
void |
| 1190 |
kd_bellon(void) |
| 1191 |
{ |
| 1192 |
unsigned char status; |
| 1193 |
|
| 1194 |
/* program timer 2 */ |
| 1195 |
outb(K_TMRCTL, K_SELTMR2 | K_RDLDTWORD | K_TSQRWAVE | K_TBINARY); |
| 1196 |
outb(K_TMR2, 1500 & 0xff); /* LSB */ |
| 1197 |
outb(K_TMR2, (int)1500 >> 8); /* MSB */ |
| 1198 |
|
| 1199 |
/* start speaker - why must we turn on K_SPKRDATA? */ |
| 1200 |
status = (inb(K_PORTB)| K_ENABLETMR2 | K_SPKRDATA); |
| 1201 |
outb(K_PORTB, status); |
| 1202 |
return; |
| 1203 |
} |
| 1204 |
|
| 1205 |
/* |
| 1206 |
* |
| 1207 |
* Function kd_putc_esc(): |
| 1208 |
* |
| 1209 |
* This function puts a character on the screen, handling escape |
| 1210 |
* sequences. |
| 1211 |
* |
| 1212 |
* input : character to be displayed (or part of an escape code) |
| 1213 |
* output : character is displayed, or some action is taken |
| 1214 |
* |
| 1215 |
*/ |
| 1216 |
void |
| 1217 |
kd_putc_esc(u_char c) |
| 1218 |
{ |
| 1219 |
if (c == (K_ESC)) { |
| 1220 |
if (esc_spt == esc_seq) { |
| 1221 |
*(esc_spt++)=(K_ESC); |
| 1222 |
*(esc_spt) = '\0'; |
| 1223 |
} else { |
| 1224 |
kd_putc((K_ESC)); |
| 1225 |
esc_spt = esc_seq; |
| 1226 |
} |
| 1227 |
} else { |
| 1228 |
if (esc_spt - esc_seq) { |
| 1229 |
if (esc_spt - esc_seq > K_MAXESC - 1) |
| 1230 |
esc_spt = esc_seq; |
| 1231 |
else { |
| 1232 |
*(esc_spt++) = c; |
| 1233 |
*(esc_spt) = '\0'; |
| 1234 |
kd_parseesc(); |
| 1235 |
} |
| 1236 |
} else { |
| 1237 |
kd_putc(c); |
| 1238 |
} |
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
/* |
| 1243 |
* |
| 1244 |
* Function kd_putc(): |
| 1245 |
* |
| 1246 |
* This function simply puts a character on the screen. It does some |
| 1247 |
* special processing for linefeed, carriage return, backspace and |
| 1248 |
* the bell. |
| 1249 |
* |
| 1250 |
* input : character to be displayed |
| 1251 |
* output : character is displayed, or some action is taken |
| 1252 |
* |
| 1253 |
*/ |
| 1254 |
int sit_for_0 = 1; |
| 1255 |
|
| 1256 |
void |
| 1257 |
kd_putc(u_char ch) |
| 1258 |
{ |
| 1259 |
if ((!ch) && sit_for_0) |
| 1260 |
return; |
| 1261 |
|
| 1262 |
switch (ch) { |
| 1263 |
case ((K_LF)): |
| 1264 |
kd_down(); |
| 1265 |
break; |
| 1266 |
case ((K_CR)): |
| 1267 |
kd_cr(); |
| 1268 |
break; |
| 1269 |
case ((K_BS)): |
| 1270 |
kd_left(); |
| 1271 |
break; |
| 1272 |
case ((K_HT)): |
| 1273 |
kd_tab(); |
| 1274 |
break; |
| 1275 |
case ((K_BEL)): |
| 1276 |
/* |
| 1277 |
* Similar problem to K_BS here (behavior might depend |
| 1278 |
* on tty setting). Also check LF and CR. |
| 1279 |
*/ |
| 1280 |
if (!kd_bellstate) |
| 1281 |
{ |
| 1282 |
kd_bellon(); |
| 1283 |
timeout(kd_belloff, 0, hz/8 ); |
| 1284 |
kd_bellstate = TRUE; |
| 1285 |
} |
| 1286 |
break; |
| 1287 |
default: |
| 1288 |
(*kd_dput)(kd_curpos, ch, kd_attr); |
| 1289 |
kd_right(); |
| 1290 |
break; |
| 1291 |
} |
| 1292 |
return; |
| 1293 |
} |
| 1294 |
|
| 1295 |
|
| 1296 |
/* |
| 1297 |
* kd_setpos: |
| 1298 |
* |
| 1299 |
* This function sets the software and hardware cursor position |
| 1300 |
* on the screen, using device-specific code to actually move and |
| 1301 |
* display the cursor. |
| 1302 |
* |
| 1303 |
* input : position on (or off) screen to move the cursor to |
| 1304 |
* output : cursor position is updated, screen has been scrolled |
| 1305 |
* if necessary to bring cursor position back onto |
| 1306 |
* screen. |
| 1307 |
* |
| 1308 |
*/ |
| 1309 |
void |
| 1310 |
kd_setpos(csrpos_t newpos) |
| 1311 |
{ |
| 1312 |
if (newpos > ONE_PAGE) { |
| 1313 |
kd_scrollup(); |
| 1314 |
newpos = BOTTOM_LINE; |
| 1315 |
} |
| 1316 |
if (newpos < 0) { |
| 1317 |
kd_scrolldn(); |
| 1318 |
newpos = 0; |
| 1319 |
} |
| 1320 |
|
| 1321 |
(*kd_dsetcursor)(newpos); |
| 1322 |
} |
| 1323 |
|
| 1324 |
|
| 1325 |
/* |
| 1326 |
* kd_scrollup: |
| 1327 |
* |
| 1328 |
* This function scrolls the screen up one line using a DMA memory |
| 1329 |
* copy. |
| 1330 |
* |
| 1331 |
* input : None |
| 1332 |
* output : lines on screen appear to be shifted up one line |
| 1333 |
* |
| 1334 |
*/ |
| 1335 |
void |
| 1336 |
kd_scrollup(void) |
| 1337 |
{ |
| 1338 |
csrpos_t to; |
| 1339 |
csrpos_t from; |
| 1340 |
int count; |
| 1341 |
|
| 1342 |
/* scroll up */ |
| 1343 |
to = 0; |
| 1344 |
from = ONE_LINE; |
| 1345 |
count = (ONE_PAGE - ONE_LINE)/ONE_SPACE; |
| 1346 |
(*kd_dmvup)(from, to, count); |
| 1347 |
|
| 1348 |
/* clear bottom line */ |
| 1349 |
to = BOTTOM_LINE; |
| 1350 |
count = ONE_LINE/ONE_SPACE; |
| 1351 |
(*kd_dclear)(to, count, kd_attr); |
| 1352 |
return; |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
/* |
| 1357 |
* kd_scrolldn: |
| 1358 |
* |
| 1359 |
* Scrolls the characters on the screen down one line. |
| 1360 |
* |
| 1361 |
* input : None |
| 1362 |
* output : Lines on screen appear to be moved down one line |
| 1363 |
* |
| 1364 |
*/ |
| 1365 |
void |
| 1366 |
kd_scrolldn(void) |
| 1367 |
{ |
| 1368 |
csrpos_t to; |
| 1369 |
csrpos_t from; |
| 1370 |
int count; |
| 1371 |
|
| 1372 |
/* move down */ |
| 1373 |
to = ONE_PAGE - ONE_SPACE; |
| 1374 |
from = ONE_PAGE - ONE_LINE - ONE_SPACE; |
| 1375 |
count = (ONE_PAGE - ONE_LINE) / ONE_SPACE; |
| 1376 |
(*kd_dmvdown)(from, to, count); |
| 1377 |
|
| 1378 |
/* clear top line */ |
| 1379 |
to = 0; |
| 1380 |
count = ONE_LINE/ONE_SPACE; |
| 1381 |
(*kd_dclear)(to, count, kd_attr); |
| 1382 |
return; |
| 1383 |
|
| 1384 |
} |
| 1385 |
|
| 1386 |
|
| 1387 |
/* |
| 1388 |
* kd_parseesc: |
| 1389 |
* |
| 1390 |
* This routine begins the parsing of an escape sequence. It uses the |
| 1391 |
* escape sequence array and the escape spot pointer to handle |
| 1392 |
* asynchronous parsing of escape sequences. |
| 1393 |
* |
| 1394 |
* input : String of characters prepended by an escape |
| 1395 |
* output : Appropriate actions are taken depending on the string as |
| 1396 |
* defined by the ansi terminal specification |
| 1397 |
* |
| 1398 |
*/ |
| 1399 |
void |
| 1400 |
kd_parseesc(void) |
| 1401 |
{ |
| 1402 |
u_char *escp; |
| 1403 |
|
| 1404 |
escp = esc_seq + 1; /* point to char following ESC */ |
| 1405 |
switch(*(escp)) { |
| 1406 |
case 'c': |
| 1407 |
kd_cls(); |
| 1408 |
kd_home(); |
| 1409 |
esc_spt = esc_seq; /* reset spot in ESC sequence */ |
| 1410 |
break; |
| 1411 |
case '[': |
| 1412 |
escp++; |
| 1413 |
kd_parserest(escp); |
| 1414 |
break; |
| 1415 |
case '\0': |
| 1416 |
break; /* not enough info yet */ |
| 1417 |
default: |
| 1418 |
kd_putc(*escp); |
| 1419 |
esc_spt = esc_seq; /* inv sequence char, reset */ |
| 1420 |
break; |
| 1421 |
} |
| 1422 |
return; |
| 1423 |
|
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
/* kd_update_kd_attr: |
| 1428 |
* |
| 1429 |
* Updates kd_attr according to kd_attrflags and kd_color. |
| 1430 |
* This code has its origin from console.c and selection.h in |
| 1431 |
* linux 2.2 drivers/char/. |
| 1432 |
* Modified for GNU Mach by Marcus Brinkmann. |
| 1433 |
*/ |
| 1434 |
|
| 1435 |
#define reverse_video_char(a) (((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77)) |
| 1436 |
static void |
| 1437 |
kd_update_kd_attr(void) |
| 1438 |
{ |
| 1439 |
kd_attr = kd_color; |
| 1440 |
if (kd_attrflags & KAX_UNDERLINE) |
| 1441 |
kd_attr = (kd_attr & 0xf0) | KAX_COL_UNDERLINE; |
| 1442 |
else if (kd_attrflags & KAX_DIM) |
| 1443 |
kd_attr = (kd_attr & 0xf0) | KAX_COL_DIM; |
| 1444 |
if (kd_attrflags & KAX_REVERSE) |
| 1445 |
kd_attr = reverse_video_char(kd_attr); |
| 1446 |
if (kd_attrflags & KAX_BLINK) |
| 1447 |
kd_attr ^= 0x80; |
| 1448 |
if (kd_attrflags & KAX_BOLD) |
| 1449 |
kd_attr ^= 0x08; |
| 1450 |
} |
| 1451 |
|
| 1452 |
/* color_table added by Julio Merino to take proper color order. |
| 1453 |
* I get this code from Linux 2.2 source code in file: |
| 1454 |
* linux/drivers/char/console.c |
| 1455 |
*/ |
| 1456 |
unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, |
| 1457 |
8,12,10,14, 9,13,11,15 }; |
| 1458 |
/* |
| 1459 |
* kd_parserest: |
| 1460 |
* |
| 1461 |
* This function will complete the parsing of an escape sequence and |
| 1462 |
* call the appropriate support routine if it matches a character. This |
| 1463 |
* function could be greatly improved by using a function jump table, and |
| 1464 |
* removing this bulky switch statement. |
| 1465 |
* |
| 1466 |
* input : An string |
| 1467 |
* output : Appropriate action based on whether the string matches a |
| 1468 |
* sequence acceptable to the ansi terminal specification |
| 1469 |
* |
| 1470 |
*/ |
| 1471 |
void |
| 1472 |
kd_parserest(u_char *cp) |
| 1473 |
{ |
| 1474 |
int number[16], npar = 0, i; |
| 1475 |
csrpos_t newpos; |
| 1476 |
boolean_t question = FALSE; |
| 1477 |
boolean_t angle = FALSE; |
| 1478 |
|
| 1479 |
if (*cp == '?') { |
| 1480 |
question = TRUE; |
| 1481 |
cp++; |
| 1482 |
} else if (*cp == '<') { |
| 1483 |
angle = TRUE; |
| 1484 |
cp++; |
| 1485 |
} |
| 1486 |
|
| 1487 |
for(i=0;i<=15;i++) |
| 1488 |
number[i] = MACH_ATOI_DEFAULT; |
| 1489 |
|
| 1490 |
do { |
| 1491 |
cp += mach_atoi(cp, &number[npar]); |
| 1492 |
} while (*cp == ';' && ++npar <= 15 && cp++); |
| 1493 |
|
| 1494 |
if (question) { |
| 1495 |
/* \e[?... */ |
| 1496 |
switch(*cp) { |
| 1497 |
case '\0': |
| 1498 |
break; /* not enough yet */ |
| 1499 |
default: |
| 1500 |
if (*cp >= '@' && *cp <= '~') |
| 1501 |
{ |
| 1502 |
/* Unsupported sequence, just silently drop */ |
| 1503 |
} |
| 1504 |
else |
| 1505 |
{ |
| 1506 |
/* Odd sequence, print it */ |
| 1507 |
kd_putc(*cp); /* show inv character */ |
| 1508 |
} |
| 1509 |
esc_spt = esc_seq; /* inv entry, reset */ |
| 1510 |
break; |
| 1511 |
} |
| 1512 |
} else if (angle) { |
| 1513 |
/* \e[<... */ |
| 1514 |
switch(*cp) { |
| 1515 |
case '\0': |
| 1516 |
break; /* not enough yet */ |
| 1517 |
default: |
| 1518 |
if (*cp >= '@' && *cp <= '~') |
| 1519 |
{ |
| 1520 |
/* Unsupported sequence, just silently drop */ |
| 1521 |
} |
| 1522 |
else |
| 1523 |
{ |
| 1524 |
/* Odd sequence, print it */ |
| 1525 |
kd_putc(*cp); /* show inv character */ |
| 1526 |
} |
| 1527 |
esc_spt = esc_seq; /* inv entry, reset */ |
| 1528 |
break; |
| 1529 |
} |
| 1530 |
} else { |
| 1531 |
/* \e[... */ |
| 1532 |
switch(*cp) { |
| 1533 |
case 'm': |
| 1534 |
for (i=0;i<=npar;i++) |
| 1535 |
switch(number[i]) { |
| 1536 |
case MACH_ATOI_DEFAULT: |
| 1537 |
case 0: |
| 1538 |
kd_attrflags = 0; |
| 1539 |
kd_color = KA_NORMAL; |
| 1540 |
break; |
| 1541 |
case 1: |
| 1542 |
kd_attrflags |= KAX_BOLD; |
| 1543 |
kd_attrflags &= ~KAX_DIM; |
| 1544 |
break; |
| 1545 |
case 2: |
| 1546 |
kd_attrflags |= KAX_DIM; |
| 1547 |
kd_attrflags &= ~KAX_BOLD; |
| 1548 |
break; |
| 1549 |
case 4: |
| 1550 |
kd_attrflags |= KAX_UNDERLINE; |
| 1551 |
break; |
| 1552 |
case 5: |
| 1553 |
kd_attrflags |= KAX_BLINK; |
| 1554 |
break; |
| 1555 |
case 7: |
| 1556 |
kd_attrflags |= KAX_REVERSE; |
| 1557 |
break; |
| 1558 |
case 8: |
| 1559 |
kd_attrflags |= KAX_INVISIBLE; |
| 1560 |
break; |
| 1561 |
case 21: |
| 1562 |
case 22: |
| 1563 |
kd_attrflags &= ~(KAX_BOLD | KAX_DIM); |
| 1564 |
break; |
| 1565 |
case 24: |
| 1566 |
kd_attrflags &= ~KAX_UNDERLINE; |
| 1567 |
break; |
| 1568 |
case 25: |
| 1569 |
kd_attrflags &= ~KAX_BLINK; |
| 1570 |
break; |
| 1571 |
case 27: |
| 1572 |
kd_attrflags &= ~KAX_REVERSE; |
| 1573 |
break; |
| 1574 |
case 38: |
| 1575 |
kd_attrflags |= KAX_UNDERLINE; |
| 1576 |
kd_color = (kd_color & 0xf0) | (KA_NORMAL & 0x0f); |
| 1577 |
break; |
| 1578 |
case 39: |
| 1579 |
kd_attrflags &= ~KAX_UNDERLINE; |
| 1580 |
kd_color = (kd_color & 0xf0) | (KA_NORMAL & 0x0f); |
| 1581 |
break; |
| 1582 |
default: |
| 1583 |
if (number[i] >= 30 && number[i] <= 37) { |
| 1584 |
/* foreground color */ |
| 1585 |
kd_color = (kd_color & 0xf0) | color_table[(number[i] - 30)]; |
| 1586 |
} else if (number[i] >= 40 && number[i] <= 47) { |
| 1587 |
/* background color */ |
| 1588 |
kd_color = (kd_color & 0x0f) | (color_table[(number[i] - 40)] << 4); |
| 1589 |
} |
| 1590 |
break; |
| 1591 |
} |
| 1592 |
kd_update_kd_attr(); |
| 1593 |
esc_spt = esc_seq; |
| 1594 |
break; |
| 1595 |
case '@': |
| 1596 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1597 |
kd_insch(1); |
| 1598 |
else |
| 1599 |
kd_insch(number[0]); |
| 1600 |
esc_spt = esc_seq; |
| 1601 |
break; |
| 1602 |
case 'A': |
| 1603 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1604 |
kd_up(); |
| 1605 |
else |
| 1606 |
while (number[0]--) |
| 1607 |
kd_up(); |
| 1608 |
esc_spt = esc_seq; |
| 1609 |
break; |
| 1610 |
case 'B': |
| 1611 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1612 |
kd_down(); |
| 1613 |
else |
| 1614 |
while (number[0]--) |
| 1615 |
kd_down(); |
| 1616 |
esc_spt = esc_seq; |
| 1617 |
break; |
| 1618 |
case 'C': |
| 1619 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1620 |
kd_right(); |
| 1621 |
else |
| 1622 |
while (number[0]--) |
| 1623 |
kd_right(); |
| 1624 |
esc_spt = esc_seq; |
| 1625 |
break; |
| 1626 |
case 'D': |
| 1627 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1628 |
kd_left(); |
| 1629 |
else |
| 1630 |
while (number[0]--) |
| 1631 |
kd_left(); |
| 1632 |
esc_spt = esc_seq; |
| 1633 |
break; |
| 1634 |
case 'E': |
| 1635 |
kd_cr(); |
| 1636 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1637 |
kd_down(); |
| 1638 |
else |
| 1639 |
while (number[0]--) |
| 1640 |
kd_down(); |
| 1641 |
esc_spt = esc_seq; |
| 1642 |
break; |
| 1643 |
case 'F': |
| 1644 |
kd_cr(); |
| 1645 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1646 |
kd_up(); |
| 1647 |
else |
| 1648 |
while (number[0]--) |
| 1649 |
kd_up(); |
| 1650 |
esc_spt = esc_seq; |
| 1651 |
break; |
| 1652 |
case 'G': |
| 1653 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1654 |
number[0] = 0; |
| 1655 |
else |
| 1656 |
if (number[0] > 0) |
| 1657 |
--number[0]; /* because number[0] is from 1 */ |
| 1658 |
kd_setpos(BEG_OF_LINE(kd_curpos) + number[0] * ONE_SPACE); |
| 1659 |
esc_spt = esc_seq; |
| 1660 |
break; |
| 1661 |
case 'f': |
| 1662 |
case 'H': |
| 1663 |
if (number[0] == MACH_ATOI_DEFAULT && number[1] == MACH_ATOI_DEFAULT) |
| 1664 |
{ |
| 1665 |
kd_home(); |
| 1666 |
esc_spt = esc_seq; |
| 1667 |
break; |
| 1668 |
} |
| 1669 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1670 |
number[0] = 0; |
| 1671 |
else if (number[0] > 0) |
| 1672 |
--number[0]; /* numbered from 1 */ |
| 1673 |
newpos = (number[0] * ONE_LINE); /* setup row */ |
| 1674 |
if (number[1] == MACH_ATOI_DEFAULT) |
| 1675 |
number[1] = 0; |
| 1676 |
else if (number[1] > 0) |
| 1677 |
number[1]--; |
| 1678 |
newpos += (number[1] * ONE_SPACE); /* setup column */ |
| 1679 |
if (newpos < 0) |
| 1680 |
newpos = 0; /* upper left */ |
| 1681 |
if (newpos > ONE_PAGE) |
| 1682 |
newpos = (ONE_PAGE - ONE_SPACE); /* lower right */ |
| 1683 |
kd_setpos(newpos); |
| 1684 |
esc_spt = esc_seq; |
| 1685 |
break; /* done or not ready */ |
| 1686 |
case 'J': |
| 1687 |
switch(number[0]) { |
| 1688 |
case MACH_ATOI_DEFAULT: |
| 1689 |
case 0: |
| 1690 |
kd_cltobcur(); /* clears from current |
| 1691 |
pos to bottom. |
| 1692 |
*/ |
| 1693 |
break; |
| 1694 |
case 1: |
| 1695 |
kd_cltopcur(); /* clears from top to |
| 1696 |
current pos. |
| 1697 |
*/ |
| 1698 |
break; |
| 1699 |
case 2: |
| 1700 |
kd_cls(); |
| 1701 |
break; |
| 1702 |
default: |
| 1703 |
break; |
| 1704 |
} |
| 1705 |
esc_spt = esc_seq; /* reset it */ |
| 1706 |
break; |
| 1707 |
case 'K': |
| 1708 |
switch(number[0]) { |
| 1709 |
case MACH_ATOI_DEFAULT: |
| 1710 |
case 0: |
| 1711 |
kd_cltoecur(); /* clears from current |
| 1712 |
pos to eoln. |
| 1713 |
*/ |
| 1714 |
break; |
| 1715 |
case 1: |
| 1716 |
kd_clfrbcur(); /* clears from begin |
| 1717 |
of line to current |
| 1718 |
pos. |
| 1719 |
*/ |
| 1720 |
break; |
| 1721 |
case 2: |
| 1722 |
kd_eraseln(); /* clear entire line */ |
| 1723 |
break; |
| 1724 |
default: |
| 1725 |
break; |
| 1726 |
} |
| 1727 |
esc_spt = esc_seq; |
| 1728 |
break; |
| 1729 |
case 'L': |
| 1730 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1731 |
kd_insln(1); |
| 1732 |
else |
| 1733 |
kd_insln(number[0]); |
| 1734 |
esc_spt = esc_seq; |
| 1735 |
break; |
| 1736 |
case 'M': |
| 1737 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1738 |
kd_delln(1); |
| 1739 |
else |
| 1740 |
kd_delln(number[0]); |
| 1741 |
esc_spt = esc_seq; |
| 1742 |
break; |
| 1743 |
case 'P': |
| 1744 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1745 |
kd_delch(1); |
| 1746 |
else |
| 1747 |
kd_delch(number[0]); |
| 1748 |
esc_spt = esc_seq; |
| 1749 |
break; |
| 1750 |
case 'S': |
| 1751 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1752 |
kd_scrollup(); |
| 1753 |
else |
| 1754 |
while (number[0]--) |
| 1755 |
kd_scrollup(); |
| 1756 |
esc_spt = esc_seq; |
| 1757 |
break; |
| 1758 |
case 'T': |
| 1759 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1760 |
kd_scrolldn(); |
| 1761 |
else |
| 1762 |
while (number[0]--) |
| 1763 |
kd_scrolldn(); |
| 1764 |
esc_spt = esc_seq; |
| 1765 |
break; |
| 1766 |
case 'X': |
| 1767 |
if (number[0] == MACH_ATOI_DEFAULT) |
| 1768 |
kd_erase(1); |
| 1769 |
else |
| 1770 |
kd_erase(number[0]); |
| 1771 |
esc_spt = esc_seq; |
| 1772 |
break; |
| 1773 |
case '\0': |
| 1774 |
break; /* not enough yet */ |
| 1775 |
default: |
| 1776 |
if (*cp >= '@' && *cp <= '~') |
| 1777 |
{ |
| 1778 |
/* Unsupported sequence, just silently drop */ |
| 1779 |
} |
| 1780 |
else |
| 1781 |
{ |
| 1782 |
/* Odd sequence, print it */ |
| 1783 |
kd_putc(*cp); /* show inv character */ |
| 1784 |
} |
| 1785 |
esc_spt = esc_seq; /* inv entry, reset */ |
| 1786 |
break; |
| 1787 |
} |
| 1788 |
} |
| 1789 |
return; |
| 1790 |
} |
| 1791 |
|
| 1792 |
void |
| 1793 |
kd_tab(void) |
| 1794 |
{ |
| 1795 |
int i; |
| 1796 |
|
| 1797 |
for (i = 8 - (CURRENT_COLUMN(kd_curpos) % 8); i > 0; i--) { |
| 1798 |
kd_putc(' '); |
| 1799 |
} |
| 1800 |
|
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
/* |
| 1805 |
* kd_cls: |
| 1806 |
* |
| 1807 |
* This function clears the screen with spaces and the current attribute. |
| 1808 |
* |
| 1809 |
* input : None |
| 1810 |
* output : Screen is cleared |
| 1811 |
* |
| 1812 |
*/ |
| 1813 |
void |
| 1814 |
kd_cls(void) |
| 1815 |
{ |
| 1816 |
(*kd_dclear)(0, ONE_PAGE/ONE_SPACE, kd_attr); |
| 1817 |
return; |
| 1818 |
} |
| 1819 |
|
| 1820 |
|
| 1821 |
/* |
| 1822 |
* kd_home: |
| 1823 |
* |
| 1824 |
* This function will move the cursor to the home position on the screen, |
| 1825 |
* as well as set the internal cursor position (kd_curpos) to home. |
| 1826 |
* |
| 1827 |
* input : None |
| 1828 |
* output : Cursor position is moved |
| 1829 |
* |
| 1830 |
*/ |
| 1831 |
void |
| 1832 |
kd_home(void) |
| 1833 |
{ |
| 1834 |
kd_setpos(0); |
| 1835 |
return; |
| 1836 |
} |
| 1837 |
|
| 1838 |
|
| 1839 |
/* |
| 1840 |
* kd_up: |
| 1841 |
* |
| 1842 |
* This function moves the cursor up one line position. |
| 1843 |
* |
| 1844 |
* input : None |
| 1845 |
* output : Cursor moves up one line, or screen is scrolled |
| 1846 |
* |
| 1847 |
*/ |
| 1848 |
void |
| 1849 |
kd_up(void) |
| 1850 |
{ |
| 1851 |
if (kd_curpos < ONE_LINE) |
| 1852 |
kd_scrolldn(); |
| 1853 |
else |
| 1854 |
kd_setpos(kd_curpos - ONE_LINE); |
| 1855 |
return; |
| 1856 |
} |
| 1857 |
|
| 1858 |
|
| 1859 |
/* |
| 1860 |
* kd_down: |
| 1861 |
* |
| 1862 |
* This function moves the cursor down one line position. |
| 1863 |
* |
| 1864 |
* input : None |
| 1865 |
* output : Cursor moves down one line or the screen is scrolled |
| 1866 |
* |
| 1867 |
*/ |
| 1868 |
void |
| 1869 |
kd_down(void) |
| 1870 |
{ |
| 1871 |
if (kd_curpos >= (ONE_PAGE - ONE_LINE)) |
| 1872 |
kd_scrollup(); |
| 1873 |
else |
| 1874 |
kd_setpos(kd_curpos + ONE_LINE); |
| 1875 |
return; |
| 1876 |
} |
| 1877 |
|
| 1878 |
|
| 1879 |
/* |
| 1880 |
* kd_right: |
| 1881 |
* |
| 1882 |
* This function moves the cursor one position to the right. |
| 1883 |
* |
| 1884 |
* input : None |
| 1885 |
* output : Cursor moves one position to the right |
| 1886 |
* |
| 1887 |
*/ |
| 1888 |
void |
| 1889 |
kd_right(void) |
| 1890 |
{ |
| 1891 |
if (kd_curpos < (ONE_PAGE - ONE_SPACE)) |
| 1892 |
kd_setpos(kd_curpos + ONE_SPACE); |
| 1893 |
else { |
| 1894 |
kd_scrollup(); |
| 1895 |
kd_setpos(BEG_OF_LINE(kd_curpos)); |
| 1896 |
} |
| 1897 |
return; |
| 1898 |
} |
| 1899 |
|
| 1900 |
|
| 1901 |
/* |
| 1902 |
* kd_left: |
| 1903 |
* |
| 1904 |
* This function moves the cursor one position to the left. |
| 1905 |
* |
| 1906 |
* input : None |
| 1907 |
* output : Cursor moves one position to the left |
| 1908 |
* |
| 1909 |
*/ |
| 1910 |
void |
| 1911 |
kd_left(void) |
| 1912 |
{ |
| 1913 |
if (0 < kd_curpos) |
| 1914 |
kd_setpos(kd_curpos - ONE_SPACE); |
| 1915 |
return; |
| 1916 |
} |
| 1917 |
|
| 1918 |
|
| 1919 |
/* |
| 1920 |
* kd_cr: |
| 1921 |
* |
| 1922 |
* This function moves the cursor to the beginning of the current |
| 1923 |
* line. |
| 1924 |
* |
| 1925 |
* input : None |
| 1926 |
* output : Cursor moves to the beginning of the current line |
| 1927 |
* |
| 1928 |
*/ |
| 1929 |
void |
| 1930 |
kd_cr(void) |
| 1931 |
{ |
| 1932 |
kd_setpos(BEG_OF_LINE(kd_curpos)); |
| 1933 |
return; |
| 1934 |
} |
| 1935 |
|
| 1936 |
|
| 1937 |
/* |
| 1938 |
* kd_cltobcur: |
| 1939 |
* |
| 1940 |
* This function clears from the current cursor position to the bottom |
| 1941 |
* of the screen. |
| 1942 |
* |
| 1943 |
* input : None |
| 1944 |
* output : Screen is cleared from current cursor position to bottom |
| 1945 |
* |
| 1946 |
*/ |
| 1947 |
void |
| 1948 |
kd_cltobcur(void) |
| 1949 |
{ |
| 1950 |
csrpos_t start; |
| 1951 |
int count; |
| 1952 |
|
| 1953 |
start = kd_curpos; |
| 1954 |
count = (ONE_PAGE - kd_curpos)/ONE_SPACE; |
| 1955 |
(*kd_dclear)(start, count, kd_attr); |
| 1956 |
return; |
| 1957 |
} |
| 1958 |
|
| 1959 |
|
| 1960 |
/* |
| 1961 |
* kd_cltopcur: |
| 1962 |
* |
| 1963 |
* This function clears from the current cursor position to the top |
| 1964 |
* of the screen. |
| 1965 |
* |
| 1966 |
* input : None |
| 1967 |
* output : Screen is cleared from current cursor position to top |
| 1968 |
* |
| 1969 |
*/ |
| 1970 |
void |
| 1971 |
kd_cltopcur(void) |
| 1972 |
{ |
| 1973 |
int count; |
| 1974 |
|
| 1975 |
count = (kd_curpos + ONE_SPACE) / ONE_SPACE; |
| 1976 |
(*kd_dclear)(0, count, kd_attr); |
| 1977 |
return; |
| 1978 |
} |
| 1979 |
|
| 1980 |
|
| 1981 |
/* |
| 1982 |
* kd_cltoecur: |
| 1983 |
* |
| 1984 |
* This function clears from the current cursor position to eoln. |
| 1985 |
* |
| 1986 |
* input : None |
| 1987 |
* output : Line is cleared from current cursor position to eoln |
| 1988 |
* |
| 1989 |
*/ |
| 1990 |
void |
| 1991 |
kd_cltoecur(void) |
| 1992 |
{ |
| 1993 |
csrpos_t i; |
| 1994 |
csrpos_t hold; |
| 1995 |
|
| 1996 |
hold = BEG_OF_LINE(kd_curpos) + ONE_LINE; |
| 1997 |
for (i = kd_curpos; i < hold; i += ONE_SPACE) { |
| 1998 |
(*kd_dput)(i, K_SPACE, kd_attr); |
| 1999 |
} |
| 2000 |
} |
| 2001 |
|
| 2002 |
|
| 2003 |
/* |
| 2004 |
* kd_clfrbcur: |
| 2005 |
* |
| 2006 |
* This function clears from the beginning of the line to the current |
| 2007 |
* cursor position. |
| 2008 |
* |
| 2009 |
* input : None |
| 2010 |
* output : Line is cleared from beginning to current position |
| 2011 |
* |
| 2012 |
*/ |
| 2013 |
void |
| 2014 |
kd_clfrbcur(void) |
| 2015 |
{ |
| 2016 |
csrpos_t i; |
| 2017 |
|
| 2018 |
for (i = BEG_OF_LINE(kd_curpos); i <= kd_curpos; i += ONE_SPACE) { |
| 2019 |
(*kd_dput)(i, K_SPACE, kd_attr); |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
|
| 2024 |
/* |
| 2025 |
* kd_delln: |
| 2026 |
* |
| 2027 |
* This function deletes 'number' lines on the screen by effectively |
| 2028 |
* scrolling the lines up and replacing the old lines with spaces. |
| 2029 |
* |
| 2030 |
* input : number of lines to delete |
| 2031 |
* output : lines appear to be deleted |
| 2032 |
* |
| 2033 |
*/ |
| 2034 |
void |
| 2035 |
kd_delln(int number) |
| 2036 |
{ |
| 2037 |
csrpos_t to; |
| 2038 |
csrpos_t from; |
| 2039 |
int delbytes; /* num of bytes to delete */ |
| 2040 |
int count; /* num of words to move or fill */ |
| 2041 |
|
| 2042 |
if (number <= 0) |
| 2043 |
return; |
| 2044 |
|
| 2045 |
delbytes = number * ONE_LINE; |
| 2046 |
to = BEG_OF_LINE(kd_curpos); |
| 2047 |
if (to + delbytes >= ONE_PAGE) |
| 2048 |
delbytes = ONE_PAGE - to; |
| 2049 |
if (to + delbytes < ONE_PAGE) { |
| 2050 |
from = to + delbytes; |
| 2051 |
count = (ONE_PAGE - from) / ONE_SPACE; |
| 2052 |
(*kd_dmvup)(from, to, count); |
| 2053 |
} |
| 2054 |
|
| 2055 |
to = ONE_PAGE - delbytes; |
| 2056 |
count = delbytes / ONE_SPACE; |
| 2057 |
(*kd_dclear)(to, count, kd_attr); |
| 2058 |
return; |
| 2059 |
} |
| 2060 |
|
| 2061 |
|
| 2062 |
/* |
| 2063 |
* kd_insln: |
| 2064 |
* |
| 2065 |
* This function inserts a line above the current one by |
| 2066 |
* scrolling the current line and all the lines below it down. |
| 2067 |
* |
| 2068 |
* input : number of lines to insert |
| 2069 |
* output : New lines appear to be inserted |
| 2070 |
* |
| 2071 |
*/ |
| 2072 |
void |
| 2073 |
kd_insln(int number) |
| 2074 |
{ |
| 2075 |
csrpos_t to; |
| 2076 |
csrpos_t from; |
| 2077 |
int count; |
| 2078 |
csrpos_t top; /* top of block to be moved */ |
| 2079 |
int insbytes; /* num of bytes inserted */ |
| 2080 |
|
| 2081 |
if (number <= 0) |
| 2082 |
return; |
| 2083 |
|
| 2084 |
top = BEG_OF_LINE(kd_curpos); |
| 2085 |
insbytes = number * ONE_LINE; |
| 2086 |
if (top + insbytes > ONE_PAGE) |
| 2087 |
insbytes = ONE_PAGE - top; |
| 2088 |
to = ONE_PAGE - ONE_SPACE; |
| 2089 |
from = to - insbytes; |
| 2090 |
if (from > top) { |
| 2091 |
count = (from - top + ONE_SPACE) / ONE_SPACE; |
| 2092 |
(*kd_dmvdown)(from, to, count); |
| 2093 |
} |
| 2094 |
|
| 2095 |
count = insbytes / ONE_SPACE; |
| 2096 |
(*kd_dclear)(top, count, kd_attr); |
| 2097 |
return; |
| 2098 |
} |
| 2099 |
|
| 2100 |
|
| 2101 |
/* |
| 2102 |
* kd_delch: |
| 2103 |
* |
| 2104 |
* This function deletes a number of characters from the current |
| 2105 |
* position in the line. |
| 2106 |
* |
| 2107 |
* input : number of characters to delete |
| 2108 |
* output : characters appear to be deleted |
| 2109 |
* |
| 2110 |
*/ |
| 2111 |
void |
| 2112 |
kd_delch(int number) |
| 2113 |
{ |
| 2114 |
int count; /* num words moved/filled */ |
| 2115 |
int delbytes; /* bytes to delete */ |
| 2116 |
csrpos_t to; |
| 2117 |
csrpos_t from; |
| 2118 |
csrpos_t nextline; /* start of next line */ |
| 2119 |
|
| 2120 |
if (number <= 0) |
| 2121 |
return; |
| 2122 |
|
| 2123 |
nextline = BEG_OF_LINE(kd_curpos) + ONE_LINE; |
| 2124 |
delbytes = number * ONE_SPACE; |
| 2125 |
if (kd_curpos + delbytes > nextline) |
| 2126 |
delbytes = nextline - kd_curpos; |
| 2127 |
if (kd_curpos + delbytes < nextline) { |
| 2128 |
from = kd_curpos + delbytes; |
| 2129 |
to = kd_curpos; |
| 2130 |
count = (nextline - from) / ONE_SPACE; |
| 2131 |
(*kd_dmvup)(from, to, count); |
| 2132 |
} |
| 2133 |
|
| 2134 |
to = nextline - delbytes; |
| 2135 |
count = delbytes / ONE_SPACE; |
| 2136 |
(*kd_dclear)(to, count, kd_attr); |
| 2137 |
return; |
| 2138 |
|
| 2139 |
} |
| 2140 |
|
| 2141 |
|
| 2142 |
/* |
| 2143 |
* kd_erase: |
| 2144 |
* |
| 2145 |
* This function overwrites characters with a space starting with the |
| 2146 |
* current cursor position and ending in number spaces away. |
| 2147 |
* |
| 2148 |
* input : number of characters to erase |
| 2149 |
* output : characters appear to be blanked or erased |
| 2150 |
* |
| 2151 |
*/ |
| 2152 |
void |
| 2153 |
kd_erase(int number) |
| 2154 |
{ |
| 2155 |
csrpos_t i; |
| 2156 |
csrpos_t stop; |
| 2157 |
|
| 2158 |
stop = kd_curpos + (ONE_SPACE * number); |
| 2159 |
if (stop > BEG_OF_LINE(kd_curpos) + ONE_LINE) |
| 2160 |
stop = BEG_OF_LINE(kd_curpos) + ONE_LINE; |
| 2161 |
for (i = kd_curpos; i < stop; i += ONE_SPACE) { |
| 2162 |
(*kd_dput)(i, K_SPACE, kd_attr); |
| 2163 |
} |
| 2164 |
return; |
| 2165 |
} |
| 2166 |
|
| 2167 |
|
| 2168 |
/* |
| 2169 |
* kd_eraseln: |
| 2170 |
* |
| 2171 |
* This function erases the current line with spaces. |
| 2172 |
* |
| 2173 |
* input : None |
| 2174 |
* output : Current line is erased |
| 2175 |
* |
| 2176 |
*/ |
| 2177 |
void |
| 2178 |
kd_eraseln(void) |
| 2179 |
{ |
| 2180 |
csrpos_t i; |
| 2181 |
csrpos_t stop; |
| 2182 |
|
| 2183 |
stop = BEG_OF_LINE(kd_curpos) + ONE_LINE; |
| 2184 |
for (i = BEG_OF_LINE(kd_curpos); i < stop; i += ONE_SPACE) { |
| 2185 |
(*kd_dput)(i, K_SPACE, kd_attr); |
| 2186 |
} |
| 2187 |
return; |
| 2188 |
} |
| 2189 |
|
| 2190 |
|
| 2191 |
/* |
| 2192 |
* kd_insch: |
| 2193 |
* |
| 2194 |
* This function inserts a blank at the current cursor position |
| 2195 |
* and moves all other characters on the line over. |
| 2196 |
* |
| 2197 |
* input : number of blanks to insert |
| 2198 |
* output : Blanks are inserted at cursor position |
| 2199 |
* |
| 2200 |
*/ |
| 2201 |
void |
| 2202 |
kd_insch(int number) |
| 2203 |
{ |
| 2204 |
csrpos_t to; |
| 2205 |
csrpos_t from; |
| 2206 |
int count; |
| 2207 |
csrpos_t nextline; /* start of next line */ |
| 2208 |
int insbytes; /* num of bytes inserted */ |
| 2209 |
|
| 2210 |
if (number <= 0) |
| 2211 |
return; |
| 2212 |
|
| 2213 |
nextline = BEG_OF_LINE(kd_curpos) + ONE_LINE; |
| 2214 |
insbytes = number * ONE_SPACE; |
| 2215 |
if (kd_curpos + insbytes > nextline) |
| 2216 |
insbytes = nextline - kd_curpos; |
| 2217 |
|
| 2218 |
to = nextline - ONE_SPACE; |
| 2219 |
from = to - insbytes; |
| 2220 |
if (from >= kd_curpos) { |
| 2221 |
count = (from - kd_curpos + ONE_SPACE) / ONE_SPACE; |
| 2222 |
(*kd_dmvdown)(from, to, count); |
| 2223 |
} |
| 2224 |
|
| 2225 |
count = insbytes / ONE_SPACE; |
| 2226 |
(*kd_dclear)(kd_curpos, count, kd_attr); |
| 2227 |
return; |
| 2228 |
} |
| 2229 |
|
| 2230 |
|
| 2231 |
/* |
| 2232 |
* kd_isupper, kd_islower: |
| 2233 |
* |
| 2234 |
* Didn't want to include ctype.h because it brings in stdio.h, and |
| 2235 |
* only want to see if the darn character is uppercase or lowercase. |
| 2236 |
* |
| 2237 |
* input : Character 'c' |
| 2238 |
* output : isuuper gives TRUE if character is uppercase, islower |
| 2239 |
* returns TRUE if character is lowercase |
| 2240 |
* |
| 2241 |
*/ |
| 2242 |
boolean_t |
| 2243 |
kd_isupper(u_char c) |
| 2244 |
{ |
| 2245 |
if (('A' <= c) && (c <= 'Z')) |
| 2246 |
return(TRUE); |
| 2247 |
return(FALSE); |
| 2248 |
} |
| 2249 |
|
| 2250 |
boolean_t |
| 2251 |
kd_islower(u_char c) |
| 2252 |
{ |
| 2253 |
if (('a' <= c) && (c <= 'z')) |
| 2254 |
return(TRUE); |
| 2255 |
return(FALSE); |
| 2256 |
} |
| 2257 |
|
| 2258 |
/* |
| 2259 |
* kd_senddata: |
| 2260 |
* |
| 2261 |
* This function sends a byte to the keyboard RDWR port, but |
| 2262 |
* first waits until the input/output data buffer is clear before |
| 2263 |
* sending the data. Note that this byte can be either data or a |
| 2264 |
* keyboard command. |
| 2265 |
* |
| 2266 |
*/ |
| 2267 |
void |
| 2268 |
kd_senddata(unsigned char ch) |
| 2269 |
{ |
| 2270 |
while (inb(K_STATUS) & K_IBUF_FUL) |
| 2271 |
; |
| 2272 |
outb(K_RDWR, ch); |
| 2273 |
last_sent = ch; |
| 2274 |
return; |
| 2275 |
} |
| 2276 |
|
| 2277 |
/* |
| 2278 |
* kd_sendcmd: |
| 2279 |
* |
| 2280 |
* This function sends a command byte to the keyboard command |
| 2281 |
* port, but first waits until the input/output data buffer is |
| 2282 |
* clear before sending the data. |
| 2283 |
* |
| 2284 |
*/ |
| 2285 |
void |
| 2286 |
kd_sendcmd(unsigned char ch) |
| 2287 |
{ |
| 2288 |
while (inb(K_STATUS) & K_IBUF_FUL) |
| 2289 |
; |
| 2290 |
outb(K_CMD, ch); |
| 2291 |
return; |
| 2292 |
} |
| 2293 |
|
| 2294 |
|
| 2295 |
/* |
| 2296 |
* kd_getdata: |
| 2297 |
* |
| 2298 |
* This function returns a data byte from the keyboard RDWR port, |
| 2299 |
* after waiting until the port is flagged as having something to |
| 2300 |
* read. |
| 2301 |
*/ |
| 2302 |
unsigned char |
| 2303 |
kd_getdata(void) |
| 2304 |
{ |
| 2305 |
while ((inb(K_STATUS) & K_OBUF_FUL) == 0) |
| 2306 |
; |
| 2307 |
return(inb(K_RDWR)); |
| 2308 |
} |
| 2309 |
|
| 2310 |
void |
| 2311 |
kd_cmdreg_write(int val) |
| 2312 |
{ |
| 2313 |
int ch=KC_CMD_WRITE; |
| 2314 |
|
| 2315 |
while (inb(K_STATUS) & K_IBUF_FUL) |
| 2316 |
; |
| 2317 |
outb(K_CMD, ch); |
| 2318 |
|
| 2319 |
while (inb(K_STATUS) & K_IBUF_FUL) |
| 2320 |
; |
| 2321 |
outb(K_RDWR, val); |
| 2322 |
} |
| 2323 |
|
| 2324 |
void |
| 2325 |
kd_mouse_drain(void) |
| 2326 |
{ |
| 2327 |
int i; |
| 2328 |
while(inb(K_STATUS) & K_IBUF_FUL) |
| 2329 |
; |
| 2330 |
while((i = inb(K_STATUS)) & K_OBUF_FUL) |
| 2331 |
printf("kbd: S = %x D = %x\n", i, inb(K_RDWR)); |
| 2332 |
} |
| 2333 |
|
| 2334 |
/* |
| 2335 |
* set_kd_state: |
| 2336 |
* |
| 2337 |
* Set kd_state and update the keyboard status LEDs. |
| 2338 |
*/ |
| 2339 |
void |
| 2340 |
set_kd_state(int newstate) |
| 2341 |
{ |
| 2342 |
kd_state = newstate; |
| 2343 |
kd_setleds1(state2leds(newstate)); |
| 2344 |
} |
| 2345 |
|
| 2346 |
/* |
| 2347 |
* state2leds: |
| 2348 |
* |
| 2349 |
* Return a byte containing LED settings for the keyboard, given |
| 2350 |
* a state vector. |
| 2351 |
*/ |
| 2352 |
u_char |
| 2353 |
state2leds(int state) |
| 2354 |
{ |
| 2355 |
u_char result = 0; |
| 2356 |
|
| 2357 |
if (state & KS_NLKED) |
| 2358 |
result |= K_LED_NUMLK; |
| 2359 |
if (state & KS_CLKED) |
| 2360 |
result |= K_LED_CAPSLK; |
| 2361 |
return(result); |
| 2362 |
} |
| 2363 |
|
| 2364 |
/* |
| 2365 |
* kd_setleds[12]: |
| 2366 |
* |
| 2367 |
* Set the keyboard LEDs according to the given byte. |
| 2368 |
*/ |
| 2369 |
void |
| 2370 |
kd_setleds1(u_char val) |
| 2371 |
{ |
| 2372 |
if (kd_ack != NOT_WAITING) { |
| 2373 |
#ifdef MACH_KBD |
| 2374 |
printf("kd_setleds1: unexpected state (%d)\n", kd_ack); |
| 2375 |
#endif |
| 2376 |
return; |
| 2377 |
} |
| 2378 |
|
| 2379 |
kd_ack = SET_LEDS; |
| 2380 |
kd_nextled = val; |
| 2381 |
kd_senddata(K_CMD_LEDS); |
| 2382 |
} |
| 2383 |
|
| 2384 |
void |
| 2385 |
kd_setleds2(void) |
| 2386 |
{ |
| 2387 |
kd_senddata(kd_nextled); |
| 2388 |
} |
| 2389 |
|
| 2390 |
|
| 2391 |
/* |
| 2392 |
* cnsetleds: |
| 2393 |
* |
| 2394 |
* like kd_setleds[12], but not interrupt-based. |
| 2395 |
* Currently disabled because cngetc ignores caps lock and num |
| 2396 |
* lock anyway. |
| 2397 |
*/ |
| 2398 |
void |
| 2399 |
cnsetleds(u_char val) |
| 2400 |
{ |
| 2401 |
kd_senddata(K_CMD_LEDS); |
| 2402 |
(void)kd_getdata(); /* XXX - assume is ACK */ |
| 2403 |
kd_senddata(val); |
| 2404 |
(void)kd_getdata(); /* XXX - assume is ACK */ |
| 2405 |
} |
| 2406 |
|
| 2407 |
void |
| 2408 |
kdreboot(void) |
| 2409 |
{ |
| 2410 |
(*kd_dreset)(); |
| 2411 |
|
| 2412 |
#ifndef BROKEN_KEYBOARD_RESET |
| 2413 |
kd_sendcmd(0xFE); /* XXX - magic # */ |
| 2414 |
delay(1000000); /* wait to see if anything happens */ |
| 2415 |
#endif |
| 2416 |
/* |
| 2417 |
* If that didn't work, then we'll just have to try and |
| 2418 |
* do it the hard way. |
| 2419 |
*/ |
| 2420 |
cpu_shutdown(); |
| 2421 |
} |
| 2422 |
|
| 2423 |
static int which_button[] = {0, MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}; |
| 2424 |
static struct mouse_motion moved; |
| 2425 |
|
| 2426 |
int |
| 2427 |
kd_kbd_magic(int scancode) |
| 2428 |
{ |
| 2429 |
int new_button = 0; |
| 2430 |
|
| 2431 |
if (kd_kbd_mouse == 2) |
| 2432 |
printf("sc = %x\n", scancode); |
| 2433 |
|
| 2434 |
switch (scancode) { |
| 2435 |
/* f1 f2 f3 */ |
| 2436 |
case 0x3d: |
| 2437 |
new_button++; |
| 2438 |
case 0x3c: |
| 2439 |
new_button++; |
| 2440 |
case 0x3b: |
| 2441 |
new_button++; |
| 2442 |
if (kd_kbd_magic_button && (new_button != kd_kbd_magic_button)) { |
| 2443 |
/* down w/o up */ |
| 2444 |
mouse_button(which_button[kd_kbd_magic_button], 1); |
| 2445 |
} |
| 2446 |
/* normal */ |
| 2447 |
if (kd_kbd_magic_button == new_button) { |
| 2448 |
mouse_button(which_button[new_button], 1); |
| 2449 |
kd_kbd_magic_button = 0; |
| 2450 |
} else { |
| 2451 |
mouse_button(which_button[new_button], 0); |
| 2452 |
kd_kbd_magic_button = new_button; |
| 2453 |
} |
| 2454 |
break; |
| 2455 |
|
| 2456 |
/* right left up down */ |
| 2457 |
case 0x4d: |
| 2458 |
moved.mm_deltaX = kd_kbd_magic_scale; |
| 2459 |
moved.mm_deltaY = 0; |
| 2460 |
mouse_moved(moved); |
| 2461 |
break; |
| 2462 |
case 0x4b: |
| 2463 |
moved.mm_deltaX = -kd_kbd_magic_scale; |
| 2464 |
moved.mm_deltaY = 0; |
| 2465 |
mouse_moved(moved); |
| 2466 |
break; |
| 2467 |
case 0x48: |
| 2468 |
moved.mm_deltaX = 0; |
| 2469 |
moved.mm_deltaY = kd_kbd_magic_scale; |
| 2470 |
mouse_moved(moved); |
| 2471 |
break; |
| 2472 |
case 0x50: |
| 2473 |
moved.mm_deltaX = 0; |
| 2474 |
moved.mm_deltaY = -kd_kbd_magic_scale; |
| 2475 |
mouse_moved(moved); |
| 2476 |
break; |
| 2477 |
/* home pageup end pagedown */ |
| 2478 |
case 0x47: |
| 2479 |
moved.mm_deltaX = -2*kd_kbd_magic_scale; |
| 2480 |
moved.mm_deltaY = 2*kd_kbd_magic_scale; |
| 2481 |
mouse_moved(moved); |
| 2482 |
break; |
| 2483 |
case 0x49: |
| 2484 |
moved.mm_deltaX = 2*kd_kbd_magic_scale; |
| 2485 |
moved.mm_deltaY = 2*kd_kbd_magic_scale; |
| 2486 |
mouse_moved(moved); |
| 2487 |
break; |
| 2488 |
case 0x4f: |
| 2489 |
moved.mm_deltaX = -2*kd_kbd_magic_scale; |
| 2490 |
moved.mm_deltaY = -2*kd_kbd_magic_scale; |
| 2491 |
mouse_moved(moved); |
| 2492 |
break; |
| 2493 |
case 0x51: |
| 2494 |
moved.mm_deltaX = 2*kd_kbd_magic_scale; |
| 2495 |
moved.mm_deltaY = -2*kd_kbd_magic_scale; |
| 2496 |
mouse_moved(moved); |
| 2497 |
break; |
| 2498 |
|
| 2499 |
default: |
| 2500 |
return 0; |
| 2501 |
} |
| 2502 |
return 1; |
| 2503 |
} |
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
/* |
| 2508 |
* Code specific to EGA/CGA/VGA boards. This code relies on the fact |
| 2509 |
* that the "slam" functions take a word count and ONE_SPACE takes up |
| 2510 |
* 1 word. |
| 2511 |
*/ |
| 2512 |
#define SLAMBPW 2 /* bytes per word for "slam" fcns */ |
| 2513 |
|
| 2514 |
/* |
| 2515 |
* xga_getpos: |
| 2516 |
* |
| 2517 |
* This function returns the current hardware cursor position on the |
| 2518 |
* screen, scaled for compatibility with kd_curpos. |
| 2519 |
* |
| 2520 |
* input : None |
| 2521 |
* output : returns the value of cursor position on screen |
| 2522 |
* |
| 2523 |
*/ |
| 2524 |
static csrpos_t |
| 2525 |
xga_getpos(void) |
| 2526 |
|
| 2527 |
{ |
| 2528 |
unsigned char low; |
| 2529 |
unsigned char high; |
| 2530 |
short pos; |
| 2531 |
|
| 2532 |
outb(kd_index_reg, C_HIGH); |
| 2533 |
high = inb(kd_io_reg); |
| 2534 |
outb(kd_index_reg, C_LOW); |
| 2535 |
low = inb(kd_io_reg); |
| 2536 |
pos = (0xff&low) + ((unsigned short)high<<8); |
| 2537 |
|
| 2538 |
return(ONE_SPACE * (csrpos_t)pos); |
| 2539 |
} |
| 2540 |
|
| 2541 |
|
| 2542 |
/* |
| 2543 |
* kd_xga_init: |
| 2544 |
* |
| 2545 |
* Initialization specific to character-based graphics adapters. |
| 2546 |
*/ |
| 2547 |
void |
| 2548 |
kd_xga_init(void) |
| 2549 |
{ |
| 2550 |
unsigned char start, stop; |
| 2551 |
|
| 2552 |
#if 0 |
| 2553 |
unsigned char screen; |
| 2554 |
|
| 2555 |
/* XXX: this conflicts with read/writing the RTC */ |
| 2556 |
|
| 2557 |
outb(CMOS_ADDR, CMOS_EB); |
| 2558 |
screen = inb(CMOS_DATA) & CM_SCRMSK; |
| 2559 |
switch(screen) { |
| 2560 |
default: |
| 2561 |
printf("kd: unknown screen type, defaulting to EGA\n"); |
| 2562 |
/* FALLTHROUGH */ |
| 2563 |
case CM_EGA_VGA: |
| 2564 |
#endif |
| 2565 |
/* |
| 2566 |
* Here we'll want to query to bios on the card |
| 2567 |
* itself, because then we can figure out what |
| 2568 |
* type we have exactly. At this point we only |
| 2569 |
* know that the card is NOT CGA or MONO. For |
| 2570 |
* now, however, we assume backwards compatibility |
| 2571 |
* with 0xb8000 as the starting screen offset |
| 2572 |
* memory location for these cards. |
| 2573 |
* |
| 2574 |
*/ |
| 2575 |
|
| 2576 |
vid_start = (u_char *)phystokv(EGA_START); |
| 2577 |
kd_index_reg = EGA_IDX_REG; |
| 2578 |
kd_io_reg = EGA_IO_REG; |
| 2579 |
kd_lines = 25; |
| 2580 |
kd_cols = 80; |
| 2581 |
kd_bitmap_start = 0xa0000; /* XXX - magic numbers */ |
| 2582 |
{ /* XXX - is there a cleaner way to do this? */ |
| 2583 |
char *addr = (char *)phystokv(kd_bitmap_start); |
| 2584 |
int i; |
| 2585 |
for (i = 0; i < 200; i++) |
| 2586 |
addr[i] = 0x00; |
| 2587 |
} |
| 2588 |
#if 0 |
| 2589 |
break; |
| 2590 |
/* XXX: some buggy BIOSes report these... */ |
| 2591 |
case CM_CGA_40: |
| 2592 |
vid_start = (u_char *)phystokv(CGA_START); |
| 2593 |
kd_index_reg = CGA_IDX_REG; |
| 2594 |
kd_io_reg = CGA_IO_REG; |
| 2595 |
kd_lines = 25; |
| 2596 |
kd_cols = 40; |
| 2597 |
break; |
| 2598 |
case CM_CGA_80: |
| 2599 |
vid_start = (u_char *)phystokv(CGA_START); |
| 2600 |
kd_index_reg = CGA_IDX_REG; |
| 2601 |
kd_io_reg = CGA_IO_REG; |
| 2602 |
kd_lines = 25; |
| 2603 |
kd_cols = 80; |
| 2604 |
break; |
| 2605 |
case CM_MONO_80: |
| 2606 |
vid_start = (u_char *)phystokv(MONO_START); |
| 2607 |
kd_index_reg = MONO_IDX_REG; |
| 2608 |
kd_io_reg = MONO_IO_REG; |
| 2609 |
kd_lines = 25; |
| 2610 |
kd_cols = 80; |
| 2611 |
break; |
| 2612 |
} |
| 2613 |
#endif |
| 2614 |
|
| 2615 |
outb(kd_index_reg, C_START); |
| 2616 |
start = inb(kd_io_reg); |
| 2617 |
/* Make sure cursor is enabled */ |
| 2618 |
start &= ~0x20; |
| 2619 |
outb(kd_io_reg, start); |
| 2620 |
outb(kd_index_reg, C_STOP); |
| 2621 |
stop = inb(kd_io_reg); |
| 2622 |
|
| 2623 |
if (!start && !stop) |
| 2624 |
{ |
| 2625 |
/* Some firmware seem not to be initializing the cursor size |
| 2626 |
* any more... Try using standard values. */ |
| 2627 |
outb(kd_index_reg, C_START); |
| 2628 |
outb(kd_io_reg, 14); |
| 2629 |
outb(kd_index_reg, C_STOP); |
| 2630 |
outb(kd_io_reg, 15); |
| 2631 |
} |
| 2632 |
|
| 2633 |
kd_setpos(xga_getpos()); |
| 2634 |
} |
| 2635 |
|
| 2636 |
|
| 2637 |
/* |
| 2638 |
* charput: |
| 2639 |
* |
| 2640 |
* Put attributed character for EGA/CGA/etc. |
| 2641 |
*/ |
| 2642 |
static void |
| 2643 |
charput(csrpos_t pos, char ch, char chattr) |
| 2644 |
{ |
| 2645 |
*(vid_start + pos) = ch; |
| 2646 |
*(vid_start + pos + 1) = chattr; |
| 2647 |
} |
| 2648 |
|
| 2649 |
|
| 2650 |
/* |
| 2651 |
* charsetcursor: |
| 2652 |
* |
| 2653 |
* Set hardware cursor position for EGA/CGA/etc. |
| 2654 |
*/ |
| 2655 |
static void |
| 2656 |
charsetcursor(csrpos_t newpos) |
| 2657 |
{ |
| 2658 |
short curpos; /* position, not scaled for attribute byte */ |
| 2659 |
|
| 2660 |
curpos = newpos / ONE_SPACE; |
| 2661 |
outb(kd_index_reg, C_HIGH); |
| 2662 |
outb(kd_io_reg, (u_char)(curpos>>8)); |
| 2663 |
outb(kd_index_reg, C_LOW); |
| 2664 |
outb(kd_io_reg, (u_char)(curpos&0xff)); |
| 2665 |
|
| 2666 |
kd_curpos = newpos; |
| 2667 |
} |
| 2668 |
|
| 2669 |
|
| 2670 |
/* |
| 2671 |
* charmvup: |
| 2672 |
* |
| 2673 |
* Block move up for EGA/CGA/etc. |
| 2674 |
*/ |
| 2675 |
static void |
| 2676 |
charmvup(csrpos_t from, csrpos_t to, int count) |
| 2677 |
{ |
| 2678 |
kd_slmscu(vid_start+from, vid_start+to, count); |
| 2679 |
} |
| 2680 |
|
| 2681 |
|
| 2682 |
/* |
| 2683 |
* charmvdown: |
| 2684 |
* |
| 2685 |
* Block move down for EGA/CGA/etc. |
| 2686 |
*/ |
| 2687 |
static void |
| 2688 |
charmvdown(csrpos_t from, csrpos_t to, int count) |
| 2689 |
{ |
| 2690 |
kd_slmscd(vid_start+from, vid_start+to, count); |
| 2691 |
} |
| 2692 |
|
| 2693 |
|
| 2694 |
/* |
| 2695 |
* charclear: |
| 2696 |
* |
| 2697 |
* Fast clear for CGA/EGA/etc. |
| 2698 |
*/ |
| 2699 |
static void |
| 2700 |
charclear(csrpos_t to, int count, char chattr) |
| 2701 |
{ |
| 2702 |
kd_slmwd(vid_start+to, count, ((unsigned short)chattr<<8)+K_SPACE); |
| 2703 |
} |
| 2704 |
|
| 2705 |
|
| 2706 |
/* |
| 2707 |
* kd_noopreset: |
| 2708 |
* |
| 2709 |
* No-op reset routine for kd_dreset. |
| 2710 |
*/ |
| 2711 |
static void |
| 2712 |
kd_noopreset(void) |
| 2713 |
{ |
| 2714 |
} |
| 2715 |
|
| 2716 |
|
| 2717 |
/* |
| 2718 |
* bmpput: Copy a character from the font to the frame buffer. |
| 2719 |
*/ |
| 2720 |
|
| 2721 |
void |
| 2722 |
bmpput( |
| 2723 |
csrpos_t pos, |
| 2724 |
char ch, |
| 2725 |
char chattr) |
| 2726 |
{ |
| 2727 |
short xbit, ybit; /* u/l corner of char pos */ |
| 2728 |
u_char *to, *from; |
| 2729 |
short i, j; |
| 2730 |
u_char mask = (chattr == KA_REVERSE ? 0xff : 0); |
| 2731 |
|
| 2732 |
if ((u_char)ch >= chars_in_font) |
| 2733 |
ch = K_QUES; |
| 2734 |
|
| 2735 |
bmpch2bit(pos, &xbit, &ybit); |
| 2736 |
to = bit2fbptr(xbit, ybit); |
| 2737 |
from = font_start + ch * char_byte_width; |
| 2738 |
for (i = 0; i < char_height; ++i) { |
| 2739 |
for (j = 0; j < char_byte_width; ++j) |
| 2740 |
*(to+j) = *(from+j) ^ mask; |
| 2741 |
to += fb_byte_width; |
| 2742 |
from += font_byte_width; |
| 2743 |
} |
| 2744 |
} |
| 2745 |
|
| 2746 |
/* |
| 2747 |
* bmpcp1char: copy 1 char from one place in the frame buffer to |
| 2748 |
* another. |
| 2749 |
*/ |
| 2750 |
static void |
| 2751 |
bmpcp1char( |
| 2752 |
csrpos_t from, |
| 2753 |
csrpos_t to) |
| 2754 |
{ |
| 2755 |
short from_xbit, from_ybit; |
| 2756 |
short to_xbit, to_ybit; |
| 2757 |
u_char *tp, *fp; |
| 2758 |
short i, j; |
| 2759 |
|
| 2760 |
bmpch2bit(from, &from_xbit, &from_ybit); |
| 2761 |
bmpch2bit(to, &to_xbit, &to_ybit); |
| 2762 |
|
| 2763 |
tp = bit2fbptr(to_xbit, to_ybit); |
| 2764 |
fp = bit2fbptr(from_xbit, from_ybit); |
| 2765 |
|
| 2766 |
for (i = 0; i < char_height; ++i) { |
| 2767 |
for (j = 0; j < char_byte_width; ++j) |
| 2768 |
*(tp+j) = *(fp+j); |
| 2769 |
tp += fb_byte_width; |
| 2770 |
fp += fb_byte_width; |
| 2771 |
} |
| 2772 |
} |
| 2773 |
|
| 2774 |
/* |
| 2775 |
* bmpvmup: Copy a block of character positions upwards. |
| 2776 |
*/ |
| 2777 |
void |
| 2778 |
bmpmvup( |
| 2779 |
csrpos_t from, |
| 2780 |
csrpos_t to, |
| 2781 |
int count) |
| 2782 |
{ |
| 2783 |
short from_xbit, from_ybit; |
| 2784 |
short to_xbit, to_ybit; |
| 2785 |
short i; |
| 2786 |
|
| 2787 |
bmpch2bit(from, &from_xbit, &from_ybit); |
| 2788 |
bmpch2bit(to, &to_xbit, &to_ybit); |
| 2789 |
|
| 2790 |
if (from_xbit == xstart && to_xbit == xstart && count%kd_cols == 0) { |
| 2791 |
/* fast case - entire lines */ |
| 2792 |
from_xbit = to_xbit = 0; |
| 2793 |
bmppaintcsr(kd_curpos, char_black); /* don't copy cursor */ |
| 2794 |
count /= kd_cols; /* num lines */ |
| 2795 |
count *= fb_byte_width * (char_height+cursor_height); |
| 2796 |
kd_slmscu(bit2fbptr(from_xbit, from_ybit), |
| 2797 |
bit2fbptr(to_xbit, to_ybit), |
| 2798 |
count/SLAMBPW); |
| 2799 |
bmppaintcsr(kd_curpos, char_white); |
| 2800 |
} else { |
| 2801 |
/* slow case - everything else */ |
| 2802 |
for (i=0; i < count; ++i) { |
| 2803 |
bmpcp1char(from, to); |
| 2804 |
from += ONE_SPACE; |
| 2805 |
to += ONE_SPACE; |
| 2806 |
} |
| 2807 |
} |
| 2808 |
} |
| 2809 |
|
| 2810 |
/* |
| 2811 |
* bmpmvdown: copy a block of characters down. |
| 2812 |
*/ |
| 2813 |
void |
| 2814 |
bmpmvdown( |
| 2815 |
csrpos_t from, |
| 2816 |
csrpos_t to, |
| 2817 |
int count) |
| 2818 |
{ |
| 2819 |
short from_xbit, from_ybit; |
| 2820 |
short to_xbit, to_ybit; |
| 2821 |
short i; |
| 2822 |
|
| 2823 |
bmpch2bit(from, &from_xbit, &from_ybit); |
| 2824 |
bmpch2bit(to, &to_xbit, &to_ybit); |
| 2825 |
|
| 2826 |
if (from_xbit == xstart + (kd_cols - 1) * char_width |
| 2827 |
&& to_xbit == xstart + (kd_cols - 1) * char_width |
| 2828 |
&& count%kd_cols == 0) { |
| 2829 |
/* fast case - entire lines*/ |
| 2830 |
from_xbit = to_xbit = 8 * (fb_byte_width - 1); |
| 2831 |
/* last byte on line */ |
| 2832 |
bmppaintcsr(kd_curpos, char_black); /* don't copy cursor */ |
| 2833 |
count /= kd_cols; /* num lines */ |
| 2834 |
count *= fb_byte_width * (char_height+cursor_height); |
| 2835 |
kd_slmscd(bit2fbptr(from_xbit, from_ybit), |
| 2836 |
bit2fbptr(to_xbit, to_ybit), |
| 2837 |
count/SLAMBPW); |
| 2838 |
bmppaintcsr(kd_curpos, char_white); |
| 2839 |
} else { |
| 2840 |
/* slow case - everything else */ |
| 2841 |
for (i=0; i < count; ++i) { |
| 2842 |
bmpcp1char(from, to); |
| 2843 |
from -= ONE_SPACE; |
| 2844 |
to -= ONE_SPACE; |
| 2845 |
} |
| 2846 |
} |
| 2847 |
} |
| 2848 |
|
| 2849 |
/* |
| 2850 |
* bmpclear: clear one or more character positions. |
| 2851 |
*/ |
| 2852 |
void |
| 2853 |
bmpclear( |
| 2854 |
csrpos_t to, /* 1st char */ |
| 2855 |
int count, /* num chars */ |
| 2856 |
char chattr) /* reverse or normal */ |
| 2857 |
{ |
| 2858 |
short i; |
| 2859 |
u_short clearval; |
| 2860 |
u_short clearbyte = (chattr == KA_REVERSE ? char_white : char_black); |
| 2861 |
|
| 2862 |
clearval = (u_short)(clearbyte<<8) + clearbyte; |
| 2863 |
if (to == 0 && count >= kd_lines * kd_cols) { |
| 2864 |
/* fast case - entire page */ |
| 2865 |
kd_slmwd(vid_start, (fb_byte_width * fb_height)/SLAMBPW, |
| 2866 |
clearval); |
| 2867 |
} else |
| 2868 |
/* slow case */ |
| 2869 |
for (i = 0; i < count; ++i) { |
| 2870 |
bmpput(to, K_SPACE, chattr); |
| 2871 |
to += ONE_SPACE; |
| 2872 |
} |
| 2873 |
} |
| 2874 |
|
| 2875 |
/* |
| 2876 |
* bmpsetcursor: update the display and set the logical cursor. |
| 2877 |
*/ |
| 2878 |
void |
| 2879 |
bmpsetcursor(csrpos_t pos) |
| 2880 |
{ |
| 2881 |
/* erase old cursor & paint new one */ |
| 2882 |
bmppaintcsr(kd_curpos, char_black); |
| 2883 |
bmppaintcsr(pos, char_white); |
| 2884 |
kd_curpos = pos; |
| 2885 |
} |
| 2886 |
|
| 2887 |
/* |
| 2888 |
* bmppaintcsr: paint cursor bits. |
| 2889 |
*/ |
| 2890 |
void |
| 2891 |
bmppaintcsr( |
| 2892 |
csrpos_t pos, |
| 2893 |
u_char val) |
| 2894 |
{ |
| 2895 |
short xbit, ybit; |
| 2896 |
u_char *cp; |
| 2897 |
short line, byte; |
| 2898 |
|
| 2899 |
bmpch2bit(pos, &xbit, &ybit); |
| 2900 |
ybit += char_height; /* position at bottom of line */ |
| 2901 |
cp = bit2fbptr(xbit, ybit); |
| 2902 |
for (line = 0; line < cursor_height; ++line) { |
| 2903 |
for (byte = 0; byte < char_byte_width; ++byte) |
| 2904 |
*(cp+byte) = val; |
| 2905 |
cp += fb_byte_width; |
| 2906 |
} |
| 2907 |
} |
| 2908 |
|
| 2909 |
/* |
| 2910 |
* bmpch2bit: convert character position to x and y bit addresses. |
| 2911 |
* (0, 0) is the upper left corner. |
| 2912 |
*/ |
| 2913 |
void |
| 2914 |
bmpch2bit( |
| 2915 |
csrpos_t pos, |
| 2916 |
short *xb, |
| 2917 |
short *yb) /* x, y bit positions, u/l corner */ |
| 2918 |
{ |
| 2919 |
short xch, ych; |
| 2920 |
|
| 2921 |
xch = (pos / ONE_SPACE) % kd_cols; |
| 2922 |
ych = pos / (ONE_SPACE * kd_cols); |
| 2923 |
*xb = xstart + xch * char_width; |
| 2924 |
*yb = ystart + ych * (char_height + cursor_height); |
| 2925 |
} |
| 2926 |
|
| 2927 |
/* |
| 2928 |
* bit2fbptr: return a pointer into the frame buffer corresponding to |
| 2929 |
* the bit address (x, y). |
| 2930 |
* Assumes that xb and yb don't point to the middle of a |
| 2931 |
* byte. |
| 2932 |
*/ |
| 2933 |
u_char * |
| 2934 |
bit2fbptr( |
| 2935 |
short xb, |
| 2936 |
short yb) |
| 2937 |
{ |
| 2938 |
return(vid_start + yb * fb_byte_width + xb/8); |
| 2939 |
} |
| 2940 |
|
| 2941 |
|
| 2942 |
/* |
| 2943 |
* console stuff |
| 2944 |
*/ |
| 2945 |
|
| 2946 |
/* |
| 2947 |
* XXX we assume that pcs *always* have a console |
| 2948 |
*/ |
| 2949 |
int |
| 2950 |
kdcnprobe(struct consdev *cp) |
| 2951 |
{ |
| 2952 |
int maj, unit, pri; |
| 2953 |
|
| 2954 |
maj = 0; |
| 2955 |
unit = 0; |
| 2956 |
pri = CN_INTERNAL; |
| 2957 |
|
| 2958 |
cp->cn_dev = makedev(maj, unit); |
| 2959 |
cp->cn_pri = pri; |
| 2960 |
return 0; |
| 2961 |
} |
| 2962 |
|
| 2963 |
int |
| 2964 |
kdcninit(struct consdev *cp) |
| 2965 |
{ |
| 2966 |
kdinit(); |
| 2967 |
return 0; |
| 2968 |
} |
| 2969 |
|
| 2970 |
int |
| 2971 |
kdcngetc(dev_t dev, int wait) |
| 2972 |
{ |
| 2973 |
if (wait) { |
| 2974 |
int c; |
| 2975 |
while ((c = kdcnmaygetc()) < 0) |
| 2976 |
continue; |
| 2977 |
return c; |
| 2978 |
} |
| 2979 |
else |
| 2980 |
return kdcnmaygetc(); |
| 2981 |
} |
| 2982 |
|
| 2983 |
int |
| 2984 |
kdcnputc(dev_t dev, int c) |
| 2985 |
{ |
| 2986 |
if (!kd_initialized) |
| 2987 |
return -1; |
| 2988 |
|
| 2989 |
/* Note that tab is handled in kd_putc */ |
| 2990 |
if (c == '\n') |
| 2991 |
kd_putc('\r'); |
| 2992 |
kd_putc_esc(c); |
| 2993 |
|
| 2994 |
return 0; |
| 2995 |
} |
| 2996 |
|
| 2997 |
/* |
| 2998 |
* kdcnmaygetc: |
| 2999 |
* |
| 3000 |
* Get one character using polling, rather than interrupts. Used |
| 3001 |
* by the kernel debugger. Note that Caps Lock is ignored. |
| 3002 |
* Normally this routine is called with interrupts already |
| 3003 |
* disabled, but there is code in place so that it will be more |
| 3004 |
* likely to work even if interrupts are turned on. |
| 3005 |
*/ |
| 3006 |
int |
| 3007 |
kdcnmaygetc(void) |
| 3008 |
{ |
| 3009 |
unsigned char c; |
| 3010 |
unsigned char scancode; |
| 3011 |
unsigned int char_idx; |
| 3012 |
#ifdef notdef |
| 3013 |
spl_t o_pri; |
| 3014 |
#endif |
| 3015 |
boolean_t up; |
| 3016 |
|
| 3017 |
if (! kd_initialized) |
| 3018 |
return -1; |
| 3019 |
|
| 3020 |
kd_extended = FALSE; |
| 3021 |
#ifdef notdef |
| 3022 |
o_pri = splhi(); |
| 3023 |
#endif |
| 3024 |
for ( ; ; ) { |
| 3025 |
if (!(inb(K_STATUS) & K_OBUF_FUL)) |
| 3026 |
return -1; |
| 3027 |
|
| 3028 |
up = FALSE; |
| 3029 |
/* |
| 3030 |
* We'd come here for mouse events in debugger, if |
| 3031 |
* the mouse were on. |
| 3032 |
*/ |
| 3033 |
if ((inb(K_STATUS) & 0x20) == 0x20) { |
| 3034 |
printf("M%xP", inb(K_RDWR)); |
| 3035 |
continue; |
| 3036 |
} |
| 3037 |
scancode = inb(K_RDWR); |
| 3038 |
/* |
| 3039 |
* Handle extend modifier and |
| 3040 |
* ack/resend, otherwise we may never receive |
| 3041 |
* a key. |
| 3042 |
*/ |
| 3043 |
if (scancode == K_EXTEND) { |
| 3044 |
kd_extended = TRUE; |
| 3045 |
continue; |
| 3046 |
} else if (scancode == K_RESEND) { |
| 3047 |
printf("cngetc: resend"); |
| 3048 |
kd_resend(); |
| 3049 |
continue; |
| 3050 |
} else if (scancode == K_ACKSC) { |
| 3051 |
printf("cngetc: handle_ack"); |
| 3052 |
kd_handle_ack(); |
| 3053 |
continue; |
| 3054 |
} |
| 3055 |
if (scancode & K_UP) { |
| 3056 |
up = TRUE; |
| 3057 |
scancode &= ~K_UP; |
| 3058 |
} |
| 3059 |
if (kd_kbd_mouse) |
| 3060 |
kd_kbd_magic(scancode); |
| 3061 |
if (scancode < NUMKEYS) { |
| 3062 |
/* Lookup in map, then process. */ |
| 3063 |
char_idx = kdstate2idx(kd_state, kd_extended); |
| 3064 |
c = key_map[scancode][char_idx]; |
| 3065 |
if (c == K_SCAN) { |
| 3066 |
c = key_map[scancode][++char_idx]; |
| 3067 |
kd_state = do_modifier(kd_state, c, up); |
| 3068 |
#ifdef notdef |
| 3069 |
cnsetleds(state2leds(kd_state)); |
| 3070 |
#endif |
| 3071 |
} else if (! up |
| 3072 |
&& c == K_ESC |
| 3073 |
&& key_map[scancode][char_idx+1] == 0x5b) { |
| 3074 |
/* As a convenience for the nice |
| 3075 |
people using our debugger, remap |
| 3076 |
some keys to the readline-like |
| 3077 |
shortcuts supported by dde. |
| 3078 |
|
| 3079 |
XXX This is a workaround for the |
| 3080 |
limited kernel getchar interface. |
| 3081 |
It is only used by the debugger. */ |
| 3082 |
c = key_map[scancode][char_idx+2]; |
| 3083 |
switch (c) { |
| 3084 |
#define _MAP(A,B,C) (C) |
| 3085 |
#define MAP(T) _MAP(T) |
| 3086 |
#define CTRL(c) ((c) & 0x1f) |
| 3087 |
case MAP(K_HOME): c = CTRL('a'); break; |
| 3088 |
case MAP(K_UA): c = CTRL('p'); break; |
| 3089 |
case MAP(K_LA): c = CTRL('b'); break; |
| 3090 |
case MAP(K_RA): c = CTRL('f'); break; |
| 3091 |
case MAP(K_DA): c = CTRL('n'); break; |
| 3092 |
case MAP(K_END): c = CTRL('e'); break; |
| 3093 |
/* delete */ |
| 3094 |
case 0x39: c = CTRL('d'); break; |
| 3095 |
#undef CTRL |
| 3096 |
#undef MAP |
| 3097 |
#undef _MAP |
| 3098 |
default: |
| 3099 |
/* Retain the old behavior. */ |
| 3100 |
c = K_ESC; |
| 3101 |
} |
| 3102 |
|
| 3103 |
return(c); |
| 3104 |
} else if (!up) { |
| 3105 |
/* regular key-down */ |
| 3106 |
if (c == K_CR) |
| 3107 |
c = K_LF; |
| 3108 |
#ifdef notdef |
| 3109 |
splx(o_pri); |
| 3110 |
#endif |
| 3111 |
return(c & 0177); |
| 3112 |
} |
| 3113 |
} |
| 3114 |
} |
| 3115 |
} |