Skip to content

Commit

Permalink
paflof: Copy sbrk code from net-snk
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Alexey Kardashevskiy <[email protected]>
  • Loading branch information
huth authored and aik committed Sep 14, 2016
1 parent 4885692 commit 9cb2fb0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
13 changes: 9 additions & 4 deletions slof/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions slof/sbrk.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 9cb2fb0

Please sign in to comment.