Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement  tsr, tw, tvm
(tw as dummy)
  • Loading branch information
Dolu1990 committed May 30, 2024
1 parent e5f3abb commit ed2df82
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/main/scala/naxriscv/execute/EnvCallPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,32 @@ class EnvCallPlugin(val euId : String)(var rescheduleAt : Int = 0) extends Plugi
setup.reschedule.cause.assignDontCare()

val xretPriv = Frontend.MICRO_OP(29 downto 28).asUInt
val trap = False
when(XRET){
setup.reschedule.cause := CAUSE_XRET //the reschedule cause isn't the final value which will end up into XCAUSE csr
setup.reschedule.tval(1 downto 0) := xretPriv.asBits
when(xretPriv > priv.getPrivilege()){
setup.reschedule.cause := CSR.MCAUSE_ENUM.ILLEGAL_INSTRUCTION
setup.reschedule.reason := ScheduleReason.TRAP
setup.reschedule.skipCommit := True
}
trap setWhen (xretPriv > priv.getPrivilege())
if(priv.p.withSupervisor) trap setWhen (priv.logic.machine.mstatus.tsr && priv.getPrivilege() === 1 && xretPriv === 1)
}
when(EBREAK){
setup.reschedule.cause := CSR.MCAUSE_ENUM.BREAKPOINT
}
when(ECALL){
setup.reschedule.cause := CSR.MCAUSE_ENUM.ECALL_MACHINE //the reschedule cause isn't the final value which will end up into XCAUSE csr
}

when(FENCE_I || FENCE_VMA || FLUSH_DATA){
setup.reschedule.cause := CAUSE_FLUSH
}
if(priv.p.withSupervisor) when(FENCE_VMA){
trap setWhen(priv.getPrivilege() === 1 && priv.logic.machine.mstatus.tvm)
trap setWhen(priv.getPrivilege() === 0)
}

when(trap){
setup.reschedule.cause := CSR.MCAUSE_ENUM.ILLEGAL_INSTRUCTION
setup.reschedule.reason := ScheduleReason.TRAP
setup.reschedule.skipCommit := True
}

//Handle FENCE.I and FENCE.VMA
val flushes = new StateMachine{
Expand Down
8 changes: 6 additions & 2 deletions src/main/scala/naxriscv/misc/MmuPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,12 @@ class MmuPlugin(var spec : MmuSpec,
// csr.readWriteRam(CSR.SATP) not suported by writeCancel

csr.onDecode(CSR.SATP){
csr.onDecodeFlushPipeline()
setup.invalidatePort.cmd.valid := True
when(priv.logic.machine.mstatus.tvm && priv.getPrivilege() === 1){
csr.onDecodeTrap()
} otherwise {
csr.onDecodeFlushPipeline()
setup.invalidatePort.cmd.valid := True
}
}

ram.allocationLock.release()
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/naxriscv/misc/PrivilegedPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ class PrivilegedPlugin(var p : PrivilegedConfig) extends Plugin with PrivilegedS
val sd = False
if(RVF) setup.isFpuEnabled setWhen(fs =/= 0)
if(withFs) sd setWhen(fs === 3)

val tsr, tw, tvm = p.withSupervisor generate RegInit(False)
}
val mip = new Area{
val meip = RegNext(io.int.machine.external) init(False)
Expand Down Expand Up @@ -432,6 +434,7 @@ class PrivilegedPlugin(var p : PrivilegedConfig) extends Plugin with PrivilegedS
csr.read (CSR.MSTATUS, XLEN-1 -> mstatus.sd)
csr.read (CSR.MIP, 11 -> mip.meip, 7 -> mip.mtip, 3 -> mip.msip)
csr.readWrite(CSR.MIE, 11 -> mie.meie, 7 -> mie.mtie, 3 -> mie.msie)
if(p.withSupervisor) csr.readWrite(CSR.MSTATUS, 22 -> mstatus.tsr, 21 -> mstatus.tw, 20 -> mstatus.tvm)


if(withFs) csr.readWrite(CSR.MSTATUS, 13 -> mstatus.fs)
Expand Down

0 comments on commit ed2df82

Please sign in to comment.