Heap allocations now works.
authorDavid Given <dg@cowlark.com>
Sat, 25 May 2013 22:28:47 +0000 (23:28 +0100)
committerDavid Given <dg@cowlark.com>
Sat, 25 May 2013 22:28:47 +0000 (23:28 +0100)
--HG--
branch : dtrg-videocore

plat/rpi/build.mk
plat/rpi/libsys/brk.c

index dffe59d..a522046 100644 (file)
@@ -18,23 +18,23 @@ platform-headers := \
 
 platform-libsys := \
        _hol0.s \
+       errno.s \
        phys_to_user.s \
        user_to_phys.s \
        uart.s \
+       creat.c \
+       close.c \
+       open.c \
+       read.c \
        write.c \
+       isatty.c \
+       brk.c \
 
 ifeq (x,y)
-       errno.s \
        _sys_rawread.s \
        _sys_rawwrite.s \
-       open.c \
-       creat.c \
-       close.c \
-       read.c \
-       brk.c \
        getpid.c \
        kill.c \
-       isatty.c \
        lseek.c \
        time.c \
        signal.c
index cff32b9..2c44347 100644 (file)
@@ -8,25 +8,25 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
+#include <pi.h>
 
 #define        OUT_OF_MEMORY (void*)(-1)       /* sbrk returns this on failure */
-#define STACK_BUFFER 128 /* number of bytes to leave for stack */
+#define STACK_BUFFER 1024 /* number of bytes to leave for stack */
 
 extern char _end[1];
 static char* current = _end;
 
+/* Top of heap: we assume that the block of memory the binary is loaded in
+ * is 256kB long. Because user pointers are always relative to the beginning
+ * of the block, this makes the end address easy to calculate. */
+static char* max = (char*) (256*1024);
+
 int brk(void* newend)
 {
-       /* This variable is used to figure out the current stack pointer,
-        * by taking its address. */
-       char dummy;
-       char* p = newend;
-       
-       if ((p > (&dummy - STACK_BUFFER)) ||
-           (p < _end)) 
+       if ((newend >= (void*)max) || (newend < (void*)_end))
                return -1;
-               
-       current = p;
+
+       current = newend;
        return 0;
 }