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 := \ platform-libsys := \
_hol0.s \ _hol0.s \
errno.s \
phys_to_user.s \ phys_to_user.s \
user_to_phys.s \ user_to_phys.s \
uart.s \ uart.s \
write.c \
ifeq (x,y)
errno.s \
_sys_rawread.s \
_sys_rawwrite.s \
open.c \
creat.c \ creat.c \
close.c \ close.c \
open.c \
read.c \ read.c \
write.c \
isatty.c \
brk.c \ brk.c \
ifeq (x,y)
_sys_rawread.s \
_sys_rawwrite.s \
getpid.c \ getpid.c \
kill.c \ kill.c \
isatty.c \
lseek.c \ lseek.c \
time.c \ time.c \
signal.c signal.c

View file

@ -8,25 +8,25 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <pi.h>
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */ #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]; extern char _end[1];
static char* current = _end; 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) int brk(void* newend)
{ {
/* This variable is used to figure out the current stack pointer, if ((newend >= (void*)max) || (newend < (void*)_end))
* by taking its address. */
char dummy;
char* p = newend;
if ((p > (&dummy - STACK_BUFFER)) ||
(p < _end))
return -1; return -1;
current = p; current = newend;
return 0; return 0;
} }