Add cachless dBus IBus access right checks

This commit is contained in:
Dolu1990 2019-03-18 12:52:22 +01:00
parent c490838202
commit 001ca45c57
2 changed files with 18 additions and 11 deletions

View File

@ -214,6 +214,7 @@ class DBusSimplePlugin(catchAddressMisaligned : Boolean = false,
object MEMORY_READ_DATA extends Stageable(Bits(32 bits)) object MEMORY_READ_DATA extends Stageable(Bits(32 bits))
object MEMORY_ADDRESS_LOW extends Stageable(UInt(2 bits)) object MEMORY_ADDRESS_LOW extends Stageable(UInt(2 bits))
object ALIGNEMENT_FAULT extends Stageable(Bool) object ALIGNEMENT_FAULT extends Stageable(Bool)
object MMU_FAULT extends Stageable(Bool)
object MMU_RSP extends Stageable(MemoryTranslatorRsp()) object MMU_RSP extends Stageable(MemoryTranslatorRsp())
var memoryExceptionPort : Flow[ExceptionCause] = null var memoryExceptionPort : Flow[ExceptionCause] = null
@ -285,6 +286,7 @@ class DBusSimplePlugin(catchAddressMisaligned : Boolean = false,
val cmdStage = if(emitCmdInMemoryStage) memory else execute val cmdStage = if(emitCmdInMemoryStage) memory else execute
cmdStage plug new Area{ cmdStage plug new Area{
import cmdStage._ import cmdStage._
val privilegeService = pipeline.serviceElse(classOf[PrivilegeService], PrivilegeServiceDefault())
val cmdSent = if(rspStage == execute) RegInit(False) setWhen(dBus.cmd.fire) clearWhen(!execute.arbitration.isStuck) else False val cmdSent = if(rspStage == execute) RegInit(False) setWhen(dBus.cmd.fire) clearWhen(!execute.arbitration.isStuck) else False
@ -295,7 +297,11 @@ class DBusSimplePlugin(catchAddressMisaligned : Boolean = false,
False False
} }
dBus.cmd.valid := arbitration.isValid && input(MEMORY_ENABLE) && !arbitration.isStuckByOthers && !arbitration.isFlushed && !input(ALIGNEMENT_FAULT) && !cmdSent
val skipCmd = False
skipCmd setWhen(input(ALIGNEMENT_FAULT))
dBus.cmd.valid := arbitration.isValid && input(MEMORY_ENABLE) && !arbitration.isStuckByOthers && !arbitration.isFlushed && !skipCmd && !cmdSent
dBus.cmd.wr := input(INSTRUCTION)(5) dBus.cmd.wr := input(INSTRUCTION)(5)
dBus.cmd.size := input(INSTRUCTION)(13 downto 12).asUInt dBus.cmd.size := input(INSTRUCTION)(13 downto 12).asUInt
dBus.cmd.payload.data := dBus.cmd.size.mux ( dBus.cmd.payload.data := dBus.cmd.size.mux (
@ -303,7 +309,7 @@ class DBusSimplePlugin(catchAddressMisaligned : Boolean = false,
U(1) -> input(RS2)(15 downto 0) ## input(RS2)(15 downto 0), U(1) -> input(RS2)(15 downto 0) ## input(RS2)(15 downto 0),
default -> input(RS2)(31 downto 0) default -> input(RS2)(31 downto 0)
) )
when(arbitration.isValid && input(MEMORY_ENABLE) && !dBus.cmd.ready && !input(ALIGNEMENT_FAULT) && !cmdSent){ when(arbitration.isValid && input(MEMORY_ENABLE) && !dBus.cmd.ready && !skipCmd && !cmdSent){
arbitration.haltItself := True arbitration.haltItself := True
} }
@ -326,11 +332,9 @@ class DBusSimplePlugin(catchAddressMisaligned : Boolean = false,
mmuBus.cmd.bypassTranslation := False mmuBus.cmd.bypassTranslation := False
dBus.cmd.address := mmuBus.rsp.physicalAddress dBus.cmd.address := mmuBus.rsp.physicalAddress
//do not emit memory request if MMU miss //do not emit memory request if MMU refilling
when(mmuBus.cmd.isValid && (mmuBus.rsp.exception || mmuBus.rsp.refilling)){ insert(MMU_FAULT) := input(MMU_RSP).exception || (!input(MMU_RSP).allowWrite && input(INSTRUCTION)(5)) || (!input(MMU_RSP).allowRead && !input(INSTRUCTION)(5)) || (!input(MMU_RSP).allowUser && privilegeService.isUser(memory))
dBus.cmd.valid := False skipCmd.setWhen(input(MMU_FAULT) || input(MMU_RSP).refilling)
arbitration.haltItself := False
}
insert(MMU_RSP) := mmuBus.rsp insert(MMU_RSP) := mmuBus.rsp
} }
@ -370,7 +374,7 @@ class DBusSimplePlugin(catchAddressMisaligned : Boolean = false,
when(input(MMU_RSP).refilling){ when(input(MMU_RSP).refilling){
redoBranch.valid := True redoBranch.valid := True
memoryExceptionPort.valid := False memoryExceptionPort.valid := False
} elsewhen(input(MMU_RSP).exception) { } elsewhen(input(MMU_FAULT)) {
memoryExceptionPort.valid := True memoryExceptionPort.valid := True
memoryExceptionPort.code := (input(INSTRUCTION)(5) ? U(15) | U(13)).resized memoryExceptionPort.code := (input(INSTRUCTION)(5) ? U(15) | U(13)).resized
} }

View File

@ -314,9 +314,12 @@ class IBusSimplePlugin(resetVector : BigInt,
decodeExceptionPort.code := 1 decodeExceptionPort.code := 1
exceptionDetected := True exceptionDetected := True
} }
if(memoryTranslatorPortConfig != null) when(stages.last.input.valid && mmu.joinCtx.exception){ if(memoryTranslatorPortConfig != null) {
decodeExceptionPort.code := 12 val privilegeService = pipeline.serviceElse(classOf[PrivilegeService], PrivilegeServiceDefault())
exceptionDetected := True when(stages.last.input.valid && (mmu.joinCtx.exception || !mmu.joinCtx.allowExecute || (!mmu.joinCtx.allowUser && privilegeService.isUser(decode)))){
decodeExceptionPort.code := 12
exceptionDetected := True
}
} }
decodeExceptionPort.valid := exceptionDetected && iBusRsp.readyForError decodeExceptionPort.valid := exceptionDetected && iBusRsp.readyForError
} }