1 Commits

Author SHA1 Message Date
aaebeaf023 changes the io_buf 2025-03-11 12:00:31 +01:00
4 changed files with 14 additions and 18 deletions

View File

@ -314,11 +314,16 @@ inline void write_reg_uint32(uint64_t offs, uint32_t& reg, const uint8_t* const
}
struct riscv_hart_common {
riscv_hart_common(){};
~riscv_hart_common(){};
~riscv_hart_common() {
if(io_buf.str().length()) {
CPPLOG(INFO) << "tohost send '" << io_buf.str() << "'";
}
};
std::unordered_map<std::string, uint64_t> symbol_table;
uint64_t entry_address{0};
uint64_t tohost = std::numeric_limits<uint64_t>::max();
uint64_t fromhost = std::numeric_limits<uint64_t>::max();
std::stringstream io_buf;
bool read_elf_file(std::string name, uint8_t expected_elf_class,
std::function<iss::status(uint64_t, uint64_t, const uint8_t* const)> cb) {
@ -378,7 +383,6 @@ struct riscv_hart_common {
return false;
};
iss::status execute_sys_write(arch_if* aif, const std::array<uint64_t, 8>& loaded_payload, unsigned mem_type) {
std::stringstream io_buf;
uint64_t fd = loaded_payload[1];
uint64_t buf_ptr = loaded_payload[2];
uint64_t len = loaded_payload[3];
@ -389,15 +393,13 @@ struct riscv_hart_common {
}
// we disregard the fd and just log to stdout
for(size_t i = 0; i < len; i++) {
if(buf[i] == '\n') {
if(buf[i] == '\n' || buf[i] == '\0') {
CPPLOG(INFO) << "tohost send '" << io_buf.str() << "'";
io_buf.str("");
} else
io_buf << buf[i];
}
if(io_buf.str().length()) {
CPPLOG(INFO) << "tohost send '" << io_buf.str() << "'";
}
// Not sure what the correct return value should be
uint8_t ret_val = 1;
if(fromhost != std::numeric_limits<uint64_t>::max())

View File

@ -1072,11 +1072,9 @@ iss::status riscv_hart_m_p<BASE, FEAT, LOGCAT>::write_mem(phys_addr_t paddr, uns
if(paddr.val == tohost) {
reg_t cur_data = *reinterpret_cast<const reg_t*>(data);
// Extract Device (bits 63:56)
uint8_t device = traits<BASE>::XLEN == 32 ? *reinterpret_cast<uint32_t*>(p.data() + ((tohost + 4) & mem.page_addr_mask)) >> 24
: (cur_data >> 56) & 0xFF;
uint8_t device = traits<BASE>::XLEN == 32 ? 0 : (cur_data >> 56) & 0xFF;
// Extract Command (bits 55:48)
uint8_t command = traits<BASE>::XLEN == 32 ? *reinterpret_cast<uint32_t*>(p.data() + ((tohost + 4) & mem.page_addr_mask)) >> 16
: (cur_data >> 48) & 0xFF;
uint8_t command = traits<BASE>::XLEN == 32 ? 0 : (cur_data >> 48) & 0xFF;
// Extract payload (bits 47:0)
uint64_t payload_addr = cur_data & 0xFFFFFFFFFFFFULL;
if(payload_addr & 1) {

View File

@ -1001,11 +1001,9 @@ template <typename BASE> iss::status riscv_hart_msu_vp<BASE>::write_mem(phys_add
if(paddr.val == tohost) {
reg_t cur_data = *reinterpret_cast<const reg_t*>(data);
// Extract Device (bits 63:56)
uint8_t device = traits<BASE>::XLEN == 32 ? *reinterpret_cast<uint32_t*>(p.data() + ((tohost + 4) & mem.page_addr_mask)) >> 24
: (cur_data >> 56) & 0xFF;
uint8_t device = traits<BASE>::XLEN == 32 ? 0 : (cur_data >> 56) & 0xFF;
// Extract Command (bits 55:48)
uint8_t command = traits<BASE>::XLEN == 32 ? *reinterpret_cast<uint32_t*>(p.data() + ((tohost + 4) & mem.page_addr_mask)) >> 16
: (cur_data >> 48) & 0xFF;
uint8_t command = traits<BASE>::XLEN == 32 ? 0 : (cur_data >> 48) & 0xFF;
// Extract payload (bits 47:0)
uint64_t payload_addr = cur_data & 0xFFFFFFFFFFFFULL;
if(payload_addr & 1) {

View File

@ -1293,11 +1293,9 @@ iss::status riscv_hart_mu_p<BASE, FEAT, LOGCAT>::write_mem(phys_addr_t paddr, un
if(paddr.val == tohost) {
reg_t cur_data = *reinterpret_cast<const reg_t*>(data);
// Extract Device (bits 63:56)
uint8_t device = traits<BASE>::XLEN == 32 ? *reinterpret_cast<uint32_t*>(p.data() + ((tohost + 4) & mem.page_addr_mask)) >> 24
: (cur_data >> 56) & 0xFF;
uint8_t device = traits<BASE>::XLEN == 32 ? 0 : (cur_data >> 56) & 0xFF;
// Extract Command (bits 55:48)
uint8_t command = traits<BASE>::XLEN == 32 ? *reinterpret_cast<uint32_t*>(p.data() + ((tohost + 4) & mem.page_addr_mask)) >> 16
: (cur_data >> 48) & 0xFF;
uint8_t command = traits<BASE>::XLEN == 32 ? 0 : (cur_data >> 48) & 0xFF;
// Extract payload (bits 47:0)
uint64_t payload_addr = cur_data & 0xFFFFFFFFFFFFULL;
if(payload_addr & 1) {