MIPS系列笔记-CP0 Hazard

CP0 hazard

Because resources controlled via Coprocessor 0 affect the operation of various pipeline stages of a MIPS32 processor,manipulation of these resources may produce results that are not detectable by subsequent instructions for some number of execution cycles. When no hardware interlock exists between one instruction that causes an effect that is visible to a
second instruction, a CP0 hazard exists.

逻辑上讲,对CP0进行一次操作后,后继指令应该会运行在改变后的模式下。但是由于乱序执行的特点,这种逻辑上的观点很难直接满足,很容易出现非预期行为,称为CP0 hazard。

为了解决cp0 hazard,某些处理器采用了硬件方式解决,MIPS将这一问题留给了内核软件:

Some MIPS implementations have placed the entire burden on the kernel programmer to pad the instruction stream in such a way that the second instruction is spaced far enough from the first that the effects of the first are seen by the second.

cp0操作后插入足够多的nop指令!

另外一种软件方式就是插入一条ehb指令,比如:

 

[摘自 http://bbs.lzu.edu.cn/pc/pccon.php?id=10159&nid=1448&s=all]

[ref]

mtc0 t0, SR
ehb

其中ehb为exception hazard barrier,这个主要有MIPS的pipe lines引起,大致可以理解为由于MIPS采用的流水线(pipe lines)结构,即使在异常处理代码中(这里由于改变了状态寄存器情况类似),由于流水线的作用,异常处理结束时,其下一条(可能超过一条,依赖流水线的设计)仍然被预取执行,这样由于CPU的特权级别发生了改变,但被流水线预取的指令并不知道这些,因而导致严重的安全性问题。为了避免这种情况发生,MIPS专门使用了ehb指令。类似的指令还包括eret,即从异常(原子的,atomically)返回。
[/ref]

 

另外,SSNOP指令也值得注意,它可以自动知道需要停顿的周期数。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值