vgabios: Unify code to generate the vbe mode list.
authorKevin O'Connor <kevin@koconnor.net>
Tue, 10 Jan 2012 01:55:31 +0000 (20:55 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 14 Jan 2012 22:19:39 +0000 (17:19 -0500)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
vgasrc/bochsvga.c
vgasrc/bochsvga.h
vgasrc/clext.c
vgasrc/clext.h
vgasrc/stdvga.c
vgasrc/stdvga.h
vgasrc/vbe.c
vgasrc/vgahw.h

index d1919ecd58554bb0c1656c7289a035accfc4d2cc..5ab1bc222b79ebbffc0e7799e3fa0a3844a701af 100644 (file)
@@ -199,26 +199,20 @@ static int mode_valid(struct vgamode_s *vmode_g)
     return 1;
 }
 
-int
-bochsvga_list_modes(u16 seg, u16 ptr)
+void
+bochsvga_list_modes(u16 seg, u16 *dest, u16 *last)
 {
-    int count = 0;
-    u16 *dest = (u16 *)(u32)ptr;
-
     struct bochsvga_mode *m = bochsvga_modes;
-    for (; m < &bochsvga_modes[ARRAY_SIZE(bochsvga_modes)]; m++) {
+    for (; m < &bochsvga_modes[ARRAY_SIZE(bochsvga_modes)] && dest<last; m++) {
         if (!mode_valid(&m->info))
             continue;
 
         dprintf(1, "VBE found mode %x valid.\n", GET_GLOBAL(m->mode));
-        SET_FARVAR(seg, dest[count], GET_GLOBAL(m->mode));
-
-        count++;
+        SET_FARVAR(seg, *dest, GET_GLOBAL(m->mode));
+        dest++;
     }
 
-    SET_FARVAR(seg, dest[count], 0xffff); /* End of list */
-
-    return count;
+    stdvga_list_modes(seg, dest, last);
 }
 
 int
index 963b0d3e6e10ce03c3d0b6e9c1591cb0c03c7814..c08f103f54139b751ccaf9ad74c8258d0a2d0b8d 100644 (file)
@@ -55,7 +55,7 @@ static inline void dispi_write(u16 reg, u16 val)
 int bochsvga_init(void);
 int bochsvga_enabled(void);
 u16 bochsvga_total_mem(void);
-int bochsvga_list_modes(u16 seg, u16 ptr);
+void bochsvga_list_modes(u16 seg, u16 *dest, u16 *last);
 struct vbe_modeinfo;
 int bochsvga_mode_info(u16 mode, struct vbe_modeinfo *info);
 void bochsvga_hires_enable(int enable);
index 90d7924ae2442ce90ffadfc15522f27a2c2d01e6..90f37c8489171651cab740f6f4d80abe0130090b 100644 (file)
@@ -566,6 +566,17 @@ static struct {
     { 0x11a, 0x75 },
 };
 
+void
+clext_list_modes(u16 seg, u16 *dest, u16 *last)
+{
+    int i;
+    for (i=0; i<ARRAY_SIZE(cirrus_vesa_modelist) && dest<last; i++) {
+        SET_FARVAR(seg, *dest, GET_GLOBAL(cirrus_vesa_modelist[i].vesamode));
+        dest++;
+    }
+    stdvga_list_modes(seg, dest, last);
+}
+
 static u16
 cirrus_vesamode_to_mode(u16 vesamode)
 {
@@ -706,12 +717,9 @@ cirrus_vesa_00h(struct bregs *regs)
     SET_FARVAR(seg, info->total_memory, cirrus_get_memsize());
 
     u16 *destmode = (void*)info->reserved;
+    u16 *last = (void*)&info->reserved[sizeof(info->reserved)];
     SET_FARVAR(seg, info->video_mode, SEGOFF(seg, (u32)destmode));
-    int i;
-    for (i=0; i<ARRAY_SIZE(cirrus_vesa_modelist); i++)
-        SET_FARVAR(seg, destmode[i]
-                   , GET_GLOBAL(cirrus_vesa_modelist[i].vesamode));
-    SET_FARVAR(seg, destmode[i], 0xffff);
+    clext_list_modes(seg, destmode, last);
 
     regs->ax = 0x004f;
 }
index e344639e03f47e2e4c088fa21a958749906288d4..f337b65e20de98d0486d57e8da05a3cbeff08ea9 100644 (file)
@@ -5,6 +5,7 @@
 
 struct vgamode_s *clext_find_mode(int mode);
 int clext_set_mode(int mode, int flags);
+void clext_list_modes(u16 seg, u16 *dest, u16 *last);
 int clext_init(void);
 
 #endif // clext.h
index 70d018abb294e48968558b45bcf42a88fb6e2151..6998cd09268090a6b33e67c76264bbd935612573 100644 (file)
@@ -641,6 +641,12 @@ stdvga_set_mode(int mode, int flags)
  * Misc
  ****************************************************************/
 
+void
+stdvga_list_modes(u16 seg, u16 *dest, u16 *last)
+{
+    SET_FARVAR(seg, *dest, 0xffff);
+}
+
 void
 stdvga_enable_video_addressing(u8 disable)
 {
index 4cef89f2e02ea84d5bd0882e3ad9497f3b185b41..033a711604b7c0adf29e7a0075e479ea5d99db55 100644 (file)
@@ -119,6 +119,7 @@ void stdvga_save_state(u16 seg, struct saveVideoHardware *info);
 void stdvga_restore_state(u16 seg, struct saveVideoHardware *info);
 int stdvga_set_mode(int mode, int flags);
 void stdvga_enable_video_addressing(u8 disable);
+void stdvga_list_modes(u16 seg, u16 *dest, u16 *last);
 int stdvga_init(void);
 
 #endif // stdvga.h
index 8256cae4ce91f2564044a8f6ebcff6a80e2ae574..daf8c514fac43bf09389f107aa6533d9de0dd122 100644 (file)
@@ -39,7 +39,8 @@ vbe_104f00(struct bregs *regs)
     SET_FARVAR(seg, info->capabilities, 0x1); /* 8BIT DAC */
 
     /* We generate our mode list in the reserved field of the info block */
-    SET_FARVAR(seg, info->video_mode, SEGOFF(seg, regs->di + 34));
+    u16 *destmode = (void*)info->reserved;
+    SET_FARVAR(seg, info->video_mode, SEGOFF(seg, (u32)destmode));
 
     /* Total memory (in 64 blocks) */
     SET_FARVAR(seg, info->total_memory, bochsvga_total_mem());
@@ -52,7 +53,8 @@ vbe_104f00(struct bregs *regs)
             SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING));
 
     /* Fill list of modes */
-    bochsvga_list_modes(seg, regs->di + 32);
+    u16 *last = (void*)&info->reserved[sizeof(info->reserved)];
+    vgahw_list_modes(seg, destmode, last - 1);
 
     regs->al = regs->ah; /* 0x4F, Function supported */
     regs->ah = 0x0; /* 0x0, Function call successful */
index 9d8a06793f42e79512737193f1a259e622ec4a52..1101e510737a1f9510be364f9fc8334d47fd7009 100644 (file)
@@ -25,6 +25,15 @@ static inline int vgahw_set_mode(int mode, int flags) {
     return stdvga_set_mode(mode, flags);
 }
 
+static inline void vgahw_list_modes(u16 seg, u16 *dest, u16 *last) {
+    if (CONFIG_VGA_CIRRUS)
+        clext_list_modes(seg, dest, last);
+    else if (CONFIG_VGA_BOCHS)
+        bochsvga_list_modes(seg, dest, last);
+    else
+        stdvga_list_modes(seg, dest, last);
+}
+
 static inline int vgahw_init(void) {
     if (CONFIG_VGA_CIRRUS)
         return clext_init();