Skip to content

Commit 6f4116d

Browse files
jerryz123abejgonzalez
authored andcommitted
Move isa property to a field of processor_t, not sim_t
This incidentally makes it easier to support heterogeneous-hart configs in the future
1 parent c536aff commit 6f4116d

File tree

7 files changed

+33
-33
lines changed

7 files changed

+33
-33
lines changed

riscv/dts.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz,
1616
const cfg_t* cfg,
17-
const isa_parser_t* isa,
1817
std::vector<std::pair<reg_t, abstract_mem_t*>> mems,
1918
std::string device_nodes)
2019
{
@@ -23,6 +22,7 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz,
2322
const char* bootargs = cfg->bootargs;
2423
reg_t pmpregions = cfg->pmpregions;
2524
reg_t pmpgranularity = cfg->pmpgranularity;
25+
isa_parser_t isa(cfg->isa, cfg->priv);
2626

2727
std::stringstream s;
2828
s << std::dec <<
@@ -63,8 +63,8 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz,
6363
" reg = <" << cfg->hartids[i] << ">;\n"
6464
" status = \"okay\";\n"
6565
" compatible = \"riscv\";\n"
66-
" riscv,isa = \"" << isa->get_isa_string() << "\";\n"
67-
" mmu-type = \"riscv," << (isa->get_max_xlen() <= 32 ? "sv32" : "sv57") << "\";\n"
66+
" riscv,isa = \"" << isa.get_isa_string() << "\";\n"
67+
" mmu-type = \"riscv," << (isa.get_max_xlen() <= 32 ? "sv32" : "sv57") << "\";\n"
6868
" riscv,pmpregions = <" << pmpregions << ">;\n"
6969
" riscv,pmpgranularity = <" << pmpgranularity << ">;\n"
7070
" clock-frequency = <" << cpu_hz << ">;\n"

riscv/dts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz,
1010
const cfg_t* cfg,
11-
const isa_parser_t* isa,
1211
std::vector<std::pair<reg_t, abstract_mem_t*>> mems,
1312
std::string device_nodes);
1413

riscv/processor.cc

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,50 @@
3030
#undef STATE
3131
#define STATE state
3232

