diff --git a/README.md b/README.md index 2a38101..ea0c672 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Helper classes: Current performance is about 1.500.000 instructions / sec in a Intel Core i5-5200@2.2Ghz and about 3.000.000 instructions / sec in a Intel Core i7-8550U@1.8Ghz. +Trace perihperal creates a xterm window where it prints out all received data. ### Structure ![Modules' hierarchy](https://github.com/mariusmm/RISC-V-TLM/blob/master/doc/Hierarchy.png) @@ -72,7 +73,7 @@ i5-5200@2.2Ghz and about 3.000.000 instructions / sec in a Intel Co | Base | Module | Description | | ---- | :----: | ---- | -| 0x40000000 | Trace | Output data directly to stdout | +| 0x40000000 | Trace | Output data to xterm | | 0x40004000 | Timer | LSB Timer | | 0x40004004 | Timer | MSB Timer | | 0x40004008 | Timer | MSB Timer Comparator | @@ -122,6 +123,7 @@ $ ./RISCV_TLM asm/BasicLoop.hex ### Arguments -D loglevel: 3 for detailed (INFO) log, 0 to ERROR log level + -f filename .hex filename to use ## Cross-compiler @@ -137,6 +139,11 @@ wait for long time ... $ export PATH=$PATH:/opt/riscv/bin ~~~ +In test/C/long_test/ example there is a Makefile that compiles a project with any .c files and links them against new-lib nano. +There is a Helper_functions.c file with defiitions of all missing functions needed by the library (**_read()**, **_close()**, **_fstat_r()**, +**_lseek_r()**, **_isatty_r()**, **_write()**). All of them are defined empty except **_write()** that is written to use the Trace perihperal. +The definition of the function **_write()** allows developer to use printf() as usual and the stdout will be redirected to the Trace perihperal. + ## Docker container There is a Docker container available with the latest release at https://hub.docker.com/r/mariusmm/riscv-tlm. @@ -147,10 +154,16 @@ This container has RISCV-TLM already build at /usr/src/riscv64/RISCV-TLM directo $ docker pull mariusmm/riscv-tlm $ docker run -v /:/tmp -u $UID -e DISPLAY=$DISPLAY --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -it mariusmm/riscv-tlm /bin/bash -# cd /usr/src/riscv64/RISCV_TLM/ +# cd /usr/src/riscv64/RISC-V-TLM/ # ./RISCV_TLM /tmp/ ``` +or you can call binary inside docker image directly: + +``` +$ docker run -v /:/tmp -u $UID -e DISPLAY=$DISPLAY --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -it mariusmm/riscv-tlm /usr/src/riscv64/RISC-V-TLM/RISCV_TLM /tmp/ +``` + I'm using docker image [zmors/riscv_gcc](https://hub.docker.com/r/zmors/riscv_gcc) to have a cross-compiler, I'm using both docker images this way: ``` console1: diff --git a/doc/Doxygen.cfg b/doc/Doxyfile similarity index 100% rename from doc/Doxygen.cfg rename to doc/Doxyfile diff --git a/src/CPU.cpp b/src/CPU.cpp index ff271fe..46a24ca 100644 --- a/src/CPU.cpp +++ b/src/CPU.cpp @@ -40,8 +40,7 @@ bool CPU::cpu_process_IRQ() { if (interrupt == true) { csr_temp = register_bank->getCSR(CSR_MSTATUS); - if (csr_temp & MSTATUS_MIE) { - } else { + if ( (csr_temp & MSTATUS_MIE) == 0) { log->SC_log(Log::DEBUG) << "interrupt delayed" << endl; return ret_value; } @@ -547,7 +546,7 @@ void CPU::CPU_thread(void) { void CPU::call_interrupt(tlm::tlm_generic_payload &trans, sc_time &delay) { interrupt = true; /* Socket caller send a cause (its id) */ - memcpy(&int_cause, trans.get_data_ptr(), sizeof(int)); + memcpy(&int_cause, trans.get_data_ptr(), sizeof(uint32_t)); } void CPU::invalidate_direct_mem_ptr(sc_dt::uint64 start, sc_dt::uint64 end) diff --git a/tests/C/long_test1/Makefile b/tests/C/long_test1/Makefile index fc446be..9e76816 100644 --- a/tests/C/long_test1/Makefile +++ b/tests/C/long_test1/Makefile @@ -1,16 +1,15 @@ TARGET = long_test1 -TARGET_ARCH=riscv32 +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 +LINKER = riscv32-unknown-elf-gcc # linking flags here -LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld +LDFLAGS = -I. -static LIBS = $(EXTRA_LIBS) @@ -30,15 +29,14 @@ rm = rm -f $(BINDIR)/$(TARGET): $(OBJECTS) -# $(LINKER) $(OBJECTS) $(LDFLAGS) $(LIBS) $(LIBDIR) -o $@ - riscv32-unknown-elf-objdump -d $< > dump - riscv32-unknown-elf-objcopy -Oihex $< $(TARGET).hex -# @echo "Linking complete!" + $(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)/%.c @echo "Compiling "$<" ..." -# $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@ - $(CC) $(CFLAGS) $(INCDIR) $< -o $@ + $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@ @echo "Done!" .PHONY: clean diff --git a/tests/C/long_test1/helper_functions.c b/tests/C/long_test1/helper_functions.c new file mode 100644 index 0000000..18efcba --- /dev/null +++ b/tests/C/long_test1/helper_functions.c @@ -0,0 +1,35 @@ +#include +#include + + +#define TRACE (*(unsigned char *)0x40000000) +int _read(int file, char* ptr, int len) { + 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); +} + diff --git a/tests/C/long_test1/long_test1.c b/tests/C/long_test1/long_test1.c index d2d8a70..71fcb49 100644 --- a/tests/C/long_test1/long_test1.c +++ b/tests/C/long_test1/long_test1.c @@ -1,36 +1,7 @@ #include #include -#define TRACE (*(unsigned char *)0x40000000) -int _read(int file, char* ptr, int len) { - 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 main(void) { diff --git a/tests/C/test_malloc/Makefile b/tests/C/malloc_test/Makefile similarity index 57% rename from tests/C/test_malloc/Makefile rename to tests/C/malloc_test/Makefile index 656ba6c..f761442 100644 --- a/tests/C/test_malloc/Makefile +++ b/tests/C/malloc_test/Makefile @@ -1,15 +1,15 @@ -TARGET = test_malloc +TARGET = malloc_test -TARGET_ARCH=riscv32 +TARGET_ARCH = riscv32 CC = riscv32-unknown-elf-gcc # compiling flags here -CFLAGS = -Wall -I. -O0 -static --specs=nosys.specs +CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs -LINKER = riscv32-unknown-linux-gnu-gcc +LINKER = riscv32-unknown-elf-gcc # linking flags here -LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld +LDFLAGS = -I. -static LIBS = $(EXTRA_LIBS) @@ -24,19 +24,19 @@ 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-elf-objdump -d $< > dump - objcopy -Oihex $< $(TARGET).hex -# @echo "Linking complete!" + $(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)/%.c @echo "Compiling "$<" ..." -# $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@ - $(CC) $(CFLAGS) $(INCDIR) $< -o $@ + $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@ @echo "Done!" .PHONY: clean @@ -46,5 +46,5 @@ clean: .PHONY: remove remove: clean - @$(rm) $(BINDIR)/$(TARGET) + @$(rm) $(BINDIR)/$(TARGET) $(OBJECTS) @echo "Executable removed!" diff --git a/tests/C/malloc_test/helper_functions.c b/tests/C/malloc_test/helper_functions.c new file mode 100644 index 0000000..18efcba --- /dev/null +++ b/tests/C/malloc_test/helper_functions.c @@ -0,0 +1,35 @@ +#include +#include + + +#define TRACE (*(unsigned char *)0x40000000) +int _read(int file, char* ptr, int len) { + 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); +} + diff --git a/tests/C/malloc_test/malloc_test b/tests/C/malloc_test/malloc_test new file mode 100755 index 0000000..3e29984 Binary files /dev/null and b/tests/C/malloc_test/malloc_test differ diff --git a/tests/C/test_malloc/test_malloc.c b/tests/C/malloc_test/malloc_test.c similarity index 70% rename from tests/C/test_malloc/test_malloc.c rename to tests/C/malloc_test/malloc_test.c index 8344d6d..88f7b29 100644 --- a/tests/C/test_malloc/test_malloc.c +++ b/tests/C/malloc_test/malloc_test.c @@ -2,45 +2,9 @@ #include #include #include -#include -#include #define BUFFER_SIZE (512) -#define TRACE (*(unsigned char *)0x40000000) -extern int errno; - -int _write(int file, const char *ptr, int len) { - int x; - - for (x = 0; x < len; x++) { - TRACE = *ptr++; - } - - return (len); -} - -int _read (int file, char *ptr, int len) { - return 0; -} - -int _close (int file) { - errno = EBADF; - return -1; -} - -int _fstat (int file, struct stat *st) { - st->st_mode = S_IFCHR; - return 0; -} - -int _isatty (int file) { - return 1; -} - -int _lseek (int file, int offset, int whence) { - return 0; -} int main(void) { uint16_t *buffA, *buffB; diff --git a/tests/C/timer/timer.c b/tests/C/timer/timer.c index a9c1d80..4f43332 100644 --- a/tests/C/timer/timer.c +++ b/tests/C/timer/timer.c @@ -35,7 +35,7 @@ void register_timer_isr() { asm volatile("csrw mie, t1"); // enable interrupts - asm volatile( "csrs mstatus,1" ); + asm volatile( "csrs mstatus,0x0F" ); } int main(void) {