C++ example
This commit is contained in:
parent
c33524e726
commit
7ddacbfe1e
|
@ -0,0 +1,50 @@
|
|||
TARGET = cout
|
||||
|
||||
TARGET_ARCH = riscv32
|
||||
|
||||
CC = riscv32-unknown-elf-g++
|
||||
|
||||
# compiling flags here
|
||||
CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs
|
||||
|
||||
LINKER = riscv32-unknown-elf-g++
|
||||
# linking flags here
|
||||
LDFLAGS = -I. -static
|
||||
LIBS = $(EXTRA_LIBS)
|
||||
|
||||
|
||||
# change these to proper directories where each file should be
|
||||
SRCDIR = ./
|
||||
OBJDIR = .
|
||||
BINDIR = ./
|
||||
INCDIR = -I.
|
||||
LIBDIR = -L.
|
||||
|
||||
|
||||
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
|
||||
INCLUDES := $(wildcard $(INCDIR)/*.h)
|
||||
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
|
||||
|
||||
rm = rm -f
|
||||
|
||||
|
||||
$(BINDIR)/$(TARGET): $(OBJECTS)
|
||||
$(LINKER) $(CFLAGS) $(LDFLAGS) $(LIBS) $(LIBDIR) $(OBJECTS) -o $@
|
||||
riscv32-unknown-elf-objdump -d $@ > dump
|
||||
riscv32-unknown-elf-objcopy -Oihex $@ $(TARGET).hex
|
||||
@echo "Linking complete!"
|
||||
|
||||
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
|
||||
@echo "Compiling "$<" ..."
|
||||
$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
|
||||
@echo "Done!"
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@$(rm) $(OBJECTS) *.hex dump
|
||||
@echo "Cleanup complete!"
|
||||
|
||||
.PHONY: remove
|
||||
remove: clean
|
||||
@$(rm) $(BINDIR)/$(TARGET)
|
||||
@echo "Executable removed!"
|
|
@ -0,0 +1,21 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(void) {
|
||||
|
||||
int aux[5] = {0, 1, 2, 3, 4};
|
||||
int aux2[5];
|
||||
int counter = 0;
|
||||
|
||||
cout << "Test Start" << endl;
|
||||
|
||||
|
||||
for ( const auto &x : aux ) std::cout << x << ' ';
|
||||
std::cout << std::endl;
|
||||
|
||||
cout << "Test End" << endl;
|
||||
asm volatile ("ecall");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define TRACE (*(unsigned char *)0x40000000)
|
||||
extern "C" {
|
||||
|
||||
int _read(int file, char* ptr, int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(int fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _close(int fd){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _fstat_r(int fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _lseek_r(struct _reent *ptr, FILE *fp, long offset, int whence){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty_r(struct _reent *ptr, int fd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int _write(int file, const char *ptr, int len) {
|
||||
int x;
|
||||
|
||||
for (x = 0; x < len; x++) {
|
||||
TRACE = *ptr++;
|
||||
}
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
int _getpid(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _kill(int pid) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue