vgabios: Handle VGA option rom being re-run.
[seabios.git] / vgasrc / vgabios.c
index 25d97294dd0cfe43d0116b6bebdb8c99b98ce9d1..ec251fe20c0b01def6008862110e451018a26486 100644 (file)
@@ -138,11 +138,9 @@ set_cursor_pos(struct cursorpos cp)
         return;
 
     // Calculate the memory address
-    u16 nbcols = GET_BDA(video_cols);
-    u16 address = (GET_BDA(video_pagesize) * cp.page
-                   + (cp.x + cp.y * nbcols) * 2);
-
-    stdvga_set_cursor_pos(address / 2);
+    int address = (GET_BDA(video_pagesize) * cp.page
+                   + (cp.x + cp.y * GET_BDA(video_cols)) * 2);
+    stdvga_set_cursor_pos(address);
 }
 
 static struct cursorpos
@@ -1273,16 +1271,19 @@ init_bios_area(void)
 }
 
 int VgaBDF VAR16 = -1;
+int HaveRunInit VAR16;
 
 void VISIBLE16
 vga_post(struct bregs *regs)
 {
     debug_enter(regs, DEBUG_VGA_POST);
 
-    if (CONFIG_VGA_PCI) {
+    if (CONFIG_VGA_PCI && !GET_GLOBAL(HaveRunInit)) {
         u16 bdf = regs->ax;
-        if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
-            && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
+        if ((pci_config_readw(bdf, PCI_VENDOR_ID)
+             == GET_GLOBAL(rom_pci_data.vendor))
+            && (pci_config_readw(bdf, PCI_DEVICE_ID)
+                == GET_GLOBAL(rom_pci_data.device)))
             SET_VGA(VgaBDF, bdf);
     }
 
@@ -1292,6 +1293,9 @@ vga_post(struct bregs *regs)
         return;
     }
 
+    if (GET_GLOBAL(HaveRunInit))
+        return;
+
     init_bios_area();
 
     SET_VGA(video_save_pointer_table.videoparam
@@ -1303,6 +1307,8 @@ vga_post(struct bregs *regs)
 
     // XXX - clear screen and display info
 
+    SET_VGA(HaveRunInit, 1);
+
     // Fixup checksum
     extern u8 _rom_header_size, _rom_header_checksum;
     SET_VGA(_rom_header_checksum, 0);