Skip to contentSkip to conversation

VGA console endian bug

PATCH Hollis Blanchard 3 participants 8 messages Aug 9, 2001 – Aug 11, 2001

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

These two patches came from Daniel Berlin on July 9. They completely resolve the VGA console backwards-endian problem for me on PPC. If they have Geert's seal of approval ;) can they be committed?

-Hollis

include/asm-ppc/vga.h renamed from include/asm-ppc/vga.h.old +3 -0
@@ -37,6 +37,9 @@
 
 #define VT_BUF_HAVE_MEMCPYW
 #define scr_memcpyw	memcpy
+#define VT_BUF_HAVE_MEMCPYF
+#define scr_memcpyw_to memcpy
+#define scr_memcpyw_from memcpy
 
 #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */
 
drivers/video/fbcon.c renamed from drivers/video/fbcon.c.old +4 -4
@@ -2028,13 +2028,13 @@
 	if (!conp->vc_can_do_color)
 	    *p++ ^= 0x0800;
 	else if (conp->vc_hi_font_mask == 0x100) {
-	    u16 a = *p;
+	    u16 a = scr_read(p);
 	    a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
-	    *p++ = a;
+	    scr_write(a, p++);
 	} else {
-	    u16 a = *p;
+	    u16 a = scr_read(p);
 	    a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
-	    *p++ = a;
+	    scr_write(a, p++);
 	}
 	if (p == (u16 *)softback_end)
 	    p = (u16 *)softback_buf;

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 9 lines · Hollis Blanchard

These two patches came from Daniel Berlin on July 9. They completely resolve the VGA console backwards-endian problem for me on PPC. If they have Geert's seal of approval ;) can they be committed?

(quoted diff) +0 -1
-Hollis

include/asm-ppc/vga.h line 44

Quoted 8 lines
include/asm-ppc/vga.h renamed from include/asm-ppc/vga.h.old +3 -0
@@ -37,6 +37,9 @@
 
 #define VT_BUF_HAVE_MEMCPYW
 #define scr_memcpyw	memcpy
+#define VT_BUF_HAVE_MEMCPYF
+#define scr_memcpyw_to memcpy
+#define scr_memcpyw_from memcpy
 
 #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */

The first I cannot approve: if scr_{write,read}w() swap bytes, how can it work if scr_memcpyw_{to,from}() don't swap bytes?

Quoted 10 lines
drivers/video/fbcon.c renamed from drivers/video/fbcon.c.old +1 -2
@@ -2028,13 +2028,13 @@
 	if (!conp->vc_can_do_color)
 	    *p++ ^= 0x0800;
 	else if (conp->vc_hi_font_mask == 0x100) {
-	    u16 a = *p;
+	    u16 a = scr_read(p);
 	    a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
-	    *p++ = a;

drivers/video/fbcon.c line 2040

Quoted 10 lines
drivers/video/fbcon.c renamed from drivers/video/fbcon.c.old +3 -2
+	    scr_write(a, p++);
 	} else {
-	    u16 a = *p;
+	    u16 a = scr_read(p);
 	    a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
-	    *p++ = a;
+	    scr_write(a, p++);
 	}
 	if (p == (u16 *)softback_end)
 	    p = (u16 *)softback_buf;

Approved :-)

And where's the 3rd patch? I once posted a patch to fix a similar bug in drivers/char/console.c.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw
Quoted 18 lines · Geert Uytterhoeven
Quoted 16 lines · Hollis Blanchard

These two patches came from Daniel Berlin on July 9. They completely resolve the VGA console backwards-endian problem for me on PPC. If they have Geert's seal of approval ;) can they be committed?

(quoted diff) +0 -1
-Hollis
include/asm-ppc/vga.h renamed from include/asm-ppc/vga.h.old +3 -0
@@ -37,6 +37,9 @@
 
 #define VT_BUF_HAVE_MEMCPYW
 #define scr_memcpyw	memcpy
+#define VT_BUF_HAVE_MEMCPYF
+#define scr_memcpyw_to memcpy
+#define scr_memcpyw_from memcpy
 
Quoted 4 lines

include/asm-ppc/vga.h line 44

Quoted 1 line
include/asm-ppc/vga.h renamed from include/asm-ppc/vga.h.old +0 -0
 #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */

