]> xenbits.xensource.com Git - seabios.git/commitdiff
post: Always set HaveRunPost prior to setting any other global variable
authorKevin O'Connor <kevin@koconnor.net>
Tue, 12 Jan 2016 19:22:33 +0000 (14:22 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 12 Jan 2016 19:22:33 +0000 (14:22 -0500)
The HaveRunPost flag controls whether post or reboot handling is
entered on a reset signal.  The flag needs to be set before any other
global variable because an external reboot signal could occur at any
time.  (If any global variable is modified prior to setting
HaveRunPost then the code might enter post with global variables in a
dirty state.)

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/fw/csm.c
src/fw/shadow.c
src/fw/xen.c
src/post.c
src/util.h

index 7cadd12e5b99cda517fce05a4b9625249db0e129..b01f181f95c1480426604ac04625d48ff5b61419 100644 (file)
@@ -289,6 +289,7 @@ handle_csm(struct bregs *regs)
 
     dprintf(3, "handle_csm regs %p AX=%04x\n", regs, regs->ax);
 
+    code_mutable_preinit();
     pic_irqmask_write(PICMask);
 
     switch(regs->ax) {
index 4486884bd5d78428b1fe1e40b04504df07c52d34..bdb5c5ba9287b6f60b65e1dd05da473d94ca384b 100644 (file)
@@ -123,12 +123,14 @@ make_bios_writable(void)
         if (vendor == PCI_VENDOR_ID_INTEL
             && device == PCI_DEVICE_ID_INTEL_82441) {
             make_bios_writable_intel(bdf, I440FX_PAM0);
+            code_mutable_preinit();
             ShadowBDF = bdf;
             return;
         }
         if (vendor == PCI_VENDOR_ID_INTEL
             && device == PCI_DEVICE_ID_INTEL_Q35_MCH) {
             make_bios_writable_intel(bdf, Q35_HOST_BRIDGE_PAM0);
+            code_mutable_preinit();
             ShadowBDF = bdf;
             return;
         }
index 3f19ef2dcfffcb9d22135c3fcf50ebe174e6bf0f..a215b9ea99e67a833b2577f514f398fc348291e1 100644 (file)
@@ -71,6 +71,7 @@ void xen_preinit(void)
                 signature, base);
         if (strcmp(signature, "XenVMMXenVMM") == 0) {
             /* Set debug_io_port first, so the following messages work. */
+            code_mutable_preinit();
             DebugOutputPort = 0xe9;
             debug_banner();
             dprintf(1, "\nFound Xen hypervisor signature at %x\n", base);
index 49c22b8751c0a53b8a7d569b4cf2d25b4d942627..e5fa4be0dfd946de00abed1ba54d5c00a8966f5f 100644 (file)
@@ -41,10 +41,6 @@ ivt_init(void)
 {
     dprintf(3, "init ivt\n");
 
-    // Setup reset-vector entry point (controls legacy reboots).
-    HaveRunPost = 1;
-    rtc_write(CMOS_RESET_CODE, 0);
-
     // Initialize all vectors to the default handler.
     int i;
     for (i=0; i<256; i++)
@@ -304,10 +300,26 @@ reloc_preinit(void *f, void *arg)
     func(arg);
 }
 
+// Runs after all code is present and prior to any modifications
+void
+code_mutable_preinit(void)
+{
+    if (HaveRunPost)
+        // Already run
+        return;
+    // Setup reset-vector entry point (controls legacy reboots).
+    rtc_write(CMOS_RESET_CODE, 0);
+    barrier();
+    HaveRunPost = 1;
+    barrier();
+}
+
 // Setup for code relocation and then relocate.
 void VISIBLE32INIT
 dopost(void)
 {
+    code_mutable_preinit();
+
     // Detect ram and setup internal malloc.
     qemu_preinit();
     coreboot_preinit();
index 76db57fbb22f3df5332956d15776e6ef00470472..43f219998a172cfd84c7c87f2b628830cf272680 100644 (file)
@@ -223,6 +223,7 @@ void device_hardware_setup(void);
 void prepareboot(void);
 void startBoot(void);
 void reloc_preinit(void *f, void *arg);
+void code_mutable_preinit(void);
 
 // serial.c
 void serial_setup(void);