1 /* $NetBSD: ite.c,v 1.82 2008/06/13 09:41:15 cegger Exp $ */
4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1990, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * the Systems Programming Group of the University of Utah Computer
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * from: Utah $Hdr: ite.c 1.28 92/12/20$
66 * @(#)ite.c 8.2 (Berkeley) 1/12/94
69 * Copyright (c) 1988 University of Utah.
71 * This code is derived from software contributed to Berkeley by
72 * the Systems Programming Group of the University of Utah Computer
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by the University of
86 * California, Berkeley and its contributors.
87 * 4. Neither the name of the University nor the names of its contributors
88 * may be used to endorse or promote products derived from this software
89 * without specific prior written permission.
91 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
92 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
97 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
103 * from: Utah $Hdr: ite.c 1.28 92/12/20$
105 * @(#)ite.c 8.2 (Berkeley) 1/12/94
109 * Bit-mapped display terminal emulator machine independent code.
110 * This is a very rudimentary. Much more can be abstracted out of
111 * the hardware dependent routines.
114 #include <sys/cdefs.h>
115 __KERNEL_RCSID(0, "$NetBSD: ite.c,v 1.82 2008/06/13 09:41:15 cegger Exp $");
119 #include <sys/param.h>
120 #include <sys/conf.h>
121 #include <sys/proc.h>
122 #include <sys/ioctl.h>
124 #include <sys/systm.h>
125 #include <sys/malloc.h>
126 #include <sys/device.h>
127 #include <sys/kauth.h>
129 #include <machine/autoconf.h>
130 #include <machine/bus.h>
132 #include <dev/cons.h>
134 #include <hp300/dev/grfioctl.h>
135 #include <hp300/dev/grfvar.h>
136 #include <hp300/dev/hilioctl.h>
137 #include <hp300/dev/hilvar.h>
138 #include <hp300/dev/itevar.h>
139 #include <hp300/dev/kbdmap.h>
143 #define set_attr(ip, attr) ((ip)->attribute |= (attr))
144 #define clr_attr(ip, attr) ((ip)->attribute &= ~(attr))
147 * # of chars are output in a single itestart() call.
148 * If this is too big, user processes will be blocked out for
149 * long periods of time while we are emptying the queue in itestart().
150 * If it is too small, console output will be very ragged.
154 static int itematch(device_t
, cfdata_t
, void *);
155 static void iteattach(device_t
, device_t
, void *);
157 CFATTACH_DECL_NEW(ite
, sizeof(struct ite_softc
),
158 itematch
, iteattach
, NULL
, NULL
);
160 /* XXX this has always been global, but shouldn't be */
161 static struct kbdmap
*ite_km
;
163 static dev_type_open(iteopen
);
164 static dev_type_close(iteclose
);
165 static dev_type_read(iteread
);
166 static dev_type_write(itewrite
);
167 static dev_type_ioctl(iteioctl
);
168 static dev_type_tty(itetty
);
169 static dev_type_poll(itepoll
);
171 const struct cdevsw ite_cdevsw
= {
172 iteopen
, iteclose
, iteread
, itewrite
, iteioctl
,
173 nostop
, itetty
, itepoll
, nommap
, ttykqfilter
, D_TTY
177 * Terminal emulator state information, statically allocated
178 * for the benefit of the console.
180 static struct ite_data ite_cn
;
185 static struct consdev ite_cons
= {
197 static int console_kbd_attached
;
198 static int console_display_attached
;
199 static struct ite_kbdops
*console_kbdops
;
200 static struct ite_kbdmap
*console_kbdmap
;
202 static void iteinit(struct ite_data
*);
203 static void iteputchar(int, struct ite_data
*);
204 static void itecheckwrap(struct ite_data
*, struct itesw
*);
205 static void ite_dchar(struct ite_data
*, struct itesw
*);
206 static void ite_ichar(struct ite_data
*, struct itesw
*);
207 static void ite_dline(struct ite_data
*, struct itesw
*);
208 static void ite_iline(struct ite_data
*, struct itesw
*);
209 static void ite_clrtoeol(struct ite_data
*, struct itesw
*, int, int);
210 static void ite_clrtoeos(struct ite_data
*, struct itesw
*);
211 static void itestart(struct tty
*);
214 * Primary attribute buffer to be used by the first bitmapped console
215 * found. Secondary displays alloc the attribute buffer as needed.
216 * Size is based on a 68x128 display, which is currently our largest.
218 static u_char ite_console_attributes
[0x2200];
220 #define ite_erasecursor(ip, sp) { \
221 if ((ip)->flags & ITE_CURSORON) \
222 (*(sp)->ite_cursor)((ip), ERASE_CURSOR); \
224 #define ite_drawcursor(ip, sp) { \
225 if ((ip)->flags & ITE_CURSORON) \
226 (*(sp)->ite_cursor)((ip), DRAW_CURSOR); \
228 #define ite_movecursor(ip, sp) { \
229 if ((ip)->flags & ITE_CURSORON) \
230 (*(sp)->ite_cursor)((ip), MOVE_CURSOR); \
234 itematch(device_t parent
, cfdata_t cf
, void *aux
)
241 iteattach(device_t parent
, device_t self
, void *aux
)
243 struct ite_softc
*ite
= device_private(self
);
244 struct grf_softc
*grf
= device_private(parent
);
245 struct grfdev_attach_args
*ga
= aux
;
249 /* Allocate the ite_data. */
250 if (ga
->ga_isconsole
) {
251 ite
->sc_data
= &ite_cn
;
252 aprint_normal(": console");
255 * We didn't know which unit this would be during
256 * the console probe, so we have to fixup cn_dev here.
258 cn_tab
->cn_dev
= makedev(cdevsw_lookup_major(&ite_cdevsw
),
261 ite
->sc_data
= malloc(sizeof(struct ite_data
), M_DEVBUF
,
263 if (ite
->sc_data
== NULL
) {
265 aprint_error_dev(self
, "malloc for ite_data failed\n");
268 ite
->sc_data
->flags
= ITE_ALIVE
;
272 * Cross-reference the ite and the grf.
281 iteinstallkeymap(void *v
)
284 ite_km
= (struct kbdmap
*)v
;
288 * Perform functions necessary to setup device as a terminal emulator.
291 iteon(struct ite_data
*ip
, int flag
)
294 if ((ip
->flags
& ITE_ALIVE
) == 0)
297 /* force ite active, overriding graphics mode */
299 ip
->flags
|= ITE_ACTIVE
;
300 ip
->flags
&= ~(ITE_INGRF
|ITE_INITED
);
303 /* leave graphics mode */
305 ip
->flags
&= ~ITE_INGRF
;
306 if ((ip
->flags
& ITE_ACTIVE
) == 0)
310 ip
->flags
|= ITE_ACTIVE
;
311 if (ip
->flags
& ITE_INGRF
)
314 if (console_kbdops
!= NULL
)
315 (*console_kbdops
->enable
)(console_kbdops
->arg
);
322 iteinit(struct ite_data
*ip
)
325 if (ip
->flags
& ITE_INITED
)
333 (*ip
->isw
->ite_init
)(ip
);
334 ip
->flags
|= ITE_CURSORON
;
335 ite_drawcursor(ip
, ip
->isw
);
338 if (ip
->attrbuf
== NULL
)
339 ip
->attrbuf
= malloc(ip
->rows
* ip
->cols
,
340 M_DEVBUF
, M_WAITOK
| M_ZERO
);
343 ip
->flags
|= ITE_INITED
;
347 * "Shut down" device as terminal emulator.
348 * Note that we do not deinit the console device unless forced.
349 * Deinit'ing the console every time leads to a very active
350 * screen when processing /etc/rc.
353 iteoff(struct ite_data
*ip
, int flag
)
357 ip
->flags
|= ITE_INGRF
;
358 ip
->flags
&= ~ITE_CURSORON
;
360 if ((ip
->flags
& ITE_ACTIVE
) == 0)
363 (ip
->flags
& (ITE_INGRF
|ITE_ISCONS
|ITE_INITED
)) == ITE_INITED
)
364 (*ip
->isw
->ite_deinit
)(ip
);
367 * XXX When the system is rebooted with "reboot", init(8)
368 * kills the last process to have the console open.
369 * If we don't prevent the ITE_ACTIVE bit from being
370 * cleared, we will never see messages printed during
371 * the process of rebooting.
373 if ((flag
& 2) == 0 && (ip
->flags
& ITE_ISCONS
) == 0)
374 ip
->flags
&= ~ITE_ACTIVE
;
379 iteopen(dev_t dev
, int mode
, int devtype
, struct lwp
*l
)
381 int unit
= ITEUNIT(dev
);
383 struct ite_softc
*sc
;
388 sc
= device_lookup_private(&ite_cd
, unit
);
393 if (ip
->tty
== NULL
) {
394 tp
= ip
->tty
= ttymalloc();
398 if (kauth_authorize_device_tty(l
->l_cred
, KAUTH_DEVICE_TTY_OPEN
, tp
))
400 if ((ip
->flags
& ITE_ACTIVE
) == 0) {
401 error
= iteon(ip
, 0);
406 tp
->t_oproc
= itestart
;
409 if ((tp
->t_state
&TS_ISOPEN
) == 0) {
411 tp
->t_iflag
= TTYDEF_IFLAG
;
412 tp
->t_oflag
= TTYDEF_OFLAG
;
413 tp
->t_cflag
= CS8
|CREAD
;
414 tp
->t_lflag
= TTYDEF_LFLAG
;
415 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
416 tp
->t_state
= TS_ISOPEN
|TS_CARR_ON
;
419 error
= (*tp
->t_linesw
->l_open
)(dev
, tp
);
421 tp
->t_winsize
.ws_row
= ip
->rows
;
422 tp
->t_winsize
.ws_col
= ip
->cols
;
430 iteclose(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
432 struct ite_softc
*sc
= device_lookup_private(&ite_cd
, ITEUNIT(dev
));
433 struct ite_data
*ip
= sc
->sc_data
;
434 struct tty
*tp
= ip
->tty
;
436 (*tp
->t_linesw
->l_close
)(tp
, flag
);
448 iteread(dev_t dev
, struct uio
*uio
, int flag
)
450 struct ite_softc
*sc
= device_lookup_private(&ite_cd
, ITEUNIT(dev
));
451 struct tty
*tp
= sc
->sc_data
->tty
;
453 return (*tp
->t_linesw
->l_read
)(tp
, uio
, flag
);
457 itewrite(dev_t dev
, struct uio
*uio
, int flag
)
459 struct ite_softc
*sc
= device_lookup_private(&ite_cd
, ITEUNIT(dev
));
460 struct tty
*tp
= sc
->sc_data
->tty
;
462 return (*tp
->t_linesw
->l_write
)(tp
, uio
, flag
);
466 itepoll(dev_t dev
, int events
, struct lwp
*l
)
468 struct ite_softc
*sc
= device_lookup_private(&ite_cd
, ITEUNIT(dev
));
469 struct tty
*tp
= sc
->sc_data
->tty
;
471 return (*tp
->t_linesw
->l_poll
)(tp
, events
, l
);
477 struct ite_softc
*sc
= device_lookup_private(&ite_cd
, ITEUNIT(dev
));
479 return sc
->sc_data
->tty
;
483 iteioctl(dev_t dev
, u_long cmd
, void *addr
, int flag
, struct lwp
*l
)
485 struct ite_softc
*sc
= device_lookup_private(&ite_cd
, ITEUNIT(dev
));
486 struct ite_data
*ip
= sc
->sc_data
;
487 struct tty
*tp
= ip
->tty
;
490 error
= (*tp
->t_linesw
->l_ioctl
)(tp
, cmd
, addr
, flag
, l
);
491 if (error
!= EPASSTHROUGH
)
493 return ttioctl(tp
, cmd
, addr
, flag
, l
);
497 itestart(struct tty
*tp
)
500 int hiwat
= 0, hadcursor
= 0;
501 struct ite_softc
*sc
;
504 sc
= device_lookup_private(&ite_cd
, ITEUNIT(tp
->t_dev
));
508 if (tp
->t_state
& (TS_TIMEOUT
|TS_BUSY
|TS_TTSTOP
)) {
512 tp
->t_state
|= TS_BUSY
;
513 cc
= tp
->t_outq
.c_cc
;
516 * Handle common (?) case
519 iteputchar(getc(&tp
->t_outq
), ip
);
522 * Limit the amount of output we do in one burst
523 * to prevent hogging the CPU.
530 * Turn off cursor while we output multiple characters.
531 * Saves a lot of expensive window move operations.
533 if (ip
->flags
& ITE_CURSORON
) {
534 ite_erasecursor(ip
, ip
->isw
);
535 ip
->flags
&= ~ITE_CURSORON
;
539 iteputchar(getc(&tp
->t_outq
), ip
);
541 ip
->flags
|= ITE_CURSORON
;
542 ite_drawcursor(ip
, ip
->isw
);
545 tp
->t_state
|= TS_TIMEOUT
;
546 callout_schedule(&tp
->t_rstrt_ch
, 1);
549 tp
->t_state
&= ~TS_BUSY
;
554 itefilter(char stat
, char c
)
556 static int capsmode
= 0;
557 static int metamode
= 0;
562 if (ite_cn
.tty
== NULL
)
565 kbd_tty
= ite_cn
.tty
;
569 capsmode
= !capsmode
;
572 case KBD_EXT_LEFT_DOWN
:
573 case KBD_EXT_RIGHT_DOWN
:
577 case KBD_EXT_LEFT_UP
:
578 case KBD_EXT_RIGHT_UP
:
584 switch ((stat
>>KBD_SSHIFT
) & KBD_SMASK
) {
587 code
= ite_km
->kbd_keymap
[(int)c
];
589 code
= toupper(code
);
593 code
= ite_km
->kbd_shiftmap
[(int)c
];
595 code
= tolower(code
);
599 code
= ite_km
->kbd_ctrlmap
[(int)c
];
603 code
= ite_km
->kbd_ctrlshiftmap
[(int)c
];
607 if (code
== '\0' && (str
= ite_km
->kbd_stringmap
[(int)c
]) != NULL
) {
609 (*kbd_tty
->t_linesw
->l_rint
)(*str
++, kbd_tty
);
613 (*kbd_tty
->t_linesw
->l_rint
)(code
, kbd_tty
);
618 iteputchar(int c
, struct ite_data
*ip
)
620 struct itesw
*sp
= ip
->isw
;
623 if ((ip
->flags
& (ITE_ACTIVE
|ITE_INGRF
)) != ITE_ACTIVE
)
628 switch (ip
->escape
) {
630 case '&': /* Next can be a,d, or s */
637 case 'a': /* cursor change */
640 case 'Y': /* Only y coord. */
641 ip
->cury
= min(ip
->pos
, ip
->rows
-1);
644 ite_movecursor(ip
, sp
);
645 clr_attr(ip
, ATTR_INV
);
648 case 'y': /* y coord first */
649 ip
->cury
= min(ip
->pos
, ip
->rows
-1);
654 case 'C': /* x coord */
655 ip
->curx
= min(ip
->pos
, ip
->cols
-1);
658 ite_movecursor(ip
, sp
);
659 clr_attr(ip
, ATTR_INV
);
662 default: /* Possibly a 3 digit number. */
663 if (c
>= '0' && c
<= '9' && ip
->fpd
< 3) {
664 ip
->pos
= ip
->pos
* 10 + (c
- '0');
674 case 'd': /* attribute change */
678 set_attr(ip
, ATTR_INV
);
681 /* XXX: we don't do anything for underline */
682 set_attr(ip
, ATTR_UL
);
685 clr_attr(ip
, ATTR_ALL
);
691 case 's': /* keypad control */
704 clr_attr(ip
, ATTR_KPAD
);
707 set_attr(ip
, ATTR_KPAD
);
716 case 'i': /* back tab */
717 if (ip
->curx
> TABSIZE
) {
718 n
= ip
->curx
- (ip
->curx
& (TABSIZE
- 1));
722 ite_movecursor(ip
, sp
);
726 case '3': /* clear all tabs */
729 case 'K': /* clear_eol */
730 ite_clrtoeol(ip
, sp
, ip
->cury
, ip
->curx
);
734 case 'J': /* clear_eos */
735 ite_clrtoeos(ip
, sp
);
739 case 'B': /* cursor down 1 line */
740 if (++ip
->cury
== ip
->rows
) {
742 ite_erasecursor(ip
, sp
);
743 (*sp
->ite_scroll
)(ip
, 1, 0, 1, SCROLL_UP
);
744 ite_clrtoeol(ip
, sp
, ip
->cury
, 0);
747 ite_movecursor(ip
, sp
);
748 clr_attr(ip
, ATTR_INV
);
752 case 'C': /* cursor forward 1 char */
754 itecheckwrap(ip
, sp
);
757 case 'A': /* cursor up 1 line */
760 ite_movecursor(ip
, sp
);
763 clr_attr(ip
, ATTR_INV
);
766 case 'P': /* delete character */
771 case 'M': /* delete line */
776 case 'Q': /* enter insert mode */
781 case 'R': /* exit insert mode */
786 case 'L': /* insert blank line */
791 case 'h': /* home key */
792 ip
->cury
= ip
->curx
= 0;
793 ite_movecursor(ip
, sp
);
797 case 'D': /* left arrow key */
800 ite_movecursor(ip
, sp
);
805 case '1': /* set tab in all rows */
809 if ((ip
->escape
= c
) == ESC
)
826 if (++ip
->cury
== ip
->rows
) {
828 ite_erasecursor(ip
, sp
);
829 (*sp
->ite_scroll
)(ip
, 1, 0, 1, SCROLL_UP
);
830 ite_clrtoeol(ip
, sp
, ip
->cury
, 0);
832 ite_movecursor(ip
, sp
);
833 clr_attr(ip
, ATTR_INV
);
839 ite_movecursor(ip
, sp
);
847 ite_movecursor(ip
, sp
);
851 if (ip
->curx
< TABEND(ip
)) {
852 n
= TABSIZE
- (ip
->curx
& (TABSIZE
- 1));
854 ite_movecursor(ip
, sp
);
856 itecheckwrap(ip
, sp
);
860 if (console_kbdops
!= NULL
)
861 (*console_kbdops
->bell
)(console_kbdops
->arg
);
869 if (c
< ' ' || c
== DEL
)
873 if ((ip
->attribute
& ATTR_INV
) || attrtest(ip
, ATTR_INV
)) {
874 attrset(ip
, ATTR_INV
);
875 (*sp
->ite_putc
)(ip
, c
, ip
->cury
, ip
->curx
, ATTR_INV
);
877 (*sp
->ite_putc
)(ip
, c
, ip
->cury
, ip
->curx
, ATTR_NOR
);
878 ite_drawcursor(ip
, sp
);
879 itecheckwrap(ip
, sp
);
885 itecheckwrap(struct ite_data
*ip
, struct itesw
*sp
)
888 if (++ip
->curx
== ip
->cols
) {
890 clr_attr(ip
, ATTR_INV
);
891 if (++ip
->cury
== ip
->rows
) {
893 ite_erasecursor(ip
, sp
);
894 (*sp
->ite_scroll
)(ip
, 1, 0, 1, SCROLL_UP
);
895 ite_clrtoeol(ip
, sp
, ip
->cury
, 0);
899 ite_movecursor(ip
, sp
);
903 ite_dchar(struct ite_data
*ip
, struct itesw
*sp
)
906 if (ip
->curx
< ip
->cols
- 1) {
907 ite_erasecursor(ip
, sp
);
908 (*sp
->ite_scroll
)(ip
, ip
->cury
, ip
->curx
+ 1, 1, SCROLL_LEFT
);
909 attrmov(ip
, ip
->cury
, ip
->curx
+ 1, ip
->cury
, ip
->curx
,
910 1, ip
->cols
- ip
->curx
- 1);
912 attrclr(ip
, ip
->cury
, ip
->cols
- 1, 1, 1);
913 (*sp
->ite_putc
)(ip
, ' ', ip
->cury
, ip
->cols
- 1, ATTR_NOR
);
914 ite_drawcursor(ip
, sp
);
918 ite_ichar(struct ite_data
*ip
, struct itesw
*sp
)
921 if (ip
->curx
< ip
->cols
- 1) {
922 ite_erasecursor(ip
, sp
);
923 (*sp
->ite_scroll
)(ip
, ip
->cury
, ip
->curx
, 1, SCROLL_RIGHT
);
924 attrmov(ip
, ip
->cury
, ip
->curx
, ip
->cury
, ip
->curx
+ 1,
925 1, ip
->cols
- ip
->curx
- 1);
927 attrclr(ip
, ip
->cury
, ip
->curx
, 1, 1);
928 (*sp
->ite_putc
)(ip
, ' ', ip
->cury
, ip
->curx
, ATTR_NOR
);
929 ite_drawcursor(ip
, sp
);
933 ite_dline(struct ite_data
*ip
, struct itesw
*sp
)
936 if (ip
->cury
< ip
->rows
- 1) {
937 ite_erasecursor(ip
, sp
);
938 (*sp
->ite_scroll
)(ip
, ip
->cury
+ 1, 0, 1, SCROLL_UP
);
939 attrmov(ip
, ip
->cury
+ 1, 0, ip
->cury
, 0,
940 ip
->rows
- ip
->cury
- 1, ip
->cols
);
942 ite_clrtoeol(ip
, sp
, ip
->rows
- 1, 0);
946 ite_iline(struct ite_data
*ip
, struct itesw
*sp
)
949 if (ip
->cury
< ip
->rows
- 1) {
950 ite_erasecursor(ip
, sp
);
951 (*sp
->ite_scroll
)(ip
, ip
->cury
, 0, 1, SCROLL_DOWN
);
952 attrmov(ip
, ip
->cury
, 0, ip
->cury
+ 1, 0,
953 ip
->rows
- ip
->cury
- 1, ip
->cols
);
955 ite_clrtoeol(ip
, sp
, ip
->cury
, 0);
959 ite_clrtoeol(struct ite_data
*ip
, struct itesw
*sp
, int y
, int x
)
962 (*sp
->ite_clear
)(ip
, y
, x
, 1, ip
->cols
- x
);
963 attrclr(ip
, y
, x
, 1, ip
->cols
- x
);
964 ite_drawcursor(ip
, sp
);
968 ite_clrtoeos(struct ite_data
*ip
, struct itesw
*sp
)
971 (*sp
->ite_clear
)(ip
, ip
->cury
, 0, ip
->rows
- ip
->cury
, ip
->cols
);
972 attrclr(ip
, ip
->cury
, 0, ip
->rows
- ip
->cury
, ip
->cols
);
973 ite_drawcursor(ip
, sp
);
979 * Console functions. Console probes are done by the individual
980 * framebuffer drivers.
984 itedisplaycnattach(struct grf_data
*gp
, struct itesw
*isw
)
986 struct ite_data
*ip
= &ite_cn
;
989 * Set up required ite data and initialize ite.
993 ip
->flags
= ITE_ALIVE
|ITE_CONSOLE
|ITE_ACTIVE
|ITE_ISCONS
;
994 ip
->attrbuf
= ite_console_attributes
;
996 console_display_attached
= 1;
998 if (console_kbd_attached
&& console_display_attached
)
1003 itekbdcnattach(struct ite_kbdops
*ops
, struct ite_kbdmap
*map
)
1006 console_kbdops
= ops
;
1007 console_kbdmap
= map
;
1008 console_kbd_attached
= 1;
1010 if (console_kbd_attached
&& console_display_attached
)
1019 cn_tab
->cn_dev
= makedev(cdevsw_lookup_major(&ite_cdevsw
), 0);
1024 itecngetc(dev_t dev
)
1029 if (console_kbdops
== NULL
)
1032 c
= (*console_kbdops
->getc
)(&stat
);
1033 switch ((stat
>> KBD_SSHIFT
) & KBD_SMASK
) {
1035 c
= console_kbdmap
->shiftmap
[c
& KBD_CHARMASK
];
1038 c
= console_kbdmap
->ctrlmap
[c
& KBD_CHARMASK
];
1041 c
= console_kbdmap
->keymap
[c
& KBD_CHARMASK
];
1052 itecnputc(dev_t dev
, int c
)
1054 static int paniced
= 0;
1055 struct ite_data
*ip
= &ite_cn
;
1057 if (panicstr
&& !paniced
&&
1058 (ip
->flags
& (ITE_ACTIVE
|ITE_INGRF
)) != ITE_ACTIVE
) {
1059 (void) iteon(ip
, 3);