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 int conv_uni_to_pc(long ucs);
158 extern void reset_palette (int currcons) ;
159 extern void set_palette (void) ;
160
161
162 static unsigned char video_type;
163 static unsigned long video_mem_base;
164 static unsigned long video_mem_term;
165 static unsigned char video_page;
166
167 unsigned short video_port_reg;
168 unsigned short video_port_val;
169
170 unsigned long video_num_columns;
171 unsigned long video_num_lines;
172 unsigned long video_size_row;
173 static unsigned long video_screen_size;
174 static int can_do_color = 0;
175 static int printable = 0;
176
177 int video_mode_512ch = 0;
178 unsigned long video_font_height;
179 unsigned long video_scan_lines;
180 static unsigned short console_charmask = 0x0ff;
181
182 static unsigned short *vc_scrbuf[MAX_NR_CONSOLES];
183
184 static int console_blanked = 0;
185 static int blankinterval = 10*60*HZ;
186 static long blank_origin, blank__origin, unblank_origin;
187
188
189 struct vc_data {
190 unsigned long vc_screenbuf_size;
191 unsigned short vc_video_erase_char;
192 unsigned char vc_attr;
193 unsigned char vc_def_color;
194 unsigned char vc_color;
195 unsigned char vc_s_color;
196 unsigned char vc_ulcolor;
197 unsigned char vc_halfcolor;
198 unsigned long vc_origin;
199 unsigned long vc_scr_end;
200 unsigned long vc_pos;
201 unsigned long vc_x,vc_y;
202 unsigned long vc_top,vc_bottom;
203 unsigned long vc_state;
204 unsigned long vc_npar,vc_par[NPAR];
205 unsigned long vc_video_mem_start;
206 unsigned long vc_video_mem_end;
207 unsigned long vc_saved_x;
208 unsigned long vc_saved_y;
209
210 unsigned long vc_charset : 1;
211 unsigned long vc_s_charset : 1;
212 unsigned long vc_disp_ctrl : 1;
213 unsigned long vc_toggle_meta : 1;
214 unsigned long vc_decscnm : 1;
215 unsigned long vc_decom : 1;
216 unsigned long vc_decawm : 1;
217 unsigned long vc_deccm : 1;
218 unsigned long vc_decim : 1;
219 unsigned long vc_deccolm : 1;
220
221 unsigned long vc_intensity : 2;
222 unsigned long vc_underline : 1;
223 unsigned long vc_blink : 1;
224 unsigned long vc_reverse : 1;
225 unsigned long vc_s_intensity : 2;
226 unsigned long vc_s_underline : 1;
227 unsigned long vc_s_blink : 1;
228 unsigned long vc_s_reverse : 1;
229
230 unsigned long vc_ques : 1;
231 unsigned long vc_need_wrap : 1;
232 unsigned long vc_has_scrolled : 1;
233 unsigned long vc_kmalloced : 1;
234 unsigned long vc_report_mouse : 2;
235 unsigned char vc_utf : 1;
236 unsigned char vc_utf_count;
237 long vc_utf_char;
238 unsigned long vc_tab_stop[5];
239 unsigned char vc_palette[16*3];
240 unsigned short * vc_translate;
241 unsigned char vc_G0_charset;
242 unsigned char vc_G1_charset;
243 unsigned char vc_saved_G0;
244 unsigned char vc_saved_G1;
245
246 };
247
248 static struct vc {
249 struct vc_data *d;
250
251
252
253
254 } vc_cons [MAX_NR_CONSOLES];
255
256 #define screenbuf_size (vc_cons[currcons].d->vc_screenbuf_size)
257 #define origin (vc_cons[currcons].d->vc_origin)
258 #define scr_end (vc_cons[currcons].d->vc_scr_end)
259 #define pos (vc_cons[currcons].d->vc_pos)
260 #define top (vc_cons[currcons].d->vc_top)
261 #define bottom (vc_cons[currcons].d->vc_bottom)
262 #define x (vc_cons[currcons].d->vc_x)
263 #define y (vc_cons[currcons].d->vc_y)
264 #define vc_state (vc_cons[currcons].d->vc_state)
265 #define npar (vc_cons[currcons].d->vc_npar)
266 #define par (vc_cons[currcons].d->vc_par)
267 #define ques (vc_cons[currcons].d->vc_ques)
268 #define attr (vc_cons[currcons].d->vc_attr)
269 #define saved_x (vc_cons[currcons].d->vc_saved_x)
270 #define saved_y (vc_cons[currcons].d->vc_saved_y)
271 #define translate (vc_cons[currcons].d->vc_translate)
272 #define G0_charset (vc_cons[currcons].d->vc_G0_charset)
273 #define G1_charset (vc_cons[currcons].d->vc_G1_charset)
274 #define saved_G0 (vc_cons[currcons].d->vc_saved_G0)
275 #define saved_G1 (vc_cons[currcons].d->vc_saved_G1)
276 #define utf (vc_cons[currcons].d->vc_utf)
277 #define utf_count (vc_cons[currcons].d->vc_utf_count)
278 #define utf_char (vc_cons[currcons].d->vc_utf_char)
279 #define video_mem_start (vc_cons[currcons].d->vc_video_mem_start)
280 #define video_mem_end (vc_cons[currcons].d->vc_video_mem_end)
281 #define video_erase_char (vc_cons[currcons].d->vc_video_erase_char)
282 #define disp_ctrl (vc_cons[currcons].d->vc_disp_ctrl)
283 #define toggle_meta (vc_cons[currcons].d->vc_toggle_meta)
284 #define decscnm (vc_cons[currcons].d->vc_decscnm)
285 #define decom (vc_cons[currcons].d->vc_decom)
286 #define decawm (vc_cons[currcons].d->vc_decawm)
287 #define deccm (vc_cons[currcons].d->vc_deccm)
288 #define decim (vc_cons[currcons].d->vc_decim)
289 #define deccolm (vc_cons[currcons].d->vc_deccolm)
290 #define need_wrap (vc_cons[currcons].d->vc_need_wrap)
291 #define has_scrolled (vc_cons[currcons].d->vc_has_scrolled)
292 #define kmalloced (vc_cons[currcons].d->vc_kmalloced)
293 #define report_mouse (vc_cons[currcons].d->vc_report_mouse)
294 #define color (vc_cons[currcons].d->vc_color)
295 #define s_color (vc_cons[currcons].d->vc_s_color)
296 #define def_color (vc_cons[currcons].d->vc_def_color)
297 #define foreground (color & 0x0f)
298 #define background (color & 0xf0)
299 #define charset (vc_cons[currcons].d->vc_charset)
300 #define s_charset (vc_cons[currcons].d->vc_s_charset)
301 #define intensity (vc_cons[currcons].d->vc_intensity)
302 #define underline (vc_cons[currcons].d->vc_underline)
303 #define blink (vc_cons[currcons].d->vc_blink)
304 #define reverse (vc_cons[currcons].d->vc_reverse)
305 #define s_intensity (vc_cons[currcons].d->vc_s_intensity)
306 #define s_underline (vc_cons[currcons].d->vc_s_underline)
307 #define s_blink (vc_cons[currcons].d->vc_s_blink)
308 #define s_reverse (vc_cons[currcons].d->vc_s_reverse)
309 #define ulcolor (vc_cons[currcons].d->vc_ulcolor)
310 #define halfcolor (vc_cons[currcons].d->vc_halfcolor)
311 #define tab_stop (vc_cons[currcons].d->vc_tab_stop)
312 #define palette (vc_cons[currcons].d->vc_palette)
313
314 #define vcmode (vt_cons[currcons]->vc_mode)
315 #define structsize (sizeof(struct vc_data) + sizeof(struct vt_struct))
316
317 static void memsetw(void * s, unsigned short c, unsigned int count)
318 {
319 unsigned short * addr = (unsigned short *) s;
320
321 count /= 2;
322 while (count) {
323 count--;
324 scr_writew(c, addr++);
325 }
326 }
327
328 static inline void memcpyw(unsigned short *to, unsigned short *from,
329 unsigned int count)
330 {
331 count /= 2;
332 while (count) {
333 count--;
334 scr_writew(scr_readw(from++), to++);
335 }
336 }
337
338 int vc_cons_allocated(unsigned int i)
339 {
340 return (i < MAX_NR_CONSOLES && vc_cons[i].d);
341 }
342
343 int vc_allocate(unsigned int i)
344 {
345 if (i >= MAX_NR_CONSOLES)
346 return -ENODEV;
347 if (!vc_cons[i].d) {
348 long p, q;
349
350
351 if (i >= MAX_NR_USER_CONSOLES && !suser())
352 return -EPERM;
353
354
355
356
357 q = (long) kmalloc(video_screen_size, GFP_KERNEL);
358 if (!q)
359 return -ENOMEM;
360 p = (long) kmalloc(structsize, GFP_KERNEL);
361 if (!p) {
362 kfree_s((char *) q, video_screen_size);
363 return -ENOMEM;
364 }
365
366 vc_cons[i].d = (struct vc_data *) p;
367 p += sizeof(struct vc_data);
368 vt_cons[i] = (struct vt_struct *) p;
369 vc_scrbuf[i] = (unsigned short *) q;
370 vc_cons[i].d->vc_kmalloced = 1;
371 vc_cons[i].d->vc_screenbuf_size = video_screen_size;
372 vc_init (i, video_num_lines, video_num_columns, 1);
373 }
374 return 0;
375 }
376
377
378
379
380
381
382 int vc_resize(unsigned long lines, unsigned long cols)
383 {
384 unsigned long cc, ll, ss, sr;
385 unsigned long occ, oll, oss, osr;
386 unsigned short *p;
387 unsigned int currcons, i;
388 unsigned short *newscreens[MAX_NR_CONSOLES];
389 long ol, nl, rlth, rrem;
390
391 cc = (cols ? cols : video_num_columns);
392 ll = (lines ? lines : video_num_lines);
393 sr = cc << 1;
394 ss = sr * ll;
395
396 if (ss > video_mem_term - video_mem_base)
397 return -ENOMEM;
398
399
400
401
402
403
404
405 for (currcons = 0; currcons < MAX_NR_CONSOLES; currcons++) {
406 if (!vc_cons_allocated(currcons))
407 newscreens[currcons] = 0;
408 else {
409 p = (unsigned short *) kmalloc(ss, GFP_USER);
410 if (!p) {
411 for (i = 0; i< currcons; i++)
412 if (newscreens[i])
413 kfree_s(newscreens[i], ss);
414 return -ENOMEM;
415 }
416 newscreens[currcons] = p;
417 }
418 }
419
420 get_scrmem(fg_console);
421
422 oll = video_num_lines;
423 occ = video_num_columns;
424 osr = video_size_row;
425 oss = video_screen_size;
426
427 video_num_lines = ll;
428 video_num_columns = cc;
429 video_size_row = sr;
430 video_screen_size = ss;
431
432 for (currcons = 0; currcons < MAX_NR_CONSOLES; currcons++) {
433 if (!vc_cons_allocated(currcons))
434 continue;
435
436 rlth = MIN(osr, sr);
437 rrem = sr - rlth;
438 ol = origin;
439 nl = (long) newscreens[currcons];
440 if (ll < oll)
441 ol += (oll - ll) * osr;
442
443 while (ol < scr_end) {
444 memcpyw((unsigned short *) nl, (unsigned short *) ol, rlth);
445 if (rrem)
446 memsetw((void *)(nl + rlth), video_erase_char, rrem);
447 ol += osr;
448 nl += sr;
449 }
450
451 if (kmalloced)
452 kfree_s(vc_scrbuf[currcons], screenbuf_size);
453 vc_scrbuf[currcons] = newscreens[currcons];
454 kmalloced = 1;
455 screenbuf_size = ss;
456
457 origin = video_mem_start = (long) vc_scrbuf[currcons];
458 scr_end = video_mem_end = video_mem_start + ss;
459
460 if (scr_end > nl)
461 memsetw((void *) nl, video_erase_char, scr_end - nl);
462
463
464 top = 0;
465 bottom = video_num_lines;
466 gotoxy(currcons, x, y);
467 save_cur(currcons);
468 }
469
470 set_scrmem(fg_console, 0);
471 set_origin(fg_console);
472 set_cursor(fg_console);
473
474 return 0;
475 }
476
477 void vc_disallocate(unsigned int currcons)
478 {
479 if (vc_cons_allocated(currcons)) {
480 if (kmalloced)
481 kfree_s(vc_scrbuf[currcons], screenbuf_size);
482 if (currcons >= MIN_NR_CONSOLES)
483 kfree_s(vc_cons[currcons].d, structsize);
484 vc_cons[currcons].d = 0;
485 }
486 }
487
488
489 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x)
490 #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x)
491 #define is_kbd(x) vc_kbd_mode(kbd_table+currcons,x)
492
493 #define decarm VC_REPEAT
494 #define decckm VC_CKMODE
495 #define kbdapplic VC_APPLIC
496 #define lnm VC_CRLF
497
498
499
500
501 #define VT100ID "\033[?1;2c"
502 #define VT102ID "\033[?6c"
503
504 static unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
505 8,12,10,14, 9,13,11,15 };
506
507
508 static int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
509 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
510 static int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
511 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
512 static int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
513 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
514
515
516
517
518
519
520 static void gotoxy(int currcons, int new_x, int new_y)
521 {
522 int max_y;
523
524 if (new_x < 0)
525 x = 0;
526 else
527 if (new_x >= video_num_columns)
528 x = video_num_columns - 1;
529 else
530 x = new_x;
531 if (decom) {
532 new_y += top;
533 max_y = bottom;
534 } else
535 max_y = video_num_lines;
536 if (new_y < 0)
537 y = 0;
538 else
539 if (new_y >= max_y)
540 y = max_y - 1;
541 else
542 y = new_y;
543 pos = origin + y*video_size_row + (x<<1);
544 need_wrap = 0;
545 }
546
547
548
549
550 static unsigned short __real_origin;
551 static unsigned short __origin;
552 #define last_lpos (((video_mem_term-video_mem_base)/video_num_columns/2)-video_num_lines+1)
553 #define last_origin_rel ( last_lpos * video_num_columns )
554 #define last_origin ( video_mem_base + last_origin_rel * 2 )
555 static unsigned short __scrollback_mode;
556
557 static inline void __set_origin(unsigned short offset)
558 {
559 unsigned long flags;
560
561 clear_selection();
562
563 save_flags(flags); cli();
564 __origin = offset;
565 outb_p(12, video_port_reg);
566 outb_p(offset >> 8, video_port_val);
567 outb_p(13, video_port_reg);
568 outb_p(offset, video_port_val);
569 restore_flags(flags);
570 }
571
572 void scrollback(int lines)
573 {
574 if (!lines)
575 lines = video_num_lines/2;
576 lines *= video_num_columns;
577 lines = __origin - lines;
578 if (__scrollback_mode == 0) {
579 if (lines < 0)
580 lines = 0;
581 } else {
582 int s_top = __real_origin+video_num_lines*video_num_columns ;
583 if (lines < 0) {
584 int count ;
585 unsigned short * d = (unsigned short *) video_mem_base;
586 unsigned short * s = (unsigned short *) last_origin;
587
588 lines += last_origin_rel;
589
590
591 count = (video_num_lines-1)*video_num_columns;
592 while (count) {
593 count--;
594 scr_writew(scr_readw(d++),s++);
595 }
596 } else if (__origin > __real_origin && lines < s_top)
597 lines = s_top ;
598 }
599 __set_origin(lines);
600 }
601
602 void scrollfront(int lines)
603 {
604 if (!lines)
605 lines = video_num_lines/2;
606 lines *= video_num_columns;
607 if (__origin > __real_origin) {
608
609 lines += __origin;
610 if (lines >= last_origin_rel) {
611 lines -= last_origin_rel ;
612 if (lines > __real_origin)
613 lines = __real_origin;
614 }
615 } else {
616 lines += __origin;
617 if (lines > __real_origin)
618 lines = __real_origin;
619 }
620 __set_origin(lines);
621 }
622
623 static void set_origin(int currcons)
624 {
625 if (video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_VGAC
626 && video_type != VIDEO_TYPE_EGAM)
627 return;
628 if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS)
629 return;
630 __real_origin = (origin-video_mem_base) >> 1;
631 __set_origin(__real_origin);
632 }
633
634
635
636
637 static inline void hide_cursor(void)
638 {
639
640
641
642 outb_p(14, video_port_reg);
643 outb_p(0xff&((video_mem_term-video_mem_base)>>9), video_port_val);
644 outb_p(15, video_port_reg);
645 outb_p(0xff&((video_mem_term-video_mem_base)>>1), video_port_val);
646 }
647
648 static inline void set_cursor(int currcons)
649 {
650 unsigned long flags;
651
652 if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS)
653 return;
654 if (__real_origin != __origin)
655 __set_origin(__real_origin);
656 save_flags(flags); cli();
657 if (deccm) {
658 outb_p(14, video_port_reg);
659 outb_p(0xff&((pos-video_mem_base)>>9), video_port_val);
660 outb_p(15, video_port_reg);
661 outb_p(0xff&((pos-video_mem_base)>>1), video_port_val);
662 } else
663 hide_cursor();
664 restore_flags(flags);
665 }
666
667 static void scrup(int currcons, unsigned int t, unsigned int b)
668 {
669 int hardscroll = 1;
670
671 if (b > video_num_lines || t >= b)
672 return;
673 if (video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_VGAC
674 && video_type != VIDEO_TYPE_EGAM)
675 hardscroll = 0;
676 else if (t || b != video_num_lines)
677 hardscroll = 0;
678 if (hardscroll) {
679 origin += video_size_row;
680 pos += video_size_row;
681 scr_end += video_size_row;
682 if (origin >= last_origin) {
683 unsigned short * d = (unsigned short *) video_mem_start;
684 unsigned short * s = (unsigned short *) origin;
685 unsigned int count;
686
687 count = (video_num_lines-1)*video_num_columns;
688 while (count) {
689 count--;
690 scr_writew(scr_readw(s++),d++);
691 }
692 count = video_num_columns;
693 while (count) {
694 count--;
695 scr_writew(video_erase_char, d++);
696 }
697 scr_end -= origin-video_mem_start;
698 pos -= origin-video_mem_start;
699 origin = video_mem_start;
700 has_scrolled = 1;
701 if (currcons == fg_console)
702 __scrollback_mode = 1;
703 } else {
704 unsigned short * d;
705 unsigned int count;
706
707 d = (unsigned short *) (scr_end - video_size_row);
708 count = video_num_columns;
709 while (count) {
710 count--;
711 scr_writew(video_erase_char, d++);
712 }
713 if (scr_end > last_origin)
714 __scrollback_mode = 0;
715 }
716 set_origin(currcons);
717 } else {
718 unsigned short * d = (unsigned short *) (origin+video_size_row*t);
719 unsigned short * s = (unsigned short *) (origin+video_size_row*(t+1));
720 unsigned int count = (b-t-1) * video_num_columns;
721
722 while (count) {
723 count--;
724 scr_writew(scr_readw(s++), d++);
725 }
726 count = video_num_columns;
727 while (count) {
728 count--;
729 scr_writew(video_erase_char, d++);
730 }
731 }
732 }
733
734 static void scrdown(int currcons, unsigned int t, unsigned int b)
735 {
736 unsigned short *d, *s;
737 unsigned int count;
738
739 if (b > video_num_lines || t >= b)
740 return;
741 d = (unsigned short *) (origin+video_size_row*b);
742 s = (unsigned short *) (origin+video_size_row*(b-1));
743 count = (b-t-1)*video_num_columns;
744 while (count) {
745 count--;
746 scr_writew(scr_readw(--s), --d);
747 }
748 count = video_num_columns;
749 while (count) {
750 count--;
751 scr_writew(video_erase_char, --d);
752 }
753 has_scrolled = 1;
754 }
755
756 static void lf(int currcons)
757 {
758
759
760
761 if (y+1 == bottom)
762 scrup(currcons,top,bottom);
763 else if (y < video_num_lines-1) {
764 y++;
765 pos += video_size_row;
766 }
767 need_wrap = 0;
768 }
769
770 static void ri(int currcons)
771 {
772
773
774
775 if (y == top)
776 scrdown(currcons,top,bottom);
777 else if (y > 0) {
778 y--;
779 pos -= video_size_row;
780 }
781 need_wrap = 0;
782 }
783
784 static inline void cr(int currcons)
785 {
786 pos -= x<<1;
787 need_wrap = x = 0;
788 }
789
790 static inline void bs(int currcons)
791 {
792 if (x) {
793 pos -= 2;
794 x--;
795 need_wrap = 0;
796 }
797 }
798
799 static inline void del(int currcons)
800 {
801
802 }
803
804 static void csi_J(int currcons, int vpar)
805 {
806 unsigned long count;
807 unsigned short * start;
808
809 switch (vpar) {
810 case 0:
811 count = (scr_end-pos)>>1;
812 start = (unsigned short *) pos;
813 break;
814 case 1:
815 count = ((pos-origin)>>1)+1;
816 start = (unsigned short *) origin;
817 break;
818 case 2:
819 count = video_num_columns * video_num_lines;
820 start = (unsigned short *) origin;
821 break;
822 default:
823 return;
824 }
825 while (count) {
826 count--;
827 scr_writew(video_erase_char, start++);
828 }
829 need_wrap = 0;
830 }
831
832 static void csi_K(int currcons, int vpar)
833 {
834 unsigned long count;
835 unsigned short * start;
836
837 switch (vpar) {
838 case 0:
839 count = video_num_columns-x;
840 start = (unsigned short *) pos;
841 break;
842 case 1:
843 start = (unsigned short *) (pos - (x<<1));
844 count = x+1;
845 break;
846 case 2:
847 start = (unsigned short *) (pos - (x<<1));
848 count = video_num_columns;
849 break;
850 default:
851 return;
852 }
853 while (count) {
854 count--;
855 scr_writew(video_erase_char, start++);
856 }
857 need_wrap = 0;
858 }
859
860 static void csi_X(int currcons, int vpar)
861 {
862 unsigned long count;
863 unsigned short * start;
864
865 if (!vpar)
866 vpar++;
867
868 start = (unsigned short *) pos;
869 count = (vpar > video_num_columns-x) ? (video_num_columns-x) : vpar;
870
871 while (count) {
872 count--;
873 scr_writew(video_erase_char, start++);
874 }
875 need_wrap = 0;
876 }
877
878 static void update_attr(int currcons)
879 {
880 attr = color;
881 if (can_do_color) {
882 if (underline)
883 attr = (attr & 0xf0) | ulcolor;
884 else if (intensity == 0)
885 attr = (attr & 0xf0) | halfcolor;
886 }
887 if (reverse ^ decscnm)
888 attr = reverse_video_char(attr);
889 if (blink)
890 attr ^= 0x80;
891 if (intensity == 2)
892 attr ^= 0x08;
893 if (!can_do_color) {
894 if (underline)
895 attr = (attr & 0xf8) | 0x01;
896 else if (intensity == 0)
897 attr = (attr & 0xf0) | 0x08;
898 }
899 if (decscnm)
900 video_erase_char = (reverse_video_char(color) << 8) | ' ';
901 else
902 video_erase_char = (color << 8) | ' ';
903 }
904
905 static void default_attr(int currcons)
906 {
907 intensity = 1;
908 underline = 0;
909 reverse = 0;
910 blink = 0;
911 color = def_color;
912 }
913
914 static void csi_m(int currcons)
915 {
916 int i;
917
918 for (i=0;i<=npar;i++)
919 switch (par[i]) {
920 case 0:
921 default_attr(currcons);
922 break;
923 case 1:
924 intensity = 2;
925 break;
926 case 2:
927 intensity = 0;
928 break;
929 case 4:
930 underline = 1;
931 break;
932 case 5:
933 blink = 1;
934 break;
935 case 7:
936 reverse = 1;
937 break;
938 case 10:
939
940
941
942
943 translate = set_translate(charset == 0
944 ? G0_charset
945 : G1_charset);
946 disp_ctrl = 0;
947 toggle_meta = 0;
948 break;
949 case 11:
950
951
952
953 translate = set_translate(IBMPC_MAP);
954 disp_ctrl = 1;
955 toggle_meta = 0;
956 break;
957 case 12:
958
959
960
961 translate = set_translate(IBMPC_MAP);
962 disp_ctrl = 1;
963 toggle_meta = 1;
964 break;
965 case 21:
966 case 22:
967 intensity = 1;
968 break;
969 case 24:
970 underline = 0;
971 break;
972 case 25:
973 blink = 0;
974 break;
975 case 27:
976 reverse = 0;
977 break;
978 case 38:
979
980
981
982
983 color = (def_color & 0x0f) | background;
984 underline = 1;
985 break;
986 case 39:
987
988
989
990
991 color = (def_color & 0x0f) | background;
992 underline = 0;
993 break;
994 case 49:
995 color = (def_color & 0xf0) | foreground;
996 break;
997 default:
998 if (par[i] >= 30 && par[i] <= 37)
999 color = color_table[par[i]-30]
1000 | background;
1001 else if (par[i] >= 40 && par[i] <= 47)
1002 color = (color_table[par[i]-40]<<4)
1003 | foreground;
1004 break;
1005 }
1006 update_attr(currcons);
1007 }
1008
1009 static void respond_string(char * p, struct tty_struct * tty)
1010 {
1011 while (*p) {
1012 tty_insert_flip_char(tty, *p, 0);
1013 p++;
1014 }
1015 tty_schedule_flip(tty);
1016 }
1017
1018 static void cursor_report(int currcons, struct tty_struct * tty)
1019 {
1020 char buf[40];
1021
1022 sprintf(buf, "\033[%ld;%ldR", y + (decom ? top+1 : 1), x+1);
1023 respond_string(buf, tty);
1024 }
1025
1026 static inline void status_report(struct tty_struct * tty)
1027 {
1028 respond_string("\033[0n", tty);
1029 }
1030
1031 static inline void respond_ID(struct tty_struct * tty)
1032 {
1033 respond_string(VT102ID, tty);
1034 }
1035
1036 void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry)
1037 {
1038 char buf[8];
1039
1040 sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),
1041 (char)('!' + mry));
1042 respond_string(buf, tty);
1043 }
1044
1045
1046 int mouse_reporting(void)
1047 {
1048 int currcons = fg_console;
1049
1050 return report_mouse;
1051 }
1052
1053 static inline unsigned short *screenpos(int currcons, int offset, int viewed)
1054 {
1055 unsigned short *p = (unsigned short *)(origin + offset);
1056 if (viewed && currcons == fg_console)
1057 p -= (__real_origin - __origin);
1058 return p;
1059 }
1060
1061
1062 void invert_screen(int currcons, int offset, int count, int viewed)
1063 {
1064 unsigned short *p;
1065
1066 count /= 2;
1067 p = screenpos(currcons, offset, viewed);
1068 if (can_do_color)
1069 while (count--) {
1070 unsigned short old = scr_readw(p);
1071 scr_writew(reverse_video_short(old), p);
1072 p++;
1073 }
1074 else
1075 while (count--) {
1076 unsigned short old = scr_readw(p);
1077 scr_writew(old ^ (((old & 0x0700) == 0x0100)
1078 ? 0x7000 : 0x7700), p);
1079 p++;
1080 }
1081 }
1082
1083
1084 void complement_pos(int currcons, int offset)
1085 {
1086 static unsigned short *p = NULL;
1087 static unsigned short old = 0;
1088
1089 if (p)
1090 scr_writew(old, p);
1091 if (offset == -1)
1092 p = NULL;
1093 else {
1094 p = screenpos(currcons, offset, 1);
1095 old = scr_readw(p);
1096 scr_writew(old ^ 0x7700, p);
1097 }
1098 }
1099
1100
1101 unsigned short screen_word(int currcons, int offset, int viewed)
1102 {
1103 return scr_readw(screenpos(currcons, offset, viewed));
1104 }
1105
1106
1107 unsigned short *screen_pos(int currcons, int w_offset, int viewed)
1108 {
1109 return screenpos(currcons, 2 * w_offset, viewed);
1110 }
1111
1112 void getconsxy(int currcons, char *p)
1113 {
1114 p[0] = x;
1115 p[1] = y;
1116 }
1117
1118 void putconsxy(int currcons, char *p)
1119 {
1120 gotoxy(currcons, p[0], p[1]);
1121 set_cursor(currcons);
1122 }
1123
1124 static void set_mode(int currcons, int on_off)
1125 {
1126 int i;
1127
1128 for (i=0; i<=npar; i++)
1129 if (ques) switch(par[i]) {
1130 case 1:
1131 if (on_off)
1132 set_kbd(decckm);
1133 else
1134 clr_kbd(decckm);
1135 break;
1136 case 3:
1137 deccolm = on_off;
1138 #if 0
1139 (void) vc_resize(video_num_lines, deccolm ? 132 : 80);
1140
1141
1142 #endif
1143 break;
1144 case 5:
1145 if (decscnm != on_off) {
1146 decscnm = on_off;
1147 invert_screen(currcons, 0, video_screen_size, 0);
1148 update_attr(currcons);
1149 }
1150 break;
1151 case 6:
1152 decom = on_off;
1153 gotoxy(currcons,0,0);
1154 break;
1155 case 7:
1156 decawm = on_off;
1157 break;
1158 case 8:
1159 if (on_off)
1160 set_kbd(decarm);
1161 else
1162 clr_kbd(decarm);
1163 break;
1164 case 9:
1165 report_mouse = on_off ? 1 : 0;
1166 break;
1167 case 25:
1168 deccm = on_off;
1169 set_cursor(currcons);
1170 break;
1171 case 1000:
1172 report_mouse = on_off ? 2 : 0;
1173 break;
1174 } else switch(par[i]) {
1175 case 3:
1176 disp_ctrl = on_off;
1177 break;
1178 case 4:
1179 decim = on_off;
1180 break;
1181 case 20:
1182 if (on_off)
1183 set_kbd(lnm);
1184 else
1185 clr_kbd(lnm);
1186 break;
1187 }
1188 }
1189
1190 static void setterm_command(int currcons)
1191 {
1192 switch(par[0]) {
1193 case 1:
1194 if (can_do_color && par[1] < 16) {
1195 ulcolor = color_table[par[1]];
1196 if (underline)
1197 update_attr(currcons);
1198 }
1199 break;
1200 case 2:
1201 if (can_do_color && par[1] < 16) {
1202 halfcolor = color_table[par[1]];
1203 if (intensity == 0)
1204 update_attr(currcons);
1205 }
1206 break;
1207 case 8:
1208 def_color = attr;
1209 default_attr(currcons);
1210 update_attr(currcons);
1211 break;
1212 case 9:
1213 blankinterval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;
1214 poke_blanked_console();
1215 break;
1216 }
1217 }
1218
1219 static void insert_char(int currcons)
1220 {
1221 unsigned int i = x;
1222 unsigned short tmp, old = video_erase_char;
1223 unsigned short * p = (unsigned short *) pos;
1224
1225 while (i++ < video_num_columns) {
1226 tmp = scr_readw(p);
1227 scr_writew(old, p);
1228 old = tmp;
1229 p++;
1230 }
1231 need_wrap = 0;
1232 }
1233
1234 static void insert_line(int currcons)
1235 {
1236 scrdown(currcons,y,bottom);
1237 need_wrap = 0;
1238 }
1239
1240 static void delete_char(int currcons)
1241 {
1242 unsigned int i = x;
1243 unsigned short * p = (unsigned short *) pos;
1244
1245 while (++i < video_num_columns) {
1246 scr_writew(scr_readw(p+1), p);
1247 p++;
1248 }
1249 scr_writew(video_erase_char, p);
1250 need_wrap = 0;
1251 }
1252
1253 static void delete_line(int currcons)
1254 {
1255 scrup(currcons,y,bottom);
1256 need_wrap = 0;
1257 }
1258
1259 static void csi_at(int currcons, unsigned int nr)
1260 {
1261 if (nr > video_num_columns)
1262 nr = video_num_columns;
1263 else if (!nr)
1264 nr = 1;
1265 while (nr--)
1266 insert_char(currcons);
1267 }
1268
1269 static void csi_L(int currcons, unsigned int nr)
1270 {
1271 if (nr > video_num_lines)
1272 nr = video_num_lines;
1273 else if (!nr)
1274 nr = 1;
1275 while (nr--)
1276 insert_line(currcons);
1277 }
1278
1279 static void csi_P(int currcons, unsigned int nr)
1280 {
1281 if (nr > video_num_columns)
1282 nr = video_num_columns;
1283 else if (!nr)
1284 nr = 1;
1285 while (nr--)
1286 delete_char(currcons);
1287 }
1288
1289 static void csi_M(int currcons, unsigned int nr)
1290 {
1291 if (nr > video_num_lines)
1292 nr = video_num_lines;
1293 else if (!nr)
1294 nr=1;
1295 while (nr--)
1296 delete_line(currcons);
1297 }
1298
1299 static void save_cur(int currcons)
1300 {
1301 saved_x = x;
1302 saved_y = y;
1303 s_intensity = intensity;
1304 s_underline = underline;
1305 s_blink = blink;
1306 s_reverse = reverse;
1307 s_charset = charset;
1308 s_color = color;
1309 saved_G0 = G0_charset;
1310 saved_G1 = G1_charset;
1311 }
1312
1313 static void restore_cur(int currcons)
1314 {
1315 gotoxy(currcons,saved_x,saved_y);
1316 intensity = s_intensity;
1317 underline = s_underline;
1318 blink = s_blink;
1319 reverse = s_reverse;
1320 charset = s_charset;
1321 color = s_color;
1322 G0_charset = saved_G0;
1323 G1_charset = saved_G1;
1324 translate = set_translate(charset ? G1_charset : G0_charset);
1325 update_attr(currcons);
1326 need_wrap = 0;
1327 }
1328
1329 enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
1330 EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,
1331 ESpalette };
1332
1333 static void reset_terminal(int currcons, int do_clear)
1334 {
1335 top = 0;
1336 bottom = video_num_lines;
1337 vc_state = ESnormal;
1338 ques = 0;
1339 translate = set_translate(LAT1_MAP);
1340 G0_charset = LAT1_MAP;
1341 G1_charset = GRAF_MAP;
1342 charset = 0;
1343 need_wrap = 0;
1344 report_mouse = 0;
1345 utf = 0;
1346 utf_count = 0;
1347
1348 disp_ctrl = 0;
1349 toggle_meta = 0;
1350
1351 decscnm = 0;
1352 decom = 0;
1353 decawm = 1;
1354 deccm = 1;
1355 decim = 0;
1356
1357 set_kbd(decarm);
1358 clr_kbd(decckm);
1359 clr_kbd(kbdapplic);
1360 clr_kbd(lnm);
1361 kbd_table[currcons].lockstate = 0;
1362 kbd_table[currcons].ledmode = LED_SHOW_FLAGS;
1363 kbd_table[currcons].ledflagstate = kbd_table[currcons].default_ledflagstate;
1364 set_leds();
1365
1366 default_attr(currcons);
1367 update_attr(currcons);
1368
1369 tab_stop[0] = 0x01010100;
1370 tab_stop[1] =
1371 tab_stop[2] =
1372 tab_stop[3] =
1373 tab_stop[4] = 0x01010101;
1374
1375 gotoxy(currcons,0,0);
1376 save_cur(currcons);
1377 if (do_clear)
1378 csi_J(currcons,2);
1379 }
1380
1381
1382
1383
1384 static void con_stop(struct tty_struct *tty)
1385 {
1386 int console_num;
1387 if (!tty)
1388 return;
1389 console_num = MINOR(tty->device) - (tty->driver.minor_start);
1390 if (!vc_cons_allocated(console_num))
1391 return;
1392 set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
1393 set_leds();
1394 }
1395
1396
1397
1398
1399 static void con_start(struct tty_struct *tty)
1400 {
1401 int console_num;
1402 if (!tty)
1403 return;
1404 console_num = MINOR(tty->device) - (tty->driver.minor_start);
1405 if (!vc_cons_allocated(console_num))
1406 return;
1407 clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
1408 set_leds();
1409 }
1410
1411 static int con_write(struct tty_struct * tty, int from_user,
1412 unsigned char *buf, int count)
1413 {
1414 int c, tc, ok, n = 0;
1415 unsigned int currcons;
1416 struct vt_struct *vt = (struct vt_struct *)tty->driver_data;
1417
1418 currcons = vt->vc_num;
1419 if (!vc_cons_allocated(currcons)) {
1420
1421 static int error = 0;
1422 if (!error) {
1423 error = 1;
1424 printk("con_write: tty %d not allocated\n", currcons+1);
1425 }
1426 return 0;
1427 }
1428
1429 if (currcons == sel_cons)
1430 clear_selection();
1431
1432 disable_bh(KEYBOARD_BH);
1433 while (!tty->stopped && count) {
1434 c = from_user ? get_user(buf) : *buf;
1435 buf++; n++; count--;
1436
1437 if (utf) {
1438
1439
1440 if(c > 0x7f) {
1441 if (utf_count > 0 && (c & 0xc0) == 0x80) {
1442 utf_char = (utf_char << 6) | (c & 0x3f);
1443 utf_count--;
1444 if (utf_count == 0)
1445 tc = c = utf_char;
1446 else continue;
1447 } else {
1448 if ((c & 0xe0) == 0xc0) {
1449 utf_count = 1;
1450 utf_char = (c & 0x1f);
1451 } else if ((c & 0xf0) == 0xe0) {
1452 utf_count = 2;
1453 utf_char = (c & 0x0f);
1454 } else if ((c & 0xf8) == 0xf0) {
1455 utf_count = 3;
1456 utf_char = (c & 0x07);
1457 } else if ((c & 0xfc) == 0xf8) {
1458 utf_count = 4;
1459 utf_char = (c & 0x03);
1460 } else if ((c & 0xfe) == 0xfc) {
1461 utf_count = 5;
1462 utf_char = (c & 0x01);
1463 } else
1464 utf_count = 0;
1465 continue;
1466 }
1467 } else {
1468 tc = c;
1469 utf_count = 0;
1470 }
1471 } else {
1472 tc = translate[toggle_meta ? (c|0x80) : c];
1473 }
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484 ok = (tc && (c >= 32 || (!utf && !(((disp_ctrl ? CTRL_ALWAYS
1485 : CTRL_ACTION) >> c) & 1))));
1486
1487 if (vc_state == ESnormal && ok) {
1488
1489 tc = conv_uni_to_pc(tc);
1490 if ( tc == -4 )
1491 {
1492
1493
1494 tc = conv_uni_to_pc(0xfffd);
1495 }
1496 else if ( tc == -3 )
1497 {
1498
1499 tc = c;
1500 }
1501 if (tc & ~console_charmask)
1502 continue;
1503
1504 if (need_wrap) {
1505 cr(currcons);
1506 lf(currcons);
1507 }
1508 if (decim)
1509 insert_char(currcons);
1510 scr_writew( video_mode_512ch ?
1511 ((attr & 0xf7) << 8) + ((tc & 0x100) << 3) +
1512 (tc & 0x0ff) : (attr << 8) + tc,
1513 (unsigned short *) pos);
1514 if (x == video_num_columns - 1)
1515 need_wrap = decawm;
1516 else {
1517 x++;
1518 pos+=2;
1519 }
1520 continue;
1521 }
1522
1523
1524
1525
1526
1527 switch (c) {
1528 case 7:
1529 kd_mksound(0x637, HZ/8);
1530 continue;
1531 case 8:
1532 bs(currcons);
1533 continue;
1534 case 9:
1535 pos -= (x << 1);
1536 while (x < video_num_columns - 1) {
1537 x++;
1538 if (tab_stop[x >> 5] & (1 << (x & 31)))
1539 break;
1540 }
1541 pos += (x << 1);
1542 continue;
1543 case 10: case 11: case 12:
1544 lf(currcons);
1545 if (!is_kbd(lnm))
1546 continue;
1547 case 13:
1548 cr(currcons);
1549 continue;
1550 case 14:
1551 charset = 1;
1552 translate = set_translate(G1_charset);
1553 disp_ctrl = 1;
1554 continue;
1555 case 15:
1556 charset = 0;
1557 translate = set_translate(G0_charset);
1558 disp_ctrl = 0;
1559 continue;
1560 case 24: case 26:
1561 vc_state = ESnormal;
1562 continue;
1563 case 27:
1564 vc_state = ESesc;
1565 continue;
1566 case 127:
1567 del(currcons);
1568 continue;
1569 case 128+27:
1570 vc_state = ESsquare;
1571 continue;
1572 }
1573 switch(vc_state) {
1574 case ESesc:
1575 vc_state = ESnormal;
1576 switch (c) {
1577 case '[':
1578 vc_state = ESsquare;
1579 continue;
1580 case ']':
1581 vc_state = ESnonstd;
1582 continue;
1583 case '%':
1584 vc_state = ESpercent;
1585 continue;
1586 case 'E':
1587 cr(currcons);
1588 lf(currcons);
1589 continue;
1590 case 'M':
1591 ri(currcons);
1592 continue;
1593 case 'D':
1594 lf(currcons);
1595 continue;
1596 case 'H':
1597 tab_stop[x >> 5] |= (1 << (x & 31));
1598 continue;
1599 case 'Z':
1600 respond_ID(tty);
1601 continue;
1602 case '7':
1603 save_cur(currcons);
1604 continue;
1605 case '8':
1606 restore_cur(currcons);
1607 continue;
1608 case '(':
1609 vc_state = ESsetG0;
1610 continue;
1611 case ')':
1612 vc_state = ESsetG1;
1613 continue;
1614 case '#':
1615 vc_state = EShash;
1616 continue;
1617 case 'c':
1618 reset_terminal(currcons,1);
1619 continue;
1620 case '>':
1621 clr_kbd(kbdapplic);
1622 continue;
1623 case '=':
1624 set_kbd(kbdapplic);
1625 continue;
1626 }
1627 continue;
1628 case ESnonstd:
1629 if (c=='P') {
1630 for (npar=0; npar<NPAR; npar++)
1631 par[npar] = 0 ;
1632 npar = 0 ;
1633 vc_state = ESpalette;
1634 continue;
1635 } else if (c=='R') {
1636 reset_palette (currcons);
1637 vc_state = ESnormal;
1638 } else
1639 vc_state = ESnormal;
1640 continue;
1641 case ESpalette:
1642 if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {
1643 par[npar++] = (c>'9' ? (c&0xDF)-'A'+10 : c-'0') ;
1644 if (npar==7) {
1645 int i = par[0]*3, j = 1;
1646 palette[i] = 16*par[j++];
1647 palette[i++] += par[j++];
1648 palette[i] = 16*par[j++];
1649 palette[i++] += par[j++];
1650 palette[i] = 16*par[j++];
1651 palette[i] += par[j];
1652 set_palette() ;
1653 vc_state = ESnormal;
1654 }
1655 } else
1656 vc_state = ESnormal;
1657 continue;
1658 case ESsquare:
1659 for(npar = 0 ; npar < NPAR ; npar++)
1660 par[npar] = 0;
1661 npar = 0;
1662 vc_state = ESgetpars;
1663 if (c == '[') {
1664 vc_state=ESfunckey;
1665 continue;
1666 }
1667 ques = (c=='?');
1668 if (ques)
1669 continue;
1670 case ESgetpars:
1671 if (c==';' && npar<NPAR-1) {
1672 npar++;
1673 continue;
1674 } else if (c>='0' && c<='9') {
1675 par[npar] *= 10;
1676 par[npar] += c-'0';
1677 continue;
1678 } else vc_state=ESgotpars;
1679 case ESgotpars:
1680 vc_state = ESnormal;
1681 switch(c) {
1682 case 'h':
1683 set_mode(currcons,1);
1684 continue;
1685 case 'l':
1686 set_mode(currcons,0);
1687 continue;
1688 case 'n':
1689 if (!ques)
1690 if (par[0] == 5)
1691 status_report(tty);
1692 else if (par[0] == 6)
1693 cursor_report(currcons,tty);
1694 continue;
1695 }
1696 if (ques) {
1697 ques = 0;
1698 continue;
1699 }
1700 switch(c) {
1701 case 'G': case '`':
1702 if (par[0]) par[0]--;
1703 gotoxy(currcons,par[0],y);
1704 continue;
1705 case 'A':
1706 if (!par[0]) par[0]++;
1707 gotoxy(currcons,x,y-par[0]);
1708 continue;
1709 case 'B': case 'e':
1710 if (!par[0]) par[0]++;
1711 gotoxy(currcons,x,y+par[0]);
1712 continue;
1713 case 'C': case 'a':
1714 if (!par[0]) par[0]++;
1715 gotoxy(currcons,x+par[0],y);
1716 continue;
1717 case 'D':
1718 if (!par[0]) par[0]++;
1719 gotoxy(currcons,x-par[0],y);
1720 continue;
1721 case 'E':
1722 if (!par[0]) par[0]++;
1723 gotoxy(currcons,0,y+par[0]);
1724 continue;
1725 case 'F':
1726 if (!par[0]) par[0]++;
1727 gotoxy(currcons,0,y-par[0]);
1728 continue;
1729 case 'd':
1730 if (par[0]) par[0]--;
1731 gotoxy(currcons,x,par[0]);
1732 continue;
1733 case 'H': case 'f':
1734 if (par[0]) par[0]--;
1735 if (par[1]) par[1]--;
1736 gotoxy(currcons,par[1],par[0]);
1737 continue;
1738 case 'J':
1739 csi_J(currcons,par[0]);
1740 continue;
1741 case 'K':
1742 csi_K(currcons,par[0]);
1743 continue;
1744 case 'L':
1745 csi_L(currcons,par[0]);
1746 continue;
1747 case 'M':
1748 csi_M(currcons,par[0]);
1749 continue;
1750 case 'P':
1751 csi_P(currcons,par[0]);
1752 continue;
1753 case 'c':
1754 if (!par[0])
1755 respond_ID(tty);
1756 continue;
1757 case 'g':
1758 if (!par[0])
1759 tab_stop[x >> 5] &= ~(1 << (x & 31));
1760 else if (par[0] == 3) {
1761 tab_stop[0] =
1762 tab_stop[1] =
1763 tab_stop[2] =
1764 tab_stop[3] =
1765 tab_stop[4] = 0;
1766 }
1767 continue;
1768 case 'm':
1769 csi_m(currcons);
1770 continue;
1771 case 'q':
1772
1773 if (par[0] < 4)
1774 setledstate(kbd_table + currcons,
1775 (par[0] < 3) ? par[0] : 4);
1776 continue;
1777 case 'r':
1778 if (!par[0])
1779 par[0]++;
1780 if (!par[1])
1781 par[1] = video_num_lines;
1782
1783 if (par[0] < par[1] &&
1784 par[1] <= video_num_lines) {
1785 top=par[0]-1;
1786 bottom=par[1];
1787 gotoxy(currcons,0,0);
1788 }
1789 continue;
1790 case 's':
1791 save_cur(currcons);
1792 continue;
1793 case 'u':
1794 restore_cur(currcons);
1795 continue;
1796 case 'X':
1797 csi_X(currcons, par[0]);
1798 continue;
1799 case '@':
1800 csi_at(currcons,par[0]);
1801 continue;
1802 case ']':
1803 setterm_command(currcons);
1804 continue;
1805 }
1806 continue;
1807 case ESpercent:
1808 vc_state = ESnormal;
1809 switch (c) {
1810 case '@':
1811 utf = 0;
1812 continue;
1813 case 'G':
1814 case '8':
1815 utf = 1;
1816 continue;
1817 }
1818 continue;
1819 case ESfunckey:
1820 vc_state = ESnormal;
1821 continue;
1822 case EShash:
1823 vc_state = ESnormal;
1824 if (c == '8') {
1825
1826 video_erase_char =
1827 (video_erase_char & 0xff00) | 'E';
1828 csi_J(currcons, 2);
1829 video_erase_char =
1830 (video_erase_char & 0xff00) | ' ';
1831 }
1832 continue;
1833 case ESsetG0:
1834 if (c == '0')
1835 G0_charset = GRAF_MAP;
1836 else if (c == 'B')
1837 G0_charset = LAT1_MAP;
1838 else if (c == 'U')
1839 G0_charset = IBMPC_MAP;
1840 else if (c == 'K')
1841 G0_charset = USER_MAP;
1842 if (charset == 0)
1843 translate = set_translate(G0_charset);
1844 vc_state = ESnormal;
1845 continue;
1846 case ESsetG1:
1847 if (c == '0')
1848 G1_charset = GRAF_MAP;
1849 else if (c == 'B')
1850 G1_charset = LAT1_MAP;
1851 else if (c == 'U')
1852 G1_charset = IBMPC_MAP;
1853 else if (c == 'K')
1854 G1_charset = USER_MAP;
1855 if (charset == 1)
1856 translate = set_translate(G1_charset);
1857 vc_state = ESnormal;
1858 continue;
1859 default:
1860 vc_state = ESnormal;
1861 }
1862 }
1863 if (vcmode != KD_GRAPHICS)
1864 set_cursor(currcons);
1865 enable_bh(KEYBOARD_BH);
1866 return n;
1867 }
1868
1869 static int con_write_room(struct tty_struct *tty)
1870 {
1871 if (tty->stopped)
1872 return 0;
1873 return 4096;
1874 }
1875
1876 static int con_chars_in_buffer(struct tty_struct *tty)
1877 {
1878 return 0;
1879 }
1880
1881 void poke_blanked_console(void)
1882 {
1883 timer_active &= ~(1<<BLANK_TIMER);
1884 if (vt_cons[fg_console]->vc_mode == KD_GRAPHICS)
1885 return;
1886 if (console_blanked) {
1887 timer_table[BLANK_TIMER].expires = 0;
1888 timer_active |= 1<<BLANK_TIMER;
1889 } else if (blankinterval) {
1890 timer_table[BLANK_TIMER].expires = jiffies + blankinterval;
1891 timer_active |= 1<<BLANK_TIMER;
1892 }
1893 }
1894
1895 void console_print(const char * b)
1896 {
1897 int currcons = fg_console;
1898 unsigned char c;
1899 static int printing = 0;
1900
1901 if (!printable || printing)
1902 return;
1903 printing = 1;
1904
1905 if (!vc_cons_allocated(currcons)) {
1906
1907 printk("console_print: tty %d not allocated ??\n", currcons+1);
1908 return;
1909 }
1910
1911 while ((c = *(b++)) != 0) {
1912 if (c == 10 || c == 13 || need_wrap) {
1913 if (c != 13)
1914 lf(currcons);
1915 cr(currcons);
1916 if (c == 10 || c == 13)
1917 continue;
1918 }
1919 scr_writew((attr << 8) + c, (unsigned short *) pos);
1920 if (x == video_num_columns - 1) {
1921 need_wrap = 1;
1922 continue;
1923 }
1924 x++;
1925 pos+=2;
1926 }
1927 set_cursor(currcons);
1928 poke_blanked_console();
1929 printing = 0;
1930 }
1931
1932
1933
1934
1935
1936
1937 static void con_throttle(struct tty_struct *tty)
1938 {
1939 }
1940
1941 static void con_unthrottle(struct tty_struct *tty)
1942 {
1943 struct vt_struct *vt = (struct vt_struct *) tty->driver_data;
1944
1945 wake_up_interruptible(&vt->paste_wait);
1946 }
1947
1948 static void vc_init(unsigned int currcons, unsigned long rows, unsigned long cols, int do_clear)
1949 {
1950 long base = (long) vc_scrbuf[currcons];
1951 int j, k ;
1952
1953 video_num_columns = cols;
1954 video_num_lines = rows;
1955 video_size_row = cols<<1;
1956 video_screen_size = video_num_lines * video_size_row;
1957
1958 pos = origin = video_mem_start = base;
1959 scr_end = base + video_screen_size;
1960 video_mem_end = base + video_screen_size;
1961 reset_vc(currcons);
1962 for (j=k=0; j<16; j++) {
1963 vc_cons[currcons].d->vc_palette[k++] = default_red[j] ;
1964 vc_cons[currcons].d->vc_palette[k++] = default_grn[j] ;
1965 vc_cons[currcons].d->vc_palette[k++] = default_blu[j] ;
1966 }
1967 def_color = 0x07;
1968 ulcolor = 0x0f;
1969 halfcolor = 0x08;
1970 vt_cons[currcons]->paste_wait = 0;
1971 reset_terminal(currcons, do_clear);
1972 }
1973
1974 static void con_setsize(unsigned long rows, unsigned long cols)
1975 {
1976 video_num_lines = rows;
1977 video_num_columns = cols;
1978 video_size_row = 2 * cols;
1979 video_screen_size = video_num_lines * video_size_row;
1980 }
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992 long con_init(long kmem_start)
1993 {
1994 char *display_desc = "????";
1995 int currcons = 0;
1996 int orig_x = ORIG_X;
1997 int orig_y = ORIG_Y;
1998
1999 memset(&console_driver, 0, sizeof(struct tty_driver));
2000 console_driver.magic = TTY_DRIVER_MAGIC;
2001 console_driver.name = "tty";
2002 console_driver.name_base = 1;
2003 console_driver.major = TTY_MAJOR;
2004 console_driver.minor_start = 1;
2005 console_driver.num = MAX_NR_CONSOLES;
2006 console_driver.type = TTY_DRIVER_TYPE_CONSOLE;
2007 console_driver.init_termios = tty_std_termios;
2008 console_driver.flags = TTY_DRIVER_REAL_RAW;
2009 console_driver.refcount = &console_refcount;
2010 console_driver.table = console_table;
2011 console_driver.termios = console_termios;
2012 console_driver.termios_locked = console_termios_locked;
2013
2014 console_driver.open = con_open;
2015 console_driver.write = con_write;
2016 console_driver.write_room = con_write_room;
2017 console_driver.chars_in_buffer = con_chars_in_buffer;
2018 console_driver.ioctl = vt_ioctl;
2019 console_driver.stop = con_stop;
2020 console_driver.start = con_start;
2021 console_driver.throttle = con_throttle;
2022 console_driver.unthrottle = con_unthrottle;
2023
2024 if (tty_register_driver(&console_driver))
2025 panic("Couldn't register console driver\n");
2026
2027 con_setsize(ORIG_VIDEO_LINES, ORIG_VIDEO_COLS);
2028 video_page = ORIG_VIDEO_PAGE;
2029 __scrollback_mode = 0 ;
2030
2031 timer_table[BLANK_TIMER].fn = blank_screen;
2032 timer_table[BLANK_TIMER].expires = 0;
2033 if (blankinterval) {
2034 timer_table[BLANK_TIMER].expires = jiffies+blankinterval;
2035 timer_active |= 1<<BLANK_TIMER;
2036 }
2037
2038 if (ORIG_VIDEO_MODE == 7)
2039 {
2040 video_mem_base = 0xb0000;
2041 video_port_reg = 0x3b4;
2042 video_port_val = 0x3b5;
2043 if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10)
2044 {
2045 video_type = VIDEO_TYPE_EGAM;
2046 video_mem_term = 0xb8000;
2047 display_desc = "EGA+";
2048 request_region(0x3b0,16,"ega");
2049 }
2050 else
2051 {
2052 video_type = VIDEO_TYPE_MDA;
2053 video_mem_term = 0xb2000;
2054 display_desc = "*MDA";
2055 request_region(0x3b0,16,"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 }