Merge branch 'master' of https://github.com/mariusmm/RISC-V-TLM
This commit is contained in:
commit
ede34d7768
17
README.md
17
README.md
|
@ -63,6 +63,7 @@ Helper classes:
|
||||||
Current performance is about 1.500.000 instructions / sec in a Intel Core
|
Current performance is about 1.500.000 instructions / sec in a Intel Core
|
||||||
i5-5200<span>@</span>2.2Ghz and about 3.000.000 instructions / sec in a Intel Core i7-8550U<span>@</span>1.8Ghz.
|
i5-5200<span>@</span>2.2Ghz and about 3.000.000 instructions / sec in a Intel Core i7-8550U<span>@</span>1.8Ghz.
|
||||||
|
|
||||||
|
Trace perihperal creates a xterm window where it prints out all received data.
|
||||||
|
|
||||||
### Structure
|
### Structure
|
||||||
![Modules' hierarchy](https://github.com/mariusmm/RISC-V-TLM/blob/master/doc/Hierarchy.png)
|
![Modules' hierarchy](https://github.com/mariusmm/RISC-V-TLM/blob/master/doc/Hierarchy.png)
|
||||||
|
@ -72,7 +73,7 @@ i5-5200<span>@</span>2.2Ghz and about 3.000.000 instructions / sec in a Intel Co
|
||||||
|
|
||||||
| Base | Module | Description |
|
| Base | Module | Description |
|
||||||
| ---- | :----: | ---- |
|
| ---- | :----: | ---- |
|
||||||
| 0x40000000 | Trace | Output data directly to stdout |
|
| 0x40000000 | Trace | Output data to xterm |
|
||||||
| 0x40004000 | Timer | LSB Timer |
|
| 0x40004000 | Timer | LSB Timer |
|
||||||
| 0x40004004 | Timer | MSB Timer |
|
| 0x40004004 | Timer | MSB Timer |
|
||||||
| 0x40004008 | Timer | MSB Timer Comparator |
|
| 0x40004008 | Timer | MSB Timer Comparator |
|
||||||
|
@ -122,6 +123,7 @@ $ ./RISCV_TLM asm/BasicLoop.hex
|
||||||
|
|
||||||
### Arguments
|
### Arguments
|
||||||
-D loglevel: 3 for detailed (INFO) log, 0 to ERROR log level
|
-D loglevel: 3 for detailed (INFO) log, 0 to ERROR log level
|
||||||
|
|
||||||
-f filename .hex filename to use
|
-f filename .hex filename to use
|
||||||
|
|
||||||
## Cross-compiler
|
## Cross-compiler
|
||||||
|
@ -137,6 +139,11 @@ wait for long time ...
|
||||||
$ export PATH=$PATH:/opt/riscv/bin
|
$ 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
|
## Docker container
|
||||||
|
|
||||||
There is a Docker container available with the latest release at https://hub.docker.com/r/mariusmm/riscv-tlm.
|
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 pull mariusmm/riscv-tlm
|
||||||
$ docker run -v <path_to_RISCV-V-TLM>/:/tmp -u $UID -e DISPLAY=$DISPLAY --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -it mariusmm/riscv-tlm /bin/bash
|
$ docker run -v <path_to_RISCV-V-TLM>/:/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/<your_hex_file>
|
# ./RISCV_TLM /tmp/<your_hex_file>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or you can call binary inside docker image directly:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ docker run -v <path_to_RISCV-V-TLM>/:/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/<your_hex_file>
|
||||||
|
```
|
||||||
|
|
||||||
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:
|
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:
|
console1:
|
||||||
|
|
|
@ -40,8 +40,7 @@ bool CPU::cpu_process_IRQ() {
|
||||||
|
|
||||||
if (interrupt == true) {
|
if (interrupt == true) {
|
||||||
csr_temp = register_bank->getCSR(CSR_MSTATUS);
|
csr_temp = register_bank->getCSR(CSR_MSTATUS);
|
||||||
if (csr_temp & MSTATUS_MIE) {
|
if ( (csr_temp & MSTATUS_MIE) == 0) {
|
||||||
} else {
|
|
||||||
log->SC_log(Log::DEBUG) << "interrupt delayed" << endl;
|
log->SC_log(Log::DEBUG) << "interrupt delayed" << endl;
|
||||||
return ret_value;
|
return ret_value;
|
||||||
}
|
}
|
||||||
|
@ -547,7 +546,7 @@ void CPU::CPU_thread(void) {
|
||||||
void CPU::call_interrupt(tlm::tlm_generic_payload &trans, sc_time &delay) {
|
void CPU::call_interrupt(tlm::tlm_generic_payload &trans, sc_time &delay) {
|
||||||
interrupt = true;
|
interrupt = true;
|
||||||
/* Socket caller send a cause (its id) */
|
/* 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)
|
void CPU::invalidate_direct_mem_ptr(sc_dt::uint64 start, sc_dt::uint64 end)
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
TARGET = long_test1
|
TARGET = long_test1
|
||||||
|
|
||||||
TARGET_ARCH=riscv32
|
TARGET_ARCH = riscv32
|
||||||
|
|
||||||
CC = riscv32-unknown-elf-gcc
|
CC = riscv32-unknown-elf-gcc
|
||||||
|
|
||||||
# compiling flags here
|
# compiling flags here
|
||||||
CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs
|
CFLAGS = -Wall -I. -O0 -static -march=rv32imac -mabi=ilp32 --specs=nosys.specs
|
||||||
|
|
||||||
|
LINKER = riscv32-unknown-elf-gcc
|
||||||
LINKER = riscv32-unknown-linux-gnu-gcc
|
|
||||||
# linking flags here
|
# linking flags here
|
||||||
LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld
|
LDFLAGS = -I. -static
|
||||||
LIBS = $(EXTRA_LIBS)
|
LIBS = $(EXTRA_LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,15 +29,14 @@ rm = rm -f
|
||||||
|
|
||||||
|
|
||||||
$(BINDIR)/$(TARGET): $(OBJECTS)
|
$(BINDIR)/$(TARGET): $(OBJECTS)
|
||||||
# $(LINKER) $(OBJECTS) $(LDFLAGS) $(LIBS) $(LIBDIR) -o $@
|
$(LINKER) $(CFLAGS) $(LDFLAGS) $(LIBS) $(LIBDIR) $(OBJECTS) -o $@
|
||||||
riscv32-unknown-elf-objdump -d $< > dump
|
riscv32-unknown-elf-objdump -d $@ > dump
|
||||||
riscv32-unknown-elf-objcopy -Oihex $< $(TARGET).hex
|
riscv32-unknown-elf-objcopy -Oihex $@ $(TARGET).hex
|
||||||
# @echo "Linking complete!"
|
@echo "Linking complete!"
|
||||||
|
|
||||||
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
|
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
|
||||||
@echo "Compiling "$<" ..."
|
@echo "Compiling "$<" ..."
|
||||||
# $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
|
$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
|
||||||
$(CC) $(CFLAGS) $(INCDIR) $< -o $@
|
|
||||||
@echo "Done!"
|
@echo "Done!"
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
|
@ -1,36 +1,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#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) {
|
int main(void) {
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
TARGET = test_malloc
|
TARGET = malloc_test
|
||||||
|
|
||||||
TARGET_ARCH=riscv32
|
TARGET_ARCH = riscv32
|
||||||
|
|
||||||
CC = riscv32-unknown-elf-gcc
|
CC = riscv32-unknown-elf-gcc
|
||||||
|
|
||||||
# compiling flags here
|
# 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
|
# linking flags here
|
||||||
LDFLAGS = -I. --entry main -L/opt/riscv/riscv32-unknown-elf/lib/ -T ld_script.ld
|
LDFLAGS = -I. -static
|
||||||
LIBS = $(EXTRA_LIBS)
|
LIBS = $(EXTRA_LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,19 +24,19 @@ 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) $(LDFLAGS) $(LIBS) $(LIBDIR) -o $@
|
$(LINKER) $(CFLAGS) $(LDFLAGS) $(LIBS) $(LIBDIR) $(OBJECTS) -o $@
|
||||||
riscv32-unknown-elf-objdump -d $< > dump
|
riscv32-unknown-elf-objdump -d $@ > dump
|
||||||
objcopy -Oihex $< $(TARGET).hex
|
riscv32-unknown-elf-objcopy -Oihex $@ $(TARGET).hex
|
||||||
# @echo "Linking complete!"
|
@echo "Linking complete!"
|
||||||
|
|
||||||
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
|
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
|
||||||
@echo "Compiling "$<" ..."
|
@echo "Compiling "$<" ..."
|
||||||
# $(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
|
$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
|
||||||
$(CC) $(CFLAGS) $(INCDIR) $< -o $@
|
|
||||||
@echo "Done!"
|
@echo "Done!"
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
@ -46,5 +46,5 @@ clean:
|
||||||
|
|
||||||
.PHONY: remove
|
.PHONY: remove
|
||||||
remove: clean
|
remove: clean
|
||||||
@$(rm) $(BINDIR)/$(TARGET)
|
@$(rm) $(BINDIR)/$(TARGET) $(OBJECTS)
|
||||||
@echo "Executable removed!"
|
@echo "Executable removed!"
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
|
@ -2,45 +2,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#define BUFFER_SIZE (512)
|
#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) {
|
int main(void) {
|
||||||
uint16_t *buffA, *buffB;
|
uint16_t *buffA, *buffB;
|
|
@ -35,7 +35,7 @@ void register_timer_isr() {
|
||||||
asm volatile("csrw mie, t1");
|
asm volatile("csrw mie, t1");
|
||||||
|
|
||||||
// enable interrupts
|
// enable interrupts
|
||||||
asm volatile( "csrs mstatus,1" );
|
asm volatile( "csrs mstatus,0x0F" );
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
Loading…
Reference in New Issue