fixed compiling options

This commit is contained in:
mariusmonton 2019-01-09 23:03:08 +01:00
parent 9a7e7abeb0
commit 532d9f7c85
14 changed files with 325 additions and 31 deletions

View File

@ -2,11 +2,9 @@ TARGET = func1
TARGET_ARCH=riscv32 TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-elf-gcc
# compiling flags here # compiling flags here
#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 CFLAGS = -Wall -L. -O0 -g -static
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 LINKER = riscv32-unknown-linux-gnu-gcc

View File

@ -5,7 +5,7 @@ int func1(int a, int* b) {
} }
void main(void) { int main(void) {
int x1, x2, x3; int x1, x2, x3;
x1 = 6; x1 = 6;
@ -22,4 +22,6 @@ void main(void) {
TRACE = 'R'; TRACE = 'R';
TRACE = '\n'; TRACE = '\n';
} }
asm volatile ("ecall");
} }

View File

@ -2,11 +2,9 @@ TARGET = func2
TARGET_ARCH=riscv32 TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-elf-gcc
# compiling flags here # compiling flags here
#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 CFLAGS = -Wall -I. -O0 -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 LINKER = riscv32-unknown-linux-gnu-gcc

View File

@ -13,7 +13,7 @@ int func1(int a, int* b) {
} }
void main(void) { int main(void) {
int x1, x2, x3; int x1, x2, x3;
x1 = 6; x1 = 6;
@ -26,4 +26,7 @@ void main(void) {
} else { } else {
print("ERROR\n"); print("ERROR\n");
} }
asm volatile ("ecall");
} }

View File

@ -2,19 +2,14 @@ TARGET = func3
TARGET_ARCH=riscv32 TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-elf-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
# compiling flags here
CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs
LINKER = riscv32-unknown-linux-gnu-gcc LINKER = riscv32-unknown-linux-gnu-gcc
# linking flags here
LFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/
LIBS = $(EXTRA_LIBS) LIBS = $(EXTRA_LIBS)
# change these to proper directories where each file should be # change these to proper directories where each file should be
SRCDIR = ./ SRCDIR = ./
OBJDIR = . OBJDIR = .
@ -22,18 +17,16 @@ BINDIR = ./
INCDIR = -I. INCDIR = -I.
LIBDIR = -L. LIBDIR = -L.
SOURCES := $(wildcard $(SRCDIR)/*.c) SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(INCDIR)/*.h) INCLUDES := $(wildcard $(INCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
rm = rm -f rm = rm -f
$(BINDIR)/$(TARGET): $(OBJECTS) $(BINDIR)/$(TARGET): $(OBJECTS)
# $(LINKER) $(OBJECTS) $(LFLAGS) $(LIBS) $(LIBDIR) -o $@ # $(LINKER) $(OBJECTS) $(LDFLAGS) $(LIBS) $(LIBDIR) -o $@
riscv32-unknown-linux-gnu-objdump -d $< > dump riscv32-unknown-linux-gnu-objdump -d $< > dump
objcopy -Oihex $< $(TARGET).hex objcopy -Oihex $< $(TARGET).hex
# @echo "Linking complete!" @echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c $(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
@echo "Compiling "$<" ..." @echo "Compiling "$<" ..."

View File

@ -15,22 +15,29 @@ int func1(int a, int* b) {
} }
void main(void) { int main(void) {
int x1, x2, x3; int x1, x2, x3;
int aux[5] = {0}; int aux[5] = {0};
int aux2[5]; int aux2[5];
TRACE = 'a';
TRACE = 'b';
x1 = 6; x1 = 6;
x2 = 7; x2 = 7;
x3 = func1(x1, &x2); x3 = func1(x1, &x2);
if (x3 == (6-7)) { if (x3 == (6-7)) {
print("OK\n"); print("\nOK\n");
} else { } else {
print("ERROR\n"); print("\nERROR\n");
} }
memcpy(aux, aux2, 5); memcpy(aux, aux2, 5);
asm volatile ("ecall");
return 0;
} }

50
tests/C/func4/Makefile Normal file
View File

@ -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!"

52
tests/C/func4/func4.c Normal file
View File

@ -0,0 +1,52 @@
#include <string.h>
#include <stdio.h>
#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;
}

50
tests/C/func5/Makefile Normal file
View File

@ -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!"

37
tests/C/func5/func5.c Normal file
View File

@ -0,0 +1,37 @@
#include <string.h>
#include <stdio.h>
#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;
}

51
tests/C/func6/Makefile Normal file
View File

@ -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!"

49
tests/C/func6/func6.c Normal file
View File

@ -0,0 +1,49 @@
#include <string.h>
#include <stdio.h>
#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;
}

View File

@ -2,11 +2,9 @@ TARGET = stdlibs
TARGET_ARCH=riscv32 TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-elf-gcc
# compiling flags here # compiling flags here
#CFLAGS = -Wall -I. -O0 -march=rv32 -mabi=ilp32 CFLAGS = -Wall -I. -O0 -march=rv32i -mabi=ilp32 --specs=nosys.specs
#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 LINKER = riscv32-unknown-linux-gnu-gcc

View File

@ -10,8 +10,14 @@ void print(char *msg) {
} }
} }
void main(void) { int main(void) {
char msg[50]; char msg[50];
print("hello"); print("hello\n");
sprintf(msg, "%i", 5); sprintf(msg, "%i", 5);
print(msg);
asm volatile ("ecall");
return 0;
} }