diff --git a/tests/C/func1/Makefile b/tests/C/func1/Makefile index 3cb3b47..930f3f7 100644 --- a/tests/C/func1/Makefile +++ b/tests/C/func1/Makefile @@ -2,11 +2,9 @@ TARGET = func1 TARGET_ARCH=riscv32 -CC = riscv32-unknown-linux-gnu-gcc +CC = riscv32-unknown-elf-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 +CFLAGS = -Wall -L. -O0 -g -static LINKER = riscv32-unknown-linux-gnu-gcc diff --git a/tests/C/func1/func1.c b/tests/C/func1/func1.c index e317581..b783fe6 100644 --- a/tests/C/func1/func1.c +++ b/tests/C/func1/func1.c @@ -5,7 +5,7 @@ int func1(int a, int* b) { } -void main(void) { +int main(void) { int x1, x2, x3; x1 = 6; @@ -22,4 +22,6 @@ void main(void) { TRACE = 'R'; TRACE = '\n'; } + + asm volatile ("ecall"); } diff --git a/tests/C/func2/Makefile b/tests/C/func2/Makefile index 92a39b7..049a267 100644 --- a/tests/C/func2/Makefile +++ b/tests/C/func2/Makefile @@ -2,11 +2,9 @@ TARGET = func2 TARGET_ARCH=riscv32 -CC = riscv32-unknown-linux-gnu-gcc +CC = riscv32-unknown-elf-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 +CFLAGS = -Wall -I. -O0 -march=rv32i -mabi=ilp32 LINKER = riscv32-unknown-linux-gnu-gcc diff --git a/tests/C/func2/func2.c b/tests/C/func2/func2.c index 531112d..bd0e038 100644 --- a/tests/C/func2/func2.c +++ b/tests/C/func2/func2.c @@ -13,7 +13,7 @@ int func1(int a, int* b) { } -void main(void) { +int main(void) { int x1, x2, x3; x1 = 6; @@ -26,4 +26,7 @@ void main(void) { } else { print("ERROR\n"); } + + asm volatile ("ecall"); + } diff --git a/tests/C/func3/Makefile b/tests/C/func3/Makefile index d1ee44b..2313792 100644 --- a/tests/C/func3/Makefile +++ b/tests/C/func3/Makefile @@ -2,19 +2,14 @@ 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 -static -#CFLAGS = -Wall -I. -O0 -Xlinker --gc-sections -lgcc -lc -static --specs=nano.specs +CC = riscv32-unknown-elf-gcc +# compiling flags here +CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs LINKER = riscv32-unknown-linux-gnu-gcc -# linking flags here -LFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ LIBS = $(EXTRA_LIBS) - # change these to proper directories where each file should be SRCDIR = ./ OBJDIR = . @@ -22,18 +17,16 @@ 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 $@ +# $(LINKER) $(OBJECTS) $(LDFLAGS) $(LIBS) $(LIBDIR) -o $@ riscv32-unknown-linux-gnu-objdump -d $< > dump objcopy -Oihex $< $(TARGET).hex -# @echo "Linking complete!" + @echo "Linking complete!" $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c @echo "Compiling "$<" ..." diff --git a/tests/C/func3/func3.c b/tests/C/func3/func3.c index b3e7b8d..f5cacea 100644 --- a/tests/C/func3/func3.c +++ b/tests/C/func3/func3.c @@ -15,22 +15,29 @@ int func1(int a, int* b) { } -void main(void) { +int main(void) { int x1, x2, x3; int aux[5] = {0}; int aux2[5]; + TRACE = 'a'; + TRACE = 'b'; + x1 = 6; x2 = 7; x3 = func1(x1, &x2); if (x3 == (6-7)) { - print("OK\n"); + print("\nOK\n"); } else { - print("ERROR\n"); + print("\nERROR\n"); } memcpy(aux, aux2, 5); + + asm volatile ("ecall"); + + return 0; } diff --git a/tests/C/func4/Makefile b/tests/C/func4/Makefile new file mode 100644 index 0000000..eaaa711 --- /dev/null +++ b/tests/C/func4/Makefile @@ -0,0 +1,50 @@ +TARGET = func4 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-elf-gcc +# compiling flags here +CFLAGS = -Wall -I. -O0 -Xlinker --gc-sections -lgcc -lc -static --specs=nano.specs + + +LINKER = riscv32-unknown-linux-gnu-gcc +# linking flags here +LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld +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) $(LDFLAGS) $(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/func4/func4.c b/tests/C/func4/func4.c new file mode 100644 index 0000000..245a4d9 --- /dev/null +++ b/tests/C/func4/func4.c @@ -0,0 +1,52 @@ +#include +#include + +#define TRACE (*(unsigned char *)0x40000000) + +void print(char *msg) { + int i = 0; + while(msg[i] != '\0') { + TRACE = msg[i]; + i++; + } +} + +int _write(int file, const char *ptr, int len) { + int x; + + for (x = 0; x < len; x++) { + TRACE = *ptr++; + } + + return (len); +} + +int func1(int a, int* b) { + return a - (*b); +} + + +int main(void) { + int x1, x2, x3; + int aux[5] = {0, 1, 2, 3, 4}; + int aux2[5]; + + print("Hello\n"); + x1 = 6; + x2 = 7; + x3 = func1(x1, &x2); + + memcpy(aux, aux2, sizeof(int)*5); + + for(int i = 0; i < 5; i++) { + if (aux[i] != aux2[i]) { + print("ERROR\n"); + asm volatile ("ecall"); + } + } + + print("OK!\n"); + asm volatile ("ecall"); + + return 0; +} diff --git a/tests/C/func5/Makefile b/tests/C/func5/Makefile new file mode 100644 index 0000000..922d4e5 --- /dev/null +++ b/tests/C/func5/Makefile @@ -0,0 +1,50 @@ +TARGET = func5 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-elf-gcc + +# compiling flags here +CFLAGS = -Wall -I. -O0 -static --specs=nosys.specs + +LINKER = riscv32-unknown-linux-gnu-gcc +# linking flags here +LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld +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) $(LDFLAGS) $(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/func5/func5.c b/tests/C/func5/func5.c new file mode 100644 index 0000000..4b6e59c --- /dev/null +++ b/tests/C/func5/func5.c @@ -0,0 +1,37 @@ +#include +#include + +#define TRACE (*(unsigned char *)0x40000000) + +void print(char *msg) { + int i = 0; + while(msg[i] != '\0') { + TRACE = msg[i]; + i++; + } +} + +int _write(int file, const char *ptr, int len) { + int x; + + for (x = 0; x < len; x++) { + TRACE = *ptr++; + } + + return (len); +} + +int func1(int a, int* b) { + return a - (*b); +} + + +int main(void) { + + printf("Using printf!\n"); + + print("Using custom print!\n"); + asm volatile ("ecall"); + + return 0; +} diff --git a/tests/C/func6/Makefile b/tests/C/func6/Makefile new file mode 100644 index 0000000..d7b7eb3 --- /dev/null +++ b/tests/C/func6/Makefile @@ -0,0 +1,51 @@ +TARGET = func6 + +TARGET_ARCH=riscv32 + +CC = riscv32-unknown-elf-gcc + +# compiling flags here +CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs + + +LINKER = riscv32-unknown-linux-gnu-gcc +# linking flags here +LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld +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) $(LDFLAGS) $(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/func6/func6.c b/tests/C/func6/func6.c new file mode 100644 index 0000000..a20b511 --- /dev/null +++ b/tests/C/func6/func6.c @@ -0,0 +1,49 @@ +#include +#include + +#define TRACE (*(unsigned char *)0x40000000) + +int _write(int file, const char *ptr, int len) { + int x; + + for (x = 0; x < len; x++) { + TRACE = *ptr++; + } + + return (len); +} + +int func1(int a, int* b) { + return a - (*b); +} + + +int main(void) { + int x1, x2, x3; + int aux[5] = {0, 1, 2, 3, 4}; + int aux2[5]; + + printf("Hello\n"); + x1 = 6; + x2 = 7; + x3 = func1(x1, &x2); + + memcpy(aux, aux2, sizeof(int)*5); + + for(int i = 0; i < 5; i++) { + if (aux[i] != aux2[i]) { + printf("ERROR %d\n", i); + asm volatile ("ecall"); + } + } + + printf("OK!\n"); + printf("x1 = %d\n", x1); + printf("x2 = %d\n", x2); + printf("x3 = %d\n", x3); + + + asm volatile ("ecall"); + + return 0; +} diff --git a/tests/C/stdlibs/Makefile b/tests/C/stdlibs/Makefile index 4eca9d0..5e76e8a 100644 --- a/tests/C/stdlibs/Makefile +++ b/tests/C/stdlibs/Makefile @@ -2,11 +2,9 @@ TARGET = stdlibs TARGET_ARCH=riscv32 -CC = riscv32-unknown-linux-gnu-gcc +CC = riscv32-unknown-elf-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 +CFLAGS = -Wall -I. -O0 -march=rv32i -mabi=ilp32 --specs=nosys.specs LINKER = riscv32-unknown-linux-gnu-gcc diff --git a/tests/C/stdlibs/stdlibs.c b/tests/C/stdlibs/stdlibs.c index a1047b0..3d0791f 100644 --- a/tests/C/stdlibs/stdlibs.c +++ b/tests/C/stdlibs/stdlibs.c @@ -10,8 +10,14 @@ void print(char *msg) { } } -void main(void) { +int main(void) { char msg[50]; - print("hello"); + print("hello\n"); sprintf(msg, "%i", 5); + print(msg); + + asm volatile ("ecall"); + + return 0; + }