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