The first I cannot approve: if scr_{write,read}w() swap bytes, how can it work if scr_memcpyw_{to,from}() don't swap bytes?

I have no idea. Perhaps those functions weren't used, and that's why it appeared to work. I have not tried with only the second patch; perhaps that will be enough...

Quoted 2 lines

And where's the 3rd patch? I once posted a patch to fix a similar bug in drivers/char/console.c.

I can't find it in the linuxppc-dev archives. :(

-Hollis

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw
Quoted 23 lines · Hollis Blanchard
Quoted 17 lines · Geert Uytterhoeven
Quoted 16 lines · Hollis Blanchard

These two patches came from Daniel Berlin on July 9. They completely resolve the VGA console backwards-endian problem for me on PPC. If they have Geert's seal of approval ;) can they be committed?

(quoted diff) +0 -1
-Hollis
include/asm-ppc/vga.h renamed from include/asm-ppc/vga.h.old +3 -0
@@ -37,6 +37,9 @@
 
 #define VT_BUF_HAVE_MEMCPYW
 #define scr_memcpyw	memcpy
+#define VT_BUF_HAVE_MEMCPYF
+#define scr_memcpyw_to memcpy
+#define scr_memcpyw_from memcpy
 
Quoted 4 lines

include/asm-ppc/vga.h line 44

Quoted 1 line
include/asm-ppc/vga.h renamed from include/asm-ppc/vga.h.old +0 -0
 #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */

The first I cannot approve: if scr_{write,read}w() swap bytes, how can it work if scr_memcpyw_{to,from}() don't swap bytes?

Quoted 8 lines

I have no idea. Perhaps those functions weren't used, and that's why it appeared to work. I have not tried with only the second patch; perhaps that will be enough...

Quoted 2 lines

And where's the 3rd patch? I once posted a patch to fix a similar bug in drivers/char/console.c.

I can't find it in the linuxppc-dev archives. :(

It indeed wasn't sent to that list. I attached the mail I sent to Ben H, which includes the mail I sent before.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

From [email protected] Sat Aug 11 10:31:13 2001
Date: Mon, 9 Jul 2001 18:45:14 +0200 (CEST)
From: Geert Uytterhoeven <[email protected]>
To: Benjamin Herrenschmidt <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Subject: Re: Fwd: Re: gpm selection vs VGA console & fbcon

Hi Ben,

Quoted 10 lines

Geert, does that patch sounds the right thing to you ? If yes, I'll push it all over the bk's and to Linus, I'm tired of getting this bug reported ;)

