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>
This commit is contained in:
Thomas Huth 2016-09-09 21:52:00 +02:00 committed by Alexey Kardashevskiy
parent 4885692898
commit 9cb2fb0cd9
2 changed files with 48 additions and 4 deletions

View File

@ -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

39
slof/sbrk.c Normal file
View File

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