Commit 5286292b authored by Tristan Gingold's avatar Tristan Gingold

Remove use of nano_c, add lib.c for a simple malloc/free.

parent b605ce0a
CROSS_COMPILE_TARGET ?= /home/mattia/riscv32-nanolib/gnu-mcu-eclipse/riscv-none-gcc/8.1.0-2-20181019-0952/bin/riscv-none-embed-
CROSS_COMPILE_TARGET ?= riscv32-elf-
openPOWERLINK=../..
#CROSS_COMPILE_TARGET ?= /home/mattia/riscv-toolchain/riscv/bin/riscv32-elf-
#CFLAGS += -mabi=ilp32 -march=rv32im -O2 -lgcc -lc
CFLAGS += -mabi=ilp32 -march=rv32i -Os -ffunction-sections -fdata-sections --specs=nano.specs --specs=nosys.specs -lgcc -lc -Wl,--gc-sections
CFLAGS += -mabi=ilp32 -march=rv32i -Os -ffunction-sections -fdata-sections -lgcc -lc -Wl,--gc-sections
CFLAGS += -I./
CFLAGS += -I$(openPOWERLINK)/stack/include/
CFLAGS += -I$(openPOWERLINK)/stack/proj/generic/liboplkcn
......@@ -14,6 +14,8 @@ CFLAGS += -I$(openPOWERLINK)/stack/src/arch
CFLAGS += -D__URV__ -DCONFIG_PCP=TRUE -DNDEBUG
LDFLAGS=-T powerlink.ld -nostdlib -lgcc -lc
CC = $(CROSS_COMPILE_TARGET)gcc
LD = $(CROSS_COMPILE_TARGET)ld
OBJDUMP = $(CROSS_COMPILE_TARGET)objdump
......@@ -25,12 +27,7 @@ PL_URV_ENV ?= ./
BUILDDIR ?= build
OBJDIR := $(PL_URV_ENV)
OBJS := crt0.o
OBJS += irq.o
#OBJS += eth_config.o
OBJS += app.o
OBJS += event.o
OBJS += main.o
OBJS := crt0.o main.o app.o event.o irq.o lib.o
OBJDIR += stack/src/arch/urv
OBJS += stack/src/arch/urv/lock-localnoos.o
......@@ -194,7 +191,7 @@ $(BUILDDIR)/%.o: %.c
$(CC) -c -o $@ $(CFLAGS) $<
main: $(OBJS_BUILD) powerlink.ld
$(CC) -o $@ -nostartfiles $(CFLAGS) $(OBJS_BUILD) -T powerlink.ld
$(CC) -o $@ -nostartfiles $(CFLAGS) $(OBJS_BUILD) $(LDFLAGS)
main-text.bin: main
riscv32-elf-objcopy -j .text -O binary $< $@
......
#include <stdlib.h>
extern char _end;
static char *next = &_end;
#define BUSY 1
void *
malloc(size_t len)
{
void *res;
/* Align. */
len = (len + 3) & ~3U;
/* Try to find a free block. */
res = &_end;
while (res != next) {
/* Read block length. */
unsigned l = *(unsigned *)res;
/* Get block start address. */
res += sizeof (unsigned);
/* If block is free and if length match, return it. */
if (l == len)
return res;
/* Next block. */
res += l & ~BUSY;
}
/* No free block. */
*(unsigned *)next = len | BUSY;
res = next + sizeof (unsigned);
next = res + len;
return res;
}
void free(void *ptr)
{
if (ptr == NULL)
return;
/* Just clear the busy bit. */
ptr -= sizeof (unsigned);
*(unsigned *)ptr = *(unsigned *)ptr & ~BUSY;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment