Merge pull request #1171 from freechipsproject/fix-msb-check
Enforce physical-address canonicalization
This commit is contained in:
commit
206892899f
@ -744,11 +744,8 @@ class Rocket(implicit p: Parameters) extends CoreModule()(p)
|
|||||||
def encodeVirtualAddress(a0: UInt, ea: UInt) = if (vaddrBitsExtended == vaddrBits) ea else {
|
def encodeVirtualAddress(a0: UInt, ea: UInt) = if (vaddrBitsExtended == vaddrBits) ea else {
|
||||||
// efficient means to compress 64-bit VA into vaddrBits+1 bits
|
// efficient means to compress 64-bit VA into vaddrBits+1 bits
|
||||||
// (VA is bad if VA(vaddrBits) != VA(vaddrBits-1))
|
// (VA is bad if VA(vaddrBits) != VA(vaddrBits-1))
|
||||||
val a = a0 >> vaddrBits-1
|
val a = a0.asSInt >> vaddrBits
|
||||||
val e = ea(vaddrBits,vaddrBits-1).asSInt
|
val msb = Mux(a === 0.S || a === -1.S, ea(vaddrBits), !ea(vaddrBits-1))
|
||||||
val msb =
|
|
||||||
Mux(a === UInt(0) || a === UInt(1), e =/= SInt(0),
|
|
||||||
Mux(a.asSInt === SInt(-1) || a.asSInt === SInt(-2), e === SInt(-1), e(0)))
|
|
||||||
Cat(msb, ea(vaddrBits-1,0))
|
Cat(msb, ea(vaddrBits-1,0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +98,11 @@ class TLB(instruction: Boolean, lgMaxSize: Int, nEntries: Int)(implicit edge: TL
|
|||||||
val vm_enabled = Bool(usingVM) && io.ptw.ptbr.mode(io.ptw.ptbr.mode.getWidth-1) && priv_uses_vm && !io.req.bits.passthrough
|
val vm_enabled = Bool(usingVM) && io.ptw.ptbr.mode(io.ptw.ptbr.mode.getWidth-1) && priv_uses_vm && !io.req.bits.passthrough
|
||||||
|
|
||||||
// share a single physical memory attribute checker (unshare if critical path)
|
// share a single physical memory attribute checker (unshare if critical path)
|
||||||
val vpn = io.req.bits.vaddr(vaddrBits-1, pgIdxBits)
|
|
||||||
val refill_ppn = io.ptw.resp.bits.pte.ppn(ppnBits-1, 0)
|
val refill_ppn = io.ptw.resp.bits.pte.ppn(ppnBits-1, 0)
|
||||||
val do_refill = Bool(usingVM) && io.ptw.resp.valid
|
val do_refill = Bool(usingVM) && io.ptw.resp.valid
|
||||||
val invalidate_refill = state.isOneOf(s_request /* don't care */, s_wait_invalidate)
|
val invalidate_refill = state.isOneOf(s_request /* don't care */, s_wait_invalidate)
|
||||||
val mpu_ppn = Mux(do_refill, refill_ppn,
|
val mpu_ppn = Mux(do_refill, refill_ppn,
|
||||||
Mux(vm_enabled, entries.last.ppn, vpn))
|
Mux(vm_enabled, entries.last.ppn, io.req.bits.vaddr >> pgIdxBits))
|
||||||
val mpu_physaddr = Cat(mpu_ppn, io.req.bits.vaddr(pgIdxBits-1, 0))
|
val mpu_physaddr = Cat(mpu_ppn, io.req.bits.vaddr(pgIdxBits-1, 0))
|
||||||
val pmp = Module(new PMPChecker(lgMaxSize))
|
val pmp = Module(new PMPChecker(lgMaxSize))
|
||||||
pmp.io.addr := mpu_physaddr
|
pmp.io.addr := mpu_physaddr
|
||||||
@ -122,6 +121,7 @@ class TLB(instruction: Boolean, lgMaxSize: Int, nEntries: Int)(implicit edge: TL
|
|||||||
val prot_x = fastCheck(_.executable) && pmp.io.x
|
val prot_x = fastCheck(_.executable) && pmp.io.x
|
||||||
val prot_eff = fastCheck(Seq(RegionType.PUT_EFFECTS, RegionType.GET_EFFECTS) contains _.regionType)
|
val prot_eff = fastCheck(Seq(RegionType.PUT_EFFECTS, RegionType.GET_EFFECTS) contains _.regionType)
|
||||||
|
|
||||||
|
val vpn = io.req.bits.vaddr(vaddrBits-1, pgIdxBits)
|
||||||
val lookup_tag = Cat(io.ptw.ptbr.asid, vpn)
|
val lookup_tag = Cat(io.ptw.ptbr.asid, vpn)
|
||||||
val hitsVec = (0 until totalEntries).map { i => if (!usingVM) false.B else vm_enabled && {
|
val hitsVec = (0 until totalEntries).map { i => if (!usingVM) false.B else vm_enabled && {
|
||||||
var tagMatch = valid(i)
|
var tagMatch = valid(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user