aboutsummaryrefslogtreecommitdiffstats
path: root/src/pmm.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2009-08-30 19:19:31 -0400
committerKevin O'Connor <kevin@koconnor.net>2009-08-30 19:19:31 -0400
commit415d4298dfad6122c5a41214bd977b3598317718 (patch)
tree2e60f94207aee637c6c22dbc8912630a443e9497 /src/pmm.c
parent7b184d8470308095340622d8376878a20fff299e (diff)
downloadseabios-415d4298dfad6122c5a41214bd977b3598317718.tar.gz
Cleanups for malloc code.
Fix bug where zones over 2gig may fail to allocate. Add memalign_high() and use for acpi facs allocation. Misc code cleanups.
Diffstat (limited to 'src/pmm.c')
-rw-r--r--src/pmm.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/pmm.c b/src/pmm.c
index 3b4aa07c..1732c69b 100644
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -39,11 +39,12 @@ struct zone_s *Zones[] VAR32VISIBLE = {
};
// Obtain memory from a given zone.
-static void *
+void *
zone_malloc(struct zone_s *zone, u32 size, u32 align)
{
- u32 newpos = (GET_PMMVAR(zone->cur) - size) / align * align;
- if ((s32)(newpos - GET_PMMVAR(zone->bottom)) < 0)
+ u32 oldpos = GET_PMMVAR(zone->cur);
+ u32 newpos = ALIGN_DOWN(oldpos - size, align);
+ if (newpos < GET_PMMVAR(zone->bottom) || newpos > oldpos)
// No space
return NULL;
SET_PMMVAR(zone->cur, newpos);
@@ -88,20 +89,6 @@ dumpZones()
}
}
-// Allocate memory at the top of 32bit ram.
-void *
-malloc_high(u32 size)
-{
- return zone_malloc(&ZoneHigh, size, MALLOC_MIN_ALIGN);
-}
-
-// Allocate memory in the 0xf0000-0x100000 area of ram.
-void *
-malloc_fseg(u32 size)
-{
- return zone_malloc(&ZoneFSeg, size, MALLOC_MIN_ALIGN);
-}
-
void
malloc_setup()
{
@@ -148,7 +135,7 @@ malloc_finalize()
dumpZones();
// Give back unused high ram.
- u32 giveback = (ZoneHigh.cur - ZoneHigh.bottom) / 4096 * 4096;
+ u32 giveback = ALIGN_DOWN(ZoneHigh.cur - ZoneHigh.bottom, PAGE_SIZE);
add_e820(ZoneHigh.bottom, giveback, E820_RAM);
dprintf(1, "Returned %d bytes of ZoneHigh\n", giveback);