i found a few small flaws with this.

On Sat, 28 Mar 2015 03:44:06 -0400 dan mclaughlin <[email protected]> 
wrote:
> >Synopsis:    vesa driver garbles loaded vga fonts.
> >Category:    kernel/X11
...
> 
>     i added a 'data' field to wsdisplay_font, and saved the font data
>     there. when WSDISPLAY_SMODE is invoked to return to emulation, or when

i actually added the 'data' field to *struct vgafont*. which, i should note
is not used anywhere outside of vga.c, so there should be no risk of outside
complications.

and my diffs were slightly off. i actually changed this but pulled in the
slightly older ones.

-void vga_reload_fonts(void *);
+void vga_reload_fonts(struct vga_config *);

so here are the corrected ones (for vga.c & vgavar.h, no change to the
earlier wsdisplay.c patch)

--- sys/dev/ic/vgavar.h.orig    Sat Aug 28 08:48:14 2010
+++ sys/dev/ic/vgavar.h Sat Mar 28 01:27:59 2015
@@ -64,7 +64,8 @@ struct vga_config {
        const struct wsscreen_descr *currenttype;
        int currentfontset1, currentfontset2;
 
-       struct vgafont *vc_fonts[8];
+#define VGA_MAXFONT 8
+       struct vgafont *vc_fonts[VGA_MAXFONT];
        uint8_t vc_palette[256 * 3];
 
        struct vgascreen *wantedscreen;
@@ -185,6 +186,7 @@ struct wsscreen_descr;
 void   vga_loadchars(struct vga_handle *, int, int, int, int, char *);
 void   vga_restore_palette(struct vga_config *);
 void   vga_save_palette(struct vga_config *);
+void   vga_reload_fonts(struct vga_config *);
 void   vga_setfontset(struct vga_handle *, int, int);
 void   vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
 #if NVGA_PCI > 0

--------------------

--- sys/dev/ic/vga.c.orig       Sun Jul 13 20:42:37 2014
+++ sys/dev/ic/vga.c    Sat Mar 28 02:17:59 2015
@@ -86,6 +86,7 @@ static struct vgafont {
        int firstchar, numchars;
 #endif
        int slot;
+       void *data;
 } vga_builtinfont = {
        "builtin",
        16,
@@ -93,6 +94,7 @@ static struct vgafont {
 #ifdef notyet
        0, 256,
 #endif
+       0,
        0
 };
 
@@ -354,7 +356,7 @@ vga_selectfont(struct vga_config *vc, struct vgascreen
 
        f1 = f2 = 0;
 
-       for (i = 0; i < 8; i++) {
+       for (i = 0; i < VGA_MAXFONT; i++) {
                struct vgafont *f = vc->vc_fonts[i];
                if (!f || f->height != type->fontheight)
                        continue;
@@ -500,7 +502,7 @@ vga_init(struct vga_config *vc, bus_space_tag_t iot, b
        vc->currenttype = vh->vh_mono ? &vga_stdscreen_mono : &vga_stdscreen;
 
        vc->vc_fonts[0] = &vga_builtinfont;
-       for (i = 1; i < 8; i++)
+       for (i = 1; i < VGA_MAXFONT; i++)
                vc->vc_fonts[i] = NULL;
 
        vc->currentfontset1 = vc->currentfontset2 = 0;
@@ -614,8 +616,10 @@ vga_ioctl(void *v, u_long cmd, caddr_t data, int flag,
 
        case WSDISPLAYIO_SMODE:
                mode = *(u_int *)data;
-               if (mode == WSDISPLAYIO_MODE_EMUL)
+               if (mode == WSDISPLAYIO_MODE_EMUL) {
                        vga_restore_palette(vc);
+                       vga_reload_fonts(vc);
+               }
                break;
 
        case WSDISPLAYIO_GVIDEO:
@@ -805,6 +809,7 @@ vga_doswitch(struct vga_config *vc)
 
        vga_setfont(vc, scr);
        vga_restore_palette(vc);
+       vga_reload_fonts(vc);
 
        scr->pcs.visibleoffset = scr->pcs.dispoffset = scr->mindispoffset;
        if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
@@ -857,13 +862,13 @@ vga_load_font(void *v, void *cookie, struct wsdisplay_
                return (EINVAL);
 
        if (data->index < 0) {
-               for (slot = 0; slot < 8; slot++)
+               for (slot = 0; slot < VGA_MAXFONT; slot++)
                        if (!vc->vc_fonts[slot])
                                break;
        } else
                slot = data->index;
 
-       if (slot >= 8)
+       if (slot >= VGA_MAXFONT)
                return (ENOSPC);
 
        if (vc->vc_fonts[slot] != NULL)
@@ -883,10 +888,9 @@ vga_load_font(void *v, void *cookie, struct wsdisplay_
               f->height, f->encoding, slot);
 #endif
        vga_loadchars(&vc->hdl, slot, 0, 256, f->height, data->data);
-       f->slot = slot;
-       vc->vc_fonts[slot] = f;
-       data->cookie = f;
-       data->index = slot;
+       data->index  = f->slot = slot;
+       data->cookie = vc->vc_fonts[slot] = f;
+       f->data = data->data;
 
        return (0);
 }
@@ -897,7 +901,7 @@ vga_list_font(void *v, struct wsdisplay_font *data)
        struct vga_config *vc = v;
        struct vgafont *f;
 
-       if (data->index < 0 || data->index >= nitems(vc->vc_fonts))
+       if (data->index < 0 || data->index >= VGA_MAXFONT)
                return EINVAL;
 
        if ((f = vc->vc_fonts[data->index]) == NULL)
@@ -1214,6 +1218,19 @@ vga_restore_palette(struct vga_config *vc)
        vga_raw_read(vh, 0x0a);                 /* reset flip/flop */
 
        vga_enable(vh);
+}
+
+void
+vga_reload_fonts(struct vga_config *v)
+{
+       struct vga_config *vc = v;
+       int slot;
+       struct vgafont *f;
+
+       for (slot = 1; slot < VGA_MAXFONT; slot++)
+               if ((f = vc->vc_fonts[slot]))
+                       vga_loadchars(&vc->hdl, slot, 0, 256,
+                               f->height, f->data);
 }
 
 struct cfdriver vga_cd = {

Reply via email to