aboutsummaryrefslogtreecommitdiff
path: root/slof
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2016-09-09 21:52:00 +0200
committerAlexey Kardashevskiy <aik@ozlabs.ru>2016-09-14 17:50:40 +1000
commit9cb2fb0cd9adcd48162175029f3efa96e6b17c54 (patch)
treed8d75dd0bc119d19e6c40883972b7d17061c5818 /slof
parent488569289854dba3f6cf63dcbdc2629c44258c0f (diff)
downloadSLOF-9cb2fb0cd9adcd48162175029f3efa96e6b17c54.zip
SLOF-9cb2fb0cd9adcd48162175029f3efa96e6b17c54.tar.gz
SLOF-9cb2fb0cd9adcd48162175029f3efa96e6b17c54.tar.bz2
paflof: Copy sbrk code from net-snk
sbrk() is needed for the malloc() implementation of our libc, so to be able to use malloc() from the Paflof code, we need to provide sbrk() here, too. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'slof')
-rw-r--r--slof/Makefile.inc13
-rw-r--r--slof/sbrk.c39
2 files changed, 48 insertions, 4 deletions
diff --git a/slof/Makefile.inc b/slof/Makefile.inc
index d7a6b38..5b766a9 100644
--- a/slof/Makefile.inc
+++ b/slof/Makefile.inc
@@ -42,7 +42,9 @@ DICT = $(SLOFCMNDIR)/prim.in $(SLOFCMNDIR)/engine.in \
$(BOARD_SLOF_IN) $(SLOFCMNDIR)/$(TARG).in
# Source code files with automatic dependencies:
-SLOF_BUILD_SRCS = paflof.c helpers.c allocator.c
+SLOF_BUILD_SRCS = paflof.c helpers.c allocator.c sbrk.c
+
+SLOF_BUILD_OBJS = $(SLOF_BUILD_SRCS:%.c=%.o)
# Flags for pre-processing Forth code with CPP:
FPPFLAGS = -nostdinc -traditional-cpp -undef -P -C $(FLAG)
@@ -81,10 +83,10 @@ board.code:
echo > $@
endif
-paflof: $(SLOFCMNDIR)/OF.lds $(SLOFCMNDIR)/ofw.o paflof.o $(SLOFCMNDIR)/entry.o \
- helpers.o allocator.o romfs.o version.o OF.o nvramlog.o $(LLFWBRDDIR)/board_io.o \
+paflof: $(SLOFCMNDIR)/OF.lds $(SLOFCMNDIR)/ofw.o $(SLOFCMNDIR)/entry.o romfs.o \
+ $(SLOF_BUILD_OBJS) version.o OF.o nvramlog.o $(LLFWBRDDIR)/board_io.o \
$(LLFWBRDDIR)/io_generic_lib.o $(SLOF_LIBS)
- $(CC) -T$(SLOFCMNDIR)/OF.lds $(SLOFCMNDIR)/ofw.o version.o paflof.o helpers.o allocator.o \
+ $(CC) -T$(SLOFCMNDIR)/OF.lds $(SLOFCMNDIR)/ofw.o version.o $(SLOF_BUILD_OBJS) \
$(SLOFCMNDIR)/entry.o romfs.o OF.o nvramlog.o $(LLFWBRDDIR)/board_io.o \
$(LLFWBRDDIR)/io_generic_lib.o $(LDFLAGS) $(SLOF_LIBS) -o $@
#save a copy of paflof before stripping
@@ -100,6 +102,9 @@ helpers.o:
allocator.o:
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(SLOFCMNDIR)/allocator.c
+sbrk.o:
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(SLOFCMNDIR)/sbrk.c
+
$(SLOFCMNDIR)/xvect.bin: $(SLOFCMNDIR)/lowmem.o
$(CC) $(LDFLAGS) -Wl,--oformat,binary -Ttext=0x100 -o xvect.bin.tmp $<
dd if=xvect.bin.tmp of=$(SLOFCMNDIR)/xvect.bin bs=256 skip=1 2>/dev/null
diff --git a/slof/sbrk.c b/slof/sbrk.c
new file mode 100644
index 0000000..2ec1b5f
--- /dev/null
+++ b/slof/sbrk.c
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * Copyright (c) 2004, 2008 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#include <unistd.h>
+
+#define HEAP_SIZE 0x200000
+
+
+static char heap[HEAP_SIZE];
+static char *actptr;
+
+void *sbrk(int increment)
+{
+ char *oldptr;
+
+ /* Called for the first time? Then init the actual pointer */
+ if (!actptr) {
+ actptr = heap;
+ }
+
+ if (actptr + increment > heap + HEAP_SIZE) {
+ /* Out of memory */
+ return (void *)-1;
+ }
+
+ oldptr = actptr;
+ actptr += increment;
+
+ return oldptr;
+}