Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Commit 6dde6b8

Browse files
author
f74064054@mail.ncku.edu.tw
committed
Inter save
1 parent bf3a5b0 commit 6dde6b8

File tree

131 files changed

+18241
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+18241
-5
lines changed

CSRs.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,91 @@ uint32_t uip; /* User interrupt pending */
8989
// ====================================================== //
9090
uint32_t fflags; /* Floating-Point Accrued Exceptions*/
9191
uint32_t frm; /* Floating-Point Dynamic Rounding Mode*/
92+
uint32_t fcsr; /* Floating-Point Control and Status Register (frm + fflags )*/
93+
// ====================================================== //
94+
// ================ User Counter / TImers =============== //
95+
// ====================================================== //
96+
uint32_t cycle; /* Cycle counter for RDCYCLE instruction */
97+
uint32_t time; /* Timer for RDTIME instruction */
98+
uint32_t instret; /* Instructions-retired counter for RDINSTRET instructions*/
99+
uint32_t cycleh; /* Upper 32 bits of cycle, RV32I only. */
100+
uint32_t timeh; /* Upper 32 bits of time, RV32I only. */
101+
102+
103+
// ====================================================== //
104+
// ================ Supervior Trap Setup ================ //
105+
// ====================================================== //
106+
uint32_t sstatus; /* Supervisor status register */
107+
uint32_t sedeleg; /* Supervisor exception delegation register */
108+
uint32_t sideleg; /* Supervisor interrupt delegation register */
109+
uint32_t sie; /* Supervisor interrupt-enable register*/
110+
uint32_t stvec; /* Supervisor trap handler base address */
111+
// ====================================================== //
112+
// ============== Supervisor Trap Handling ============== //
113+
// ====================================================== //
114+
uint32_t sscratch; /* Scratch register for supervisor trap handlers */
115+
uint32_t sepc; /* Supervisor exception program counter */
116+
uint32_t scause; /* Supervisor trap cause */
117+
uint32_t sbadaddr; /* Supervisor bad address */
118+
uint32_t sip; /* Supervisor interrupt pending */
119+
// ====================================================== //
120+
// ======== Supervisor Protection and Translation ======= //
121+
// ====================================================== //
122+
uint32_t sptbr; /* Page-table base register */
123+
124+
125+
// ====================================================== //
126+
// ================ Hypervisor Trap Setup =============== //
127+
// ====================================================== //
128+
uint32_t hstatus; /* Hypervisor status register */
129+
uint32_t hedeleg; /* Hypervisor exception delegation register */
130+
uint32_t hideleg; /* Hyperbisor interrupt delegation register */
131+
uint32_t hie; /* Hypervisor interrupt-enable register */
132+
uint32_t htvec; /* Hypervisor trap handler base address */
133+
// ====================================================== //
134+
// ============== Hypervisor Trap Handling ============== //
135+
// ====================================================== //
136+
uint32_t hscratch; /* Scratch register for hypervisor trap handlers */
137+
uint32_t hepc; /* Hypervisor exception program counter */
138+
uint32_t hcause; /* Hypervisor trap cause */
139+
uint32_t hbadaddr; /* Hypervisor bad address */
140+
uint32_t hip; /* Hypervisor interrupt pending */
141+
// ====================================================== //
142+
// ======== Hypervisor Protection and Translation ======= //
143+
// ====================================================== //
144+
// uint32_t TBD; /* TBD */
145+
146+
147+
// ====================================================== //
148+
// ============ Machine Information Register ============ //
149+
// ====================================================== //
150+
uint32_t mvendorid; /* Vendor ID*/
151+
uint32_t marchid; /* Architecture ID */
152+
uint32_t mimpid; /* Implementation ID */
153+
uint32_t mhartid; /* Hardware thread ID */
154+
// ====================================================== //
155+
// ================= Machine Trap Setup ================= //
156+
// ====================================================== //
157+
uint32_t mstatus; /* Machine status register */
158+
uint32_t misa; /* ISA and extensions */
159+
uint32_t medeleg; /* Machine exception delegation register */
160+
uint32_t mideleg; /* Machine interrupt delegation register */
161+
uint32_t mie; /* Machine interrupt-enable register */
162+
uint32_t mtvec; /* Machine trap-handler base address */
163+
// ====================================================== //
164+
// ================ Machine Trap Handling =============== //
165+
// ====================================================== //
166+
uint32_t mscratch; /* Scratch register for machine trap handlers */
167+
uint32_t mepc; /* Machine exception program counter */
168+
uint32_t mcause; /* Machine trap cause */
169+
uint32_t mbadaddr; /* Machine bad address */
170+
uint32_t mip; /* Machine interrupt pending */
171+
// ====================================================== //
172+
// ========= Machine Protextion and Translation ========= //
173+
// ====================================================== //
174+
uint32_t mbase; /* Base regsiter */
175+
uint32_t mbound; /* Bound register */
176+
uint32_t mibase; /* Instruction base register */
177+
uint32_t mibound; /* Instruction bound register */
178+
uint32_t mdbase; /* Data base register */
179+
uint32_t mdbound; /* Data bound register */

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ RV32I_CFLAGS = -march=rv32i -mabi=ilp32 -O3 -nostdlib
66
CFLAGS = -O3 -Wall
77
LDFLAGS = -lelf
88

