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