Subject: Make vga(4) always install a sane font
To: None <tech-kern@NetBSD.org>
From: Julio M. Merino Vidal <jmmv84@gmail.com>
List: tech-kern
Date: 07/31/2007 17:53:30
--Apple-Mail-5--715902860
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Hello,
While enabling wscons support in NetBSD/shark's INSTALL kernel, I
noticed that sysinst used very ugly characters to draw the boxes
around menus. After further inspection this seems to be caused by a
broken font in its VGA ROM. Effectively: replacing the font with one
of those in /usr/share/wscons/fonts fixes the problem.
In order to fix this, I've changed the vga driver to always replace
the builtin font by a sane one (i.e. one that we know is able to draw
all the characters we need). The nice thing is that this has been
trivial (and that this does not grow current kernels), because wsfont
already provides a sane font in the kernel in all situations.
However, using the default font provided by wsfont (unless overridden
by a kernel option) is suboptimal because it does not match the font
typically used by VGA cards. Hence this is why I'm changing wsfont's
default from "bold" to "vt220l8x16". Does something rely on "bold"
that could be disturbed by this change? Or has some platform used
the "bold" font as the default for its console for a so long time
that could disturb our users?
Patch attached. Can you see any serious problem with it?
Objections? (If so, proposed alternatives?)
Thank you,
PS: I was also suggested to simply set TERM to 'vt100' or something
like that to avoid the ACS drawing characters... but that is a
workaround, not a fix: the user will be hit by ugly characters again
when the system is up and running.
--Apple-Mail-5--715902860
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name=patch.diff
Content-Disposition: attachment;
filename=patch.diff
? ic/.vga.c.swp
Index: ic/vga.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/vga.c,v
retrieving revision 1.95
diff -u -p -r1.95 vga.c
--- ic/vga.c 28 Jul 2007 20:28:56 -0000 1.95
+++ ic/vga.c 31 Jul 2007 15:42:37 -0000
@@ -62,7 +62,17 @@ __KERNEL_RCSID(0, "$NetBSD: vga.c,v 1.95
#include <arch/i386/bios/vesafbvar.h>
#endif
-int vga_no_builtinfont = 0;
+/* Prefer the 'vt220l' font, which matches the most common font in PC
+ * VGA ROMs. The driver will resort to any other font if this one is
+ * not found. */
+#define VGA_PREFERRED_FONT "vt220l"
+
+/* We default to 1 to always override the font built into the VGA's ROM.
+ * This is because some ROMs have bogus fonts in them (as is the case of
+ * the card provided by the DNARD) and we cannot detect this situation.
+ * Simply replace the font with a known one (VGA_PREFERRED_FONT as
+ * define above) to live on the safe side. */
+int vga_no_builtinfont = 1;
static struct wsdisplay_font _vga_builtinfont = {
"builtin", /* typeface name */
@@ -572,8 +582,11 @@ vga_init(struct vga_config *vc, bus_spac
struct wsdisplay_font *wf;
int cookie;
- cookie = wsfont_find(NULL, 8, 16, 0,
+ cookie = wsfont_find(VGA_PREFERRED_FONT, 8, 16, 0,
WSDISPLAY_FONTORDER_L2R, 0);
+ if (cookie == -1)
+ cookie = wsfont_find(NULL, 8, 16, 0,
+ WSDISPLAY_FONTORDER_L2R, 0);
if (cookie == -1 || wsfont_lock(cookie, &wf))
panic("vga_init: can't load console font");
vga_loadchars(&vc->hdl, 0, wf->firstchar, wf->numchars,
@@ -653,6 +666,11 @@ vga_common_attach(struct vga_softc *sc,
vga_builtinfont.wsfont->data = data;
}
+ aprint_normal("%s: using font \"%s\", slot %d\n",
+ sc->sc_dev.dv_xname,
+ vga_builtinfont.wsfont->name,
+ vga_builtinfont.slot);
+
vc->vc_type = type;
vc->vc_funcs = vf;
vc->vc_quirks = quirks;
Index: wsfont/wsfont.c
===================================================================
RCS file: /cvsroot/src/sys/dev/wsfont/wsfont.c,v
retrieving revision 1.44
diff -u -p -r1.44 wsfont.c
--- wsfont/wsfont.c 2 Feb 2007 02:10:24 -0000 1.44
+++ wsfont/wsfont.c 31 Jul 2007 15:42:38 -0000
@@ -55,6 +55,11 @@ __KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1
#undef HAVE_FONT
+#ifdef FONT_BOLD8x16
+#define HAVE_FONT 1
+#include <dev/wsfont/bold8x16.h>
+#endif
+
#ifdef FONT_QVSS8x15
#define HAVE_FONT 1
#include <dev/wsfont/qvss8x15.h>
@@ -120,11 +125,11 @@ __KERNEL_RCSID(0, "$NetBSD: wsfont.c,v 1
/* Make sure we always have at least one font. */
#ifndef HAVE_FONT
#define HAVE_FONT 1
-#define FONT_BOLD8x16 1
+#define FONT_VT220L8x16 1
#endif
-#ifdef FONT_BOLD8x16
-#include <dev/wsfont/bold8x16.h>
+#ifdef FONT_VT220L8x16
+#include <dev/wsfont/vt220l8x16.h>
#endif
#define WSFONT_IDENT_MASK 0xffffff00
--Apple-Mail-5--715902860
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
--
Julio M. Merino Vidal <jmmv84@gmail.com>
--Apple-Mail-5--715902860--