9+
RUN_TARGET := ./emu-rv32i
10+
WORK_DIR = work/rv32imc
11+
12+
913
all: $(BINS)
10-
14+
1115
emu-rv32i: emu-rv32i.c
1216
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
1317

1418
test1: test1.c
1519
$(CROSS_COMPILE)gcc $(RV32I_CFLAGS) -o $@ $<
1620

21+
22+
%.log: $(WORK_DIR)/%.elf
23+
$(RUN_TARGET) $<
24+
1725
check: $(BINS)
1826
./emu-rv32i test1
1927

emu-rv32i.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ original copyright:
8787
#include <gelf.h>
8888

8989
/* uncomment this for an instruction trace and other debug outputs */
90-
#if 0
90+
#if 1
9191
#define DEBUG_OUTPUT
9292
#endif
93-
#if 0
93+
#if 1
9494
#define DEBUG_EXTRA
9595
#endif
9696

@@ -779,6 +779,8 @@ uint32_t get_insn32(uint32_t pc)
779779
uint32_t ptr = pc - ram_start;
780780
if (ptr > RAM_SIZE) return 1;
781781
uint8_t* p = ram + ptr;
782+
if((p[0] & 0x03) < 3)
783+
return p[0] | (p[1] << 8);
782784
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
783785
}
784786

@@ -1904,7 +1906,13 @@ void execute_instruction()
19041906
break;
19051907

19061908
#endif
1909+
#ifndef RV32C
1910+
1911+
case 1: /* Compressed insn */
1912+
1913+
break;
19071914

1915+
#endif
19081916
default:
19091917
raise_exception(CAUSE_ILLEGAL_INSTRUCTION, insn);
19101918
return;
@@ -1944,6 +1952,9 @@ void riscv_cpu_interp_x32()
19441952
} else {
19451953
/* normal instruction execution */
19461954
insn = get_insn32(pc);
1955+
#ifdef DEBUG_EXTRA
1956+
printf("insn : %#x\n", insn);
1957+
#endif
19471958
insn_counter++;
19481959

19491960
#ifdef DEBUG_OUTPUT
@@ -2023,7 +2034,7 @@ int main(int argc, char** argv)
20232034
GElf_Sym sym;
20242035
gelf_getsym(data, i, &sym);
20252036
char* name = elf_strptr(elf, shdr.sh_link, sym.st_name);
2026-
#if 0
2037+
#ifdef DEBUG_EXTRA
20272038
if(*name) printf("sym '%s' %lx\n",name,sym.st_value);
20282039
#endif
20292040
if (strcmp(name, "begin_signature") == 0) {
@@ -2056,6 +2067,7 @@ int main(int argc, char** argv)
20562067

20572068
/* scan for program */
20582069
while ((scn = elf_nextscn(elf, scn)) != NULL) {
2070+
/* ELF Section Header Table*/
20592071
gelf_getshdr(scn, &shdr);
20602072
if (shdr.sh_type == SHT_PROGBITS) {
20612073
Elf_Data *data = elf_getdata(scn, NULL);
@@ -2145,7 +2157,7 @@ int main(int argc, char** argv)
21452157
/* run program in emulator */
21462158
pc = ram_start;
21472159
/* Initialize the address of stack pointer*/
2148-
reg[2] = ram_start + RAM_SIZE - 4;
2160+
reg[2] = ram_start + RAM_SIZE;
21492161
riscv_cpu_interp_x32();
21502162

21512163
uint64_t ns2 = get_clock();

include/RV32C-01.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef RV32C_H
2+
#define RC32C_H
3+
4+
5+
6+
#endif

0 commit comments

Comments
 (0)