bool processor_t::load(reg_t addr, size_t len, uint8_t* bytes)
{
- try {
- auto res = get_csr(addr / (max_xlen / 8));
- memcpy(bytes, &res, len);
- return true;
- } catch (trap_illegal_instruction& t) {
- return false;
- }
+ return false;
}
bool processor_t::store(reg_t addr, size_t len, const uint8_t* bytes)
{
- try {
- reg_t value = 0;
- memcpy(&value, bytes, len);
- set_csr(addr / (max_xlen / 8), value);
- return true;
- } catch (trap_illegal_instruction& t) {
- return false;
+ switch (addr)
+ {
+ case 0:
+ state.mip &= ~MIP_MSIP;
+ if (bytes[0] & 1)
+ state.mip |= MIP_MSIP;
+ return true;
+
+ default:
+ return false;
}
}
void sim_t::make_config_string()
{
- reg_t boot_rom_addr = DEFAULT_RSTVEC;
- reg_t boot_rom_size = 0x2000;
- reg_t rtc_addr = boot_rom_addr + boot_rom_size;
+ reg_t rtc_addr = EXT_IO_BASE;
bus.add_device(rtc_addr, rtc.get());
+ const int align = 0x1000;
+ reg_t cpu_addr = rtc_addr + ((rtc->size() - 1) / align + 1) * align;
+ reg_t cpu_size = align;
+
uint32_t reset_vec[8] = {
0x297 + DRAM_BASE - DEFAULT_RSTVEC, // reset vector
0x00028067, // jump straight to DRAM_BASE
0, // config string pointer
0, 0, 0, 0 // trap vector
};
- reset_vec[3] = boot_rom_addr + sizeof(reset_vec); // config string pointer
+ reset_vec[3] = DEFAULT_RSTVEC + sizeof(reset_vec); // config string pointer
std::vector<char> rom((char*)reset_vec, (char*)reset_vec + sizeof(reset_vec));
" " << "0 {\n" << // hart 0 on core i
" isa " << procs[i]->isa_string << ";\n"
" timecmp 0x" << (rtc_addr + 8*(1+i)) << ";\n"
+ " ipi 0x" << cpu_addr << ";\n"
" };\n"
" };\n";
+ bus.add_device(cpu_addr, procs[i]);
+ cpu_addr += cpu_size;
}
s << "};\n";
config_string = s.str();
rom.insert(rom.end(), config_string.begin(), config_string.end());
- assert(rom.size() < boot_rom_size);
- rom.resize(boot_rom_size);
+ rom.resize((rom.size() / align + 1) * align);
boot_rom.reset(new rom_device_t(rom));
- bus.add_device(boot_rom_addr, boot_rom.get());
+ bus.add_device(DEFAULT_RSTVEC, boot_rom.get());
}