--- Gnu-Mach/i386/i386at/kd.c 2020/09/02 04:36:58 1.1 +++ Gnu-Mach/i386/i386at/kd.c 2020/09/02 04:46:53 1.1.1.4 @@ -1,34 +1,34 @@ -/* +/* * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ -/* +/* * Olivetti Mach Console driver v0.0 * Copyright Ing. C. Olivetti & C. S.p.A. 1988, 1989 * All rights reserved. * - */ + */ /* Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc., Cupertino, California. @@ -76,46 +76,32 @@ WITH THE USE OR PERFORMANCE OF THIS SOFT /* $ Header: $ */ -#include - #include -#include +#include +#include +#include #include #include #include #include /* for struct uio (!) */ -#include #include -#include "vm_param.h" +#include +#include +#include #include +#include #include #include +#include +#include #include -#include - -#include -#if NBLIT > 0 -#include -#else -#define blit_present() FALSE -#define blit_init() /* nothing */ -#endif - -#include -#if NEVC > 0 -int evc1init(); -#else -#define evc1init() FALSE -#endif +#include +#include #define DEBUG 1 /* export feep() */ -#define DEFAULT -1 /* see kd_atoi */ - void kd_enqsc(); /* enqueues a scancode */ -void timeout(); - #if 0 #define BROKEN_KEYBOARD_RESET #endif @@ -127,12 +113,9 @@ static void charput(), charmvup(), charm static void kd_noopreset(); boolean_t kdcheckmagic(); -int kdcnprobe(struct consdev *cp); -int kdcninit(struct consdev *cp); -int kdcngetc(dev_t dev, int wait); -int kdcnputc(dev_t dev, int c); +int do_modifier (int, Scancode, boolean_t); -/* +/* * These routines define the interface to the device-specific layer. * See kdsoft.h for a more complete description of what each routine does. */ @@ -154,15 +137,17 @@ unsigned char kd_getdata(), state2leds() */ vm_offset_t kd_bitmap_start = (vm_offset_t)0xa0000; /* XXX - put in kd.h */ -u_char *vid_start = (u_char *)EGA_START; +u_char *vid_start = (u_char *)EGA_START; /* VM start of video RAM or frame buffer */ csrpos_t kd_curpos = 0; /* set indirectly by kd_setpos--see kdsoft.h */ short kd_lines = 25; short kd_cols = 80; char kd_attr = KA_NORMAL; /* current attribute */ +char kd_color = KA_NORMAL; +char kd_attrflags = 0; /* Not reverse, underline, blink */ -/* - * kd_state shows the state of the modifier keys (ctrl, caps lock, +/* + * kd_state shows the state of the modifier keys (ctrl, caps lock, * etc.) It should normally be changed by calling set_kd_state(), so * that the keyboard status LEDs are updated correctly. */ @@ -176,18 +161,18 @@ int kd_kbd_mouse = 0; int kd_kbd_magic_scale = 6; int kd_kbd_magic_button = 0; -/* - * Some keyboard commands work by sending a command, waiting for an - * ack (handled by kdintr), then sending data, which generates a +/* + * Some keyboard commands work by sending a command, waiting for an + * ack (handled by kdintr), then sending data, which generates a * second ack. If we are in the middle of such a sequence, kd_ack * shows what the ack is for. - * - * When a byte is sent to the keyboard, it is kept around in last_sent + * + * When a byte is sent to the keyboard, it is kept around in last_sent * in case it needs to be resent. - * + * * The rest of the variables here hold the data required to complete * the sequence. - * + * * XXX - the System V driver keeps a command queue, I guess in case we * want to start a command while another is in progress. Is this * something we should worry about? @@ -208,113 +193,131 @@ boolean_t kd_initialized = FALSE; /* dr boolean_t kd_extended = FALSE; /* Array for processing escape sequences. */ -#define K_MAXESC 16 +#define K_MAXESC 32 u_char esc_seq[K_MAXESC]; u_char *esc_spt = (u_char *)0; /* * This array maps scancodes to Ascii characters (or character - * sequences). + * sequences). * Each row corresponds to one key. There are NUMOUTPUT bytes per key * state. The states are ordered: Normal, SHIFT, CTRL, ALT, * SHIFT/ALT. */ + +/* This new keymap from Tudor Hulubei (tudor@cs.unh.edu) makes the + following changes to the keyboard driver: + + - Alt + key (m-key) returns `ESC key' instead of `ESC N key'. + - Backspace returns 0x7f instead of 0x08. + - Delete returns `ESC [ 9' instead of 0x7f. + - Alt + function keys return key sequences that are different + from the key sequences returned by the function keys alone. + This is done with the idea of alowing a terminal server to + implement multiple virtual consoles mapped on Alt+F1, Alt+F2, + etc, as in Linux. + + -- Derek Upham 1997/06/25 */ + unsigned char key_map[NUMKEYS][WIDTH_KMAP] = { -{NC,NC,NC,NC,NC,NC,NC,NC,NC,NC,NC,NC,NC,NC,NC}, -{K_ESC,NC,NC, K_ESC,NC,NC, K_ESC,NC,NC, K_ESC,NC,NC, K_ESC,NC,NC}, -{K_ONE,NC,NC, K_BANG,NC,NC, K_ONE,NC,NC, 0x1b,0x4e,0x31, 0x1b,0x4e,0x21}, -{K_TWO,NC,NC, K_ATSN,NC,NC, K_NUL,NC,NC, 0x1b,0x4e,0x32, 0x1b,0x4e,0x40}, -{K_THREE,NC,NC, K_POUND,NC,NC, K_THREE,NC,NC, 0x1b,0x4e,0x33, 0x1b,0x4e,0x23}, -{K_FOUR,NC,NC, K_DOLLAR,NC,NC, K_FOUR,NC,NC, 0x1b,0x4e,0x34, 0x1b,0x4e,0x24}, -{K_FIVE,NC,NC, K_PERC,NC,NC, K_FIVE,NC,NC, 0x1b,0x4e,0x35, 0x1b,0x4e,0x25}, -{K_SIX,NC,NC, K_CARET,NC,NC, K_RS,NC,NC, 0x1b,0x4e,0x36, 0x1b,0x4e,0x5e}, -{K_SEVEN,NC,NC, K_AMPER,NC,NC, K_SEVEN,NC,NC, 0x1b,0x4e,0x37, 0x1b,0x4e,0x26}, -{K_EIGHT,NC,NC, K_ASTER,NC,NC, K_EIGHT,NC,NC, 0x1b,0x4e,0x38, 0x1b,0x4e,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ALTSC,NC}, -{K_SPACE,NC,NC, K_SPACE,NC,NC, K_NUL,NC,NC, K_SPACE,NC,NC, K_SPACE,NC,NC}, -{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}, -{K_F1, K_F1S, K_F1, K_F1, K_F1S}, -{K_F2, K_F2S, K_F2, K_F2, K_F2S}, -{K_F3, K_F3S, K_F3, K_F3, K_F3S}, -{K_F4, K_F4S, K_F4, K_F4, K_F4S}, -{K_F5, K_F5S, K_F5, K_F5, K_F5S}, -{K_F6, K_F6S, K_F6, K_F6, K_F6S}, -{K_F7, K_F7S, K_F7, K_F7, K_F7S}, -{K_F8, K_F8S, K_F8, K_F8, K_F8S}, -{K_F9, K_F9S, K_F9, K_F9, K_F9S}, -{K_F10, K_F10S, K_F10, K_F10, K_F10S}, -{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}, -{K_SCRL, K_NUL,NC,NC, K_SCRL, K_SCRL, K_NUL,NC,NC}, -{K_HOME, K_SEVEN,NC,NC, K_HOME, K_HOME, 0x1b,0x4e,0x37}, -{K_UA, K_EIGHT,NC,NC, K_UA, K_UA, 0x1b,0x4e,0x38}, -{K_PUP, K_NINE,NC,NC, K_PUP, K_PUP, 0x1b,0x4e,0x39}, -{0x1b,0x5b,0x53, K_MINUS,NC,NC, 0x1b,0x5b,0x53,0x1b,0x5b,0x53,0x1b,0x4e,0x2d}, -{K_LA, K_FOUR,NC,NC, K_LA, K_LA, 0x1b,0x4e,0x34}, -{0x1b,0x5b,0x47,K_FIVE,NC,NC,0x1b,0x5b,0x47, 0x1b,0x5b,0x47, 0x1b,0x4e,0x35}, -{K_RA, K_SIX,NC,NC, K_RA, K_RA, 0x1b,0x4e,0x36}, -{0x1b,0x5b,0x54,K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,K_m,NC, 0x1b,0x4e,K_M}, +{K_COMMA,NC,NC, K_LTHN,NC,NC, K_COMMA,NC,NC, 0x1b,K_COMMA,NC, 0x1b,0x4e,K_LTHN}, +{K_PERIOD,NC,NC,K_GTHN,NC,NC, K_PERIOD,NC,NC,0x1b,K_PERIOD,NC, 0x1b,0x4e,K_GTHN}, +{K_SLASH,NC,NC, K_QUES,NC,NC, K_SLASH,NC,NC, 0x1b,K_SLASH,NC, 0x1b,0x4e,K_QUES}, +{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}, +{K_ASTER,NC,NC, K_ASTER,NC,NC, K_ASTER,NC,NC, 0x1b,K_ASTER,NC, 0x1b,0x4e,K_ASTER}, +{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}, +{K_SPACE,NC,NC, K_SPACE,NC,NC, K_NUL,NC,NC, 0x1b,K_SPACE,NC, K_SPACE,NC,NC}, +{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}, +{K_F1, K_F1S, K_F1, K_F1A, K_F1S}, +{K_F2, K_F2S, K_F2, K_F2A, K_F2S}, +{K_F3, K_F3S, K_F3, K_F3A, K_F3S}, +{K_F4, K_F4S, K_F4, K_F4A, K_F4S}, +{K_F5, K_F5S, K_F5, K_F5A, K_F5S}, +{K_F6, K_F6S, K_F6, K_F6A, K_F6S}, +{K_F7, K_F7S, K_F7, K_F7A, K_F7S}, +{K_F8, K_F8S, K_F8, K_F8A, K_F8S}, +{K_F9, K_F9S, K_F9, K_F9A, K_F9S}, +{K_F10, K_F10S, K_F10, K_F10A, K_F10S}, +{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}, +{K_SCRL, K_NUL,NC,NC, K_SCRL, K_SCRL, K_NUL,NC,NC}, +{K_HOME, K_SEVEN,NC,NC, K_HOME, K_HOME, 0x1b,0x4e,K_SEVEN}, +{K_UA, K_EIGHT,NC,NC, K_UA, K_UA, 0x1b,0x4e,K_EIGHT}, +{K_PUP, K_NINE,NC,NC, K_PUP, K_PUP, 0x1b,0x4e,K_NINE}, +{0x1b,0x5b,0x53, K_MINUS,NC,NC, 0x1b,0x5b,0x53, 0x1b,0x5b,0x53, + 0x1b,0x4e,0x2d}, +{K_LA, K_FOUR,NC,NC, K_LA, K_LA, 0x1b,0x4e,K_FOUR}, +{0x1b,0x5b,0x47, K_FIVE,NC,NC, 0x1b,0x5b,0x47, 0x1b,0x5b,0x47, + 0x1b,0x4e,0x35}, +{K_RA, K_SIX,NC,NC, K_RA, K_RA, 0x1b,0x4e,K_SIX}, +{0x1b,0x5b,0x54, K_PLUS,NC,NC, 0x1b,0x5b,0x54, 0x1b,0x5b,0x54, + 0x1b,0x4e,0x2b}, +{K_END, K_ONE,NC,NC, K_END, K_END, 0x1b,0x4e,K_ONE}, +{K_DA, K_TWO,NC,NC, K_DA, K_DA, 0x1b,0x4e,K_TWO}, +{K_PDN, K_THREE,NC,NC, K_PDN, K_PDN, 0x1b,0x4e,K_THREE}, +{K_INS, K_ZERO,NC,NC, K_INS, K_INS, 0x1b,0x4e,K_ZERO}, +{0x1b,0x5b,0x39, K_PERIOD,NC,NC, K_DEL,NC,NC, K_DEL,NC,NC, 0x1b,0x4e,K_PERIOD}, +{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, +{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, +{NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC, NC,NC,NC}, +{K_F11, K_F11S, K_F11, K_F11A, K_F11S}, +{K_F12, K_F12S, K_F12, K_F12A, K_F12S} }; @@ -325,31 +328,6 @@ unsigned char key_map[NUMKEYS][WIDTH_KMA short kd_index_reg = EGA_IDX_REG; short kd_io_reg = EGA_IO_REG; -/* - * IO port sets for different controllers. - */ -io_reg_t vga_port_list[] = { - 0x3b4, 0x3b5, 0x3b8, 0x3b9, 0x3ba, /* MDA/EGA */ - 0x3d4, 0x3d5, 0x3d8, 0x3d9, 0x3da, /* CGA/EGA */ - 0x3c0, 0x3c1, 0x3c2, 0x3c3, 0x3c4, 0x3c5, 0x3c6, 0x3c7, - 0x3c8, 0x3c9, 0x3ca, 0x3cb, 0x3cc, 0x3cd, 0x3ce, 0x3cf, - IO_REG_NULL -}; - -mach_device_t kd_io_device = 0; - -kd_io_map_open(device) - mach_device_t device; -{ - kd_io_device = device; - io_port_create(device, vga_port_list); -} - -kd_io_map_close() -{ - io_port_destroy(kd_io_device); - kd_io_device = 0; -} /* * Globals used only for bitmap-based controllers. See kdsoft.h for @@ -382,12 +360,13 @@ short font_byte_width = 0; /* num bytes int kd_pollc = 0; #ifdef DEBUG -/* +/* * feep: * - * Ring the bell for a short time. + * Ring the bell for a short time. * Warning: uses outb(). You may prefer to use kd_debug_put. */ +void feep() { int i; @@ -395,9 +374,10 @@ feep() kd_bellon(); for (i = 0; i < 50000; ++i) ; - kd_belloff(); + kd_belloff(NULL); } +void pause() { int i; @@ -406,11 +386,12 @@ pause() ; } -/* +/* * Put a debugging character on the screen. - * LOC=0 means put it in the bottom right corner, LOC=1 means put it + * LOC=0 means put it in the bottom right corner, LOC=1 means put it * one column to the left, etc. */ +void kd_debug_put(loc, c) int loc; char c; @@ -425,6 +406,7 @@ char c; extern int mouse_in_use; int old_kb_mode; +void cnpollc(on) boolean_t on; { @@ -466,15 +448,16 @@ boolean_t on; * output: device is opened and setup * */ +int kdopen(dev, flag, ior) dev_t dev; int flag; io_req_t ior; { struct tty *tp; - int kdstart(); + void kdstart(); spl_t o_pri; - int kdstop(); + void kdstop(); tp = &kd_tty; o_pri = spltty(); @@ -487,17 +470,12 @@ kdopen(dev, flag, ior) /* * Special support for boot-time rc scripts, which don't * stty the console. - */ + */ tp->t_oproc = kdstart; tp->t_stop = kdstop; tp->t_ospeed = tp->t_ispeed = B9600; tp->t_flags = ODDP|EVENP|ECHO|CRMOD|XTABS; kdinit(); - - /* XXX kd_io_map_open allocates memory */ - simple_unlock(&tp->t_lock); - kd_io_map_open(ior->io_device); - simple_lock(&tp->t_lock); } tp->t_state |= TS_CARR_ON; simple_unlock(&tp->t_lock); @@ -513,11 +491,12 @@ kdopen(dev, flag, ior) * closing the line discipline. * * input: device number 'dev', and flag - * + * * output: device is closed * */ /*ARGSUSED*/ +void kdclose(dev, flag) int dev; int flag; @@ -533,10 +512,7 @@ int flag; splx(s); } - kd_io_map_close(); - return; - } @@ -552,12 +528,13 @@ int flag; * */ /*ARGSUSED*/ +int kdread(dev, uio) int dev; struct uio *uio; { struct tty *tp; - + tp = &kd_tty; tp->t_state |= TS_CARR_ON; return((*linesw[kd_tty.t_line].l_read)(tp, uio)); @@ -576,6 +553,7 @@ struct uio *uio; * */ /*ARGSUSED*/ +int kdwrite(dev, uio) int dev; struct uio *uio; @@ -583,7 +561,7 @@ struct uio *uio; return((*linesw[kd_tty.t_line].l_write)(&kd_tty, uio)); } -/* +/* * Mmap. */ @@ -601,11 +579,12 @@ kdmmap(dev, off, prot) return(i386_btop(kd_bitmap_start+off)); } +int kdportdeath(dev, port) dev_t dev; mach_port_t port; { - return (tty_portdeath(&kd_tty, port)); + return (tty_portdeath(&kd_tty, (ipc_port_t)port)); } /*ARGSUSED*/ @@ -613,7 +592,7 @@ io_return_t kdgetstat(dev, flavor, data, dev_t dev; int flavor; int * data; /* pointer to OUT array */ - unsigned int *count; /* OUT */ + natural_t *count; /* OUT */ { io_return_t result; @@ -643,7 +622,7 @@ io_return_t kdsetstat(dev, flavor, data, dev_t dev; int flavor; int * data; - unsigned int count; + natural_t count; { io_return_t result; @@ -669,12 +648,13 @@ io_return_t kdsetstat(dev, flavor, data, -/* +/* * kdsetbell: - * - * Turn the bell on or off. Returns error code, if given bogus + * + * Turn the bell on or off. Returns error code, if given bogus * on/off value. */ +int kdsetbell(val, flags) int val; /* on or off */ int flags; /* flags set for console */ @@ -685,7 +665,7 @@ int flags; /* flags set for console * if (val == KD_BELLON) kd_bellon(); else if (val == KD_BELLOFF) - kd_belloff(); + kd_belloff(NULL); else err = D_INVALID_OPERATION; @@ -693,11 +673,12 @@ int flags; /* flags set for console * } -/* +/* * kdgetkbent: - * + * * Get entry from key mapping table. Returns error code, if any. */ +int kdgetkbent(kbent) struct kbentry * kbent; { @@ -713,9 +694,9 @@ struct kbentry * kbent; } -/* +/* * kdsetkbent: - * + * * Set entry in key mapping table. Return error code, if any. */ int @@ -740,8 +721,8 @@ int flags; /* flags set for console * * * This function is the interrupt code for the driver. Since this is * a special tty (console), interrupts are only for input, so we read in - * the character. If in ascii mode, we then do the mapping translation - * from the keyboard switch table and place the characters on the tty's + * the character. If in ascii mode, we then do the mapping translation + * from the keyboard switch table and place the characters on the tty's * input switch table. If in event mode, we create and queue a kd_event. * * input: interrupt vector 'vec' @@ -750,46 +731,48 @@ int flags; /* flags set for console * * */ /*ARGSUSED*/ -kdintr(vec, regs) +void +kdintr(vec) int vec; -int regs; { struct tty *tp; unsigned char c; unsigned char scancode; - int o_pri; int char_idx; boolean_t up = FALSE; /* key-up event */ extern int mouse_in_use; if (kd_pollc) return; /* kdb polling kbd */ + if (!kd_initialized) + return; + tp = &kd_tty; #ifdef old while ((inb(K_STATUS) & K_OBUF_FUL) == 0); /* this should never loop */ -#else old +#else /* old */ { /* - * Allow for keyboards that raise interrupt before + * Allow for keyboards that raise interrupt before * the character gets to the buffer. But don't wait * forever if grabbing the character by polling leaves * the interrupt on but buffer empty. */ /* - * Micronics VLB motherboard with 486DX2 can report keyboard + * Micronics VLB motherboard with 486DX2 can report keyboard * interrupt before K_STATUS register indicates that the * output buffer is full. Moreover, the bus won't settle w * while we poll K_STATUS at speed. Temporary fix is to break - * out after safety runs out and pick up keyboard event. This - * should be fixed eventually by putting a 1us timout between - * inb's to K_STATUS and fix the pic initialization order to + * out after safety runs out and pick up keyboard event. This + * should be fixed eventually by putting a 1us timout between + * inb's to K_STATUS and fix the pic initialization order to * avoid bootup keyboard wedging (ie make kd a real device) */ int safety = 1000; while ((inb(K_STATUS) & K_OBUF_FUL) == 0) if (!safety--) break; /* XXX */ } -#endif old +#endif /* old */ /* * We may have seen a mouse event. */ @@ -804,9 +787,8 @@ int regs; } scancode = inb(K_RDWR); - if (scancode == K_EXTEND) { - if (kb_mode != KB_EVENT) - kd_extended = TRUE; + if (scancode == K_EXTEND && kb_mode != KB_EVENT) { + kd_extended = TRUE; goto done; } else if (scancode == K_RESEND) { kd_resend(); @@ -816,7 +798,7 @@ int regs; goto done; } else if (kd_kbd_mouse && kd_kbd_magic(scancode)) { goto done; - } else if (kdcheckmagic(scancode, ®s)) { + } else if (kdcheckmagic(scancode)) { goto done; } else if (kb_mode == KB_EVENT) { kd_enqsc(scancode); @@ -867,13 +849,13 @@ int regs; } } - /* + /* * here's where we actually put the char (or * char sequence, for function keys) onto the * input queue. */ - for ( ; (c != K_DONE) && (char_idx <= max); - c = key_map[scancode][char_idx++]) { + for ( ; (c != K_DONE) && (char_idx <= max); + c = key_map[scancode][char_idx++]) { (*linesw[tp->t_line].l_rint)(c, tp); } kd_extended = FALSE; @@ -884,12 +866,13 @@ int regs; return; } -/* +/* * kd_handle_ack: - * - * For pending commands, complete the command. For data bytes, + * + * For pending commands, complete the command. For data bytes, * drop the ack on the floor. */ +void kd_handle_ack() { switch (kd_ack) { @@ -909,14 +892,15 @@ kd_handle_ack() } } -/* +/* * kd_resend: * * Resend a missed keyboard command or data byte. */ +void kd_resend() { - if (kd_ack == NOT_WAITING) + if (kd_ack == NOT_WAITING) printf("unexpected RESEND from keyboard\n"); else kd_senddata(last_sent); @@ -929,11 +913,12 @@ kd_resend() * Change keyboard state according to which modifier key and * whether it went down or up. * - * input: the current state, the key, and the key's direction. + * input: the current state, the key, and the key's direction. * The key can be any key, not just a modifier key. - * + * * output: the new state */ +int do_modifier(state, c, up) int state; Scancode c; @@ -949,7 +934,7 @@ boolean_t up; break; #ifndef ORC case (K_CLCKSC): -#endif ORC +#endif /* ORC */ case (K_CTLSC): if (up) state &= ~KS_CTLED; @@ -962,7 +947,7 @@ boolean_t up; if (!up) state ^= KS_CLKED; break; -#endif ORC +#endif /* ORC */ case (K_NLCKSC): if (!up) state ^= KS_NLKED; @@ -981,27 +966,26 @@ boolean_t up; } -/* +/* * kdcheckmagic: - * - * Check for magic keystrokes for invoking the debugger or + * + * Check for magic keystrokes for invoking the debugger or * rebooting or ... * * input: an unprocessed scancode - * - * output: TRUE if a magic key combination was recognized and + * + * output: TRUE if a magic key combination was recognized and * processed. FALSE otherwise. * - * side effects: + * side effects: * various actions possible, depending on which keys are - * pressed. If the debugger is called, steps are taken - * to ensure that the system doesn't think the magic keys + * pressed. If the debugger is called, steps are taken + * to ensure that the system doesn't think the magic keys * are still held down. */ boolean_t -kdcheckmagic(scancode, regs) +kdcheckmagic(scancode) Scancode scancode; -int *regs; { static int magic_state = KS_NORMAL; /* like kd_state */ boolean_t up = FALSE; @@ -1038,7 +1022,7 @@ int *regs; } return(TRUE); break; -#endif MACH_KDB +#endif /* MACH_KDB */ case K_DELSC: /* ctl-alt-del */ /* if rebootflag is on, reboot the system */ if (rebootflag) @@ -1053,9 +1037,10 @@ int *regs; /* * kdstate2idx: * - * Return the value for the 2nd index into key_map that + * Return the value for the 2nd index into key_map that * corresponds to the given state. */ +int kdstate2idx(state, extended) int state; /* bit vector, not a state index */ boolean_t extended; @@ -1065,12 +1050,15 @@ boolean_t extended; if ((!extended) && state != KS_NORMAL) { if ((state&(KS_SHIFTED|KS_ALTED)) == (KS_SHIFTED|KS_ALTED)) state_idx = SHIFT_ALT; + /* CTRL should have higher priority than SHIFT. That + way, CTRL-SHIFT-2 and CTRL-2 produce the same keycode. + --Derek Upham 1997/06/25 */ + else if (state&KS_CTLED) + state_idx = CTRL_STATE; else if (state&KS_SHIFTED) state_idx = SHIFT_STATE; else if (state&KS_ALTED) state_idx = ALT_STATE; - else if (state&KS_CTLED) - state_idx = CTRL_STATE; } return (CHARIDX(state_idx)); @@ -1092,17 +1080,18 @@ boolean_t extended; * Entered and left at spltty. Drops priority to spl0 to display character. * ASSUMES that it is never called from interrupt-driven code. */ +void kdstart(tp) struct tty *tp; { spl_t o_pri; int ch; unsigned char c; - + if (tp->t_state & TS_TTSTOP) return; for ( ; ; ) { - tp->t_state &= ~TS_BUSY; + tp->t_state &= ~TS_BUSY; if (tp->t_state & TS_TTSTOP) break; if ((tp->t_outq.c_cc <= 0) || (ch = getc(&tp->t_outq)) == -1) @@ -1142,6 +1131,7 @@ struct tty *tp; } /*ARGSUSED*/ +void kdstop(tp, flags) register struct tty *tp; int flags; @@ -1156,7 +1146,7 @@ kdstop(tp, flags) * kdinit: * * This code initializes the structures and sets up the port registers - * for the console driver. + * for the console driver. * * Each bitmap-based graphics card is likely to require a unique * way to determine the card's presence. The driver runs through @@ -1168,6 +1158,7 @@ kdstop(tp, flags) * output : Driver is initialized * */ +void kdinit() { void kd_xga_init(); @@ -1179,15 +1170,13 @@ kdinit() esc_spt = esc_seq; kd_attr = KA_NORMAL; + kd_attrflags = 0; + kd_color = KA_NORMAL; /* * board specific initialization: set up globals and kd_dxxx * pointers, and synch displayed cursor with logical cursor. */ - if (!evc1init()) - if (blit_present()) - blit_init(); - else - kd_xga_init(); + kd_xga_init(); /* get rid of any garbage in output buffer */ if (inb(K_STATUS) & K_OBUF_FUL) @@ -1220,6 +1209,9 @@ kdinit() enable the keyboard controller. This keeps NUM-LOCK from being set on the NEC Versa. */ + + /* Allocate the input buffer. */ + ttychars(&kd_tty); } /* @@ -1233,7 +1225,9 @@ kdinit() * */ static unsigned int kd_bellstate = 0; -kd_belloff() + +void +kd_belloff(void * param) { unsigned char status; @@ -1253,6 +1247,7 @@ kd_belloff() * output : bell is turned on * */ +void kd_bellon() { unsigned char status; @@ -1282,17 +1277,18 @@ kd_bellon() */ int sit_for_0 = 1; +void kd_putc(ch) u_char ch; { if ((!ch) && sit_for_0) return; - switch (ch) { + switch (ch) { case ((K_LF)): kd_down(); break; - case ((K_CR)): + case ((K_CR)): kd_cr(); break; case ((K_BS)): @@ -1335,6 +1331,7 @@ u_char ch; * screen. * */ +void kd_setpos(newpos) csrpos_t newpos; { @@ -1361,6 +1358,7 @@ csrpos_t newpos; * output : lines on screen appear to be shifted up one line * */ +void kd_scrollup() { csrpos_t to; @@ -1390,6 +1388,7 @@ kd_scrollup() * output : Lines on screen appear to be moved down one line * */ +void kd_scrolldn() { csrpos_t to; @@ -1407,7 +1406,7 @@ kd_scrolldn() count = ONE_LINE/ONE_SPACE; (*kd_dclear)(to, count, kd_attr); return; - + } @@ -1415,7 +1414,7 @@ kd_scrolldn() * kd_parseesc: * * This routine begins the parsing of an escape sequence. It uses the - * escape sequence array and the escape spot pointer to handle + * escape sequence array and the escape spot pointer to handle * asynchronous parsing of escape sequences. * * input : String of characters prepended by an escape @@ -1423,6 +1422,7 @@ kd_scrolldn() * defined by the ansi terminal specification * */ +void kd_parseesc() { u_char *escp; @@ -1450,6 +1450,37 @@ kd_parseesc() } +/* kd_update_kd_attr: + * + * Updates kd_attr according to kd_attrflags and kd_color. + * This code has its origin from console.c and selection.h in + * linux 2.2 drivers/char/. + * Modified for GNU Mach by Marcus Brinkmann. + */ + +#define reverse_video_char(a) (((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77)) +void +kd_update_kd_attr(void) +{ + kd_attr = kd_color; + if (kd_attrflags & KAX_UNDERLINE) + kd_attr = (kd_attr & 0xf0) | KAX_COL_UNDERLINE; + else if (kd_attrflags & KAX_DIM) + kd_attr = (kd_attr & 0xf0) | KAX_COL_DIM; + if (kd_attrflags & KAX_REVERSE) + kd_attr = reverse_video_char(kd_attr); + if (kd_attrflags & KAX_BLINK) + kd_attr ^= 0x80; + if (kd_attrflags & KAX_BOLD) + kd_attr ^= 0x08; +} + +/* color_table added by Julio Merino to take proper color order. + * I get this code from Linux 2.2 source code in file: + * linux/drivers/char/console.c + */ +unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, + 8,12,10,14, 9,13,11,15 }; /* * kd_parserest: * @@ -1463,143 +1494,186 @@ kd_parseesc() * sequence acceptable to the ansi terminal specification * */ +void kd_parserest(cp) u_char *cp; { - int number; + int number[16], npar = 0, i; csrpos_t newpos; - cp += kd_atoi(cp, &number); + for(i=0;i<=15;i++) + number[i] = MACH_ATOI_DEFAULT; + + do { + cp += mach_atoi(cp, &number[npar]); + } while (*cp == ';' && ++npar <= 15 && cp++); + switch(*cp) { case 'm': - switch(number) { - case DEFAULT: - case 0: - kd_attr = KA_NORMAL; - break; - case 7: - kd_attr = KA_REVERSE; - break; - default: - kd_attr = KA_NORMAL; - break; - } + for (i=0;i<=npar;i++) + switch(number[i]) { + case MACH_ATOI_DEFAULT: + case 0: + kd_attrflags = 0; + kd_color = KA_NORMAL; + break; + case 1: + kd_attrflags |= KAX_BOLD; + kd_attrflags &= ~KAX_DIM; + break; + case 2: + kd_attrflags |= KAX_DIM; + kd_attrflags &= ~KAX_BOLD; + break; + case 4: + kd_attrflags |= KAX_UNDERLINE; + break; + case 5: + kd_attrflags |= KAX_BLINK; + break; + case 7: + kd_attrflags |= KAX_REVERSE; + break; + case 8: + kd_attrflags |= KAX_INVISIBLE; + break; + case 21: + case 22: + kd_attrflags &= ~(KAX_BOLD | KAX_DIM); + break; + case 24: + kd_attrflags &= ~KAX_UNDERLINE; + break; + case 25: + kd_attrflags &= ~KAX_BLINK; + break; + case 27: + kd_attrflags &= ~KAX_REVERSE; + break; + case 38: + kd_attrflags |= KAX_UNDERLINE; + kd_color = (kd_color & 0xf0) | (KA_NORMAL & 0x0f); + break; + case 39: + kd_attrflags &= ~KAX_UNDERLINE; + kd_color = (kd_color & 0xf0) | (KA_NORMAL & 0x0f); + break; + default: + if (number[i] >= 30 && number[i] <= 37) { + /* foreground color */ + kd_color = (kd_color & 0xf0) | color_table[(number[i] - 30)]; + } else if (number[i] >= 40 && number[i] <= 47) { + /* background color */ + kd_color = (kd_color & 0x0f) | (color_table[(number[i] - 40)] << 4); + } + break; + } + kd_update_kd_attr(); esc_spt = esc_seq; break; case '@': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_insch(1); else - kd_insch(number); - esc_spt = esc_seq; - break; - case 'H': - kd_home(); + kd_insch(number[0]); esc_spt = esc_seq; break; case 'A': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_up(); else - while (number--) + while (number[0]--) kd_up(); esc_spt = esc_seq; break; case 'B': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_down(); else - while (number--) + while (number[0]--) kd_down(); esc_spt = esc_seq; break; case 'C': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_right(); else - while (number--) + while (number[0]--) kd_right(); esc_spt = esc_seq; break; case 'D': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_left(); else - while (number--) + while (number[0]--) kd_left(); esc_spt = esc_seq; break; case 'E': kd_cr(); - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_down(); else - while (number--) + while (number[0]--) kd_down(); esc_spt = esc_seq; break; case 'F': kd_cr(); - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_up(); else - while (number--) + while (number[0]--) kd_up(); esc_spt = esc_seq; break; case 'G': - if (number == DEFAULT) - number = 0; + if (number[0] == MACH_ATOI_DEFAULT) + number[0] = 0; else - if (number > 0) - --number; /* because number is from 1 */ - kd_setpos(BEG_OF_LINE(kd_curpos) + number * ONE_SPACE); + if (number[0] > 0) + --number[0]; /* because number[0] is from 1 */ + kd_setpos(BEG_OF_LINE(kd_curpos) + number[0] * ONE_SPACE); esc_spt = esc_seq; break; - case ';': - ++cp; - if (*cp == '\0') - break; /* not ready yet */ - if (number == DEFAULT) - number = 0; - else - if (number > 0) - --number; /* numbered from 1 */ - newpos = (number * ONE_LINE); /* setup row */ - cp += kd_atoi(cp, &number); - if (*cp == '\0') - break; /* not ready yet */ - if (number == DEFAULT) - number = 0; - else if (number > 0) - number--; - newpos += (number * ONE_SPACE); /* setup column */ + case 'f': + case 'H': + if (number[0] == MACH_ATOI_DEFAULT && number[1] == MACH_ATOI_DEFAULT) + { + kd_home(); + esc_spt = esc_seq; + break; + } + if (number[0] == MACH_ATOI_DEFAULT) + number[0] = 0; + else if (number[0] > 0) + --number[0]; /* numbered from 1 */ + newpos = (number[0] * ONE_LINE); /* setup row */ + if (number[1] == MACH_ATOI_DEFAULT) + number[1] = 0; + else if (number[1] > 0) + number[1]--; + newpos += (number[1] * ONE_SPACE); /* setup column */ if (newpos < 0) newpos = 0; /* upper left */ if (newpos > ONE_PAGE) - newpos = (ONE_PAGE - ONE_SPACE); - /* lower right */ - if (*cp == '\0') - break; /* not ready yet */ - if (*cp == 'H') { - kd_setpos(newpos); - esc_spt = esc_seq; /* done, reset */ - } - else - esc_spt = esc_seq; + newpos = (ONE_PAGE - ONE_SPACE); /* lower right */ + kd_setpos(newpos); + esc_spt = esc_seq; break; /* done or not ready */ case 'J': - switch(number) { - case DEFAULT: + switch(number[0]) { + case MACH_ATOI_DEFAULT: case 0: kd_cltobcur(); /* clears from current pos to bottom. - */ + */ break; case 1: kd_cltopcur(); /* clears from top to current pos. - */ + */ break; case 2: kd_cls(); @@ -1610,12 +1684,12 @@ u_char *cp; esc_spt = esc_seq; /* reset it */ break; case 'K': - switch(number) { - case DEFAULT: + switch(number[0]) { + case MACH_ATOI_DEFAULT: case 0: kd_cltoecur(); /* clears from current pos to eoln. - */ + */ break; case 1: kd_clfrbcur(); /* clears from begin @@ -1632,49 +1706,49 @@ u_char *cp; esc_spt = esc_seq; break; case 'L': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_insln(1); else - kd_insln(number); + kd_insln(number[0]); esc_spt = esc_seq; break; case 'M': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_delln(1); else - kd_delln(number); + kd_delln(number[0]); esc_spt = esc_seq; break; case 'P': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_delch(1); else - kd_delch(number); + kd_delch(number[0]); esc_spt = esc_seq; break; case 'S': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_scrollup(); else - while (number--) + while (number[0]--) kd_scrollup(); esc_spt = esc_seq; break; case 'T': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_scrolldn(); else - while (number--) + while (number[0]--) kd_scrolldn(); esc_spt = esc_seq; break; case 'X': - if (number == DEFAULT) + if (number[0] == MACH_ATOI_DEFAULT) kd_erase(1); else - kd_erase(number); + kd_erase(number[0]); esc_spt = esc_seq; - break; + break; case '\0': break; /* not enough yet */ default: @@ -1685,37 +1759,7 @@ u_char *cp; return; } -/* - * kd_atoi: - * - * This function converts an ascii string into an integer, and - * returns DEFAULT if no integer was found. Note that this is why - * we don't use the regular atio(), because ZERO is ZERO and not - * the DEFAULT in all cases. - * - * input : string - * output : a number or possibly DEFAULT, and the count of characters - * consumed by the conversion - * - */ -int -kd_atoi(cp, nump) -u_char *cp; -int *nump; -{ - int number; - u_char *original; - - original = cp; - for (number = 0; ('0' <= *cp) && (*cp <= '9'); cp++) - number = (number * 10) + (*cp - '0'); - if (original == cp) - *nump = DEFAULT; - else - *nump = number; - return(cp - original); -} - +void kd_tab() { int i; @@ -1736,6 +1780,7 @@ kd_tab() * output : Screen is cleared * */ +void kd_cls() { (*kd_dclear)(0, ONE_PAGE/ONE_SPACE, kd_attr); @@ -1753,6 +1798,7 @@ kd_cls() * output : Cursor position is moved * */ +void kd_home() { kd_setpos(0); @@ -1769,6 +1815,7 @@ kd_home() * output : Cursor moves up one line, or screen is scrolled * */ +void kd_up() { if (kd_curpos < ONE_LINE) @@ -1788,6 +1835,7 @@ kd_up() * output : Cursor moves down one line or the screen is scrolled * */ +void kd_down() { if (kd_curpos >= (ONE_PAGE - ONE_LINE)) @@ -1807,6 +1855,7 @@ kd_down() * output : Cursor moves one position to the right * */ +void kd_right() { if (kd_curpos < (ONE_PAGE - ONE_SPACE)) @@ -1828,6 +1877,7 @@ kd_right() * output : Cursor moves one position to the left * */ +void kd_left() { if (0 < kd_curpos) @@ -1846,6 +1896,7 @@ kd_left() * output : Cursor moves to the beginning of the current line * */ +void kd_cr() { kd_setpos(BEG_OF_LINE(kd_curpos)); @@ -1863,6 +1914,7 @@ kd_cr() * output : Screen is cleared from current cursor postion to bottom * */ +void kd_cltobcur() { csrpos_t start; @@ -1885,6 +1937,7 @@ kd_cltobcur() * output : Screen is cleared from current cursor postion to top * */ +void kd_cltopcur() { int count; @@ -1898,12 +1951,13 @@ kd_cltopcur() /* * kd_cltoecur: * - * This function clears from the current cursor position to eoln. + * This function clears from the current cursor position to eoln. * * input : None * output : Line is cleared from current cursor position to eoln * */ +void kd_cltoecur() { csrpos_t i; @@ -1926,6 +1980,7 @@ kd_cltoecur() * output : Line is cleared from beginning to current position * */ +void kd_clfrbcur() { csrpos_t i; @@ -1946,6 +2001,7 @@ kd_clfrbcur() * output : lines appear to be deleted * */ +void kd_delln(number) int number; { @@ -1984,6 +2040,7 @@ int number; * output : New lines appear to be inserted * */ +void kd_insln(number) int number; { @@ -2016,13 +2073,14 @@ int number; /* * kd_delch: * - * This function deletes a number of characters from the current + * This function deletes a number of characters from the current * position in the line. * * input : number of characters to delete * output : characters appear to be deleted * */ +void kd_delch(number) int number; { @@ -2064,13 +2122,14 @@ int number; * output : characters appear to be blanked or erased * */ +void kd_erase(number) int number; { csrpos_t i; csrpos_t stop; - stop = kd_curpos + (ONE_SPACE * number); + stop = kd_curpos + (ONE_SPACE * number); if (stop > BEG_OF_LINE(kd_curpos) + ONE_LINE) stop = BEG_OF_LINE(kd_curpos) + ONE_LINE; for (i = kd_curpos; i < stop; i += ONE_SPACE) { @@ -2089,13 +2148,14 @@ int number; * output : Current line is erased * */ +void kd_eraseln() { csrpos_t i; csrpos_t stop; stop = BEG_OF_LINE(kd_curpos) + ONE_LINE; - for (i = BEG_OF_LINE(kd_curpos); i < stop; i += ONE_SPACE) { + for (i = BEG_OF_LINE(kd_curpos); i < stop; i += ONE_SPACE) { (*kd_dput)(i, K_SPACE, kd_attr); } return; @@ -2112,6 +2172,7 @@ kd_eraseln() * output : Blanks are inserted at cursor position * */ +void kd_insch(number) int number; { @@ -2153,6 +2214,7 @@ int number; * returns TRUE if character is lowercase * */ +boolean_t kd_isupper(c) u_char c; { @@ -2161,6 +2223,7 @@ u_char c; return(FALSE); } +boolean_t kd_islower(c) u_char c; { @@ -2178,6 +2241,7 @@ u_char c; * keyboard command. * */ +void kd_senddata(ch) unsigned char ch; { @@ -2195,6 +2259,7 @@ unsigned char ch; * clear before sending the data. * */ +void kd_sendcmd(ch) unsigned char ch; { @@ -2204,12 +2269,12 @@ unsigned char ch; } -/* +/* * kd_getdata: - * - * This function returns a data byte from the keyboard RDWR port, - * after waiting until the port is flagged as having something to - * read. + * + * This function returns a data byte from the keyboard RDWR port, + * after waiting until the port is flagged as having something to + * read. */ unsigned char kd_getdata() @@ -2218,6 +2283,7 @@ kd_getdata() return(inb(K_RDWR)); } +unsigned char kd_cmdreg_read() { int ch=KC_CMD_READ; @@ -2229,6 +2295,7 @@ int ch=KC_CMD_READ; return(inb(K_RDWR)); } +void kd_cmdreg_write(val) { int ch=KC_CMD_WRITE; @@ -2240,6 +2307,7 @@ int ch=KC_CMD_WRITE; outb(K_RDWR, val); } +void kd_mouse_drain() { int i; @@ -2248,12 +2316,12 @@ kd_mouse_drain() printf("kbd: S = %x D = %x\n", i, inb(K_RDWR)); } -/* +/* * set_kd_state: - * + * * Set kd_state and update the keyboard status LEDs. */ - +void set_kd_state(newstate) int newstate; { @@ -2261,10 +2329,10 @@ int newstate; kd_setleds1(state2leds(newstate)); } -/* +/* * state2leds: - * - * Return a byte containing LED settings for the keyboard, given + * + * Return a byte containing LED settings for the keyboard, given * a state vector. */ u_char @@ -2280,16 +2348,19 @@ int state; return(result); } -/* +/* * kd_setleds[12]: - * - * Set the keyboard LEDs according to the given byte. + * + * Set the keyboard LEDs according to the given byte. */ +void kd_setleds1(val) u_char val; { if (kd_ack != NOT_WAITING) { +#ifdef MACH_KBD printf("kd_setleds1: unexpected state (%d)\n", kd_ack); +#endif return; } @@ -2298,19 +2369,21 @@ u_char val; kd_senddata(K_CMD_LEDS); } +void kd_setleds2() { kd_senddata(kd_nextled); } -/* +/* * cnsetleds: - * + * * like kd_setleds[12], but not interrupt-based. - * Currently disabled because cngetc ignores caps lock and num + * Currently disabled because cngetc ignores caps lock and num * lock anyway. */ +void cnsetleds(val) u_char val; { @@ -2320,6 +2393,7 @@ u_char val; (void)kd_getdata(); /* XXX - assume is ACK */ } +void kdreboot() { (*kd_dreset)(); @@ -2328,9 +2402,9 @@ kdreboot() kd_sendcmd(0xFE); /* XXX - magic # */ delay(1000000); /* wait to see if anything happens */ #endif - /* + /* * If that didn't work, then we'll just have to try and - * do it the hard way. + * do it the hard way. */ cpu_shutdown(); } @@ -2338,6 +2412,7 @@ kdreboot() static int which_button[] = {0, MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}; static struct mouse_motion moved; +int kd_kbd_magic(scancode) { int new_button = 0; @@ -2451,7 +2526,7 @@ kd_xga_init() * memory location for these cards. * */ - + vid_start = (u_char *)phystokv(EGA_START); kd_index_reg = EGA_IDX_REG; kd_io_reg = EGA_IO_REG; @@ -2602,9 +2677,9 @@ char chattr; } -/* +/* * kd_noopreset: - * + * * No-op reset routine for kd_dreset. */ static void @@ -2705,7 +2780,7 @@ int count; count /= kd_cols; /* num lines */ count *= fb_byte_width * (char_height+cursor_height); kd_slmscu(bit2fbptr(from_xbit, from_ybit), - bit2fbptr(to_xbit, to_ybit), + bit2fbptr(to_xbit, to_ybit), count/SLAMBPW); bmppaintcsr(kd_curpos, char_white); } else { @@ -2774,7 +2849,7 @@ char chattr; /* reverse or normal */ /* fast case - entire page */ kd_slmwd(vid_start, (fb_byte_width * fb_height)/SLAMBPW, clearval); - } else + } else /* slow case */ for (i = 0; i < count; ++i) { bmpput(to, K_SPACE, chattr); @@ -2863,9 +2938,10 @@ kdcnprobe(struct consdev *cp) maj = 0; unit = 0; pri = CN_INTERNAL; - + cp->cn_dev = makedev(maj, unit); cp->cn_pri = pri; + return 0; } int @@ -2891,24 +2967,24 @@ kdcngetc(dev_t dev, int wait) int kdcnputc(dev_t dev, int c) { - int i; - if (!kd_initialized) - return; + return -1; /* Note that tab is handled in kd_putc */ if (c == '\n') kd_putc('\r'); kd_putc(c); + + return 0; } -/* +/* * kdcnmaygetc: - * - * Get one character using polling, rather than interrupts. Used + * + * Get one character using polling, rather than interrupts. Used * by the kernel debugger. Note that Caps Lock is ignored. - * Normally this routine is called with interrupts already - * disabled, but there is code in place so that it will be more + * Normally this routine is called with interrupts already + * disabled, but there is code in place so that it will be more * likely to work even if interrupts are turned on. */ int