[PATCH 2/3] tty/vt: Prevent 8th bit corruption with soft cursor

Zsolt Kajtar posted 3 patches 1 month ago
There is a newer version of this series
[PATCH 2/3] tty/vt: Prevent 8th bit corruption with soft cursor
Posted by Zsolt Kajtar 1 month ago
The attributes of the soft cursor are configurable and one would rightly
expect that only the attributes are to be affected. But that's not
guaranteed for a font with 512 glyphs as the 8th bit is in the attribute
byte. This patch makes sure that really only the attribute bits are
changed by the cursor and not the glyph's appearance.

Signed-off-by: Zsolt Kajtar <soci@c64.rulez.org>
---
 drivers/tty/vt/vt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index c6c931047..d54f4d24e 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -823,6 +823,7 @@ static void add_softcursor(struct vc_data *vc)
 {
 	int i = scr_readw((u16 *) vc->vc_pos);
 	u32 type = vc->vc_cursor_type;
+	int mask = vc->vc_hi_font_mask | 0xff;
 
 	if (!(type & CUR_SW))
 		return;
@@ -836,6 +837,7 @@ static void add_softcursor(struct vc_data *vc)
 		i ^= CUR_BG;
 	if ((type & CUR_INVERT_FG_BG) && (i & CUR_FG) == ((i & CUR_BG) >> 4))
 		i ^= CUR_FG;
+	i = (i & ~mask) | (softcursor_original & mask);
 	scr_writew(i, (u16 *)vc->vc_pos);
 	if (con_should_update(vc))
 		con_putc(vc, i, vc->state.y, vc->state.x);
-- 
2.30.2
Re: [PATCH 2/3] tty/vt: Prevent 8th bit corruption with soft cursor
Posted by Jiri Slaby 1 month ago
On 29. 08. 25, 21:49, Zsolt Kajtar wrote:
> The attributes of the soft cursor are configurable and one would rightly
> expect that only the attributes are to be affected. But that's not
> guaranteed for a font with 512 glyphs as the 8th bit is in the attribute
> byte. This patch makes sure that really only the attribute bits are
> changed by the cursor and not the glyph's appearance.
> 
> Signed-off-by: Zsolt Kajtar <soci@c64.rulez.org>
> ---
>   drivers/tty/vt/vt.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index c6c931047..d54f4d24e 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -823,6 +823,7 @@ static void add_softcursor(struct vc_data *vc)
>   {
>   	int i = scr_readw((u16 *) vc->vc_pos);

It's terrible how the current code uses weird types (int here).

>   	u32 type = vc->vc_cursor_type;
> +	int mask = vc->vc_hi_font_mask | 0xff;

But since you are introducing a new one, use u16, not int. Esp. when it 
is a mask.
>   	if (!(type & CUR_SW))
>   		return;
> @@ -836,6 +837,7 @@ static void add_softcursor(struct vc_data *vc)
>   		i ^= CUR_BG;
>   	if ((type & CUR_INVERT_FG_BG) && (i & CUR_FG) == ((i & CUR_BG) >> 4))
>   		i ^= CUR_FG;
> +	i = (i & ~mask) | (softcursor_original & mask);
>   	scr_writew(i, (u16 *)vc->vc_pos);
>   	if (con_should_update(vc))
>   		con_putc(vc, i, vc->state.y, vc->state.x);

thanks,
-- 
js
suse labs