From a1682c1ea29d5ca89fc1552fc02e91f93a1d2c3a Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Thu, 30 Aug 2012 17:36:30 -0700 Subject: [PATCH] new tohost/fromhost semantics --- riscv/htif.cc | 13 ++++++++----- riscv/insns/mtpcr.h | 3 +-- riscv/processor.cc | 3 ++- riscv/processor.h | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/riscv/htif.cc b/riscv/htif.cc index 1be8d87..cffe3ba 100644 --- a/riscv/htif.cc +++ b/riscv/htif.cc @@ -116,17 +116,19 @@ int htif_t::wait_for_packet() sim->mmu->store_uint64((p.addr+i)*HTIF_DATA_ALIGN, p.data[i]); break; case APP_CMD_READ_CONTROL_REG: + case APP_CMD_WRITE_CONTROL_REG: { assert(pcr_coreid < sim->num_cores()); assert(p.data_size == 1); ackpacket.data_size = 1; reg_t pcr = sim->procs[pcr_coreid]->get_pcr(pcr_reg); + if (pcr_reg == PCR_TOHOST) + sim->procs[pcr_coreid]->tohost = 0; memcpy(ackpacket.data, &pcr, sizeof(pcr)); - break; - } - case APP_CMD_WRITE_CONTROL_REG: - assert(pcr_coreid < sim->num_cores()); - assert(p.data_size == 1); + + if (p.cmd == APP_CMD_READ_CONTROL_REG) + break; + if (pcr_reg == PCR_RESET) { reset = p.data[0] & 1; @@ -139,6 +141,7 @@ int htif_t::wait_for_packet() sim->procs[pcr_coreid]->set_pcr(pcr_reg, pcr); } break; + } } send_packet(&ackpacket); diff --git a/riscv/insns/mtpcr.h b/riscv/insns/mtpcr.h index 9b0beba..5cd0134 100644 --- a/riscv/insns/mtpcr.h +++ b/riscv/insns/mtpcr.h @@ -1,5 +1,4 @@ require_supervisor; reg_t val = get_pcr(insn.rtype.rs1); -if (val == 0 || insn.rtype.rs1 != PCR_TOHOST) - set_pcr(insn.rtype.rs1, RS2); +set_pcr(insn.rtype.rs1, RS2); RD = val; diff --git a/riscv/processor.cc b/riscv/processor.cc index 070ec15..e047126 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -271,7 +271,8 @@ void processor_t::set_pcr(int which, reg_t val) vecbanks_count = __builtin_popcountll(vecbanks); break; case PCR_TOHOST: - tohost = val; + if (tohost == 0) + tohost = val; break; case PCR_FROMHOST: fromhost = val; diff --git a/riscv/processor.h b/riscv/processor.h index 927f06c..e9c8be3 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -87,6 +87,7 @@ private: friend class sim_t; friend class mmu_t; + friend class htif_t; #include "dispatch.h" }; -- 2.30.2