.. | .. |
---|
127 | 127 | static struct con_driver registered_con_driver[MAX_NR_CON_DRIVER]; |
---|
128 | 128 | const struct consw *conswitchp; |
---|
129 | 129 | |
---|
130 | | -/* A bitmap for codes <32. A bit of 1 indicates that the code |
---|
131 | | - * corresponding to that bit number invokes some special action |
---|
132 | | - * (such as cursor movement) and should not be displayed as a |
---|
133 | | - * glyph unless the disp_ctrl mode is explicitly enabled. |
---|
134 | | - */ |
---|
135 | | -#define CTRL_ACTION 0x0d00ff81 |
---|
136 | | -#define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */ |
---|
137 | | - |
---|
138 | 130 | /* |
---|
139 | 131 | * Here is the default bell parameters: 750HZ, 1/8th of a second |
---|
140 | 132 | */ |
---|
.. | .. |
---|
171 | 163 | int global_cursor_default = -1; |
---|
172 | 164 | module_param(global_cursor_default, int, S_IRUGO | S_IWUSR); |
---|
173 | 165 | |
---|
174 | | -static int cur_default = CUR_DEFAULT; |
---|
| 166 | +static int cur_default = CUR_UNDERLINE; |
---|
175 | 167 | module_param(cur_default, int, S_IRUGO | S_IWUSR); |
---|
176 | 168 | |
---|
177 | 169 | /* |
---|
.. | .. |
---|
291 | 283 | return con_is_visible(vc) && !console_blanked; |
---|
292 | 284 | } |
---|
293 | 285 | |
---|
294 | | -static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed) |
---|
| 286 | +static inline unsigned short *screenpos(const struct vc_data *vc, int offset, |
---|
| 287 | + bool viewed) |
---|
295 | 288 | { |
---|
296 | 289 | unsigned short *p; |
---|
297 | 290 | |
---|
.. | .. |
---|
351 | 344 | /* allocate everything in one go */ |
---|
352 | 345 | memsize = cols * rows * sizeof(char32_t); |
---|
353 | 346 | memsize += rows * sizeof(char32_t *); |
---|
354 | | - p = vmalloc(memsize); |
---|
| 347 | + p = vzalloc(memsize); |
---|
355 | 348 | if (!p) |
---|
356 | 349 | return NULL; |
---|
357 | 350 | |
---|
.. | .. |
---|
381 | 374 | struct uni_screen *uniscr = get_vc_uniscr(vc); |
---|
382 | 375 | |
---|
383 | 376 | if (uniscr) |
---|
384 | | - uniscr->lines[vc->vc_y][vc->vc_x] = uc; |
---|
| 377 | + uniscr->lines[vc->state.y][vc->state.x] = uc; |
---|
385 | 378 | } |
---|
386 | 379 | |
---|
387 | 380 | static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr) |
---|
.. | .. |
---|
389 | 382 | struct uni_screen *uniscr = get_vc_uniscr(vc); |
---|
390 | 383 | |
---|
391 | 384 | if (uniscr) { |
---|
392 | | - char32_t *ln = uniscr->lines[vc->vc_y]; |
---|
393 | | - unsigned int x = vc->vc_x, cols = vc->vc_cols; |
---|
| 385 | + char32_t *ln = uniscr->lines[vc->state.y]; |
---|
| 386 | + unsigned int x = vc->state.x, cols = vc->vc_cols; |
---|
394 | 387 | |
---|
395 | 388 | memmove(&ln[x + nr], &ln[x], (cols - x - nr) * sizeof(*ln)); |
---|
396 | 389 | memset32(&ln[x], ' ', nr); |
---|
.. | .. |
---|
402 | 395 | struct uni_screen *uniscr = get_vc_uniscr(vc); |
---|
403 | 396 | |
---|
404 | 397 | if (uniscr) { |
---|
405 | | - char32_t *ln = uniscr->lines[vc->vc_y]; |
---|
406 | | - unsigned int x = vc->vc_x, cols = vc->vc_cols; |
---|
| 398 | + char32_t *ln = uniscr->lines[vc->state.y]; |
---|
| 399 | + unsigned int x = vc->state.x, cols = vc->vc_cols; |
---|
407 | 400 | |
---|
408 | 401 | memcpy(&ln[x], &ln[x + nr], (cols - x - nr) * sizeof(*ln)); |
---|
409 | 402 | memset32(&ln[cols - nr], ' ', nr); |
---|
.. | .. |
---|
416 | 409 | struct uni_screen *uniscr = get_vc_uniscr(vc); |
---|
417 | 410 | |
---|
418 | 411 | if (uniscr) { |
---|
419 | | - char32_t *ln = uniscr->lines[vc->vc_y]; |
---|
| 412 | + char32_t *ln = uniscr->lines[vc->state.y]; |
---|
420 | 413 | |
---|
421 | 414 | memset32(&ln[x], ' ', nr); |
---|
422 | 415 | } |
---|
.. | .. |
---|
551 | 544 | * This must be preceded by a successful call to vc_uniscr_check() once |
---|
552 | 545 | * the console lock has been taken. |
---|
553 | 546 | */ |
---|
554 | | -void vc_uniscr_copy_line(struct vc_data *vc, void *dest, int viewed, |
---|
| 547 | +void vc_uniscr_copy_line(const struct vc_data *vc, void *dest, bool viewed, |
---|
555 | 548 | unsigned int row, unsigned int col, unsigned int nr) |
---|
556 | 549 | { |
---|
557 | 550 | struct uni_screen *uniscr = get_vc_uniscr(vc); |
---|
.. | .. |
---|
705 | 698 | |
---|
706 | 699 | /* Structure of attributes is hardware-dependent */ |
---|
707 | 700 | |
---|
708 | | -static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, |
---|
709 | | - u8 _underline, u8 _reverse, u8 _italic) |
---|
| 701 | +static u8 build_attr(struct vc_data *vc, u8 _color, |
---|
| 702 | + enum vc_intensity _intensity, bool _blink, bool _underline, |
---|
| 703 | + bool _reverse, bool _italic) |
---|
710 | 704 | { |
---|
711 | 705 | if (vc->vc_sw->con_build_attr) |
---|
712 | 706 | return vc->vc_sw->con_build_attr(vc, _color, _intensity, |
---|
.. | .. |
---|
726 | 720 | u8 a = _color; |
---|
727 | 721 | if (!vc->vc_can_do_color) |
---|
728 | 722 | return _intensity | |
---|
729 | | - (_italic ? 2 : 0) | |
---|
730 | | - (_underline ? 4 : 0) | |
---|
731 | | - (_reverse ? 8 : 0) | |
---|
732 | | - (_blink ? 0x80 : 0); |
---|
| 723 | + (_italic << 1) | |
---|
| 724 | + (_underline << 2) | |
---|
| 725 | + (_reverse << 3) | |
---|
| 726 | + (_blink << 7); |
---|
733 | 727 | if (_italic) |
---|
734 | 728 | a = (a & 0xF0) | vc->vc_itcolor; |
---|
735 | 729 | else if (_underline) |
---|
736 | 730 | a = (a & 0xf0) | vc->vc_ulcolor; |
---|
737 | | - else if (_intensity == 0) |
---|
| 731 | + else if (_intensity == VCI_HALF_BRIGHT) |
---|
738 | 732 | a = (a & 0xf0) | vc->vc_halfcolor; |
---|
739 | 733 | if (_reverse) |
---|
740 | | - a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77); |
---|
| 734 | + a = (a & 0x88) | (((a >> 4) | (a << 4)) & 0x77); |
---|
741 | 735 | if (_blink) |
---|
742 | 736 | a ^= 0x80; |
---|
743 | | - if (_intensity == 2) |
---|
| 737 | + if (_intensity == VCI_BOLD) |
---|
744 | 738 | a ^= 0x08; |
---|
745 | 739 | if (vc->vc_hi_font_mask == 0x100) |
---|
746 | 740 | a <<= 1; |
---|
.. | .. |
---|
750 | 744 | |
---|
751 | 745 | static void update_attr(struct vc_data *vc) |
---|
752 | 746 | { |
---|
753 | | - vc->vc_attr = build_attr(vc, vc->vc_color, vc->vc_intensity, |
---|
754 | | - vc->vc_blink, vc->vc_underline, |
---|
755 | | - vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic); |
---|
756 | | - vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' '; |
---|
| 747 | + vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity, |
---|
| 748 | + vc->state.blink, vc->state.underline, |
---|
| 749 | + vc->state.reverse ^ vc->vc_decscnm, vc->state.italic); |
---|
| 750 | + vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color, |
---|
| 751 | + VCI_NORMAL, vc->state.blink, false, |
---|
| 752 | + vc->vc_decscnm, false) << 8); |
---|
757 | 753 | } |
---|
758 | 754 | |
---|
759 | 755 | /* Note: inverting the screen twice should revert to the original state */ |
---|
760 | | -void invert_screen(struct vc_data *vc, int offset, int count, int viewed) |
---|
| 756 | +void invert_screen(struct vc_data *vc, int offset, int count, bool viewed) |
---|
761 | 757 | { |
---|
762 | 758 | unsigned short *p; |
---|
763 | 759 | |
---|
.. | .. |
---|
782 | 778 | } else if (vc->vc_hi_font_mask == 0x100) { |
---|
783 | 779 | while (cnt--) { |
---|
784 | 780 | a = scr_readw(q); |
---|
785 | | - a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4); |
---|
| 781 | + a = (a & 0x11ff) | |
---|
| 782 | + ((a & 0xe000) >> 4) | |
---|
| 783 | + ((a & 0x0e00) << 4); |
---|
786 | 784 | scr_writew(a, q); |
---|
787 | 785 | q++; |
---|
788 | 786 | } |
---|
789 | 787 | } else { |
---|
790 | 788 | while (cnt--) { |
---|
791 | 789 | a = scr_readw(q); |
---|
792 | | - a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4); |
---|
| 790 | + a = (a & 0x88ff) | |
---|
| 791 | + ((a & 0x7000) >> 4) | |
---|
| 792 | + ((a & 0x0700) << 4); |
---|
793 | 793 | scr_writew(a, q); |
---|
794 | 794 | q++; |
---|
795 | 795 | } |
---|
.. | .. |
---|
812 | 812 | |
---|
813 | 813 | if (old_offset != -1 && old_offset >= 0 && |
---|
814 | 814 | old_offset < vc->vc_screenbuf_size) { |
---|
815 | | - scr_writew(old, screenpos(vc, old_offset, 1)); |
---|
| 815 | + scr_writew(old, screenpos(vc, old_offset, true)); |
---|
816 | 816 | if (con_should_update(vc)) |
---|
817 | 817 | vc->vc_sw->con_putc(vc, old, oldy, oldx); |
---|
818 | 818 | notify_update(vc); |
---|
.. | .. |
---|
824 | 824 | offset < vc->vc_screenbuf_size) { |
---|
825 | 825 | unsigned short new; |
---|
826 | 826 | unsigned short *p; |
---|
827 | | - p = screenpos(vc, offset, 1); |
---|
| 827 | + p = screenpos(vc, offset, true); |
---|
828 | 828 | old = scr_readw(p); |
---|
829 | 829 | new = old ^ vc->vc_complement_mask; |
---|
830 | 830 | scr_writew(new, p); |
---|
.. | .. |
---|
842 | 842 | unsigned short *p = (unsigned short *) vc->vc_pos; |
---|
843 | 843 | |
---|
844 | 844 | vc_uniscr_insert(vc, nr); |
---|
845 | | - scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2); |
---|
| 845 | + scr_memmovew(p + nr, p, (vc->vc_cols - vc->state.x - nr) * 2); |
---|
846 | 846 | scr_memsetw(p, vc->vc_video_erase_char, nr * 2); |
---|
847 | 847 | vc->vc_need_wrap = 0; |
---|
848 | 848 | if (con_should_update(vc)) |
---|
849 | 849 | do_update_region(vc, (unsigned long) p, |
---|
850 | | - vc->vc_cols - vc->vc_x); |
---|
| 850 | + vc->vc_cols - vc->state.x); |
---|
851 | 851 | } |
---|
852 | 852 | |
---|
853 | 853 | static void delete_char(struct vc_data *vc, unsigned int nr) |
---|
.. | .. |
---|
855 | 855 | unsigned short *p = (unsigned short *) vc->vc_pos; |
---|
856 | 856 | |
---|
857 | 857 | vc_uniscr_delete(vc, nr); |
---|
858 | | - scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2); |
---|
859 | | - scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char, |
---|
| 858 | + scr_memmovew(p, p + nr, (vc->vc_cols - vc->state.x - nr) * 2); |
---|
| 859 | + scr_memsetw(p + vc->vc_cols - vc->state.x - nr, vc->vc_video_erase_char, |
---|
860 | 860 | nr * 2); |
---|
861 | 861 | vc->vc_need_wrap = 0; |
---|
862 | 862 | if (con_should_update(vc)) |
---|
863 | 863 | do_update_region(vc, (unsigned long) p, |
---|
864 | | - vc->vc_cols - vc->vc_x); |
---|
| 864 | + vc->vc_cols - vc->state.x); |
---|
865 | 865 | } |
---|
866 | 866 | |
---|
867 | 867 | static int softcursor_original = -1; |
---|
.. | .. |
---|
871 | 871 | int i = scr_readw((u16 *) vc->vc_pos); |
---|
872 | 872 | u32 type = vc->vc_cursor_type; |
---|
873 | 873 | |
---|
874 | | - if (! (type & 0x10)) return; |
---|
875 | | - if (softcursor_original != -1) return; |
---|
| 874 | + if (!(type & CUR_SW)) |
---|
| 875 | + return; |
---|
| 876 | + if (softcursor_original != -1) |
---|
| 877 | + return; |
---|
876 | 878 | softcursor_original = i; |
---|
877 | | - i |= ((type >> 8) & 0xff00 ); |
---|
878 | | - i ^= ((type) & 0xff00 ); |
---|
879 | | - if ((type & 0x20) && ((softcursor_original & 0x7000) == (i & 0x7000))) i ^= 0x7000; |
---|
880 | | - if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700; |
---|
881 | | - scr_writew(i, (u16 *) vc->vc_pos); |
---|
| 879 | + i |= CUR_SET(type); |
---|
| 880 | + i ^= CUR_CHANGE(type); |
---|
| 881 | + if ((type & CUR_ALWAYS_BG) && |
---|
| 882 | + (softcursor_original & CUR_BG) == (i & CUR_BG)) |
---|
| 883 | + i ^= CUR_BG; |
---|
| 884 | + if ((type & CUR_INVERT_FG_BG) && (i & CUR_FG) == ((i & CUR_BG) >> 4)) |
---|
| 885 | + i ^= CUR_FG; |
---|
| 886 | + scr_writew(i, (u16 *)vc->vc_pos); |
---|
882 | 887 | if (con_should_update(vc)) |
---|
883 | | - vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x); |
---|
| 888 | + vc->vc_sw->con_putc(vc, i, vc->state.y, vc->state.x); |
---|
884 | 889 | } |
---|
885 | 890 | |
---|
886 | 891 | static void hide_softcursor(struct vc_data *vc) |
---|
.. | .. |
---|
889 | 894 | scr_writew(softcursor_original, (u16 *)vc->vc_pos); |
---|
890 | 895 | if (con_should_update(vc)) |
---|
891 | 896 | vc->vc_sw->con_putc(vc, softcursor_original, |
---|
892 | | - vc->vc_y, vc->vc_x); |
---|
| 897 | + vc->state.y, vc->state.x); |
---|
893 | 898 | softcursor_original = -1; |
---|
894 | 899 | } |
---|
895 | 900 | } |
---|
.. | .. |
---|
911 | 916 | if (vc_is_sel(vc)) |
---|
912 | 917 | clear_selection(); |
---|
913 | 918 | add_softcursor(vc); |
---|
914 | | - if ((vc->vc_cursor_type & 0x0f) != 1) |
---|
| 919 | + if (CUR_SIZE(vc->vc_cursor_type) != CUR_NONE) |
---|
915 | 920 | vc->vc_sw->con_cursor(vc, CM_DRAW); |
---|
916 | 921 | } else |
---|
917 | 922 | hide_cursor(vc); |
---|
.. | .. |
---|
927 | 932 | vc->vc_origin = (unsigned long)vc->vc_screenbuf; |
---|
928 | 933 | vc->vc_visible_origin = vc->vc_origin; |
---|
929 | 934 | vc->vc_scr_end = vc->vc_origin + vc->vc_screenbuf_size; |
---|
930 | | - vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->vc_y + 2 * vc->vc_x; |
---|
| 935 | + vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->state.y + |
---|
| 936 | + 2 * vc->state.x; |
---|
931 | 937 | } |
---|
932 | 938 | |
---|
933 | 939 | static void save_screen(struct vc_data *vc) |
---|
.. | .. |
---|
1025 | 1031 | clear_buffer_attributes(vc); |
---|
1026 | 1032 | } |
---|
1027 | 1033 | |
---|
1028 | | - /* Forcibly update if we're panicing */ |
---|
1029 | | - if ((update && vc->vc_mode != KD_GRAPHICS) || |
---|
1030 | | - vt_force_oops_output(vc)) |
---|
| 1034 | + if (update && vc->vc_mode != KD_GRAPHICS) |
---|
1031 | 1035 | do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2); |
---|
1032 | 1036 | } |
---|
1033 | 1037 | set_cursor(vc); |
---|
.. | .. |
---|
1067 | 1071 | vc->vc_hi_font_mask = 0; |
---|
1068 | 1072 | vc->vc_complement_mask = 0; |
---|
1069 | 1073 | vc->vc_can_do_color = 0; |
---|
1070 | | - vc->vc_panic_force_write = false; |
---|
1071 | 1074 | vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS; |
---|
1072 | 1075 | vc->vc_sw->con_init(vc, init); |
---|
1073 | 1076 | if (!vc->vc_complement_mask) |
---|
.. | .. |
---|
1178 | 1181 | /** |
---|
1179 | 1182 | * vc_do_resize - resizing method for the tty |
---|
1180 | 1183 | * @tty: tty being resized |
---|
1181 | | - * @real_tty: real tty (different to tty if a pty/tty pair) |
---|
1182 | 1184 | * @vc: virtual console private data |
---|
1183 | 1185 | * @cols: columns |
---|
1184 | 1186 | * @lines: lines |
---|
.. | .. |
---|
1276 | 1278 | new_origin = (long) newscreen; |
---|
1277 | 1279 | new_scr_end = new_origin + new_screen_size; |
---|
1278 | 1280 | |
---|
1279 | | - if (vc->vc_y > new_rows) { |
---|
1280 | | - if (old_rows - vc->vc_y < new_rows) { |
---|
| 1281 | + if (vc->state.y > new_rows) { |
---|
| 1282 | + if (old_rows - vc->state.y < new_rows) { |
---|
1281 | 1283 | /* |
---|
1282 | 1284 | * Cursor near the bottom, copy contents from the |
---|
1283 | 1285 | * bottom of buffer |
---|
.. | .. |
---|
1288 | 1290 | * Cursor is in no man's land, copy 1/2 screenful |
---|
1289 | 1291 | * from the top and bottom of cursor position |
---|
1290 | 1292 | */ |
---|
1291 | | - first_copied_row = (vc->vc_y - new_rows/2); |
---|
| 1293 | + first_copied_row = (vc->state.y - new_rows/2); |
---|
1292 | 1294 | } |
---|
1293 | 1295 | old_origin += first_copied_row * old_row_size; |
---|
1294 | 1296 | } else |
---|
.. | .. |
---|
1323 | 1325 | /* do part of a reset_terminal() */ |
---|
1324 | 1326 | vc->vc_top = 0; |
---|
1325 | 1327 | vc->vc_bottom = vc->vc_rows; |
---|
1326 | | - gotoxy(vc, vc->vc_x, vc->vc_y); |
---|
| 1328 | + gotoxy(vc, vc->state.x, vc->state.y); |
---|
1327 | 1329 | save_cur(vc); |
---|
1328 | 1330 | |
---|
1329 | 1331 | if (tty) { |
---|
.. | .. |
---|
1410 | 1412 | * VT102 emulator |
---|
1411 | 1413 | */ |
---|
1412 | 1414 | |
---|
| 1415 | +enum { EPecma = 0, EPdec, EPeq, EPgt, EPlt}; |
---|
| 1416 | + |
---|
1413 | 1417 | #define set_kbd(vc, x) vt_set_kbd_mode_bit((vc)->vc_num, (x)) |
---|
1414 | 1418 | #define clr_kbd(vc, x) vt_clr_kbd_mode_bit((vc)->vc_num, (x)) |
---|
1415 | 1419 | #define is_kbd(vc, x) vt_get_kbd_mode_bit((vc)->vc_num, (x)) |
---|
.. | .. |
---|
1418 | 1422 | #define decckm VC_CKMODE |
---|
1419 | 1423 | #define kbdapplic VC_APPLIC |
---|
1420 | 1424 | #define lnm VC_CRLF |
---|
1421 | | - |
---|
1422 | | -/* |
---|
1423 | | - * this is what the terminal answers to a ESC-Z or csi0c query. |
---|
1424 | | - */ |
---|
1425 | | -#define VT100ID "\033[?1;2c" |
---|
1426 | | -#define VT102ID "\033[?6c" |
---|
1427 | 1425 | |
---|
1428 | 1426 | const unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, |
---|
1429 | 1427 | 8,12,10,14, 9,13,11,15 }; |
---|
.. | .. |
---|
1457 | 1455 | int min_y, max_y; |
---|
1458 | 1456 | |
---|
1459 | 1457 | if (new_x < 0) |
---|
1460 | | - vc->vc_x = 0; |
---|
| 1458 | + vc->state.x = 0; |
---|
1461 | 1459 | else { |
---|
1462 | 1460 | if (new_x >= vc->vc_cols) |
---|
1463 | | - vc->vc_x = vc->vc_cols - 1; |
---|
| 1461 | + vc->state.x = vc->vc_cols - 1; |
---|
1464 | 1462 | else |
---|
1465 | | - vc->vc_x = new_x; |
---|
| 1463 | + vc->state.x = new_x; |
---|
1466 | 1464 | } |
---|
1467 | 1465 | |
---|
1468 | 1466 | if (vc->vc_decom) { |
---|
.. | .. |
---|
1473 | 1471 | max_y = vc->vc_rows; |
---|
1474 | 1472 | } |
---|
1475 | 1473 | if (new_y < min_y) |
---|
1476 | | - vc->vc_y = min_y; |
---|
| 1474 | + vc->state.y = min_y; |
---|
1477 | 1475 | else if (new_y >= max_y) |
---|
1478 | | - vc->vc_y = max_y - 1; |
---|
| 1476 | + vc->state.y = max_y - 1; |
---|
1479 | 1477 | else |
---|
1480 | | - vc->vc_y = new_y; |
---|
1481 | | - vc->vc_pos = vc->vc_origin + vc->vc_y * vc->vc_size_row + (vc->vc_x<<1); |
---|
| 1478 | + vc->state.y = new_y; |
---|
| 1479 | + vc->vc_pos = vc->vc_origin + vc->state.y * vc->vc_size_row + |
---|
| 1480 | + (vc->state.x << 1); |
---|
1482 | 1481 | vc->vc_need_wrap = 0; |
---|
1483 | 1482 | } |
---|
1484 | 1483 | |
---|
.. | .. |
---|
1505 | 1504 | /* don't scroll if above bottom of scrolling region, or |
---|
1506 | 1505 | * if below scrolling region |
---|
1507 | 1506 | */ |
---|
1508 | | - if (vc->vc_y + 1 == vc->vc_bottom) |
---|
| 1507 | + if (vc->state.y + 1 == vc->vc_bottom) |
---|
1509 | 1508 | con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_UP, 1); |
---|
1510 | | - else if (vc->vc_y < vc->vc_rows - 1) { |
---|
1511 | | - vc->vc_y++; |
---|
| 1509 | + else if (vc->state.y < vc->vc_rows - 1) { |
---|
| 1510 | + vc->state.y++; |
---|
1512 | 1511 | vc->vc_pos += vc->vc_size_row; |
---|
1513 | 1512 | } |
---|
1514 | 1513 | vc->vc_need_wrap = 0; |
---|
.. | .. |
---|
1520 | 1519 | /* don't scroll if below top of scrolling region, or |
---|
1521 | 1520 | * if above scrolling region |
---|
1522 | 1521 | */ |
---|
1523 | | - if (vc->vc_y == vc->vc_top) |
---|
| 1522 | + if (vc->state.y == vc->vc_top) |
---|
1524 | 1523 | con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_DOWN, 1); |
---|
1525 | | - else if (vc->vc_y > 0) { |
---|
1526 | | - vc->vc_y--; |
---|
| 1524 | + else if (vc->state.y > 0) { |
---|
| 1525 | + vc->state.y--; |
---|
1527 | 1526 | vc->vc_pos -= vc->vc_size_row; |
---|
1528 | 1527 | } |
---|
1529 | 1528 | vc->vc_need_wrap = 0; |
---|
.. | .. |
---|
1531 | 1530 | |
---|
1532 | 1531 | static inline void cr(struct vc_data *vc) |
---|
1533 | 1532 | { |
---|
1534 | | - vc->vc_pos -= vc->vc_x << 1; |
---|
1535 | | - vc->vc_need_wrap = vc->vc_x = 0; |
---|
| 1533 | + vc->vc_pos -= vc->state.x << 1; |
---|
| 1534 | + vc->vc_need_wrap = vc->state.x = 0; |
---|
1536 | 1535 | notify_write(vc, '\r'); |
---|
1537 | 1536 | } |
---|
1538 | 1537 | |
---|
1539 | 1538 | static inline void bs(struct vc_data *vc) |
---|
1540 | 1539 | { |
---|
1541 | | - if (vc->vc_x) { |
---|
| 1540 | + if (vc->state.x) { |
---|
1542 | 1541 | vc->vc_pos -= 2; |
---|
1543 | | - vc->vc_x--; |
---|
| 1542 | + vc->state.x--; |
---|
1544 | 1543 | vc->vc_need_wrap = 0; |
---|
1545 | 1544 | notify_write(vc, '\b'); |
---|
1546 | 1545 | } |
---|
.. | .. |
---|
1558 | 1557 | |
---|
1559 | 1558 | switch (vpar) { |
---|
1560 | 1559 | case 0: /* erase from cursor to end of display */ |
---|
1561 | | - vc_uniscr_clear_line(vc, vc->vc_x, |
---|
1562 | | - vc->vc_cols - vc->vc_x); |
---|
1563 | | - vc_uniscr_clear_lines(vc, vc->vc_y + 1, |
---|
1564 | | - vc->vc_rows - vc->vc_y - 1); |
---|
| 1560 | + vc_uniscr_clear_line(vc, vc->state.x, |
---|
| 1561 | + vc->vc_cols - vc->state.x); |
---|
| 1562 | + vc_uniscr_clear_lines(vc, vc->state.y + 1, |
---|
| 1563 | + vc->vc_rows - vc->state.y - 1); |
---|
1565 | 1564 | count = (vc->vc_scr_end - vc->vc_pos) >> 1; |
---|
1566 | 1565 | start = (unsigned short *)vc->vc_pos; |
---|
1567 | 1566 | break; |
---|
1568 | 1567 | case 1: /* erase from start to cursor */ |
---|
1569 | | - vc_uniscr_clear_line(vc, 0, vc->vc_x + 1); |
---|
1570 | | - vc_uniscr_clear_lines(vc, 0, vc->vc_y); |
---|
| 1568 | + vc_uniscr_clear_line(vc, 0, vc->state.x + 1); |
---|
| 1569 | + vc_uniscr_clear_lines(vc, 0, vc->state.y); |
---|
1571 | 1570 | count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1; |
---|
1572 | 1571 | start = (unsigned short *)vc->vc_origin; |
---|
1573 | 1572 | break; |
---|
1574 | 1573 | case 3: /* include scrollback */ |
---|
1575 | 1574 | flush_scrollback(vc); |
---|
1576 | | - /* fallthrough */ |
---|
| 1575 | + fallthrough; |
---|
1577 | 1576 | case 2: /* erase whole display */ |
---|
1578 | 1577 | vc_uniscr_clear_lines(vc, 0, vc->vc_rows); |
---|
1579 | 1578 | count = vc->vc_cols * vc->vc_rows; |
---|
.. | .. |
---|
1597 | 1596 | switch (vpar) { |
---|
1598 | 1597 | case 0: /* erase from cursor to end of line */ |
---|
1599 | 1598 | offset = 0; |
---|
1600 | | - count = vc->vc_cols - vc->vc_x; |
---|
| 1599 | + count = vc->vc_cols - vc->state.x; |
---|
1601 | 1600 | break; |
---|
1602 | 1601 | case 1: /* erase from start of line to cursor */ |
---|
1603 | | - offset = -vc->vc_x; |
---|
1604 | | - count = vc->vc_x + 1; |
---|
| 1602 | + offset = -vc->state.x; |
---|
| 1603 | + count = vc->state.x + 1; |
---|
1605 | 1604 | break; |
---|
1606 | 1605 | case 2: /* erase whole line */ |
---|
1607 | | - offset = -vc->vc_x; |
---|
| 1606 | + offset = -vc->state.x; |
---|
1608 | 1607 | count = vc->vc_cols; |
---|
1609 | 1608 | break; |
---|
1610 | 1609 | default: |
---|
1611 | 1610 | return; |
---|
1612 | 1611 | } |
---|
1613 | | - vc_uniscr_clear_line(vc, vc->vc_x + offset, count); |
---|
| 1612 | + vc_uniscr_clear_line(vc, vc->state.x + offset, count); |
---|
1614 | 1613 | scr_memsetw(start + offset, vc->vc_video_erase_char, 2 * count); |
---|
1615 | 1614 | vc->vc_need_wrap = 0; |
---|
1616 | 1615 | if (con_should_update(vc)) |
---|
1617 | 1616 | do_update_region(vc, (unsigned long)(start + offset), count); |
---|
1618 | 1617 | } |
---|
1619 | 1618 | |
---|
1620 | | -static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */ |
---|
| 1619 | +/* erase the following vpar positions */ |
---|
| 1620 | +static void csi_X(struct vc_data *vc, unsigned int vpar) |
---|
1621 | 1621 | { /* not vt100? */ |
---|
1622 | | - int count; |
---|
| 1622 | + unsigned int count; |
---|
1623 | 1623 | |
---|
1624 | 1624 | if (!vpar) |
---|
1625 | 1625 | vpar++; |
---|
1626 | | - count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar; |
---|
1627 | 1626 | |
---|
1628 | | - vc_uniscr_clear_line(vc, vc->vc_x, count); |
---|
| 1627 | + count = min(vpar, vc->vc_cols - vc->state.x); |
---|
| 1628 | + |
---|
| 1629 | + vc_uniscr_clear_line(vc, vc->state.x, count); |
---|
1629 | 1630 | scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); |
---|
1630 | 1631 | if (con_should_update(vc)) |
---|
1631 | | - vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count); |
---|
| 1632 | + vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, 1, count); |
---|
1632 | 1633 | vc->vc_need_wrap = 0; |
---|
1633 | 1634 | } |
---|
1634 | 1635 | |
---|
1635 | 1636 | static void default_attr(struct vc_data *vc) |
---|
1636 | 1637 | { |
---|
1637 | | - vc->vc_intensity = 1; |
---|
1638 | | - vc->vc_italic = 0; |
---|
1639 | | - vc->vc_underline = 0; |
---|
1640 | | - vc->vc_reverse = 0; |
---|
1641 | | - vc->vc_blink = 0; |
---|
1642 | | - vc->vc_color = vc->vc_def_color; |
---|
| 1638 | + vc->state.intensity = VCI_NORMAL; |
---|
| 1639 | + vc->state.italic = false; |
---|
| 1640 | + vc->state.underline = false; |
---|
| 1641 | + vc->state.reverse = false; |
---|
| 1642 | + vc->state.blink = false; |
---|
| 1643 | + vc->state.color = vc->vc_def_color; |
---|
1643 | 1644 | } |
---|
1644 | 1645 | |
---|
1645 | 1646 | struct rgb { u8 r; u8 g; u8 b; }; |
---|
.. | .. |
---|
1675 | 1676 | |
---|
1676 | 1677 | if (hue == 7 && max <= 0x55) { |
---|
1677 | 1678 | hue = 0; |
---|
1678 | | - vc->vc_intensity = 2; |
---|
| 1679 | + vc->state.intensity = VCI_BOLD; |
---|
1679 | 1680 | } else if (max > 0xaa) |
---|
1680 | | - vc->vc_intensity = 2; |
---|
| 1681 | + vc->state.intensity = VCI_BOLD; |
---|
1681 | 1682 | else |
---|
1682 | | - vc->vc_intensity = 1; |
---|
| 1683 | + vc->state.intensity = VCI_NORMAL; |
---|
1683 | 1684 | |
---|
1684 | | - vc->vc_color = (vc->vc_color & 0xf0) | hue; |
---|
| 1685 | + vc->state.color = (vc->state.color & 0xf0) | hue; |
---|
1685 | 1686 | } |
---|
1686 | 1687 | |
---|
1687 | 1688 | static void rgb_background(struct vc_data *vc, const struct rgb *c) |
---|
1688 | 1689 | { |
---|
1689 | 1690 | /* For backgrounds, err on the dark side. */ |
---|
1690 | | - vc->vc_color = (vc->vc_color & 0x0f) |
---|
| 1691 | + vc->state.color = (vc->state.color & 0x0f) |
---|
1691 | 1692 | | (c->r&0x80) >> 1 | (c->g&0x80) >> 2 | (c->b&0x80) >> 3; |
---|
1692 | 1693 | } |
---|
1693 | 1694 | |
---|
1694 | 1695 | /* |
---|
1695 | 1696 | * ITU T.416 Higher colour modes. They break the usual properties of SGR codes |
---|
1696 | | - * and thus need to be detected and ignored by hand. Strictly speaking, that |
---|
1697 | | - * standard also wants : rather than ; as separators, contrary to ECMA-48, but |
---|
1698 | | - * no one produces such codes and almost no one accepts them. |
---|
| 1697 | + * and thus need to be detected and ignored by hand. That standard also |
---|
| 1698 | + * wants : rather than ; as separators but sequences containing : are currently |
---|
| 1699 | + * completely ignored by the parser. |
---|
1699 | 1700 | * |
---|
1700 | 1701 | * Subcommands 3 (CMY) and 4 (CMYK) are so insane there's no point in |
---|
1701 | 1702 | * supporting them. |
---|
.. | .. |
---|
1738 | 1739 | default_attr(vc); |
---|
1739 | 1740 | break; |
---|
1740 | 1741 | case 1: |
---|
1741 | | - vc->vc_intensity = 2; |
---|
| 1742 | + vc->state.intensity = VCI_BOLD; |
---|
1742 | 1743 | break; |
---|
1743 | 1744 | case 2: |
---|
1744 | | - vc->vc_intensity = 0; |
---|
| 1745 | + vc->state.intensity = VCI_HALF_BRIGHT; |
---|
1745 | 1746 | break; |
---|
1746 | 1747 | case 3: |
---|
1747 | | - vc->vc_italic = 1; |
---|
| 1748 | + vc->state.italic = true; |
---|
1748 | 1749 | break; |
---|
1749 | 1750 | case 21: |
---|
1750 | 1751 | /* |
---|
.. | .. |
---|
1752 | 1753 | * convert it to a single underline. |
---|
1753 | 1754 | */ |
---|
1754 | 1755 | case 4: |
---|
1755 | | - vc->vc_underline = 1; |
---|
| 1756 | + vc->state.underline = true; |
---|
1756 | 1757 | break; |
---|
1757 | 1758 | case 5: |
---|
1758 | | - vc->vc_blink = 1; |
---|
| 1759 | + vc->state.blink = true; |
---|
1759 | 1760 | break; |
---|
1760 | 1761 | case 7: |
---|
1761 | | - vc->vc_reverse = 1; |
---|
| 1762 | + vc->state.reverse = true; |
---|
1762 | 1763 | break; |
---|
1763 | 1764 | case 10: /* ANSI X3.64-1979 (SCO-ish?) |
---|
1764 | 1765 | * Select primary font, don't display control chars if |
---|
1765 | 1766 | * defined, don't set bit 8 on output. |
---|
1766 | 1767 | */ |
---|
1767 | | - vc->vc_translate = set_translate(vc->vc_charset == 0 |
---|
1768 | | - ? vc->vc_G0_charset |
---|
1769 | | - : vc->vc_G1_charset, vc); |
---|
| 1768 | + vc->vc_translate = set_translate(vc->state.Gx_charset[vc->state.charset], vc); |
---|
1770 | 1769 | vc->vc_disp_ctrl = 0; |
---|
1771 | 1770 | vc->vc_toggle_meta = 0; |
---|
1772 | 1771 | break; |
---|
.. | .. |
---|
1787 | 1786 | vc->vc_toggle_meta = 1; |
---|
1788 | 1787 | break; |
---|
1789 | 1788 | case 22: |
---|
1790 | | - vc->vc_intensity = 1; |
---|
| 1789 | + vc->state.intensity = VCI_NORMAL; |
---|
1791 | 1790 | break; |
---|
1792 | 1791 | case 23: |
---|
1793 | | - vc->vc_italic = 0; |
---|
| 1792 | + vc->state.italic = false; |
---|
1794 | 1793 | break; |
---|
1795 | 1794 | case 24: |
---|
1796 | | - vc->vc_underline = 0; |
---|
| 1795 | + vc->state.underline = false; |
---|
1797 | 1796 | break; |
---|
1798 | 1797 | case 25: |
---|
1799 | | - vc->vc_blink = 0; |
---|
| 1798 | + vc->state.blink = false; |
---|
1800 | 1799 | break; |
---|
1801 | 1800 | case 27: |
---|
1802 | | - vc->vc_reverse = 0; |
---|
| 1801 | + vc->state.reverse = false; |
---|
1803 | 1802 | break; |
---|
1804 | 1803 | case 38: |
---|
1805 | 1804 | i = vc_t416_color(vc, i, rgb_foreground); |
---|
.. | .. |
---|
1808 | 1807 | i = vc_t416_color(vc, i, rgb_background); |
---|
1809 | 1808 | break; |
---|
1810 | 1809 | case 39: |
---|
1811 | | - vc->vc_color = (vc->vc_def_color & 0x0f) | |
---|
1812 | | - (vc->vc_color & 0xf0); |
---|
| 1810 | + vc->state.color = (vc->vc_def_color & 0x0f) | |
---|
| 1811 | + (vc->state.color & 0xf0); |
---|
1813 | 1812 | break; |
---|
1814 | 1813 | case 49: |
---|
1815 | | - vc->vc_color = (vc->vc_def_color & 0xf0) | |
---|
1816 | | - (vc->vc_color & 0x0f); |
---|
| 1814 | + vc->state.color = (vc->vc_def_color & 0xf0) | |
---|
| 1815 | + (vc->state.color & 0x0f); |
---|
1817 | 1816 | break; |
---|
1818 | 1817 | default: |
---|
1819 | 1818 | if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) { |
---|
1820 | 1819 | if (vc->vc_par[i] < 100) |
---|
1821 | | - vc->vc_intensity = 2; |
---|
| 1820 | + vc->state.intensity = VCI_BOLD; |
---|
1822 | 1821 | vc->vc_par[i] -= 60; |
---|
1823 | 1822 | } |
---|
1824 | 1823 | if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37) |
---|
1825 | | - vc->vc_color = color_table[vc->vc_par[i] - 30] |
---|
1826 | | - | (vc->vc_color & 0xf0); |
---|
| 1824 | + vc->state.color = color_table[vc->vc_par[i] - 30] |
---|
| 1825 | + | (vc->state.color & 0xf0); |
---|
1827 | 1826 | else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47) |
---|
1828 | | - vc->vc_color = (color_table[vc->vc_par[i] - 40] << 4) |
---|
1829 | | - | (vc->vc_color & 0x0f); |
---|
| 1827 | + vc->state.color = (color_table[vc->vc_par[i] - 40] << 4) |
---|
| 1828 | + | (vc->state.color & 0x0f); |
---|
1830 | 1829 | break; |
---|
1831 | 1830 | } |
---|
1832 | 1831 | update_attr(vc); |
---|
1833 | 1832 | } |
---|
1834 | 1833 | |
---|
1835 | | -static void respond_string(const char *p, struct tty_port *port) |
---|
| 1834 | +static void respond_string(const char *p, size_t len, struct tty_port *port) |
---|
1836 | 1835 | { |
---|
1837 | | - while (*p) { |
---|
1838 | | - tty_insert_flip_char(port, *p, 0); |
---|
1839 | | - p++; |
---|
1840 | | - } |
---|
1841 | | - tty_schedule_flip(port); |
---|
| 1836 | + tty_insert_flip_string(port, p, len); |
---|
| 1837 | + tty_flip_buffer_push(port); |
---|
1842 | 1838 | } |
---|
1843 | 1839 | |
---|
1844 | 1840 | static void cursor_report(struct vc_data *vc, struct tty_struct *tty) |
---|
1845 | 1841 | { |
---|
1846 | 1842 | char buf[40]; |
---|
| 1843 | + int len; |
---|
1847 | 1844 | |
---|
1848 | | - sprintf(buf, "\033[%d;%dR", vc->vc_y + (vc->vc_decom ? vc->vc_top + 1 : 1), vc->vc_x + 1); |
---|
1849 | | - respond_string(buf, tty->port); |
---|
| 1845 | + len = sprintf(buf, "\033[%d;%dR", vc->state.y + |
---|
| 1846 | + (vc->vc_decom ? vc->vc_top + 1 : 1), |
---|
| 1847 | + vc->state.x + 1); |
---|
| 1848 | + respond_string(buf, len, tty->port); |
---|
1850 | 1849 | } |
---|
1851 | 1850 | |
---|
1852 | 1851 | static inline void status_report(struct tty_struct *tty) |
---|
1853 | 1852 | { |
---|
1854 | | - respond_string("\033[0n", tty->port); /* Terminal ok */ |
---|
| 1853 | + static const char teminal_ok[] = "\033[0n"; |
---|
| 1854 | + |
---|
| 1855 | + respond_string(teminal_ok, strlen(teminal_ok), tty->port); |
---|
1855 | 1856 | } |
---|
1856 | 1857 | |
---|
1857 | 1858 | static inline void respond_ID(struct tty_struct *tty) |
---|
1858 | 1859 | { |
---|
1859 | | - respond_string(VT102ID, tty->port); |
---|
| 1860 | + /* terminal answer to an ESC-Z or csi0c query. */ |
---|
| 1861 | + static const char vt102_id[] = "\033[?6c"; |
---|
| 1862 | + |
---|
| 1863 | + respond_string(vt102_id, strlen(vt102_id), tty->port); |
---|
1860 | 1864 | } |
---|
1861 | 1865 | |
---|
1862 | 1866 | void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry) |
---|
1863 | 1867 | { |
---|
1864 | 1868 | char buf[8]; |
---|
| 1869 | + int len; |
---|
1865 | 1870 | |
---|
1866 | | - sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx), |
---|
1867 | | - (char)('!' + mry)); |
---|
1868 | | - respond_string(buf, tty->port); |
---|
| 1871 | + len = sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), |
---|
| 1872 | + (char)('!' + mrx), (char)('!' + mry)); |
---|
| 1873 | + respond_string(buf, len, tty->port); |
---|
1869 | 1874 | } |
---|
1870 | 1875 | |
---|
1871 | | -/* invoked via ioctl(TIOCLINUX) and through set_selection */ |
---|
| 1876 | +/* invoked via ioctl(TIOCLINUX) and through set_selection_user */ |
---|
1872 | 1877 | int mouse_reporting(void) |
---|
1873 | 1878 | { |
---|
1874 | 1879 | return vc_cons[fg_console].d->vc_report_mouse; |
---|
.. | .. |
---|
1880 | 1885 | int i; |
---|
1881 | 1886 | |
---|
1882 | 1887 | for (i = 0; i <= vc->vc_npar; i++) |
---|
1883 | | - if (vc->vc_ques) { |
---|
| 1888 | + if (vc->vc_priv == EPdec) { |
---|
1884 | 1889 | switch(vc->vc_par[i]) { /* DEC private modes set/reset */ |
---|
1885 | 1890 | case 1: /* Cursor keys send ^[Ox/^[[x */ |
---|
1886 | 1891 | if (on_off) |
---|
.. | .. |
---|
1898 | 1903 | case 5: /* Inverted screen on/off */ |
---|
1899 | 1904 | if (vc->vc_decscnm != on_off) { |
---|
1900 | 1905 | vc->vc_decscnm = on_off; |
---|
1901 | | - invert_screen(vc, 0, vc->vc_screenbuf_size, 0); |
---|
| 1906 | + invert_screen(vc, 0, |
---|
| 1907 | + vc->vc_screenbuf_size, |
---|
| 1908 | + false); |
---|
1902 | 1909 | update_attr(vc); |
---|
1903 | 1910 | } |
---|
1904 | 1911 | break; |
---|
.. | .. |
---|
1946 | 1953 | /* console_lock is held */ |
---|
1947 | 1954 | static void setterm_command(struct vc_data *vc) |
---|
1948 | 1955 | { |
---|
1949 | | - switch(vc->vc_par[0]) { |
---|
1950 | | - case 1: /* set color for underline mode */ |
---|
1951 | | - if (vc->vc_can_do_color && |
---|
1952 | | - vc->vc_par[1] < 16) { |
---|
1953 | | - vc->vc_ulcolor = color_table[vc->vc_par[1]]; |
---|
1954 | | - if (vc->vc_underline) |
---|
1955 | | - update_attr(vc); |
---|
1956 | | - } |
---|
1957 | | - break; |
---|
1958 | | - case 2: /* set color for half intensity mode */ |
---|
1959 | | - if (vc->vc_can_do_color && |
---|
1960 | | - vc->vc_par[1] < 16) { |
---|
1961 | | - vc->vc_halfcolor = color_table[vc->vc_par[1]]; |
---|
1962 | | - if (vc->vc_intensity == 0) |
---|
1963 | | - update_attr(vc); |
---|
1964 | | - } |
---|
1965 | | - break; |
---|
1966 | | - case 8: /* store colors as defaults */ |
---|
1967 | | - vc->vc_def_color = vc->vc_attr; |
---|
1968 | | - if (vc->vc_hi_font_mask == 0x100) |
---|
1969 | | - vc->vc_def_color >>= 1; |
---|
1970 | | - default_attr(vc); |
---|
1971 | | - update_attr(vc); |
---|
1972 | | - break; |
---|
1973 | | - case 9: /* set blanking interval */ |
---|
1974 | | - blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60; |
---|
1975 | | - poke_blanked_console(); |
---|
1976 | | - break; |
---|
1977 | | - case 10: /* set bell frequency in Hz */ |
---|
1978 | | - if (vc->vc_npar >= 1) |
---|
1979 | | - vc->vc_bell_pitch = vc->vc_par[1]; |
---|
1980 | | - else |
---|
1981 | | - vc->vc_bell_pitch = DEFAULT_BELL_PITCH; |
---|
1982 | | - break; |
---|
1983 | | - case 11: /* set bell duration in msec */ |
---|
1984 | | - if (vc->vc_npar >= 1) |
---|
1985 | | - vc->vc_bell_duration = (vc->vc_par[1] < 2000) ? |
---|
1986 | | - msecs_to_jiffies(vc->vc_par[1]) : 0; |
---|
1987 | | - else |
---|
1988 | | - vc->vc_bell_duration = DEFAULT_BELL_DURATION; |
---|
1989 | | - break; |
---|
1990 | | - case 12: /* bring specified console to the front */ |
---|
1991 | | - if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1)) |
---|
1992 | | - set_console(vc->vc_par[1] - 1); |
---|
1993 | | - break; |
---|
1994 | | - case 13: /* unblank the screen */ |
---|
1995 | | - poke_blanked_console(); |
---|
1996 | | - break; |
---|
1997 | | - case 14: /* set vesa powerdown interval */ |
---|
1998 | | - vesa_off_interval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ; |
---|
1999 | | - break; |
---|
2000 | | - case 15: /* activate the previous console */ |
---|
2001 | | - set_console(last_console); |
---|
2002 | | - break; |
---|
2003 | | - case 16: /* set cursor blink duration in msec */ |
---|
2004 | | - if (vc->vc_npar >= 1 && vc->vc_par[1] >= 50 && |
---|
2005 | | - vc->vc_par[1] <= USHRT_MAX) |
---|
2006 | | - vc->vc_cur_blink_ms = vc->vc_par[1]; |
---|
2007 | | - else |
---|
2008 | | - vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS; |
---|
2009 | | - break; |
---|
| 1956 | + switch (vc->vc_par[0]) { |
---|
| 1957 | + case 1: /* set color for underline mode */ |
---|
| 1958 | + if (vc->vc_can_do_color && vc->vc_par[1] < 16) { |
---|
| 1959 | + vc->vc_ulcolor = color_table[vc->vc_par[1]]; |
---|
| 1960 | + if (vc->state.underline) |
---|
| 1961 | + update_attr(vc); |
---|
| 1962 | + } |
---|
| 1963 | + break; |
---|
| 1964 | + case 2: /* set color for half intensity mode */ |
---|
| 1965 | + if (vc->vc_can_do_color && vc->vc_par[1] < 16) { |
---|
| 1966 | + vc->vc_halfcolor = color_table[vc->vc_par[1]]; |
---|
| 1967 | + if (vc->state.intensity == VCI_HALF_BRIGHT) |
---|
| 1968 | + update_attr(vc); |
---|
| 1969 | + } |
---|
| 1970 | + break; |
---|
| 1971 | + case 8: /* store colors as defaults */ |
---|
| 1972 | + vc->vc_def_color = vc->vc_attr; |
---|
| 1973 | + if (vc->vc_hi_font_mask == 0x100) |
---|
| 1974 | + vc->vc_def_color >>= 1; |
---|
| 1975 | + default_attr(vc); |
---|
| 1976 | + update_attr(vc); |
---|
| 1977 | + break; |
---|
| 1978 | + case 9: /* set blanking interval */ |
---|
| 1979 | + blankinterval = min(vc->vc_par[1], 60U) * 60; |
---|
| 1980 | + poke_blanked_console(); |
---|
| 1981 | + break; |
---|
| 1982 | + case 10: /* set bell frequency in Hz */ |
---|
| 1983 | + if (vc->vc_npar >= 1) |
---|
| 1984 | + vc->vc_bell_pitch = vc->vc_par[1]; |
---|
| 1985 | + else |
---|
| 1986 | + vc->vc_bell_pitch = DEFAULT_BELL_PITCH; |
---|
| 1987 | + break; |
---|
| 1988 | + case 11: /* set bell duration in msec */ |
---|
| 1989 | + if (vc->vc_npar >= 1) |
---|
| 1990 | + vc->vc_bell_duration = (vc->vc_par[1] < 2000) ? |
---|
| 1991 | + msecs_to_jiffies(vc->vc_par[1]) : 0; |
---|
| 1992 | + else |
---|
| 1993 | + vc->vc_bell_duration = DEFAULT_BELL_DURATION; |
---|
| 1994 | + break; |
---|
| 1995 | + case 12: /* bring specified console to the front */ |
---|
| 1996 | + if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1)) |
---|
| 1997 | + set_console(vc->vc_par[1] - 1); |
---|
| 1998 | + break; |
---|
| 1999 | + case 13: /* unblank the screen */ |
---|
| 2000 | + poke_blanked_console(); |
---|
| 2001 | + break; |
---|
| 2002 | + case 14: /* set vesa powerdown interval */ |
---|
| 2003 | + vesa_off_interval = min(vc->vc_par[1], 60U) * 60 * HZ; |
---|
| 2004 | + break; |
---|
| 2005 | + case 15: /* activate the previous console */ |
---|
| 2006 | + set_console(last_console); |
---|
| 2007 | + break; |
---|
| 2008 | + case 16: /* set cursor blink duration in msec */ |
---|
| 2009 | + if (vc->vc_npar >= 1 && vc->vc_par[1] >= 50 && |
---|
| 2010 | + vc->vc_par[1] <= USHRT_MAX) |
---|
| 2011 | + vc->vc_cur_blink_ms = vc->vc_par[1]; |
---|
| 2012 | + else |
---|
| 2013 | + vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS; |
---|
| 2014 | + break; |
---|
2010 | 2015 | } |
---|
2011 | 2016 | } |
---|
2012 | 2017 | |
---|
2013 | 2018 | /* console_lock is held */ |
---|
2014 | 2019 | static void csi_at(struct vc_data *vc, unsigned int nr) |
---|
2015 | 2020 | { |
---|
2016 | | - if (nr > vc->vc_cols - vc->vc_x) |
---|
2017 | | - nr = vc->vc_cols - vc->vc_x; |
---|
| 2021 | + if (nr > vc->vc_cols - vc->state.x) |
---|
| 2022 | + nr = vc->vc_cols - vc->state.x; |
---|
2018 | 2023 | else if (!nr) |
---|
2019 | 2024 | nr = 1; |
---|
2020 | 2025 | insert_char(vc, nr); |
---|
.. | .. |
---|
2023 | 2028 | /* console_lock is held */ |
---|
2024 | 2029 | static void csi_L(struct vc_data *vc, unsigned int nr) |
---|
2025 | 2030 | { |
---|
2026 | | - if (nr > vc->vc_rows - vc->vc_y) |
---|
2027 | | - nr = vc->vc_rows - vc->vc_y; |
---|
| 2031 | + if (nr > vc->vc_rows - vc->state.y) |
---|
| 2032 | + nr = vc->vc_rows - vc->state.y; |
---|
2028 | 2033 | else if (!nr) |
---|
2029 | 2034 | nr = 1; |
---|
2030 | | - con_scroll(vc, vc->vc_y, vc->vc_bottom, SM_DOWN, nr); |
---|
| 2035 | + con_scroll(vc, vc->state.y, vc->vc_bottom, SM_DOWN, nr); |
---|
2031 | 2036 | vc->vc_need_wrap = 0; |
---|
2032 | 2037 | } |
---|
2033 | 2038 | |
---|
2034 | 2039 | /* console_lock is held */ |
---|
2035 | 2040 | static void csi_P(struct vc_data *vc, unsigned int nr) |
---|
2036 | 2041 | { |
---|
2037 | | - if (nr > vc->vc_cols - vc->vc_x) |
---|
2038 | | - nr = vc->vc_cols - vc->vc_x; |
---|
| 2042 | + if (nr > vc->vc_cols - vc->state.x) |
---|
| 2043 | + nr = vc->vc_cols - vc->state.x; |
---|
2039 | 2044 | else if (!nr) |
---|
2040 | 2045 | nr = 1; |
---|
2041 | 2046 | delete_char(vc, nr); |
---|
.. | .. |
---|
2044 | 2049 | /* console_lock is held */ |
---|
2045 | 2050 | static void csi_M(struct vc_data *vc, unsigned int nr) |
---|
2046 | 2051 | { |
---|
2047 | | - if (nr > vc->vc_rows - vc->vc_y) |
---|
2048 | | - nr = vc->vc_rows - vc->vc_y; |
---|
| 2052 | + if (nr > vc->vc_rows - vc->state.y) |
---|
| 2053 | + nr = vc->vc_rows - vc->state.y; |
---|
2049 | 2054 | else if (!nr) |
---|
2050 | 2055 | nr=1; |
---|
2051 | | - con_scroll(vc, vc->vc_y, vc->vc_bottom, SM_UP, nr); |
---|
| 2056 | + con_scroll(vc, vc->state.y, vc->vc_bottom, SM_UP, nr); |
---|
2052 | 2057 | vc->vc_need_wrap = 0; |
---|
2053 | 2058 | } |
---|
2054 | 2059 | |
---|
2055 | 2060 | /* console_lock is held (except via vc_init->reset_terminal */ |
---|
2056 | 2061 | static void save_cur(struct vc_data *vc) |
---|
2057 | 2062 | { |
---|
2058 | | - vc->vc_saved_x = vc->vc_x; |
---|
2059 | | - vc->vc_saved_y = vc->vc_y; |
---|
2060 | | - vc->vc_s_intensity = vc->vc_intensity; |
---|
2061 | | - vc->vc_s_italic = vc->vc_italic; |
---|
2062 | | - vc->vc_s_underline = vc->vc_underline; |
---|
2063 | | - vc->vc_s_blink = vc->vc_blink; |
---|
2064 | | - vc->vc_s_reverse = vc->vc_reverse; |
---|
2065 | | - vc->vc_s_charset = vc->vc_charset; |
---|
2066 | | - vc->vc_s_color = vc->vc_color; |
---|
2067 | | - vc->vc_saved_G0 = vc->vc_G0_charset; |
---|
2068 | | - vc->vc_saved_G1 = vc->vc_G1_charset; |
---|
| 2063 | + memcpy(&vc->saved_state, &vc->state, sizeof(vc->state)); |
---|
2069 | 2064 | } |
---|
2070 | 2065 | |
---|
2071 | 2066 | /* console_lock is held */ |
---|
2072 | 2067 | static void restore_cur(struct vc_data *vc) |
---|
2073 | 2068 | { |
---|
2074 | | - gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y); |
---|
2075 | | - vc->vc_intensity = vc->vc_s_intensity; |
---|
2076 | | - vc->vc_italic = vc->vc_s_italic; |
---|
2077 | | - vc->vc_underline = vc->vc_s_underline; |
---|
2078 | | - vc->vc_blink = vc->vc_s_blink; |
---|
2079 | | - vc->vc_reverse = vc->vc_s_reverse; |
---|
2080 | | - vc->vc_charset = vc->vc_s_charset; |
---|
2081 | | - vc->vc_color = vc->vc_s_color; |
---|
2082 | | - vc->vc_G0_charset = vc->vc_saved_G0; |
---|
2083 | | - vc->vc_G1_charset = vc->vc_saved_G1; |
---|
2084 | | - vc->vc_translate = set_translate(vc->vc_charset ? vc->vc_G1_charset : vc->vc_G0_charset, vc); |
---|
| 2069 | + memcpy(&vc->state, &vc->saved_state, sizeof(vc->state)); |
---|
| 2070 | + |
---|
| 2071 | + gotoxy(vc, vc->state.x, vc->state.y); |
---|
| 2072 | + vc->vc_translate = set_translate(vc->state.Gx_charset[vc->state.charset], |
---|
| 2073 | + vc); |
---|
2085 | 2074 | update_attr(vc); |
---|
2086 | 2075 | vc->vc_need_wrap = 0; |
---|
2087 | 2076 | } |
---|
2088 | 2077 | |
---|
2089 | 2078 | enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, |
---|
2090 | | - EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, |
---|
2091 | | - ESpalette, ESosc }; |
---|
| 2079 | + EShash, ESsetG0, ESsetG1, ESpercent, EScsiignore, ESnonstd, |
---|
| 2080 | + ESpalette, ESosc, ESapc, ESpm, ESdcs }; |
---|
2092 | 2081 | |
---|
2093 | 2082 | /* console_lock is held (except via vc_init()) */ |
---|
2094 | 2083 | static void reset_terminal(struct vc_data *vc, int do_clear) |
---|
2095 | 2084 | { |
---|
| 2085 | + unsigned int i; |
---|
| 2086 | + |
---|
2096 | 2087 | vc->vc_top = 0; |
---|
2097 | 2088 | vc->vc_bottom = vc->vc_rows; |
---|
2098 | 2089 | vc->vc_state = ESnormal; |
---|
2099 | | - vc->vc_ques = 0; |
---|
| 2090 | + vc->vc_priv = EPecma; |
---|
2100 | 2091 | vc->vc_translate = set_translate(LAT1_MAP, vc); |
---|
2101 | | - vc->vc_G0_charset = LAT1_MAP; |
---|
2102 | | - vc->vc_G1_charset = GRAF_MAP; |
---|
2103 | | - vc->vc_charset = 0; |
---|
| 2092 | + vc->state.Gx_charset[0] = LAT1_MAP; |
---|
| 2093 | + vc->state.Gx_charset[1] = GRAF_MAP; |
---|
| 2094 | + vc->state.charset = 0; |
---|
2104 | 2095 | vc->vc_need_wrap = 0; |
---|
2105 | 2096 | vc->vc_report_mouse = 0; |
---|
2106 | 2097 | vc->vc_utf = default_utf8; |
---|
.. | .. |
---|
2123 | 2114 | default_attr(vc); |
---|
2124 | 2115 | update_attr(vc); |
---|
2125 | 2116 | |
---|
2126 | | - vc->vc_tab_stop[0] = |
---|
2127 | | - vc->vc_tab_stop[1] = |
---|
2128 | | - vc->vc_tab_stop[2] = |
---|
2129 | | - vc->vc_tab_stop[3] = |
---|
2130 | | - vc->vc_tab_stop[4] = |
---|
2131 | | - vc->vc_tab_stop[5] = |
---|
2132 | | - vc->vc_tab_stop[6] = |
---|
2133 | | - vc->vc_tab_stop[7] = 0x01010101; |
---|
| 2117 | + bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT); |
---|
| 2118 | + for (i = 0; i < VC_TABSTOPS_COUNT; i += 8) |
---|
| 2119 | + set_bit(i, vc->vc_tab_stop); |
---|
2134 | 2120 | |
---|
2135 | 2121 | vc->vc_bell_pitch = DEFAULT_BELL_PITCH; |
---|
2136 | 2122 | vc->vc_bell_duration = DEFAULT_BELL_DURATION; |
---|
.. | .. |
---|
2142 | 2128 | csi_J(vc, 2); |
---|
2143 | 2129 | } |
---|
2144 | 2130 | |
---|
| 2131 | +static void vc_setGx(struct vc_data *vc, unsigned int which, int c) |
---|
| 2132 | +{ |
---|
| 2133 | + unsigned char *charset = &vc->state.Gx_charset[which]; |
---|
| 2134 | + |
---|
| 2135 | + switch (c) { |
---|
| 2136 | + case '0': |
---|
| 2137 | + *charset = GRAF_MAP; |
---|
| 2138 | + break; |
---|
| 2139 | + case 'B': |
---|
| 2140 | + *charset = LAT1_MAP; |
---|
| 2141 | + break; |
---|
| 2142 | + case 'U': |
---|
| 2143 | + *charset = IBMPC_MAP; |
---|
| 2144 | + break; |
---|
| 2145 | + case 'K': |
---|
| 2146 | + *charset = USER_MAP; |
---|
| 2147 | + break; |
---|
| 2148 | + } |
---|
| 2149 | + |
---|
| 2150 | + if (vc->state.charset == which) |
---|
| 2151 | + vc->vc_translate = set_translate(*charset, vc); |
---|
| 2152 | +} |
---|
| 2153 | + |
---|
| 2154 | +/* is this state an ANSI control string? */ |
---|
| 2155 | +static bool ansi_control_string(unsigned int state) |
---|
| 2156 | +{ |
---|
| 2157 | + if (state == ESosc || state == ESapc || state == ESpm || state == ESdcs) |
---|
| 2158 | + return true; |
---|
| 2159 | + return false; |
---|
| 2160 | +} |
---|
| 2161 | + |
---|
2145 | 2162 | /* console_lock is held */ |
---|
2146 | 2163 | static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) |
---|
2147 | 2164 | { |
---|
2148 | 2165 | /* |
---|
2149 | 2166 | * Control characters can be used in the _middle_ |
---|
2150 | | - * of an escape sequence. |
---|
| 2167 | + * of an escape sequence, aside from ANSI control strings. |
---|
2151 | 2168 | */ |
---|
2152 | | - if (vc->vc_state == ESosc && c>=8 && c<=13) /* ... except for OSC */ |
---|
| 2169 | + if (ansi_control_string(vc->vc_state) && c >= 8 && c <= 13) |
---|
2153 | 2170 | return; |
---|
2154 | 2171 | switch (c) { |
---|
2155 | 2172 | case 0: |
---|
2156 | 2173 | return; |
---|
2157 | 2174 | case 7: |
---|
2158 | | - if (vc->vc_state == ESosc) |
---|
| 2175 | + if (ansi_control_string(vc->vc_state)) |
---|
2159 | 2176 | vc->vc_state = ESnormal; |
---|
2160 | 2177 | else if (vc->vc_bell_duration) |
---|
2161 | 2178 | kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); |
---|
.. | .. |
---|
2164 | 2181 | bs(vc); |
---|
2165 | 2182 | return; |
---|
2166 | 2183 | case 9: |
---|
2167 | | - vc->vc_pos -= (vc->vc_x << 1); |
---|
2168 | | - while (vc->vc_x < vc->vc_cols - 1) { |
---|
2169 | | - vc->vc_x++; |
---|
2170 | | - if (vc->vc_tab_stop[7 & (vc->vc_x >> 5)] & (1 << (vc->vc_x & 31))) |
---|
2171 | | - break; |
---|
2172 | | - } |
---|
2173 | | - vc->vc_pos += (vc->vc_x << 1); |
---|
| 2184 | + vc->vc_pos -= (vc->state.x << 1); |
---|
| 2185 | + |
---|
| 2186 | + vc->state.x = find_next_bit(vc->vc_tab_stop, |
---|
| 2187 | + min(vc->vc_cols - 1, VC_TABSTOPS_COUNT), |
---|
| 2188 | + vc->state.x + 1); |
---|
| 2189 | + if (vc->state.x >= VC_TABSTOPS_COUNT) |
---|
| 2190 | + vc->state.x = vc->vc_cols - 1; |
---|
| 2191 | + |
---|
| 2192 | + vc->vc_pos += (vc->state.x << 1); |
---|
2174 | 2193 | notify_write(vc, '\t'); |
---|
2175 | 2194 | return; |
---|
2176 | 2195 | case 10: case 11: case 12: |
---|
2177 | 2196 | lf(vc); |
---|
2178 | 2197 | if (!is_kbd(vc, lnm)) |
---|
2179 | 2198 | return; |
---|
| 2199 | + fallthrough; |
---|
2180 | 2200 | case 13: |
---|
2181 | 2201 | cr(vc); |
---|
2182 | 2202 | return; |
---|
2183 | 2203 | case 14: |
---|
2184 | | - vc->vc_charset = 1; |
---|
2185 | | - vc->vc_translate = set_translate(vc->vc_G1_charset, vc); |
---|
| 2204 | + vc->state.charset = 1; |
---|
| 2205 | + vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc); |
---|
2186 | 2206 | vc->vc_disp_ctrl = 1; |
---|
2187 | 2207 | return; |
---|
2188 | 2208 | case 15: |
---|
2189 | | - vc->vc_charset = 0; |
---|
2190 | | - vc->vc_translate = set_translate(vc->vc_G0_charset, vc); |
---|
| 2209 | + vc->state.charset = 0; |
---|
| 2210 | + vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc); |
---|
2191 | 2211 | vc->vc_disp_ctrl = 0; |
---|
2192 | 2212 | return; |
---|
2193 | 2213 | case 24: case 26: |
---|
.. | .. |
---|
2213 | 2233 | case ']': |
---|
2214 | 2234 | vc->vc_state = ESnonstd; |
---|
2215 | 2235 | return; |
---|
| 2236 | + case '_': |
---|
| 2237 | + vc->vc_state = ESapc; |
---|
| 2238 | + return; |
---|
| 2239 | + case '^': |
---|
| 2240 | + vc->vc_state = ESpm; |
---|
| 2241 | + return; |
---|
2216 | 2242 | case '%': |
---|
2217 | 2243 | vc->vc_state = ESpercent; |
---|
2218 | 2244 | return; |
---|
.. | .. |
---|
2227 | 2253 | lf(vc); |
---|
2228 | 2254 | return; |
---|
2229 | 2255 | case 'H': |
---|
2230 | | - vc->vc_tab_stop[7 & (vc->vc_x >> 5)] |= (1 << (vc->vc_x & 31)); |
---|
| 2256 | + if (vc->state.x < VC_TABSTOPS_COUNT) |
---|
| 2257 | + set_bit(vc->state.x, vc->vc_tab_stop); |
---|
| 2258 | + return; |
---|
| 2259 | + case 'P': |
---|
| 2260 | + vc->vc_state = ESdcs; |
---|
2231 | 2261 | return; |
---|
2232 | 2262 | case 'Z': |
---|
2233 | 2263 | respond_ID(tty); |
---|
.. | .. |
---|
2299 | 2329 | vc->vc_state=ESfunckey; |
---|
2300 | 2330 | return; |
---|
2301 | 2331 | } |
---|
2302 | | - vc->vc_ques = (c == '?'); |
---|
2303 | | - if (vc->vc_ques) |
---|
| 2332 | + switch (c) { |
---|
| 2333 | + case '?': |
---|
| 2334 | + vc->vc_priv = EPdec; |
---|
2304 | 2335 | return; |
---|
| 2336 | + case '>': |
---|
| 2337 | + vc->vc_priv = EPgt; |
---|
| 2338 | + return; |
---|
| 2339 | + case '=': |
---|
| 2340 | + vc->vc_priv = EPeq; |
---|
| 2341 | + return; |
---|
| 2342 | + case '<': |
---|
| 2343 | + vc->vc_priv = EPlt; |
---|
| 2344 | + return; |
---|
| 2345 | + } |
---|
| 2346 | + vc->vc_priv = EPecma; |
---|
| 2347 | + fallthrough; |
---|
2305 | 2348 | case ESgetpars: |
---|
2306 | 2349 | if (c == ';' && vc->vc_npar < NPAR - 1) { |
---|
2307 | 2350 | vc->vc_npar++; |
---|
.. | .. |
---|
2311 | 2354 | vc->vc_par[vc->vc_npar] += c - '0'; |
---|
2312 | 2355 | return; |
---|
2313 | 2356 | } |
---|
| 2357 | + if (c >= 0x20 && c <= 0x3f) { /* 0x2x, 0x3a and 0x3c - 0x3f */ |
---|
| 2358 | + vc->vc_state = EScsiignore; |
---|
| 2359 | + return; |
---|
| 2360 | + } |
---|
2314 | 2361 | vc->vc_state = ESnormal; |
---|
2315 | 2362 | switch(c) { |
---|
2316 | 2363 | case 'h': |
---|
2317 | | - set_mode(vc, 1); |
---|
| 2364 | + if (vc->vc_priv <= EPdec) |
---|
| 2365 | + set_mode(vc, 1); |
---|
2318 | 2366 | return; |
---|
2319 | 2367 | case 'l': |
---|
2320 | | - set_mode(vc, 0); |
---|
| 2368 | + if (vc->vc_priv <= EPdec) |
---|
| 2369 | + set_mode(vc, 0); |
---|
2321 | 2370 | return; |
---|
2322 | 2371 | case 'c': |
---|
2323 | | - if (vc->vc_ques) { |
---|
| 2372 | + if (vc->vc_priv == EPdec) { |
---|
2324 | 2373 | if (vc->vc_par[0]) |
---|
2325 | | - vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16); |
---|
| 2374 | + vc->vc_cursor_type = |
---|
| 2375 | + CUR_MAKE(vc->vc_par[0], |
---|
| 2376 | + vc->vc_par[1], |
---|
| 2377 | + vc->vc_par[2]); |
---|
2326 | 2378 | else |
---|
2327 | 2379 | vc->vc_cursor_type = cur_default; |
---|
2328 | 2380 | return; |
---|
2329 | 2381 | } |
---|
2330 | 2382 | break; |
---|
2331 | 2383 | case 'm': |
---|
2332 | | - if (vc->vc_ques) { |
---|
| 2384 | + if (vc->vc_priv == EPdec) { |
---|
2333 | 2385 | clear_selection(); |
---|
2334 | 2386 | if (vc->vc_par[0]) |
---|
2335 | 2387 | vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1]; |
---|
.. | .. |
---|
2339 | 2391 | } |
---|
2340 | 2392 | break; |
---|
2341 | 2393 | case 'n': |
---|
2342 | | - if (!vc->vc_ques) { |
---|
| 2394 | + if (vc->vc_priv == EPecma) { |
---|
2343 | 2395 | if (vc->vc_par[0] == 5) |
---|
2344 | 2396 | status_report(tty); |
---|
2345 | 2397 | else if (vc->vc_par[0] == 6) |
---|
.. | .. |
---|
2347 | 2399 | } |
---|
2348 | 2400 | return; |
---|
2349 | 2401 | } |
---|
2350 | | - if (vc->vc_ques) { |
---|
2351 | | - vc->vc_ques = 0; |
---|
| 2402 | + if (vc->vc_priv != EPecma) { |
---|
| 2403 | + vc->vc_priv = EPecma; |
---|
2352 | 2404 | return; |
---|
2353 | 2405 | } |
---|
2354 | 2406 | switch(c) { |
---|
2355 | 2407 | case 'G': case '`': |
---|
2356 | 2408 | if (vc->vc_par[0]) |
---|
2357 | 2409 | vc->vc_par[0]--; |
---|
2358 | | - gotoxy(vc, vc->vc_par[0], vc->vc_y); |
---|
| 2410 | + gotoxy(vc, vc->vc_par[0], vc->state.y); |
---|
2359 | 2411 | return; |
---|
2360 | 2412 | case 'A': |
---|
2361 | 2413 | if (!vc->vc_par[0]) |
---|
2362 | 2414 | vc->vc_par[0]++; |
---|
2363 | | - gotoxy(vc, vc->vc_x, vc->vc_y - vc->vc_par[0]); |
---|
| 2415 | + gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]); |
---|
2364 | 2416 | return; |
---|
2365 | 2417 | case 'B': case 'e': |
---|
2366 | 2418 | if (!vc->vc_par[0]) |
---|
2367 | 2419 | vc->vc_par[0]++; |
---|
2368 | | - gotoxy(vc, vc->vc_x, vc->vc_y + vc->vc_par[0]); |
---|
| 2420 | + gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]); |
---|
2369 | 2421 | return; |
---|
2370 | 2422 | case 'C': case 'a': |
---|
2371 | 2423 | if (!vc->vc_par[0]) |
---|
2372 | 2424 | vc->vc_par[0]++; |
---|
2373 | | - gotoxy(vc, vc->vc_x + vc->vc_par[0], vc->vc_y); |
---|
| 2425 | + gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y); |
---|
2374 | 2426 | return; |
---|
2375 | 2427 | case 'D': |
---|
2376 | 2428 | if (!vc->vc_par[0]) |
---|
2377 | 2429 | vc->vc_par[0]++; |
---|
2378 | | - gotoxy(vc, vc->vc_x - vc->vc_par[0], vc->vc_y); |
---|
| 2430 | + gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y); |
---|
2379 | 2431 | return; |
---|
2380 | 2432 | case 'E': |
---|
2381 | 2433 | if (!vc->vc_par[0]) |
---|
2382 | 2434 | vc->vc_par[0]++; |
---|
2383 | | - gotoxy(vc, 0, vc->vc_y + vc->vc_par[0]); |
---|
| 2435 | + gotoxy(vc, 0, vc->state.y + vc->vc_par[0]); |
---|
2384 | 2436 | return; |
---|
2385 | 2437 | case 'F': |
---|
2386 | 2438 | if (!vc->vc_par[0]) |
---|
2387 | 2439 | vc->vc_par[0]++; |
---|
2388 | | - gotoxy(vc, 0, vc->vc_y - vc->vc_par[0]); |
---|
| 2440 | + gotoxy(vc, 0, vc->state.y - vc->vc_par[0]); |
---|
2389 | 2441 | return; |
---|
2390 | 2442 | case 'd': |
---|
2391 | 2443 | if (vc->vc_par[0]) |
---|
2392 | 2444 | vc->vc_par[0]--; |
---|
2393 | | - gotoxay(vc, vc->vc_x ,vc->vc_par[0]); |
---|
| 2445 | + gotoxay(vc, vc->state.x ,vc->vc_par[0]); |
---|
2394 | 2446 | return; |
---|
2395 | 2447 | case 'H': case 'f': |
---|
2396 | 2448 | if (vc->vc_par[0]) |
---|
.. | .. |
---|
2419 | 2471 | respond_ID(tty); |
---|
2420 | 2472 | return; |
---|
2421 | 2473 | case 'g': |
---|
2422 | | - if (!vc->vc_par[0]) |
---|
2423 | | - vc->vc_tab_stop[7 & (vc->vc_x >> 5)] &= ~(1 << (vc->vc_x & 31)); |
---|
2424 | | - else if (vc->vc_par[0] == 3) { |
---|
2425 | | - vc->vc_tab_stop[0] = |
---|
2426 | | - vc->vc_tab_stop[1] = |
---|
2427 | | - vc->vc_tab_stop[2] = |
---|
2428 | | - vc->vc_tab_stop[3] = |
---|
2429 | | - vc->vc_tab_stop[4] = |
---|
2430 | | - vc->vc_tab_stop[5] = |
---|
2431 | | - vc->vc_tab_stop[6] = |
---|
2432 | | - vc->vc_tab_stop[7] = 0; |
---|
2433 | | - } |
---|
| 2474 | + if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT) |
---|
| 2475 | + set_bit(vc->state.x, vc->vc_tab_stop); |
---|
| 2476 | + else if (vc->vc_par[0] == 3) |
---|
| 2477 | + bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT); |
---|
2434 | 2478 | return; |
---|
2435 | 2479 | case 'm': |
---|
2436 | 2480 | csi_m(vc); |
---|
.. | .. |
---|
2471 | 2515 | return; |
---|
2472 | 2516 | } |
---|
2473 | 2517 | return; |
---|
| 2518 | + case EScsiignore: |
---|
| 2519 | + if (c >= 20 && c <= 0x3f) |
---|
| 2520 | + return; |
---|
| 2521 | + vc->vc_state = ESnormal; |
---|
| 2522 | + return; |
---|
2474 | 2523 | case ESpercent: |
---|
2475 | 2524 | vc->vc_state = ESnormal; |
---|
2476 | 2525 | switch (c) { |
---|
.. | .. |
---|
2499 | 2548 | } |
---|
2500 | 2549 | return; |
---|
2501 | 2550 | case ESsetG0: |
---|
2502 | | - if (c == '0') |
---|
2503 | | - vc->vc_G0_charset = GRAF_MAP; |
---|
2504 | | - else if (c == 'B') |
---|
2505 | | - vc->vc_G0_charset = LAT1_MAP; |
---|
2506 | | - else if (c == 'U') |
---|
2507 | | - vc->vc_G0_charset = IBMPC_MAP; |
---|
2508 | | - else if (c == 'K') |
---|
2509 | | - vc->vc_G0_charset = USER_MAP; |
---|
2510 | | - if (vc->vc_charset == 0) |
---|
2511 | | - vc->vc_translate = set_translate(vc->vc_G0_charset, vc); |
---|
| 2551 | + vc_setGx(vc, 0, c); |
---|
2512 | 2552 | vc->vc_state = ESnormal; |
---|
2513 | 2553 | return; |
---|
2514 | 2554 | case ESsetG1: |
---|
2515 | | - if (c == '0') |
---|
2516 | | - vc->vc_G1_charset = GRAF_MAP; |
---|
2517 | | - else if (c == 'B') |
---|
2518 | | - vc->vc_G1_charset = LAT1_MAP; |
---|
2519 | | - else if (c == 'U') |
---|
2520 | | - vc->vc_G1_charset = IBMPC_MAP; |
---|
2521 | | - else if (c == 'K') |
---|
2522 | | - vc->vc_G1_charset = USER_MAP; |
---|
2523 | | - if (vc->vc_charset == 1) |
---|
2524 | | - vc->vc_translate = set_translate(vc->vc_G1_charset, vc); |
---|
| 2555 | + vc_setGx(vc, 1, c); |
---|
2525 | 2556 | vc->vc_state = ESnormal; |
---|
2526 | 2557 | return; |
---|
| 2558 | + case ESapc: |
---|
| 2559 | + return; |
---|
2527 | 2560 | case ESosc: |
---|
| 2561 | + return; |
---|
| 2562 | + case ESpm: |
---|
| 2563 | + return; |
---|
| 2564 | + case ESdcs: |
---|
2528 | 2565 | return; |
---|
2529 | 2566 | default: |
---|
2530 | 2567 | vc->vc_state = ESnormal; |
---|
.. | .. |
---|
2533 | 2570 | |
---|
2534 | 2571 | /* is_double_width() is based on the wcwidth() implementation by |
---|
2535 | 2572 | * Markus Kuhn -- 2007-05-26 (Unicode 5.0) |
---|
2536 | | - * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c |
---|
| 2573 | + * Latest version: https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c |
---|
2537 | 2574 | */ |
---|
2538 | 2575 | struct interval { |
---|
2539 | 2576 | uint32_t first; |
---|
.. | .. |
---|
2568 | 2605 | sizeof(struct interval), ucs_cmp) != NULL; |
---|
2569 | 2606 | } |
---|
2570 | 2607 | |
---|
2571 | | -static void con_flush(struct vc_data *vc, unsigned long draw_from, |
---|
2572 | | - unsigned long draw_to, int *draw_x) |
---|
| 2608 | +struct vc_draw_region { |
---|
| 2609 | + unsigned long from, to; |
---|
| 2610 | + int x; |
---|
| 2611 | +}; |
---|
| 2612 | + |
---|
| 2613 | +static void con_flush(struct vc_data *vc, struct vc_draw_region *draw) |
---|
2573 | 2614 | { |
---|
2574 | | - if (*draw_x < 0) |
---|
| 2615 | + if (draw->x < 0) |
---|
2575 | 2616 | return; |
---|
2576 | 2617 | |
---|
2577 | | - vc->vc_sw->con_putcs(vc, (u16 *)draw_from, |
---|
2578 | | - (u16 *)draw_to - (u16 *)draw_from, vc->vc_y, *draw_x); |
---|
2579 | | - *draw_x = -1; |
---|
| 2618 | + vc->vc_sw->con_putcs(vc, (u16 *)draw->from, |
---|
| 2619 | + (u16 *)draw->to - (u16 *)draw->from, vc->state.y, |
---|
| 2620 | + draw->x); |
---|
| 2621 | + draw->x = -1; |
---|
| 2622 | +} |
---|
| 2623 | + |
---|
| 2624 | +static inline int vc_translate_ascii(const struct vc_data *vc, int c) |
---|
| 2625 | +{ |
---|
| 2626 | + if (IS_ENABLED(CONFIG_CONSOLE_TRANSLATIONS)) { |
---|
| 2627 | + if (vc->vc_toggle_meta) |
---|
| 2628 | + c |= 0x80; |
---|
| 2629 | + |
---|
| 2630 | + return vc->vc_translate[c]; |
---|
| 2631 | + } |
---|
| 2632 | + |
---|
| 2633 | + return c; |
---|
| 2634 | +} |
---|
| 2635 | + |
---|
| 2636 | + |
---|
| 2637 | +/** |
---|
| 2638 | + * vc_sanitize_unicode -- Replace invalid Unicode code points with U+FFFD |
---|
| 2639 | + * @c: the received character, or U+FFFD for invalid sequences. |
---|
| 2640 | + */ |
---|
| 2641 | +static inline int vc_sanitize_unicode(const int c) |
---|
| 2642 | +{ |
---|
| 2643 | + if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) |
---|
| 2644 | + return 0xfffd; |
---|
| 2645 | + |
---|
| 2646 | + return c; |
---|
| 2647 | +} |
---|
| 2648 | + |
---|
| 2649 | +/** |
---|
| 2650 | + * vc_translate_unicode -- Combine UTF-8 into Unicode in @vc_utf_char |
---|
| 2651 | + * @vc: virtual console |
---|
| 2652 | + * @c: character to translate |
---|
| 2653 | + * @rescan: we return true if we need more (continuation) data |
---|
| 2654 | + * |
---|
| 2655 | + * @vc_utf_char is the being-constructed unicode character. |
---|
| 2656 | + * @vc_utf_count is the number of continuation bytes still expected to arrive. |
---|
| 2657 | + * @vc_npar is the number of continuation bytes arrived so far. |
---|
| 2658 | + */ |
---|
| 2659 | +static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan) |
---|
| 2660 | +{ |
---|
| 2661 | + static const u32 utf8_length_changes[] = { |
---|
| 2662 | + 0x0000007f, 0x000007ff, 0x0000ffff, |
---|
| 2663 | + 0x001fffff, 0x03ffffff, 0x7fffffff |
---|
| 2664 | + }; |
---|
| 2665 | + |
---|
| 2666 | + /* Continuation byte received */ |
---|
| 2667 | + if ((c & 0xc0) == 0x80) { |
---|
| 2668 | + /* Unexpected continuation byte? */ |
---|
| 2669 | + if (!vc->vc_utf_count) |
---|
| 2670 | + return 0xfffd; |
---|
| 2671 | + |
---|
| 2672 | + vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f); |
---|
| 2673 | + vc->vc_npar++; |
---|
| 2674 | + if (--vc->vc_utf_count) |
---|
| 2675 | + goto need_more_bytes; |
---|
| 2676 | + |
---|
| 2677 | + /* Got a whole character */ |
---|
| 2678 | + c = vc->vc_utf_char; |
---|
| 2679 | + /* Reject overlong sequences */ |
---|
| 2680 | + if (c <= utf8_length_changes[vc->vc_npar - 1] || |
---|
| 2681 | + c > utf8_length_changes[vc->vc_npar]) |
---|
| 2682 | + return 0xfffd; |
---|
| 2683 | + |
---|
| 2684 | + return vc_sanitize_unicode(c); |
---|
| 2685 | + } |
---|
| 2686 | + |
---|
| 2687 | + /* Single ASCII byte or first byte of a sequence received */ |
---|
| 2688 | + if (vc->vc_utf_count) { |
---|
| 2689 | + /* Continuation byte expected */ |
---|
| 2690 | + *rescan = true; |
---|
| 2691 | + vc->vc_utf_count = 0; |
---|
| 2692 | + return 0xfffd; |
---|
| 2693 | + } |
---|
| 2694 | + |
---|
| 2695 | + /* Nothing to do if an ASCII byte was received */ |
---|
| 2696 | + if (c <= 0x7f) |
---|
| 2697 | + return c; |
---|
| 2698 | + |
---|
| 2699 | + /* First byte of a multibyte sequence received */ |
---|
| 2700 | + vc->vc_npar = 0; |
---|
| 2701 | + if ((c & 0xe0) == 0xc0) { |
---|
| 2702 | + vc->vc_utf_count = 1; |
---|
| 2703 | + vc->vc_utf_char = (c & 0x1f); |
---|
| 2704 | + } else if ((c & 0xf0) == 0xe0) { |
---|
| 2705 | + vc->vc_utf_count = 2; |
---|
| 2706 | + vc->vc_utf_char = (c & 0x0f); |
---|
| 2707 | + } else if ((c & 0xf8) == 0xf0) { |
---|
| 2708 | + vc->vc_utf_count = 3; |
---|
| 2709 | + vc->vc_utf_char = (c & 0x07); |
---|
| 2710 | + } else if ((c & 0xfc) == 0xf8) { |
---|
| 2711 | + vc->vc_utf_count = 4; |
---|
| 2712 | + vc->vc_utf_char = (c & 0x03); |
---|
| 2713 | + } else if ((c & 0xfe) == 0xfc) { |
---|
| 2714 | + vc->vc_utf_count = 5; |
---|
| 2715 | + vc->vc_utf_char = (c & 0x01); |
---|
| 2716 | + } else { |
---|
| 2717 | + /* 254 and 255 are invalid */ |
---|
| 2718 | + return 0xfffd; |
---|
| 2719 | + } |
---|
| 2720 | + |
---|
| 2721 | +need_more_bytes: |
---|
| 2722 | + return -1; |
---|
| 2723 | +} |
---|
| 2724 | + |
---|
| 2725 | +static int vc_translate(struct vc_data *vc, int *c, bool *rescan) |
---|
| 2726 | +{ |
---|
| 2727 | + /* Do no translation at all in control states */ |
---|
| 2728 | + if (vc->vc_state != ESnormal) |
---|
| 2729 | + return *c; |
---|
| 2730 | + |
---|
| 2731 | + if (vc->vc_utf && !vc->vc_disp_ctrl) |
---|
| 2732 | + return *c = vc_translate_unicode(vc, *c, rescan); |
---|
| 2733 | + |
---|
| 2734 | + /* no utf or alternate charset mode */ |
---|
| 2735 | + return vc_translate_ascii(vc, *c); |
---|
| 2736 | +} |
---|
| 2737 | + |
---|
| 2738 | +static inline unsigned char vc_invert_attr(const struct vc_data *vc) |
---|
| 2739 | +{ |
---|
| 2740 | + if (!vc->vc_can_do_color) |
---|
| 2741 | + return vc->vc_attr ^ 0x08; |
---|
| 2742 | + |
---|
| 2743 | + if (vc->vc_hi_font_mask == 0x100) |
---|
| 2744 | + return (vc->vc_attr & 0x11) | |
---|
| 2745 | + ((vc->vc_attr & 0xe0) >> 4) | |
---|
| 2746 | + ((vc->vc_attr & 0x0e) << 4); |
---|
| 2747 | + |
---|
| 2748 | + return (vc->vc_attr & 0x88) | |
---|
| 2749 | + ((vc->vc_attr & 0x70) >> 4) | |
---|
| 2750 | + ((vc->vc_attr & 0x07) << 4); |
---|
| 2751 | +} |
---|
| 2752 | + |
---|
| 2753 | +static bool vc_is_control(struct vc_data *vc, int tc, int c) |
---|
| 2754 | +{ |
---|
| 2755 | + /* |
---|
| 2756 | + * A bitmap for codes <32. A bit of 1 indicates that the code |
---|
| 2757 | + * corresponding to that bit number invokes some special action (such |
---|
| 2758 | + * as cursor movement) and should not be displayed as a glyph unless |
---|
| 2759 | + * the disp_ctrl mode is explicitly enabled. |
---|
| 2760 | + */ |
---|
| 2761 | + static const u32 CTRL_ACTION = 0x0d00ff81; |
---|
| 2762 | + /* Cannot be overridden by disp_ctrl */ |
---|
| 2763 | + static const u32 CTRL_ALWAYS = 0x0800f501; |
---|
| 2764 | + |
---|
| 2765 | + if (vc->vc_state != ESnormal) |
---|
| 2766 | + return true; |
---|
| 2767 | + |
---|
| 2768 | + if (!tc) |
---|
| 2769 | + return true; |
---|
| 2770 | + |
---|
| 2771 | + /* |
---|
| 2772 | + * If the original code was a control character we only allow a glyph |
---|
| 2773 | + * to be displayed if the code is not normally used (such as for cursor |
---|
| 2774 | + * movement) or if the disp_ctrl mode has been explicitly enabled. |
---|
| 2775 | + * Certain characters (as given by the CTRL_ALWAYS bitmap) are always |
---|
| 2776 | + * displayed as control characters, as the console would be pretty |
---|
| 2777 | + * useless without them; to display an arbitrary font position use the |
---|
| 2778 | + * direct-to-font zone in UTF-8 mode. |
---|
| 2779 | + */ |
---|
| 2780 | + if (c < 32) { |
---|
| 2781 | + if (vc->vc_disp_ctrl) |
---|
| 2782 | + return CTRL_ALWAYS & BIT(c); |
---|
| 2783 | + else |
---|
| 2784 | + return vc->vc_utf || (CTRL_ACTION & BIT(c)); |
---|
| 2785 | + } |
---|
| 2786 | + |
---|
| 2787 | + if (c == 127 && !vc->vc_disp_ctrl) |
---|
| 2788 | + return true; |
---|
| 2789 | + |
---|
| 2790 | + if (c == 128 + 27) |
---|
| 2791 | + return true; |
---|
| 2792 | + |
---|
| 2793 | + return false; |
---|
| 2794 | +} |
---|
| 2795 | + |
---|
| 2796 | +static int vc_con_write_normal(struct vc_data *vc, int tc, int c, |
---|
| 2797 | + struct vc_draw_region *draw) |
---|
| 2798 | +{ |
---|
| 2799 | + int next_c; |
---|
| 2800 | + unsigned char vc_attr = vc->vc_attr; |
---|
| 2801 | + u16 himask = vc->vc_hi_font_mask, charmask = himask ? 0x1ff : 0xff; |
---|
| 2802 | + u8 width = 1; |
---|
| 2803 | + bool inverse = false; |
---|
| 2804 | + |
---|
| 2805 | + if (vc->vc_utf && !vc->vc_disp_ctrl) { |
---|
| 2806 | + if (is_double_width(c)) |
---|
| 2807 | + width = 2; |
---|
| 2808 | + } |
---|
| 2809 | + |
---|
| 2810 | + /* Now try to find out how to display it */ |
---|
| 2811 | + tc = conv_uni_to_pc(vc, tc); |
---|
| 2812 | + if (tc & ~charmask) { |
---|
| 2813 | + if (tc == -1 || tc == -2) |
---|
| 2814 | + return -1; /* nothing to display */ |
---|
| 2815 | + |
---|
| 2816 | + /* Glyph not found */ |
---|
| 2817 | + if ((!vc->vc_utf || vc->vc_disp_ctrl || c < 128) && |
---|
| 2818 | + !(c & ~charmask)) { |
---|
| 2819 | + /* |
---|
| 2820 | + * In legacy mode use the glyph we get by a 1:1 |
---|
| 2821 | + * mapping. |
---|
| 2822 | + * This would make absolutely no sense with Unicode in |
---|
| 2823 | + * mind, but do this for ASCII characters since a font |
---|
| 2824 | + * may lack Unicode mapping info and we don't want to |
---|
| 2825 | + * end up with having question marks only. |
---|
| 2826 | + */ |
---|
| 2827 | + tc = c; |
---|
| 2828 | + } else { |
---|
| 2829 | + /* |
---|
| 2830 | + * Display U+FFFD. If it's not found, display an inverse |
---|
| 2831 | + * question mark. |
---|
| 2832 | + */ |
---|
| 2833 | + tc = conv_uni_to_pc(vc, 0xfffd); |
---|
| 2834 | + if (tc < 0) { |
---|
| 2835 | + inverse = true; |
---|
| 2836 | + tc = conv_uni_to_pc(vc, '?'); |
---|
| 2837 | + if (tc < 0) |
---|
| 2838 | + tc = '?'; |
---|
| 2839 | + |
---|
| 2840 | + vc_attr = vc_invert_attr(vc); |
---|
| 2841 | + con_flush(vc, draw); |
---|
| 2842 | + } |
---|
| 2843 | + } |
---|
| 2844 | + } |
---|
| 2845 | + |
---|
| 2846 | + next_c = c; |
---|
| 2847 | + while (1) { |
---|
| 2848 | + if (vc->vc_need_wrap || vc->vc_decim) |
---|
| 2849 | + con_flush(vc, draw); |
---|
| 2850 | + if (vc->vc_need_wrap) { |
---|
| 2851 | + cr(vc); |
---|
| 2852 | + lf(vc); |
---|
| 2853 | + } |
---|
| 2854 | + if (vc->vc_decim) |
---|
| 2855 | + insert_char(vc, 1); |
---|
| 2856 | + vc_uniscr_putc(vc, next_c); |
---|
| 2857 | + |
---|
| 2858 | + if (himask) |
---|
| 2859 | + tc = ((tc & 0x100) ? himask : 0) | |
---|
| 2860 | + (tc & 0xff); |
---|
| 2861 | + tc |= (vc_attr << 8) & ~himask; |
---|
| 2862 | + |
---|
| 2863 | + scr_writew(tc, (u16 *)vc->vc_pos); |
---|
| 2864 | + |
---|
| 2865 | + if (con_should_update(vc) && draw->x < 0) { |
---|
| 2866 | + draw->x = vc->state.x; |
---|
| 2867 | + draw->from = vc->vc_pos; |
---|
| 2868 | + } |
---|
| 2869 | + if (vc->state.x == vc->vc_cols - 1) { |
---|
| 2870 | + vc->vc_need_wrap = vc->vc_decawm; |
---|
| 2871 | + draw->to = vc->vc_pos + 2; |
---|
| 2872 | + } else { |
---|
| 2873 | + vc->state.x++; |
---|
| 2874 | + draw->to = (vc->vc_pos += 2); |
---|
| 2875 | + } |
---|
| 2876 | + |
---|
| 2877 | + if (!--width) |
---|
| 2878 | + break; |
---|
| 2879 | + |
---|
| 2880 | + /* A space is printed in the second column */ |
---|
| 2881 | + tc = conv_uni_to_pc(vc, ' '); |
---|
| 2882 | + if (tc < 0) |
---|
| 2883 | + tc = ' '; |
---|
| 2884 | + next_c = ' '; |
---|
| 2885 | + } |
---|
| 2886 | + notify_write(vc, c); |
---|
| 2887 | + |
---|
| 2888 | + if (inverse) |
---|
| 2889 | + con_flush(vc, draw); |
---|
| 2890 | + |
---|
| 2891 | + return 0; |
---|
2580 | 2892 | } |
---|
2581 | 2893 | |
---|
2582 | 2894 | /* acquires console_lock */ |
---|
2583 | 2895 | static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count) |
---|
2584 | 2896 | { |
---|
2585 | | - int c, next_c, tc, ok, n = 0, draw_x = -1; |
---|
| 2897 | + struct vc_draw_region draw = { |
---|
| 2898 | + .x = -1, |
---|
| 2899 | + }; |
---|
| 2900 | + int c, tc, n = 0; |
---|
2586 | 2901 | unsigned int currcons; |
---|
2587 | | - unsigned long draw_from = 0, draw_to = 0; |
---|
2588 | 2902 | struct vc_data *vc; |
---|
2589 | | - unsigned char vc_attr; |
---|
2590 | 2903 | struct vt_notifier_param param; |
---|
2591 | | - uint8_t rescan; |
---|
2592 | | - uint8_t inverse; |
---|
2593 | | - uint8_t width; |
---|
2594 | | - u16 himask, charmask; |
---|
| 2904 | + bool rescan; |
---|
2595 | 2905 | |
---|
2596 | 2906 | if (in_interrupt()) |
---|
2597 | 2907 | return count; |
---|
2598 | | - |
---|
2599 | | - might_sleep(); |
---|
2600 | 2908 | |
---|
2601 | 2909 | console_lock(); |
---|
2602 | 2910 | vc = tty->driver_data; |
---|
.. | .. |
---|
2614 | 2922 | return 0; |
---|
2615 | 2923 | } |
---|
2616 | 2924 | |
---|
2617 | | - himask = vc->vc_hi_font_mask; |
---|
2618 | | - charmask = himask ? 0x1ff : 0xff; |
---|
2619 | 2925 | |
---|
2620 | 2926 | /* undraw cursor first */ |
---|
2621 | 2927 | if (con_is_fg(vc)) |
---|
.. | .. |
---|
2625 | 2931 | |
---|
2626 | 2932 | while (!tty->stopped && count) { |
---|
2627 | 2933 | int orig = *buf; |
---|
2628 | | - c = orig; |
---|
2629 | 2934 | buf++; |
---|
2630 | 2935 | n++; |
---|
2631 | 2936 | count--; |
---|
2632 | | - rescan = 0; |
---|
2633 | | - inverse = 0; |
---|
2634 | | - width = 1; |
---|
2635 | | - |
---|
2636 | | - /* Do no translation at all in control states */ |
---|
2637 | | - if (vc->vc_state != ESnormal) { |
---|
2638 | | - tc = c; |
---|
2639 | | - } else if (vc->vc_utf && !vc->vc_disp_ctrl) { |
---|
2640 | | - /* Combine UTF-8 into Unicode in vc_utf_char. |
---|
2641 | | - * vc_utf_count is the number of continuation bytes still |
---|
2642 | | - * expected to arrive. |
---|
2643 | | - * vc_npar is the number of continuation bytes arrived so |
---|
2644 | | - * far |
---|
2645 | | - */ |
---|
2646 | 2937 | rescan_last_byte: |
---|
2647 | | - if ((c & 0xc0) == 0x80) { |
---|
2648 | | - /* Continuation byte received */ |
---|
2649 | | - static const uint32_t utf8_length_changes[] = { 0x0000007f, 0x000007ff, 0x0000ffff, 0x001fffff, 0x03ffffff, 0x7fffffff }; |
---|
2650 | | - if (vc->vc_utf_count) { |
---|
2651 | | - vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f); |
---|
2652 | | - vc->vc_npar++; |
---|
2653 | | - if (--vc->vc_utf_count) { |
---|
2654 | | - /* Still need some bytes */ |
---|
2655 | | - continue; |
---|
2656 | | - } |
---|
2657 | | - /* Got a whole character */ |
---|
2658 | | - c = vc->vc_utf_char; |
---|
2659 | | - /* Reject overlong sequences */ |
---|
2660 | | - if (c <= utf8_length_changes[vc->vc_npar - 1] || |
---|
2661 | | - c > utf8_length_changes[vc->vc_npar]) |
---|
2662 | | - c = 0xfffd; |
---|
2663 | | - } else { |
---|
2664 | | - /* Unexpected continuation byte */ |
---|
2665 | | - vc->vc_utf_count = 0; |
---|
2666 | | - c = 0xfffd; |
---|
2667 | | - } |
---|
2668 | | - } else { |
---|
2669 | | - /* Single ASCII byte or first byte of a sequence received */ |
---|
2670 | | - if (vc->vc_utf_count) { |
---|
2671 | | - /* Continuation byte expected */ |
---|
2672 | | - rescan = 1; |
---|
2673 | | - vc->vc_utf_count = 0; |
---|
2674 | | - c = 0xfffd; |
---|
2675 | | - } else if (c > 0x7f) { |
---|
2676 | | - /* First byte of a multibyte sequence received */ |
---|
2677 | | - vc->vc_npar = 0; |
---|
2678 | | - if ((c & 0xe0) == 0xc0) { |
---|
2679 | | - vc->vc_utf_count = 1; |
---|
2680 | | - vc->vc_utf_char = (c & 0x1f); |
---|
2681 | | - } else if ((c & 0xf0) == 0xe0) { |
---|
2682 | | - vc->vc_utf_count = 2; |
---|
2683 | | - vc->vc_utf_char = (c & 0x0f); |
---|
2684 | | - } else if ((c & 0xf8) == 0xf0) { |
---|
2685 | | - vc->vc_utf_count = 3; |
---|
2686 | | - vc->vc_utf_char = (c & 0x07); |
---|
2687 | | - } else if ((c & 0xfc) == 0xf8) { |
---|
2688 | | - vc->vc_utf_count = 4; |
---|
2689 | | - vc->vc_utf_char = (c & 0x03); |
---|
2690 | | - } else if ((c & 0xfe) == 0xfc) { |
---|
2691 | | - vc->vc_utf_count = 5; |
---|
2692 | | - vc->vc_utf_char = (c & 0x01); |
---|
2693 | | - } else { |
---|
2694 | | - /* 254 and 255 are invalid */ |
---|
2695 | | - c = 0xfffd; |
---|
2696 | | - } |
---|
2697 | | - if (vc->vc_utf_count) { |
---|
2698 | | - /* Still need some bytes */ |
---|
2699 | | - continue; |
---|
2700 | | - } |
---|
2701 | | - } |
---|
2702 | | - /* Nothing to do if an ASCII byte was received */ |
---|
2703 | | - } |
---|
2704 | | - /* End of UTF-8 decoding. */ |
---|
2705 | | - /* c is the received character, or U+FFFD for invalid sequences. */ |
---|
2706 | | - /* Replace invalid Unicode code points with U+FFFD too */ |
---|
2707 | | - if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) |
---|
2708 | | - c = 0xfffd; |
---|
2709 | | - tc = c; |
---|
2710 | | - } else { /* no utf or alternate charset mode */ |
---|
2711 | | - tc = vc_translate(vc, c); |
---|
2712 | | - } |
---|
| 2938 | + c = orig; |
---|
| 2939 | + rescan = false; |
---|
| 2940 | + |
---|
| 2941 | + tc = vc_translate(vc, &c, &rescan); |
---|
| 2942 | + if (tc == -1) |
---|
| 2943 | + continue; |
---|
2713 | 2944 | |
---|
2714 | 2945 | param.c = tc; |
---|
2715 | 2946 | if (atomic_notifier_call_chain(&vt_notifier_list, VT_PREWRITE, |
---|
2716 | 2947 | ¶m) == NOTIFY_STOP) |
---|
2717 | 2948 | continue; |
---|
2718 | 2949 | |
---|
2719 | | - /* If the original code was a control character we |
---|
2720 | | - * only allow a glyph to be displayed if the code is |
---|
2721 | | - * not normally used (such as for cursor movement) or |
---|
2722 | | - * if the disp_ctrl mode has been explicitly enabled. |
---|
2723 | | - * Certain characters (as given by the CTRL_ALWAYS |
---|
2724 | | - * bitmap) are always displayed as control characters, |
---|
2725 | | - * as the console would be pretty useless without |
---|
2726 | | - * them; to display an arbitrary font position use the |
---|
2727 | | - * direct-to-font zone in UTF-8 mode. |
---|
2728 | | - */ |
---|
2729 | | - ok = tc && (c >= 32 || |
---|
2730 | | - !(vc->vc_disp_ctrl ? (CTRL_ALWAYS >> c) & 1 : |
---|
2731 | | - vc->vc_utf || ((CTRL_ACTION >> c) & 1))) |
---|
2732 | | - && (c != 127 || vc->vc_disp_ctrl) |
---|
2733 | | - && (c != 128+27); |
---|
2734 | | - |
---|
2735 | | - if (vc->vc_state == ESnormal && ok) { |
---|
2736 | | - if (vc->vc_utf && !vc->vc_disp_ctrl) { |
---|
2737 | | - if (is_double_width(c)) |
---|
2738 | | - width = 2; |
---|
2739 | | - } |
---|
2740 | | - /* Now try to find out how to display it */ |
---|
2741 | | - tc = conv_uni_to_pc(vc, tc); |
---|
2742 | | - if (tc & ~charmask) { |
---|
2743 | | - if (tc == -1 || tc == -2) { |
---|
2744 | | - continue; /* nothing to display */ |
---|
2745 | | - } |
---|
2746 | | - /* Glyph not found */ |
---|
2747 | | - if ((!(vc->vc_utf && !vc->vc_disp_ctrl) || c < 128) && !(c & ~charmask)) { |
---|
2748 | | - /* In legacy mode use the glyph we get by a 1:1 mapping. |
---|
2749 | | - This would make absolutely no sense with Unicode in mind, |
---|
2750 | | - but do this for ASCII characters since a font may lack |
---|
2751 | | - Unicode mapping info and we don't want to end up with |
---|
2752 | | - having question marks only. */ |
---|
2753 | | - tc = c; |
---|
2754 | | - } else { |
---|
2755 | | - /* Display U+FFFD. If it's not found, display an inverse question mark. */ |
---|
2756 | | - tc = conv_uni_to_pc(vc, 0xfffd); |
---|
2757 | | - if (tc < 0) { |
---|
2758 | | - inverse = 1; |
---|
2759 | | - tc = conv_uni_to_pc(vc, '?'); |
---|
2760 | | - if (tc < 0) tc = '?'; |
---|
2761 | | - } |
---|
2762 | | - } |
---|
2763 | | - } |
---|
2764 | | - |
---|
2765 | | - if (!inverse) { |
---|
2766 | | - vc_attr = vc->vc_attr; |
---|
2767 | | - } else { |
---|
2768 | | - /* invert vc_attr */ |
---|
2769 | | - if (!vc->vc_can_do_color) { |
---|
2770 | | - vc_attr = (vc->vc_attr) ^ 0x08; |
---|
2771 | | - } else if (vc->vc_hi_font_mask == 0x100) { |
---|
2772 | | - vc_attr = ((vc->vc_attr) & 0x11) | (((vc->vc_attr) & 0xe0) >> 4) | (((vc->vc_attr) & 0x0e) << 4); |
---|
2773 | | - } else { |
---|
2774 | | - vc_attr = ((vc->vc_attr) & 0x88) | (((vc->vc_attr) & 0x70) >> 4) | (((vc->vc_attr) & 0x07) << 4); |
---|
2775 | | - } |
---|
2776 | | - con_flush(vc, draw_from, draw_to, &draw_x); |
---|
2777 | | - } |
---|
2778 | | - |
---|
2779 | | - next_c = c; |
---|
2780 | | - while (1) { |
---|
2781 | | - if (vc->vc_need_wrap || vc->vc_decim) |
---|
2782 | | - con_flush(vc, draw_from, draw_to, |
---|
2783 | | - &draw_x); |
---|
2784 | | - if (vc->vc_need_wrap) { |
---|
2785 | | - cr(vc); |
---|
2786 | | - lf(vc); |
---|
2787 | | - } |
---|
2788 | | - if (vc->vc_decim) |
---|
2789 | | - insert_char(vc, 1); |
---|
2790 | | - vc_uniscr_putc(vc, next_c); |
---|
2791 | | - scr_writew(himask ? |
---|
2792 | | - ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) : |
---|
2793 | | - (vc_attr << 8) + tc, |
---|
2794 | | - (u16 *) vc->vc_pos); |
---|
2795 | | - if (con_should_update(vc) && draw_x < 0) { |
---|
2796 | | - draw_x = vc->vc_x; |
---|
2797 | | - draw_from = vc->vc_pos; |
---|
2798 | | - } |
---|
2799 | | - if (vc->vc_x == vc->vc_cols - 1) { |
---|
2800 | | - vc->vc_need_wrap = vc->vc_decawm; |
---|
2801 | | - draw_to = vc->vc_pos + 2; |
---|
2802 | | - } else { |
---|
2803 | | - vc->vc_x++; |
---|
2804 | | - draw_to = (vc->vc_pos += 2); |
---|
2805 | | - } |
---|
2806 | | - |
---|
2807 | | - if (!--width) break; |
---|
2808 | | - |
---|
2809 | | - tc = conv_uni_to_pc(vc, ' '); /* A space is printed in the second column */ |
---|
2810 | | - if (tc < 0) tc = ' '; |
---|
2811 | | - next_c = ' '; |
---|
2812 | | - } |
---|
2813 | | - notify_write(vc, c); |
---|
2814 | | - |
---|
2815 | | - if (inverse) |
---|
2816 | | - con_flush(vc, draw_from, draw_to, &draw_x); |
---|
2817 | | - |
---|
2818 | | - if (rescan) { |
---|
2819 | | - rescan = 0; |
---|
2820 | | - inverse = 0; |
---|
2821 | | - width = 1; |
---|
2822 | | - c = orig; |
---|
2823 | | - goto rescan_last_byte; |
---|
2824 | | - } |
---|
| 2950 | + if (vc_is_control(vc, tc, c)) { |
---|
| 2951 | + con_flush(vc, &draw); |
---|
| 2952 | + do_con_trol(tty, vc, orig); |
---|
2825 | 2953 | continue; |
---|
2826 | 2954 | } |
---|
2827 | | - con_flush(vc, draw_from, draw_to, &draw_x); |
---|
2828 | | - do_con_trol(tty, vc, orig); |
---|
| 2955 | + |
---|
| 2956 | + if (vc_con_write_normal(vc, tc, c, &draw) < 0) |
---|
| 2957 | + continue; |
---|
| 2958 | + |
---|
| 2959 | + if (rescan) |
---|
| 2960 | + goto rescan_last_byte; |
---|
2829 | 2961 | } |
---|
2830 | | - con_flush(vc, draw_from, draw_to, &draw_x); |
---|
| 2962 | + con_flush(vc, &draw); |
---|
2831 | 2963 | vc_uniscr_debug_check(vc); |
---|
2832 | 2964 | console_conditional_schedule(); |
---|
2833 | 2965 | notify_update(vc); |
---|
.. | .. |
---|
2969 | 3101 | goto quit; |
---|
2970 | 3102 | } |
---|
2971 | 3103 | |
---|
2972 | | - if (vc->vc_mode != KD_TEXT && !vt_force_oops_output(vc)) |
---|
| 3104 | + if (vc->vc_mode != KD_TEXT) |
---|
2973 | 3105 | goto quit; |
---|
2974 | 3106 | |
---|
2975 | 3107 | /* undraw cursor first */ |
---|
.. | .. |
---|
2977 | 3109 | hide_cursor(vc); |
---|
2978 | 3110 | |
---|
2979 | 3111 | start = (ushort *)vc->vc_pos; |
---|
2980 | | - start_x = vc->vc_x; |
---|
| 3112 | + start_x = vc->state.x; |
---|
2981 | 3113 | cnt = 0; |
---|
2982 | 3114 | while (count--) { |
---|
2983 | 3115 | c = *b++; |
---|
2984 | 3116 | if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) { |
---|
2985 | 3117 | if (cnt && con_is_visible(vc)) |
---|
2986 | | - vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, start_x); |
---|
| 3118 | + vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x); |
---|
2987 | 3119 | cnt = 0; |
---|
2988 | 3120 | if (c == 8) { /* backspace */ |
---|
2989 | 3121 | bs(vc); |
---|
2990 | 3122 | start = (ushort *)vc->vc_pos; |
---|
2991 | | - start_x = vc->vc_x; |
---|
| 3123 | + start_x = vc->state.x; |
---|
2992 | 3124 | continue; |
---|
2993 | 3125 | } |
---|
2994 | 3126 | if (c != 13) |
---|
2995 | 3127 | lf(vc); |
---|
2996 | 3128 | cr(vc); |
---|
2997 | 3129 | start = (ushort *)vc->vc_pos; |
---|
2998 | | - start_x = vc->vc_x; |
---|
| 3130 | + start_x = vc->state.x; |
---|
2999 | 3131 | if (c == 10 || c == 13) |
---|
3000 | 3132 | continue; |
---|
3001 | 3133 | } |
---|
.. | .. |
---|
3003 | 3135 | scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos); |
---|
3004 | 3136 | notify_write(vc, c); |
---|
3005 | 3137 | cnt++; |
---|
3006 | | - if (vc->vc_x == vc->vc_cols - 1) { |
---|
| 3138 | + if (vc->state.x == vc->vc_cols - 1) { |
---|
3007 | 3139 | vc->vc_need_wrap = 1; |
---|
3008 | 3140 | } else { |
---|
3009 | 3141 | vc->vc_pos += 2; |
---|
3010 | | - vc->vc_x++; |
---|
| 3142 | + vc->state.x++; |
---|
3011 | 3143 | } |
---|
3012 | 3144 | } |
---|
3013 | 3145 | if (cnt && con_is_visible(vc)) |
---|
3014 | | - vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, start_x); |
---|
| 3146 | + vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x); |
---|
3015 | 3147 | set_cursor(vc); |
---|
3016 | 3148 | notify_update(vc); |
---|
3017 | 3149 | |
---|
.. | .. |
---|
3047 | 3179 | * There are some functions which can sleep for arbitrary periods |
---|
3048 | 3180 | * (paste_selection) but we don't need the lock there anyway. |
---|
3049 | 3181 | * |
---|
3050 | | - * set_selection has locking, and definitely needs it |
---|
| 3182 | + * set_selection_user has locking, and definitely needs it |
---|
3051 | 3183 | */ |
---|
3052 | 3184 | |
---|
3053 | 3185 | int tioclinux(struct tty_struct *tty, unsigned long arg) |
---|
.. | .. |
---|
3066 | 3198 | switch (type) |
---|
3067 | 3199 | { |
---|
3068 | 3200 | case TIOCL_SETSEL: |
---|
3069 | | - ret = set_selection((struct tiocl_selection __user *)(p+1), tty); |
---|
| 3201 | + ret = set_selection_user((struct tiocl_selection |
---|
| 3202 | + __user *)(p+1), tty); |
---|
3070 | 3203 | break; |
---|
3071 | 3204 | case TIOCL_PASTESEL: |
---|
3072 | 3205 | ret = paste_selection(tty); |
---|
.. | .. |
---|
3362 | 3495 | |
---|
3363 | 3496 | console_lock(); |
---|
3364 | 3497 | |
---|
3365 | | - if (conswitchp) |
---|
3366 | | - display_desc = conswitchp->con_startup(); |
---|
| 3498 | + if (!conswitchp) |
---|
| 3499 | + conswitchp = &dummy_con; |
---|
| 3500 | + display_desc = conswitchp->con_startup(); |
---|
3367 | 3501 | if (!display_desc) { |
---|
3368 | 3502 | fg_console = 0; |
---|
3369 | 3503 | console_unlock(); |
---|
.. | .. |
---|
3405 | 3539 | master_display_fg = vc = vc_cons[currcons].d; |
---|
3406 | 3540 | set_origin(vc); |
---|
3407 | 3541 | save_screen(vc); |
---|
3408 | | - gotoxy(vc, vc->vc_x, vc->vc_y); |
---|
| 3542 | + gotoxy(vc, vc->state.x, vc->state.y); |
---|
3409 | 3543 | csi_J(vc, 0); |
---|
3410 | 3544 | update_screen(vc); |
---|
3411 | 3545 | pr_info("Console: %s %s %dx%d\n", |
---|
.. | .. |
---|
3605 | 3739 | |
---|
3606 | 3740 | |
---|
3607 | 3741 | #ifdef CONFIG_VT_HW_CONSOLE_BINDING |
---|
3608 | | -/* unlocked version of unbind_con_driver() */ |
---|
3609 | 3742 | int do_unbind_con_driver(const struct consw *csw, int first, int last, int deflt) |
---|
3610 | 3743 | { |
---|
3611 | 3744 | struct module *owner = csw->owner; |
---|
.. | .. |
---|
3809 | 3942 | char *buf) |
---|
3810 | 3943 | { |
---|
3811 | 3944 | struct con_driver *con = dev_get_drvdata(dev); |
---|
3812 | | - int bind = con_is_bound(con->con); |
---|
| 3945 | + int bind; |
---|
| 3946 | + |
---|
| 3947 | + console_lock(); |
---|
| 3948 | + bind = con_is_bound(con->con); |
---|
| 3949 | + console_unlock(); |
---|
3813 | 3950 | |
---|
3814 | 3951 | return snprintf(buf, PAGE_SIZE, "%i\n", bind); |
---|
3815 | 3952 | } |
---|
.. | .. |
---|
3860 | 3997 | { |
---|
3861 | 3998 | int i, bound = 0; |
---|
3862 | 3999 | |
---|
| 4000 | + WARN_CONSOLE_UNLOCKED(); |
---|
| 4001 | + |
---|
3863 | 4002 | for (i = 0; i < MAX_NR_CONSOLES; i++) { |
---|
3864 | 4003 | if (con_driver_map[i] == csw) { |
---|
3865 | 4004 | bound = 1; |
---|
.. | .. |
---|
3872 | 4011 | EXPORT_SYMBOL(con_is_bound); |
---|
3873 | 4012 | |
---|
3874 | 4013 | /** |
---|
| 4014 | + * con_is_visible - checks whether the current console is visible |
---|
| 4015 | + * @vc: virtual console |
---|
| 4016 | + * |
---|
| 4017 | + * RETURNS: zero if not visible, nonzero if visible |
---|
| 4018 | + */ |
---|
| 4019 | +bool con_is_visible(const struct vc_data *vc) |
---|
| 4020 | +{ |
---|
| 4021 | + WARN_CONSOLE_UNLOCKED(); |
---|
| 4022 | + |
---|
| 4023 | + return *vc->vc_display_fg == vc; |
---|
| 4024 | +} |
---|
| 4025 | +EXPORT_SYMBOL(con_is_visible); |
---|
| 4026 | + |
---|
| 4027 | +/** |
---|
3875 | 4028 | * con_debug_enter - prepare the console for the kernel debugger |
---|
3876 | | - * @sw: console driver |
---|
| 4029 | + * @vc: virtual console |
---|
3877 | 4030 | * |
---|
3878 | 4031 | * Called when the console is taken over by the kernel debugger, this |
---|
3879 | 4032 | * function needs to save the current console state, then put the console |
---|
.. | .. |
---|
3931 | 4084 | |
---|
3932 | 4085 | /** |
---|
3933 | 4086 | * con_debug_leave - restore console state |
---|
3934 | | - * @sw: console driver |
---|
3935 | 4087 | * |
---|
3936 | 4088 | * Restore the console state to what it was before the kernel debugger |
---|
3937 | 4089 | * was invoked. |
---|
.. | .. |
---|
4113 | 4265 | * when a driver wants to take over some existing consoles |
---|
4114 | 4266 | * and become default driver for newly opened ones. |
---|
4115 | 4267 | * |
---|
4116 | | - * do_take_over_console is basically a register followed by unbind |
---|
| 4268 | + * do_take_over_console is basically a register followed by bind |
---|
4117 | 4269 | */ |
---|
4118 | 4270 | int do_take_over_console(const struct consw *csw, int first, int last, int deflt) |
---|
4119 | 4271 | { |
---|
.. | .. |
---|
4204 | 4356 | struct vc_data *vc = vc_cons[fg_console].d; |
---|
4205 | 4357 | int i; |
---|
4206 | 4358 | |
---|
| 4359 | + might_sleep(); |
---|
| 4360 | + |
---|
4207 | 4361 | WARN_CONSOLE_UNLOCKED(); |
---|
4208 | 4362 | |
---|
4209 | 4363 | if (console_blanked) { |
---|
.. | .. |
---|
4281 | 4435 | return; |
---|
4282 | 4436 | } |
---|
4283 | 4437 | vc = vc_cons[fg_console].d; |
---|
4284 | | - /* Try to unblank in oops case too */ |
---|
4285 | | - if (vc->vc_mode != KD_TEXT && !vt_force_oops_output(vc)) |
---|
| 4438 | + if (vc->vc_mode != KD_TEXT) |
---|
4286 | 4439 | return; /* but leave console_blanked != 0 */ |
---|
4287 | 4440 | |
---|
4288 | 4441 | if (blankinterval) { |
---|
.. | .. |
---|
4291 | 4444 | } |
---|
4292 | 4445 | |
---|
4293 | 4446 | console_blanked = 0; |
---|
4294 | | - if (vc->vc_sw->con_blank(vc, 0, leaving_gfx) || vt_force_oops_output(vc)) |
---|
| 4447 | + if (vc->vc_sw->con_blank(vc, 0, leaving_gfx)) |
---|
4295 | 4448 | /* Low-level driver cannot restore -> do it ourselves */ |
---|
4296 | 4449 | update_screen(vc); |
---|
4297 | 4450 | if (console_blank_hook) |
---|
.. | .. |
---|
4472 | 4625 | |
---|
4473 | 4626 | if (op->data && font.charcount > op->charcount) |
---|
4474 | 4627 | rc = -ENOSPC; |
---|
4475 | | - if (!(op->flags & KD_FONT_FLAG_OLD)) { |
---|
4476 | | - if (font.width > op->width || font.height > op->height) |
---|
4477 | | - rc = -ENOSPC; |
---|
4478 | | - } else { |
---|
4479 | | - if (font.width != 8) |
---|
4480 | | - rc = -EIO; |
---|
4481 | | - else if ((op->height && font.height > op->height) || |
---|
4482 | | - font.height > 32) |
---|
4483 | | - rc = -ENOSPC; |
---|
4484 | | - } |
---|
| 4628 | + if (font.width > op->width || font.height > op->height) |
---|
| 4629 | + rc = -ENOSPC; |
---|
4485 | 4630 | if (rc) |
---|
4486 | 4631 | goto out; |
---|
4487 | 4632 | |
---|
.. | .. |
---|
4509 | 4654 | return -EINVAL; |
---|
4510 | 4655 | if (op->charcount > 512) |
---|
4511 | 4656 | return -EINVAL; |
---|
4512 | | - if (op->width <= 0 || op->width > 32 || op->height > 32) |
---|
| 4657 | + if (op->width <= 0 || op->width > 32 || !op->height || op->height > 32) |
---|
4513 | 4658 | return -EINVAL; |
---|
4514 | 4659 | size = (op->width+7)/8 * 32 * op->charcount; |
---|
4515 | 4660 | if (size > max_font_size) |
---|
.. | .. |
---|
4519 | 4664 | if (IS_ERR(font.data)) |
---|
4520 | 4665 | return PTR_ERR(font.data); |
---|
4521 | 4666 | |
---|
4522 | | - if (!op->height) { /* Need to guess font height [compat] */ |
---|
4523 | | - int h, i; |
---|
4524 | | - u8 *charmap = font.data; |
---|
4525 | | - |
---|
4526 | | - /* |
---|
4527 | | - * If from KDFONTOP ioctl, don't allow things which can be done |
---|
4528 | | - * in userland,so that we can get rid of this soon |
---|
4529 | | - */ |
---|
4530 | | - if (!(op->flags & KD_FONT_FLAG_OLD)) { |
---|
4531 | | - kfree(font.data); |
---|
4532 | | - return -EINVAL; |
---|
4533 | | - } |
---|
4534 | | - |
---|
4535 | | - for (h = 32; h > 0; h--) |
---|
4536 | | - for (i = 0; i < op->charcount; i++) |
---|
4537 | | - if (charmap[32*i+h-1]) |
---|
4538 | | - goto nonzero; |
---|
4539 | | - |
---|
4540 | | - kfree(font.data); |
---|
4541 | | - return -EINVAL; |
---|
4542 | | - |
---|
4543 | | - nonzero: |
---|
4544 | | - op->height = h; |
---|
4545 | | - } |
---|
4546 | | - |
---|
4547 | 4667 | font.charcount = op->charcount; |
---|
4548 | 4668 | font.width = op->width; |
---|
4549 | 4669 | font.height = op->height; |
---|
.. | .. |
---|
4551 | 4671 | console_lock(); |
---|
4552 | 4672 | if (vc->vc_mode != KD_TEXT) |
---|
4553 | 4673 | rc = -EINVAL; |
---|
4554 | | - else if (vc->vc_sw->con_font_set) |
---|
| 4674 | + else if (vc->vc_sw->con_font_set) { |
---|
| 4675 | + if (vc_is_sel(vc)) |
---|
| 4676 | + clear_selection(); |
---|
4555 | 4677 | rc = vc->vc_sw->con_font_set(vc, &font, op->flags); |
---|
4556 | | - else |
---|
| 4678 | + } else |
---|
4557 | 4679 | rc = -ENOSYS; |
---|
4558 | 4680 | console_unlock(); |
---|
4559 | 4681 | kfree(font.data); |
---|
.. | .. |
---|
4580 | 4702 | console_unlock(); |
---|
4581 | 4703 | return -EINVAL; |
---|
4582 | 4704 | } |
---|
4583 | | - if (vc->vc_sw->con_font_default) |
---|
| 4705 | + if (vc->vc_sw->con_font_default) { |
---|
| 4706 | + if (vc_is_sel(vc)) |
---|
| 4707 | + clear_selection(); |
---|
4584 | 4708 | rc = vc->vc_sw->con_font_default(vc, &font, s); |
---|
4585 | | - else |
---|
| 4709 | + } else |
---|
4586 | 4710 | rc = -ENOSYS; |
---|
4587 | 4711 | console_unlock(); |
---|
4588 | 4712 | if (!rc) { |
---|
.. | .. |
---|
4613 | 4737 | */ |
---|
4614 | 4738 | |
---|
4615 | 4739 | /* used by selection */ |
---|
4616 | | -u16 screen_glyph(struct vc_data *vc, int offset) |
---|
| 4740 | +u16 screen_glyph(const struct vc_data *vc, int offset) |
---|
4617 | 4741 | { |
---|
4618 | | - u16 w = scr_readw(screenpos(vc, offset, 1)); |
---|
| 4742 | + u16 w = scr_readw(screenpos(vc, offset, true)); |
---|
4619 | 4743 | u16 c = w & 0xff; |
---|
4620 | 4744 | |
---|
4621 | 4745 | if (w & vc->vc_hi_font_mask) |
---|
.. | .. |
---|
4624 | 4748 | } |
---|
4625 | 4749 | EXPORT_SYMBOL_GPL(screen_glyph); |
---|
4626 | 4750 | |
---|
4627 | | -u32 screen_glyph_unicode(struct vc_data *vc, int n) |
---|
| 4751 | +u32 screen_glyph_unicode(const struct vc_data *vc, int n) |
---|
4628 | 4752 | { |
---|
4629 | 4753 | struct uni_screen *uniscr = get_vc_uniscr(vc); |
---|
4630 | 4754 | |
---|
.. | .. |
---|
4635 | 4759 | EXPORT_SYMBOL_GPL(screen_glyph_unicode); |
---|
4636 | 4760 | |
---|
4637 | 4761 | /* used by vcs - note the word offset */ |
---|
4638 | | -unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed) |
---|
| 4762 | +unsigned short *screen_pos(const struct vc_data *vc, int w_offset, bool viewed) |
---|
4639 | 4763 | { |
---|
4640 | 4764 | return screenpos(vc, 2 * w_offset, viewed); |
---|
4641 | 4765 | } |
---|
4642 | 4766 | EXPORT_SYMBOL_GPL(screen_pos); |
---|
4643 | 4767 | |
---|
4644 | | -void getconsxy(struct vc_data *vc, unsigned char *p) |
---|
| 4768 | +void getconsxy(const struct vc_data *vc, unsigned char xy[static 2]) |
---|
4645 | 4769 | { |
---|
4646 | | - p[0] = vc->vc_x; |
---|
4647 | | - p[1] = vc->vc_y; |
---|
| 4770 | + /* clamp values if they don't fit */ |
---|
| 4771 | + xy[0] = min(vc->state.x, 0xFFu); |
---|
| 4772 | + xy[1] = min(vc->state.y, 0xFFu); |
---|
4648 | 4773 | } |
---|
4649 | 4774 | |
---|
4650 | | -void putconsxy(struct vc_data *vc, unsigned char *p) |
---|
| 4775 | +void putconsxy(struct vc_data *vc, unsigned char xy[static const 2]) |
---|
4651 | 4776 | { |
---|
4652 | 4777 | hide_cursor(vc); |
---|
4653 | | - gotoxy(vc, p[0], p[1]); |
---|
| 4778 | + gotoxy(vc, xy[0], xy[1]); |
---|
4654 | 4779 | set_cursor(vc); |
---|
4655 | 4780 | } |
---|
4656 | 4781 | |
---|
4657 | | -u16 vcs_scr_readw(struct vc_data *vc, const u16 *org) |
---|
| 4782 | +u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org) |
---|
4658 | 4783 | { |
---|
4659 | 4784 | if ((unsigned long)org == vc->vc_pos && softcursor_original != -1) |
---|
4660 | 4785 | return softcursor_original; |
---|