This commit is contained in:
John Terrell 2023-04-25 16:45:58 -07:00
parent b82a6a9a79
commit 96b36317b3
Signed by untrusted user who does not match committer: johnt
GPG Key ID: 2E424258DD3731F4
2 changed files with 27 additions and 26 deletions

View File

@ -150,8 +150,8 @@ endinstance
interface MachineStatusIfc#(numeric type xlen); interface MachineStatusIfc#(numeric type xlen);
method Action beginTrap(RVPrivilegeLevel currentPriv); method Action beginTrap(RVPrivilegeLevel currentPriv);
interface Get#(Bit#(xlen)) getMachineStatus; method Bit#(xlen) get;
interface Put#(Bit#(xlen)) putMachineStatus; method Action put(Bit#(xlen) newMachineStatus);
endinterface endinterface
module mkMachineStatus#(IsaCfg#(xlen) cfg)(MachineStatusIfc#(xlen)) module mkMachineStatus#(IsaCfg#(xlen) cfg)(MachineStatusIfc#(xlen))
@ -172,30 +172,31 @@ module mkMachineStatus#(IsaCfg#(xlen) cfg)(MachineStatusIfc#(xlen))
mstatus <= mstatus_pack(mstatus_); mstatus <= mstatus_pack(mstatus_);
endmethod endmethod
interface Get getMachineStatus = toGet(mstatus); method Bit#(xlen) get;
interface Put putMachineStatus; return mstatus;
method Action put(Bit#(xlen) newValue); endmethod
//
// Only MPP, MIE, and MIE are writable.
//
MachineStatus mstatus_ = mstatus_unpack(mstatus);
MachineStatus value = mstatus_unpack(newValue);
if (cfg.extS) begin method Action put(Bit#(xlen) newMachineStatus);
mstatus_.mpp = value.mpp; //
end else begin // Only MPP, MIE, and MIE are writable.
// Supervisor mode not supported, ensure only USER and MACHINE //
// mode are set in MPP. MachineStatus mstatus_ = mstatus_unpack(mstatus);
RVPrivilegeLevel requestedMPP = value.mpp; MachineStatus value = mstatus_unpack(newMachineStatus);
if (requestedMPP == priv_USER || requestedMPP == priv_MACHINE) begin
mstatus_.mpp = requestedMPP; if (cfg.extS) begin
end mstatus_.mpp = value.mpp;
end else begin
// Supervisor mode not supported, ensure only USER and MACHINE
// mode are set in MPP.
RVPrivilegeLevel requestedMPP = value.mpp;
if (requestedMPP == priv_USER || requestedMPP == priv_MACHINE) begin
mstatus_.mpp = requestedMPP;
end end
end
mstatus_.mpie = value.mpie; mstatus_.mpie = value.mpie;
mstatus_.mie = value.mie; mstatus_.mie = value.mie;
mstatus <= mstatus_pack(mstatus_); mstatus <= mstatus_pack(mstatus_);
endmethod endmethod
endinterface
endmodule endmodule

View File

@ -180,7 +180,7 @@ module mkCsrFile#(IsaCfg#(xlen) cfg)(CsrFileIfc#(xlen))
csr_MIDELEG: result.value = mideleg; csr_MIDELEG: result.value = mideleg;
csr_MEDELEG: result.value = medeleg; csr_MEDELEG: result.value = medeleg;
csr_MSTATUS: result.value <- mstatus.getMachineStatus.get; csr_MSTATUS: result.value = mstatus.get;
csr_MCYCLE, csr_CYCLE: begin csr_MCYCLE, csr_CYCLE: begin
result.value = mcycle; result.value = mcycle;
@ -226,7 +226,7 @@ module mkCsrFile#(IsaCfg#(xlen) cfg)(CsrFileIfc#(xlen))
// No-Op // No-Op
end end
csr_MSCRATCH: mscratch <= value; csr_MSCRATCH: mscratch <= value;
csr_MSTATUS: mstatus.putMachineStatus.put(value); csr_MSTATUS: mstatus.put(value);
csr_MTVAL: mtval <= value; csr_MTVAL: mtval <= value;
csr_MTVEC: mtvec <= value; csr_MTVEC: mtvec <= value;
csr_MIE: mie <= value; csr_MIE: mie <= value;