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 set_leds(void);
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
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_kbdapplic : 1;
92 unsigned long vc_charset : 1;
93 unsigned long vc_s_charset : 1;
94 unsigned long vc_decckm : 1;
95 unsigned long vc_decscnm : 1;
96 unsigned long vc_decom : 1;
97 unsigned long vc_decawm : 1;
98 unsigned long vc_decarm : 1;
99 unsigned long vc_deccm : 1;
100 unsigned long vc_decim : 1;
101 unsigned long vc_lnm : 1;
102
103 unsigned long vc_intensity : 2;
104 unsigned long vc_underline : 1;
105 unsigned long vc_blink : 1;
106 unsigned long vc_reverse : 1;
107 unsigned long vc_s_intensity : 2;
108 unsigned long vc_s_underline : 1;
109 unsigned long vc_s_blink : 1;
110 unsigned long vc_s_reverse : 1;
111
112 unsigned long vc_ques : 1;
113 unsigned long vc_need_wrap : 1;
114 unsigned long vc_tab_stop[5];
115 unsigned char vc_kbdmode;
116 char * vc_translate;
117 char * vc_G0_charset;
118 char * vc_G1_charset;
119 char * vc_saved_G0;
120 char * vc_saved_G1;
121
122 } vc_cons [NR_CONSOLES];
123
124 #define MEM_BUFFER_SIZE (2*80*50*8)
125
126 unsigned short *vc_scrbuf[NR_CONSOLES];
127 static unsigned short * vc_scrmembuf;
128 static int console_blanked = 0;
129
130 #define origin (vc_cons[currcons].vc_origin)
131 #define scr_end (vc_cons[currcons].vc_scr_end)
132 #define pos (vc_cons[currcons].vc_pos)
133 #define top (vc_cons[currcons].vc_top)
134 #define bottom (vc_cons[currcons].vc_bottom)
135 #define x (vc_cons[currcons].vc_x)
136 #define y (vc_cons[currcons].vc_y)
137 #define state (vc_cons[currcons].vc_state)
138 #define npar (vc_cons[currcons].vc_npar)
139 #define par (vc_cons[currcons].vc_par)
140 #define ques (vc_cons[currcons].vc_ques)
141 #define attr (vc_cons[currcons].vc_attr)
142 #define saved_x (vc_cons[currcons].vc_saved_x)
143 #define saved_y (vc_cons[currcons].vc_saved_y)
144 #define translate (vc_cons[currcons].vc_translate)
145 #define G0_charset (vc_cons[currcons].vc_G0_charset)
146 #define G1_charset (vc_cons[currcons].vc_G1_charset)
147 #define saved_G0 (vc_cons[currcons].vc_saved_G0)
148 #define saved_G1 (vc_cons[currcons].vc_saved_G1)
149 #define video_mem_start (vc_cons[currcons].vc_video_mem_start)
150 #define video_mem_end (vc_cons[currcons].vc_video_mem_end)
151 #define video_erase_char (vc_cons[currcons].vc_video_erase_char)
152 #define decscnm (vc_cons[currcons].vc_decscnm)
153 #define decom (vc_cons[currcons].vc_decom)
154 #define decawm (vc_cons[currcons].vc_decawm)
155 #define deccm (vc_cons[currcons].vc_deccm)
156 #define decim (vc_cons[currcons].vc_decim)
157 #define kbdapplic (vc_cons[currcons].vc_kbdapplic)
158 #define need_wrap (vc_cons[currcons].vc_need_wrap)
159 #define color (vc_cons[currcons].vc_color)
160 #define s_color (vc_cons[currcons].vc_s_color)
161 #define def_color (vc_cons[currcons].vc_def_color)
162 #define foreground (color & 0x0f)
163 #define background (color & 0xf0)
164 #define charset (vc_cons[currcons].vc_charset)
165 #define s_charset (vc_cons[currcons].vc_s_charset)
166 #define intensity (vc_cons[currcons].vc_intensity)
167 #define underline (vc_cons[currcons].vc_underline)
168 #define blink (vc_cons[currcons].vc_blink)
169 #define reverse (vc_cons[currcons].vc_reverse)
170 #define s_intensity (vc_cons[currcons].vc_s_intensity)
171 #define s_underline (vc_cons[currcons].vc_s_underline)
172 #define s_blink (vc_cons[currcons].vc_s_blink)
173 #define s_reverse (vc_cons[currcons].vc_s_reverse)
174 #define ulcolor (vc_cons[currcons].vc_ulcolor)
175 #define halfcolor (vc_cons[currcons].vc_halfcolor)
176 #define kbdmode (vc_cons[currcons].vc_kbdmode)
177 #define tab_stop (vc_cons[currcons].vc_tab_stop)
178 #define vtmode (vt_cons[currcons].vt_mode)
179
180 #define set_kbd(x) set_vc_kbd_flag(kbd_table+currcons,x)
181 #define clr_kbd(x) clr_vc_kbd_flag(kbd_table+currcons,x)
182 #define is_kbd(x) vc_kbd_flag(kbd_table+currcons,x)
183
184 #define decarm VC_REPEAT
185 #define decckm 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\016\017"
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 || vtmode == 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 #define is_kbd(x) vc_kbd_flag(kbd_table+currcons,x)
872 kbd_table[currcons].flags =
873 (kbd_table[currcons].flags & ~LED_MASK) |
874 (kbd_table[currcons].default_flags & LED_MASK);
875 kbdmode = 0;
876 set_leds();
877
878 default_attr(currcons);
879 update_attr(currcons);
880
881 tab_stop[0] = 0x01010100;
882 tab_stop[1] =
883 tab_stop[2] =
884 tab_stop[3] =
885 tab_stop[4] = 0x01010101;
886
887 if (do_clear) {
888 gotoxy(currcons,0,0);
889 csi_J(currcons,2);
890 save_cur(currcons);
891 }
892 }
893
894 void con_write(struct tty_struct * tty)
895 {
896 int c;
897 unsigned int currcons;
898
899 wake_up_interruptible(&tty->write_q.proc_list);
900 currcons = tty->line - 1;
901 if (currcons >= NR_CONSOLES) {
902 printk("con_write: illegal tty (%d)\n", currcons);
903 return;
904 }
905 while (!tty->stopped && (c = get_tty_queue(&tty->write_q)) >= 0) {
906 if (state == ESnormal && translate[c]) {
907 if (need_wrap) {
908 cr(currcons);
909 lf(currcons);
910 }
911 if (decim)
912 insert_char(currcons);
913 c = translate[c];
914 *(char *) pos = c;
915 *(char *) (pos+1) = attr;
916 if (x == video_num_columns - 1)
917 need_wrap = decawm;
918 else {
919 x++;
920 pos+=2;
921 }
922 continue;
923 }
924
925
926
927
928
929 switch (c) {
930 case 7:
931 sysbeep();
932 continue;
933 case 8:
934 bs(currcons);
935 continue;
936 case 9:
937 pos -= (x << 1);
938 while (x < video_num_columns - 1) {
939 x++;
940 if (tab_stop[x >> 5] & (1 << (x & 31)))
941 break;
942 }
943 pos += (x << 1);
944 continue;
945 case 10: case 11: case 12:
946 lf(currcons);
947 if (!is_kbd(lnm))
948 continue;
949 case 13:
950 cr(currcons);
951 continue;
952 case 14:
953 charset = 1;
954 translate = G1_charset;
955 continue;
956 case 15:
957 charset = 0;
958 translate = G0_charset;
959 continue;
960 case 24: case 26:
961 state = ESnormal;
962 continue;
963 case 27:
964 state = ESesc;
965 continue;
966 case 127:
967 del(currcons);
968 continue;
969 case 128+27:
970 state = ESsquare;
971 continue;
972 }
973 switch(state) {
974 case ESesc:
975 state = ESnormal;
976 switch (c) {
977 case '[':
978 state = ESsquare;
979 continue;
980 case 'E':
981 cr(currcons);
982 lf(currcons);
983 continue;
984 case 'M':
985 ri(currcons);
986 continue;
987 case 'D':
988 lf(currcons);
989 continue;
990 case 'H':
991 tab_stop[x >> 5] |= (1 << (x & 31));
992 continue;
993 case 'Z':
994 respond_ID(currcons,tty);
995 continue;
996 case '7':
997 save_cur(currcons);
998 continue;
999 case '8':
1000 restore_cur(currcons);
1001 continue;
1002 case '(':
1003 state = ESsetG0;
1004 continue;
1005 case ')':
1006 state = ESsetG1;
1007 continue;
1008 case '#':
1009 state = EShash;
1010 continue;
1011 case 'c':
1012 reset_terminal(currcons,1);
1013 continue;
1014 case '>':
1015 kbdapplic = 0;
1016 continue;
1017 case '=':
1018 kbdapplic = 1;
1019 continue;
1020 }
1021 continue;
1022 case ESsquare:
1023 for(npar = 0 ; npar < NPAR ; npar++)
1024 par[npar] = 0;
1025 npar = 0;
1026 state = ESgetpars;
1027 if (c == '[') {
1028 state=ESfunckey;
1029 continue;
1030 }
1031 ques = (c=='?');
1032 if (ques)
1033 continue;
1034 case ESgetpars:
1035 if (c==';' && npar<NPAR-1) {
1036 npar++;
1037 continue;
1038 } else if (c>='0' && c<='9') {
1039 par[npar] *= 10;
1040 par[npar] += c-'0';
1041 continue;
1042 } else state=ESgotpars;
1043 case ESgotpars:
1044 state = ESnormal;
1045 switch(c) {
1046 case 'h':
1047 set_mode(currcons,1);
1048 continue;
1049 case 'l':
1050 set_mode(currcons,0);
1051 continue;
1052 case 'n':
1053 if (!ques)
1054 if (par[0] == 5)
1055 status_report(currcons,tty);
1056 else if (par[0] == 6)
1057 cursor_report(currcons,tty);
1058 continue;
1059 }
1060 if (ques) {
1061 ques = 0;
1062 continue;
1063 }
1064 switch(c) {
1065 case 'G': case '`':
1066 if (par[0]) par[0]--;
1067 gotoxy(currcons,par[0],y);
1068 continue;
1069 case 'A':
1070 if (!par[0]) par[0]++;
1071 gotoxy(currcons,x,y-par[0]);
1072 continue;
1073 case 'B': case 'e':
1074 if (!par[0]) par[0]++;
1075 gotoxy(currcons,x,y+par[0]);
1076 continue;
1077 case 'C': case 'a':
1078 if (!par[0]) par[0]++;
1079 gotoxy(currcons,x+par[0],y);
1080 continue;
1081 case 'D':
1082 if (!par[0]) par[0]++;
1083 gotoxy(currcons,x-par[0],y);
1084 continue;
1085 case 'E':
1086 if (!par[0]) par[0]++;
1087 gotoxy(currcons,0,y+par[0]);
1088 continue;
1089 case 'F':
1090 if (!par[0]) par[0]++;
1091 gotoxy(currcons,0,y-par[0]);
1092 continue;
1093 case 'd':
1094 if (par[0]) par[0]--;
1095 gotoxy(currcons,x,par[0]);
1096 continue;
1097 case 'H': case 'f':
1098 if (par[0]) par[0]--;
1099 if (par[1]) par[1]--;
1100 gotoxy(currcons,par[1],par[0]);
1101 continue;
1102 case 'J':
1103 csi_J(currcons,par[0]);
1104 continue;
1105 case 'K':
1106 csi_K(currcons,par[0]);
1107 continue;
1108 case 'L':
1109 csi_L(currcons,par[0]);
1110 continue;
1111 case 'M':
1112 csi_M(currcons,par[0]);
1113 continue;
1114 case 'P':
1115 csi_P(currcons,par[0]);
1116 continue;
1117 case 'c':
1118 if (!par[0])
1119 respond_ID(currcons,tty);
1120 continue;
1121 case 'g':
1122 if (!par[0])
1123 tab_stop[x >> 5] &= ~(1 << (x & 31));
1124 else if (par[0] == 3) {
1125 tab_stop[0] =
1126 tab_stop[1] =
1127 tab_stop[2] =
1128 tab_stop[3] =
1129 tab_stop[4] = 0;
1130 }
1131 continue;
1132 case 'm':
1133 csi_m(currcons);
1134 continue;
1135 case 'r':
1136 if (!par[0])
1137 par[0]++;
1138 if (!par[1])
1139 par[1] = video_num_lines;
1140
1141 if (par[0] < par[1] &&
1142 par[1] <= video_num_lines) {
1143 top=par[0]-1;
1144 bottom=par[1];
1145 gotoxy(currcons,0,0);
1146 }
1147 continue;
1148 case 's':
1149 save_cur(currcons);
1150 continue;
1151 case 'u':
1152 restore_cur(currcons);
1153 continue;
1154 case '@':
1155 csi_at(currcons,par[0]);
1156 continue;
1157 case ']':
1158 setterm_command(currcons);
1159 continue;
1160 }
1161 continue;
1162 case ESfunckey:
1163 state = ESnormal;
1164 continue;
1165 case EShash:
1166 state = ESnormal;
1167 if (c == '8') {
1168
1169 video_erase_char =
1170 (video_erase_char & 0xff00) | 'E';
1171 csi_J(currcons, 2);
1172 video_erase_char =
1173 (video_erase_char & 0xff00) | ' ';
1174 }
1175 continue;
1176 case ESsetG0:
1177 if (c == '0')
1178 G0_charset = GRAF_TRANS;
1179 else if (c == 'B')
1180 G0_charset = NORM_TRANS;
1181 else if (c == 'U')
1182 G0_charset = NULL_TRANS;
1183 if (charset == 0)
1184 translate = G0_charset;
1185 state = ESnormal;
1186 continue;
1187 case ESsetG1:
1188 if (c == '0')
1189 G1_charset = GRAF_TRANS;
1190 else if (c == 'B')
1191 G1_charset = NORM_TRANS;
1192 else if (c == 'U')
1193 G1_charset = NULL_TRANS;
1194 if (charset == 1)
1195 translate = G1_charset;
1196 state = ESnormal;
1197 continue;
1198 default:
1199 state = ESnormal;
1200 }
1201 }
1202 if (vtmode == KD_GRAPHICS)
1203 return;
1204 set_cursor(currcons);
1205 }
1206
1207 void do_keyboard_interrupt(void)
1208 {
1209 TTY_READ_FLUSH(TTY_TABLE(0));
1210 timer_active &= ~(1<<BLANK_TIMER);
1211 if (vt_cons[fg_console].vt_mode == KD_GRAPHICS)
1212 return;
1213 if (console_blanked) {
1214 timer_table[BLANK_TIMER].expires = 0;
1215 timer_active |= 1<<BLANK_TIMER;
1216 } else if (blankinterval) {
1217 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1218 timer_active |= 1<<BLANK_TIMER;
1219 }
1220 }
1221
1222 void * memsetw(void * s,unsigned short c,int count)
1223 {
1224 __asm__("cld\n\t"
1225 "rep\n\t"
1226 "stosw"
1227 ::"a" (c),"D" (s),"c" (count)
1228 :"cx","di");
1229 return s;
1230 }
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242 long con_init(long kmem_start)
1243 {
1244 char *display_desc = "????";
1245 char *display_ptr;
1246 int currcons = 0;
1247 long base;
1248 int orig_x = ORIG_X;
1249 int orig_y = ORIG_Y;
1250
1251 vc_scrmembuf = (unsigned short *) kmem_start;
1252 video_num_columns = ORIG_VIDEO_COLS;
1253 video_size_row = video_num_columns * 2;
1254 video_num_lines = ORIG_VIDEO_LINES;
1255 video_page = ORIG_VIDEO_PAGE;
1256 screen_size = (video_num_lines * video_size_row);
1257 kmem_start += NR_CONSOLES * screen_size;
1258 timer_table[BLANK_TIMER].fn = blank_screen;
1259 timer_table[BLANK_TIMER].expires = 0;
1260 if (blankinterval) {
1261 timer_table[BLANK_TIMER].expires = jiffies+blankinterval;
1262 timer_active |= 1<<BLANK_TIMER;
1263 }
1264
1265 if (ORIG_VIDEO_MODE == 7)
1266 {
1267 video_mem_base = 0xb0000;
1268 video_port_reg = 0x3b4;
1269 video_port_val = 0x3b5;
1270 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
1271 {
1272 video_type = VIDEO_TYPE_EGAM;
1273 video_mem_term = 0xb8000;
1274 display_desc = "EGAm";
1275 }
1276 else
1277 {
1278 video_type = VIDEO_TYPE_MDA;
1279 video_mem_term = 0xb2000;
1280 display_desc = "*MDA";
1281 }
1282 }
1283 else
1284 {
1285 can_do_color = 1;
1286 video_mem_base = 0xb8000;
1287 video_port_reg = 0x3d4;
1288 video_port_val = 0x3d5;
1289 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
1290 {
1291 video_type = VIDEO_TYPE_EGAC;
1292 video_mem_term = 0xc0000;
1293 display_desc = "EGAc";
1294 }
1295 else
1296 {
1297 video_type = VIDEO_TYPE_CGA;
1298 video_mem_term = 0xba000;
1299 display_desc = "*CGA";
1300 }
1301 }
1302
1303
1304
1305 display_ptr = ((char *)video_mem_base) + video_size_row - 8;
1306 while (*display_desc)
1307 {
1308 *display_ptr++ = *display_desc++;
1309 display_ptr++;
1310 }
1311
1312
1313
1314 base = (long)vc_scrmembuf;
1315 for (currcons = 0; currcons<NR_CONSOLES; currcons++) {
1316 pos = origin = video_mem_start = base;
1317 scr_end = video_mem_end = (base += screen_size);
1318 vc_scrbuf[currcons] = (unsigned short *) origin;
1319 vtmode = KD_TEXT;
1320 clr_kbd(kbdraw);
1321 def_color = 0x07;
1322 ulcolor = 0x0f;
1323 halfcolor = 0x08;
1324 reset_terminal(currcons, currcons);
1325 }
1326 currcons = fg_console = 0;
1327
1328 video_mem_start = video_mem_base;
1329 video_mem_end = video_mem_term;
1330 origin = video_mem_start;
1331 scr_end = video_mem_start + video_num_lines * video_size_row;
1332 gotoxy(currcons,0,0);
1333 save_cur(currcons);
1334 gotoxy(currcons,orig_x,orig_y);
1335 update_screen(fg_console);
1336 return kmem_start;
1337 }
1338
1339
1340
1341
1342
1343 void kbdsave(int new_console)
1344 {
1345 }
1346
1347 static void get_scrmem(int currcons)
1348 {
1349 memcpy((void *)vc_scrbuf[fg_console],(void *)origin, screen_size);
1350 video_mem_start = (unsigned long)vc_scrbuf[fg_console];
1351 origin = video_mem_start;
1352 scr_end = video_mem_end = video_mem_start+screen_size;
1353 pos = origin + y*video_size_row + (x<<1);
1354 }
1355
1356 static void set_scrmem(int currcons)
1357 {
1358 video_mem_start = video_mem_base;
1359 video_mem_end = video_mem_term;
1360 origin = video_mem_start;
1361 scr_end = video_mem_start + screen_size;
1362 pos = origin + y*video_size_row + (x<<1);
1363 memcpy((void *)video_mem_base, (void *)vc_scrbuf[fg_console], screen_size);
1364 }
1365
1366 void blank_screen(void)
1367 {
1368 timer_table[BLANK_TIMER].fn = unblank_screen;
1369 get_scrmem(fg_console);
1370 hide_cursor(fg_console);
1371 console_blanked = 1;
1372 memsetw((void *)video_mem_base, 0x0020, video_mem_term-video_mem_base );
1373 }
1374
1375 void unblank_screen(void)
1376 {
1377 timer_table[BLANK_TIMER].fn = blank_screen;
1378 if (blankinterval) {
1379 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1380 timer_active |= 1<<BLANK_TIMER;
1381 }
1382 console_blanked = 0;
1383 set_scrmem(fg_console);
1384 set_origin(fg_console);
1385 set_cursor(fg_console);
1386 }
1387
1388 void update_screen(int new_console)
1389 {
1390 static int lock = 0;
1391
1392 if (new_console == fg_console || lock)
1393 return;
1394 lock = 1;
1395 kbdsave(new_console);
1396 get_scrmem(fg_console);
1397 fg_console = new_console;
1398 set_scrmem(fg_console);
1399 set_origin(fg_console);
1400 set_cursor(new_console);
1401 set_leds();
1402 lock = 0;
1403 }
1404
1405
1406
1407 static void sysbeepstop(void)
1408 {
1409
1410 outb(inb_p(0x61)&0xFC, 0x61);
1411 }
1412
1413 static void sysbeep(void)
1414 {
1415
1416 outb_p(inb_p(0x61)|3, 0x61);
1417
1418 outb_p(0xB6, 0x43);
1419
1420 outb_p(0x37, 0x42);
1421 outb(0x06, 0x42);
1422
1423 timer_table[BEEP_TIMER].expires = jiffies + HZ/8;
1424 timer_table[BEEP_TIMER].fn = sysbeepstop;
1425 timer_active |= 1<<BEEP_TIMER;
1426 }
1427
1428 int do_screendump(int arg)
1429 {
1430 char *sptr, *buf = (char *)arg;
1431 int currcons, l;
1432
1433 verify_area(buf,2+video_num_columns*video_num_lines);
1434 currcons = get_fs_byte(buf+1);
1435 if ((currcons<0) || (currcons>=NR_CONSOLES))
1436 return -EIO;
1437 put_fs_byte((char)(video_num_lines),buf++);
1438 put_fs_byte((char)(video_num_columns),buf++);
1439 currcons = (currcons ? currcons-1 : fg_console);
1440 sptr = (char *) origin;
1441 for (l=video_num_lines*video_num_columns; l>0 ; l--, sptr++)
1442 put_fs_byte(*sptr++,buf++);
1443 return(0);
1444 }
1445
1446 void console_print(const char * b)
1447 {
1448 int currcons = fg_console;
1449 char c;
1450
1451 if (currcons<0 || currcons>=NR_CONSOLES)
1452 currcons = 0;
1453 while ((c = *(b++)) != 0) {
1454 if (c == 10 || c == 13 || need_wrap) {
1455 if (c != 13)
1456 lf(currcons);
1457 cr(currcons);
1458 if (c == 10 || c == 13)
1459 continue;
1460 }
1461 *(char *) pos = c;
1462 *(char *) (pos+1) = attr;
1463 if (x == video_num_columns - 1) {
1464 need_wrap = 1;
1465 continue;
1466 }
1467 x++;
1468 pos+=2;
1469 }
1470 set_cursor(currcons);
1471 if (vt_cons[fg_console].vt_mode == KD_GRAPHICS)
1472 return;
1473 timer_active &= ~(1<<BLANK_TIMER);
1474 if (console_blanked) {
1475 timer_table[BLANK_TIMER].expires = 0;
1476 timer_active |= 1<<BLANK_TIMER;
1477 } else if (blankinterval) {
1478 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1479 timer_active |= 1<<BLANK_TIMER;
1480 }
1481 }
1482
1483
1484
1485
1486
1487 int con_open(struct tty_struct *tty, struct file * filp)
1488 {
1489 tty->write = con_write;
1490 tty->ioctl = vt_ioctl;
1491 return 0;
1492 }