2 * linux/drivers/char/console.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * Hopefully this will be a rather complete VT102 implementation.
10 * Beeping thanks to John T Kohl.
12 * Virtual Consoles, Screen Blanking, Screen Dumping, Color, Graphics
13 * Chars, and VT100 enhancements by Peter MacDonald.
15 * Copy and paste function by Andrew Haylett,
16 * some enhancements by Alessandro Rubini.
18 * Code to check for different video-cards mostly by Galen Hunt,
19 * <g-hunt@ee.utah.edu>
21 * Rudimentary ISO 10646/Unicode/UTF-8 character set support by
22 * Markus Kuhn, <mskuhn@immd4.informatik.uni-erlangen.de>.
24 * Dynamic allocation of consoles, aeb@cwi.nl, May 1994
25 * Resizing of consoles, aeb, 940926
27 * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94
30 * User-defined bell sound, new setterm control sequences and printk
31 * redirection by Martin Mares <mj@k332.feld.cvut.cz> 19-Nov-95
33 * APM screenblank bug fixed Takashi Manabe <manabe@roy.dsl.tutics.tut.jp>
35 * Merge with the abstract console driver by Geert Uytterhoeven
36 * <geert@linux-m68k.org>, Jan 1997.
38 * Original m68k console driver modifications by
40 * - Arno Griffioen <arno@usn.nl>
41 * - David Carter <carter@cs.bris.ac.uk>
43 * Note that the abstract console driver allows all consoles to be of
44 * potentially different sizes, so the following variables depend on the
45 * current console (currcons):
52 * The abstract console driver provides a generic interface for a text
53 * console. It supports VGA text mode, frame buffer based graphical consoles
54 * and special graphics processors that are only accessible through some
55 * registers (e.g. a TMS340x0 GSP).
57 * The interface to the hardware is specified using a special structure
58 * (struct consw) which contains function pointers to console operations
59 * (see <linux/console.h> for more information).
61 * Support for changeable cursor shape
62 * by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>, August 1997
64 * Ported to i386 and con_scrolldelta fixed
65 * by Emmanuel Marty <core@ggi-project.org>, April 1998
67 * Resurrected character buffers in videoram plus lots of other trickery
68 * by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998
71 #include <linux/module.h>
72 #include <linux/sched.h>
73 #include <linux/tty.h>
74 #include <linux/tty_flip.h>
75 #include <linux/kernel.h>
76 #include <linux/string.h>
77 #include <linux/errno.h>
79 #include <linux/malloc.h>
80 #include <linux/major.h>
82 #include <linux/console.h>
83 #include <linux/init.h>
84 #include <linux/vt_kern.h>
85 #include <linux/selection.h>
86 #include <linux/console_struct.h>
87 #include <linux/kbd_kern.h>
88 #include <linux/consolemap.h>
89 #include <linux/timer.h>
90 #include <linux/interrupt.h>
91 #include <linux/config.h>
92 #include <linux/version.h>
93 #include <linux/tqueue.h>
95 #include <linux/apm_bios.h>
99 #include <asm/system.h>
100 #include <asm/uaccess.h>
101 #include <asm/bitops.h>
103 #include <asm/linux_logo.h>
105 #include "console_macros.h"
108 struct consw
*conswitchp
= NULL
;
110 /* A bitmap for codes <32. A bit of 1 indicates that the code
111 * corresponding to that bit number invokes some special action
112 * (such as cursor movement) and should not be displayed as a
113 * glyph unless the disp_ctrl mode is explicitly enabled.
115 #define CTRL_ACTION 0x0d00ff81
116 #define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */
119 * Here is the default bell parameters: 750HZ, 1/8th of a second
121 #define DEFAULT_BELL_PITCH 750
122 #define DEFAULT_BELL_DURATION (HZ/8)
125 #define MIN(a,b) ((a) < (b) ? (a) : (b))
128 static struct tty_struct
*console_table
[MAX_NR_CONSOLES
];
129 static struct termios
*console_termios
[MAX_NR_CONSOLES
];
130 static struct termios
*console_termios_locked
[MAX_NR_CONSOLES
];
131 struct vc vc_cons
[MAX_NR_CONSOLES
];
133 #ifndef VT_SINGLE_DRIVER
134 static struct consw
*con_driver_map
[MAX_NR_CONSOLES
];
137 static int con_open(struct tty_struct
*, struct file
*);
138 static void vc_init(unsigned int console
, unsigned int rows
,
139 unsigned int cols
, int do_clear
);
140 static void blank_screen(void);
141 static void gotoxy(int currcons
, int new_x
, int new_y
);
142 static void save_cur(int currcons
);
143 static void reset_terminal(int currcons
, int do_clear
);
144 static void con_flush_chars(struct tty_struct
*tty
);
145 static void set_vesa_blanking(unsigned long arg
);
146 static void set_cursor(int currcons
);
147 static void hide_cursor(int currcons
);
149 static int printable
= 0; /* Is console ready for printing? */
151 int do_poke_blanked_console
= 0;
152 int console_blanked
= 0;
154 static int vesa_blank_mode
= 0; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
155 static int blankinterval
= 10*60*HZ
;
156 static int vesa_off_interval
= 0;
159 * fg_console is the current virtual console,
160 * last_console is the last used one,
161 * want_console is the console we want to switch to,
162 * kmsg_redirect is the console for kernel messages,
165 int last_console
= 0;
166 int want_console
= -1;
167 int kmsg_redirect
= 0;
170 * For each existing display, we have a pointer to console currently visible
171 * on that display, allowing consoles other than fg_console to be refreshed
172 * appropriately. Unless the low-level driver supplies its own display_fg
173 * variable, we use this one for the "master display".
175 static struct vc_data
*master_display_fg
= NULL
;
178 * Unfortunately, we need to delay tty echo when we're currently writing to the
179 * console since the code is (and always was) not re-entrant, so we insert
180 * all filp requests to con_task_queue instead of tq_timer and run it from
183 DECLARE_TASK_QUEUE(con_task_queue
);
186 * For the same reason, we defer scrollback to the console_bh.
188 static int scrollback_delta
= 0;
191 * Low-Level Functions
194 #define IS_FG (currcons == fg_console)
195 #define IS_VISIBLE CON_IS_VISIBLE(vc_cons[currcons].d)
197 #ifdef VT_BUF_VRAM_ONLY
200 #define DO_UPDATE IS_VISIBLE
203 static inline unsigned short *screenpos(int currcons
, int offset
, int viewed
)
208 p
= (unsigned short *)(origin
+ offset
);
209 else if (!sw
->con_screen_pos
)
210 p
= (unsigned short *)(visible_origin
+ offset
);
212 p
= sw
->con_screen_pos(vc_cons
[currcons
].d
, offset
);
216 static inline void scrolldelta(int lines
)
218 scrollback_delta
+= lines
;
222 static void scrup(int currcons
, unsigned int t
, unsigned int b
, int nr
)
224 unsigned short *d
, *s
;
228 if (b
> video_num_lines
|| t
>= b
|| nr
< 1)
230 if (IS_VISIBLE
&& sw
->con_scroll(vc_cons
[currcons
].d
, t
, b
, SM_UP
, nr
))
232 d
= (unsigned short *) (origin
+video_size_row
*t
);
233 s
= (unsigned short *) (origin
+video_size_row
*(t
+nr
));
234 scr_memcpyw(d
, s
, (b
-t
-nr
) * video_size_row
);
235 scr_memsetw(d
+ (b
-t
-nr
) * video_num_columns
, video_erase_char
, video_size_row
*nr
);
239 scrdown(int currcons
, unsigned int t
, unsigned int b
, int nr
)
246 if (b
> video_num_lines
|| t
>= b
|| nr
< 1)
248 if (IS_VISIBLE
&& sw
->con_scroll(vc_cons
[currcons
].d
, t
, b
, SM_DOWN
, nr
))
250 s
= (unsigned short *) (origin
+video_size_row
*t
);
251 step
= video_num_columns
* nr
;
252 scr_memmovew(s
+ step
, s
, (b
-t
-nr
)*video_size_row
);
253 scr_memsetw(s
, video_erase_char
, 2*step
);
256 static void do_update_region(int currcons
, unsigned long start
, int count
)
258 #ifndef VT_BUF_VRAM_ONLY
259 unsigned int xx
, yy
, offset
;
263 if (!sw
->con_getxy
) {
264 offset
= (start
- origin
) / 2;
265 xx
= offset
% video_num_columns
;
266 yy
= offset
/ video_num_columns
;
269 start
= sw
->con_getxy(vc_cons
[currcons
].d
, start
, &nxx
, &nyy
);
273 u16 attrib
= scr_readw(p
) & 0xff00;
276 while (xx
< video_num_columns
&& count
) {
277 if (attrib
!= (scr_readw(p
) & 0xff00)) {
279 sw
->con_putcs(vc_cons
[currcons
].d
, q
, p
-q
, yy
, startx
);
282 attrib
= scr_readw(p
) & 0xff00;
289 sw
->con_putcs(vc_cons
[currcons
].d
, q
, p
-q
, yy
, startx
);
296 start
= sw
->con_getxy(vc_cons
[currcons
].d
, start
, NULL
, NULL
);
302 void update_region(int currcons
, unsigned long start
, int count
)
305 hide_cursor(currcons
);
306 do_update_region(currcons
, start
, count
);
307 set_cursor(currcons
);
311 /* Structure of attributes is hardware-dependent */
313 static u8
build_attr(int currcons
, u8 _color
, u8 _intensity
, u8 _blink
, u8 _underline
, u8 _reverse
)
315 if (sw
->con_build_attr
)
316 return sw
->con_build_attr(vc_cons
[currcons
].d
, _color
, _intensity
, _blink
, _underline
, _reverse
);
318 #ifndef VT_BUF_VRAM_ONLY
320 * ++roman: I completely changed the attribute format for monochrome
321 * mode (!can_do_color). The formerly used MDA (monochrome display
322 * adapter) format didn't allow the combination of certain effects.
323 * Now the attribute is just a bit vector:
324 * Bit 0..1: intensity (0..2)
333 (_underline
? 4 : 0) |
337 a
= (a
& 0xf0) | ulcolor
;
338 else if (_intensity
== 0)
339 a
= (a
& 0xf0) | halfcolor
;
341 a
= ((a
) & 0x88) | ((((a
) >> 4) | ((a
) << 4)) & 0x77);
346 if (hi_font_mask
== 0x100)
355 static void update_attr(int currcons
)
357 attr
= build_attr(currcons
, color
, intensity
, blink
, underline
, reverse
^ decscnm
);
358 video_erase_char
= (build_attr(currcons
, color
, 1, 0, 0, decscnm
) << 8) | ' ';
361 /* Note: inverting the screen twice should revert to the original state */
363 void invert_screen(int currcons
, int offset
, int count
, int viewed
)
368 p
= screenpos(currcons
, offset
, viewed
);
369 if (sw
->con_invert_region
)
370 sw
->con_invert_region(vc_cons
[currcons
].d
, p
, count
);
371 #ifndef VT_BUF_VRAM_ONLY
377 while (cnt
--) *q
++ ^= 0x0800;
378 } else if (hi_font_mask
== 0x100) {
381 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) | (((a
) & 0x0e00) << 4);
387 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) | (((a
) & 0x0700) << 4);
394 do_update_region(currcons
, (unsigned long) p
, count
);
397 /* used by selection: complement pointer position */
398 void complement_pos(int currcons
, int offset
)
400 static unsigned short *p
= NULL
;
401 static unsigned short old
= 0;
402 static unsigned short oldx
= 0, oldy
= 0;
407 sw
->con_putc(vc_cons
[currcons
].d
, old
, oldy
, oldx
);
413 p
= screenpos(currcons
, offset
, 1);
415 new = old
^ complement_mask
;
418 oldx
= (offset
>> 1) % video_num_columns
;
419 oldy
= (offset
>> 1) / video_num_columns
;
420 sw
->con_putc(vc_cons
[currcons
].d
, new, oldy
, oldx
);
425 static void insert_char(int currcons
, unsigned int nr
)
427 unsigned short *p
, *q
= (unsigned short *) pos
;
429 p
= q
+ video_num_columns
- nr
- x
;
431 scr_writew(scr_readw(p
), p
+ nr
);
432 scr_memsetw(q
, video_erase_char
, nr
*2);
435 unsigned short oldattr
= attr
;
436 sw
->con_bmove(vc_cons
[currcons
].d
,y
,x
,y
,x
+nr
,1,
437 video_num_columns
-x
-nr
);
438 attr
= video_erase_char
>> 8;
440 sw
->con_putc(vc_cons
[currcons
].d
,
441 video_erase_char
,y
,x
+nr
);
446 static void delete_char(int currcons
, unsigned int nr
)
449 unsigned short *p
= (unsigned short *) pos
;
451 while (++i
<= video_num_columns
- nr
) {
452 scr_writew(scr_readw(p
+nr
), p
);
455 scr_memsetw(p
, video_erase_char
, nr
*2);
458 unsigned short oldattr
= attr
;
459 sw
->con_bmove(vc_cons
[currcons
].d
, y
, x
+nr
, y
, x
, 1,
460 video_num_columns
-x
-nr
);
461 attr
= video_erase_char
>> 8;
463 sw
->con_putc(vc_cons
[currcons
].d
,
465 video_num_columns
-1-nr
);
470 static int softcursor_original
;
472 static void add_softcursor(int currcons
)
474 int i
= scr_readw((u16
*) pos
);
475 u32 type
= cursor_type
;
477 if (! (type
& 0x10)) return;
478 if (softcursor_original
!= -1) return;
479 softcursor_original
= i
;
480 i
|= ((type
>> 8) & 0xff00 );
481 i
^= ((type
) & 0xff00 );
482 if ((type
& 0x20) && ((softcursor_original
& 0x7000) == (i
& 0x7000))) i
^= 0x7000;
483 if ((type
& 0x40) && ((i
& 0x700) == ((i
& 0x7000) >> 4))) i
^= 0x0700;
484 scr_writew(i
, (u16
*) pos
);
486 sw
->con_putc(vc_cons
[currcons
].d
, i
, y
, x
);
489 static void hide_cursor(int currcons
)
491 if (currcons
== sel_cons
)
493 if (softcursor_original
!= -1) {
494 scr_writew(softcursor_original
,(u16
*) pos
);
496 sw
->con_putc(vc_cons
[currcons
].d
, softcursor_original
, y
, x
);
497 softcursor_original
= -1;
499 sw
->con_cursor(vc_cons
[currcons
].d
,CM_ERASE
);
502 static void set_cursor(int currcons
)
504 if (!IS_FG
|| console_blanked
|| vcmode
== KD_GRAPHICS
)
507 if (currcons
== sel_cons
)
509 add_softcursor(currcons
);
510 if ((cursor_type
& 0x0f) != 1)
511 sw
->con_cursor(vc_cons
[currcons
].d
,CM_DRAW
);
513 hide_cursor(currcons
);
516 static void set_origin(int currcons
)
519 !sw
->con_set_origin
||
520 !sw
->con_set_origin(vc_cons
[currcons
].d
))
521 origin
= (unsigned long) screenbuf
;
522 visible_origin
= origin
;
523 scr_end
= origin
+ screenbuf_size
;
524 pos
= origin
+ video_size_row
*y
+ 2*x
;
527 static inline void save_screen(int currcons
)
529 if (sw
->con_save_screen
)
530 sw
->con_save_screen(vc_cons
[currcons
].d
);
534 * Redrawing of screen
537 void redraw_screen(int new_console
, int is_switch
)
540 int currcons
, old_console
;
545 if (!vc_cons_allocated(new_console
)) {
547 printk("redraw_screen: tty %d not allocated ??\n", new_console
+1);
553 currcons
= fg_console
;
554 hide_cursor(currcons
);
555 if (fg_console
!= new_console
) {
556 struct vc_data
**display
= vc_cons
[new_console
].d
->vc_display_fg
;
557 old_console
= (*display
) ? (*display
)->vc_num
: fg_console
;
558 *display
= vc_cons
[new_console
].d
;
559 fg_console
= new_console
;
560 currcons
= old_console
;
562 save_screen(currcons
);
563 set_origin(currcons
);
565 currcons
= new_console
;
566 if (old_console
== new_console
)
570 currcons
= new_console
;
571 hide_cursor(currcons
);
575 set_origin(currcons
);
576 set_palette(currcons
);
577 if (sw
->con_switch(vc_cons
[currcons
].d
) && vcmode
!= KD_GRAPHICS
)
578 /* Update the screen contents */
579 do_update_region(currcons
, origin
, screenbuf_size
/2);
581 set_cursor(currcons
);
584 compute_shiftstate();
590 * Allocation, freeing and resizing of VTs.
593 int vc_cons_allocated(unsigned int i
)
595 return (i
< MAX_NR_CONSOLES
&& vc_cons
[i
].d
);
598 static void visual_init(int currcons
, int init
)
600 /* ++Geert: sw->con_init determines console size */
602 #ifndef VT_SINGLE_DRIVER
603 if (con_driver_map
[currcons
])
604 sw
= con_driver_map
[currcons
];
607 display_fg
= &master_display_fg
;
608 vc_cons
[currcons
].d
->vc_uni_pagedir_loc
= &vc_cons
[currcons
].d
->vc_uni_pagedir
;
609 vc_cons
[currcons
].d
->vc_uni_pagedir
= 0;
613 sw
->con_init(vc_cons
[currcons
].d
, init
);
614 if (!complement_mask
)
615 complement_mask
= can_do_color
? 0x7700 : 0x0800;
616 s_complement_mask
= complement_mask
;
617 video_size_row
= video_num_columns
<<1;
618 screenbuf_size
= video_num_lines
*video_size_row
;
621 int vc_allocate(unsigned int currcons
) /* return 0 on success */
623 if (currcons
>= MAX_NR_CONSOLES
)
625 if (!vc_cons
[currcons
].d
) {
628 /* prevent users from taking too much memory */
629 if (currcons
>= MAX_NR_USER_CONSOLES
&& !capable(CAP_SYS_RESOURCE
))
632 /* due to the granularity of kmalloc, we waste some memory here */
633 /* the alloc is done in two steps, to optimize the common situation
634 of a 25x80 console (structsize=216, screenbuf_size=4000) */
635 /* although the numbers above are not valid since long ago, the
636 point is still up-to-date and the comment still has its value
637 even if only as a historical artifact. --mj, July 1998 */
638 p
= (long) kmalloc(structsize
, GFP_KERNEL
);
641 vc_cons
[currcons
].d
= (struct vc_data
*)p
;
642 vt_cons
[currcons
] = (struct vt_struct
*)(p
+sizeof(struct vc_data
));
643 visual_init(currcons
, 1);
644 if (!*vc_cons
[currcons
].d
->vc_uni_pagedir_loc
)
645 con_set_default_unimap(currcons
);
646 q
= (long)kmalloc(screenbuf_size
, GFP_KERNEL
);
648 kfree_s((char *) p
, structsize
);
649 vc_cons
[currcons
].d
= NULL
;
650 vt_cons
[currcons
] = NULL
;
653 screenbuf
= (unsigned short *) q
;
655 vc_init(currcons
, video_num_lines
, video_num_columns
, 1);
661 * Change # of rows and columns (0 means unchanged/the size of fg_console)
662 * [this is to be used together with some user program
663 * like resize that changes the hardware videomode]
665 int vc_resize(unsigned int lines
, unsigned int cols
,
666 unsigned int first
, unsigned int last
)
668 unsigned int cc
, ll
, ss
, sr
, todo
= 0;
669 unsigned int currcons
= fg_console
, i
;
670 unsigned short *newscreens
[MAX_NR_CONSOLES
];
672 cc
= (cols
? cols
: video_num_columns
);
673 ll
= (lines
? lines
: video_num_lines
);
677 for (currcons
= first
; currcons
<= last
; currcons
++) {
678 if (!vc_cons_allocated(currcons
) ||
679 (cc
== video_num_columns
&& ll
== video_num_lines
))
680 newscreens
[currcons
] = NULL
;
682 unsigned short *p
= (unsigned short *) kmalloc(ss
, GFP_USER
);
684 for (i
= first
; i
< currcons
; i
++)
686 kfree_s(newscreens
[i
], ss
);
689 newscreens
[currcons
] = p
;
696 for (currcons
= first
; currcons
<= last
; currcons
++) {
697 unsigned int occ
, oll
, oss
, osr
;
698 unsigned long ol
, nl
, nlend
, rlth
, rrem
;
699 if (!newscreens
[currcons
] || !vc_cons_allocated(currcons
))
702 oll
= video_num_lines
;
703 occ
= video_num_columns
;
704 osr
= video_size_row
;
705 oss
= screenbuf_size
;
707 video_num_lines
= ll
;
708 video_num_columns
= cc
;
715 nl
= (long) newscreens
[currcons
];
718 ol
+= (oll
- ll
) * osr
;
720 update_attr(currcons
);
722 while (ol
< scr_end
) {
723 scr_memcpyw((unsigned short *) nl
, (unsigned short *) ol
, rlth
);
725 scr_memsetw((void *)(nl
+ rlth
), video_erase_char
, rrem
);
730 scr_memsetw((void *) nl
, video_erase_char
, nlend
- nl
);
732 kfree_s(screenbuf
, oss
);
733 screenbuf
= newscreens
[currcons
];
736 set_origin(currcons
);
738 /* do part of a reset_terminal() */
740 bottom
= video_num_lines
;
741 gotoxy(currcons
, x
, y
);
744 if (console_table
[currcons
]) {
745 struct winsize ws
, *cws
= &console_table
[currcons
]->winsize
;
746 memset(&ws
, 0, sizeof(ws
));
747 ws
.ws_row
= video_num_lines
;
748 ws
.ws_col
= video_num_columns
;
749 if ((ws
.ws_row
!= cws
->ws_row
|| ws
.ws_col
!= cws
->ws_col
) &&
750 console_table
[currcons
]->pgrp
> 0)
751 kill_pg(console_table
[currcons
]->pgrp
, SIGWINCH
, 1);
756 update_screen(currcons
);
763 void vc_disallocate(unsigned int currcons
)
765 if (vc_cons_allocated(currcons
)) {
766 sw
->con_deinit(vc_cons
[currcons
].d
);
768 kfree_s(screenbuf
, screenbuf_size
);
769 if (currcons
>= MIN_NR_CONSOLES
)
770 kfree_s(vc_cons
[currcons
].d
, structsize
);
771 vc_cons
[currcons
].d
= NULL
;
779 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x)
780 #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x)
781 #define is_kbd(x) vc_kbd_mode(kbd_table+currcons,x)
783 #define decarm VC_REPEAT
784 #define decckm VC_CKMODE
785 #define kbdapplic VC_APPLIC
789 * this is what the terminal answers to a ESC-Z or csi0c query.
791 #define VT100ID "\033[?1;2c"
792 #define VT102ID "\033[?6c"
794 unsigned char color_table
[] = { 0, 4, 2, 6, 1, 5, 3, 7,
795 8,12,10,14, 9,13,11,15 };
797 /* the default colour table, for VGA+ colour systems */
798 int default_red
[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
799 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
800 int default_grn
[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
801 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
802 int default_blu
[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
803 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
806 * gotoxy() must verify all boundaries, because the arguments
807 * might also be negative. If the given position is out of
808 * bounds, the cursor is placed at the nearest margin.
810 static void gotoxy(int currcons
, int new_x
, int new_y
)
817 if (new_x
>= video_num_columns
)
818 x
= video_num_columns
- 1;
826 max_y
= video_num_lines
;
830 else if (new_y
>= max_y
)
834 pos
= origin
+ y
*video_size_row
+ (x
<<1);
838 /* for absolute user moves, when decom is set */
839 static void gotoxay(int currcons
, int new_x
, int new_y
)
841 gotoxy(currcons
, new_x
, decom
? (top
+new_y
) : new_y
);
844 void scrollback(int lines
)
846 int currcons
= fg_console
;
849 lines
= video_num_lines
/2;
853 void scrollfront(int lines
)
855 int currcons
= fg_console
;
858 lines
= video_num_lines
/2;
862 static void lf(int currcons
)
864 /* don't scroll if above bottom of scrolling region, or
865 * if below scrolling region
868 scrup(currcons
,top
,bottom
,1);
869 else if (y
< video_num_lines
-1) {
871 pos
+= video_size_row
;
876 static void ri(int currcons
)
878 /* don't scroll if below top of scrolling region, or
879 * if above scrolling region
882 scrdown(currcons
,top
,bottom
,1);
885 pos
-= video_size_row
;
890 static inline void cr(int currcons
)
896 static inline void bs(int currcons
)
905 static inline void del(int currcons
)
910 static void csi_J(int currcons
, int vpar
)
913 unsigned short * start
;
916 case 0: /* erase from cursor to end of display */
917 count
= (scr_end
-pos
)>>1;
918 start
= (unsigned short *) pos
;
920 /* do in two stages */
921 sw
->con_clear(vc_cons
[currcons
].d
, y
, x
, 1,
922 video_num_columns
-x
);
923 sw
->con_clear(vc_cons
[currcons
].d
, y
+1, 0,
928 case 1: /* erase from start to cursor */
929 count
= ((pos
-origin
)>>1)+1;
930 start
= (unsigned short *) origin
;
932 /* do in two stages */
933 sw
->con_clear(vc_cons
[currcons
].d
, 0, 0, y
,
935 sw
->con_clear(vc_cons
[currcons
].d
, y
, 0, 1,
939 case 2: /* erase whole display */
940 count
= video_num_columns
* video_num_lines
;
941 start
= (unsigned short *) origin
;
943 sw
->con_clear(vc_cons
[currcons
].d
, 0, 0,
950 scr_memsetw(start
, video_erase_char
, 2*count
);
954 static void csi_K(int currcons
, int vpar
)
957 unsigned short * start
;
960 case 0: /* erase from cursor to end of line */
961 count
= video_num_columns
-x
;
962 start
= (unsigned short *) pos
;
964 sw
->con_clear(vc_cons
[currcons
].d
, y
, x
, 1,
965 video_num_columns
-x
);
967 case 1: /* erase from start of line to cursor */
968 start
= (unsigned short *) (pos
- (x
<<1));
971 sw
->con_clear(vc_cons
[currcons
].d
, y
, 0, 1,
974 case 2: /* erase whole line */
975 start
= (unsigned short *) (pos
- (x
<<1));
976 count
= video_num_columns
;
978 sw
->con_clear(vc_cons
[currcons
].d
, y
, 0, 1,
984 scr_memsetw(start
, video_erase_char
, 2 * count
);
988 static void csi_X(int currcons
, int vpar
) /* erase the following vpar positions */
994 count
= (vpar
> video_num_columns
-x
) ? (video_num_columns
-x
) : vpar
;
996 scr_memsetw((unsigned short *) pos
, video_erase_char
, 2 * count
);
998 sw
->con_clear(vc_cons
[currcons
].d
, y
, x
, 1, count
);
1002 static void default_attr(int currcons
)
1011 static void csi_m(int currcons
)
1015 for (i
=0;i
<=npar
;i
++)
1017 case 0: /* all attributes off */
1018 default_attr(currcons
);
1035 case 10: /* ANSI X3.64-1979 (SCO-ish?)
1036 * Select primary font, don't display
1037 * control chars if defined, don't set
1040 translate
= set_translate(charset
== 0
1042 : G1_charset
,currcons
);
1046 case 11: /* ANSI X3.64-1979 (SCO-ish?)
1047 * Select first alternate font, lets
1048 * chars < 32 be displayed as ROM chars.
1050 translate
= set_translate(IBMPC_MAP
,currcons
);
1054 case 12: /* ANSI X3.64-1979 (SCO-ish?)
1055 * Select second alternate font, toggle
1056 * high bit before displaying as ROM char.
1058 translate
= set_translate(IBMPC_MAP
,currcons
);
1075 case 38: /* ANSI X3.64-1979 (SCO-ish?)
1076 * Enables underscore, white foreground
1077 * with white underscore (Linux - use
1078 * default foreground).
1080 color
= (def_color
& 0x0f) | background
;
1083 case 39: /* ANSI X3.64-1979 (SCO-ish?)
1084 * Disable underline option.
1085 * Reset colour to default? It did this
1088 color
= (def_color
& 0x0f) | background
;
1092 color
= (def_color
& 0xf0) | foreground
;
1095 if (par
[i
] >= 30 && par
[i
] <= 37)
1096 color
= color_table
[par
[i
]-30]
1098 else if (par
[i
] >= 40 && par
[i
] <= 47)
1099 color
= (color_table
[par
[i
]-40]<<4)
1103 update_attr(currcons
);
1106 static void respond_string(const char * p
, struct tty_struct
* tty
)
1109 tty_insert_flip_char(tty
, *p
, 0);
1112 con_schedule_flip(tty
);
1115 static void cursor_report(int currcons
, struct tty_struct
* tty
)
1119 sprintf(buf
, "\033[%d;%dR", y
+ (decom
? top
+1 : 1), x
+1);
1120 respond_string(buf
, tty
);
1123 static inline void status_report(struct tty_struct
* tty
)
1125 respond_string("\033[0n", tty
); /* Terminal ok */
1128 static inline void respond_ID(struct tty_struct
* tty
)
1130 respond_string(VT102ID
, tty
);
1133 void mouse_report(struct tty_struct
* tty
, int butt
, int mrx
, int mry
)
1137 sprintf(buf
, "\033[M%c%c%c", (char)(' ' + butt
), (char)('!' + mrx
),
1139 respond_string(buf
, tty
);
1142 /* invoked via ioctl(TIOCLINUX) and through set_selection */
1143 int mouse_reporting(void)
1145 int currcons
= fg_console
;
1147 return report_mouse
;
1150 static void set_mode(int currcons
, int on_off
)
1154 for (i
=0; i
<=npar
; i
++)
1155 if (ques
) switch(par
[i
]) { /* DEC private modes set/reset */
1156 case 1: /* Cursor keys send ^[Ox/^[[x */
1162 case 3: /* 80/132 mode switch unimplemented */
1165 (void) vc_resize(video_num_lines
, deccolm
? 132 : 80);
1166 /* this alone does not suffice; some user mode
1167 utility has to change the hardware regs */
1170 case 5: /* Inverted screen on/off */
1171 if (decscnm
!= on_off
) {
1173 invert_screen(currcons
, 0, screenbuf_size
, 0);
1174 update_attr(currcons
);
1177 case 6: /* Origin relative/absolute */
1179 gotoxay(currcons
,0,0);
1181 case 7: /* Autowrap on/off */
1184 case 8: /* Autorepeat on/off */
1191 report_mouse
= on_off
? 1 : 0;
1193 case 25: /* Cursor on/off */
1197 report_mouse
= on_off
? 2 : 0;
1199 } else switch(par
[i
]) { /* ANSI modes set/reset */
1200 case 3: /* Monitor (display ctrls) */
1203 case 4: /* Insert Mode on/off */
1206 case 20: /* Lf, Enter == CrLf/Lf */
1215 static void setterm_command(int currcons
)
1218 case 1: /* set color for underline mode */
1219 if (can_do_color
&& par
[1] < 16) {
1220 ulcolor
= color_table
[par
[1]];
1222 update_attr(currcons
);
1225 case 2: /* set color for half intensity mode */
1226 if (can_do_color
&& par
[1] < 16) {
1227 halfcolor
= color_table
[par
[1]];
1229 update_attr(currcons
);
1232 case 8: /* store colors as defaults */
1234 if (hi_font_mask
== 0x100)
1236 default_attr(currcons
);
1237 update_attr(currcons
);
1239 case 9: /* set blanking interval */
1240 blankinterval
= ((par
[1] < 60) ? par
[1] : 60) * 60 * HZ
;
1241 poke_blanked_console();
1243 case 10: /* set bell frequency in Hz */
1245 bell_pitch
= par
[1];
1247 bell_pitch
= DEFAULT_BELL_PITCH
;
1249 case 11: /* set bell duration in msec */
1251 bell_duration
= (par
[1] < 2000) ?
1254 bell_duration
= DEFAULT_BELL_DURATION
;
1256 case 12: /* bring specified console to the front */
1257 if (par
[1] >= 1 && vc_cons_allocated(par
[1]-1))
1258 set_console(par
[1] - 1);
1260 case 13: /* unblank the screen */
1261 poke_blanked_console();
1263 case 14: /* set vesa powerdown interval */
1264 vesa_off_interval
= ((par
[1] < 60) ? par
[1] : 60) * 60 * HZ
;
1269 static void insert_line(int currcons
, unsigned int nr
)
1271 scrdown(currcons
,y
,bottom
,nr
);
1276 static void delete_line(int currcons
, unsigned int nr
)
1278 scrup(currcons
,y
,bottom
,nr
);
1282 static void csi_at(int currcons
, unsigned int nr
)
1284 if (nr
> video_num_columns
- x
)
1285 nr
= video_num_columns
- x
;
1288 insert_char(currcons
, nr
);
1291 static void csi_L(int currcons
, unsigned int nr
)
1293 if (nr
> video_num_lines
- y
)
1294 nr
= video_num_lines
- y
;
1297 insert_line(currcons
, nr
);
1300 static void csi_P(int currcons
, unsigned int nr
)
1302 if (nr
> video_num_columns
- x
)
1303 nr
= video_num_columns
- x
;
1306 delete_char(currcons
, nr
);
1309 static void csi_M(int currcons
, unsigned int nr
)
1311 if (nr
> video_num_lines
- y
)
1312 nr
= video_num_lines
- y
;
1315 delete_line(currcons
, nr
);
1318 static void save_cur(int currcons
)
1322 s_intensity
= intensity
;
1323 s_underline
= underline
;
1325 s_reverse
= reverse
;
1326 s_charset
= charset
;
1328 saved_G0
= G0_charset
;
1329 saved_G1
= G1_charset
;
1332 static void restore_cur(int currcons
)
1334 gotoxy(currcons
,saved_x
,saved_y
);
1335 intensity
= s_intensity
;
1336 underline
= s_underline
;
1338 reverse
= s_reverse
;
1339 charset
= s_charset
;
1341 G0_charset
= saved_G0
;
1342 G1_charset
= saved_G1
;
1343 translate
= set_translate(charset
? G1_charset
: G0_charset
,currcons
);
1344 update_attr(currcons
);
1348 enum { ESnormal
, ESesc
, ESsquare
, ESgetpars
, ESgotpars
, ESfunckey
,
1349 EShash
, ESsetG0
, ESsetG1
, ESpercent
, ESignore
, ESnonstd
,
1352 static void reset_terminal(int currcons
, int do_clear
)
1355 bottom
= video_num_lines
;
1356 vc_state
= ESnormal
;
1358 translate
= set_translate(LAT1_MAP
,currcons
);
1359 G0_charset
= LAT1_MAP
;
1360 G1_charset
= GRAF_MAP
;
1380 kbd_table
[currcons
].lockstate
= 0;
1381 kbd_table
[currcons
].slockstate
= 0;
1382 kbd_table
[currcons
].ledmode
= LED_SHOW_FLAGS
;
1383 kbd_table
[currcons
].ledflagstate
= kbd_table
[currcons
].default_ledflagstate
;
1386 cursor_type
= CUR_DEFAULT
;
1387 complement_mask
= s_complement_mask
;
1389 default_attr(currcons
);
1390 update_attr(currcons
);
1392 tab_stop
[0] = 0x01010100;
1396 tab_stop
[4] = 0x01010101;
1398 bell_pitch
= DEFAULT_BELL_PITCH
;
1399 bell_duration
= DEFAULT_BELL_DURATION
;
1401 gotoxy(currcons
,0,0);
1407 static void do_con_trol(struct tty_struct
*tty
, unsigned int currcons
, int c
)
1410 * Control characters can be used in the _middle_
1411 * of an escape sequence.
1418 kd_mksound(bell_pitch
, bell_duration
);
1425 while (x
< video_num_columns
- 1) {
1427 if (tab_stop
[x
>> 5] & (1 << (x
& 31)))
1432 case 10: case 11: case 12:
1441 translate
= set_translate(G1_charset
,currcons
);
1446 translate
= set_translate(G0_charset
,currcons
);
1450 vc_state
= ESnormal
;
1459 vc_state
= ESsquare
;
1464 vc_state
= ESnormal
;
1467 vc_state
= ESsquare
;
1470 vc_state
= ESnonstd
;
1473 vc_state
= ESpercent
;
1486 tab_stop
[x
>> 5] |= (1 << (x
& 31));
1495 restore_cur(currcons
);
1507 reset_terminal(currcons
,1);
1509 case '>': /* Numeric keypad */
1512 case '=': /* Appl. keypad */
1518 if (c
=='P') { /* palette escape sequence */
1519 for (npar
=0; npar
<NPAR
; npar
++)
1522 vc_state
= ESpalette
;
1524 } else if (c
=='R') { /* reset palette */
1525 reset_palette(currcons
);
1526 vc_state
= ESnormal
;
1528 vc_state
= ESnormal
;
1531 if ( (c
>='0'&&c
<='9') || (c
>='A'&&c
<='F') || (c
>='a'&&c
<='f') ) {
1532 par
[npar
++] = (c
>'9' ? (c
&0xDF)-'A'+10 : c
-'0') ;
1534 int i
= par
[0]*3, j
= 1;
1535 palette
[i
] = 16*par
[j
++];
1536 palette
[i
++] += par
[j
++];
1537 palette
[i
] = 16*par
[j
++];
1538 palette
[i
++] += par
[j
++];
1539 palette
[i
] = 16*par
[j
++];
1540 palette
[i
] += par
[j
];
1541 set_palette(currcons
);
1542 vc_state
= ESnormal
;
1545 vc_state
= ESnormal
;
1548 for(npar
= 0 ; npar
< NPAR
; npar
++)
1551 vc_state
= ESgetpars
;
1552 if (c
== '[') { /* Function key */
1560 if (c
==';' && npar
<NPAR
-1) {
1563 } else if (c
>='0' && c
<='9') {
1567 } else vc_state
=ESgotpars
;
1569 vc_state
= ESnormal
;
1572 set_mode(currcons
,1);
1575 set_mode(currcons
,0);
1580 cursor_type
= par
[0] | (par
[1]<<8) | (par
[2]<<16);
1582 cursor_type
= CUR_DEFAULT
;
1590 complement_mask
= par
[0]<<8 | par
[1];
1592 complement_mask
= s_complement_mask
;
1600 else if (par
[0] == 6)
1601 cursor_report(currcons
,tty
);
1611 if (par
[0]) par
[0]--;
1612 gotoxy(currcons
,par
[0],y
);
1615 if (!par
[0]) par
[0]++;
1616 gotoxy(currcons
,x
,y
-par
[0]);
1619 if (!par
[0]) par
[0]++;
1620 gotoxy(currcons
,x
,y
+par
[0]);
1623 if (!par
[0]) par
[0]++;
1624 gotoxy(currcons
,x
+par
[0],y
);
1627 if (!par
[0]) par
[0]++;
1628 gotoxy(currcons
,x
-par
[0],y
);
1631 if (!par
[0]) par
[0]++;
1632 gotoxy(currcons
,0,y
+par
[0]);
1635 if (!par
[0]) par
[0]++;
1636 gotoxy(currcons
,0,y
-par
[0]);
1639 if (par
[0]) par
[0]--;
1640 gotoxay(currcons
,x
,par
[0]);
1643 if (par
[0]) par
[0]--;
1644 if (par
[1]) par
[1]--;
1645 gotoxay(currcons
,par
[1],par
[0]);
1648 csi_J(currcons
,par
[0]);
1651 csi_K(currcons
,par
[0]);
1654 csi_L(currcons
,par
[0]);
1657 csi_M(currcons
,par
[0]);
1660 csi_P(currcons
,par
[0]);
1668 tab_stop
[x
>> 5] &= ~(1 << (x
& 31));
1669 else if (par
[0] == 3) {
1680 case 'q': /* DECLL - but only 3 leds */
1681 /* map 0,1,2,3 to 0,1,2,4 */
1683 setledstate(kbd_table
+ currcons
,
1684 (par
[0] < 3) ? par
[0] : 4);
1690 par
[1] = video_num_lines
;
1691 /* Minimum allowed region is 2 lines */
1692 if (par
[0] < par
[1] &&
1693 par
[1] <= video_num_lines
) {
1696 gotoxay(currcons
,0,0);
1703 restore_cur(currcons
);
1706 csi_X(currcons
, par
[0]);
1709 csi_at(currcons
,par
[0]);
1711 case ']': /* setterm functions */
1712 setterm_command(currcons
);
1717 vc_state
= ESnormal
;
1719 case '@': /* defined in ISO 2022 */
1722 case 'G': /* prelim official escape code */
1723 case '8': /* retained for compatibility */
1729 vc_state
= ESnormal
;
1732 vc_state
= ESnormal
;
1734 /* DEC screen alignment test. kludge :-) */
1736 (video_erase_char
& 0xff00) | 'E';
1739 (video_erase_char
& 0xff00) | ' ';
1740 do_update_region(currcons
, origin
, screenbuf_size
/2);
1745 G0_charset
= GRAF_MAP
;
1747 G0_charset
= LAT1_MAP
;
1749 G0_charset
= IBMPC_MAP
;
1751 G0_charset
= USER_MAP
;
1753 translate
= set_translate(G0_charset
,currcons
);
1754 vc_state
= ESnormal
;
1758 G1_charset
= GRAF_MAP
;
1760 G1_charset
= LAT1_MAP
;
1762 G1_charset
= IBMPC_MAP
;
1764 G1_charset
= USER_MAP
;
1766 translate
= set_translate(G1_charset
,currcons
);
1767 vc_state
= ESnormal
;
1770 vc_state
= ESnormal
;
1774 static int do_con_write(struct tty_struct
* tty
, int from_user
,
1775 const unsigned char *buf
, int count
)
1777 #ifdef VT_BUF_VRAM_ONLY
1778 #define FLUSH do { } while(0);
1780 #define FLUSH if (draw_x >= 0) { \
1781 sw->con_putcs(vc_cons[currcons].d, (u16 *)draw_from, (u16 *)draw_to-(u16 *)draw_from, y, draw_x); \
1786 int c
, tc
, ok
, n
= 0, draw_x
= -1;
1787 unsigned int currcons
;
1788 unsigned long draw_from
= 0, draw_to
= 0;
1789 struct vt_struct
*vt
= (struct vt_struct
*)tty
->driver_data
;
1790 u16 himask
, charmask
;
1792 currcons
= vt
->vc_num
;
1793 if (!vc_cons_allocated(currcons
)) {
1794 /* could this happen? */
1795 static int error
= 0;
1798 printk("con_write: tty %d not allocated\n", currcons
+1);
1804 /* just to make sure that noone lurks at places he shouldn't see. */
1805 if (verify_area(VERIFY_READ
, buf
, count
))
1806 return 0; /* ?? are error codes legal here ?? */
1809 himask
= hi_font_mask
;
1810 charmask
= himask
? 0x1ff : 0xff;
1812 /* undraw cursor first */
1814 hide_cursor(currcons
);
1816 disable_bh(CONSOLE_BH
);
1817 while (!tty
->stopped
&& count
) {
1818 enable_bh(CONSOLE_BH
);
1823 buf
++; n
++; count
--;
1824 disable_bh(CONSOLE_BH
);
1827 /* Combine UTF-8 into Unicode */
1828 /* Incomplete characters silently ignored */
1830 if (utf_count
> 0 && (c
& 0xc0) == 0x80) {
1831 utf_char
= (utf_char
<< 6) | (c
& 0x3f);
1837 if ((c
& 0xe0) == 0xc0) {
1839 utf_char
= (c
& 0x1f);
1840 } else if ((c
& 0xf0) == 0xe0) {
1842 utf_char
= (c
& 0x0f);
1843 } else if ((c
& 0xf8) == 0xf0) {
1845 utf_char
= (c
& 0x07);
1846 } else if ((c
& 0xfc) == 0xf8) {
1848 utf_char
= (c
& 0x03);
1849 } else if ((c
& 0xfe) == 0xfc) {
1851 utf_char
= (c
& 0x01);
1860 } else { /* no utf */
1861 tc
= translate
[toggle_meta
? (c
|0x80) : c
];
1864 /* If the original code was a control character we
1865 * only allow a glyph to be displayed if the code is
1866 * not normally used (such as for cursor movement) or
1867 * if the disp_ctrl mode has been explicitly enabled.
1868 * Certain characters (as given by the CTRL_ALWAYS
1869 * bitmap) are always displayed as control characters,
1870 * as the console would be pretty useless without
1871 * them; to display an arbitrary font position use the
1872 * direct-to-font zone in UTF-8 mode.
1874 ok
= tc
&& (c
>= 32 ||
1875 (!utf
&& !(((disp_ctrl
? CTRL_ALWAYS
1876 : CTRL_ACTION
) >> c
) & 1)))
1877 && (c
!= 127 || disp_ctrl
)
1880 if (vc_state
== ESnormal
&& ok
) {
1881 /* Now try to find out how to display it */
1882 tc
= conv_uni_to_pc(vc_cons
[currcons
].d
, tc
);
1884 /* If we got -4 (not found) then see if we have
1885 defined a replacement character (U+FFFD) */
1886 tc
= conv_uni_to_pc(vc_cons
[currcons
].d
, 0xfffd);
1888 /* One reason for the -4 can be that we just
1889 did a clear_unimap();
1890 try at least to show something. */
1893 } else if ( tc
== -3 ) {
1894 /* Bad hash table -- hope for the best */
1898 continue; /* Conversion failed */
1900 if (need_wrap
|| decim
)
1907 insert_char(currcons
, 1);
1909 ((attr
<< 8) & ~himask
) + ((tc
& 0x100) ? himask
: 0) + (tc
& 0xff) :
1912 if (DO_UPDATE
&& draw_x
< 0) {
1916 if (x
== video_num_columns
- 1) {
1926 do_con_trol(tty
, currcons
, c
);
1929 enable_bh(CONSOLE_BH
);
1935 * This is the console switching bottom half handler.
1937 * Doing console switching in a bottom half handler allows
1938 * us to do the switches asynchronously (needed when we want
1939 * to switch due to a keyboard interrupt), while still giving
1940 * us the option to easily disable it to avoid races when we
1941 * need to write to the console.
1943 static void console_bh(void)
1945 run_task_queue(&con_task_queue
);
1946 if (want_console
>= 0) {
1947 if (want_console
!= fg_console
&& vc_cons_allocated(want_console
)) {
1948 hide_cursor(fg_console
);
1949 change_console(want_console
);
1950 /* we only changed when the console had already
1951 been allocated - a new console is not created
1952 in an interrupt routine */
1956 if (do_poke_blanked_console
) { /* do not unblank for a LED change */
1957 do_poke_blanked_console
= 0;
1958 poke_blanked_console();
1960 if (scrollback_delta
) {
1961 int currcons
= fg_console
;
1963 if (vcmode
== KD_TEXT
)
1964 sw
->con_scrolldelta(vc_cons
[currcons
].d
, scrollback_delta
);
1965 scrollback_delta
= 0;
1969 #ifdef CONFIG_VT_CONSOLE
1972 * Console on virtual terminal
1974 * NOTE NOTE NOTE! This code can do no global locking. In particular,
1975 * we can't disable interrupts or bottom half handlers globally, because
1976 * we can be called from contexts that hold critical spinlocks, and
1977 * trying do get a global lock at this point will lead to deadlocks.
1980 void vt_console_print(struct console
*co
, const char * b
, unsigned count
)
1982 int currcons
= fg_console
;
1984 static unsigned long printing
= 0;
1985 const ushort
*start
;
1989 /* console busy or not yet initialized */
1990 if (!printable
|| test_and_set_bit(0, &printing
))
1993 if (kmsg_redirect
&& vc_cons_allocated(kmsg_redirect
- 1))
1994 currcons
= kmsg_redirect
- 1;
1996 /* read `x' only after setting currecons properly (otherwise
1997 the `x' macro will read the x of the foreground console). */
2000 if (!vc_cons_allocated(currcons
)) {
2002 printk("vt_console_print: tty %d not allocated ??\n", currcons
+1);
2006 if (vcmode
!= KD_TEXT
)
2009 /* undraw cursor first */
2011 hide_cursor(currcons
);
2013 start
= (ushort
*)pos
;
2015 /* Contrived structure to try to emulate original need_wrap behaviour
2016 * Problems caused when we have need_wrap set on '\n' character */
2019 if (c
== 10 || c
== 13 || c
== 8 || need_wrap
) {
2022 sw
->con_putcs(vc_cons
[currcons
].d
, start
, cnt
, y
, x
);
2028 if (c
== 8) { /* backspace */
2030 start
= (ushort
*)pos
;
2037 start
= (ushort
*)pos
;
2039 if (c
== 10 || c
== 13)
2042 scr_writew((attr
<< 8) + c
, (unsigned short *) pos
);
2044 if (myx
== video_num_columns
- 1) {
2053 sw
->con_putcs(vc_cons
[currcons
].d
, start
, cnt
, y
, x
);
2055 if (x
== video_num_columns
) {
2060 set_cursor(currcons
);
2061 poke_blanked_console();
2064 clear_bit(0, &printing
);
2067 static kdev_t
vt_console_device(struct console
*c
)
2069 return MKDEV(TTY_MAJOR
, c
->index
? c
->index
: fg_console
+ 1);
2072 struct console vt_console_driver
= {
2077 keyboard_wait_for_keypress
,
2088 * Handling of Linux-specific VC ioctls
2091 int tioclinux(struct tty_struct
*tty
, unsigned long arg
)
2095 if (tty
->driver
.type
!= TTY_DRIVER_TYPE_CONSOLE
)
2097 if (current
->tty
!= tty
&& !suser())
2099 if (get_user(type
, (char *)arg
))
2104 return set_selection(arg
, tty
, 1);
2106 return paste_selection(tty
);
2111 return sel_loadlut(arg
);
2115 * Make it possible to react to Shift+Mousebutton.
2116 * Note that 'shift_state' is an undocumented
2117 * kernel-internal variable; programs not closely
2118 * related to the kernel should not use this.
2121 return __put_user(data
, (char *) arg
);
2123 data
= mouse_reporting();
2124 return __put_user(data
, (char *) arg
);
2126 set_vesa_blanking(arg
);
2128 case 11: /* set kmsg redirect */
2131 if (get_user(data
, (char *)arg
+1))
2133 kmsg_redirect
= data
;
2135 case 12: /* get fg_console */
2142 * /dev/ttyN handling
2145 static int con_write(struct tty_struct
* tty
, int from_user
,
2146 const unsigned char *buf
, int count
)
2150 retval
= do_con_write(tty
, from_user
, buf
, count
);
2151 con_flush_chars(tty
);
2156 static void con_put_char(struct tty_struct
*tty
, unsigned char ch
)
2158 do_con_write(tty
, 0, &ch
, 1);
2161 static int con_write_room(struct tty_struct
*tty
)
2165 return 4096; /* No limit, really; we're not buffering */
2168 static int con_chars_in_buffer(struct tty_struct
*tty
)
2170 return 0; /* we're not buffering */
2174 * con_throttle and con_unthrottle are only used for
2175 * paste_selection(), which has to stuff in a large number of
2178 static void con_throttle(struct tty_struct
*tty
)
2182 static void con_unthrottle(struct tty_struct
*tty
)
2184 struct vt_struct
*vt
= (struct vt_struct
*) tty
->driver_data
;
2186 wake_up_interruptible(&vt
->paste_wait
);
2190 * Turn the Scroll-Lock LED on when the tty is stopped
2192 static void con_stop(struct tty_struct
*tty
)
2197 console_num
= MINOR(tty
->device
) - (tty
->driver
.minor_start
);
2198 if (!vc_cons_allocated(console_num
))
2200 set_vc_kbd_led(kbd_table
+ console_num
, VC_SCROLLOCK
);
2205 * Turn the Scroll-Lock LED off when the console is started
2207 static void con_start(struct tty_struct
*tty
)
2212 console_num
= MINOR(tty
->device
) - (tty
->driver
.minor_start
);
2213 if (!vc_cons_allocated(console_num
))
2215 clr_vc_kbd_led(kbd_table
+ console_num
, VC_SCROLLOCK
);
2219 static void con_flush_chars(struct tty_struct
*tty
)
2221 struct vt_struct
*vt
= (struct vt_struct
*)tty
->driver_data
;
2223 set_cursor(vt
->vc_num
);
2227 * Allocate the console screen memory.
2229 static int con_open(struct tty_struct
*tty
, struct file
* filp
)
2231 unsigned int currcons
;
2234 currcons
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2236 i
= vc_allocate(currcons
);
2240 vt_cons
[currcons
]->vc_num
= currcons
;
2241 tty
->driver_data
= vt_cons
[currcons
];
2243 if (!tty
->winsize
.ws_row
&& !tty
->winsize
.ws_col
) {
2244 tty
->winsize
.ws_row
= video_num_lines
;
2245 tty
->winsize
.ws_col
= video_num_columns
;
2250 static void con_close(struct tty_struct
*tty
, struct file
* filp
)
2252 if (tty
->count
== 1)
2253 tty
->driver_data
= 0;
2256 static void vc_init(unsigned int currcons
, unsigned int rows
, unsigned int cols
, int do_clear
)
2260 video_num_columns
= cols
;
2261 video_num_lines
= rows
;
2262 video_size_row
= cols
<<1;
2263 screenbuf_size
= video_num_lines
* video_size_row
;
2265 set_origin(currcons
);
2268 for (j
=k
=0; j
<16; j
++) {
2269 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_red
[j
] ;
2270 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_grn
[j
] ;
2271 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_blu
[j
] ;
2273 def_color
= 0x07; /* white */
2274 ulcolor
= 0x0f; /* bold white */
2275 halfcolor
= 0x08; /* grey */
2276 init_waitqueue_head(&vt_cons
[currcons
]->paste_wait
);
2277 reset_terminal(currcons
, do_clear
);
2281 * This routine initializes console interrupts, and does nothing
2282 * else. If you want the screen to clear, call tty_write with
2283 * the appropriate escape-sequence.
2286 struct tty_driver console_driver
;
2287 static int console_refcount
;
2289 unsigned long __init
con_init(unsigned long kmem_start
)
2291 const char *display_desc
= NULL
;
2292 unsigned int currcons
= 0;
2295 display_desc
= conswitchp
->con_startup();
2296 if (!display_desc
) {
2301 memset(&console_driver
, 0, sizeof(struct tty_driver
));
2302 console_driver
.magic
= TTY_DRIVER_MAGIC
;
2303 console_driver
.name
= "tty";
2304 console_driver
.name_base
= 1;
2305 console_driver
.major
= TTY_MAJOR
;
2306 console_driver
.minor_start
= 1;
2307 console_driver
.num
= MAX_NR_CONSOLES
;
2308 console_driver
.type
= TTY_DRIVER_TYPE_CONSOLE
;
2309 console_driver
.init_termios
= tty_std_termios
;
2310 console_driver
.flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_RESET_TERMIOS
;
2311 console_driver
.refcount
= &console_refcount
;
2312 console_driver
.table
= console_table
;
2313 console_driver
.termios
= console_termios
;
2314 console_driver
.termios_locked
= console_termios_locked
;
2316 console_driver
.open
= con_open
;
2317 console_driver
.close
= con_close
;
2318 console_driver
.write
= con_write
;
2319 console_driver
.write_room
= con_write_room
;
2320 console_driver
.put_char
= con_put_char
;
2321 console_driver
.flush_chars
= con_flush_chars
;
2322 console_driver
.chars_in_buffer
= con_chars_in_buffer
;
2323 console_driver
.ioctl
= vt_ioctl
;
2324 console_driver
.stop
= con_stop
;
2325 console_driver
.start
= con_start
;
2326 console_driver
.throttle
= con_throttle
;
2327 console_driver
.unthrottle
= con_unthrottle
;
2329 if (tty_register_driver(&console_driver
))
2330 panic("Couldn't register console driver\n");
2332 timer_table
[BLANK_TIMER
].fn
= blank_screen
;
2333 timer_table
[BLANK_TIMER
].expires
= 0;
2334 if (blankinterval
) {
2335 timer_table
[BLANK_TIMER
].expires
= jiffies
+ blankinterval
;
2336 timer_active
|= 1<<BLANK_TIMER
;
2339 /* Unfortunately, kmalloc is not running yet */
2340 /* Due to kmalloc roundup allocating statically is more efficient -
2341 so provide MIN_NR_CONSOLES for people with very little memory */
2342 for (currcons
= 0; currcons
< MIN_NR_CONSOLES
; currcons
++) {
2345 vc_cons
[currcons
].d
= (struct vc_data
*) kmem_start
;
2346 kmem_start
+= sizeof(struct vc_data
);
2347 vt_cons
[currcons
] = (struct vt_struct
*) kmem_start
;
2348 kmem_start
+= sizeof(struct vt_struct
);
2349 visual_init(currcons
, 1);
2350 screenbuf
= (unsigned short *) kmem_start
;
2351 kmem_start
+= screenbuf_size
;
2353 vc_init(currcons
, video_num_lines
, video_num_columns
,
2354 currcons
|| !sw
->con_save_screen
);
2355 for (j
=k
=0; j
<16; j
++) {
2356 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_red
[j
] ;
2357 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_grn
[j
] ;
2358 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_blu
[j
] ;
2361 currcons
= fg_console
= 0;
2362 master_display_fg
= vc_cons
[currcons
].d
;
2363 set_origin(currcons
);
2364 save_screen(currcons
);
2365 gotoxy(currcons
,x
,y
);
2367 update_screen(fg_console
);
2368 printk("Console: %s %s %dx%d",
2369 can_do_color
? "colour" : "mono",
2370 display_desc
, video_num_columns
, video_num_lines
);
2374 #ifdef CONFIG_VT_CONSOLE
2375 register_console(&vt_console_driver
);
2378 init_bh(CONSOLE_BH
, console_bh
);
2383 #ifndef VT_SINGLE_DRIVER
2385 static void clear_buffer_attributes(int currcons
)
2387 unsigned short *p
= (unsigned short *) origin
;
2388 int count
= screenbuf_size
/2;
2389 int mask
= hi_font_mask
| 0xff;
2391 for (; count
> 0; count
--, p
++) {
2392 scr_writew((scr_readw(p
)&mask
) | (video_erase_char
&~mask
), p
);
2397 * If we support more console drivers, this function is used
2398 * when a driver wants to take over some existing consoles
2399 * and become default driver for newly opened ones.
2402 void take_over_console(struct consw
*csw
, int first
, int last
, int deflt
)
2407 desc
= csw
->con_startup();
2412 for (i
= first
; i
<= last
; i
++) {
2416 con_driver_map
[i
] = csw
;
2418 if (!vc_cons
[i
].d
|| !vc_cons
[i
].d
->vc_sw
)
2424 old_was_color
= vc_cons
[i
].d
->vc_can_do_color
;
2425 vc_cons
[i
].d
->vc_sw
->con_deinit(vc_cons
[i
].d
);
2429 /* If the console changed between mono <-> color, then
2430 * the attributes in the screenbuf will be wrong. The
2431 * following resets all attributes to something sane.
2433 if (old_was_color
!= vc_cons
[i
].d
->vc_can_do_color
)
2434 clear_buffer_attributes(i
);
2439 printk("Console: switching ");
2441 printk("consoles %d-%d ", first
+1, last
+1);
2443 printk("to %s %s %dx%d\n",
2444 vc_cons
[j
].d
->vc_can_do_color
? "colour" : "mono",
2445 desc
, vc_cons
[j
].d
->vc_cols
, vc_cons
[j
].d
->vc_rows
);
2447 printk("to %s\n", desc
);
2450 void give_up_console(struct consw
*csw
)
2454 for(i
= 0; i
< MAX_NR_CONSOLES
; i
++)
2455 if (con_driver_map
[i
] == csw
)
2456 con_driver_map
[i
] = NULL
;
2465 static void set_vesa_blanking(unsigned long arg
)
2467 char *argp
= (char *)arg
+ 1;
2469 get_user(mode
, argp
);
2470 vesa_blank_mode
= (mode
< 4) ? mode
: 0;
2473 static void vesa_powerdown(void)
2475 struct vc_data
*c
= vc_cons
[fg_console
].d
;
2477 * Power down if currently suspended (1 or 2),
2478 * suspend if currently blanked (0),
2479 * else do nothing (i.e. already powered down (3)).
2480 * Called only if powerdown features are allowed.
2482 switch (vesa_blank_mode
) {
2483 case VESA_NO_BLANKING
:
2484 c
->vc_sw
->con_blank(c
, VESA_VSYNC_SUSPEND
+1);
2486 case VESA_VSYNC_SUSPEND
:
2487 case VESA_HSYNC_SUSPEND
:
2488 c
->vc_sw
->con_blank(c
, VESA_POWERDOWN
+1);
2493 static void vesa_powerdown_screen(void)
2495 timer_active
&= ~(1<<BLANK_TIMER
);
2496 timer_table
[BLANK_TIMER
].fn
= unblank_screen
;
2501 void do_blank_screen(int entering_gfx
)
2503 int currcons
= fg_console
;
2506 if (console_blanked
)
2509 /* entering graphics mode? */
2511 hide_cursor(currcons
);
2512 save_screen(currcons
);
2513 sw
->con_blank(vc_cons
[currcons
].d
, -1);
2514 console_blanked
= fg_console
+ 1;
2515 set_origin(currcons
);
2519 /* don't blank graphics */
2520 if (vcmode
!= KD_TEXT
) {
2521 console_blanked
= fg_console
+ 1;
2525 hide_cursor(currcons
);
2526 if (vesa_off_interval
) {
2527 timer_table
[BLANK_TIMER
].fn
= vesa_powerdown_screen
;
2528 timer_table
[BLANK_TIMER
].expires
= jiffies
+ vesa_off_interval
;
2529 timer_active
|= (1<<BLANK_TIMER
);
2531 timer_active
&= ~(1<<BLANK_TIMER
);
2532 timer_table
[BLANK_TIMER
].fn
= unblank_screen
;
2535 save_screen(currcons
);
2536 /* In case we need to reset origin, blanking hook returns 1 */
2537 i
= sw
->con_blank(vc_cons
[currcons
].d
, 1);
2538 console_blanked
= fg_console
+ 1;
2540 set_origin(currcons
);
2543 if (apm_display_blank())
2546 if (vesa_blank_mode
)
2547 sw
->con_blank(vc_cons
[currcons
].d
, vesa_blank_mode
+ 1);
2550 void unblank_screen(void)
2554 if (!console_blanked
)
2556 if (!vc_cons_allocated(fg_console
)) {
2558 printk("unblank_screen: tty %d not allocated ??\n", fg_console
+1);
2561 timer_table
[BLANK_TIMER
].fn
= blank_screen
;
2562 if (blankinterval
) {
2563 timer_table
[BLANK_TIMER
].expires
= jiffies
+ blankinterval
;
2564 timer_active
|= 1<<BLANK_TIMER
;
2567 currcons
= fg_console
;
2568 console_blanked
= 0;
2570 apm_display_unblank();
2572 if (sw
->con_blank(vc_cons
[currcons
].d
, 0))
2573 /* Low-level driver cannot restore -> do it ourselves */
2574 update_screen(fg_console
);
2575 set_cursor(fg_console
);
2578 static void blank_screen(void)
2583 void poke_blanked_console(void)
2585 timer_active
&= ~(1<<BLANK_TIMER
);
2586 if (vt_cons
[fg_console
]->vc_mode
== KD_GRAPHICS
)
2588 if (console_blanked
) {
2589 timer_table
[BLANK_TIMER
].fn
= unblank_screen
;
2590 timer_table
[BLANK_TIMER
].expires
= jiffies
; /* Now */
2591 timer_active
|= 1<<BLANK_TIMER
;
2592 } else if (blankinterval
) {
2593 timer_table
[BLANK_TIMER
].expires
= jiffies
+ blankinterval
;
2594 timer_active
|= 1<<BLANK_TIMER
;
2602 void set_palette(int currcons
)
2604 if (vcmode
!= KD_GRAPHICS
)
2605 sw
->con_set_palette(vc_cons
[currcons
].d
, color_table
);
2608 static int set_get_cmap(unsigned char *arg
, int set
)
2612 for (i
= 0; i
< 16; i
++)
2614 get_user(default_red
[i
], arg
++);
2615 get_user(default_grn
[i
], arg
++);
2616 get_user(default_blu
[i
], arg
++);
2618 put_user(default_red
[i
], arg
++);
2619 put_user(default_grn
[i
], arg
++);
2620 put_user(default_blu
[i
], arg
++);
2623 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
2624 if (vc_cons_allocated(i
)) {
2625 for (j
= k
= 0; j
< 16; j
++) {
2626 vc_cons
[i
].d
->vc_palette
[k
++] = default_red
[j
];
2627 vc_cons
[i
].d
->vc_palette
[k
++] = default_grn
[j
];
2628 vc_cons
[i
].d
->vc_palette
[k
++] = default_blu
[j
];
2637 * Load palette into the DAC registers. arg points to a colour
2638 * map, 3 bytes per colour, 16 colours, range from 0 to 255.
2641 int con_set_cmap(unsigned char *arg
)
2643 return set_get_cmap (arg
,1);
2646 int con_get_cmap(unsigned char *arg
)
2648 return set_get_cmap (arg
,0);
2651 void reset_palette(int currcons
)
2654 for (j
=k
=0; j
<16; j
++) {
2655 palette
[k
++] = default_red
[j
];
2656 palette
[k
++] = default_grn
[j
];
2657 palette
[k
++] = default_blu
[j
];
2659 set_palette(currcons
);
2665 * Currently we only support fonts up to 32 pixels wide, at a maximum height
2666 * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints,
2667 * depending on width) reserved for each character which is kinda wasty, but
2668 * this is done in order to maintain compatibility with the EGA/VGA fonts. It
2669 * is upto the actual low-level console-driver convert data into its favorite
2670 * format (maybe we should add a `fontoffset' field to the `display'
2671 * structure so we wont have to convert the fontdata all the time.
2675 #define max_font_size 65536
2677 int con_font_op(int currcons
, struct console_font_op
*op
)
2680 int size
= max_font_size
, set
;
2682 struct console_font_op old_op
;
2684 if (vt_cons
[currcons
]->vc_mode
!= KD_TEXT
)
2686 memcpy(&old_op
, op
, sizeof(old_op
));
2687 if (op
->op
== KD_FONT_OP_SET
) {
2690 if (op
->charcount
> 512)
2692 if (!op
->height
) { /* Need to guess font height [compat] */
2694 u8
*charmap
= op
->data
, tmp
;
2696 /* If from KDFONTOP ioctl, don't allow things which can be done in userland,
2697 so that we can get rid of this soon */
2698 if (!(op
->flags
& KD_FONT_FLAG_OLD
))
2701 for (h
= 32; h
> 0; h
--)
2702 for (i
= 0; i
< op
->charcount
; i
++) {
2703 if (get_user(tmp
, &charmap
[32*i
+h
-1]))
2714 if (op
->width
> 32 || op
->height
> 32)
2716 size
= (op
->width
+7)/8 * 32 * op
->charcount
;
2717 if (size
> max_font_size
)
2720 } else if (op
->op
== KD_FONT_OP_GET
)
2723 return sw
->con_font_op(vc_cons
[currcons
].d
, op
);
2725 temp
= kmalloc(size
, GFP_KERNEL
);
2728 if (set
&& copy_from_user(temp
, op
->data
, size
)) {
2734 disable_bh(CONSOLE_BH
);
2735 rc
= sw
->con_font_op(vc_cons
[currcons
].d
, op
);
2736 enable_bh(CONSOLE_BH
);
2737 op
->data
= old_op
.data
;
2739 int c
= (op
->width
+7)/8 * 32 * op
->charcount
;
2741 if (op
->data
&& op
->charcount
> old_op
.charcount
)
2743 if (!(op
->flags
& KD_FONT_FLAG_OLD
)) {
2744 if (op
->width
> old_op
.width
||
2745 op
->height
> old_op
.height
)
2750 else if ((old_op
.height
&& op
->height
> old_op
.height
) ||
2754 if (!rc
&& op
->data
&& copy_to_user(op
->data
, temp
, c
))
2758 kfree_s(temp
, size
);
2763 * Interface exported to selection and vcs.
2766 /* used by selection */
2767 u16
screen_glyph(int currcons
, int offset
)
2769 u16 w
= scr_readw(screenpos(currcons
, offset
, 1));
2772 if (w
& hi_font_mask
)
2777 /* used by vcs - note the word offset */
2778 unsigned short *screen_pos(int currcons
, int w_offset
, int viewed
)
2780 return screenpos(currcons
, 2 * w_offset
, viewed
);
2783 void getconsxy(int currcons
, char *p
)
2789 void putconsxy(int currcons
, char *p
)
2791 gotoxy(currcons
, p
[0], p
[1]);
2792 set_cursor(currcons
);
2795 u16
vcs_scr_readw(int currcons
, const u16
*org
)
2797 if ((unsigned long)org
== pos
&& softcursor_original
!= -1)
2798 return softcursor_original
;
2799 return scr_readw(org
);
2802 void vcs_scr_writew(int currcons
, u16 val
, u16
*org
)
2804 scr_writew(val
, org
);
2805 if ((unsigned long)org
== pos
) {
2806 softcursor_original
= -1;
2807 add_softcursor(currcons
);
2813 * Visible symbols for modules
2816 EXPORT_SYMBOL(color_table
);
2817 EXPORT_SYMBOL(default_red
);
2818 EXPORT_SYMBOL(default_grn
);
2819 EXPORT_SYMBOL(default_blu
);
2820 EXPORT_SYMBOL(video_font_height
);
2821 EXPORT_SYMBOL(video_scan_lines
);
2822 EXPORT_SYMBOL(vc_resize
);
2824 #ifndef VT_SINGLE_DRIVER
2825 EXPORT_SYMBOL(take_over_console
);
2826 EXPORT_SYMBOL(give_up_console
);