*** vga.h Wed Jul 4 10:58:40 2001
--- /root/linux/include/asm-ppc/vga.h Thu Jun 28 14:22:02 2001
*************** extern inline u16 scr_readw(volatile con *** 37,42 ****
--- 37,45 ----

Quoted 7 lines

#define VT_BUF_HAVE_MEMCPYW
#define scr_memcpyw memcpy
+ #define VT_BUF_HAVE_MEMCPYF
+ #define scr_memcpyw_to memcpy
+ #define scr_memcpyw_from memcpy

  #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */

I fail to see how the first part can solve a problem: scr_memcpyw_{to,from} copy between the VGA text buffer on the graphics card (little endian) and native endianness, so setting them to memcpy() cannot be right. I suspect there's another bug somewhere else...

Note that I've been having a fight with Olaf Hering about this as well :-)

BTW, the comment after the #endif is wrong, it should be

    #endif /* CONFIG_VGA_CONSOLE || CONFIG_MDA_CONSOLE */

instead of

    #endif /* !CONFIG_VGA_CONSOLE && !CONFIG_MDA_CONSOLE */
Quoted 23 lines

*** fbcon.c Tue Jul 3 17:58:41 2001
--- /root/linux/drivers/video/fbcon.c Wed Jun 27 14:52:59 2001
*************** static void fbcon_invert_region(struct v
*** 1954,1966 ****
if (!conp->vc_can_do_color)
*p++ ^= 0x0800;
else if (conp->vc_hi_font_mask == 0x100) {
! u16 a = *p;
a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
! *p++ = a;
} else {
! u16 a = *p;
a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
! *p++ = a;
}
if (p == (u16 *)softback_end)
p = (u16 *)softback_buf;
--- 1954,1966 ----
if (!conp->vc_can_do_color)
*p++ ^= 0x0800;
else if (conp->vc_hi_font_mask == 0x100) {
! u16 a = scr_readw(p);
a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);

Quoted 8 lines

! scr_writew(a, p++);
} else {
! u16 a = scr_readw(p);
a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
! scr_writew(a, p++);
}
if (p == (u16 *)softback_end)
p = (u16 *)softback_buf;

The second part is OK for me.

There's a similar bug in console.c: always use scr_{read,write}w() when accessing the text/attribute buffer. See the patch (still untested by me) in the mail below.

--snip--------------------------------------------------------------------------

Quoted 1 line

From [email protected] Mon Jul 9 18:38:17 2001

Date: Sat, 2 Jun 2001 21:23:32 +0200 (CEST)
From: Geert Uytterhoeven <[email protected]>
To: Daniel Berlin <[email protected]>
Cc: Linux Frame Buffer Device Development
<[email protected]>,
Alan Cox <[email protected]>, Olaf Hering <[email protected]>
Subject: Re: FBCon invert_region is endian unsafe,
same with generic invert_region

Hi Daniel,

Quoted 10 lines

I'm not quite sure who the maintainer is, fbcon.c lists 5 people, and no one is listed in the MAINTAINERS file (i searched on fbcon).

This one has been bothering me for a long time.
It causes text selection to fail on fbcon devices for big endian platforms (Because, obviously, it gets big endian data on big endian machines, sinceit neglects to use scr_readw/scr_writew. Dumb. You end up inverting, pasting each byte reversed without fixing this, so where you would normally have pasted/see a background inverted 'u' (0x75), you get a 'W' (0x57)).

    [...]
Quoted 5 lines

However, it's important to note that console.c has the same damn bug in it's generic inversion routine.

Changing the code to the right way makes text selection work perfectly again, which it hasn't since 2.2.x, at least for me.

So this patch (untested) fixes it?

Olaf: is this the missing piece for you as well?

drivers/char/console.c renamed from drivers/char/console.c.orig +13 -5
@@ -390,20 +390,28 @@
 	else {
 		u16 *q = p;
 		int cnt = count;
+		u16 a;
 
 		if (!can_do_color) {
-			while (cnt--) *q++ ^= 0x0800;
+			while (cnt--) {
+			    a = scr_readw(q);
+			    a ^= 0x0800;
+			    scr_writew(a, q);
+			    q++;
+			}
 		} else if (hi_font_mask == 0x100) {
 			while (cnt--) {
-				u16 a = *q;
+				a = scr_readw(q);
 				a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
-				*q++ = a;
+				scr_writew(a, q);
+				q++;
 			}
 		} else {
 			while (cnt--) {
-				u16 a = *q;
+				a = scr_readw(q);
 				a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
-				*q++ = a;
+				scr_writew(a, q);
+				q++
 			}
 		}
 	}
drivers/video/fbcon.c renamed from drivers/video/fbcon.c.orig +6 -8
@@ -1934,17 +1934,15 @@
 static void fbcon_invert_region(struct vc_data *conp, u16 *p, int cnt)
 {
     while (cnt--) {
+	u16 a = scr_readw(p);
 	if (!conp->vc_can_do_color)
-	    *p++ ^= 0x0800;
-	else if (conp->vc_hi_font_mask == 0x100) {
-	    u16 a = *p;
+	    a ^= 0x0800;
+	else if (conp->vc_hi_font_mask == 0x100)
 	    a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
-	    *p++ = a;
-	} else {
-	    u16 a = *p;
+	else
 	    a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
-	    *p++ = a;
-	}
+	scr_writew(a, p);
+	p++;
 	if (p == (u16 *)softback_end)
 	    p = (u16 *)softback_buf;
 	if (p == (u16 *)softback_in)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

--snip--------------------------------------------------------------------------

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#4 lore raw
Quoted 2 lines · Geert Uytterhoeven

Note that I've been having a fight with Olaf Hering about this as well :-)

And the battle goes on :)

It really fixes my VGA problems so far, but I guess the bug is somewhere else.
We use a patch to display the kernel version above the framebuffer logo. It works on intel and on sparc, but it gives the usual garbage for the version chars on ppc.

It uses the fbcon_putcs() function. I will see how it works without that vga patch.

Gruss Olaf

--

 $ man clone

BUGS
Main feature not yet implemented...

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#5 lore raw
Quoted 8 lines · Olaf Hering
Quoted 2 lines · Geert Uytterhoeven

Note that I've been having a fight with Olaf Hering about this as well :-)

And the battle goes on :)

Quoted 8 lines

It really fixes my VGA problems so far, but I guess the bug is somewhere else.
We use a patch to display the kernel version above the framebuffer logo. It works on intel and on sparc, but it gives the usual garbage for the version chars on ppc.

It uses the fbcon_putcs() function. I will see how it works without that vga patch.

sigh,

I removed the vga patch and the version string appears still as garbage. We have the clgen driver in the kernel and it prints its messages also as garbage, this was always the case, also in 2.2. That does not happen with the vga patch.

The bootlogo-version patch can be found here:
/mirror/SuSE/ftp.suse.com/pub/suse/ppc/kernel/BETA/patches/50_bootlogo-ver-2.4.5.gz

Gruss Olaf

--

 $ man clone

BUGS
Main feature not yet implemented...

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#6 lore raw
Quoted 17 lines · Olaf Hering
Quoted 5 lines · Olaf Hering
Quoted 1 line · Geert Uytterhoeven

Note that I've been having a fight with Olaf Hering about this as well :-)

And the battle goes on :)

