From ecb26b87dea3ca7cca7bbeff6d58ba3976aa1d61 Mon Sep 17 00:00:00 2001 From: mariusmonton Date: Mon, 15 Oct 2018 17:36:07 +0200 Subject: [PATCH] last test, using glibc library --- tests/C/func3/Makefile | 52 ++++++++++++++++++++++++++++++++++++++++++ tests/C/func3/func3.c | 36 +++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/C/func3/Makefile create mode 100644 tests/C/func3/func3.c diff --git a/tests/C/func3/Makefile b/tests/C/func3/Makefile new file mode 100644 index 0000000..0143e1f --- /dev/null +++ b/tests/C/func3/Makefile @@ -0,0 +1,52 @@ +TARGET = func3 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 +CFLAGS = -Wall -I. -O0 -Xlinker --gc-sections -lgcc -lc -static + + +LINKER = riscv32-unknown-linux-gnu-gcc +# linking flags here +LFLAGS = -I. --entry main +LIBS = $(EXTRA_LIBS) + + +# change these to proper directories where each file should be +SRCDIR = ./ +OBJDIR = . +BINDIR = ./ +INCDIR = -I. +LIBDIR = -L. + + +SOURCES := $(wildcard $(SRCDIR)/*.c) +INCLUDES := $(wildcard $(INCDIR)/*.h) +OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) +rm = rm -f + + +$(BINDIR)/$(TARGET): $(OBJECTS) +# $(LINKER) $(OBJECTS) $(LFLAGS) $(LIBS) $(LIBDIR) -o $@ + riscv32-unknown-linux-gnu-objdump -d $< > dump + objcopy -Oihex $< $(TARGET).hex +# @echo "Linking complete!" + +$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c + @echo "Compiling "$<" ..." +# $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@ + $(CC) $(CFLAGS) $(INCDIR) $< -o $@ + @echo "Done!" + +.PHONY: clean +clean: + @$(rm) $(OBJECTS) *.hex dump + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/func3/func3.c b/tests/C/func3/func3.c new file mode 100644 index 0000000..b3e7b8d --- /dev/null +++ b/tests/C/func3/func3.c @@ -0,0 +1,36 @@ +#include + +#define TRACE (*(unsigned char *)0x40000000) + +void print(char *msg) { + int i = 0; + while(msg[i] != '\0') { + TRACE = msg[i]; + i++; + } +} + +int func1(int a, int* b) { + return a - (*b); +} + + +void main(void) { + int x1, x2, x3; + int aux[5] = {0}; + int aux2[5]; + + x1 = 6; + x2 = 7; + + x3 = func1(x1, &x2); + + if (x3 == (6-7)) { + print("OK\n"); + } else { + print("ERROR\n"); + } + + + memcpy(aux, aux2, 5); +}