upgrade to latest rocket-chip
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
GCC=riscv64-unknown-elf-gcc
|
||||
OBJDUMP=riscv64-unknown-elf-objdump
|
||||
CFLAGS=-mcmodel=medany -std=gnu99 -O2 -fno-common -fno-builtin-printf
|
||||
LDFLAGS=-static -nostdlib -nostartfiles -lgcc
|
||||
|
||||
default: pwm.riscv
|
||||
PROGRAMS = pwm
|
||||
|
||||
default: $(addsuffix .riscv,$(PROGRAMS))
|
||||
|
||||
dumps: $(addsuffix .dump,$(PROGRAMS))
|
||||
|
||||
%.o: %.S
|
||||
$(GCC) $(CFLAGS) -D__ASSEMBLY__=1 -c $< -o $@
|
||||
@@ -13,5 +18,8 @@ default: pwm.riscv
|
||||
%.riscv: %.o crt.o syscalls.o
|
||||
$(GCC) -T link.ld $(LDFLAGS) $^ -o $@
|
||||
|
||||
%.dump: %.riscv
|
||||
$(OBJDUMP) -D $< > $@
|
||||
|
||||
clean:
|
||||
rm -f *.riscv *.o
|
||||
rm -f *.riscv *.o *.dump
|
||||
|
||||
38
tests/crt.S
38
tests/crt.S
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "encoding.h"
|
||||
|
||||
#ifdef __riscv64
|
||||
#if __riscv_xlen == 64
|
||||
# define LREG ld
|
||||
# define SREG sd
|
||||
# define REGBYTES 8
|
||||
@@ -12,12 +12,9 @@
|
||||
# define REGBYTES 4
|
||||
#endif
|
||||
|
||||
.text
|
||||
.section ".text.init"
|
||||
.globl _start
|
||||
_start:
|
||||
la t0, trap_entry
|
||||
csrw mtvec, t0
|
||||
|
||||
li x1, 0
|
||||
li x2, 0
|
||||
li x3, 0
|
||||
@@ -55,20 +52,23 @@ _start:
|
||||
csrs mstatus, t0
|
||||
|
||||
# make sure XLEN agrees with compilation choice
|
||||
csrr t0, misa
|
||||
#ifdef __riscv64
|
||||
bltz t0, 1f
|
||||
#else
|
||||
li t0, 1
|
||||
slli t0, t0, 31
|
||||
#if __riscv_xlen == 64
|
||||
bgez t0, 1f
|
||||
#else
|
||||
bltz t0, 1f
|
||||
#endif
|
||||
li a0, 1234
|
||||
j tohost_exit
|
||||
2:
|
||||
li a0, 1
|
||||
sw a0, tohost, t0
|
||||
j 2b
|
||||
1:
|
||||
|
||||
#ifdef __riscv_hard_float
|
||||
#ifdef __riscv_flen
|
||||
# initialize FPU if we have one
|
||||
andi t0, t0, 1 << ('f' - 'a')
|
||||
beqz t0, 1f
|
||||
la t0, 1f
|
||||
csrw mtvec, t0
|
||||
|
||||
fssr x0
|
||||
fmv.s.x f0, x0
|
||||
@@ -103,12 +103,18 @@ _start:
|
||||
fmv.s.x f29,x0
|
||||
fmv.s.x f30,x0
|
||||
fmv.s.x f31,x0
|
||||
1:
|
||||
#endif
|
||||
|
||||
1:
|
||||
# initialize trap vector
|
||||
la t0, trap_entry
|
||||
csrw mtvec, t0
|
||||
|
||||
# initialize global pointer
|
||||
la gp, _gp
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, __global_pointer$
|
||||
.option pop
|
||||
|
||||
la tp, _end + 63
|
||||
and tp, tp, -64
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
specifically one of the entires in bfd/cpu-mips.c */
|
||||
|
||||
OUTPUT_ARCH( "riscv" )
|
||||
ENTRY(_start)
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* Sections */
|
||||
@@ -22,7 +23,7 @@ SECTIONS
|
||||
|
||||
/* text: test code section */
|
||||
. = 0x80000000;
|
||||
.text.init : { crt.o(.text) }
|
||||
.text.init : { *(.text.init) }
|
||||
|
||||
.tohost ALIGN(0x1000) : { *(.tohost) }
|
||||
|
||||
@@ -32,7 +33,7 @@ SECTIONS
|
||||
.data : { *(.data) }
|
||||
|
||||
.sdata : {
|
||||
_gp = . + 0x800;
|
||||
__global_pointer$ = . + 0x800;
|
||||
*(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
|
||||
*(.sdata .sdata.* .gnu.linkonce.s.*)
|
||||
}
|
||||
@@ -48,14 +49,14 @@ SECTIONS
|
||||
.tdata :
|
||||
{
|
||||
_tls_data = .;
|
||||
crt.o(.tdata.begin)
|
||||
*(.tdata.begin)
|
||||
*(.tdata)
|
||||
crt.o(.tdata.end)
|
||||
*(.tdata.end)
|
||||
}
|
||||
.tbss :
|
||||
{
|
||||
*(.tbss)
|
||||
crt.o(.tbss.end)
|
||||
*(.tbss.end)
|
||||
}
|
||||
|
||||
/* End of uninitalized data segement */
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <sys/signal.h>
|
||||
#include "util.h"
|
||||
|
||||
#define SYS_write 64
|
||||
#define SYS_exit 93
|
||||
#define SYS_stats 1234
|
||||
|
||||
#undef strcmp
|
||||
|
||||
extern volatile uint64_t tohost;
|
||||
extern volatile uint64_t fromhost;
|
||||
|
||||
static uintptr_t handle_frontend_syscall(uintptr_t which, uint64_t arg0, uint64_t arg1, uint64_t arg2)
|
||||
static uintptr_t syscall(uintptr_t which, uint64_t arg0, uint64_t arg1, uint64_t arg2)
|
||||
{
|
||||
volatile uint64_t magic_mem[8] __attribute__((aligned(64)));
|
||||
magic_mem[0] = which;
|
||||
@@ -36,7 +37,7 @@ static uintptr_t handle_frontend_syscall(uintptr_t which, uint64_t arg0, uint64_
|
||||
static uintptr_t counters[NUM_COUNTERS];
|
||||
static char* counter_names[NUM_COUNTERS];
|
||||
|
||||
static int handle_stats(int enable)
|
||||
void setStats(int enable)
|
||||
{
|
||||
int i = 0;
|
||||
#define READ_CTR(name) do { \
|
||||
@@ -50,7 +51,6 @@ static int handle_stats(int enable)
|
||||
READ_CTR(minstret);
|
||||
|
||||
#undef READ_CTR
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __attribute__((noreturn)) tohost_exit(uintptr_t code)
|
||||
@@ -59,39 +59,19 @@ void __attribute__((noreturn)) tohost_exit(uintptr_t code)
|
||||
while (1);
|
||||
}
|
||||
|
||||
uintptr_t handle_trap(uintptr_t cause, uintptr_t epc, uintptr_t regs[32])
|
||||
uintptr_t __attribute__((weak)) handle_trap(uintptr_t cause, uintptr_t epc, uintptr_t regs[32])
|
||||
{
|
||||
if (cause != CAUSE_MACHINE_ECALL)
|
||||
tohost_exit(1337);
|
||||
else if (regs[17] == SYS_exit)
|
||||
tohost_exit(regs[10]);
|
||||
else if (regs[17] == SYS_stats)
|
||||
regs[10] = handle_stats(regs[10]);
|
||||
else
|
||||
regs[10] = handle_frontend_syscall(regs[17], regs[10], regs[11], regs[12]);
|
||||
|
||||
return epc + ((*(unsigned short*)epc & 3) == 3 ? 4 : 2);
|
||||
}
|
||||
|
||||
static uintptr_t syscall(uintptr_t num, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2)
|
||||
{
|
||||
register uintptr_t a7 asm("a7") = num;
|
||||
register uintptr_t a0 asm("a0") = arg0;
|
||||
register uintptr_t a1 asm("a1") = arg1;
|
||||
register uintptr_t a2 asm("a2") = arg2;
|
||||
asm volatile ("scall" : "+r"(a0) : "r"(a1), "r"(a2), "r"(a7));
|
||||
return a0;
|
||||
tohost_exit(1337);
|
||||
}
|
||||
|
||||
void exit(int code)
|
||||
{
|
||||
syscall(SYS_exit, code, 0, 0);
|
||||
while (1);
|
||||
tohost_exit(code);
|
||||
}
|
||||
|
||||
void setStats(int enable)
|
||||
void abort()
|
||||
{
|
||||
syscall(SYS_stats, enable, 0, 0);
|
||||
exit(128 + SIGABRT);
|
||||
}
|
||||
|
||||
void printstr(const char* s)
|
||||
|
||||
Reference in New Issue
Block a user