33-
processor_t::processor_t(const isa_parser_t *isa, const cfg_t *cfg,
33+
processor_t::processor_t(const char* isa_str, const char* priv_str,
34+
const cfg_t *cfg,
3435
simif_t* sim, uint32_t id, bool halt_on_reset,
3536
FILE* log_file, std::ostream& sout_)
36-
: debug(false), halt_request(HR_NONE), isa(isa), cfg(cfg), sim(sim), id(id), xlen(0),
37+
: debug(false), halt_request(HR_NONE), isa(isa_str, priv_str), cfg(cfg), sim(sim), id(id), xlen(0),
3738
histogram_enabled(false), log_commits_enabled(false),
3839
log_file(log_file), sout_(sout_.rdbuf()), halt_on_reset(halt_on_reset),
3940
in_wfi(false), check_triggers_icount(false),
40-
impl_table(256, false), extension_enable_table(isa->get_extension_table()),
41+
impl_table(256, false), extension_enable_table(isa.get_extension_table()),
4142
last_pc(1), executions(1), TM(cfg->trigger_count)
4243
{
4344
VU.p = this;
4445
TM.proc = this;
4546

4647
#ifndef HAVE_INT128
47-
if (isa->has_any_vector()) {
48+
if (isa.has_any_vector()) {
4849
fprintf(stderr, "V extension is not supported on platforms without __int128 type\n");
4950
abort();
5051
}
5152

52-
if (isa->extension_enabled(EXT_ZACAS) && isa->get_max_xlen() == 64) {
53+
if (isa.extension_enabled(EXT_ZACAS) && isa.get_max_xlen() == 64) {
5354
fprintf(stderr, "Zacas extension is not supported on 64-bit platforms without __int128 type\n");
5455
abort();
5556
}
5657
#endif
5758

58-
VU.VLEN = isa->get_vlen();
59-
VU.ELEN = isa->get_elen();
60-
VU.vlenb = isa->get_vlen() / 8;
59+
VU.VLEN = isa.get_vlen();
60+
VU.ELEN = isa.get_elen();
61+
VU.vlenb = isa.get_vlen() / 8;
6162
VU.vstart_alu = 0;
6263

6364
register_base_instructions();
6465
mmu = new mmu_t(sim, cfg->endianness, this);
6566

66-
disassembler = new disassembler_t(isa);
67-
for (auto e : isa->get_extensions())
67+
disassembler = new disassembler_t(&isa);
68+
for (auto e : isa.get_extensions())
6869
register_extension(find_extension(e.c_str())());
6970

7071
set_pmp_granularity(cfg->pmpgranularity);
7172
set_pmp_num(cfg->pmpregions);
7273

73-
if (isa->get_max_xlen() == 32)
74+
if (isa.get_max_xlen() == 32)
7475
set_mmu_capability(IMPL_MMU_SV32);
75-
else if (isa->get_max_xlen() == 64)
76+
else if (isa.get_max_xlen() == 64)
7677
set_mmu_capability(IMPL_MMU_SV57);
7778

7879
set_impl(IMPL_MMU_ASID, true);
@@ -575,8 +576,8 @@ void processor_t::enable_log_commits()
575576

576577
void processor_t::reset()
577578
{
578-
xlen = isa->get_max_xlen();
579-
state.reset(this, isa->get_max_isa());
579+
xlen = isa.get_max_xlen();
580+
state.reset(this, isa.get_max_isa());
580581
state.dcsr->halt = halt_on_reset;
581582
halt_on_reset = false;
582583
if (any_vector_extensions())
@@ -724,7 +725,7 @@ void processor_t::take_interrupt(reg_t pending_interrupts)
724725
abort();
725726

726727
if (check_triggers_icount) TM.detect_icount_match();
727-
throw trap_t(((reg_t)1 << (isa->get_max_xlen() - 1)) | ctz(enabled_interrupts));
728+
throw trap_t(((reg_t)1 << (isa.get_max_xlen() - 1)) | ctz(enabled_interrupts));
728729
}
729730
}
730731

@@ -796,7 +797,7 @@ void processor_t::debug_output_log(std::stringstream *s)
796797

797798
void processor_t::take_trap(trap_t& t, reg_t epc)
798799
{
799-
unsigned max_xlen = isa->get_max_xlen();
800+
unsigned max_xlen = isa.get_max_xlen();
800801

801802
if (debug) {
802803
std::stringstream s; // first put everything in a string, later send it to output
@@ -974,7 +975,7 @@ void processor_t::disasm(insn_t insn)
974975
<< ": Executed " << executions << " times" << std::endl;
975976
}
976977

977-
unsigned max_xlen = isa->get_max_xlen();
978+
unsigned max_xlen = isa.get_max_xlen();
978979

979980
s << "core " << std::dec << std::setfill(' ') << std::setw(3) << id
980981
<< std::hex << ": 0x" << std::setfill('0') << std::setw(max_xlen / 4)
@@ -993,7 +994,7 @@ void processor_t::disasm(insn_t insn)
993994

994995
int processor_t::paddr_bits()
995996
{
996-
unsigned max_xlen = isa->get_max_xlen();
997+
unsigned max_xlen = isa.get_max_xlen();
997998
assert(xlen == max_xlen);
998999
return max_xlen == 64 ? 50 : 34;
9991000
}
@@ -1120,7 +1121,7 @@ void processor_t::register_base_instructions()
11201121
// add overlapping instructions first, in order
11211122
#define DECLARE_OVERLAP_INSN(name, ext) \
11221123
name##_overlapping = true; \
1123-
if (isa->extension_enabled(ext)) \
1124+
if (isa.extension_enabled(ext)) \
11241125
register_base_insn((insn_desc_t) { \
11251126
name##_match, \
11261127
name##_mask, \

riscv/processor.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,13 @@ class opcode_cache_entry_t {
236236
class processor_t : public abstract_device_t
237237
{
238238
public:
239-
processor_t(const isa_parser_t *isa, const cfg_t* cfg,
239+
processor_t(const char* isa_str, const char* priv_str,
240+
const cfg_t* cfg,
240241
simif_t* sim, uint32_t id, bool halt_on_reset,
241242
FILE *log_file, std::ostream& sout_); // because of command line option --log and -s we need both
242243
~processor_t();
243244

244-
const isa_parser_t &get_isa() { return *isa; }
245+
const isa_parser_t &get_isa() { return isa; }
245246
const cfg_t &get_cfg() { return *cfg; }
246247

247248
void set_debug(bool value);
@@ -303,7 +304,7 @@ class processor_t : public abstract_device_t
303304
void set_extension_enable(unsigned char ext, bool enable) {
304305
assert(!extension_assumed_const[ext]);
305306
extension_dynamic[ext] = true;
306-
extension_enable_table[ext] = enable && isa->extension_enabled(ext);
307+
extension_enable_table[ext] = enable && isa.extension_enabled(ext);
307308
}
308309
void set_impl(uint8_t impl, bool val) { impl_table[impl] = val; }
309310
bool supports_impl(uint8_t impl) const {
@@ -362,7 +363,7 @@ class processor_t : public abstract_device_t
362363
void check_if_lpad_required();
363364

364365
private:
365-
const isa_parser_t * const isa;
366+
const isa_parser_t isa;
366367
const cfg_t * const cfg;
367368

368369
simif_t* sim;

riscv/sim.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ sim_t::sim_t(const cfg_t *cfg, bool halted,
4646
bool socket_enabled,
4747
FILE *cmd_file) // needed for command line option --cmd
4848
: htif_t(args),
49-
isa(cfg->isa, cfg->priv),
5049
cfg(cfg),
5150
mems(mems),
5251
procs(std::max(cfg->nprocs(), size_t(1))),
@@ -99,7 +98,8 @@ sim_t::sim_t(const cfg_t *cfg, bool halted,
9998
debug_mmu = new mmu_t(this, cfg->endianness, NULL);
10099

101100
for (size_t i = 0; i < cfg->nprocs(); i++) {
102-
procs[i] = new processor_t(&isa, cfg, this, cfg->hartids[i], halted,
101+
procs[i] = new processor_t(cfg->isa, cfg->priv,
102+
cfg, this, cfg->hartids[i], halted,
103103
log_file.get(), sout_);
104104
harts[cfg->hartids[i]] = procs[i];
105105
}
@@ -141,7 +141,7 @@ sim_t::sim_t(const cfg_t *cfg, bool halted,
141141
const std::vector<std::string>& sargs = factory_sargs.second;
142142
device_nodes.append(factory->generate_dts(this, sargs));
143143
}
144-
dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, cfg, &isa, mems, device_nodes);
144+
dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, cfg, mems, device_nodes);
145145
dtb = dts_compile(dts);
146146
}
147147

@@ -253,7 +253,7 @@ int sim_t::run()
253253
if (!debug && log)
254254
set_procs_debug(true);
255255

256-
htif_t::set_expected_xlen(isa.get_max_xlen());
256+
htif_t::set_expected_xlen(harts[0]->get_isa().get_max_xlen());
257257

258258
// htif_t::run() will repeatedly call back into sim_t::idle(), each
259259
// invocation of which will advance target time

riscv/sim.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class sim_t : public htif_t, public simif_t
6969
static const size_t CPU_HZ = 1000000000; // 1GHz CPU
7070

7171
private:
72-
isa_parser_t isa;
7372
const cfg_t * const cfg;
7473
std::vector<std::pair<reg_t, abstract_mem_t*>> mems;
7574
std::vector<processor_t*> procs;

spike_main/spike-log-parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(int UNUSED argc, char** argv)
3131
cfg_t cfg;
3232

3333
isa_parser_t isa(isa_string, DEFAULT_PRIV);
34-
processor_t p(&isa, &cfg, 0, 0, false, nullptr, cerr);
34+
processor_t p(isa_string, DEFAULT_PRIV, &cfg, 0, 0, false, nullptr, cerr);
3535
if (extension) {
3636
p.register_extension(extension());
3737
}

0 commit comments

Comments
 (0)