From d405857f25888b348fee9904d1915634c178ee18 Mon Sep 17 00:00:00 2001 From: mariusmonton Date: Sat, 6 Oct 2018 22:19:29 +0200 Subject: [PATCH] Moved C and ASM code to tests folder --- tests/C/forloop/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/forloop/forloop.c | 8 ++++++ tests/C/func1/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/func1/func1.c | 25 +++++++++++++++++ tests/C/func2/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/func2/func2.c | 29 ++++++++++++++++++++ tests/C/stdlibs/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/stdlibs/stdlibs.c | 17 ++++++++++++ tests/C/trace/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/trace/trace.c | 7 +++++ tests/C/trace2/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/trace2/trace2.c | 9 +++++++ tests/C/trace3/Makefile | 52 ++++++++++++++++++++++++++++++++++++ tests/C/trace3/trace3.c | 10 +++++++ tests/asm/BasicLoop.asm | 10 +++++++ tests/asm/BasicRegisters.asm | 11 ++++++++ tests/asm/EternalLoop.asm | 12 +++++++++ tests/asm/Memoryaccess.asm | 8 ++++++ tests/asm/trace.asm | 34 +++++++++++++++++++++++ 19 files changed, 544 insertions(+) create mode 100644 tests/C/forloop/Makefile create mode 100644 tests/C/forloop/forloop.c create mode 100644 tests/C/func1/Makefile create mode 100644 tests/C/func1/func1.c create mode 100644 tests/C/func2/Makefile create mode 100644 tests/C/func2/func2.c create mode 100644 tests/C/stdlibs/Makefile create mode 100644 tests/C/stdlibs/stdlibs.c create mode 100644 tests/C/trace/Makefile create mode 100644 tests/C/trace/trace.c create mode 100644 tests/C/trace2/Makefile create mode 100644 tests/C/trace2/trace2.c create mode 100644 tests/C/trace3/Makefile create mode 100644 tests/C/trace3/trace3.c create mode 100644 tests/asm/BasicLoop.asm create mode 100644 tests/asm/BasicRegisters.asm create mode 100644 tests/asm/EternalLoop.asm create mode 100644 tests/asm/Memoryaccess.asm create mode 100644 tests/asm/trace.asm diff --git a/tests/C/forloop/Makefile b/tests/C/forloop/Makefile new file mode 100644 index 0000000..83ab5e5 --- /dev/null +++ b/tests/C/forloop/Makefile @@ -0,0 +1,52 @@ +TARGET = forloop + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 -nodefaultlibs -march=rv32i -mabi=ilp32 + + +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/forloop/forloop.c b/tests/C/forloop/forloop.c new file mode 100644 index 0000000..65b50f1 --- /dev/null +++ b/tests/C/forloop/forloop.c @@ -0,0 +1,8 @@ +void main(void) { + volatile int i; + volatile int a; + + for(i=0;i<10;i++) { + a=i+5; + } +} diff --git a/tests/C/func1/Makefile b/tests/C/func1/Makefile new file mode 100644 index 0000000..3cb3b47 --- /dev/null +++ b/tests/C/func1/Makefile @@ -0,0 +1,52 @@ +TARGET = func1 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 -nodefaultlibs -march=rv32i -mabi=ilp32 + + +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/func1/func1.c b/tests/C/func1/func1.c new file mode 100644 index 0000000..e317581 --- /dev/null +++ b/tests/C/func1/func1.c @@ -0,0 +1,25 @@ +#define TRACE (*(unsigned char *)0x40000000) + +int func1(int a, int* b) { + return a + (*b); +} + + +void main(void) { + int x1, x2, x3; + + x1 = 6; + x2 = 7; + + x3 = func1(x1, &x2); + + if (x3 == 13) { + TRACE = 'O'; + TRACE = 'K'; + TRACE = '\n'; + } else { + TRACE = 'E'; + TRACE = 'R'; + TRACE = '\n'; + } +} diff --git a/tests/C/func2/Makefile b/tests/C/func2/Makefile new file mode 100644 index 0000000..92a39b7 --- /dev/null +++ b/tests/C/func2/Makefile @@ -0,0 +1,52 @@ +TARGET = func2 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 -nodefaultlibs -march=rv32i -mabi=ilp32 + + +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/func2/func2.c b/tests/C/func2/func2.c new file mode 100644 index 0000000..531112d --- /dev/null +++ b/tests/C/func2/func2.c @@ -0,0 +1,29 @@ +#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; + + x1 = 6; + x2 = 7; + + x3 = func1(x1, &x2); + + if (x3 == 13) { + print("OK\n"); + } else { + print("ERROR\n"); + } +} diff --git a/tests/C/stdlibs/Makefile b/tests/C/stdlibs/Makefile new file mode 100644 index 0000000..4eca9d0 --- /dev/null +++ b/tests/C/stdlibs/Makefile @@ -0,0 +1,52 @@ +TARGET = stdlibs + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -march=rv32 -mabi=ilp32 +#CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main -lc +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main + + +LINKER = riscv32-unknown-linux-gnu-gcc +# linking flags here +LFLAGS = -I. +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/stdlibs/stdlibs.c b/tests/C/stdlibs/stdlibs.c new file mode 100644 index 0000000..a1047b0 --- /dev/null +++ b/tests/C/stdlibs/stdlibs.c @@ -0,0 +1,17 @@ +#include + +#define TRACE (*(unsigned char *)0x40000000) + +void print(char *msg) { + int i = 0; + while(msg[i] != '\0') { + TRACE = msg[i]; + i++; + } +} + +void main(void) { + char msg[50]; + print("hello"); + sprintf(msg, "%i", 5); +} diff --git a/tests/C/trace/Makefile b/tests/C/trace/Makefile new file mode 100644 index 0000000..7026d26 --- /dev/null +++ b/tests/C/trace/Makefile @@ -0,0 +1,52 @@ +TARGET = trace + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 -nodefaultlibs -march=rv32i -mabi=ilp32 + + +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/trace/trace.c b/tests/C/trace/trace.c new file mode 100644 index 0000000..7597464 --- /dev/null +++ b/tests/C/trace/trace.c @@ -0,0 +1,7 @@ + +#define TRACE (*(unsigned char *)0x40000000) + +void main(void) { + TRACE = 'H'; + TRACE = 'e'; +} diff --git a/tests/C/trace2/Makefile b/tests/C/trace2/Makefile new file mode 100644 index 0000000..9b2501f --- /dev/null +++ b/tests/C/trace2/Makefile @@ -0,0 +1,52 @@ +TARGET = trace2 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 -nodefaultlibs -march=rv32i -mabi=ilp32 + + +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/trace2/trace2.c b/tests/C/trace2/trace2.c new file mode 100644 index 0000000..18274f7 --- /dev/null +++ b/tests/C/trace2/trace2.c @@ -0,0 +1,9 @@ + +#define TRACE (*(unsigned char *)0x40000000) + +void main(void) { + int i; + for(i=0;i<10;i++) { + TRACE = 'a' + i; + } +} diff --git a/tests/C/trace3/Makefile b/tests/C/trace3/Makefile new file mode 100644 index 0000000..554024f --- /dev/null +++ b/tests/C/trace3/Makefile @@ -0,0 +1,52 @@ +TARGET = trace3 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-linux-gnu-gcc +# compiling flags here +#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 +CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 --entry main +#CFLAGS = -Wall -I. -O0 -nodefaultlibs -march=rv32i -mabi=ilp32 + + +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) + @echo "Cleanup complete!" + +.PHONY: remove +remove: clean + @$(rm) $(BINDIR)/$(TARGET) + @echo "Executable removed!" diff --git a/tests/C/trace3/trace3.c b/tests/C/trace3/trace3.c new file mode 100644 index 0000000..3a7483d --- /dev/null +++ b/tests/C/trace3/trace3.c @@ -0,0 +1,10 @@ +#define TRACE (*(unsigned char *)0x40000000) + +void main(void) { + char msg[] = "abcdefg\n"; + int i; + + for (i=0; i<5; i++) { + TRACE = msg[i]; + } +} diff --git a/tests/asm/BasicLoop.asm b/tests/asm/BasicLoop.asm new file mode 100644 index 0000000..6454d8a --- /dev/null +++ b/tests/asm/BasicLoop.asm @@ -0,0 +1,10 @@ +.section .text +.globl _start +_start: +# Basic loop + ADDI t1, zero, 10 # t1 to 10 + ADDI t2, zero, 1 #t2 to 1 +loop: + SUB t1, t1, t2 + BNE t1, zero, loop +# END diff --git a/tests/asm/BasicRegisters.asm b/tests/asm/BasicRegisters.asm new file mode 100644 index 0000000..06dd943 --- /dev/null +++ b/tests/asm/BasicRegisters.asm @@ -0,0 +1,11 @@ +.section .text +.globl _start +_start: + +li t1, 150 +li t2, 300 +li t3, -250 +ADD t4, t1, t2 +ADD t5, t2, t3 +SUB t6, t2, t1 +#SUB t7, t1, t2 diff --git a/tests/asm/EternalLoop.asm b/tests/asm/EternalLoop.asm new file mode 100644 index 0000000..01eba6b --- /dev/null +++ b/tests/asm/EternalLoop.asm @@ -0,0 +1,12 @@ +.section .text +.globl _start +_start: + +li t1, 150 +li t2, 300 +li t3, -250 +loop: +ADD t4, t1, t2 +ADD t5, t2, t3 +SUB t6, t2, t1 +J loop diff --git a/tests/asm/Memoryaccess.asm b/tests/asm/Memoryaccess.asm new file mode 100644 index 0000000..c1ccc5e --- /dev/null +++ b/tests/asm/Memoryaccess.asm @@ -0,0 +1,8 @@ +li t1, 0xCAFE +li t2, 300 +li t3, 0xBEEF +sb t1, -6(t2) +sb t3, -13(t2) +li t1, 23 +lbu t1, -6(t2) +lbu t3, -13(t2) diff --git a/tests/asm/trace.asm b/tests/asm/trace.asm new file mode 100644 index 0000000..5c00639 --- /dev/null +++ b/tests/asm/trace.asm @@ -0,0 +1,34 @@ +.equ TRACE_BASE, 0x40000000 + +#msg: +# .string "Hello World\n" + +.section .text +.globl _start + +_start: + li a2, TRACE_BASE + li t0, 'H' + sb t0, 0(a2) + li t0, 'e' + sb t0, 0(a2) + li t0, 'l' + sb t0, 0(a2) + li t0, 'l' + sb t0, 0(a2) + li t0, 'o' + sb t0, 0(a2) + li t0, ' ' + sb t0, 0(a2) + li t0, 'w' + sb t0, 0(a2) + li t0, 'o' + sb t0, 0(a2) + li t0, 'r' + sb t0, 0(a2) + li t0, 'l' + sb t0, 0(a2) + li t0, 'd' + sb t0, 0(a2) + li t0, '\n' + sb t0, 0(a2)