Quoted 8 lines

It really fixes my VGA problems so far, but I guess the bug is somewhere else.
We use a patch to display the kernel version above the framebuffer logo. It works on intel and on sparc, but it gives the usual garbage for the version chars on ppc.

It uses the fbcon_putcs() function. I will see how it works without that vga patch.

sigh,

Quoted 7 lines

I removed the vga patch and the version string appears still as garbage. We have the clgen driver in the kernel and it prints its messages also as garbage, this was always the case, also in 2.2. That does not happen with the vga patch.

The bootlogo-version patch can be found here:
/mirror/SuSE/ftp.suse.com/pub/suse/ppc/kernel/BETA/patches/50_bootlogo-ver-2.4.5.gz

+       /* G.S.: Display a line above the Boot Logo to state what
+       * version of the kernel we are booting.
+       */
+       char welcometext[] = "Linux " UTS_RELEASE;
+       unsigned short welcomestring[ sizeof(welcometext) ];
+       int i;
+       for(i = 0; i < sizeof(welcometext); i++)
+           welcomestring[i] = 0x0700 | welcometext[i];
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

+ fbcon_putcs( conp, welcomestring, sizeof(welcometext), 0, 0 );

That's not correct, you _must_ use scr_{read,write}w() to access screen buffers. fbcon_putcs() expects a pointer to a shadow screen buffer.

Please try

    scr_writew(0x0700 | welcometext[i], &welcomestring[i]);

instead.

Your code works on ia32 because ia32 and VGA are both little endian. It works on SPARC because SPARC and fbdev on SPARC are both big endian. I guess it fails on a real VGA textconsole on SPARC too (iff SPARC would support VGA text mode).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#7 lore raw
Quoted 10 lines · Geert Uytterhoeven
(quoted diff) +3 -0
+       for(i = 0; i < sizeof(welcometext); i++)
+           welcomestring[i] = 0x0700 | welcometext[i];
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+       fbcon_putcs( conp, welcomestring, sizeof(welcometext), 0, 0 );

That's not correct, you _must_ use scr_{read,write}w() to access screen buffers. fbcon_putcs() expects a pointer to a shadow screen buffer.

Please try

Quoted 8 lines
    scr_writew(0x0700 | welcometext[i], &welcomestring[i]);

instead.

Your code works on ia32 because ia32 and VGA are both little endian. It works on SPARC because SPARC and fbdev on SPARC are both big endian. I guess it fails on a real VGA textconsole on SPARC too (iff SPARC would support VGA text mode).

Well, that fixes "the last known problem".

But it still leaves the question whats really wrong with the vga console :)

Gruss Olaf

--

 $ man clone

BUGS
Main feature not yet implemented...

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/