summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRon Minnich <rminnich@gmail.com>2012-04-11 10:30:15 -0700
committerPatrick Georgi <patrick@georgi-clan.de>2012-04-12 08:38:58 +0200
commiteb59636cc5875bac98a949f206e5f8c0462be238 (patch)
treebf96c66301113572e856eeaafd9809fd8d387344 /src
parent392562263858011ef898e377477124f5f66b1302 (diff)
downloadcoreboot-eb59636cc5875bac98a949f206e5f8c0462be238.tar.xz
Add support for aligned allocation
Add a memalign function and have malloc use it. Also, change the default alignment for malloc to u64-aligned. Change-Id: I0788637008f5cb5ac801d8bbdc430ca992c98e81 Signed-off-by: Ron Minnich <rminnich@gmail.com> Reviewed-on: http://review.coreboot.org/887 Tested-by: build bot (Jenkins) Reviewed-by: Mathias Krause <minipli@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/stdlib.h1
-rw-r--r--src/lib/malloc.c23
2 files changed, 17 insertions, 7 deletions
diff --git a/src/include/stdlib.h b/src/include/stdlib.h
index 5465c14f92..bd0ee30774 100644
--- a/src/include/stdlib.h
+++ b/src/include/stdlib.h
@@ -12,6 +12,7 @@
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#if !defined(__PRE_RAM__)
+void *memalign(size_t boundary, size_t size);
void *malloc(size_t size);
void free(void *ptr);
#endif
diff --git a/src/lib/malloc.c b/src/lib/malloc.c
index c10750d5e9..2e700f78e5 100644
--- a/src/lib/malloc.c
+++ b/src/lib/malloc.c
@@ -11,29 +11,38 @@ extern unsigned char _heap, _eheap;
static void *free_mem_ptr = &_heap; /* Start of heap */
static void *free_mem_end_ptr = &_eheap; /* End of heap */
-void *malloc(size_t size)
+/* We don't restrict the boundary. This is firmware,
+ * you are supposed to know what you are doing.
+ */
+void *memalign(size_t boundary, size_t size)
{
void *p;
- MALLOCDBG("%s Enter, size %ld, free_mem_ptr %p\n", __func__, size, free_mem_ptr);
+ MALLOCDBG("%s Enter, boundary %ld, size %ld, free_mem_ptr %p\n",
+ __func__, boundary, size, free_mem_ptr);
/* Overzealous linker check */
if (free_mem_ptr <= 0)
- die("Error! malloc: Free_mem_ptr <= 0");
+ die("Error! memalign: Free_mem_ptr <= 0");
- free_mem_ptr = (void *)ALIGN((unsigned long)free_mem_ptr, 4);
+ free_mem_ptr = (void *)ALIGN((unsigned long)free_mem_ptr, boundary);
- p = (void *) free_mem_ptr;
+ p = free_mem_ptr;
free_mem_ptr += size;
if (free_mem_ptr >= free_mem_end_ptr)
- die("Error! malloc: Out of memory (free_mem_ptr >= free_mem_end_ptr)");
+ die("Error! memalign: Out of memory (free_mem_ptr >= free_mem_end_ptr)");
- MALLOCDBG("malloc %p\n", p);
+ MALLOCDBG("memalign %p\n", p);
return p;
}
+void *malloc(size_t size)
+{
+ return memalign(sizeof(u64), size);
+}
+
void free(void *where)
{
/* Don't care */