[SeaBIOS] [PATCH 2/3] vgabios: Cache a pointer to the current mode struct in the BDA

Kevin O'Connor kevin at koconnor.net
Sat Oct 18 20:27:34 CEST 2014


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 at koconnor.net>
---
 vgasrc/vgabios.c | 8 ++++++--
 vgasrc/vgabios.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c
index d36b62a..fcc5b34 100644
--- a/vgasrc/vgabios.c
+++ b/vgasrc/vgabios.c
@@ -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);
diff --git a/vgasrc/vgabios.h b/vgasrc/vgabios.h
index 70682c9..d17b48f 100644
--- a/vgasrc/vgabios.h
+++ b/vgasrc/vgabios.h
@@ -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) \
-- 
1.9.3




More information about the SeaBIOS mailing list