]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
vgabios: Cache a pointer to the current mode struct in the BDA
authorKevin O'Connor <kevin@koconnor.net>
Sat, 18 Oct 2014 01:37:23 +0000 (21:37 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Mon, 27 Oct 2014 15:00:32 +0000 (11:00 -0400)
Cache a pointer to the current mode 'vgamode_s' struct in the BDA to
avoid doing a linear scan of all available vga modes when the struct
is needed.

This uses an additional two bytes in the BDA (at offset 0xbc).  It's
possible this could conflict with some other software, but that seams
unlikely because that part of the BDA seems reserved for BIOS and
VGABIOS uses.  (And neither SeaBIOS nor Bochs BIOS currently make use
of that area.)

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
vgasrc/vgabios.c
vgasrc/vgabios.h

index d36b62a379b98ed099f378c718f15c749e01147b..fcc5b34b75c78f8e916772bf39a11d634221383a 100644 (file)
@@ -261,7 +261,10 @@ bda_save_restore(int cmd, u16 seg, void *data)
                    , sizeof(info->bda_0x49));
         memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84
                    , sizeof(info->bda_0x84));
-        SET_BDA_EXT(vbe_mode, GET_FARVAR(seg, info->vbe_mode));
+        u16 vbe_mode = GET_FARVAR(seg, info->vbe_mode);
+        SET_BDA_EXT(vbe_mode, vbe_mode);
+        struct vgamode_s *vmode_g = vgahw_find_mode(vbe_mode);
+        SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
         SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
         SET_IVT(0x43, GET_FARVAR(seg, info->font1));
     }
@@ -276,7 +279,7 @@ bda_save_restore(int cmd, u16 seg, void *data)
 struct vgamode_s *
 get_current_mode(void)
 {
-    return vgahw_find_mode(GET_BDA_EXT(vbe_mode) & ~MF_VBEFLAGS);
+    return (void*)(GET_BDA_EXT(vgamode_offset)+0);
 }
 
 // Setup BDA after a mode switch.
@@ -302,6 +305,7 @@ vga_set_mode(int mode, int flags)
     else
         SET_BDA(video_mode, 0xff);
     SET_BDA_EXT(vbe_mode, mode | (flags & MF_VBEFLAGS));
+    SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
     if (memmodel == MM_TEXT) {
         SET_BDA(video_cols, width);
         SET_BDA(video_rows, height-1);
index 70682c955227f98c0e3ffdf156c016d5437bde70..d17b48fe23337027a31d84e024cefcd24413a190 100644 (file)
@@ -81,6 +81,7 @@ struct gfx_op {
 struct vga_bda_s {
     u8 vbe_flag;
     u16 vbe_mode;
+    u16 vgamode_offset;
 } PACKED;
 
 #define GET_BDA_EXT(var) \