Run option rom visible PMM code in 32bit mode instead of 16bit mode.
[seabios.git] / src / pmm.c
index 682be39c96238c91a0743285f61fb9e47400786f..2e9d1ff1c56b503827441540ba51da57963941a5 100644 (file)
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -44,13 +44,13 @@ struct zone_s {
     struct allocinfo_s *info;
 };
 
-struct zone_s ZoneLow VAR32FLATVISIBLE;
-struct zone_s ZoneHigh VAR32FLATVISIBLE;
-struct zone_s ZoneFSeg VAR32FLATVISIBLE;
-struct zone_s ZoneTmpLow VAR32FLATVISIBLE;
-struct zone_s ZoneTmpHigh VAR32FLATVISIBLE;
+struct zone_s ZoneLow;
+struct zone_s ZoneHigh;
+struct zone_s ZoneFSeg;
+struct zone_s ZoneTmpLow;
+struct zone_s ZoneTmpHigh;
 
-struct zone_s *Zones[] VAR32FLATVISIBLE = {
+struct zone_s *Zones[] = {
     &ZoneTmpLow, &ZoneLow, &ZoneFSeg, &ZoneTmpHigh, &ZoneHigh
 };
 
@@ -193,17 +193,6 @@ malloc_setup(void)
     ASSERT32FLAT();
     dprintf(3, "malloc setup\n");
 
-    ZoneLow.info = ZoneHigh.info = ZoneFSeg.info = NULL;
-    ZoneTmpLow.info = ZoneTmpHigh.info = NULL;
-
-    // Clear memory in 0xf0000 area.
-    extern u8 code32flat_start[];
-    if ((u32)code32flat_start > BUILD_BIOS_ADDR)
-        // Clear unused parts of f-segment
-        memset((void*)BUILD_BIOS_ADDR, 0
-               , (u32)code32flat_start - BUILD_BIOS_ADDR);
-    memset(BiosTableSpace, 0, CONFIG_MAX_BIOSTABLE);
-
     // Populate temp high ram
     u32 highram = 0;
     int i;
@@ -236,6 +225,22 @@ malloc_setup(void)
     }
 }
 
+// Update pointers after code relocation.
+void
+malloc_fixupreloc(void)
+{
+    ASSERT32FLAT();
+    if (!CONFIG_RELOCATE_INIT)
+        return;
+    dprintf(3, "malloc fixup reloc\n");
+
+    int i;
+    for (i=0; i<ARRAY_SIZE(Zones); i++) {
+        struct zone_s *zone = Zones[i];
+        zone->info->pprev = &zone->info;
+    }
+}
+
 void
 malloc_finalize(void)
 {
@@ -252,9 +257,6 @@ malloc_finalize(void)
         add_e820((u32)info->dataend, giveback, E820_RAM);
         dprintf(1, "Returned %d bytes of ZoneHigh\n", giveback);
     }
-
-    // Clear low-memory allocations.
-    memset((void*)BUILD_STACK_ADDR, 0, BUILD_EBDA_MINIMUM - BUILD_STACK_ADDR);
 }
 
 
@@ -556,7 +558,7 @@ handle_pmmXX(u16 *args)
     return PMM_FUNCTION_NOT_SUPPORTED;
 }
 
-u32 VISIBLE16
+u32 VISIBLE32INIT
 handle_pmm(u16 *args)
 {
     if (! CONFIG_PMM)
@@ -565,12 +567,25 @@ handle_pmm(u16 *args)
     u16 arg1 = args[0];
     dprintf(DEBUG_HDL_pmm, "pmm call arg1=%x\n", arg1);
 
+    int oldpreempt;
+    if (CONFIG_THREAD_OPTIONROMS) {
+        // Not a preemption event - don't wait in wait_preempt()
+        oldpreempt = CanPreempt;
+        CanPreempt = 0;
+    }
+
+    u32 ret;
     switch (arg1) {
-    case 0x00: return handle_pmm00(args);
-    case 0x01: return handle_pmm01(args);
-    case 0x02: return handle_pmm02(args);
-    default:   return handle_pmmXX(args);
+    case 0x00: ret = handle_pmm00(args); break;
+    case 0x01: ret = handle_pmm01(args); break;
+    case 0x02: ret = handle_pmm02(args); break;
+    default:   ret = handle_pmmXX(args); break;
     }
+
+    if (CONFIG_THREAD_OPTIONROMS)
+        CanPreempt = oldpreempt;
+
+    return ret;
 }
 
 // romlayout.S