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