This source file includes following definitions.
- gotoxy
- __set_origin
- scrollback
- scrollfront
- set_origin
- hide_cursor
- set_cursor
- scrup
- scrdown
- lf
- ri
- cr
- bs
- del
- csi_J
- csi_K
- update_attr
- default_attr
- csi_m
- respond_string
- respond_num
- cursor_report
- status_report
- respond_ID
- invert_screen
- set_mode
- setterm_command
- insert_char
- insert_line
- delete_char
- delete_line
- csi_at
- csi_L
- csi_P
- csi_M
- save_cur
- restore_cur
- reset_terminal
- con_write
- do_keyboard_interrupt
- memsetw
- con_init
- kbdsave
- get_scrmem
- set_scrmem
- blank_screen
- unblank_screen
- update_screen
- do_screendump
- console_print
- con_open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 #include <linux/sched.h>
39 #include <linux/timer.h>
40 #include <linux/tty.h>
41 #include <linux/config.h>
42 #include <linux/kernel.h>
43 #include <linux/string.h>
44 #include <linux/errno.h>
45 #include <linux/kd.h>
46 #include <linux/keyboard.h>
47
48 #include <asm/io.h>
49 #include <asm/system.h>
50 #include <asm/segment.h>
51
52 #include "vt_kern.h"
53
54 #define NPAR 16
55
56 extern void vt_init(void);
57 extern void register_console(void (*proc)(const char *));
58
59 unsigned long video_num_columns;
60 unsigned long video_num_lines;
61
62 static unsigned char video_type;
63 static unsigned long video_mem_base;
64 static unsigned long video_mem_term;
65 static unsigned long video_size_row;
66 static unsigned char video_page;
67 static unsigned short video_port_reg;
68 static unsigned short video_port_val;
69 static int can_do_color = 0;
70 static int printable = 0;
71
72 static struct {
73 unsigned short vc_video_erase_char;
74 unsigned char vc_attr;
75 unsigned char vc_def_color;
76 unsigned char vc_color;
77 unsigned char vc_s_color;
78 unsigned char vc_ulcolor;
79 unsigned char vc_halfcolor;
80 unsigned long vc_origin;
81 unsigned long vc_scr_end;
82 unsigned long vc_pos;
83 unsigned long vc_x,vc_y;
84 unsigned long vc_top,vc_bottom;
85 unsigned long vc_state;
86 unsigned long vc_npar,vc_par[NPAR];
87 unsigned long vc_video_mem_start;
88 unsigned long vc_video_mem_end;
89 unsigned long vc_saved_x;
90 unsigned long vc_saved_y;
91
92 unsigned long vc_charset : 1;
93 unsigned long vc_s_charset : 1;
94 unsigned long vc_decscnm : 1;
95 unsigned long vc_decom : 1;
96 unsigned long vc_decawm : 1;
97 unsigned long vc_deccm : 1;
98 unsigned long vc_decim : 1;
99
100 unsigned long vc_intensity : 2;
101 unsigned long vc_underline : 1;
102 unsigned long vc_blink : 1;
103 unsigned long vc_reverse : 1;
104 unsigned long vc_s_intensity : 2;
105 unsigned long vc_s_underline : 1;
106 unsigned long vc_s_blink : 1;
107 unsigned long vc_s_reverse : 1;
108
109 unsigned long vc_ques : 1;
110 unsigned long vc_need_wrap : 1;
111 unsigned long vc_tab_stop[5];
112 unsigned char vc_kbdmode;
113 unsigned char * vc_translate;
114 unsigned char * vc_G0_charset;
115 unsigned char * vc_G1_charset;
116 unsigned char * vc_saved_G0;
117 unsigned char * vc_saved_G1;
118
119 } vc_cons [NR_CONSOLES];
120
121 unsigned short *vc_scrbuf[NR_CONSOLES];
122 static unsigned short * vc_scrmembuf;
123 static int console_blanked = 0;
124
125 #define origin (vc_cons[currcons].vc_origin)
126 #define scr_end (vc_cons[currcons].vc_scr_end)
127 #define pos (vc_cons[currcons].vc_pos)
128 #define top (vc_cons[currcons].vc_top)
129 #define bottom (vc_cons[currcons].vc_bottom)
130 #define x (vc_cons[currcons].vc_x)
131 #define y (vc_cons[currcons].vc_y)
132 #define state (vc_cons[currcons].vc_state)
133 #define npar (vc_cons[currcons].vc_npar)
134 #define par (vc_cons[currcons].vc_par)
135 #define ques (vc_cons[currcons].vc_ques)
136 #define attr (vc_cons[currcons].vc_attr)
137 #define saved_x (vc_cons[currcons].vc_saved_x)
138 #define saved_y (vc_cons[currcons].vc_saved_y)
139 #define translate (vc_cons[currcons].vc_translate)
140 #define G0_charset (vc_cons[currcons].vc_G0_charset)
141 #define G1_charset (vc_cons[currcons].vc_G1_charset)
142 #define saved_G0 (vc_cons[currcons].vc_saved_G0)
143 #define saved_G1 (vc_cons[currcons].vc_saved_G1)
144 #define video_mem_start (vc_cons[currcons].vc_video_mem_start)
145 #define video_mem_end (vc_cons[currcons].vc_video_mem_end)
146 #define video_erase_char (vc_cons[currcons].vc_video_erase_char)
147 #define decscnm (vc_cons[currcons].vc_decscnm)
148 #define decom (vc_cons[currcons].vc_decom)
149 #define decawm (vc_cons[currcons].vc_decawm)
150 #define deccm (vc_cons[currcons].vc_deccm)
151 #define decim (vc_cons[currcons].vc_decim)
152 #define need_wrap (vc_cons[currcons].vc_need_wrap)
153 #define color (vc_cons[currcons].vc_color)
154 #define s_color (vc_cons[currcons].vc_s_color)
155 #define def_color (vc_cons[currcons].vc_def_color)
156 #define foreground (color & 0x0f)
157 #define background (color & 0xf0)
158 #define charset (vc_cons[currcons].vc_charset)
159 #define s_charset (vc_cons[currcons].vc_s_charset)
160 #define intensity (vc_cons[currcons].vc_intensity)
161 #define underline (vc_cons[currcons].vc_underline)
162 #define blink (vc_cons[currcons].vc_blink)
163 #define reverse (vc_cons[currcons].vc_reverse)
164 #define s_intensity (vc_cons[currcons].vc_s_intensity)
165 #define s_underline (vc_cons[currcons].vc_s_underline)
166 #define s_blink (vc_cons[currcons].vc_s_blink)
167 #define s_reverse (vc_cons[currcons].vc_s_reverse)
168 #define ulcolor (vc_cons[currcons].vc_ulcolor)
169 #define halfcolor (vc_cons[currcons].vc_halfcolor)
170 #define kbdmode (vc_cons[currcons].vc_kbdmode)
171 #define tab_stop (vc_cons[currcons].vc_tab_stop)
172 #define vcmode (vt_cons[currcons].vc_mode)
173 #define vtmode (vt_cons[currcons].vt_mode)
174 #define vtpid (vt_cons[currcons].vt_pid)
175 #define vtnewvt (vt_cons[currcons].vt_newvt)
176
177 #define set_kbd(x) set_vc_kbd_flag(kbd_table+currcons,x)
178 #define clr_kbd(x) clr_vc_kbd_flag(kbd_table+currcons,x)
179 #define is_kbd(x) vc_kbd_flag(kbd_table+currcons,x)
180
181 #define decarm VC_REPEAT
182 #define decckm VC_CKMODE
183 #define kbdapplic VC_APPLIC
184 #define kbdraw VC_RAW
185 #define lnm VC_CRLF
186
187 int blankinterval = 10*60*HZ;
188 static int screen_size = 0;
189
190 extern void kd_mksound(int freq, int time);
191
192
193
194
195 #define VT100ID "\033[?1;2c"
196 #define VT102ID "\033[?6c"
197
198 static unsigned char * translations[] = {
199
200 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
201 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
202 " !\"#$%&'()*+,-./0123456789:;<=>?"
203 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
204 "`abcdefghijklmnopqrstuvwxyz{|}~\0"
205 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
206 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
207 "\040\255\233\234\376\235\174\025\376\376\246\256\252\055\376\376"
208 "\370\361\375\376\376\346\024\371\376\376\247\257\254\253\376\250"
209 "\376\376\376\376\216\217\222\200\376\220\376\376\376\376\376\376"
210 "\376\245\376\376\376\376\231\376\376\376\376\376\232\376\376\341"
211 "\205\240\203\376\204\206\221\207\212\202\210\211\215\241\214\213"
212 "\376\244\225\242\223\376\224\366\376\227\243\226\201\376\376\230",
213
214 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
215 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
216 " !\"#$%&'()*+,-./0123456789:;<=>?"
217 "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ "
218 "\004\261\007\007\007\007\370\361\040\007\331\277\332\300\305\007"
219 "\007\304\007\007\303\264\301\302\263\007\007\007\007\007\234\0"
220 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
221 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
222 "\040\255\233\234\376\235\174\025\376\376\246\256\252\055\376\376"
223 "\370\361\375\376\376\346\024\371\376\376\247\257\254\253\376\250"
224 "\376\376\376\376\216\217\222\200\376\220\376\376\376\376\376\376"
225 "\376\245\376\376\376\376\231\376\376\376\376\376\232\376\376\341"
226 "\205\240\203\376\204\206\221\207\212\202\210\211\215\241\214\213"
227 "\376\244\225\242\223\376\224\366\376\227\243\226\201\376\376\230",
228
229 "\000\001\002\003\004\005\006\007\010\011\000\013\000\000\000\000"
230 "\020\021\022\023\024\025\026\027\030\031\032\000\034\035\036\037"
231 "\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057"
232 "\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077"
233 "\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117"
234 "\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137"
235 "\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157"
236 "\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"
237 "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217"
238 "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237"
239 "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257"
240 "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277"
241 "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"
242 "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337"
243 "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357"
244 "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
245 };
246
247 #define NORM_TRANS (translations[0])
248 #define GRAF_TRANS (translations[1])
249 #define NULL_TRANS (translations[2])
250
251 static unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
252 8,12,10,14, 9,13,11,15 };
253
254
255
256
257
258
259 static void gotoxy(int currcons, int new_x, int new_y)
260 {
261 int max_y;
262
263 if (new_x < 0)
264 x = 0;
265 else
266 if (new_x >= video_num_columns)
267 x = video_num_columns - 1;
268 else
269 x = new_x;
270 if (decom) {
271 new_y += top;
272 max_y = bottom;
273 } else
274 max_y = video_num_lines;
275 if (new_y < 0)
276 y = 0;
277 else
278 if (new_y >= max_y)
279 y = max_y - 1;
280 else
281 y = new_y;
282 pos = origin + y*video_size_row + (x<<1);
283 need_wrap = 0;
284 }
285
286
287
288
289 static unsigned short __real_origin;
290 static unsigned short __origin;
291
292 static inline void __set_origin(unsigned short offset)
293 {
294 cli();
295 __origin = offset;
296 outb_p(12, video_port_reg);
297 outb_p(offset >> 8, video_port_val);
298 outb_p(13, video_port_reg);
299 outb_p(offset, video_port_val);
300 sti();
301 }
302
303 void scrollback(int lines)
304 {
305 if (!lines)
306 lines = video_num_lines/2;
307 lines *= video_num_columns;
308 lines = __origin - lines;
309 if (lines < 0)
310 lines = 0;
311 __set_origin(lines);
312 }
313
314 void scrollfront(int lines)
315 {
316 if (!lines)
317 lines = video_num_lines/2;
318 lines *= video_num_columns;
319 lines = __origin + lines;
320 if (lines > __real_origin)
321 lines = __real_origin;
322 __set_origin(lines);
323 }
324
325 static void set_origin(int currcons)
326 {
327 if (video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_EGAM)
328 return;
329 if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS)
330 return;
331 __real_origin = (origin-video_mem_base) >> 1;
332 __set_origin(__real_origin);
333 }
334
335 static inline void hide_cursor(int currcons)
336 {
337 outb_p(14, video_port_reg);
338 outb_p(0xff&((scr_end-video_mem_base)>>9), video_port_val);
339 outb_p(15, video_port_reg);
340 outb_p(0xff&((scr_end-video_mem_base)>>1), video_port_val);
341 }
342
343 static inline void set_cursor(int currcons)
344 {
345 if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS)
346 return;
347 if (__real_origin != __origin)
348 set_origin(__real_origin);
349 cli();
350 if (deccm) {
351 outb_p(14, video_port_reg);
352 outb_p(0xff&((pos-video_mem_base)>>9), video_port_val);
353 outb_p(15, video_port_reg);
354 outb_p(0xff&((pos-video_mem_base)>>1), video_port_val);
355 } else
356 hide_cursor(currcons);
357 sti();
358 }
359
360 static void scrup(int currcons, unsigned int t, unsigned int b)
361 {
362 int hardscroll = 1;
363
364 if (b > video_num_lines || t >= b)
365 return;
366 if (video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_EGAM)
367 hardscroll = 0;
368 else if (t || b != video_num_lines)
369 hardscroll = 0;
370 if (hardscroll) {
371 origin += video_size_row;
372 pos += video_size_row;
373 scr_end += video_size_row;
374 if (scr_end > video_mem_end) {
375 __asm__("cld\n\t"
376 "rep\n\t"
377 "movsl\n\t"
378 "movl _video_num_columns,%1\n\t"
379 "rep\n\t"
380 "stosw"
381 ::"a" (video_erase_char),
382 "c" ((video_num_lines-1)*video_num_columns>>1),
383 "D" (video_mem_start),
384 "S" (origin)
385 :"cx","di","si");
386 scr_end -= origin-video_mem_start;
387 pos -= origin-video_mem_start;
388 origin = video_mem_start;
389 } else {
390 __asm__("cld\n\t"
391 "rep\n\t"
392 "stosw"
393 ::"a" (video_erase_char),
394 "c" (video_num_columns),
395 "D" (scr_end-video_size_row)
396 :"cx","di");
397 }
398 set_origin(currcons);
399 } else {
400 __asm__("cld\n\t"
401 "rep\n\t"
402 "movsl\n\t"
403 "movl _video_num_columns,%%ecx\n\t"
404 "rep\n\t"
405 "stosw"
406 ::"a" (video_erase_char),
407 "c" ((b-t-1)*video_num_columns>>1),
408 "D" (origin+video_size_row*t),
409 "S" (origin+video_size_row*(t+1))
410 :"cx","di","si");
411 }
412 }
413
414 static void scrdown(int currcons, unsigned int t, unsigned int b)
415 {
416 if (b > video_num_lines || t >= b)
417 return;
418 __asm__("std\n\t"
419 "rep\n\t"
420 "movsl\n\t"
421 "addl $2,%%edi\n\t"
422 "movl _video_num_columns,%%ecx\n\t"
423 "rep\n\t"
424 "stosw\n\t"
425 "cld"
426 ::"a" (video_erase_char),
427 "c" ((b-t-1)*video_num_columns>>1),
428 "D" (origin+video_size_row*b-4),
429 "S" (origin+video_size_row*(b-1)-4)
430 :"ax","cx","di","si");
431 }
432
433 static void lf(int currcons)
434 {
435 if (y+1<bottom) {
436 y++;
437 pos += video_size_row;
438 return;
439 } else
440 scrup(currcons,top,bottom);
441 need_wrap = 0;
442 }
443
444 static void ri(int currcons)
445 {
446 if (y>top) {
447 y--;
448 pos -= video_size_row;
449 return;
450 } else
451 scrdown(currcons,top,bottom);
452 need_wrap = 0;
453 }
454
455 static inline void cr(int currcons)
456 {
457 pos -= x<<1;
458 need_wrap = x = 0;
459 }
460
461 static inline void bs(int currcons)
462 {
463 if (x) {
464 pos -= 2;
465 x--;
466 need_wrap = 0;
467 }
468 }
469
470 static inline void del(int currcons)
471 {
472 if (x) {
473 pos -= 2;
474 x--;
475 *(unsigned short *)pos = video_erase_char;
476 need_wrap = 0;
477 }
478 }
479
480 static void csi_J(int currcons, int vpar)
481 {
482 unsigned long count;
483 unsigned long start;
484
485 switch (vpar) {
486 case 0:
487 count = (scr_end-pos)>>1;
488 start = pos;
489 break;
490 case 1:
491 count = ((pos-origin)>>1)+1;
492 start = origin;
493 break;
494 case 2:
495 count = video_num_columns * video_num_lines;
496 start = origin;
497 break;
498 default:
499 return;
500 }
501 __asm__("cld\n\t"
502 "rep\n\t"
503 "stosw\n\t"
504 ::"c" (count),
505 "D" (start),"a" (video_erase_char)
506 :"cx","di");
507 need_wrap = 0;
508 }
509
510 static void csi_K(int currcons, int vpar)
511 {
512 long count;
513 long start;
514
515 switch (vpar) {
516 case 0:
517 count = video_num_columns-x;
518 start = pos;
519 break;
520 case 1:
521 start = pos - (x<<1);
522 count = x+1;
523 break;
524 case 2:
525 start = pos - (x<<1);
526 count = video_num_columns;
527 break;
528 default:
529 return;
530 }
531 __asm__("cld\n\t"
532 "rep\n\t"
533 "stosw\n\t"
534 ::"c" (count),
535 "D" (start),"a" (video_erase_char)
536 :"cx","di");
537 need_wrap = 0;
538 }
539
540
541
542
543 static void update_attr(int currcons)
544 {
545 attr = color;
546 if (can_do_color) {
547 if (underline)
548 attr = (attr & 0xf0) | ulcolor;
549 else if (intensity == 0)
550 attr = (attr & 0xf0) | halfcolor;
551 }
552 if (reverse ^ decscnm)
553 attr = (attr & 0x88) | (((attr >> 4) | (attr << 4)) & 0x77);
554 if (blink)
555 attr ^= 0x80;
556 if (intensity == 2)
557 attr ^= 0x08;
558 if (!can_do_color) {
559 if (underline)
560 attr = (attr & 0xf8) | 0x01;
561 else if (intensity == 0)
562 attr = (attr & 0xf0) | 0x08;
563 }
564 if (decscnm)
565 video_erase_char = ((color & 0x88) | (((color >> 4) |
566 (color << 4)) & 0x77) << 8) | ' ';
567 else
568 video_erase_char = (color << 8) | ' ';
569 }
570
571 static void default_attr(int currcons) {
572 intensity = 1;
573 underline = 0;
574 reverse = 0;
575 blink = 0;
576 color = def_color;
577 }
578
579 static void csi_m(int currcons)
580 {
581 int i;
582
583 for (i=0;i<=npar;i++)
584 switch (par[i]) {
585 case 0:
586 default_attr(currcons);
587 break;
588 case 1:
589 intensity = 2;
590 break;
591 case 2:
592 intensity = 0;
593 break;
594 case 4:
595 underline = 1;
596 break;
597 case 5:
598 blink = 1;
599 break;
600 case 7:
601 reverse = 1;
602 break;
603 case 21:
604 case 22:
605 intensity = 1;
606 break;
607 case 24:
608 underline = 0;
609 break;
610 case 25:
611 blink = 0;
612 break;
613 case 27:
614 reverse = 0;
615 break;
616 case 39:
617 color = (def_color & 0x0f) | background;
618 break;
619 case 49:
620 color = (def_color & 0xf0) | foreground;
621 break;
622 default:
623 if (par[i] >= 30 && par[i] <= 37)
624 color = color_table[par[i]-30]
625 | background;
626 else if (par[i] >= 40 && par[i] <= 47)
627 color = (color_table[par[i]-40]<<4)
628 | foreground;
629 break;
630 }
631 update_attr(currcons);
632 }
633
634 static void respond_string(char * p, int currcons, struct tty_struct * tty)
635 {
636 while (*p) {
637 put_tty_queue(*p, &tty->read_q);
638 p++;
639 }
640 TTY_READ_FLUSH(tty);
641 }
642
643 static void respond_num(unsigned int n, int currcons, struct tty_struct * tty)
644 {
645 char buff[3];
646 int i = 0;
647
648 do {
649 buff[i++] = (n%10)+'0';
650 n /= 10;
651 } while(n && i < 3);
652 while (i--) {
653 put_tty_queue(buff[i], &tty->read_q);
654 }
655
656 }
657
658 static void cursor_report(int currcons, struct tty_struct * tty)
659 {
660 put_tty_queue('\033', &tty->read_q);
661 put_tty_queue('[', &tty->read_q);
662 respond_num(y + (decom ? top+1 : 1), currcons, tty);
663 put_tty_queue(';', &tty->read_q);
664 respond_num(x+1, currcons, tty);
665 put_tty_queue('R', &tty->read_q);
666 TTY_READ_FLUSH(tty);
667 }
668
669 static inline void status_report(int currcons, struct tty_struct * tty)
670 {
671 respond_string("\033[0n", currcons, tty);
672 }
673
674 static inline void respond_ID(int currcons, struct tty_struct * tty)
675 {
676 respond_string(VT102ID, currcons, tty);
677 }
678
679 static void invert_screen(int currcons) {
680 unsigned char *p;
681
682 if (can_do_color)
683 for (p = (unsigned char *)origin+1; p < (unsigned char *)scr_end; p+=2)
684 *p = (*p & 0x88) | (((*p >> 4) | (*p << 4)) & 0x77);
685 else
686 for (p = (unsigned char *)origin+1; p < (unsigned char *)scr_end; p+=2)
687 *p ^= *p & 0x07 == 1 ? 0x70 : 0x77;
688 }
689
690 static void set_mode(int currcons, int on_off)
691 {
692 int i;
693
694 for (i=0; i<=npar; i++)
695 if (ques) switch(par[i]) {
696 case 1:
697 if (on_off)
698 set_kbd(decckm);
699 else
700 clr_kbd(decckm);
701 break;
702 case 3:
703 csi_J(currcons,2);
704 gotoxy(currcons,0,0);
705 break;
706 case 5:
707 if (decscnm != on_off) {
708 decscnm = on_off;
709 invert_screen(currcons);
710 update_attr(currcons);
711 }
712 break;
713 case 6:
714 decom = on_off;
715 gotoxy(currcons,0,0);
716 break;
717 case 7:
718 decawm = on_off;
719 break;
720 case 8:
721 if (on_off)
722 set_kbd(decarm);
723 else
724 clr_kbd(decarm);
725 break;
726 case 25:
727 deccm = on_off;
728 set_cursor(currcons);
729 break;
730 } else switch(par[i]) {
731 case 4:
732 decim = on_off;
733 break;
734 case 20:
735 if (on_off)
736 set_kbd(lnm);
737 else
738 clr_kbd(lnm);
739 break;
740 }
741 }
742
743 static void setterm_command(int currcons)
744 {
745 switch(par[0]) {
746 case 1:
747 if (can_do_color && par[1] < 16) {
748 ulcolor = color_table[par[1]];
749 if (underline)
750 update_attr(currcons);
751 }
752 break;
753 case 2:
754 if (can_do_color && par[1] < 16) {
755 halfcolor = color_table[par[1]];
756 if (intensity == 0)
757 update_attr(currcons);
758 }
759 break;
760 case 8:
761 def_color = attr;
762 default_attr(currcons);
763 update_attr(currcons);
764 break;
765 case 9:
766 blankinterval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;
767 break;
768 }
769 }
770
771 static void insert_char(int currcons)
772 {
773 unsigned int i = x;
774 unsigned short tmp, old = video_erase_char;
775 unsigned short * p = (unsigned short *) pos;
776
777 while (i++ < video_num_columns) {
778 tmp = *p;
779 *p = old;
780 old = tmp;
781 p++;
782 }
783 need_wrap = 0;
784 }
785
786 static void insert_line(int currcons)
787 {
788 scrdown(currcons,y,bottom);
789 need_wrap = 0;
790 }
791
792 static void delete_char(int currcons)
793 {
794 unsigned int i = x;
795 unsigned short * p = (unsigned short *) pos;
796
797 while (++i < video_num_columns) {
798 *p = *(p+1);
799 p++;
800 }
801 *p = video_erase_char;
802 need_wrap = 0;
803 }
804
805 static void delete_line(int currcons)
806 {
807 scrup(currcons,y,bottom);
808 need_wrap = 0;
809 }
810
811 static void csi_at(int currcons, unsigned int nr)
812 {
813 if (nr > video_num_columns)
814 nr = video_num_columns;
815 else if (!nr)
816 nr = 1;
817 while (nr--)
818 insert_char(currcons);
819 }
820
821 static void csi_L(int currcons, unsigned int nr)
822 {
823 if (nr > video_num_lines)
824 nr = video_num_lines;
825 else if (!nr)
826 nr = 1;
827 while (nr--)
828 insert_line(currcons);
829 }
830
831 static void csi_P(int currcons, unsigned int nr)
832 {
833 if (nr > video_num_columns)
834 nr = video_num_columns;
835 else if (!nr)
836 nr = 1;
837 while (nr--)
838 delete_char(currcons);
839 }
840
841 static void csi_M(int currcons, unsigned int nr)
842 {
843 if (nr > video_num_lines)
844 nr = video_num_lines;
845 else if (!nr)
846 nr=1;
847 while (nr--)
848 delete_line(currcons);
849 }
850
851 static void save_cur(int currcons)
852 {
853 saved_x = x;
854 saved_y = y;
855 s_intensity = intensity;
856 s_underline = underline;
857 s_blink = blink;
858 s_reverse = reverse;
859 s_charset = charset;
860 s_color = color;
861 saved_G0 = G0_charset;
862 saved_G1 = G1_charset;
863 }
864
865 static void restore_cur(int currcons)
866 {
867 gotoxy(currcons,saved_x,saved_y);
868 intensity = s_intensity;
869 underline = s_underline;
870 blink = s_blink;
871 reverse = s_reverse;
872 charset = s_charset;
873 color = s_color;
874 G0_charset = saved_G0;
875 G1_charset = saved_G1;
876 translate = charset ? G1_charset : G0_charset;
877 update_attr(currcons);
878 need_wrap = 0;
879 }
880
881 enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
882 EShash, ESsetG0, ESsetG1, ESignore };
883
884 static void reset_terminal(int currcons, int do_clear)
885 {
886 top = 0;
887 bottom = video_num_lines;
888 state = ESnormal;
889 ques = 0;
890 translate = NORM_TRANS;
891 G0_charset = NORM_TRANS;
892 G1_charset = GRAF_TRANS;
893 charset = 0;
894 need_wrap = 0;
895
896 decscnm = 0;
897 decom = 0;
898 decawm = 1;
899 deccm = 1;
900 decim = 0;
901
902 set_kbd(decarm);
903 clr_kbd(decckm);
904 clr_kbd(kbdapplic);
905 clr_kbd(lnm);
906 kbd_table[currcons].flags =
907 (kbd_table[currcons].flags & ~LED_MASK) |
908 (kbd_table[currcons].default_flags & LED_MASK);
909 kbdmode = 0;
910 set_leds();
911
912 default_attr(currcons);
913 update_attr(currcons);
914
915 tab_stop[0] = 0x01010100;
916 tab_stop[1] =
917 tab_stop[2] =
918 tab_stop[3] =
919 tab_stop[4] = 0x01010101;
920
921 if (do_clear) {
922 gotoxy(currcons,0,0);
923 csi_J(currcons,2);
924 save_cur(currcons);
925 }
926 }
927
928 void con_write(struct tty_struct * tty)
929 {
930 int c;
931 unsigned int currcons;
932
933 wake_up_interruptible(&tty->write_q.proc_list);
934 currcons = tty->line - 1;
935 if (currcons >= NR_CONSOLES) {
936 printk("con_write: illegal tty (%d)\n", currcons);
937 return;
938 }
939 while (!tty->stopped && (c = get_tty_queue(&tty->write_q)) >= 0) {
940 if (state == ESnormal && translate[c]) {
941 if (need_wrap) {
942 cr(currcons);
943 lf(currcons);
944 }
945 if (decim)
946 insert_char(currcons);
947 c = translate[c];
948 *(unsigned short *) pos = (attr << 8) + c;
949 if (x == video_num_columns - 1)
950 need_wrap = decawm;
951 else {
952 x++;
953 pos+=2;
954 }
955 continue;
956 }
957
958
959
960
961
962 switch (c) {
963 case 7:
964 kd_mksound(0x637, HZ/8);
965 continue;
966 case 8:
967 bs(currcons);
968 continue;
969 case 9:
970 pos -= (x << 1);
971 while (x < video_num_columns - 1) {
972 x++;
973 if (tab_stop[x >> 5] & (1 << (x & 31)))
974 break;
975 }
976 pos += (x << 1);
977 continue;
978 case 10: case 11: case 12:
979 lf(currcons);
980 if (!is_kbd(lnm))
981 continue;
982 case 13:
983 cr(currcons);
984 continue;
985 case 14:
986 charset = 1;
987 translate = G1_charset;
988 continue;
989 case 15:
990 charset = 0;
991 translate = G0_charset;
992 continue;
993 case 24: case 26:
994 state = ESnormal;
995 continue;
996 case 27:
997 state = ESesc;
998 continue;
999 case 127:
1000 del(currcons);
1001 continue;
1002 case 128+27:
1003 state = ESsquare;
1004 continue;
1005 }
1006 switch(state) {
1007 case ESesc:
1008 state = ESnormal;
1009 switch (c) {
1010 case '[':
1011 state = ESsquare;
1012 continue;
1013 case 'E':
1014 cr(currcons);
1015 lf(currcons);
1016 continue;
1017 case 'M':
1018 ri(currcons);
1019 continue;
1020 case 'D':
1021 lf(currcons);
1022 continue;
1023 case 'H':
1024 tab_stop[x >> 5] |= (1 << (x & 31));
1025 continue;
1026 case 'Z':
1027 respond_ID(currcons,tty);
1028 continue;
1029 case '7':
1030 save_cur(currcons);
1031 continue;
1032 case '8':
1033 restore_cur(currcons);
1034 continue;
1035 case '(':
1036 state = ESsetG0;
1037 continue;
1038 case ')':
1039 state = ESsetG1;
1040 continue;
1041 case '#':
1042 state = EShash;
1043 continue;
1044 case 'c':
1045 reset_terminal(currcons,1);
1046 continue;
1047 case '>':
1048 clr_kbd(kbdapplic);
1049 continue;
1050 case '=':
1051 set_kbd(kbdapplic);
1052 continue;
1053 }
1054 continue;
1055 case ESsquare:
1056 for(npar = 0 ; npar < NPAR ; npar++)
1057 par[npar] = 0;
1058 npar = 0;
1059 state = ESgetpars;
1060 if (c == '[') {
1061 state=ESfunckey;
1062 continue;
1063 }
1064 ques = (c=='?');
1065 if (ques)
1066 continue;
1067 case ESgetpars:
1068 if (c==';' && npar<NPAR-1) {
1069 npar++;
1070 continue;
1071 } else if (c>='0' && c<='9') {
1072 par[npar] *= 10;
1073 par[npar] += c-'0';
1074 continue;
1075 } else state=ESgotpars;
1076 case ESgotpars:
1077 state = ESnormal;
1078 switch(c) {
1079 case 'h':
1080 set_mode(currcons,1);
1081 continue;
1082 case 'l':
1083 set_mode(currcons,0);
1084 continue;
1085 case 'n':
1086 if (!ques)
1087 if (par[0] == 5)
1088 status_report(currcons,tty);
1089 else if (par[0] == 6)
1090 cursor_report(currcons,tty);
1091 continue;
1092 }
1093 if (ques) {
1094 ques = 0;
1095 continue;
1096 }
1097 switch(c) {
1098 case 'G': case '`':
1099 if (par[0]) par[0]--;
1100 gotoxy(currcons,par[0],y);
1101 continue;
1102 case 'A':
1103 if (!par[0]) par[0]++;
1104 gotoxy(currcons,x,y-par[0]);
1105 continue;
1106 case 'B': case 'e':
1107 if (!par[0]) par[0]++;
1108 gotoxy(currcons,x,y+par[0]);
1109 continue;
1110 case 'C': case 'a':
1111 if (!par[0]) par[0]++;
1112 gotoxy(currcons,x+par[0],y);
1113 continue;
1114 case 'D':
1115 if (!par[0]) par[0]++;
1116 gotoxy(currcons,x-par[0],y);
1117 continue;
1118 case 'E':
1119 if (!par[0]) par[0]++;
1120 gotoxy(currcons,0,y+par[0]);
1121 continue;
1122 case 'F':
1123 if (!par[0]) par[0]++;
1124 gotoxy(currcons,0,y-par[0]);
1125 continue;
1126 case 'd':
1127 if (par[0]) par[0]--;
1128 gotoxy(currcons,x,par[0]);
1129 continue;
1130 case 'H': case 'f':
1131 if (par[0]) par[0]--;
1132 if (par[1]) par[1]--;
1133 gotoxy(currcons,par[1],par[0]);
1134 continue;
1135 case 'J':
1136 csi_J(currcons,par[0]);
1137 continue;
1138 case 'K':
1139 csi_K(currcons,par[0]);
1140 continue;
1141 case 'L':
1142 csi_L(currcons,par[0]);
1143 continue;
1144 case 'M':
1145 csi_M(currcons,par[0]);
1146 continue;
1147 case 'P':
1148 csi_P(currcons,par[0]);
1149 continue;
1150 case 'c':
1151 if (!par[0])
1152 respond_ID(currcons,tty);
1153 continue;
1154 case 'g':
1155 if (!par[0])
1156 tab_stop[x >> 5] &= ~(1 << (x & 31));
1157 else if (par[0] == 3) {
1158 tab_stop[0] =
1159 tab_stop[1] =
1160 tab_stop[2] =
1161 tab_stop[3] =
1162 tab_stop[4] = 0;
1163 }
1164 continue;
1165 case 'm':
1166 csi_m(currcons);
1167 continue;
1168 case 'r':
1169 if (!par[0])
1170 par[0]++;
1171 if (!par[1])
1172 par[1] = video_num_lines;
1173
1174 if (par[0] < par[1] &&
1175 par[1] <= video_num_lines) {
1176 top=par[0]-1;
1177 bottom=par[1];
1178 gotoxy(currcons,0,0);
1179 }
1180 continue;
1181 case 's':
1182 save_cur(currcons);
1183 continue;
1184 case 'u':
1185 restore_cur(currcons);
1186 continue;
1187 case '@':
1188 csi_at(currcons,par[0]);
1189 continue;
1190 case ']':
1191 setterm_command(currcons);
1192 continue;
1193 }
1194 continue;
1195 case ESfunckey:
1196 state = ESnormal;
1197 continue;
1198 case EShash:
1199 state = ESnormal;
1200 if (c == '8') {
1201
1202 video_erase_char =
1203 (video_erase_char & 0xff00) | 'E';
1204 csi_J(currcons, 2);
1205 video_erase_char =
1206 (video_erase_char & 0xff00) | ' ';
1207 }
1208 continue;
1209 case ESsetG0:
1210 if (c == '0')
1211 G0_charset = GRAF_TRANS;
1212 else if (c == 'B')
1213 G0_charset = NORM_TRANS;
1214 else if (c == 'U')
1215 G0_charset = NULL_TRANS;
1216 if (charset == 0)
1217 translate = G0_charset;
1218 state = ESnormal;
1219 continue;
1220 case ESsetG1:
1221 if (c == '0')
1222 G1_charset = GRAF_TRANS;
1223 else if (c == 'B')
1224 G1_charset = NORM_TRANS;
1225 else if (c == 'U')
1226 G1_charset = NULL_TRANS;
1227 if (charset == 1)
1228 translate = G1_charset;
1229 state = ESnormal;
1230 continue;
1231 default:
1232 state = ESnormal;
1233 }
1234 }
1235 if (vcmode == KD_GRAPHICS)
1236 return;
1237 set_cursor(currcons);
1238 }
1239
1240 void do_keyboard_interrupt(void)
1241 {
1242 TTY_READ_FLUSH(TTY_TABLE(0));
1243 timer_active &= ~(1<<BLANK_TIMER);
1244 if (vt_cons[fg_console].vc_mode == KD_GRAPHICS)
1245 return;
1246 if (console_blanked) {
1247 timer_table[BLANK_TIMER].expires = 0;
1248 timer_active |= 1<<BLANK_TIMER;
1249 } else if (blankinterval) {
1250 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1251 timer_active |= 1<<BLANK_TIMER;
1252 }
1253 }
1254
1255 void * memsetw(void * s,unsigned short c,int count)
1256 {
1257 __asm__("cld\n\t"
1258 "rep\n\t"
1259 "stosw"
1260 ::"a" (c),"D" (s),"c" (count)
1261 :"cx","di");
1262 return s;
1263 }
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275 long con_init(long kmem_start)
1276 {
1277 char *display_desc = "????";
1278 int currcons = 0;
1279 long base;
1280 int orig_x = ORIG_X;
1281 int orig_y = ORIG_Y;
1282 void console_print(const char * b);
1283
1284 vc_scrmembuf = (unsigned short *) kmem_start;
1285 video_num_columns = ORIG_VIDEO_COLS;
1286 video_size_row = video_num_columns * 2;
1287 video_num_lines = ORIG_VIDEO_LINES;
1288 video_page = ORIG_VIDEO_PAGE;
1289 screen_size = (video_num_lines * video_size_row);
1290 kmem_start += NR_CONSOLES * screen_size;
1291 timer_table[BLANK_TIMER].fn = blank_screen;
1292 timer_table[BLANK_TIMER].expires = 0;
1293 if (blankinterval) {
1294 timer_table[BLANK_TIMER].expires = jiffies+blankinterval;
1295 timer_active |= 1<<BLANK_TIMER;
1296 }
1297
1298 if (ORIG_VIDEO_MODE == 7)
1299 {
1300 video_mem_base = 0xb0000;
1301 video_port_reg = 0x3b4;
1302 video_port_val = 0x3b5;
1303 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
1304 {
1305 video_type = VIDEO_TYPE_EGAM;
1306 video_mem_term = 0xb8000;
1307 display_desc = "EGA+";
1308 }
1309 else
1310 {
1311 video_type = VIDEO_TYPE_MDA;
1312 video_mem_term = 0xb2000;
1313 display_desc = "*MDA";
1314 }
1315 }
1316 else
1317 {
1318 can_do_color = 1;
1319 video_mem_base = 0xb8000;
1320 video_port_reg = 0x3d4;
1321 video_port_val = 0x3d5;
1322 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
1323 {
1324 video_type = VIDEO_TYPE_EGAC;
1325 video_mem_term = 0xc0000;
1326 display_desc = "EGA+";
1327 }
1328 else
1329 {
1330 video_type = VIDEO_TYPE_CGA;
1331 video_mem_term = 0xba000;
1332 display_desc = "*CGA";
1333 }
1334 }
1335
1336
1337
1338 base = (long)vc_scrmembuf;
1339 for (currcons = 0; currcons<NR_CONSOLES; currcons++) {
1340 pos = origin = video_mem_start = base;
1341 scr_end = video_mem_end = (base += screen_size);
1342 vc_scrbuf[currcons] = (unsigned short *) origin;
1343 vcmode = KD_TEXT;
1344 vtmode.mode = VT_AUTO;
1345 vtmode.waitv = 0;
1346 vtmode.relsig = 0;
1347 vtmode.acqsig = 0;
1348 vtmode.frsig = 0;
1349 vtpid = -1;
1350 vtnewvt = -1;
1351 clr_kbd(kbdraw);
1352 def_color = 0x07;
1353 ulcolor = 0x0f;
1354 halfcolor = 0x08;
1355 reset_terminal(currcons, currcons);
1356 }
1357 currcons = fg_console = 0;
1358
1359 video_mem_start = video_mem_base;
1360 video_mem_end = video_mem_term;
1361 origin = video_mem_start;
1362 scr_end = video_mem_start + video_num_lines * video_size_row;
1363 gotoxy(currcons,0,0);
1364 save_cur(currcons);
1365 gotoxy(currcons,orig_x,orig_y);
1366 update_screen(fg_console);
1367 printable = 1;
1368 printk("Console: %s %s %dx%d, %d virtual consoles\n",
1369 can_do_color?"colour":"mono",
1370 display_desc,
1371 video_num_columns,video_num_lines,
1372 NR_CONSOLES);
1373 register_console(console_print);
1374 return kmem_start;
1375 }
1376
1377
1378
1379
1380
1381 void kbdsave(int new_console)
1382 {
1383 }
1384
1385 static void get_scrmem(int currcons)
1386 {
1387 memcpy((void *)vc_scrbuf[currcons],(void *)origin, screen_size);
1388 video_mem_start = (unsigned long)vc_scrbuf[currcons];
1389 origin = video_mem_start;
1390 scr_end = video_mem_end = video_mem_start+screen_size;
1391 pos = origin + y*video_size_row + (x<<1);
1392 }
1393
1394 static void set_scrmem(int currcons)
1395 {
1396 video_mem_start = video_mem_base;
1397 video_mem_end = video_mem_term;
1398 origin = video_mem_start;
1399 scr_end = video_mem_start + screen_size;
1400 pos = origin + y*video_size_row + (x<<1);
1401 memcpy((void *)video_mem_base, (void *)vc_scrbuf[fg_console], screen_size);
1402 }
1403
1404 void blank_screen(void)
1405 {
1406 if (console_blanked)
1407 return;
1408 timer_table[BLANK_TIMER].fn = unblank_screen;
1409 get_scrmem(fg_console);
1410 hide_cursor(fg_console);
1411 console_blanked = 1;
1412 memsetw((void *)video_mem_base, 0x0020, video_mem_term-video_mem_base );
1413 }
1414
1415 void unblank_screen(void)
1416 {
1417 if (!console_blanked)
1418 return;
1419 timer_table[BLANK_TIMER].fn = blank_screen;
1420 if (blankinterval) {
1421 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1422 timer_active |= 1<<BLANK_TIMER;
1423 }
1424 console_blanked = 0;
1425 set_scrmem(fg_console);
1426 set_origin(fg_console);
1427 set_cursor(fg_console);
1428 }
1429
1430 void update_screen(int new_console)
1431 {
1432 static int lock = 0;
1433
1434 if (new_console == fg_console || lock)
1435 return;
1436 lock = 1;
1437 kbdsave(new_console);
1438 get_scrmem(fg_console);
1439 fg_console = new_console;
1440 set_scrmem(fg_console);
1441 set_origin(fg_console);
1442 set_cursor(new_console);
1443 set_leds();
1444 lock = 0;
1445 }
1446
1447 int do_screendump(int arg)
1448 {
1449 char *sptr, *buf = (char *)arg;
1450 int currcons, l;
1451
1452 if (!suser())
1453 return -EPERM;
1454 l = verify_area(VERIFY_WRITE, buf,2+video_num_columns*video_num_lines);
1455 if (l)
1456 return l;
1457 currcons = get_fs_byte(buf+1);
1458 if ((currcons<0) || (currcons>=NR_CONSOLES))
1459 return -EIO;
1460 put_fs_byte((char)(video_num_lines),buf++);
1461 put_fs_byte((char)(video_num_columns),buf++);
1462 currcons = (currcons ? currcons-1 : fg_console);
1463 sptr = (char *) origin;
1464 for (l=video_num_lines*video_num_columns; l>0 ; l--, sptr++)
1465 put_fs_byte(*sptr++,buf++);
1466 return(0);
1467 }
1468
1469 void console_print(const char * b)
1470 {
1471 int currcons = fg_console;
1472 unsigned char c;
1473
1474 if (!printable || currcons<0 || currcons>=NR_CONSOLES)
1475 return;
1476 while ((c = *(b++)) != 0) {
1477 if (c == 10 || c == 13 || need_wrap) {
1478 if (c != 13)
1479 lf(currcons);
1480 cr(currcons);
1481 if (c == 10 || c == 13)
1482 continue;
1483 }
1484 *(unsigned short *) pos = (attr << 8) + c;
1485 if (x == video_num_columns - 1) {
1486 need_wrap = 1;
1487 continue;
1488 }
1489 x++;
1490 pos+=2;
1491 }
1492 set_cursor(currcons);
1493 if (vt_cons[fg_console].vc_mode == KD_GRAPHICS)
1494 return;
1495 timer_active &= ~(1<<BLANK_TIMER);
1496 if (console_blanked) {
1497 timer_table[BLANK_TIMER].expires = 0;
1498 timer_active |= 1<<BLANK_TIMER;
1499 } else if (blankinterval) {
1500 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1501 timer_active |= 1<<BLANK_TIMER;
1502 }
1503 }
1504
1505
1506
1507
1508
1509 int con_open(struct tty_struct *tty, struct file * filp)
1510 {
1511 tty->write = con_write;
1512 tty->ioctl = vt_ioctl;
1513 if (tty->line > NR_CONSOLES)
1514 return -ENODEV;
1515 return 0;
1516 }