Heap allocations now works.

--HG--
branch : dtrg-videocore
This commit is contained in:
David Given 2013-05-25 23:28:47 +01:00
parent 3b07fee160
commit 6a672d5e96
2 changed files with 18 additions and 18 deletions

View file

@ -18,23 +18,23 @@ platform-headers := \
platform-libsys := \
_hol0.s \
errno.s \
phys_to_user.s \
user_to_phys.s \
uart.s \
write.c \
ifeq (x,y)
errno.s \
_sys_rawread.s \
_sys_rawwrite.s \
open.c \
creat.c \
close.c \
open.c \
read.c \
write.c \
isatty.c \
brk.c \
ifeq (x,y)
_sys_rawread.s \
_sys_rawwrite.s \
getpid.c \
kill.c \
isatty.c \
lseek.c \
time.c \
signal.c

View 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;
}