new C examples ,modified Makefile

This commit is contained in:
mariusmonton 2018-09-21 09:26:02 +02:00
parent 4ba8b1bbb7
commit e6b95298cd
10 changed files with 244 additions and 8 deletions

View File

@ -5,11 +5,13 @@ TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-linux-gnu-gcc
# compiling flags here # compiling flags here
#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 #CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32
CFLAGS = -Wall -I. -O0 -nostdlib -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
# linking flags here # linking flags here
LFLAGS = -I. LFLAGS = -I. --entry main
LIBS = $(EXTRA_LIBS) LIBS = $(EXTRA_LIBS)

52
C/func1/Makefile Normal file
View File

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

25
C/func1/func1.c Normal file
View File

@ -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';
}
}

52
C/func2/Makefile Normal file
View File

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

29
C/func2/func2.c Normal file
View File

@ -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");
}
}

52
C/stdlibs/Makefile Normal file
View File

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

17
C/stdlibs/stdlibs.c Normal file
View File

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

View File

@ -5,11 +5,13 @@ TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-linux-gnu-gcc
# compiling flags here # compiling flags here
#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 #CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32
CFLAGS = -Wall -I. -O0 -nostdlib -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
# linking flags here # linking flags here
LFLAGS = -I. LFLAGS = -I. --entry main
LIBS = $(EXTRA_LIBS) LIBS = $(EXTRA_LIBS)

View File

@ -4,11 +4,14 @@ TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-linux-gnu-gcc
# compiling flags here # compiling flags here
CFLAGS = -Wall -I. -O0 -nostdlib -march=rv32i -mabi=ilp32 #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 LINKER = riscv32-unknown-linux-gnu-gcc
# linking flags here # linking flags here
LFLAGS = -I. LFLAGS = -I. --entry main
LIBS = $(EXTRA_LIBS) LIBS = $(EXTRA_LIBS)

View File

@ -5,11 +5,13 @@ TARGET_ARCH=riscv32
CC = riscv32-unknown-linux-gnu-gcc CC = riscv32-unknown-linux-gnu-gcc
# compiling flags here # compiling flags here
#CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32 #CFLAGS = -Wall -I. -O0 -nostartfiles -march=rv32i -mabi=ilp32
CFLAGS = -Wall -I. -O0 -nostdlib -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
# linking flags here # linking flags here
LFLAGS = -I. LFLAGS = -I. --entry main
LIBS = $(EXTRA_LIBS) LIBS = $(EXTRA_LIBS)