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.Uytterhoeven@cs.kuleuven.ac.be>, 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/vt_kern.h>
89 #include <linux/consolemap.h>
90 #include <linux/timer.h>
91 #include <linux/interrupt.h>
92 #include <linux/config.h>
93 #include <linux/version.h>
94 #include <linux/tqueue.h>
96 #include <linux/apm_bios.h>
100 #include <asm/system.h>
101 #include <asm/uaccess.h>
102 #include <asm/bitops.h>
104 #include <asm/linux_logo.h>
106 #include "console_macros.h"
109 struct consw
*conswitchp
= NULL
;
111 /* A bitmap for codes <32. A bit of 1 indicates that the code
112 * corresponding to that bit number invokes some special action
113 * (such as cursor movement) and should not be displayed as a
114 * glyph unless the disp_ctrl mode is explicitly enabled.
116 #define CTRL_ACTION 0x0d00ff81
117 #define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */
120 * Here is the default bell parameters: 750HZ, 1/8th of a second
122 #define DEFAULT_BELL_PITCH 750
123 #define DEFAULT_BELL_DURATION (HZ/8)
126 #define MIN(a,b) ((a) < (b) ? (a) : (b))
129 static struct tty_struct
*console_table
[MAX_NR_CONSOLES
];
130 static struct termios
*console_termios
[MAX_NR_CONSOLES
];
131 static struct termios
*console_termios_locked
[MAX_NR_CONSOLES
];
132 struct vc vc_cons
[MAX_NR_CONSOLES
];
134 #ifndef VT_SINGLE_DRIVER
135 static struct consw
*con_driver_map
[MAX_NR_CONSOLES
];
138 static int con_open(struct tty_struct
*, struct file
*);
139 static void vc_init(unsigned int console
, unsigned int rows
,
140 unsigned int cols
, int do_clear
);
141 static void blank_screen(void);
142 static void gotoxy(int currcons
, int new_x
, int new_y
);
143 static void save_cur(int currcons
);
144 static void reset_terminal(int currcons
, int do_clear
);
145 static void con_flush_chars(struct tty_struct
*tty
);
146 static void set_vesa_blanking(unsigned long arg
);
147 static void set_cursor(int currcons
);
148 static void hide_cursor(int currcons
);
150 static int printable
= 0; /* Is console ready for printing? */
152 int do_poke_blanked_console
= 0;
153 int console_blanked
= 0;
155 static int vesa_blank_mode
= 0; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
156 static int blankinterval
= 10*60*HZ
;
157 static int vesa_off_interval
= 0;
160 * fg_console is the current virtual console,
161 * last_console is the last used one,
162 * want_console is the console we want to switch to,
163 * kmsg_redirect is the console for kernel messages,
166 int last_console
= 0;
167 int want_console
= -1;
168 int kmsg_redirect
= 0;
171 * For each existing display, we have a pointer to console currently visible
172 * on that display, allowing consoles other than fg_console to be refreshed
173 * appropriately. Unless the low-level driver supplies its own display_fg
174 * variable, we use this one for the "master display".
176 static struct vc_data
*master_display_fg
= NULL
;
179 * Unfortunately, we need to delay tty echo when we're currently writing to the
180 * console since the code is (and always was) not re-entrant, so we insert
181 * all filp requests to con_task_queue instead of tq_timer and run it from
184 DECLARE_TASK_QUEUE(con_task_queue
);
187 * For the same reason, we defer scrollback to the console_bh.
189 static int scrollback_delta
= 0;
192 * Low-Level Functions
195 #define IS_FG (currcons == fg_console)
196 #define IS_VISIBLE CON_IS_VISIBLE(vc_cons[currcons].d)
198 #ifdef VT_BUF_VRAM_ONLY
201 #define DO_UPDATE IS_VISIBLE
204 static inline unsigned short *screenpos(int currcons
, int offset
, int viewed
)
206 unsigned short *p
= (unsigned short *)(visible_origin
+ offset
);
210 static inline void scrolldelta(int lines
)
212 scrollback_delta
+= lines
;
216 static void scrup(int currcons
, unsigned int t
, unsigned int b
, int nr
)
218 unsigned short *d
, *s
;
222 if (b
> video_num_lines
|| t
>= b
|| nr
< 1)
224 if (IS_VISIBLE
&& sw
->con_scroll(vc_cons
[currcons
].d
, t
, b
, SM_UP
, nr
))
226 d
= (unsigned short *) (origin
+video_size_row
*t
);
227 s
= (unsigned short *) (origin
+video_size_row
*(t
+nr
));
228 scr_memcpyw(d
, s
, (b
-t
-nr
) * video_size_row
);
229 scr_memsetw(d
+ (b
-t
-nr
) * video_num_columns
, video_erase_char
, video_size_row
*nr
);
233 scrdown(int currcons
, unsigned int t
, unsigned int b
, int nr
)
240 if (b
> video_num_lines
|| t
>= b
|| nr
< 1)
242 if (IS_VISIBLE
&& sw
->con_scroll(vc_cons
[currcons
].d
, t
, b
, SM_DOWN
, nr
))
244 s
= (unsigned short *) (origin
+video_size_row
*t
);
245 step
= video_num_columns
* nr
;
246 scr_memmovew(s
+ step
, s
, (b
-t
-nr
)*video_size_row
);
247 scr_memsetw(s
, video_erase_char
, 2*step
);
250 static void do_update_region(int currcons
, unsigned long start
, int count
)
252 #ifndef VT_BUF_VRAM_ONLY
253 unsigned int xx
, yy
, offset
;
256 if (start
< origin
) {
257 count
-= origin
- start
;
262 offset
= (start
- origin
) / 2;
263 xx
= offset
% video_num_columns
;
264 yy
= offset
/ video_num_columns
;
267 u16 attrib
= scr_readw(p
) & 0xff00;
270 while (xx
< video_num_columns
&& count
) {
271 if (attrib
!= (scr_readw(p
) & 0xff00)) {
273 sw
->con_putcs(vc_cons
[currcons
].d
, q
, p
-q
, yy
, startx
);
276 attrib
= scr_readw(p
) & 0xff00;
283 sw
->con_putcs(vc_cons
[currcons
].d
, q
, p
-q
, yy
, startx
);
292 void update_region(int currcons
, unsigned long start
, int count
)
295 hide_cursor(currcons
);
296 do_update_region(currcons
, start
, count
);
297 set_cursor(currcons
);
301 /* Structure of attributes is hardware-dependent */
303 static u8
build_attr(int currcons
, u8 _color
, u8 _intensity
, u8 _blink
, u8 _underline
, u8 _reverse
)
305 if (sw
->con_build_attr
)
306 return sw
->con_build_attr(vc_cons
[currcons
].d
, _color
, _intensity
, _blink
, _underline
, _reverse
);
308 #ifndef VT_BUF_VRAM_ONLY
310 * ++roman: I completely changed the attribute format for monochrome
311 * mode (!can_do_color). The formerly used MDA (monochrome display
312 * adapter) format didn't allow the combination of certain effects.
313 * Now the attribute is just a bit vector:
314 * Bit 0..1: intensity (0..2)
323 (_underline
? 4 : 0) |
327 a
= (a
& 0xf0) | ulcolor
;
328 else if (_intensity
== 0)
329 a
= (a
& 0xf0) | halfcolor
;
331 a
= ((a
) & 0x88) | ((((a
) >> 4) | ((a
) << 4)) & 0x77);
336 if (hi_font_mask
== 0x100)
345 static void update_attr(int currcons
)
347 attr
= build_attr(currcons
, color
, intensity
, blink
, underline
, reverse
^ decscnm
);
348 video_erase_char
= (build_attr(currcons
, color
, 1, 0, 0, decscnm
) << 8) | ' ';
351 /* Note: inverting the screen twice should revert to the original state */
353 void invert_screen(int currcons
, int offset
, int count
, int viewed
)
358 p
= screenpos(currcons
, offset
, viewed
);
359 if (sw
->con_invert_region
)
360 sw
->con_invert_region(vc_cons
[currcons
].d
, p
, count
);
361 #ifndef VT_BUF_VRAM_ONLY
367 while (cnt
--) *q
++ ^= 0x0800;
368 } else if (hi_font_mask
== 0x100) {
371 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) | (((a
) & 0x0e00) << 4);
377 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) | (((a
) & 0x0700) << 4);
384 do_update_region(currcons
, (unsigned long) p
, count
);
387 /* used by selection: complement pointer position */
388 void complement_pos(int currcons
, int offset
)
390 static unsigned short *p
= NULL
;
391 static unsigned short old
= 0;
392 static unsigned short oldx
= 0, oldy
= 0;
397 sw
->con_putc(vc_cons
[currcons
].d
, old
, oldy
, oldx
);
403 p
= screenpos(currcons
, offset
, 1);
405 new = old
^ complement_mask
;
408 oldx
= (offset
>> 1) % video_num_columns
;
409 oldy
= (offset
>> 1) / video_num_columns
;
410 sw
->con_putc(vc_cons
[currcons
].d
, new, oldy
, oldx
);
415 static void insert_char(int currcons
, unsigned int nr
)
417 unsigned short *p
, *q
= (unsigned short *) pos
;
419 p
= q
+ video_num_columns
- nr
- x
;
421 scr_writew(scr_readw(p
), p
+ nr
);
422 scr_memsetw(q
, video_erase_char
, nr
*2);
425 unsigned short oldattr
= attr
;
426 sw
->con_bmove(vc_cons
[currcons
].d
,y
,x
,y
,x
+nr
,1,
427 video_num_columns
-x
-nr
);
428 attr
= video_erase_char
>> 8;
430 sw
->con_putc(vc_cons
[currcons
].d
,
431 video_erase_char
,y
,x
+nr
);
436 static void delete_char(int currcons
, unsigned int nr
)
439 unsigned short *p
= (unsigned short *) pos
;
441 while (++i
<= video_num_columns
- nr
) {
442 scr_writew(scr_readw(p
+nr
), p
);
445 scr_memsetw(p
, video_erase_char
, nr
*2);
448 unsigned short oldattr
= attr
;
449 sw
->con_bmove(vc_cons
[currcons
].d
, y
, x
+nr
, y
, x
, 1,
450 video_num_columns
-x
-nr
);
451 attr
= video_erase_char
>> 8;
453 sw
->con_putc(vc_cons
[currcons
].d
,
455 video_num_columns
-1-nr
);
460 static int softcursor_original
;
462 static void add_softcursor(int currcons
)
464 int i
= scr_readw((u16
*) pos
);
465 u32 type
= cursor_type
;
467 if (! (type
& 0x10)) return;
468 if (softcursor_original
!= -1) return;
469 softcursor_original
= i
;
470 i
|= ((type
>> 8) & 0xff00 );
471 i
^= ((type
) & 0xff00 );
472 if ((type
& 0x20) && ((softcursor_original
& 0x7000) == (i
& 0x7000))) i
^= 0x7000;
473 if ((type
& 0x40) && ((i
& 0x700) == ((i
& 0x7000) >> 4))) i
^= 0x0700;
474 scr_writew(i
, (u16
*) pos
);
476 sw
->con_putc(vc_cons
[currcons
].d
, i
, y
, x
);
479 static void hide_cursor(int currcons
)
481 if (currcons
== sel_cons
)
483 if (softcursor_original
!= -1) {
484 scr_writew(softcursor_original
,(u16
*) pos
);
486 sw
->con_putc(vc_cons
[currcons
].d
, softcursor_original
, y
, x
);
487 softcursor_original
= -1;
489 sw
->con_cursor(vc_cons
[currcons
].d
,CM_ERASE
);
492 static void set_cursor(int currcons
)
494 if (!IS_FG
|| console_blanked
|| vcmode
== KD_GRAPHICS
)
497 if (currcons
== sel_cons
)
499 add_softcursor(currcons
);
500 if ((cursor_type
& 0x0f) != 1)
501 sw
->con_cursor(vc_cons
[currcons
].d
,CM_DRAW
);
503 hide_cursor(currcons
);
506 static void set_origin(int currcons
)
509 !sw
->con_set_origin
||
510 !sw
->con_set_origin(vc_cons
[currcons
].d
))
511 origin
= (unsigned long) screenbuf
;
512 visible_origin
= origin
;
513 scr_end
= origin
+ screenbuf_size
;
514 pos
= origin
+ video_size_row
*y
+ 2*x
;
517 static inline void save_screen(int currcons
)
519 if (sw
->con_save_screen
)
520 sw
->con_save_screen(vc_cons
[currcons
].d
);
524 * Redrawing of screen
527 void redraw_screen(int new_console
, int is_switch
)
530 int currcons
, old_console
;
535 if (!vc_cons_allocated(new_console
)) {
537 printk("redraw_screen: tty %d not allocated ??\n", new_console
+1);
543 currcons
= fg_console
;
544 hide_cursor(currcons
);
545 if (fg_console
!= new_console
) {
546 struct vc_data
**display
= vc_cons
[new_console
].d
->vc_display_fg
;
547 old_console
= (*display
) ? (*display
)->vc_num
: fg_console
;
548 *display
= vc_cons
[new_console
].d
;
549 fg_console
= new_console
;
550 currcons
= old_console
;
552 save_screen(currcons
);
553 set_origin(currcons
);
555 currcons
= new_console
;
556 if (old_console
== new_console
)
560 currcons
= new_console
;
561 hide_cursor(currcons
);
565 set_origin(currcons
);
566 set_palette(currcons
);
567 if (sw
->con_switch(vc_cons
[currcons
].d
) && vcmode
!= KD_GRAPHICS
)
568 /* Update the screen contents */
569 do_update_region(currcons
, origin
, screenbuf_size
/2);
571 set_cursor(currcons
);
574 compute_shiftstate();
580 * Allocation, freeing and resizing of VTs.
583 int vc_cons_allocated(unsigned int i
)
585 return (i
< MAX_NR_CONSOLES
&& vc_cons
[i
].d
);
588 static void visual_init(int currcons
, int init
)
590 /* ++Geert: sw->con_init determines console size */
592 #ifndef VT_SINGLE_DRIVER
593 if (con_driver_map
[currcons
])
594 sw
= con_driver_map
[currcons
];
597 display_fg
= &master_display_fg
;
598 vc_cons
[currcons
].d
->vc_uni_pagedir_loc
= &vc_cons
[currcons
].d
->vc_uni_pagedir
;
599 vc_cons
[currcons
].d
->vc_uni_pagedir
= 0;
603 sw
->con_init(vc_cons
[currcons
].d
, init
);
604 if (!complement_mask
)
605 complement_mask
= can_do_color
? 0x7700 : 0x0800;
606 s_complement_mask
= complement_mask
;
607 video_size_row
= video_num_columns
<<1;
608 screenbuf_size
= video_num_lines
*video_size_row
;
611 int vc_allocate(unsigned int currcons
) /* return 0 on success */
613 if (currcons
>= MAX_NR_CONSOLES
)
615 if (!vc_cons
[currcons
].d
) {
618 /* prevent users from taking too much memory */
619 if (currcons
>= MAX_NR_USER_CONSOLES
&& !capable(CAP_SYS_RESOURCE
))
622 /* due to the granularity of kmalloc, we waste some memory here */
623 /* the alloc is done in two steps, to optimize the common situation
624 of a 25x80 console (structsize=216, screenbuf_size=4000) */
625 /* although the numbers above are not valid since long ago, the
626 point is still up-to-date and the comment still has its value
627 even if only as a historical artifact. --mj, July 1998 */
628 p
= (long) kmalloc(structsize
, GFP_KERNEL
);
631 vc_cons
[currcons
].d
= (struct vc_data
*)p
;
632 vt_cons
[currcons
] = (struct vt_struct
*)(p
+sizeof(struct vc_data
));
633 visual_init(currcons
, 1);
634 if (!*vc_cons
[currcons
].d
->vc_uni_pagedir_loc
)
635 con_set_default_unimap(currcons
);
636 q
= (long)kmalloc(screenbuf_size
, GFP_KERNEL
);
638 kfree_s((char *) p
, structsize
);
639 vc_cons
[currcons
].d
= NULL
;
640 vt_cons
[currcons
] = NULL
;
643 screenbuf
= (unsigned short *) q
;
645 vc_init(currcons
, video_num_lines
, video_num_columns
, 1);
651 * Change # of rows and columns (0 means unchanged/the size of fg_console)
652 * [this is to be used together with some user program
653 * like resize that changes the hardware videomode]
655 int vc_resize(unsigned int lines
, unsigned int cols
,
656 unsigned int first
, unsigned int last
)
658 unsigned int cc
, ll
, ss
, sr
, todo
= 0;
659 unsigned int currcons
= fg_console
, i
;
660 unsigned short *newscreens
[MAX_NR_CONSOLES
];
662 cc
= (cols
? cols
: video_num_columns
);
663 ll
= (lines
? lines
: video_num_lines
);
667 for (currcons
= first
; currcons
<= last
; currcons
++) {
668 if (!vc_cons_allocated(currcons
) ||
669 (cc
== video_num_columns
&& ll
== video_num_lines
))
670 newscreens
[currcons
] = NULL
;
672 unsigned short *p
= (unsigned short *) kmalloc(ss
, GFP_USER
);
674 for (i
= 0; i
< currcons
; i
++)
676 kfree_s(newscreens
[i
], ss
);
679 newscreens
[currcons
] = p
;
686 for (currcons
= first
; currcons
<= last
; currcons
++) {
687 unsigned int occ
, oll
, oss
, osr
;
688 unsigned long ol
, nl
, nlend
, rlth
, rrem
;
689 if (!newscreens
[currcons
] || !vc_cons_allocated(currcons
))
692 oll
= video_num_lines
;
693 occ
= video_num_columns
;
694 osr
= video_size_row
;
695 oss
= screenbuf_size
;
697 video_num_lines
= ll
;
698 video_num_columns
= cc
;
705 nl
= (long) newscreens
[currcons
];
708 ol
+= (oll
- ll
) * osr
;
710 update_attr(currcons
);
712 while (ol
< scr_end
) {
713 scr_memcpyw((unsigned short *) nl
, (unsigned short *) ol
, rlth
);
715 scr_memsetw((void *)(nl
+ rlth
), video_erase_char
, rrem
);
720 scr_memsetw((void *) nl
, video_erase_char
, nlend
- nl
);
722 kfree_s(screenbuf
, oss
);
723 screenbuf
= newscreens
[currcons
];
726 set_origin(currcons
);
728 /* do part of a reset_terminal() */
730 bottom
= video_num_lines
;
731 gotoxy(currcons
, x
, y
);
734 if (console_table
[currcons
]) {
735 struct winsize ws
, *cws
= &console_table
[currcons
]->winsize
;
736 memset(&ws
, 0, sizeof(ws
));
737 ws
.ws_row
= video_num_lines
;
738 ws
.ws_col
= video_num_columns
;
739 if ((ws
.ws_row
!= cws
->ws_row
|| ws
.ws_col
!= cws
->ws_col
) &&
740 console_table
[currcons
]->pgrp
> 0)
741 kill_pg(console_table
[currcons
]->pgrp
, SIGWINCH
, 1);
746 update_screen(currcons
);
753 void vc_disallocate(unsigned int currcons
)
755 if (vc_cons_allocated(currcons
)) {
756 sw
->con_deinit(vc_cons
[currcons
].d
);
758 kfree_s(screenbuf
, screenbuf_size
);
759 if (currcons
>= MIN_NR_CONSOLES
)
760 kfree_s(vc_cons
[currcons
].d
, structsize
);
761 vc_cons
[currcons
].d
= NULL
;
769 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x)
770 #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x)
771 #define is_kbd(x) vc_kbd_mode(kbd_table+currcons,x)
773 #define decarm VC_REPEAT
774 #define decckm VC_CKMODE
775 #define kbdapplic VC_APPLIC
779 * this is what the terminal answers to a ESC-Z or csi0c query.
781 #define VT100ID "\033[?1;2c"
782 #define VT102ID "\033[?6c"
784 unsigned char color_table
[] = { 0, 4, 2, 6, 1, 5, 3, 7,
785 8,12,10,14, 9,13,11,15 };
787 /* the default colour table, for VGA+ colour systems */
788 int default_red
[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
789 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
790 int default_grn
[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
791 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
792 int default_blu
[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
793 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
796 * gotoxy() must verify all boundaries, because the arguments
797 * might also be negative. If the given position is out of
798 * bounds, the cursor is placed at the nearest margin.
800 static void gotoxy(int currcons
, int new_x
, int new_y
)
807 if (new_x
>= video_num_columns
)
808 x
= video_num_columns
- 1;
816 max_y
= video_num_lines
;
820 else if (new_y
>= max_y
)
824 pos
= origin
+ y
*video_size_row
+ (x
<<1);
828 /* for absolute user moves, when decom is set */
829 static void gotoxay(int currcons
, int new_x
, int new_y
)
831 gotoxy(currcons
, new_x
, decom
? (top
+new_y
) : new_y
);
834 void scrollback(int lines
)
836 int currcons
= fg_console
;
839 lines
= video_num_lines
/2;
843 void scrollfront(int lines
)
845 int currcons
= fg_console
;
848 lines
= video_num_lines
/2;
852 static void lf(int currcons
)
854 /* don't scroll if above bottom of scrolling region, or
855 * if below scrolling region
858 scrup(currcons
,top
,bottom
,1);
859 else if (y
< video_num_lines
-1) {
861 pos
+= video_size_row
;
866 static void ri(int currcons
)
868 /* don't scroll if below top of scrolling region, or
869 * if above scrolling region
872 scrdown(currcons
,top
,bottom
,1);
875 pos
-= video_size_row
;
880 static inline void cr(int currcons
)
886 static inline void bs(int currcons
)
895 static inline void del(int currcons
)
900 static void csi_J(int currcons
, int vpar
)
903 unsigned short * start
;
906 case 0: /* erase from cursor to end of display */
907 count
= (scr_end
-pos
)>>1;
908 start
= (unsigned short *) pos
;
910 /* do in two stages */
911 sw
->con_clear(vc_cons
[currcons
].d
, y
, x
, 1,
912 video_num_columns
-x
);
913 sw
->con_clear(vc_cons
[currcons
].d
, y
+1, 0,
918 case 1: /* erase from start to cursor */
919 count
= ((pos
-origin
)>>1)+1;
920 start
= (unsigned short *) origin
;
922 /* do in two stages */
923 sw
->con_clear(vc_cons
[currcons
].d
, 0, 0, y
,
925 sw
->con_clear(vc_cons
[currcons
].d
, y
, 0, 1,
929 case 2: /* erase whole display */
930 count
= video_num_columns
* video_num_lines
;
931 start
= (unsigned short *) origin
;
933 sw
->con_clear(vc_cons
[currcons
].d
, 0, 0,
940 scr_memsetw(start
, video_erase_char
, 2*count
);
944 static void csi_K(int currcons
, int vpar
)
947 unsigned short * start
;
950 case 0: /* erase from cursor to end of line */
951 count
= video_num_columns
-x
;
952 start
= (unsigned short *) pos
;
954 sw
->con_clear(vc_cons
[currcons
].d
, y
, x
, 1,
955 video_num_columns
-x
);
957 case 1: /* erase from start of line to cursor */
958 start
= (unsigned short *) (pos
- (x
<<1));
961 sw
->con_clear(vc_cons
[currcons
].d
, y
, 0, 1,
964 case 2: /* erase whole line */
965 start
= (unsigned short *) (pos
- (x
<<1));
966 count
= video_num_columns
;
968 sw
->con_clear(vc_cons
[currcons
].d
, y
, 0, 1,
974 scr_memsetw(start
, video_erase_char
, 2 * count
);
978 static void csi_X(int currcons
, int vpar
) /* erase the following vpar positions */
984 count
= (vpar
> video_num_columns
-x
) ? (video_num_columns
-x
) : vpar
;
986 scr_memsetw((unsigned short *) pos
, video_erase_char
, 2 * count
);
988 sw
->con_clear(vc_cons
[currcons
].d
, y
, x
, 1, count
);
992 static void default_attr(int currcons
)
1001 static void csi_m(int currcons
)
1005 for (i
=0;i
<=npar
;i
++)
1007 case 0: /* all attributes off */
1008 default_attr(currcons
);
1025 case 10: /* ANSI X3.64-1979 (SCO-ish?)
1026 * Select primary font, don't display
1027 * control chars if defined, don't set
1030 translate
= set_translate(charset
== 0
1032 : G1_charset
,currcons
);
1036 case 11: /* ANSI X3.64-1979 (SCO-ish?)
1037 * Select first alternate font, lets
1038 * chars < 32 be displayed as ROM chars.
1040 translate
= set_translate(IBMPC_MAP
,currcons
);
1044 case 12: /* ANSI X3.64-1979 (SCO-ish?)
1045 * Select second alternate font, toggle
1046 * high bit before displaying as ROM char.
1048 translate
= set_translate(IBMPC_MAP
,currcons
);
1065 case 38: /* ANSI X3.64-1979 (SCO-ish?)
1066 * Enables underscore, white foreground
1067 * with white underscore (Linux - use
1068 * default foreground).
1070 color
= (def_color
& 0x0f) | background
;
1073 case 39: /* ANSI X3.64-1979 (SCO-ish?)
1074 * Disable underline option.
1075 * Reset colour to default? It did this
1078 color
= (def_color
& 0x0f) | background
;
1082 color
= (def_color
& 0xf0) | foreground
;
1085 if (par
[i
] >= 30 && par
[i
] <= 37)
1086 color
= color_table
[par
[i
]-30]
1088 else if (par
[i
] >= 40 && par
[i
] <= 47)
1089 color
= (color_table
[par
[i
]-40]<<4)
1093 update_attr(currcons
);
1096 static void respond_string(const char * p
, struct tty_struct
* tty
)
1099 tty_insert_flip_char(tty
, *p
, 0);
1102 con_schedule_flip(tty
);
1105 static void cursor_report(int currcons
, struct tty_struct
* tty
)
1109 sprintf(buf
, "\033[%d;%dR", y
+ (decom
? top
+1 : 1), x
+1);
1110 respond_string(buf
, tty
);
1113 static inline void status_report(struct tty_struct
* tty
)
1115 respond_string("\033[0n", tty
); /* Terminal ok */
1118 static inline void respond_ID(struct tty_struct
* tty
)
1120 respond_string(VT102ID
, tty
);
1123 void mouse_report(struct tty_struct
* tty
, int butt
, int mrx
, int mry
)
1127 sprintf(buf
, "\033[M%c%c%c", (char)(' ' + butt
), (char)('!' + mrx
),
1129 respond_string(buf
, tty
);
1132 /* invoked via ioctl(TIOCLINUX) and through set_selection */
1133 int mouse_reporting(void)
1135 int currcons
= fg_console
;
1137 return report_mouse
;
1140 static void set_mode(int currcons
, int on_off
)
1144 for (i
=0; i
<=npar
; i
++)
1145 if (ques
) switch(par
[i
]) { /* DEC private modes set/reset */
1146 case 1: /* Cursor keys send ^[Ox/^[[x */
1152 case 3: /* 80/132 mode switch unimplemented */
1155 (void) vc_resize(video_num_lines
, deccolm
? 132 : 80);
1156 /* this alone does not suffice; some user mode
1157 utility has to change the hardware regs */
1160 case 5: /* Inverted screen on/off */
1161 if (decscnm
!= on_off
) {
1163 invert_screen(currcons
, 0, screenbuf_size
, 0);
1164 update_attr(currcons
);
1167 case 6: /* Origin relative/absolute */
1169 gotoxay(currcons
,0,0);
1171 case 7: /* Autowrap on/off */
1174 case 8: /* Autorepeat on/off */
1181 report_mouse
= on_off
? 1 : 0;
1183 case 25: /* Cursor on/off */
1187 report_mouse
= on_off
? 2 : 0;
1189 } else switch(par
[i
]) { /* ANSI modes set/reset */
1190 case 3: /* Monitor (display ctrls) */
1193 case 4: /* Insert Mode on/off */
1196 case 20: /* Lf, Enter == CrLf/Lf */
1205 static void setterm_command(int currcons
)
1208 case 1: /* set color for underline mode */
1209 if (can_do_color
&& par
[1] < 16) {
1210 ulcolor
= color_table
[par
[1]];
1212 update_attr(currcons
);
1215 case 2: /* set color for half intensity mode */
1216 if (can_do_color
&& par
[1] < 16) {
1217 halfcolor
= color_table
[par
[1]];
1219 update_attr(currcons
);
1222 case 8: /* store colors as defaults */
1224 default_attr(currcons
);
1225 update_attr(currcons
);
1227 case 9: /* set blanking interval */
1228 blankinterval
= ((par
[1] < 60) ? par
[1] : 60) * 60 * HZ
;
1229 poke_blanked_console();
1231 case 10: /* set bell frequency in Hz */
1233 bell_pitch
= par
[1];
1235 bell_pitch
= DEFAULT_BELL_PITCH
;
1237 case 11: /* set bell duration in msec */
1239 bell_duration
= (par
[1] < 2000) ?
1242 bell_duration
= DEFAULT_BELL_DURATION
;
1244 case 12: /* bring specified console to the front */
1245 if (par
[1] >= 1 && vc_cons_allocated(par
[1]-1))
1246 set_console(par
[1] - 1);
1248 case 13: /* unblank the screen */
1249 poke_blanked_console();
1251 case 14: /* set vesa powerdown interval */
1252 vesa_off_interval
= ((par
[1] < 60) ? par
[1] : 60) * 60 * HZ
;
1257 static void insert_line(int currcons
, unsigned int nr
)
1259 scrdown(currcons
,y
,bottom
,nr
);
1264 static void delete_line(int currcons
, unsigned int nr
)
1266 scrup(currcons
,y
,bottom
,nr
);
1270 static void csi_at(int currcons
, unsigned int nr
)
1272 if (nr
> video_num_columns
- x
)
1273 nr
= video_num_columns
- x
;
1276 insert_char(currcons
, nr
);
1279 static void csi_L(int currcons
, unsigned int nr
)
1281 if (nr
> video_num_lines
- y
)
1282 nr
= video_num_lines
- y
;
1285 insert_line(currcons
, nr
);
1288 static void csi_P(int currcons
, unsigned int nr
)
1290 if (nr
> video_num_columns
- x
)
1291 nr
= video_num_columns
- x
;
1294 delete_char(currcons
, nr
);
1297 static void csi_M(int currcons
, unsigned int nr
)
1299 if (nr
> video_num_lines
- y
)
1300 nr
= video_num_lines
- y
;
1303 delete_line(currcons
, nr
);
1306 static void save_cur(int currcons
)
1310 s_intensity
= intensity
;
1311 s_underline
= underline
;
1313 s_reverse
= reverse
;
1314 s_charset
= charset
;
1316 saved_G0
= G0_charset
;
1317 saved_G1
= G1_charset
;
1320 static void restore_cur(int currcons
)
1322 gotoxy(currcons
,saved_x
,saved_y
);
1323 intensity
= s_intensity
;
1324 underline
= s_underline
;
1326 reverse
= s_reverse
;
1327 charset
= s_charset
;
1329 G0_charset
= saved_G0
;
1330 G1_charset
= saved_G1
;
1331 translate
= set_translate(charset
? G1_charset
: G0_charset
,currcons
);
1332 update_attr(currcons
);
1336 enum { ESnormal
, ESesc
, ESsquare
, ESgetpars
, ESgotpars
, ESfunckey
,
1337 EShash
, ESsetG0
, ESsetG1
, ESpercent
, ESignore
, ESnonstd
,
1340 static void reset_terminal(int currcons
, int do_clear
)
1343 bottom
= video_num_lines
;
1344 vc_state
= ESnormal
;
1346 translate
= set_translate(LAT1_MAP
,currcons
);
1347 G0_charset
= LAT1_MAP
;
1348 G1_charset
= GRAF_MAP
;
1368 kbd_table
[currcons
].lockstate
= 0;
1369 kbd_table
[currcons
].slockstate
= 0;
1370 kbd_table
[currcons
].ledmode
= LED_SHOW_FLAGS
;
1371 kbd_table
[currcons
].ledflagstate
= kbd_table
[currcons
].default_ledflagstate
;
1374 cursor_type
= CUR_DEFAULT
;
1375 complement_mask
= s_complement_mask
;
1377 default_attr(currcons
);
1378 update_attr(currcons
);
1380 tab_stop
[0] = 0x01010100;
1384 tab_stop
[4] = 0x01010101;
1386 bell_pitch
= DEFAULT_BELL_PITCH
;
1387 bell_duration
= DEFAULT_BELL_DURATION
;
1389 gotoxy(currcons
,0,0);
1395 static void do_con_trol(struct tty_struct
*tty
, unsigned int currcons
, int c
)
1398 * Control characters can be used in the _middle_
1399 * of an escape sequence.
1406 kd_mksound(bell_pitch
, bell_duration
);
1413 while (x
< video_num_columns
- 1) {
1415 if (tab_stop
[x
>> 5] & (1 << (x
& 31)))
1420 case 10: case 11: case 12:
1429 translate
= set_translate(G1_charset
,currcons
);
1434 translate
= set_translate(G0_charset
,currcons
);
1438 vc_state
= ESnormal
;
1447 vc_state
= ESsquare
;
1452 vc_state
= ESnormal
;
1455 vc_state
= ESsquare
;
1458 vc_state
= ESnonstd
;
1461 vc_state
= ESpercent
;
1474 tab_stop
[x
>> 5] |= (1 << (x
& 31));
1483 restore_cur(currcons
);
1495 reset_terminal(currcons
,1);
1497 case '>': /* Numeric keypad */
1500 case '=': /* Appl. keypad */
1506 if (c
=='P') { /* palette escape sequence */
1507 for (npar
=0; npar
<NPAR
; npar
++)
1510 vc_state
= ESpalette
;
1512 } else if (c
=='R') { /* reset palette */
1513 reset_palette(currcons
);
1514 vc_state
= ESnormal
;
1516 vc_state
= ESnormal
;
1519 if ( (c
>='0'&&c
<='9') || (c
>='A'&&c
<='F') || (c
>='a'&&c
<='f') ) {
1520 par
[npar
++] = (c
>'9' ? (c
&0xDF)-'A'+10 : c
-'0') ;
1522 int i
= par
[0]*3, j
= 1;
1523 palette
[i
] = 16*par
[j
++];
1524 palette
[i
++] += par
[j
++];
1525 palette
[i
] = 16*par
[j
++];
1526 palette
[i
++] += par
[j
++];
1527 palette
[i
] = 16*par
[j
++];
1528 palette
[i
] += par
[j
];
1529 set_palette(currcons
);
1530 vc_state
= ESnormal
;
1533 vc_state
= ESnormal
;
1536 for(npar
= 0 ; npar
< NPAR
; npar
++)
1539 vc_state
= ESgetpars
;
1540 if (c
== '[') { /* Function key */
1548 if (c
==';' && npar
<NPAR
-1) {
1551 } else if (c
>='0' && c
<='9') {
1555 } else vc_state
=ESgotpars
;
1557 vc_state
= ESnormal
;
1560 set_mode(currcons
,1);
1563 set_mode(currcons
,0);
1568 cursor_type
= par
[0] | (par
[1]<<8) | (par
[2]<<16);
1570 cursor_type
= CUR_DEFAULT
;
1578 complement_mask
= par
[0]<<8 | par
[1];
1580 complement_mask
= s_complement_mask
;
1588 else if (par
[0] == 6)
1589 cursor_report(currcons
,tty
);
1599 if (par
[0]) par
[0]--;
1600 gotoxy(currcons
,par
[0],y
);
1603 if (!par
[0]) par
[0]++;
1604 gotoxy(currcons
,x
,y
-par
[0]);
1607 if (!par
[0]) par
[0]++;
1608 gotoxy(currcons
,x
,y
+par
[0]);
1611 if (!par
[0]) par
[0]++;
1612 gotoxy(currcons
,x
+par
[0],y
);
1615 if (!par
[0]) par
[0]++;
1616 gotoxy(currcons
,x
-par
[0],y
);
1619 if (!par
[0]) par
[0]++;
1620 gotoxy(currcons
,0,y
+par
[0]);
1623 if (!par
[0]) par
[0]++;
1624 gotoxy(currcons
,0,y
-par
[0]);
1627 if (par
[0]) par
[0]--;
1628 gotoxay(currcons
,x
,par
[0]);
1631 if (par
[0]) par
[0]--;
1632 if (par
[1]) par
[1]--;
1633 gotoxay(currcons
,par
[1],par
[0]);
1636 csi_J(currcons
,par
[0]);
1639 csi_K(currcons
,par
[0]);
1642 csi_L(currcons
,par
[0]);
1645 csi_M(currcons
,par
[0]);
1648 csi_P(currcons
,par
[0]);
1656 tab_stop
[x
>> 5] &= ~(1 << (x
& 31));
1657 else if (par
[0] == 3) {
1668 case 'q': /* DECLL - but only 3 leds */
1669 /* map 0,1,2,3 to 0,1,2,4 */
1671 setledstate(kbd_table
+ currcons
,
1672 (par
[0] < 3) ? par
[0] : 4);
1678 par
[1] = video_num_lines
;
1679 /* Minimum allowed region is 2 lines */
1680 if (par
[0] < par
[1] &&
1681 par
[1] <= video_num_lines
) {
1684 gotoxay(currcons
,0,0);
1691 restore_cur(currcons
);
1694 csi_X(currcons
, par
[0]);
1697 csi_at(currcons
,par
[0]);
1699 case ']': /* setterm functions */
1700 setterm_command(currcons
);
1705 vc_state
= ESnormal
;
1707 case '@': /* defined in ISO 2022 */
1710 case 'G': /* prelim official escape code */
1711 case '8': /* retained for compatibility */
1717 vc_state
= ESnormal
;
1720 vc_state
= ESnormal
;
1722 /* DEC screen alignment test. kludge :-) */
1724 (video_erase_char
& 0xff00) | 'E';
1727 (video_erase_char
& 0xff00) | ' ';
1728 do_update_region(currcons
, origin
, screenbuf_size
/2);
1733 G0_charset
= GRAF_MAP
;
1735 G0_charset
= LAT1_MAP
;
1737 G0_charset
= IBMPC_MAP
;
1739 G0_charset
= USER_MAP
;
1741 translate
= set_translate(G0_charset
,currcons
);
1742 vc_state
= ESnormal
;
1746 G1_charset
= GRAF_MAP
;
1748 G1_charset
= LAT1_MAP
;
1750 G1_charset
= IBMPC_MAP
;
1752 G1_charset
= USER_MAP
;
1754 translate
= set_translate(G1_charset
,currcons
);
1755 vc_state
= ESnormal
;
1758 vc_state
= ESnormal
;
1762 static int do_con_write(struct tty_struct
* tty
, int from_user
,
1763 const unsigned char *buf
, int count
)
1765 #ifdef VT_BUF_VRAM_ONLY
1766 #define FLUSH do { } while(0);
1768 #define FLUSH if (draw_x >= 0) { \
1769 sw->con_putcs(vc_cons[currcons].d, (u16 *)draw_from, (u16 *)draw_to-(u16 *)draw_from, y, draw_x); \
1774 int c
, tc
, ok
, n
= 0, draw_x
= -1;
1775 unsigned int currcons
;
1776 unsigned long draw_from
= 0, draw_to
= 0;
1777 struct vt_struct
*vt
= (struct vt_struct
*)tty
->driver_data
;
1778 u16 himask
, charmask
;
1780 currcons
= vt
->vc_num
;
1781 if (!vc_cons_allocated(currcons
)) {
1782 /* could this happen? */
1783 static int error
= 0;
1786 printk("con_write: tty %d not allocated\n", currcons
+1);
1792 /* just to make sure that noone lurks at places he shouldn't see. */
1793 if (verify_area(VERIFY_READ
, buf
, count
))
1794 return 0; /* ?? are error codes legal here ?? */
1797 himask
= hi_font_mask
;
1798 charmask
= himask
? 0x1ff : 0xff;
1800 /* undraw cursor first */
1802 hide_cursor(currcons
);
1804 disable_bh(CONSOLE_BH
);
1805 while (!tty
->stopped
&& count
) {
1806 enable_bh(CONSOLE_BH
);
1811 buf
++; n
++; count
--;
1812 disable_bh(CONSOLE_BH
);
1815 /* Combine UTF-8 into Unicode */
1816 /* Incomplete characters silently ignored */
1818 if (utf_count
> 0 && (c
& 0xc0) == 0x80) {
1819 utf_char
= (utf_char
<< 6) | (c
& 0x3f);
1825 if ((c
& 0xe0) == 0xc0) {
1827 utf_char
= (c
& 0x1f);
1828 } else if ((c
& 0xf0) == 0xe0) {
1830 utf_char
= (c
& 0x0f);
1831 } else if ((c
& 0xf8) == 0xf0) {
1833 utf_char
= (c
& 0x07);
1834 } else if ((c
& 0xfc) == 0xf8) {
1836 utf_char
= (c
& 0x03);
1837 } else if ((c
& 0xfe) == 0xfc) {
1839 utf_char
= (c
& 0x01);
1848 } else { /* no utf */
1849 tc
= translate
[toggle_meta
? (c
|0x80) : c
];
1852 /* If the original code was a control character we
1853 * only allow a glyph to be displayed if the code is
1854 * not normally used (such as for cursor movement) or
1855 * if the disp_ctrl mode has been explicitly enabled.
1856 * Certain characters (as given by the CTRL_ALWAYS
1857 * bitmap) are always displayed as control characters,
1858 * as the console would be pretty useless without
1859 * them; to display an arbitrary font position use the
1860 * direct-to-font zone in UTF-8 mode.
1862 ok
= tc
&& (c
>= 32 ||
1863 (!utf
&& !(((disp_ctrl
? CTRL_ALWAYS
1864 : CTRL_ACTION
) >> c
) & 1)))
1865 && (c
!= 127 || disp_ctrl
)
1868 if (vc_state
== ESnormal
&& ok
) {
1869 /* Now try to find out how to display it */
1870 tc
= conv_uni_to_pc(vc_cons
[currcons
].d
, tc
);
1872 /* If we got -4 (not found) then see if we have
1873 defined a replacement character (U+FFFD) */
1874 tc
= conv_uni_to_pc(vc_cons
[currcons
].d
, 0xfffd);
1876 /* One reason for the -4 can be that we just
1877 did a clear_unimap();
1878 try at least to show something. */
1881 } else if ( tc
== -3 ) {
1882 /* Bad hash table -- hope for the best */
1886 continue; /* Conversion failed */
1888 if (need_wrap
|| decim
)
1895 insert_char(currcons
, 1);
1897 ((attr
& ~himask
) << 8) + ((tc
& 0x100) ? himask
: 0) + (tc
& 0xff) :
1900 if (DO_UPDATE
&& draw_x
< 0) {
1904 if (x
== video_num_columns
- 1) {
1914 do_con_trol(tty
, currcons
, c
);
1917 enable_bh(CONSOLE_BH
);
1923 * This is the console switching bottom half handler.
1925 * Doing console switching in a bottom half handler allows
1926 * us to do the switches asynchronously (needed when we want
1927 * to switch due to a keyboard interrupt), while still giving
1928 * us the option to easily disable it to avoid races when we
1929 * need to write to the console.
1931 static void console_bh(void)
1933 run_task_queue(&con_task_queue
);
1934 if (want_console
>= 0) {
1935 if (want_console
!= fg_console
&& vc_cons_allocated(want_console
)) {
1936 hide_cursor(fg_console
);
1937 change_console(want_console
);
1938 /* we only changed when the console had already
1939 been allocated - a new console is not created
1940 in an interrupt routine */
1944 if (do_poke_blanked_console
) { /* do not unblank for a LED change */
1945 do_poke_blanked_console
= 0;
1946 poke_blanked_console();
1948 if (scrollback_delta
) {
1949 int currcons
= fg_console
;
1951 if (vcmode
== KD_TEXT
)
1952 sw
->con_scrolldelta(vc_cons
[currcons
].d
, scrollback_delta
);
1953 scrollback_delta
= 0;
1957 #ifdef CONFIG_VT_CONSOLE
1960 * Console on virtual terminal
1962 * NOTE NOTE NOTE! This code can do no global locking. In particular,
1963 * we can't disable interrupts or bottom half handlers globally, because
1964 * we can be called from contexts that hold critical spinlocks, and
1965 * trying do get a global lock at this point will lead to deadlocks.
1968 void vt_console_print(struct console
*co
, const char * b
, unsigned count
)
1970 int currcons
= fg_console
;
1972 static unsigned long printing
= 0;
1973 const ushort
*start
;
1977 /* console busy or not yet initialized */
1978 if (!printable
|| test_and_set_bit(0, &printing
))
1981 if (kmsg_redirect
&& vc_cons_allocated(kmsg_redirect
- 1))
1982 currcons
= kmsg_redirect
- 1;
1984 if (!vc_cons_allocated(currcons
)) {
1986 printk("vt_console_print: tty %d not allocated ??\n", currcons
+1);
1990 if (vcmode
!= KD_TEXT
)
1993 /* undraw cursor first */
1995 hide_cursor(currcons
);
1997 start
= (ushort
*)pos
;
1999 /* Contrived structure to try to emulate original need_wrap behaviour
2000 * Problems caused when we have need_wrap set on '\n' character */
2003 if (c
== 10 || c
== 13 || c
== 8 || need_wrap
) {
2006 sw
->con_putcs(vc_cons
[currcons
].d
, start
, cnt
, y
, x
);
2012 if (c
== 8) { /* backspace */
2014 start
= (ushort
*)pos
;
2021 start
= (ushort
*)pos
;
2023 if (c
== 10 || c
== 13)
2026 scr_writew((attr
<< 8) + c
, (unsigned short *) pos
);
2028 if (myx
== video_num_columns
- 1) {
2037 sw
->con_putcs(vc_cons
[currcons
].d
, start
, cnt
, y
, x
);
2039 if (x
== video_num_columns
) {
2044 set_cursor(currcons
);
2045 poke_blanked_console();
2048 clear_bit(0, &printing
);
2051 static kdev_t
vt_console_device(struct console
*c
)
2053 return MKDEV(TTY_MAJOR
, c
->index
? c
->index
: fg_console
+ 1);
2056 struct console vt_console_driver
= {
2061 keyboard_wait_for_keypress
,
2072 * Handling of Linux-specific VC ioctls
2075 int tioclinux(struct tty_struct
*tty
, unsigned long arg
)
2079 if (tty
->driver
.type
!= TTY_DRIVER_TYPE_CONSOLE
)
2081 if (current
->tty
!= tty
&& !suser())
2083 if (get_user(type
, (char *)arg
))
2088 return set_selection(arg
, tty
, 1);
2090 return paste_selection(tty
);
2095 return sel_loadlut(arg
);
2099 * Make it possible to react to Shift+Mousebutton.
2100 * Note that 'shift_state' is an undocumented
2101 * kernel-internal variable; programs not closely
2102 * related to the kernel should not use this.
2105 return __put_user(data
, (char *) arg
);
2107 data
= mouse_reporting();
2108 return __put_user(data
, (char *) arg
);
2110 set_vesa_blanking(arg
);
2112 case 11: /* set kmsg redirect */
2115 if (get_user(data
, (char *)arg
+1))
2117 kmsg_redirect
= data
;
2119 case 12: /* get fg_console */
2126 * /dev/ttyN handling
2129 static int con_write(struct tty_struct
* tty
, int from_user
,
2130 const unsigned char *buf
, int count
)
2134 retval
= do_con_write(tty
, from_user
, buf
, count
);
2135 con_flush_chars(tty
);
2140 static void con_put_char(struct tty_struct
*tty
, unsigned char ch
)
2142 do_con_write(tty
, 0, &ch
, 1);
2145 static int con_write_room(struct tty_struct
*tty
)
2149 return 4096; /* No limit, really; we're not buffering */
2152 static int con_chars_in_buffer(struct tty_struct
*tty
)
2154 return 0; /* we're not buffering */
2158 * con_throttle and con_unthrottle are only used for
2159 * paste_selection(), which has to stuff in a large number of
2162 static void con_throttle(struct tty_struct
*tty
)
2166 static void con_unthrottle(struct tty_struct
*tty
)
2168 struct vt_struct
*vt
= (struct vt_struct
*) tty
->driver_data
;
2170 wake_up_interruptible(&vt
->paste_wait
);
2174 * Turn the Scroll-Lock LED on when the tty is stopped
2176 static void con_stop(struct tty_struct
*tty
)
2181 console_num
= MINOR(tty
->device
) - (tty
->driver
.minor_start
);
2182 if (!vc_cons_allocated(console_num
))
2184 set_vc_kbd_led(kbd_table
+ console_num
, VC_SCROLLOCK
);
2189 * Turn the Scroll-Lock LED off when the console is started
2191 static void con_start(struct tty_struct
*tty
)
2196 console_num
= MINOR(tty
->device
) - (tty
->driver
.minor_start
);
2197 if (!vc_cons_allocated(console_num
))
2199 clr_vc_kbd_led(kbd_table
+ console_num
, VC_SCROLLOCK
);
2203 static void con_flush_chars(struct tty_struct
*tty
)
2205 struct vt_struct
*vt
= (struct vt_struct
*)tty
->driver_data
;
2207 set_cursor(vt
->vc_num
);
2211 * Allocate the console screen memory.
2213 static int con_open(struct tty_struct
*tty
, struct file
* filp
)
2215 unsigned int currcons
;
2218 currcons
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2220 i
= vc_allocate(currcons
);
2224 vt_cons
[currcons
]->vc_num
= currcons
;
2225 tty
->driver_data
= vt_cons
[currcons
];
2227 if (!tty
->winsize
.ws_row
&& !tty
->winsize
.ws_col
) {
2228 tty
->winsize
.ws_row
= video_num_lines
;
2229 tty
->winsize
.ws_col
= video_num_columns
;
2234 static void con_close(struct tty_struct
*tty
, struct file
* filp
)
2236 if (tty
->count
== 1)
2237 tty
->driver_data
= 0;
2240 static void vc_init(unsigned int currcons
, unsigned int rows
, unsigned int cols
, int do_clear
)
2244 video_num_columns
= cols
;
2245 video_num_lines
= rows
;
2246 video_size_row
= cols
<<1;
2247 screenbuf_size
= video_num_lines
* video_size_row
;
2249 set_origin(currcons
);
2252 for (j
=k
=0; j
<16; j
++) {
2253 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_red
[j
] ;
2254 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_grn
[j
] ;
2255 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_blu
[j
] ;
2257 def_color
= 0x07; /* white */
2258 ulcolor
= 0x0f; /* bold white */
2259 halfcolor
= 0x08; /* grey */
2260 vt_cons
[currcons
]->paste_wait
= 0;
2261 reset_terminal(currcons
, do_clear
);
2265 * This routine initializes console interrupts, and does nothing
2266 * else. If you want the screen to clear, call tty_write with
2267 * the appropriate escape-sequence.
2270 struct tty_driver console_driver
;
2271 static int console_refcount
;
2273 __initfunc(unsigned long con_init(unsigned long kmem_start
))
2275 const char *display_desc
= NULL
;
2276 unsigned int currcons
= 0;
2279 display_desc
= conswitchp
->con_startup();
2280 if (!display_desc
) {
2285 memset(&console_driver
, 0, sizeof(struct tty_driver
));
2286 console_driver
.magic
= TTY_DRIVER_MAGIC
;
2287 console_driver
.name
= "tty";
2288 console_driver
.name_base
= 1;
2289 console_driver
.major
= TTY_MAJOR
;
2290 console_driver
.minor_start
= 1;
2291 console_driver
.num
= MAX_NR_CONSOLES
;
2292 console_driver
.type
= TTY_DRIVER_TYPE_CONSOLE
;
2293 console_driver
.init_termios
= tty_std_termios
;
2294 console_driver
.flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_RESET_TERMIOS
;
2295 console_driver
.refcount
= &console_refcount
;
2296 console_driver
.table
= console_table
;
2297 console_driver
.termios
= console_termios
;
2298 console_driver
.termios_locked
= console_termios_locked
;
2300 console_driver
.open
= con_open
;
2301 console_driver
.close
= con_close
;
2302 console_driver
.write
= con_write
;
2303 console_driver
.write_room
= con_write_room
;
2304 console_driver
.put_char
= con_put_char
;
2305 console_driver
.flush_chars
= con_flush_chars
;
2306 console_driver
.chars_in_buffer
= con_chars_in_buffer
;
2307 console_driver
.ioctl
= vt_ioctl
;
2308 console_driver
.stop
= con_stop
;
2309 console_driver
.start
= con_start
;
2310 console_driver
.throttle
= con_throttle
;
2311 console_driver
.unthrottle
= con_unthrottle
;
2313 if (tty_register_driver(&console_driver
))
2314 panic("Couldn't register console driver\n");
2316 timer_table
[BLANK_TIMER
].fn
= blank_screen
;
2317 timer_table
[BLANK_TIMER
].expires
= 0;
2318 if (blankinterval
) {
2319 timer_table
[BLANK_TIMER
].expires
= jiffies
+ blankinterval
;
2320 timer_active
|= 1<<BLANK_TIMER
;
2323 /* Unfortunately, kmalloc is not running yet */
2324 /* Due to kmalloc roundup allocating statically is more efficient -
2325 so provide MIN_NR_CONSOLES for people with very little memory */
2326 for (currcons
= 0; currcons
< MIN_NR_CONSOLES
; currcons
++) {
2329 vc_cons
[currcons
].d
= (struct vc_data
*) kmem_start
;
2330 kmem_start
+= sizeof(struct vc_data
);
2331 vt_cons
[currcons
] = (struct vt_struct
*) kmem_start
;
2332 kmem_start
+= sizeof(struct vt_struct
);
2333 visual_init(currcons
, 1);
2334 screenbuf
= (unsigned short *) kmem_start
;
2335 kmem_start
+= screenbuf_size
;
2337 vc_init(currcons
, video_num_lines
, video_num_columns
,
2338 currcons
|| !sw
->con_save_screen
);
2339 for (j
=k
=0; j
<16; j
++) {
2340 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_red
[j
] ;
2341 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_grn
[j
] ;
2342 vc_cons
[currcons
].d
->vc_palette
[k
++] = default_blu
[j
] ;
2345 currcons
= fg_console
= 0;
2346 master_display_fg
= vc_cons
[currcons
].d
;
2347 set_origin(currcons
);
2348 save_screen(currcons
);
2349 gotoxy(currcons
,x
,y
);
2351 update_screen(fg_console
);
2352 printk("Console: %s %s %dx%d",
2353 can_do_color
? "colour" : "mono",
2354 display_desc
, video_num_columns
, video_num_lines
);
2358 #ifdef CONFIG_VT_CONSOLE
2359 register_console(&vt_console_driver
);
2362 init_bh(CONSOLE_BH
, console_bh
);
2367 #ifndef VT_SINGLE_DRIVER
2369 static void clear_buffer_attributes(int currcons
)
2371 unsigned short *p
= (unsigned short *) origin
;
2372 int count
= screenbuf_size
/2;
2373 int mask
= hi_font_mask
| 0xff;
2375 for (; count
> 0; count
--, p
++) {
2376 scr_writew((scr_readw(p
)&mask
) | (video_erase_char
&~mask
), p
);
2381 * If we support more console drivers, this function is used
2382 * when a driver wants to take over some existing consoles
2383 * and become default driver for newly opened ones.
2386 void take_over_console(struct consw
*csw
, int first
, int last
, int deflt
)
2391 desc
= csw
->con_startup();
2396 for (i
= first
; i
<= last
; i
++) {
2400 con_driver_map
[i
] = csw
;
2402 if (!vc_cons
[i
].d
|| !vc_cons
[i
].d
->vc_sw
)
2408 old_was_color
= vc_cons
[i
].d
->vc_can_do_color
;
2409 vc_cons
[i
].d
->vc_sw
->con_deinit(vc_cons
[i
].d
);
2413 /* If the console changed between mono <-> color, then
2414 * the attributes in the screenbuf will be wrong. The
2415 * following resets all attributes to something sane.
2417 if (old_was_color
!= vc_cons
[i
].d
->vc_can_do_color
)
2418 clear_buffer_attributes(i
);
2423 printk("Console: switching ");
2425 printk("consoles %d-%d ", first
+1, last
+1);
2427 printk("to %s %s %dx%d\n",
2428 vc_cons
[j
].d
->vc_can_do_color
? "colour" : "mono",
2429 desc
, vc_cons
[j
].d
->vc_cols
, vc_cons
[j
].d
->vc_rows
);
2431 printk("to %s\n", desc
);
2434 void give_up_console(struct consw
*csw
)
2438 for(i
= 0; i
< MAX_NR_CONSOLES
; i
++)
2439 if (con_driver_map
[i
] == csw
)
2440 con_driver_map
[i
] = NULL
;
2449 static void set_vesa_blanking(unsigned long arg
)
2451 char *argp
= (char *)arg
+ 1;
2453 get_user(mode
, argp
);
2454 vesa_blank_mode
= (mode
< 4) ? mode
: 0;
2457 static void vesa_powerdown(void)
2459 struct vc_data
*c
= vc_cons
[fg_console
].d
;
2461 * Power down if currently suspended (1 or 2),
2462 * suspend if currently blanked (0),
2463 * else do nothing (i.e. already powered down (3)).
2464 * Called only if powerdown features are allowed.
2466 switch (vesa_blank_mode
) {
2467 case VESA_NO_BLANKING
:
2468 c
->vc_sw
->con_blank(c
, VESA_VSYNC_SUSPEND
+1);
2470 case VESA_VSYNC_SUSPEND
:
2471 case VESA_HSYNC_SUSPEND
:
2472 c
->vc_sw
->con_blank(c
, VESA_POWERDOWN
+1);
2477 static void vesa_powerdown_screen(void)
2479 timer_active
&= ~(1<<BLANK_TIMER
);
2480 timer_table
[BLANK_TIMER
].fn
= unblank_screen
;
2485 void do_blank_screen(int entering_gfx
)
2487 int currcons
= fg_console
;
2490 if (console_blanked
)
2493 /* entering graphics mode? */
2495 hide_cursor(currcons
);
2496 save_screen(currcons
);
2497 sw
->con_blank(vc_cons
[currcons
].d
, -1);
2498 console_blanked
= fg_console
+ 1;
2499 set_origin(currcons
);
2503 /* don't blank graphics */
2504 if (vcmode
!= KD_TEXT
) {
2505 console_blanked
= fg_console
+ 1;
2509 hide_cursor(currcons
);
2510 if (vesa_off_interval
) {
2511 timer_table
[BLANK_TIMER
].fn
= vesa_powerdown_screen
;
2512 timer_table
[BLANK_TIMER
].expires
= jiffies
+ vesa_off_interval
;
2513 timer_active
|= (1<<BLANK_TIMER
);
2515 timer_active
&= ~(1<<BLANK_TIMER
);
2516 timer_table
[BLANK_TIMER
].fn
= unblank_screen
;
2519 save_screen(currcons
);
2520 /* In case we need to reset origin, blanking hook returns 1 */
2521 i
= sw
->con_blank(vc_cons
[currcons
].d
, 1);
2522 console_blanked
= fg_console
+ 1;
2524 set_origin(currcons
);
2527 if (apm_display_blank())
2530 if (vesa_blank_mode
)
2531 sw
->con_blank(vc_cons
[currcons
].d
, vesa_blank_mode
+ 1);
2534 void unblank_screen(void)
2538 if (!console_blanked
)
2540 if (!vc_cons_allocated(fg_console
)) {
2542 printk("unblank_screen: tty %d not allocated ??\n", fg_console
+1);
2545 timer_table
[BLANK_TIMER
].fn
= blank_screen
;
2546 if (blankinterval
) {
2547 timer_table
[BLANK_TIMER
].expires
= jiffies
+ blankinterval
;
2548 timer_active
|= 1<<BLANK_TIMER
;
2551 currcons
= fg_console
;
2552 console_blanked
= 0;
2554 apm_display_unblank();
2556 if (sw
->con_blank(vc_cons
[currcons
].d
, 0))
2557 /* Low-level driver cannot restore -> do it ourselves */
2558 update_screen(fg_console
);
2559 set_cursor(fg_console
);
2562 static void blank_screen(void)
2567 void poke_blanked_console(void)
2569 timer_active
&= ~(1<<BLANK_TIMER
);
2570 if (vt_cons
[fg_console
]->vc_mode
== KD_GRAPHICS
)
2572 if (console_blanked
) {
2573 timer_table
[BLANK_TIMER
].fn
= unblank_screen
;
2574 timer_table
[BLANK_TIMER
].expires
= jiffies
; /* Now */
2575 timer_active
|= 1<<BLANK_TIMER
;
2576 } else if (blankinterval
) {
2577 timer_table
[BLANK_TIMER
].expires
= jiffies
+ blankinterval
;
2578 timer_active
|= 1<<BLANK_TIMER
;
2586 void set_palette(int currcons
)
2588 if (vcmode
!= KD_GRAPHICS
)
2589 sw
->con_set_palette(vc_cons
[currcons
].d
, color_table
);
2592 static int set_get_cmap(unsigned char *arg
, int set
)
2596 for (i
= 0; i
< 16; i
++)
2598 get_user(default_red
[i
], arg
++);
2599 get_user(default_grn
[i
], arg
++);
2600 get_user(default_blu
[i
], arg
++);
2602 put_user(default_red
[i
], arg
++);
2603 put_user(default_grn
[i
], arg
++);
2604 put_user(default_blu
[i
], arg
++);
2607 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
2608 if (vc_cons_allocated(i
)) {
2609 for (j
= k
= 0; j
< 16; j
++) {
2610 vc_cons
[i
].d
->vc_palette
[k
++] = default_red
[j
];
2611 vc_cons
[i
].d
->vc_palette
[k
++] = default_grn
[j
];
2612 vc_cons
[i
].d
->vc_palette
[k
++] = default_blu
[j
];
2621 * Load palette into the DAC registers. arg points to a colour
2622 * map, 3 bytes per colour, 16 colours, range from 0 to 255.
2625 int con_set_cmap(unsigned char *arg
)
2627 return set_get_cmap (arg
,1);
2630 int con_get_cmap(unsigned char *arg
)
2632 return set_get_cmap (arg
,0);
2635 void reset_palette(int currcons
)
2638 for (j
=k
=0; j
<16; j
++) {
2639 palette
[k
++] = default_red
[j
];
2640 palette
[k
++] = default_grn
[j
];
2641 palette
[k
++] = default_blu
[j
];
2643 set_palette(currcons
);
2649 * Currently we only support fonts up to 32 pixels wide, at a maximum height
2650 * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints,
2651 * depending on width) reserved for each character which is kinda wasty, but
2652 * this is done in order to maintain compatibility with the EGA/VGA fonts. It
2653 * is upto the actual low-level console-driver convert data into its favorite
2654 * format (maybe we should add a `fontoffset' field to the `display'
2655 * structure so we wont have to convert the fontdata all the time.
2659 #define max_font_size 65536
2661 int con_font_op(int currcons
, struct console_font_op
*op
)
2664 int size
= max_font_size
, set
;
2666 struct console_font_op old_op
;
2668 if (vt_cons
[currcons
]->vc_mode
!= KD_TEXT
)
2670 memcpy(&old_op
, op
, sizeof(old_op
));
2671 if (op
->op
== KD_FONT_OP_SET
) {
2674 if (op
->charcount
> 512)
2676 if (!op
->height
) { /* Need to guess font height [compat] */
2678 u8
*charmap
= op
->data
, tmp
;
2680 /* If from KDFONTOP ioctl, don't allow things which can be done in userland,
2681 so that we can get rid of this soon */
2682 if (!(op
->flags
& KD_FONT_FLAG_OLD
))
2685 for (h
= 32; h
> 0; h
--)
2686 for (i
= 0; i
< op
->charcount
; i
++) {
2687 if (get_user(tmp
, &charmap
[32*i
+h
-1]))
2698 if (op
->width
> 32 || op
->height
> 32)
2700 size
= (op
->width
+7)/8 * 32 * op
->charcount
;
2701 if (size
> max_font_size
)
2704 } else if (op
->op
== KD_FONT_OP_GET
)
2707 return sw
->con_font_op(vc_cons
[currcons
].d
, op
);
2709 temp
= kmalloc(size
, GFP_KERNEL
);
2712 if (set
&& copy_from_user(temp
, op
->data
, size
)) {
2718 disable_bh(CONSOLE_BH
);
2719 rc
= sw
->con_font_op(vc_cons
[currcons
].d
, op
);
2720 enable_bh(CONSOLE_BH
);
2721 op
->data
= old_op
.data
;
2723 int c
= (op
->width
+7)/8 * 32 * op
->charcount
;
2725 if (op
->data
&& op
->charcount
> old_op
.charcount
)
2727 if (!(op
->flags
& KD_FONT_FLAG_OLD
)) {
2728 if (op
->width
> old_op
.width
||
2729 op
->height
> old_op
.height
)
2734 else if ((old_op
.height
&& op
->height
> old_op
.height
) ||
2738 if (!rc
&& op
->data
&& copy_to_user(op
->data
, temp
, c
))
2742 kfree_s(temp
, size
);
2747 * Interface exported to selection and vcs.
2750 /* used by selection */
2751 u16
screen_glyph(int currcons
, int offset
)
2753 u16 w
= scr_readw(screenpos(currcons
, offset
, 1));
2756 if (w
& hi_font_mask
)
2761 /* used by vcs - note the word offset */
2762 unsigned short *screen_pos(int currcons
, int w_offset
, int viewed
)
2764 return screenpos(currcons
, 2 * w_offset
, viewed
);
2767 void getconsxy(int currcons
, char *p
)
2773 void putconsxy(int currcons
, char *p
)
2775 gotoxy(currcons
, p
[0], p
[1]);
2776 set_cursor(currcons
);
2779 u16
vcs_scr_readw(int currcons
, u16
*org
)
2781 if ((unsigned long)org
== pos
&& softcursor_original
!= -1)
2782 return softcursor_original
;
2783 return scr_readw(org
);
2786 void vcs_scr_writew(int currcons
, u16 val
, u16
*org
)
2788 scr_writew(val
, org
);
2789 if ((unsigned long)org
== pos
) {
2790 softcursor_original
= -1;
2791 add_softcursor(currcons
);
2797 * Visible symbols for modules
2800 EXPORT_SYMBOL(color_table
);
2801 EXPORT_SYMBOL(default_red
);
2802 EXPORT_SYMBOL(default_grn
);
2803 EXPORT_SYMBOL(default_blu
);
2804 EXPORT_SYMBOL(video_font_height
);
2805 EXPORT_SYMBOL(video_scan_lines
);
2806 EXPORT_SYMBOL(vc_resize
);
2808 #ifndef VT_SINGLE_DRIVER
2809 EXPORT_SYMBOL(take_over_console
);
2810 EXPORT_SYMBOL(give_up_console
);