Commit 8d49b922 authored by Alexander Shabarshin's avatar Alexander Shabarshin

midified for pure C

parent 04d300c7
/* 18-NOV-2018 - Shaos slghtly modified this code for pure C */
/* Taken from https://gist.github.com/FrankBuss/c974e59826d33e21d7cad54491ab50e8 */
/*
RISCV emulator for the RV32I architecture
based on TinyEMU by Fabrice Bellard, see https://bellard.org/tinyemu/
......@@ -80,6 +84,10 @@ original copyright:
// uncomment this for an instruction trace and other debug outputs
//#define DEBUG_OUTPUT
// Shaos added:
#define FALSE (0)
#define TRUE (-1)
// memory mapped registers
#define MTIME_ADDR 0x40000000
#define MTIMECMP_ADDR 0x40000008
......@@ -101,7 +109,7 @@ uint32_t begin_signature = 0;
uint32_t end_signature = 0;
// is set to false to exit the emulator
bool machine_running = true;
int machine_running = TRUE;
// privilege levels
#define PRV_U 0
......@@ -251,7 +259,7 @@ int ctz32(uint32_t a)
uint32_t get_mstatus(uint32_t mask)
{
uint32_t val;
bool sd;
int sd;
val = mstatus | (fs << MSTATUS_FS_SHIFT);
val &= mask;
sd = ((val & MSTATUS_FS) == MSTATUS_FS) |
......@@ -283,7 +291,7 @@ void invalid_csr(uint32_t *pval, uint32_t csr)
/* return -1 if invalid CSR. 0 if OK. 'will_write' indicate that the
csr will be written after (used for CSR access check) */
int csr_read(uint32_t *pval, uint32_t csr,
bool will_write)
int will_write)
{
uint32_t val;
......@@ -548,11 +556,11 @@ void handle_mret()
void raise_exception(uint32_t cause,
uint32_t tval)
{
bool deleg;
int deleg;
// exit for Zephyr applications
if (cause == CAUSE_ILLEGAL_INSTRUCTION) {
machine_running = false;
machine_running = FALSE;
return;
}
......@@ -1154,7 +1162,7 @@ void execute_instruction()
funct3 &= 3;
switch(funct3) {
case 1: /* csrrw */
if (csr_read(&val2, imm, true)) {
if (csr_read(&val2, imm, TRUE)) {
raise_exception(CAUSE_ILLEGAL_INSTRUCTION, insn);
return;
}
......@@ -1207,7 +1215,7 @@ void execute_instruction()
#ifdef DEBUG_OUTPUT
printf("program end, result: %04x\n", reg[3] >> 1);
#endif
machine_running = false;
machine_running = FALSE;
return;
} else {
#ifdef DEBUG_OUTPUT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment