root/kernel/chr_drv/console.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. gotoxy
  2. set_origin
  3. scrup
  4. scrdown
  5. lf
  6. ri
  7. cr
  8. bs
  9. del
  10. csi_J
  11. csi_K
  12. update_attr
  13. default_attr
  14. csi_m
  15. hide_cursor
  16. set_cursor
  17. respond_string
  18. respond_num
  19. cursor_report
  20. status_report
  21. respond_ID
  22. invert_screen
  23. set_mode
  24. setterm_command
  25. insert_char
  26. insert_line
  27. delete_char
  28. delete_line
  29. csi_at
  30. csi_L
  31. csi_P
  32. csi_M
  33. save_cur
  34. restore_cur
  35. reset_terminal
  36. con_write
  37. do_keyboard_interrupt
  38. memsetw
  39. con_init
  40. kbdsave
  41. get_scrmem
  42. set_scrmem
  43. blank_screen
  44. unblank_screen
  45. update_screen
  46. sysbeepstop
  47. sysbeep
  48. do_screendump
  49. console_print

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

/* [previous][next][first][last][top][bottom][index][help] */