projects
/
riscv-isa-sim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix a bug caused by moving misa into state_t. (#180)
[riscv-isa-sim.git]
/
riscv
/
processor.h
diff --git
a/riscv/processor.h
b/riscv/processor.h
index 87cb6a400e28dff4c4322157ff3a692da5add6c6..ace86f963959145e3e8a7227f4fa2e91f0395e71 100644
(file)
--- a/
riscv/processor.h
+++ b/
riscv/processor.h
@@
-5,15
+5,16
@@
#include "decode.h"
#include "config.h"
#include "devices.h"
#include "decode.h"
#include "config.h"
#include "devices.h"
+#include "trap.h"
#include <string>
#include <vector>
#include <map>
#include <string>
#include <vector>
#include <map>
-#include "debug_rom
/debug_rom
_defines.h"
+#include "debug_rom_defines.h"
class processor_t;
class mmu_t;
typedef reg_t (*insn_func_t)(processor_t*, insn_t, reg_t);
class processor_t;
class mmu_t;
typedef reg_t (*insn_func_t)(processor_t*, insn_t, reg_t);
-class sim_t;
+class sim
if
_t;
class trap_t;
class extension_t;
class disassembler_t;
class trap_t;
class extension_t;
class disassembler_t;
@@
-85,7
+86,7
@@
typedef struct
// architectural state of a RISC-V hart
struct state_t
{
// architectural state of a RISC-V hart
struct state_t
{
- void reset();
+ void reset(
reg_t max_isa
);
static const int num_triggers = 4;
static const int num_triggers = 4;
@@
-95,9
+96,10
@@
struct state_t
// control and status registers
reg_t prv; // TODO: Can this be an enum instead?
// control and status registers
reg_t prv; // TODO: Can this be an enum instead?
+ reg_t misa;
reg_t mstatus;
reg_t mepc;
reg_t mstatus;
reg_t mepc;
- reg_t m
badaddr
;
+ reg_t m
tval
;
reg_t mscratch;
reg_t mtvec;
reg_t mcause;
reg_t mscratch;
reg_t mtvec;
reg_t mcause;
@@
-109,10
+111,10
@@
struct state_t
uint32_t mcounteren;
uint32_t scounteren;
reg_t sepc;
uint32_t mcounteren;
uint32_t scounteren;
reg_t sepc;
- reg_t s
badaddr
;
+ reg_t s
tval
;
reg_t sscratch;
reg_t stvec;
reg_t sscratch;
reg_t stvec;
- reg_t s
ptbr
;
+ reg_t s
atp
;
reg_t scause;
reg_t dpc;
reg_t dscratch;
reg_t scause;
reg_t dpc;
reg_t dscratch;
@@
-162,7
+164,7
@@
static int cto(reg_t val)
class processor_t : public abstract_device_t
{
public:
class processor_t : public abstract_device_t
{
public:
- processor_t(const char* isa, sim_t* sim, uint32_t id, bool halt_on_reset=false);
+ processor_t(const char* isa, sim
if
_t* sim, uint32_t id, bool halt_on_reset=false);
~processor_t();
void set_debug(bool value);
~processor_t();
void set_debug(bool value);
@@
-174,6
+176,8
@@
public:
mmu_t* get_mmu() { return mmu; }
state_t* get_state() { return &state; }
unsigned get_xlen() { return xlen; }
mmu_t* get_mmu() { return mmu; }
state_t* get_state() { return &state; }
unsigned get_xlen() { return xlen; }
+ unsigned get_max_xlen() { return max_xlen; }
+ std::string get_isa_string() { return isa_string; }
unsigned get_flen() {
return supports_extension('Q') ? 128 :
supports_extension('D') ? 64 :
unsigned get_flen() {
return supports_extension('Q') ? 128 :
supports_extension('D') ? 64 :
@@
-182,7
+186,11
@@
public:
extension_t* get_extension() { return ext; }
bool supports_extension(unsigned char ext) {
if (ext >= 'a' && ext <= 'z') ext += 'A' - 'a';
extension_t* get_extension() { return ext; }
bool supports_extension(unsigned char ext) {
if (ext >= 'a' && ext <= 'z') ext += 'A' - 'a';
- return ext >= 'A' && ext <= 'Z' && ((isa >> (ext - 'A')) & 1);
+ return ext >= 'A' && ext <= 'Z' && ((state.misa >> (ext - 'A')) & 1);
+ }
+ void check_pc_alignment(reg_t pc) {
+ if (unlikely(pc & 2) && !supports_extension('C'))
+ throw trap_instruction_address_misaligned(pc);
}
reg_t legalize_privilege(reg_t);
void set_privilege(reg_t);
}
reg_t legalize_privilege(reg_t);
void set_privilege(reg_t);
@@
-287,7
+295,7
@@
public:
void trigger_updated();
private:
void trigger_updated();
private:
- sim_t* sim;
+ sim
if
_t* sim;
mmu_t* mmu; // main memory is always accessed via the mmu
extension_t* ext;
disassembler_t* disassembler;
mmu_t* mmu; // main memory is always accessed via the mmu
extension_t* ext;
disassembler_t* disassembler;
@@
-295,7
+303,6
@@
private:
uint32_t id;
unsigned max_xlen;
unsigned xlen;
uint32_t id;
unsigned max_xlen;
unsigned xlen;
- reg_t isa;
reg_t max_isa;
std::string isa_string;
bool histogram_enabled;
reg_t max_isa;
std::string isa_string;
bool histogram_enabled;
@@
-315,7
+322,6
@@
private:
void enter_debug_mode(uint8_t cause);
void enter_debug_mode(uint8_t cause);
- friend class sim_t;
friend class mmu_t;
friend class clint_t;
friend class extension_t;
friend class mmu_t;
friend class clint_t;
friend class extension_t;