Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix epc[0] is always 0, rather than being cleared only at the time of use. #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/main/scala/nutcore/backend/fu/CSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{

// User Trap Handling
// MaskedRegMap(Uscratch, uscratch),
// MaskedRegMap(Uepc, uepc),
//Ensure that the value of epc[0] is 0 at the root, rather than clearing it at the time of use
//MaskedRegMap(Uepc, uepc, wfn = (value: UInt) => (value & ~1.U(64.W))),

// MaskedRegMap(Ucause, ucause),
// MaskedRegMap(Utval, utval),
// MaskedRegMap(Uip, uip),
Expand All @@ -411,7 +413,9 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{

// Supervisor Trap Handling
MaskedRegMap(Sscratch, sscratch),
MaskedRegMap(Sepc, sepc),
//Ensure that the value of epc[0] is 0 at the root, rather than clearing it at the time of use
MaskedRegMap(Sepc, sepc, wfn = (value: UInt) => (value & ~1.U(64.W))),

MaskedRegMap(Scause, scause),
MaskedRegMap(Stval, stval),
MaskedRegMap(Sip, mip.asUInt, sipMask, MaskedRegMap.Unwritable, sipMask),
Expand All @@ -437,7 +441,10 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{

// Machine Trap Handling
MaskedRegMap(Mscratch, mscratch),
MaskedRegMap(Mepc, mepc),
//MaskedRegMap(Mepc, mepc),
//Ensure that the value of epc[0] is 0 at the root, rather than clearing it at the time of use
MaskedRegMap(Mepc, mepc, wfn = (value: UInt) => (value & ~1.U(64.W))),

MaskedRegMap(Mcause, mcause),
MaskedRegMap(Mtval, mtval),
MaskedRegMap(Mip, mip.asUInt, 0.U, MaskedRegMap.Unwritable),
Expand Down Expand Up @@ -668,7 +675,7 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{
mstatusNew.mpp := ModeU
mstatus := mstatusNew.asUInt
lr := false.B
retTarget := mepc(VAddrBits-1, 0)
retTarget := mepc
}

when (valid && isSret) {
Expand All @@ -681,7 +688,7 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{
mstatusNew.spp := ModeU
mstatus := mstatusNew.asUInt
lr := false.B
retTarget := sepc(VAddrBits-1, 0)
retTarget := sepc
}

when (valid && isUret) {
Expand All @@ -692,7 +699,7 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{
priviledgeMode := ModeU
mstatusNew.pie.u := true.B
mstatus := mstatusNew.asUInt
retTarget := uepc(VAddrBits-1, 0)
retTarget := uepc
}

when (raiseExceptionIntr) {
Expand Down Expand Up @@ -946,3 +953,4 @@ class CSR(implicit val p: NutCoreConfig) extends NutCoreModule with HasCSRConst{
}
}
}