Skip to content

Commit 3f03196

Browse files
authored
fix(TLB): fix two issues in genVpn (#4647)
1. Level: Previously, the code always used the smaller value between s1.stage and s2.stage, regardless of the virtualization stage. In fact, only the allStage case should compare both stages; other cases should determine the level independently based on their respective stage. 2. VPN: Previously, only the allStage case checked the level to decide whether to concatenate the lower bits of the VPN. However, in reality, other cases also need to perform VPN concatenation based on the level.
1 parent 6a3636f commit 3f03196

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/scala/xiangshan/cache/mmu/MMUBundle.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,15 +1291,24 @@ class PtwRespS2(implicit p: Parameters) extends PtwBundle {
12911291
}
12921292

12931293
def getVpn(vpn: UInt): UInt = {
1294-
val level = s1.entry.level.getOrElse(0.U) min s2.entry.level.getOrElse(0.U)
1294+
val level = MuxLookup(s2xlate, 0.U)(Seq(
1295+
onlyStage1 -> s1.entry.level.getOrElse(0.U),
1296+
onlyStage2 -> s2.entry.level.getOrElse(0.U),
1297+
allStage -> (s1.entry.level.getOrElse(0.U) min s2.entry.level.getOrElse(0.U)),
1298+
noS2xlate -> s1.entry.level.getOrElse(0.U)
1299+
))
12951300
val s1tag = Cat(s1.entry.tag, OHToUInt(s1.pteidx))
12961301
val s1_vpn = MuxLookup(level, s1tag)(Seq(
12971302
3.U -> Cat(s1.entry.tag(sectorvpnLen - 1, vpnnLen * 3 - sectortlbwidth), vpn(vpnnLen * 3 - 1, 0)),
12981303
2.U -> Cat(s1.entry.tag(sectorvpnLen - 1, vpnnLen * 2 - sectortlbwidth), vpn(vpnnLen * 2 - 1, 0)),
12991304
1.U -> Cat(s1.entry.tag(sectorvpnLen - 1, vpnnLen - sectortlbwidth), vpn(vpnnLen - 1, 0)))
13001305
)
1301-
val s2_vpn = s2.entry.tag
1302-
Mux(s2xlate === onlyStage2, s2_vpn, Mux(s2xlate === allStage, s1_vpn, s1tag))
1306+
val s2_vpn = MuxLookup(level, s2.entry.tag)(Seq(
1307+
3.U -> Cat(s2.entry.tag(gvpnLen - 1, vpnnLen * 3), vpn(vpnnLen * 3 - 1, 0)),
1308+
2.U -> Cat(s2.entry.tag(gvpnLen - 1, vpnnLen * 2), vpn(vpnnLen * 2 - 1, 0)),
1309+
1.U -> Cat(s2.entry.tag(gvpnLen - 1, vpnnLen), vpn(vpnnLen - 1, 0)))
1310+
)
1311+
Mux(s2xlate === onlyStage2, s2_vpn, s1_vpn)
13031312
}
13041313

13051314
def hit(vpn: UInt, asid: UInt, vasid: UInt, vmid: UInt, allType: Boolean = false, ignoreAsid: Boolean = false): Bool = {

0 commit comments

Comments
 (0)