This source file includes following definitions.
- memcpyw
- vc_cons_allocated
- vc_allocate
- vc_resize
- vc_disallocate
- gotoxy
- __set_origin
- scrollback
- scrollfront
- set_origin
- hide_cursor
- set_cursor
- scrup
- scrdown
- lf
- ri
- cr
- bs
- del
- csi_J
- csi_K
- csi_X
- update_attr
- default_attr
- csi_m
- respond_string
- cursor_report
- status_report
- respond_ID
- mouse_report
- mouse_reporting
- screenpos
- invert_screen
- complement_pos
- screen_word
- screen_pos
- getconsxy
- putconsxy
- 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_stop
- con_start
- con_write
- con_write_room
- con_chars_in_buffer
- poke_blanked_console
- console_print
- con_throttle
- con_unthrottle
- vc_init
- con_setsize
- con_init
- get_scrmem
- set_scrmem
- do_blank_screen
- do_unblank_screen
- blank_screen
- unblank_screen
- update_screen
- con_open
- set_get_font
- set_get_cmap
- con_set_cmap
- con_get_cmap
- reset_palette
- set_palette
- con_set_font
- con_get_font
- con_adjust_height
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 #define BLANK 0x0020
82 #define CAN_LOAD_EGA_FONTS
83 #define CAN_LOAD_PALETTE
84
85
86
87
88
89
90 #define CTRL_ACTION 0x0d00ff81
91 #define CTRL_ALWAYS 0x0800f501
92
93
94
95
96
97
98
99
100 #include <linux/sched.h>
101 #include <linux/timer.h>
102 #include <linux/interrupt.h>
103 #include <linux/tty.h>
104 #include <linux/tty_flip.h>
105 #include <linux/config.h>
106 #include <linux/kernel.h>
107 #include <linux/string.h>
108 #include <linux/errno.h>
109 #include <linux/kd.h>
110 #include <linux/malloc.h>
111 #include <linux/major.h>
112 #include <linux/mm.h>
113 #include <linux/ioport.h>
114
115 #include <asm/io.h>
116 #include <asm/system.h>
117 #include <asm/segment.h>
118 #include <asm/bitops.h>
119
120 #include "kbd_kern.h"
121 #include "vt_kern.h"
122 #include "consolemap.h"
123 #include "selection.h"
124
125
126 #ifndef MIN
127 #define MIN(a,b) ((a) < (b) ? (a) : (b))
128 #endif
129
130 struct tty_driver console_driver;
131 static int console_refcount;
132 static struct tty_struct *console_table[MAX_NR_CONSOLES];
133 static struct termios *console_termios[MAX_NR_CONSOLES];
134 static struct termios *console_termios_locked[MAX_NR_CONSOLES];
135
136 #define NPAR 16
137
138 static void con_setsize(unsigned long rows, unsigned long cols);
139 static void vc_init(unsigned int console, unsigned long rows,
140 unsigned long cols, int do_clear);
141 static void get_scrmem(int currcons);
142 static void set_scrmem(int currcons, long offset);
143 static void set_origin(int currcons);
144 static void blank_screen(void);
145 static void unblank_screen(void);
146 void poke_blanked_console(void);
147 static void gotoxy(int currcons, int new_x, int new_y);
148 static void save_cur(int currcons);
149 static inline void set_cursor(int currcons);
150 static void reset_terminal(int currcons, int do_clear);
151 extern void reset_vc(unsigned int new_console);
152 extern void vt_init(void);
153 extern void register_console(void (*proc)(const char *));
154 extern void vesa_blank(void);
155 extern void vesa_unblank(void);
156 extern void compute_shiftstate(void);
157 extern void reset_palette (int currcons) ;
158 extern void set_palette (void) ;
159
160
161 static unsigned char video_type;
162 static unsigned long video_mem_base;
163 static unsigned long video_mem_term;
164 static unsigned char video_page;
165
166 unsigned short video_port_reg;
167 unsigned short video_port_val;
168
169 unsigned long video_num_columns;
170 unsigned long video_num_lines;
171 unsigned long video_size_row;
172 static unsigned long video_screen_size;
173 static int can_do_color = 0;
174 static int printable = 0;
175
176 int video_mode_512ch = 0;
177 unsigned long video_font_height;
178 unsigned long video_scan_lines;
179 static unsigned short console_charmask = 0x0ff;
180
181 static unsigned short *vc_scrbuf[MAX_NR_CONSOLES];
182
183 static int console_blanked = 0;
184 static int blankinterval = 10*60*HZ;
185 static long blank_origin, blank__origin, unblank_origin;
186
187
188 struct vc_data {
189 unsigned long vc_screenbuf_size;
190 unsigned short vc_video_erase_char;
191 unsigned char vc_attr;
192 unsigned char vc_def_color;
193 unsigned char vc_color;
194 unsigned char vc_s_color;
195 unsigned char vc_ulcolor;
196 unsigned char vc_halfcolor;
197 unsigned long vc_origin;
198 unsigned long vc_scr_end;
199 unsigned long vc_pos;
200 unsigned long vc_x,vc_y;
201 unsigned long vc_top,vc_bottom;
202 unsigned long vc_state;
203 unsigned long vc_npar,vc_par[NPAR];
204 unsigned long vc_video_mem_start;
205 unsigned long vc_video_mem_end;
206 unsigned long vc_saved_x;
207 unsigned long vc_saved_y;
208
209 unsigned long vc_charset : 1;
210 unsigned long vc_s_charset : 1;
211 unsigned long vc_disp_ctrl : 1;
212 unsigned long vc_toggle_meta : 1;
213 unsigned long vc_decscnm : 1;
214 unsigned long vc_decom : 1;
215 unsigned long vc_decawm : 1;
216 unsigned long vc_deccm : 1;
217 unsigned long vc_decim : 1;
218 unsigned long vc_deccolm : 1;
219
220 unsigned long vc_intensity : 2;
221 unsigned long vc_underline : 1;
222 unsigned long vc_blink : 1;
223 unsigned long vc_reverse : 1;
224 unsigned long vc_s_intensity : 2;
225 unsigned long vc_s_underline : 1;
226 unsigned long vc_s_blink : 1;
227 unsigned long vc_s_reverse : 1;
228
229 unsigned long vc_ques : 1;
230 unsigned long vc_need_wrap : 1;
231 unsigned long vc_has_scrolled : 1;
232 unsigned long vc_kmalloced : 1;
233 unsigned long vc_report_mouse : 2;
234 unsigned char vc_utf : 1;
235 unsigned char vc_utf_count;
236 long vc_utf_char;
237 unsigned long vc_tab_stop[5];
238 unsigned char vc_palette[16*3];
239 unsigned short * vc_translate;
240 unsigned char vc_G0_charset;
241 unsigned char vc_G1_charset;
242 unsigned char vc_saved_G0;
243 unsigned char vc_saved_G1;
244
245 };
246
247 static struct vc {
248 struct vc_data *d;
249
250
251
252
253 } vc_cons [MAX_NR_CONSOLES];
254
255 #define screenbuf_size (vc_cons[currcons].d->vc_screenbuf_size)
256 #define origin (vc_cons[currcons].d->vc_origin)
257 #define scr_end (vc_cons[currcons].d->vc_scr_end)
258 #define pos (vc_cons[currcons].d->vc_pos)
259 #define top (vc_cons[currcons].d->vc_top)
260 #define bottom (vc_cons[currcons].d->vc_bottom)
261 #define x (vc_cons[currcons].d->vc_x)
262 #define y (vc_cons[currcons].d->vc_y)
263 #define vc_state (vc_cons[currcons].d->vc_state)
264 #define npar (vc_cons[currcons].d->vc_npar)
265 #define par (vc_cons[currcons].d->vc_par)
266 #define ques (vc_cons[currcons].d->vc_ques)
267 #define attr (vc_cons[currcons].d->vc_attr)
268 #define saved_x (vc_cons[currcons].d->vc_saved_x)
269 #define saved_y (vc_cons[currcons].d->vc_saved_y)
270 #define translate (vc_cons[currcons].d->vc_translate)
271 #define G0_charset (vc_cons[currcons].d->vc_G0_charset)
272 #define G1_charset (vc_cons[currcons].d->vc_G1_charset)
273 #define saved_G0 (vc_cons[currcons].d->vc_saved_G0)
274 #define saved_G1 (vc_cons[currcons].d->vc_saved_G1)
275 #define utf (vc_cons[currcons].d->vc_utf)
276 #define utf_count (vc_cons[currcons].d->vc_utf_count)
277 #define utf_char (vc_cons[currcons].d->vc_utf_char)
278 #define video_mem_start (vc_cons[currcons].d->vc_video_mem_start)
279 #define video_mem_end (vc_cons[currcons].d->vc_video_mem_end)
280 #define video_erase_char (vc_cons[currcons].d->vc_video_erase_char)
281 #define disp_ctrl (vc_cons[currcons].d->vc_disp_ctrl)
282 #define toggle_meta (vc_cons[currcons].d->vc_toggle_meta)
283 #define decscnm (vc_cons[currcons].d->vc_decscnm)
284 #define decom (vc_cons[currcons].d->vc_decom)
285 #define decawm (vc_cons[currcons].d->vc_decawm)
286 #define deccm (vc_cons[currcons].d->vc_deccm)
287 #define decim (vc_cons[currcons].d->vc_decim)
288 #define deccolm (vc_cons[currcons].d->vc_deccolm)
289 #define need_wrap (vc_cons[currcons].d->vc_need_wrap)
290 #define has_scrolled (vc_cons[currcons].d->vc_has_scrolled)
291 #define kmalloced (vc_cons[currcons].d->vc_kmalloced)
292 #define report_mouse (vc_cons[currcons].d->vc_report_mouse)
293 #define color (vc_cons[currcons].d->vc_color)
294 #define s_color (vc_cons[currcons].d->vc_s_color)
295 #define def_color (vc_cons[currcons].d->vc_def_color)
296 #define foreground (color & 0x0f)
297 #define background (color & 0xf0)
298 #define charset (vc_cons[currcons].d->vc_charset)
299 #define s_charset (vc_cons[currcons].d->vc_s_charset)
300 #define intensity (vc_cons[currcons].d->vc_intensity)
301 #define underline (vc_cons[currcons].d->vc_underline)
302 #define blink (vc_cons[currcons].d->vc_blink)
303 #define reverse (vc_cons[currcons].d->vc_reverse)
304 #define s_intensity (vc_cons[currcons].d->vc_s_intensity)
305 #define s_underline (vc_cons[currcons].d->vc_s_underline)
306 #define s_blink (vc_cons[currcons].d->vc_s_blink)
307 #define s_reverse (vc_cons[currcons].d->vc_s_reverse)
308 #define ulcolor (vc_cons[currcons].d->vc_ulcolor)
309 #define halfcolor (vc_cons[currcons].d->vc_halfcolor)
310 #define tab_stop (vc_cons[currcons].d->vc_tab_stop)
311 #define palette (vc_cons[currcons].d->vc_palette)
312
313 #define vcmode (vt_cons[currcons]->vc_mode)
314 #define structsize (sizeof(struct vc_data) + sizeof(struct vt_struct))
315
316 static void memsetw(void * s, unsigned short c, unsigned int count)
317 {
318 unsigned short * addr = (unsigned short *) s;
319
320 count /= 2;
321 while (count) {
322 count--;
323 scr_writew(c, addr++);
324 }
325 }
326
327 static inline void memcpyw(unsigned short *to, unsigned short *from,
328 unsigned int count)
329 {
330 count /= 2;
331 while (count) {
332 count--;
333 scr_writew(scr_readw(from++), to++);
334 }
335 }
336
337 int vc_cons_allocated(unsigned int i)
338 {
339 return (i < MAX_NR_CONSOLES && vc_cons[i].d);
340 }
341
342 int vc_allocate(unsigned int i)
343 {
344 if (i >= MAX_NR_CONSOLES)
345 return -ENODEV;
346 if (!vc_cons[i].d) {
347 long p, q;
348
349
350 if (i >= MAX_NR_USER_CONSOLES && !suser())
351 return -EPERM;
352
353
354
355
356 q = (long) kmalloc(video_screen_size, GFP_KERNEL);
357 if (!q)
358 return -ENOMEM;
359 p = (long) kmalloc(structsize, GFP_KERNEL);
360 if (!p) {
361 kfree_s((char *) q, video_screen_size);
362 return -ENOMEM;
363 }
364
365 vc_cons[i].d = (struct vc_data *) p;
366 p += sizeof(struct vc_data);
367 vt_cons[i] = (struct vt_struct *) p;
368 vc_scrbuf[i] = (unsigned short *) q;
369 vc_cons[i].d->vc_kmalloced = 1;
370 vc_cons[i].d->vc_screenbuf_size = video_screen_size;
371 vc_init (i, video_num_lines, video_num_columns, 1);
372 }
373 return 0;
374 }
375
376
377
378
379
380
381 int vc_resize(unsigned long lines, unsigned long cols)
382 {
383 unsigned long cc, ll, ss, sr;
384 unsigned long occ, oll, oss, osr;
385 unsigned short *p;
386 unsigned int currcons, i;
387 unsigned short *newscreens[MAX_NR_CONSOLES];
388 long ol, nl, rlth, rrem;
389
390 cc = (cols ? cols : video_num_columns);
391 ll = (lines ? lines : video_num_lines);
392 sr = cc << 1;
393 ss = sr * ll;
394
395 if (ss > video_mem_term - video_mem_base)
396 return -ENOMEM;
397
398
399
400
401
402
403
404 for (currcons = 0; currcons < MAX_NR_CONSOLES; currcons++) {
405 if (!vc_cons_allocated(currcons))
406 newscreens[currcons] = 0;
407 else {
408 p = (unsigned short *) kmalloc(ss, GFP_USER);
409 if (!p) {
410 for (i = 0; i< currcons; i++)
411 if (newscreens[i])
412 kfree_s(newscreens[i], ss);
413 return -ENOMEM;
414 }
415 newscreens[currcons] = p;
416 }
417 }
418
419 get_scrmem(fg_console);
420
421 oll = video_num_lines;
422 occ = video_num_columns;
423 osr = video_size_row;
424 oss = video_screen_size;
425
426 video_num_lines = ll;
427 video_num_columns = cc;
428 video_size_row = sr;
429 video_screen_size = ss;
430
431 for (currcons = 0; currcons < MAX_NR_CONSOLES; currcons++) {
432 if (!vc_cons_allocated(currcons))
433 continue;
434
435 rlth = MIN(osr, sr);
436 rrem = sr - rlth;
437 ol = origin;
438 nl = (long) newscreens[currcons];
439 if (ll < oll)
440 ol += (oll - ll) * osr;
441
442 while (ol < scr_end) {
443 memcpyw((unsigned short *) nl, (unsigned short *) ol, rlth);
444 if (rrem)
445 memsetw((void *)(nl + rlth), video_erase_char, rrem);
446 ol += osr;
447 nl += sr;
448 }
449
450 if (kmalloced)
451 kfree_s(vc_scrbuf[currcons], screenbuf_size);
452 vc_scrbuf[currcons] = newscreens[currcons];
453 kmalloced = 1;
454 screenbuf_size = ss;
455
456 origin = video_mem_start = (long) vc_scrbuf[currcons];
457 scr_end = video_mem_end = video_mem_start + ss;
458
459 if (scr_end > nl)
460 memsetw((void *) nl, video_erase_char, scr_end - nl);
461
462
463 top = 0;
464 bottom = video_num_lines;
465 gotoxy(currcons, x, y);
466 save_cur(currcons);
467 }
468
469 set_scrmem(fg_console, 0);
470 set_origin(fg_console);
471 set_cursor(fg_console);
472
473 return 0;
474 }
475
476 void vc_disallocate(unsigned int currcons)
477 {
478 if (vc_cons_allocated(currcons)) {
479 if (kmalloced)
480 kfree_s(vc_scrbuf[currcons], screenbuf_size);
481 if (currcons >= MIN_NR_CONSOLES)
482 kfree_s(vc_cons[currcons].d, structsize);
483 vc_cons[currcons].d = 0;
484 }
485 }
486
487
488 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x)
489 #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x)
490 #define is_kbd(x) vc_kbd_mode(kbd_table+currcons,x)
491
492 #define decarm VC_REPEAT
493 #define decckm VC_CKMODE
494 #define kbdapplic VC_APPLIC
495 #define lnm VC_CRLF
496
497
498
499
500 #define VT100ID "\033[?1;2c"
501 #define VT102ID "\033[?6c"
502
503 static unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
504 8,12,10,14, 9,13,11,15 };
505
506
507 static int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
508 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
509 static int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
510 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
511 static int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
512 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
513
514
515
516
517
518
519 static void gotoxy(int currcons, int new_x, int new_y)
520 {
521 int max_y;
522
523 if (new_x < 0)
524 x = 0;
525 else
526 if (new_x >= video_num_columns)
527 x = video_num_columns - 1;
528 else
529 x = new_x;
530 if (decom) {
531 new_y += top;
532 max_y = bottom;
533 } else
534 max_y = video_num_lines;
535 if (new_y < 0)
536 y = 0;
537 else
538 if (new_y >= max_y)
539 y = max_y - 1;
540 else
541 y = new_y;
542 pos = origin + y*video_size_row + (x<<1);
543 need_wrap = 0;
544 }
545
546
547
548
549 static unsigned short __real_origin;
550 static unsigned short __origin;
551 #define last_lpos (((video_mem_term-video_mem_base)/video_num_columns/2)-video_num_lines+1)
552 #define last_origin_rel ( last_lpos * video_num_columns )
553 #define last_origin ( video_mem_base + last_origin_rel * 2 )
554 static unsigned short __scrollback_mode;
555
556 static inline void __set_origin(unsigned short offset)
557 {
558 unsigned long flags;
559
560 clear_selection();
561
562 save_flags(flags); cli();
563 __origin = offset;
564 outb_p(12, video_port_reg);
565 outb_p(offset >> 8, video_port_val);
566 outb_p(13, video_port_reg);
567 outb_p(offset, video_port_val);
568 restore_flags(flags);
569 }
570
571 void scrollback(int lines)
572 {
573 if (!lines)
574 lines = video_num_lines/2;
575 lines *= video_num_columns;
576 lines = __origin - lines;
577 if (__scrollback_mode == 0) {
578 if (lines < 0)
579 lines = 0;
580 } else {
581 int s_top = __real_origin+video_num_lines*video_num_columns ;
582 if (lines < 0) {
583 int count ;
584 unsigned short * d = (unsigned short *) video_mem_base;
585 unsigned short * s = (unsigned short *) last_origin;
586
587 lines += last_origin_rel;
588
589
590 count = (video_num_lines-1)*video_num_columns;
591 while (count) {
592 count--;
593 scr_writew(scr_readw(d++),s++);
594 }
595 } else if (__origin > __real_origin && lines < s_top)
596 lines = s_top ;
597 }
598 __set_origin(lines);
599 }
600
601 void scrollfront(int lines)
602 {
603 if (!lines)
604 lines = video_num_lines/2;
605 lines *= video_num_columns;
606 if (__origin > __real_origin) {
607
608 lines += __origin;
609 if (lines >= last_origin_rel) {
610 lines -= last_origin_rel ;
611 if (lines > __real_origin)
612 lines = __real_origin;
613 }
614 } else {
615 lines += __origin;
616 if (lines > __real_origin)
617 lines = __real_origin;
618 }
619 __set_origin(lines);
620 }
621
622 static void set_origin(int currcons)
623 {
624 if (video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_VGAC
625 && video_type != VIDEO_TYPE_EGAM)
626 return;
627 if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS)
628 return;
629 __real_origin = (origin-video_mem_base) >> 1;
630 __set_origin(__real_origin);
631 }
632
633
634
635
636 static inline void hide_cursor(void)
637 {
638
639
640
641 outb_p(14, video_port_reg);
642 outb_p(0xff&((video_mem_term-video_mem_base)>>9), video_port_val);
643 outb_p(15, video_port_reg);
644 outb_p(0xff&((video_mem_term-video_mem_base)>>1), video_port_val);
645 }
646
647 static inline void set_cursor(int currcons)
648 {
649 unsigned long flags;
650
651 if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS)
652 return;
653 if (__real_origin != __origin)
654 __set_origin(__real_origin);
655 save_flags(flags); cli();
656 if (deccm) {
657 outb_p(14, video_port_reg);
658 outb_p(0xff&((pos-video_mem_base)>>9), video_port_val);
659 outb_p(15, video_port_reg);
660 outb_p(0xff&((pos-video_mem_base)>>1), video_port_val);
661 } else
662 hide_cursor();
663 restore_flags(flags);
664 }
665
666 static void scrup(int currcons, unsigned int t, unsigned int b)
667 {
668 int hardscroll = 1;
669
670 if (b > video_num_lines || t >= b)
671 return;
672 if (video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_VGAC
673 && video_type != VIDEO_TYPE_EGAM)
674 hardscroll = 0;
675 else if (t || b != video_num_lines)
676 hardscroll = 0;
677 if (hardscroll) {
678 origin += video_size_row;
679 pos += video_size_row;
680 scr_end += video_size_row;
681 if (origin >= last_origin) {
682 unsigned short * d = (unsigned short *) video_mem_start;
683 unsigned short * s = (unsigned short *) origin;
684 unsigned int count;
685
686 count = (video_num_lines-1)*video_num_columns;
687 while (count) {
688 count--;
689 scr_writew(scr_readw(s++),d++);
690 }
691 count = video_num_columns;
692 while (count) {
693 count--;
694 scr_writew(video_erase_char, d++);
695 }
696 scr_end -= origin-video_mem_start;
697 pos -= origin-video_mem_start;
698 origin = video_mem_start;
699 has_scrolled = 1;
700 if (currcons == fg_console)
701 __scrollback_mode = 1;
702 } else {
703 unsigned short * d;
704 unsigned int count;
705
706 d = (unsigned short *) (scr_end - video_size_row);
707 count = video_num_columns;
708 while (count) {
709 count--;
710 scr_writew(video_erase_char, d++);
711 }
712 if (scr_end > last_origin)
713 __scrollback_mode = 0;
714 }
715 set_origin(currcons);
716 } else {
717 unsigned short * d = (unsigned short *) (origin+video_size_row*t);
718 unsigned short * s = (unsigned short *) (origin+video_size_row*(t+1));
719 unsigned int count = (b-t-1) * video_num_columns;
720
721 while (count) {
722 count--;
723 scr_writew(scr_readw(s++), d++);
724 }
725 count = video_num_columns;
726 while (count) {
727 count--;
728 scr_writew(video_erase_char, d++);
729 }
730 }
731 }
732
733 static void scrdown(int currcons, unsigned int t, unsigned int b)
734 {
735 unsigned short *d, *s;
736 unsigned int count;
737
738 if (b > video_num_lines || t >= b)
739 return;
740 d = (unsigned short *) (origin+video_size_row*b);
741 s = (unsigned short *) (origin+video_size_row*(b-1));
742 count = (b-t-1)*video_num_columns;
743 while (count) {
744 count--;
745 scr_writew(scr_readw(--s), --d);
746 }
747 count = video_num_columns;
748 while (count) {
749 count--;
750 scr_writew(video_erase_char, --d);
751 }
752 has_scrolled = 1;
753 }
754
755 static void lf(int currcons)
756 {
757
758
759
760 if (y+1 == bottom)
761 scrup(currcons,top,bottom);
762 else if (y < video_num_lines-1) {
763 y++;
764 pos += video_size_row;
765 }
766 need_wrap = 0;
767 }
768
769 static void ri(int currcons)
770 {
771
772
773
774 if (y == top)
775 scrdown(currcons,top,bottom);
776 else if (y > 0) {
777 y--;
778 pos -= video_size_row;
779 }
780 need_wrap = 0;
781 }
782
783 static inline void cr(int currcons)
784 {
785 pos -= x<<1;
786 need_wrap = x = 0;
787 }
788
789 static inline void bs(int currcons)
790 {
791 if (x) {
792 pos -= 2;
793 x--;
794 need_wrap = 0;
795 }
796 }
797
798 static inline void del(int currcons)
799 {
800
801 }
802
803 static void csi_J(int currcons, int vpar)
804 {
805 unsigned long count;
806 unsigned short * start;
807
808 switch (vpar) {
809 case 0:
810 count = (scr_end-pos)>>1;
811 start = (unsigned short *) pos;
812 break;
813 case 1:
814 count = ((pos-origin)>>1)+1;
815 start = (unsigned short *) origin;
816 break;
817 case 2:
818 count = video_num_columns * video_num_lines;
819 start = (unsigned short *) origin;
820 break;
821 default:
822 return;
823 }
824 while (count) {
825 count--;
826 scr_writew(video_erase_char, start++);
827 }
828 need_wrap = 0;
829 }
830
831 static void csi_K(int currcons, int vpar)
832 {
833 unsigned long count;
834 unsigned short * start;
835
836 switch (vpar) {
837 case 0:
838 count = video_num_columns-x;
839 start = (unsigned short *) pos;
840 break;
841 case 1:
842 start = (unsigned short *) (pos - (x<<1));
843 count = x+1;
844 break;
845 case 2:
846 start = (unsigned short *) (pos - (x<<1));
847 count = video_num_columns;
848 break;
849 default:
850 return;
851 }
852 while (count) {
853 count--;
854 scr_writew(video_erase_char, start++);
855 }
856 need_wrap = 0;
857 }
858
859 static void csi_X(int currcons, int vpar)
860 {
861 unsigned long count;
862 unsigned short * start;
863
864 if (!vpar)
865 vpar++;
866
867 start = (unsigned short *) pos;
868 count = (vpar > video_num_columns-x) ? (video_num_columns-x) : vpar;
869
870 while (count) {
871 count--;
872 scr_writew(video_erase_char, start++);
873 }
874 need_wrap = 0;
875 }
876
877 static void update_attr(int currcons)
878 {
879 attr = color;
880 if (can_do_color) {
881 if (underline)
882 attr = (attr & 0xf0) | ulcolor;
883 else if (intensity == 0)
884 attr = (attr & 0xf0) | halfcolor;
885 }
886 if (reverse ^ decscnm)
887 attr = reverse_video_char(attr);
888 if (blink)
889 attr ^= 0x80;
890 if (intensity == 2)
891 attr ^= 0x08;
892 if (!can_do_color) {
893 if (underline)
894 attr = (attr & 0xf8) | 0x01;
895 else if (intensity == 0)
896 attr = (attr & 0xf0) | 0x08;
897 }
898 if (decscnm)
899 video_erase_char = (reverse_video_char(color) << 8) | ' ';
900 else
901 video_erase_char = (color << 8) | ' ';
902 }
903
904 static void default_attr(int currcons)
905 {
906 intensity = 1;
907 underline = 0;
908 reverse = 0;
909 blink = 0;
910 color = def_color;
911 }
912
913 static void csi_m(int currcons)
914 {
915 int i;
916
917 for (i=0;i<=npar;i++)
918 switch (par[i]) {
919 case 0:
920 default_attr(currcons);
921 break;
922 case 1:
923 intensity = 2;
924 break;
925 case 2:
926 intensity = 0;
927 break;
928 case 4:
929 underline = 1;
930 break;
931 case 5:
932 blink = 1;
933 break;
934 case 7:
935 reverse = 1;
936 break;
937 case 10:
938
939
940
941
942 translate = set_translate(charset == 0
943 ? G0_charset
944 : G1_charset);
945 disp_ctrl = 0;
946 toggle_meta = 0;
947 break;
948 case 11:
949
950
951
952 translate = set_translate(IBMPC_MAP);
953 disp_ctrl = 1;
954 toggle_meta = 0;
955 break;
956 case 12:
957
958
959
960 translate = set_translate(IBMPC_MAP);
961 disp_ctrl = 1;
962 toggle_meta = 1;
963 break;
964 case 21:
965 case 22:
966 intensity = 1;
967 break;
968 case 24:
969 underline = 0;
970 break;
971 case 25:
972 blink = 0;
973 break;
974 case 27:
975 reverse = 0;
976 break;
977 case 38:
978
979
980
981
982 color = (def_color & 0x0f) | background;
983 underline = 1;
984 break;
985 case 39:
986
987
988
989
990 color = (def_color & 0x0f) | background;
991 underline = 0;
992 break;
993 case 49:
994 color = (def_color & 0xf0) | foreground;
995 break;
996 default:
997 if (par[i] >= 30 && par[i] <= 37)
998 color = color_table[par[i]-30]
999 | background;
1000 else if (par[i] >= 40 && par[i] <= 47)
1001 color = (color_table[par[i]-40]<<4)
1002 | foreground;
1003 break;
1004 }
1005 update_attr(currcons);
1006 }
1007
1008 static void respond_string(const char * p, struct tty_struct * tty)
1009 {
1010 while (*p) {
1011 tty_insert_flip_char(tty, *p, 0);
1012 p++;
1013 }
1014 tty_schedule_flip(tty);
1015 }
1016
1017 static void cursor_report(int currcons, struct tty_struct * tty)
1018 {
1019 char buf[40];
1020
1021 sprintf(buf, "\033[%ld;%ldR", y + (decom ? top+1 : 1), x+1);
1022 respond_string(buf, tty);
1023 }
1024
1025 static inline void status_report(struct tty_struct * tty)
1026 {
1027 respond_string("\033[0n", tty);
1028 }
1029
1030 static inline void respond_ID(struct tty_struct * tty)
1031 {
1032 respond_string(VT102ID, tty);
1033 }
1034
1035 void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry)
1036 {
1037 char buf[8];
1038
1039 sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),
1040 (char)('!' + mry));
1041 respond_string(buf, tty);
1042 }
1043
1044
1045 int mouse_reporting(void)
1046 {
1047 int currcons = fg_console;
1048
1049 return report_mouse;
1050 }
1051
1052 static inline unsigned short *screenpos(int currcons, int offset, int viewed)
1053 {
1054 unsigned short *p = (unsigned short *)(origin + offset);
1055 if (viewed && currcons == fg_console)
1056 p -= (__real_origin - __origin);
1057 return p;
1058 }
1059
1060
1061 void invert_screen(int currcons, int offset, int count, int viewed)
1062 {
1063 unsigned short *p;
1064
1065 count /= 2;
1066 p = screenpos(currcons, offset, viewed);
1067 if (can_do_color)
1068 while (count--) {
1069 unsigned short old = scr_readw(p);
1070 scr_writew(reverse_video_short(old), p);
1071 p++;
1072 }
1073 else
1074 while (count--) {
1075 unsigned short old = scr_readw(p);
1076 scr_writew(old ^ (((old & 0x0700) == 0x0100)
1077 ? 0x7000 : 0x7700), p);
1078 p++;
1079 }
1080 }
1081
1082
1083 void complement_pos(int currcons, int offset)
1084 {
1085 static unsigned short *p = NULL;
1086 static unsigned short old = 0;
1087
1088 if (p)
1089 scr_writew(old, p);
1090 if (offset == -1)
1091 p = NULL;
1092 else {
1093 p = screenpos(currcons, offset, 1);
1094 old = scr_readw(p);
1095 scr_writew(old ^ 0x7700, p);
1096 }
1097 }
1098
1099
1100 unsigned short screen_word(int currcons, int offset, int viewed)
1101 {
1102 return scr_readw(screenpos(currcons, offset, viewed));
1103 }
1104
1105
1106 unsigned short *screen_pos(int currcons, int w_offset, int viewed)
1107 {
1108 return screenpos(currcons, 2 * w_offset, viewed);
1109 }
1110
1111 void getconsxy(int currcons, char *p)
1112 {
1113 p[0] = x;
1114 p[1] = y;
1115 }
1116
1117 void putconsxy(int currcons, char *p)
1118 {
1119 gotoxy(currcons, p[0], p[1]);
1120 set_cursor(currcons);
1121 }
1122
1123 static void set_mode(int currcons, int on_off)
1124 {
1125 int i;
1126
1127 for (i=0; i<=npar; i++)
1128 if (ques) switch(par[i]) {
1129 case 1:
1130 if (on_off)
1131 set_kbd(decckm);
1132 else
1133 clr_kbd(decckm);
1134 break;
1135 case 3:
1136 deccolm = on_off;
1137 #if 0
1138 (void) vc_resize(video_num_lines, deccolm ? 132 : 80);
1139
1140
1141 #endif
1142 break;
1143 case 5:
1144 if (decscnm != on_off) {
1145 decscnm = on_off;
1146 invert_screen(currcons, 0, video_screen_size, 0);
1147 update_attr(currcons);
1148 }
1149 break;
1150 case 6:
1151 decom = on_off;
1152 gotoxy(currcons,0,0);
1153 break;
1154 case 7:
1155 decawm = on_off;
1156 break;
1157 case 8:
1158 if (on_off)
1159 set_kbd(decarm);
1160 else
1161 clr_kbd(decarm);
1162 break;
1163 case 9:
1164 report_mouse = on_off ? 1 : 0;
1165 break;
1166 case 25:
1167 deccm = on_off;
1168 set_cursor(currcons);
1169 break;
1170 case 1000:
1171 report_mouse = on_off ? 2 : 0;
1172 break;
1173 } else switch(par[i]) {
1174 case 3:
1175 disp_ctrl = on_off;
1176 break;
1177 case 4:
1178 decim = on_off;
1179 break;
1180 case 20:
1181 if (on_off)
1182 set_kbd(lnm);
1183 else
1184 clr_kbd(lnm);
1185 break;
1186 }
1187 }
1188
1189 static void setterm_command(int currcons)
1190 {
1191 switch(par[0]) {
1192 case 1:
1193 if (can_do_color && par[1] < 16) {
1194 ulcolor = color_table[par[1]];
1195 if (underline)
1196 update_attr(currcons);
1197 }
1198 break;
1199 case 2:
1200 if (can_do_color && par[1] < 16) {
1201 halfcolor = color_table[par[1]];
1202 if (intensity == 0)
1203 update_attr(currcons);
1204 }
1205 break;
1206 case 8:
1207 def_color = attr;
1208 default_attr(currcons);
1209 update_attr(currcons);
1210 break;
1211 case 9:
1212 blankinterval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;
1213 poke_blanked_console();
1214 break;
1215 }
1216 }
1217
1218 static void insert_char(int currcons)
1219 {
1220 unsigned int i = x;
1221 unsigned short tmp, old = video_erase_char;
1222 unsigned short * p = (unsigned short *) pos;
1223
1224 while (i++ < video_num_columns) {
1225 tmp = scr_readw(p);
1226 scr_writew(old, p);
1227 old = tmp;
1228 p++;
1229 }
1230 need_wrap = 0;
1231 }
1232
1233 static void insert_line(int currcons)
1234 {
1235 scrdown(currcons,y,bottom);
1236 need_wrap = 0;
1237 }
1238
1239 static void delete_char(int currcons)
1240 {
1241 unsigned int i = x;
1242 unsigned short * p = (unsigned short *) pos;
1243
1244 while (++i < video_num_columns) {
1245 scr_writew(scr_readw(p+1), p);
1246 p++;
1247 }
1248 scr_writew(video_erase_char, p);
1249 need_wrap = 0;
1250 }
1251
1252 static void delete_line(int currcons)
1253 {
1254 scrup(currcons,y,bottom);
1255 need_wrap = 0;
1256 }
1257
1258 static void csi_at(int currcons, unsigned int nr)
1259 {
1260 if (nr > video_num_columns)
1261 nr = video_num_columns;
1262 else if (!nr)
1263 nr = 1;
1264 while (nr--)
1265 insert_char(currcons);
1266 }
1267
1268 static void csi_L(int currcons, unsigned int nr)
1269 {
1270 if (nr > video_num_lines)
1271 nr = video_num_lines;
1272 else if (!nr)
1273 nr = 1;
1274 while (nr--)
1275 insert_line(currcons);
1276 }
1277
1278 static void csi_P(int currcons, unsigned int nr)
1279 {
1280 if (nr > video_num_columns)
1281 nr = video_num_columns;
1282 else if (!nr)
1283 nr = 1;
1284 while (nr--)
1285 delete_char(currcons);
1286 }
1287
1288 static void csi_M(int currcons, unsigned int nr)
1289 {
1290 if (nr > video_num_lines)
1291 nr = video_num_lines;
1292 else if (!nr)
1293 nr=1;
1294 while (nr--)
1295 delete_line(currcons);
1296 }
1297
1298 static void save_cur(int currcons)
1299 {
1300 saved_x = x;
1301 saved_y = y;
1302 s_intensity = intensity;
1303 s_underline = underline;
1304 s_blink = blink;
1305 s_reverse = reverse;
1306 s_charset = charset;
1307 s_color = color;
1308 saved_G0 = G0_charset;
1309 saved_G1 = G1_charset;
1310 }
1311
1312 static void restore_cur(int currcons)
1313 {
1314 gotoxy(currcons,saved_x,saved_y);
1315 intensity = s_intensity;
1316 underline = s_underline;
1317 blink = s_blink;
1318 reverse = s_reverse;
1319 charset = s_charset;
1320 color = s_color;
1321 G0_charset = saved_G0;
1322 G1_charset = saved_G1;
1323 translate = set_translate(charset ? G1_charset : G0_charset);
1324 update_attr(currcons);
1325 need_wrap = 0;
1326 }
1327
1328 enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
1329 EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,
1330 ESpalette };
1331
1332 static void reset_terminal(int currcons, int do_clear)
1333 {
1334 top = 0;
1335 bottom = video_num_lines;
1336 vc_state = ESnormal;
1337 ques = 0;
1338 translate = set_translate(LAT1_MAP);
1339 G0_charset = LAT1_MAP;
1340 G1_charset = GRAF_MAP;
1341 charset = 0;
1342 need_wrap = 0;
1343 report_mouse = 0;
1344 utf = 0;
1345 utf_count = 0;
1346
1347 disp_ctrl = 0;
1348 toggle_meta = 0;
1349
1350 decscnm = 0;
1351 decom = 0;
1352 decawm = 1;
1353 deccm = 1;
1354 decim = 0;
1355
1356 set_kbd(decarm);
1357 clr_kbd(decckm);
1358 clr_kbd(kbdapplic);
1359 clr_kbd(lnm);
1360 kbd_table[currcons].lockstate = 0;
1361 kbd_table[currcons].ledmode = LED_SHOW_FLAGS;
1362 kbd_table[currcons].ledflagstate = kbd_table[currcons].default_ledflagstate;
1363 set_leds();
1364
1365 default_attr(currcons);
1366 update_attr(currcons);
1367
1368 tab_stop[0] = 0x01010100;
1369 tab_stop[1] =
1370 tab_stop[2] =
1371 tab_stop[3] =
1372 tab_stop[4] = 0x01010101;
1373
1374 gotoxy(currcons,0,0);
1375 save_cur(currcons);
1376 if (do_clear)
1377 csi_J(currcons,2);
1378 }
1379
1380
1381
1382
1383 static void con_stop(struct tty_struct *tty)
1384 {
1385 int console_num;
1386 if (!tty)
1387 return;
1388 console_num = MINOR(tty->device) - (tty->driver.minor_start);
1389 if (!vc_cons_allocated(console_num))
1390 return;
1391 set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
1392 set_leds();
1393 }
1394
1395
1396
1397
1398 static void con_start(struct tty_struct *tty)
1399 {
1400 int console_num;
1401 if (!tty)
1402 return;
1403 console_num = MINOR(tty->device) - (tty->driver.minor_start);
1404 if (!vc_cons_allocated(console_num))
1405 return;
1406 clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
1407 set_leds();
1408 }
1409
1410 static int con_write(struct tty_struct * tty, int from_user,
1411 const unsigned char *buf, int count)
1412 {
1413 int c, tc, ok, n = 0;
1414 unsigned int currcons;
1415 struct vt_struct *vt = (struct vt_struct *)tty->driver_data;
1416
1417 currcons = vt->vc_num;
1418 if (!vc_cons_allocated(currcons)) {
1419
1420 static int error = 0;
1421 if (!error) {
1422 error = 1;
1423 printk("con_write: tty %d not allocated\n", currcons+1);
1424 }
1425 return 0;
1426 }
1427
1428 if (currcons == sel_cons)
1429 clear_selection();
1430
1431 disable_bh(KEYBOARD_BH);
1432 while (!tty->stopped && count) {
1433 c = from_user ? get_user(buf) : *buf;
1434 buf++; n++; count--;
1435
1436 if (utf) {
1437
1438
1439 if(c > 0x7f) {
1440 if (utf_count > 0 && (c & 0xc0) == 0x80) {
1441 utf_char = (utf_char << 6) | (c & 0x3f);
1442 utf_count--;
1443 if (utf_count == 0)
1444 tc = c = utf_char;
1445 else continue;
1446 } else {
1447 if ((c & 0xe0) == 0xc0) {
1448 utf_count = 1;
1449 utf_char = (c & 0x1f);
1450 } else if ((c & 0xf0) == 0xe0) {
1451 utf_count = 2;
1452 utf_char = (c & 0x0f);
1453 } else if ((c & 0xf8) == 0xf0) {
1454 utf_count = 3;
1455 utf_char = (c & 0x07);
1456 } else if ((c & 0xfc) == 0xf8) {
1457 utf_count = 4;
1458 utf_char = (c & 0x03);
1459 } else if ((c & 0xfe) == 0xfc) {
1460 utf_count = 5;
1461 utf_char = (c & 0x01);
1462 } else
1463 utf_count = 0;
1464 continue;
1465 }
1466 } else {
1467 tc = c;
1468 utf_count = 0;
1469 }
1470 } else {
1471 tc = translate[toggle_meta ? (c|0x80) : c];
1472 }
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483 ok = (tc && (c >= 32 || (!utf && !(((disp_ctrl ? CTRL_ALWAYS
1484 : CTRL_ACTION) >> c) & 1))));
1485
1486 if (vc_state == ESnormal && ok) {
1487
1488 tc = conv_uni_to_pc(tc);
1489 if ( tc == -4 )
1490 {
1491
1492
1493 tc = conv_uni_to_pc(0xfffd);
1494 }
1495 else if ( tc == -3 )
1496 {
1497
1498 tc = c;
1499 }
1500 if (tc & ~console_charmask)
1501 continue;
1502
1503 if (need_wrap) {
1504 cr(currcons);
1505 lf(currcons);
1506 }
1507 if (decim)
1508 insert_char(currcons);
1509 scr_writew( video_mode_512ch ?
1510 ((attr & 0xf7) << 8) + ((tc & 0x100) << 3) +
1511 (tc & 0x0ff) : (attr << 8) + tc,
1512 (unsigned short *) pos);
1513 if (x == video_num_columns - 1)
1514 need_wrap = decawm;
1515 else {
1516 x++;
1517 pos+=2;
1518 }
1519 continue;
1520 }
1521
1522
1523
1524
1525
1526 switch (c) {
1527 case 7:
1528 kd_mksound(0x637, HZ/8);
1529 continue;
1530 case 8:
1531 bs(currcons);
1532 continue;
1533 case 9:
1534 pos -= (x << 1);
1535 while (x < video_num_columns - 1) {
1536 x++;
1537 if (tab_stop[x >> 5] & (1 << (x & 31)))
1538 break;
1539 }
1540 pos += (x << 1);
1541 continue;
1542 case 10: case 11: case 12:
1543 lf(currcons);
1544 if (!is_kbd(lnm))
1545 continue;
1546 case 13:
1547 cr(currcons);
1548 continue;
1549 case 14:
1550 charset = 1;
1551 translate = set_translate(G1_charset);
1552 disp_ctrl = 1;
1553 continue;
1554 case 15:
1555 charset = 0;
1556 translate = set_translate(G0_charset);
1557 disp_ctrl = 0;
1558 continue;
1559 case 24: case 26:
1560 vc_state = ESnormal;
1561 continue;
1562 case 27:
1563 vc_state = ESesc;
1564 continue;
1565 case 127:
1566 del(currcons);
1567 continue;
1568 case 128+27:
1569 vc_state = ESsquare;
1570 continue;
1571 }
1572 switch(vc_state) {
1573 case ESesc:
1574 vc_state = ESnormal;
1575 switch (c) {
1576 case '[':
1577 vc_state = ESsquare;
1578 continue;
1579 case ']':
1580 vc_state = ESnonstd;
1581 continue;
1582 case '%':
1583 vc_state = ESpercent;
1584 continue;
1585 case 'E':
1586 cr(currcons);
1587 lf(currcons);
1588 continue;
1589 case 'M':
1590 ri(currcons);
1591 continue;
1592 case 'D':
1593 lf(currcons);
1594 continue;
1595 case 'H':
1596 tab_stop[x >> 5] |= (1 << (x & 31));
1597 continue;
1598 case 'Z':
1599 respond_ID(tty);
1600 continue;
1601 case '7':
1602 save_cur(currcons);
1603 continue;
1604 case '8':
1605 restore_cur(currcons);
1606 continue;
1607 case '(':
1608 vc_state = ESsetG0;
1609 continue;
1610 case ')':
1611 vc_state = ESsetG1;
1612 continue;
1613 case '#':
1614 vc_state = EShash;
1615 continue;
1616 case 'c':
1617 reset_terminal(currcons,1);
1618 continue;
1619 case '>':
1620 clr_kbd(kbdapplic);
1621 continue;
1622 case '=':
1623 set_kbd(kbdapplic);
1624 continue;
1625 }
1626 continue;
1627 case ESnonstd:
1628 if (c=='P') {
1629 for (npar=0; npar<NPAR; npar++)
1630 par[npar] = 0 ;
1631 npar = 0 ;
1632 vc_state = ESpalette;
1633 continue;
1634 } else if (c=='R') {
1635 reset_palette (currcons);
1636 vc_state = ESnormal;
1637 } else
1638 vc_state = ESnormal;
1639 continue;
1640 case ESpalette:
1641 if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {
1642 par[npar++] = (c>'9' ? (c&0xDF)-'A'+10 : c-'0') ;
1643 if (npar==7) {
1644 int i = par[0]*3, j = 1;
1645 palette[i] = 16*par[j++];
1646 palette[i++] += par[j++];
1647 palette[i] = 16*par[j++];
1648 palette[i++] += par[j++];
1649 palette[i] = 16*par[j++];
1650 palette[i] += par[j];
1651 set_palette() ;
1652 vc_state = ESnormal;
1653 }
1654 } else
1655 vc_state = ESnormal;
1656 continue;
1657 case ESsquare:
1658 for(npar = 0 ; npar < NPAR ; npar++)
1659 par[npar] = 0;
1660 npar = 0;
1661 vc_state = ESgetpars;
1662 if (c == '[') {
1663 vc_state=ESfunckey;
1664 continue;
1665 }
1666 ques = (c=='?');
1667 if (ques)
1668 continue;
1669 case ESgetpars:
1670 if (c==';' && npar<NPAR-1) {
1671 npar++;
1672 continue;
1673 } else if (c>='0' && c<='9') {
1674 par[npar] *= 10;
1675 par[npar] += c-'0';
1676 continue;
1677 } else vc_state=ESgotpars;
1678 case ESgotpars:
1679 vc_state = ESnormal;
1680 switch(c) {
1681 case 'h':
1682 set_mode(currcons,1);
1683 continue;
1684 case 'l':
1685 set_mode(currcons,0);
1686 continue;
1687 case 'n':
1688 if (!ques)
1689 if (par[0] == 5)
1690 status_report(tty);
1691 else if (par[0] == 6)
1692 cursor_report(currcons,tty);
1693 continue;
1694 }
1695 if (ques) {
1696 ques = 0;
1697 continue;
1698 }
1699 switch(c) {
1700 case 'G': case '`':
1701 if (par[0]) par[0]--;
1702 gotoxy(currcons,par[0],y);
1703 continue;
1704 case 'A':
1705 if (!par[0]) par[0]++;
1706 gotoxy(currcons,x,y-par[0]);
1707 continue;
1708 case 'B': case 'e':
1709 if (!par[0]) par[0]++;
1710 gotoxy(currcons,x,y+par[0]);
1711 continue;
1712 case 'C': case 'a':
1713 if (!par[0]) par[0]++;
1714 gotoxy(currcons,x+par[0],y);
1715 continue;
1716 case 'D':
1717 if (!par[0]) par[0]++;
1718 gotoxy(currcons,x-par[0],y);
1719 continue;
1720 case 'E':
1721 if (!par[0]) par[0]++;
1722 gotoxy(currcons,0,y+par[0]);
1723 continue;
1724 case 'F':
1725 if (!par[0]) par[0]++;
1726 gotoxy(currcons,0,y-par[0]);
1727 continue;
1728 case 'd':
1729 if (par[0]) par[0]--;
1730 gotoxy(currcons,x,par[0]);
1731 continue;
1732 case 'H': case 'f':
1733 if (par[0]) par[0]--;
1734 if (par[1]) par[1]--;
1735 gotoxy(currcons,par[1],par[0]);
1736 continue;
1737 case 'J':
1738 csi_J(currcons,par[0]);
1739 continue;
1740 case 'K':
1741 csi_K(currcons,par[0]);
1742 continue;
1743 case 'L':
1744 csi_L(currcons,par[0]);
1745 continue;
1746 case 'M':
1747 csi_M(currcons,par[0]);
1748 continue;
1749 case 'P':
1750 csi_P(currcons,par[0]);
1751 continue;
1752 case 'c':
1753 if (!par[0])
1754 respond_ID(tty);
1755 continue;
1756 case 'g':
1757 if (!par[0])
1758 tab_stop[x >> 5] &= ~(1 << (x & 31));
1759 else if (par[0] == 3) {
1760 tab_stop[0] =
1761 tab_stop[1] =
1762 tab_stop[2] =
1763 tab_stop[3] =
1764 tab_stop[4] = 0;
1765 }
1766 continue;
1767 case 'm':
1768 csi_m(currcons);
1769 continue;
1770 case 'q':
1771
1772 if (par[0] < 4)
1773 setledstate(kbd_table + currcons,
1774 (par[0] < 3) ? par[0] : 4);
1775 continue;
1776 case 'r':
1777 if (!par[0])
1778 par[0]++;
1779 if (!par[1])
1780 par[1] = video_num_lines;
1781
1782 if (par[0] < par[1] &&
1783 par[1] <= video_num_lines) {
1784 top=par[0]-1;
1785 bottom=par[1];
1786 gotoxy(currcons,0,0);
1787 }
1788 continue;
1789 case 's':
1790 save_cur(currcons);
1791 continue;
1792 case 'u':
1793 restore_cur(currcons);
1794 continue;
1795 case 'X':
1796 csi_X(currcons, par[0]);
1797 continue;
1798 case '@':
1799 csi_at(currcons,par[0]);
1800 continue;
1801 case ']':
1802 setterm_command(currcons);
1803 continue;
1804 }
1805 continue;
1806 case ESpercent:
1807 vc_state = ESnormal;
1808 switch (c) {
1809 case '@':
1810 utf = 0;
1811 continue;
1812 case 'G':
1813 case '8':
1814 utf = 1;
1815 continue;
1816 }
1817 continue;
1818 case ESfunckey:
1819 vc_state = ESnormal;
1820 continue;
1821 case EShash:
1822 vc_state = ESnormal;
1823 if (c == '8') {
1824
1825 video_erase_char =
1826 (video_erase_char & 0xff00) | 'E';
1827 csi_J(currcons, 2);
1828 video_erase_char =
1829 (video_erase_char & 0xff00) | ' ';
1830 }
1831 continue;
1832 case ESsetG0:
1833 if (c == '0')
1834 G0_charset = GRAF_MAP;
1835 else if (c == 'B')
1836 G0_charset = LAT1_MAP;
1837 else if (c == 'U')
1838 G0_charset = IBMPC_MAP;
1839 else if (c == 'K')
1840 G0_charset = USER_MAP;
1841 if (charset == 0)
1842 translate = set_translate(G0_charset);
1843 vc_state = ESnormal;
1844 continue;
1845 case ESsetG1:
1846 if (c == '0')
1847 G1_charset = GRAF_MAP;
1848 else if (c == 'B')
1849 G1_charset = LAT1_MAP;
1850 else if (c == 'U')
1851 G1_charset = IBMPC_MAP;
1852 else if (c == 'K')
1853 G1_charset = USER_MAP;
1854 if (charset == 1)
1855 translate = set_translate(G1_charset);
1856 vc_state = ESnormal;
1857 continue;
1858 default:
1859 vc_state = ESnormal;
1860 }
1861 }
1862 if (vcmode != KD_GRAPHICS)
1863 set_cursor(currcons);
1864 enable_bh(KEYBOARD_BH);
1865 return n;
1866 }
1867
1868 static int con_write_room(struct tty_struct *tty)
1869 {
1870 if (tty->stopped)
1871 return 0;
1872 return 4096;
1873 }
1874
1875 static int con_chars_in_buffer(struct tty_struct *tty)
1876 {
1877 return 0;
1878 }
1879
1880 void poke_blanked_console(void)
1881 {
1882 timer_active &= ~(1<<BLANK_TIMER);
1883 if (vt_cons[fg_console]->vc_mode == KD_GRAPHICS)
1884 return;
1885 if (console_blanked) {
1886 timer_table[BLANK_TIMER].expires = 0;
1887 timer_active |= 1<<BLANK_TIMER;
1888 } else if (blankinterval) {
1889 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1890 timer_active |= 1<<BLANK_TIMER;
1891 }
1892 }
1893
1894 void console_print(const char * b)
1895 {
1896 int currcons = fg_console;
1897 unsigned char c;
1898 static int printing = 0;
1899
1900 if (!printable || printing)
1901 return;
1902 printing = 1;
1903
1904 if (!vc_cons_allocated(currcons)) {
1905
1906 printk("console_print: tty %d not allocated ??\n", currcons+1);
1907 return;
1908 }
1909
1910 while ((c = *(b++)) != 0) {
1911 if (c == 10 || c == 13 || need_wrap) {
1912 if (c != 13)
1913 lf(currcons);
1914 cr(currcons);
1915 if (c == 10 || c == 13)
1916 continue;
1917 }
1918 scr_writew((attr << 8) + c, (unsigned short *) pos);
1919 if (x == video_num_columns - 1) {
1920 need_wrap = 1;
1921 continue;
1922 }
1923 x++;
1924 pos+=2;
1925 }
1926 set_cursor(currcons);
1927 poke_blanked_console();
1928 printing = 0;
1929 }
1930
1931
1932
1933
1934
1935
1936 static void con_throttle(struct tty_struct *tty)
1937 {
1938 }
1939
1940 static void con_unthrottle(struct tty_struct *tty)
1941 {
1942 struct vt_struct *vt = (struct vt_struct *) tty->driver_data;
1943
1944 wake_up_interruptible(&vt->paste_wait);
1945 }
1946
1947 static void vc_init(unsigned int currcons, unsigned long rows, unsigned long cols, int do_clear)
1948 {
1949 long base = (long) vc_scrbuf[currcons];
1950 int j, k ;
1951
1952 video_num_columns = cols;
1953 video_num_lines = rows;
1954 video_size_row = cols<<1;
1955 video_screen_size = video_num_lines * video_size_row;
1956
1957 pos = origin = video_mem_start = base;
1958 scr_end = base + video_screen_size;
1959 video_mem_end = base + video_screen_size;
1960 reset_vc(currcons);
1961 for (j=k=0; j<16; j++) {
1962 vc_cons[currcons].d->vc_palette[k++] = default_red[j] ;
1963 vc_cons[currcons].d->vc_palette[k++] = default_grn[j] ;
1964 vc_cons[currcons].d->vc_palette[k++] = default_blu[j] ;
1965 }
1966 def_color = 0x07;
1967 ulcolor = 0x0f;
1968 halfcolor = 0x08;
1969 vt_cons[currcons]->paste_wait = 0;
1970 reset_terminal(currcons, do_clear);
1971 }
1972
1973 static void con_setsize(unsigned long rows, unsigned long cols)
1974 {
1975 video_num_lines = rows;
1976 video_num_columns = cols;
1977 video_size_row = 2 * cols;
1978 video_screen_size = video_num_lines * video_size_row;
1979 }
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991 long con_init(long kmem_start)
1992 {
1993 const char *display_desc = "????";
1994 int currcons = 0;
1995 int orig_x = ORIG_X;
1996 int orig_y = ORIG_Y;
1997
1998 memset(&console_driver, 0, sizeof(struct tty_driver));
1999 console_driver.magic = TTY_DRIVER_MAGIC;
2000 console_driver.name = "tty";
2001 console_driver.name_base = 1;
2002 console_driver.major = TTY_MAJOR;
2003 console_driver.minor_start = 1;
2004 console_driver.num = MAX_NR_CONSOLES;
2005 console_driver.type = TTY_DRIVER_TYPE_CONSOLE;
2006 console_driver.init_termios = tty_std_termios;
2007 console_driver.flags = TTY_DRIVER_REAL_RAW;
2008 console_driver.refcount = &console_refcount;
2009 console_driver.table = console_table;
2010 console_driver.termios = console_termios;
2011 console_driver.termios_locked = console_termios_locked;
2012
2013 console_driver.open = con_open;
2014 console_driver.write = con_write;
2015 console_driver.write_room = con_write_room;
2016 console_driver.chars_in_buffer = con_chars_in_buffer;
2017 console_driver.ioctl = vt_ioctl;
2018 console_driver.stop = con_stop;
2019 console_driver.start = con_start;
2020 console_driver.throttle = con_throttle;
2021 console_driver.unthrottle = con_unthrottle;
2022
2023 if (tty_register_driver(&console_driver))
2024 panic("Couldn't register console driver\n");
2025
2026 con_setsize(ORIG_VIDEO_LINES, ORIG_VIDEO_COLS);
2027 video_page = ORIG_VIDEO_PAGE;
2028 __scrollback_mode = 0 ;
2029
2030 timer_table[BLANK_TIMER].fn = blank_screen;
2031 timer_table[BLANK_TIMER].expires = 0;
2032 if (blankinterval) {
2033 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
2034 timer_active |= 1<<BLANK_TIMER;
2035 }
2036
2037 if (ORIG_VIDEO_MODE == 7)
2038 {
2039 video_mem_base = 0xb0000;
2040 video_port_reg = 0x3b4;
2041 video_port_val = 0x3b5;
2042 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
2043 {
2044 video_type = VIDEO_TYPE_EGAM;
2045 video_mem_term = 0xb8000;
2046 display_desc = "EGA+";
2047 request_region(0x3b0,16,"ega");
2048 }
2049 else
2050 {
2051 video_type = VIDEO_TYPE_MDA;
2052 video_mem_term = 0xb2000;
2053 display_desc = "*MDA";
2054 request_region(0x3b0,12,"mda");
2055 request_region(0x3bf, 1,"mda");
2056 }
2057 }
2058 else
2059 {
2060 can_do_color = 1;
2061 video_mem_base = 0xb8000;
2062 video_port_reg = 0x3d4;
2063 video_port_val = 0x3d5;
2064 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
2065 {
2066 int i ;
2067
2068 video_mem_term = 0xc0000;
2069
2070 if (!ORIG_VIDEO_ISVGA) {
2071 video_type = VIDEO_TYPE_EGAC;
2072 display_desc = "EGA";
2073 request_region(0x3c0,32,"ega");
2074 } else {
2075 video_type = VIDEO_TYPE_VGAC;
2076 display_desc = "VGA+";
2077 request_region(0x3c0,32,"vga+");
2078
2079 #ifdef VGA_CAN_DO_64KB
2080
2081
2082
2083
2084
2085
2086 video_mem_base = 0xa0000 ;
2087 video_mem_term = 0xb0000 ;
2088 outb_p (6, 0x3ce) ;
2089 outb_p (6, 0x3cf) ;
2090 #endif
2091
2092
2093
2094
2095 for (i=0; i<16; i++) {
2096 inb_p (0x3da) ;
2097 outb_p (i, 0x3c0) ;
2098 outb_p (i, 0x3c0) ;
2099 }
2100 outb_p (0x20, 0x3c0) ;
2101
2102
2103
2104
2105 for (i=0; i<16; i++) {
2106 outb_p (color_table[i], 0x3c8) ;
2107 outb_p (default_red[i], 0x3c9) ;
2108 outb_p (default_grn[i], 0x3c9) ;
2109 outb_p (default_blu[i], 0x3c9) ;
2110 }
2111 }
2112 }
2113 else
2114 {
2115 video_type = VIDEO_TYPE_CGA;
2116 video_mem_term = 0xba000;
2117 display_desc = "*CGA";
2118 request_region(0x3d4,2,"cga");
2119 }
2120 }
2121
2122
2123
2124
2125
2126 for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
2127 int j, k ;
2128
2129 vc_cons[currcons].d = (struct vc_data *) kmem_start;
2130 kmem_start += sizeof(struct vc_data);
2131 vt_cons[currcons] = (struct vt_struct *) kmem_start;
2132 kmem_start += sizeof(struct vt_struct);
2133 vc_scrbuf[currcons] = (unsigned short *) kmem_start;
2134 kmem_start += video_screen_size;
2135 kmalloced = 0;
2136 screenbuf_size = video_screen_size;
2137 vc_init(currcons, video_num_lines, video_num_columns, currcons);
2138 for (j=k=0; j<16; j++) {
2139 vc_cons[currcons].d->vc_palette[k++] = default_red[j] ;
2140 vc_cons[currcons].d->vc_palette[k++] = default_grn[j] ;
2141 vc_cons[currcons].d->vc_palette[k++] = default_blu[j] ;
2142 }
2143 }
2144
2145 currcons = fg_console = 0;
2146
2147 video_mem_start = video_mem_base;
2148 video_mem_end = video_mem_term;
2149 origin = video_mem_start;
2150 scr_end = video_mem_start + video_num_lines * video_size_row;
2151 gotoxy(currcons,orig_x,orig_y);
2152 set_origin(currcons);
2153 csi_J(currcons, 0);
2154
2155
2156
2157
2158
2159
2160 printable = 1;
2161 if ( video_type == VIDEO_TYPE_VGAC || video_type == VIDEO_TYPE_EGAC
2162 || video_type == VIDEO_TYPE_EGAM )
2163 {
2164 video_font_height = ORIG_VIDEO_POINTS;
2165
2166 video_scan_lines = video_font_height * video_num_lines;
2167 printk("Console: %ld point font, %ld scans\n",
2168 video_font_height, video_scan_lines);
2169 }
2170
2171 printk("Console: %s %s %ldx%ld, %d virtual console%s (max %d)\n",
2172 can_do_color ? "colour" : "mono",
2173 display_desc,
2174 video_num_columns,video_num_lines,
2175 MIN_NR_CONSOLES, (MIN_NR_CONSOLES == 1) ? "" : "s", MAX_NR_CONSOLES);
2176 register_console(console_print);
2177 return kmem_start;
2178 }
2179
2180 static void get_scrmem(int currcons)
2181 {
2182 memcpyw((unsigned short *)vc_scrbuf[currcons],
2183 (unsigned short *)origin, video_screen_size);
2184 __scrollback_mode = 0 ;
2185 origin = video_mem_start = (unsigned long)vc_scrbuf[currcons];
2186 scr_end = video_mem_end = video_mem_start + video_screen_size;
2187 pos = origin + y*video_size_row + (x<<1);
2188 }
2189
2190 static void set_scrmem(int currcons, long offset)
2191 {
2192 #ifdef CONFIG_HGA
2193
2194
2195
2196
2197
2198
2199
2200 if (video_type == VIDEO_TYPE_MDA)
2201 {
2202 if (vcmode == KD_TEXT)
2203 {
2204
2205 int i;
2206 static char herc_txt_tbl[12] = {
2207 0x61,0x50,0x52,0x0f,0x19,6,0x19,0x19,2,0x0d,0x0b,0x0c };
2208 outb_p(0, 0x3bf);
2209 outb_p(0, 0x3b8);
2210 for ( i = 0 ; i < 12 ; i++ )
2211 {
2212 outb_p(i, 0x3b4);
2213 outb_p(herc_txt_tbl[i], 0x3b5);
2214 }
2215 }
2216 #define HGA_BLINKER_ON 0x20
2217 #define HGA_SCREEN_ON 8
2218
2219 outb_p(HGA_BLINKER_ON | HGA_SCREEN_ON, 0x3b8);
2220 }
2221 #endif CONFIG_HGA
2222
2223 if (video_mem_term - video_mem_base < offset + video_screen_size)
2224 offset = 0;
2225 memcpyw((unsigned short *)(video_mem_base + offset),
2226 (unsigned short *) origin, video_screen_size);
2227 video_mem_start = video_mem_base;
2228 video_mem_end = video_mem_term;
2229 origin = video_mem_base + offset;
2230 scr_end = origin + video_screen_size;
2231 pos = origin + y*video_size_row + (x<<1);
2232 }
2233
2234 void do_blank_screen(int nopowersave)
2235 {
2236 int currcons;
2237
2238 if (console_blanked)
2239 return;
2240
2241 timer_active &= ~(1<<BLANK_TIMER);
2242 timer_table[BLANK_TIMER].fn = unblank_screen;
2243
2244
2245 currcons = fg_console;
2246 has_scrolled = 0;
2247 blank__origin = __origin;
2248 blank_origin = origin;
2249 set_origin(fg_console);
2250 get_scrmem(fg_console);
2251 unblank_origin = origin;
2252 memsetw((void *)blank_origin, BLANK,
2253 2*video_num_lines*video_num_columns);
2254 hide_cursor();
2255 console_blanked = fg_console + 1;
2256
2257 if(!nopowersave)
2258 vesa_blank();
2259 }
2260
2261 void do_unblank_screen(void)
2262 {
2263 int currcons;
2264 int resetorg;
2265 long offset;
2266
2267 if (!console_blanked)
2268 return;
2269 if (!vc_cons_allocated(fg_console)) {
2270
2271 printk("unblank_screen: tty %d not allocated ??\n", fg_console+1);
2272 return;
2273 }
2274 timer_table[BLANK_TIMER].fn = blank_screen;
2275 if (blankinterval) {
2276 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
2277 timer_active |= 1<<BLANK_TIMER;
2278 }
2279
2280 currcons = fg_console;
2281 offset = 0;
2282 resetorg = 0;
2283 if (console_blanked == fg_console + 1 && origin == unblank_origin
2284 && !has_scrolled) {
2285
2286 resetorg = 1;
2287 offset = (blank_origin - video_mem_base)
2288 - (unblank_origin - video_mem_start);
2289 }
2290
2291 console_blanked = 0;
2292 set_scrmem(fg_console, offset);
2293 set_origin(fg_console);
2294 set_cursor(fg_console);
2295 if (resetorg)
2296 __set_origin(blank__origin);
2297
2298 vesa_unblank();
2299 }
2300
2301
2302
2303
2304
2305 static void blank_screen(void)
2306 {
2307 do_blank_screen(0);
2308 }
2309
2310 static void unblank_screen(void)
2311 {
2312 do_unblank_screen();
2313 }
2314
2315 void update_screen(int new_console)
2316 {
2317 static int lock = 0;
2318
2319 if (new_console == fg_console || lock)
2320 return;
2321 if (!vc_cons_allocated(new_console)) {
2322
2323 printk("update_screen: tty %d not allocated ??\n", new_console+1);
2324 return;
2325 }
2326 lock = 1;
2327
2328 clear_selection();
2329
2330 if (!console_blanked)
2331 get_scrmem(fg_console);
2332 else
2333 console_blanked = -1;
2334 fg_console = new_console;
2335
2336 set_scrmem(fg_console, 0);
2337 set_origin(fg_console);
2338 set_cursor(fg_console);
2339 set_leds();
2340 compute_shiftstate();
2341 lock = 0;
2342 }
2343
2344
2345
2346
2347 int con_open(struct tty_struct *tty, struct file * filp)
2348 {
2349 unsigned int idx;
2350 int i;
2351
2352 idx = MINOR(tty->device) - tty->driver.minor_start;
2353
2354 i = vc_allocate(idx);
2355 if (i)
2356 return i;
2357
2358 vt_cons[idx]->vc_num = idx;
2359 tty->driver_data = vt_cons[idx];
2360
2361 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
2362 tty->winsize.ws_row = video_num_lines;
2363 tty->winsize.ws_col = video_num_columns;
2364 }
2365 return 0;
2366 }
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381 #define colourmap ((char *)0xa0000)
2382
2383
2384 #define blackwmap ((char *)0xa0000)
2385 #define cmapsz 8192
2386 #define attrib_port (0x3c0)
2387 #define seq_port_reg (0x3c4)
2388 #define seq_port_val (0x3c5)
2389 #define gr_port_reg (0x3ce)
2390 #define gr_port_val (0x3cf)
2391
2392 static int set_get_font(char * arg, int set, int ch512)
2393 {
2394 #ifdef CAN_LOAD_EGA_FONTS
2395 int i;
2396 char *charmap;
2397 int beg;
2398 unsigned short video_port_status = video_port_reg + 6;
2399
2400
2401
2402 if (video_type == VIDEO_TYPE_EGAC || video_type == VIDEO_TYPE_VGAC) {
2403 charmap = colourmap;
2404 beg = 0x0e;
2405 #ifdef VGA_CAN_DO_64KB
2406 if (video_type == VIDEO_TYPE_VGAC)
2407 beg = 0x06;
2408 #endif
2409 } else if (video_type == VIDEO_TYPE_EGAM) {
2410 charmap = blackwmap;
2411 beg = 0x0a;
2412 } else
2413 return -EINVAL;
2414
2415 i = verify_area(set ? VERIFY_READ : VERIFY_WRITE, (void *)arg,
2416 ch512 ? 2*cmapsz : cmapsz);
2417 if (i)
2418 return i;
2419
2420 cli();
2421 outb_p( 0x00, seq_port_reg );
2422 outb_p( 0x01, seq_port_val );
2423 outb_p( 0x02, seq_port_reg );
2424 outb_p( 0x04, seq_port_val );
2425 outb_p( 0x04, seq_port_reg );
2426 outb_p( 0x07, seq_port_val );
2427 outb_p( 0x00, seq_port_reg );
2428 outb_p( 0x03, seq_port_val );
2429
2430 outb_p( 0x04, gr_port_reg );
2431 outb_p( 0x02, gr_port_val );
2432 outb_p( 0x05, gr_port_reg );
2433 outb_p( 0x00, gr_port_val );
2434 outb_p( 0x06, gr_port_reg );
2435 outb_p( 0x00, gr_port_val );
2436 sti();
2437
2438 if (set)
2439 for (i=0; i<cmapsz ; i++)
2440 scr_writeb(get_user(arg + i), charmap + i);
2441 else
2442 for (i=0; i<cmapsz ; i++)
2443 put_user(scr_readb(charmap + i), arg + i);
2444
2445
2446
2447
2448
2449
2450 if (ch512)
2451 {
2452 charmap += 2*cmapsz;
2453 arg += cmapsz;
2454 if (set)
2455 for (i=0; i<cmapsz ; i++)
2456 *(charmap+i) = get_user(arg+i);
2457 else
2458 for (i=0; i<cmapsz ; i++)
2459 put_user(*(charmap+i), arg+i);
2460 };
2461
2462 cli();
2463 outb_p( 0x00, seq_port_reg );
2464 outb_p( 0x01, seq_port_val );
2465 outb_p( 0x02, seq_port_reg );
2466 outb_p( 0x03, seq_port_val );
2467 outb_p( 0x04, seq_port_reg );
2468 outb_p( 0x03, seq_port_val );
2469 if (set)
2470 {
2471 outb_p( 0x03, seq_port_reg );
2472 outb_p( ch512 ? 0x04 : 0x00, seq_port_val );
2473 }
2474 outb_p( 0x00, seq_port_reg );
2475 outb_p( 0x03, seq_port_val );
2476
2477 outb_p( 0x04, gr_port_reg );
2478 outb_p( 0x00, gr_port_val );
2479 outb_p( 0x05, gr_port_reg );
2480 outb_p( 0x10, gr_port_val );
2481 outb_p( 0x06, gr_port_reg );
2482 outb_p( beg, gr_port_val );
2483 if (set)
2484 {
2485
2486
2487 inb_p( video_port_status );
2488 outb_p ( 0x12, attrib_port );
2489 outb_p ( ch512 ? 0x07 : 0x0f, attrib_port );
2490
2491
2492 inb_p( video_port_status );
2493 outb_p ( 0x20, attrib_port );
2494 }
2495 sti();
2496
2497 return 0;
2498 #else
2499 return -EINVAL;
2500 #endif
2501 }
2502
2503 #define dac_reg (0x3c8)
2504 #define dac_val (0x3c9)
2505
2506 static int set_get_cmap(unsigned char * arg, int set) {
2507 #ifdef CAN_LOAD_PALETTE
2508 int i;
2509
2510
2511
2512 if (video_type != VIDEO_TYPE_VGAC)
2513 return -EINVAL;
2514
2515 i = verify_area(set ? VERIFY_READ : VERIFY_WRITE, (void *)arg, 16*3);
2516 if (i)
2517 return i;
2518
2519 for (i=0; i<16; i++) {
2520 if (set) {
2521 default_red[i] = get_user(arg++) ;
2522 default_grn[i] = get_user(arg++) ;
2523 default_blu[i] = get_user(arg++) ;
2524 } else {
2525 put_user (default_red[i], arg++) ;
2526 put_user (default_grn[i], arg++) ;
2527 put_user (default_blu[i], arg++) ;
2528 }
2529 }
2530 if (set) {
2531 for (i=0; i<MAX_NR_CONSOLES; i++)
2532 if (vc_cons_allocated(i)) {
2533 int j, k ;
2534 for (j=k=0; j<16; j++) {
2535 vc_cons[i].d->vc_palette[k++] = default_red[j];
2536 vc_cons[i].d->vc_palette[k++] = default_grn[j];
2537 vc_cons[i].d->vc_palette[k++] = default_blu[j];
2538 }
2539 }
2540 set_palette() ;
2541 }
2542
2543 return 0;
2544 #else
2545 return -EINVAL;
2546 #endif
2547 }
2548
2549
2550
2551
2552
2553
2554 int con_set_cmap (unsigned char *arg)
2555 {
2556 return set_get_cmap (arg,1);
2557 }
2558
2559 int con_get_cmap (unsigned char *arg)
2560 {
2561 return set_get_cmap (arg,0);
2562 }
2563
2564 void reset_palette (int currcons)
2565 {
2566 int j, k ;
2567 for (j=k=0; j<16; j++) {
2568 palette[k++] = default_red[j];
2569 palette[k++] = default_grn[j];
2570 palette[k++] = default_blu[j];
2571 }
2572 set_palette() ;
2573 }
2574
2575 void set_palette (void)
2576 {
2577 int i, j ;
2578
2579 if (video_type != VIDEO_TYPE_VGAC || console_blanked ||
2580 vt_cons[fg_console]->vc_mode == KD_GRAPHICS)
2581 return ;
2582
2583 for (i=j=0; i<16; i++) {
2584 outb_p (color_table[i], dac_reg) ;
2585 outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ;
2586 outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ;
2587 outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ;
2588 }
2589 }
2590
2591
2592
2593
2594
2595
2596
2597 int con_set_font (char *arg, int ch512)
2598 {
2599 int i;
2600
2601 i = set_get_font (arg,1,ch512);
2602 if ( !i ) {
2603 hashtable_contents_valid = 0;
2604 video_mode_512ch = ch512;
2605 console_charmask = ch512 ? 0x1ff : 0x0ff;
2606 }
2607 return i;
2608 }
2609
2610 int con_get_font (char *arg)
2611 {
2612 return set_get_font (arg,0,video_mode_512ch);
2613 }
2614
2615
2616
2617
2618
2619
2620
2621 int con_adjust_height(unsigned long fontheight)
2622 {
2623 int rows, maxscan;
2624 unsigned char ovr, vde, fsr, curs, cure;
2625
2626 if (fontheight > 32 || (video_type != VIDEO_TYPE_VGAC &&
2627 video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_EGAM))
2628 return -EINVAL;
2629
2630 if ( fontheight == video_font_height || fontheight == 0 )
2631 return 0;
2632
2633 video_font_height = fontheight;
2634
2635 rows = video_scan_lines/fontheight;
2636 maxscan = rows*fontheight - 1;
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648 cli();
2649 outb_p( 0x07, video_port_reg );
2650 ovr = inb_p(video_port_val);
2651 outb_p( 0x09, video_port_reg );
2652 fsr = inb_p(video_port_val);
2653 outb_p( 0x0a, video_port_reg );
2654 curs = inb_p(video_port_val);
2655 outb_p( 0x0b, video_port_reg );
2656 cure = inb_p(video_port_val);
2657 sti();
2658
2659 vde = maxscan & 0xff;
2660 ovr = (ovr & 0xbd) +
2661 ((maxscan & 0x100) >> 7) +
2662 ((maxscan & 0x200) >> 3);
2663 fsr = (fsr & 0xe0) + (fontheight-1);
2664 curs = (curs & 0xc0) + fontheight - (fontheight < 10 ? 2 : 3);
2665 cure = (cure & 0xe0) + fontheight - (fontheight < 10 ? 1 : 2);
2666
2667 cli();
2668 outb_p( 0x07, video_port_reg );
2669 outb_p( ovr, video_port_val );
2670 outb_p( 0x09, video_port_reg );
2671 outb_p( fsr, video_port_val );
2672 outb_p( 0x0a, video_port_reg );
2673 outb_p( curs, video_port_val );
2674 outb_p( 0x0b, video_port_reg );
2675 outb_p( cure, video_port_val );
2676 outb_p( 0x12, video_port_reg );
2677 outb_p( vde, video_port_val );
2678 sti();
2679
2680 if ( rows == video_num_lines ) {
2681
2682
2683 return 0;
2684 }
2685
2686 vc_resize(rows, 0);
2687
2688 return rows;
2689 }