History

vt: convert vc_tab_stop to bitmap

vc_tab_stop is used as a bitmap, but defined as an unsigned int array. Switch it to bitmap and convert all users to the bitmap interface. Note the difference in behavior! We no longer mask the top 24 bits away from x, hence we do not wrap tabs at 256th column. Instead, we silently drop attempts to set a tab behind 256 columns. And we will also seek by '\t' to the rightmost column, when behind that boundary. I do not think the original behavior was desired and that someone relies on that. If this turns out to be the case, we can change the added 'if's back to masks here and there instead... (Or we can increase the limit as fb consoles now have 240 chars here. And they could have more with higher than my resolution, of course.)

Jiri Slaby committed 6 years ago

Commit dbee4cf1 parent b70ec4d2 files · +20 −27Browse files

Unified · Split

2 files
  1. drivers/tty/vt/vt.c +18 −26
  2. include/linux/console_struct.h +2 −1
drivers/tty/vt/vt.c+18−26
@@ -2052,6 +2052,8 @@ enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, · 2051 unmodified lines
2052/* console_lock is held (except via vc_init()) */2052/* console_lock is held (except via vc_init()) */
2053static void reset_terminal(struct vc_data *vc, int do_clear)2053static void reset_terminal(struct vc_data *vc, int do_clear)
2054{2054{
2055 unsigned int i;
2056
2055 vc->vc_top = 0;2057 vc->vc_top = 0;
2056 vc->vc_bottom = vc->vc_rows;2058 vc->vc_bottom = vc->vc_rows;
2057 vc->vc_state = ESnormal;2059 vc->vc_state = ESnormal;
@@ -2082,14 +2084,9 @@ static void reset_terminal(struct vc_data *vc, int do_clear) · 24 unmodified lines
2082 default_attr(vc);2084 default_attr(vc);
2083 update_attr(vc);2085 update_attr(vc);
2084 2086
2085 vc->vc_tab_stop[0] =2087 bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2086 vc->vc_tab_stop[1] =2088 for (i = 0; i < VC_TABSTOPS_COUNT; i += 8)
2087 vc->vc_tab_stop[2] =2089 set_bit(i, vc->vc_tab_stop);
2088 vc->vc_tab_stop[3] =
2089 vc->vc_tab_stop[4] =
2090 vc->vc_tab_stop[5] =
2091 vc->vc_tab_stop[6] =
2092 vc->vc_tab_stop[7] = 0x01010101;
2093 2090
2094 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;2091 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
2095 vc->vc_bell_duration = DEFAULT_BELL_DURATION;2092 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
@@ -2147,11 +2144,13 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 51 unmodified lines
2147 return;2144 return;
2148 case 9:2145 case 9:
2149 vc->vc_pos -= (vc->state.x << 1);2146 vc->vc_pos -= (vc->state.x << 1);
2150 while (vc->state.x < vc->vc_cols - 1) {2147
2151 vc->state.x++;2148 vc->state.x = find_next_bit(vc->vc_tab_stop,
2152 if (vc->vc_tab_stop[7 & (vc->state.x >> 5)] & (1 << (vc->state.x & 31)))2149 min(vc->vc_cols - 1, VC_TABSTOPS_COUNT),
2153 break;2150 vc->state.x + 1);
2154 }2151 if (vc->state.x >= VC_TABSTOPS_COUNT)
2152 vc->state.x = vc->vc_cols - 1;
2153
2155 vc->vc_pos += (vc->state.x << 1);2154 vc->vc_pos += (vc->state.x << 1);
2156 notify_write(vc, '\t');2155 notify_write(vc, '\t');
2157 return;2156 return;
@@ -2210,7 +2209,8 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 52 unmodified lines
2210 lf(vc);2209 lf(vc);
2211 return;2210 return;
2212 case 'H':2211 case 'H':
2213 vc->vc_tab_stop[7 & (vc->state.x >> 5)] |= (1 << (vc->state.x & 31));2212 if (vc->state.x < VC_TABSTOPS_COUNT)
2213 set_bit(vc->state.x, vc->vc_tab_stop);
2214 return;2214 return;
2215 case 'Z':2215 case 'Z':
2216 respond_ID(tty);2216 respond_ID(tty);
@@ -2421,18 +2421,10 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) · 204 unmodified lines
2421 respond_ID(tty);2421 respond_ID(tty);
2422 return;2422 return;
2423 case 'g':2423 case 'g':
2424 if (!vc->vc_par[0])2424 if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT)
2425 vc->vc_tab_stop[7 & (vc->state.x >> 5)] &= ~(1 << (vc->state.x & 31));2425 set_bit(vc->state.x, vc->vc_tab_stop);
2426 else if (vc->vc_par[0] == 3) {2426 else if (vc->vc_par[0] == 3)
2427 vc->vc_tab_stop[0] =2427 bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2428 vc->vc_tab_stop[1] =
2429 vc->vc_tab_stop[2] =
2430 vc->vc_tab_stop[3] =
2431 vc->vc_tab_stop[4] =
2432 vc->vc_tab_stop[5] =
2433 vc->vc_tab_stop[6] =
2434 vc->vc_tab_stop[7] = 0;
2435 }
2436 return;2428 return;
2437 case 'm':2429 case 'm':
2438 csi_m(vc);2430 csi_m(vc);
include/linux/console_struct.h+2−1
@@ -21,6 +21,7 @@ struct uni_pagedir; · 20 unmodified lines
21struct uni_screen;21struct uni_screen;
22 22
23#define NPAR 1623#define NPAR 16
24#define VC_TABSTOPS_COUNT 256U
24 25
25enum vc_intensity {26enum vc_intensity {
26 VCI_HALF_BRIGHT,27 VCI_HALF_BRIGHT,
@@ -147,7 +148,7 @@ struct vc_data { · 120 unmodified lines
147 unsigned char vc_utf : 1; /* Unicode UTF-8 encoding */148 unsigned char vc_utf : 1; /* Unicode UTF-8 encoding */
148 unsigned char vc_utf_count;149 unsigned char vc_utf_count;
149 int vc_utf_char;150 int vc_utf_char;
150 unsigned int vc_tab_stop[8]; /* Tab stops. 256 columns. */151 DECLARE_BITMAP(vc_tab_stop, VC_TABSTOPS_COUNT); /* Tab stops. 256 columns. */
151 unsigned char vc_palette[16*3]; /* Colour palette for VGA+ */152 unsigned char vc_palette[16*3]; /* Colour palette for VGA+ */
152 unsigned short * vc_translate;153 unsigned short * vc_translate;
153 unsigned int vc_resize_user; /* resize request from user */154 unsigned int vc_resize_user; /* resize request from user */