Change license from GPLv3 to LGPLv3.
[seabios.git] / src / memmap.c
index 3449cb483e26ddb813283a93a7484b70e15bbaca..372ec5284eec18c42995ceffb66ef5bd63956402 100644 (file)
@@ -2,16 +2,12 @@
 //
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 //
-// This file may be distributed under the terms of the GNU GPLv3 license.
+// This file may be distributed under the terms of the GNU LGPLv3 license.
 
 #include "memmap.h" // struct e820entry
 #include "util.h" // dprintf.h
 #include "biosvar.h" // SET_EBDA
 
-// Temporary storage used during map building.
-static struct e820entry e820_list[64];
-static int e820_count;
-
 // Remove an entry from the e820_list.
 static void
 remove_e820(int i)
@@ -25,7 +21,7 @@ remove_e820(int i)
 static void
 insert_e820(int i, u64 start, u64 size, u32 type)
 {
-    if (e820_count >= ARRAY_SIZE(e820_list)) {
+    if (e820_count >= CONFIG_MAX_E820) {
         dprintf(1, "Overflowed e820 list!\n");
         return;
     }
@@ -126,35 +122,41 @@ add_e820(u64 start, u64 size, u32 type)
     //dump_map();
 }
 
+// Symbols defined in romlayout.S
+extern char freespace2_start, freespace2_end;
+
 u32 bios_table_cur_addr, bios_table_end_addr;
 
 // Prep for memmap stuff - init bios table locations.
 void
 memmap_setup()
 {
-    bios_table_cur_addr = OFFSET_freespace2_start;
-    bios_table_end_addr = OFFSET_freespace2_end;
+    bios_table_cur_addr = (u32)&freespace2_start;
+    bios_table_end_addr = (u32)&freespace2_end;
     dprintf(1, "bios_table_addr: 0x%08x end=0x%08x\n",
             bios_table_cur_addr, bios_table_end_addr);
-}
-
-// Copy the temporary e820 map info to its permanent location.
-void
-memmap_finalize()
-{
-    dump_map();
 
-    u32 msize = e820_count * sizeof(e820_list[0]);
+    bios_table_cur_addr = ALIGN(bios_table_cur_addr, 4);
+    u32 msize = CONFIG_MAX_E820 * sizeof(e820_list[0]);
     if (bios_table_cur_addr + msize > bios_table_end_addr) {
         dprintf(1, "No room for e820 map!\n");
         return;
     }
-    memcpy((void*)bios_table_cur_addr, e820_list, msize);
-    SET_EBDA(e820_loc, bios_table_cur_addr);
-    SET_EBDA(e820_count, e820_count);
+    e820_count = 0;
+    e820_list = (void*)bios_table_cur_addr;
     bios_table_cur_addr += msize;
+}
+
+// Report on final memory locations.
+void
+memmap_finalize()
+{
+    dump_map();
 
-    dprintf(1, "bios_table_cur_addr: 0x%08x\n", bios_table_cur_addr);
+    dprintf(1, "final bios_table_addr: 0x%08x (used %d%%)\n"
+            , bios_table_cur_addr
+            , (100 * (bios_table_cur_addr - (u32)&freespace2_start)
+               / ((u32)&freespace2_end - (u32)&freespace2_start)));
     if (bios_table_cur_addr > bios_table_end_addr)
         BX_PANIC("bios_table_end_addr overflow!\n");
 }