(MIPS体系结构剖析,编程与实践)第4章 MIPS 异常和中断.doc
《(MIPS体系结构剖析,编程与实践)第4章 MIPS 异常和中断.doc》由会员分享,可在线阅读,更多相关《(MIPS体系结构剖析,编程与实践)第4章 MIPS 异常和中断.doc(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、(MIPS体系结构剖析,编程与实践)第4章 MIPS 异常和中断处理文库.txt小时候觉得父亲不简单,后来觉得自己不简单,再后来觉得自己孩子不简单。越是想知道自己是不是忘记的时候,反而记得越清楚。第四章 MIPS 异常和中断处理MIPS 异常和中断处理(Exception and Interrupt handling) 任何一个CPU都要提供一个详细的异常和中断处理机制。一个软件系统,如操作系统,就是一个时序逻辑系统,通过时钟,外部事件来驱动整个预先定义好的逻辑行为。这也是为什么当写一个操作系统时如何定义时间的计算是非常重要的原因。 大家都非常清楚UNIX提供了一整套系统调用(System C
2、all)。系统调用其实就是一段EXCEPTION处理程序。 我们可能要问:为什么CPU要提供Excpetion 和 Interrupt Handling呢? *处理illegal behavior, 例如,TLB Fault, or, we say, the Page fault; Cache Error; * Provide an approach for accessing priviledged resources, for example, CP0 registers. As we know, for user level tasks/processes, they are runni
3、ng with the User Mode priviledge and are prohibilited to directly control CPO. CPU need provide a mechanism for them to trap to kernel mode and then safely manipulate resources that are only available when CPU runs in kernel mode. * Provide handling for external/internal interrupts. For instance, th
4、e timer interrupts and watch dog exceptions. Those two interrupt/exceptions are very important for an embedded system applicances. Now lets get back to how MIPS supports its exception and interrupt handling. For simplicty, all information below will be based on R7K CPU, which is derived from the R4k
5、 family. * The first thing for understanding MIPS exception handling is: MIPS adopts *Precise Exceptions* mechanisms. What that means? Here is the explaination from the book of See MIPS Run: In a precise-exception CPU, on any exception we get pointed at one instruction(the exception victim). All ins
6、tructions preceding the exception victim in execution sequence are complete; any work done on the victim and on any subsequent instructions (BNN NOTE: pipeline effects) has no side effects that the software need worry about. The software that handles exceptions can ignore all the timing effects of t
7、he CPUs implementations 上面的意思其实很简单:在发生EXCEPTION之前的一切计算行为会*FINISH*。在发生EXCEPTION之后的一切计算行为将不需考虑。 对绝大多数情况而言,如你要写一个系统调用(System Call),你只要记住: MIPS已经把syscall这条指令的地址压在了EPC寄存器里。换句话说,在MIPS里,compard to the PowerPC CPU srr1 register, 你需要*explicitely* refill the EPC register by EPC-EPC+4, before you use the eret中
8、断返回。只有这样,你才能从系统调用中正确返回。 异常/中断向量(Exception/Interrupt Vector) MIPS 的Exception/Interrupt Vector的organizaion is not as good as PowerPC CPUs. For PPC, every detailed exception cause is directed to a unqiue vector address. MIPS is otherwise. Below is a recap of MIPS exception/interrupt vectors. (We herein
9、 only talk about running MIPS CPU in the 32 bit mode ) Reset, NMI 0x8000 0000 TLB refill 0x8000 0000 Cache Error 0xA000 00100 (BNN: Why goes to 0xAxxxxx? A question to readers. Please think about the difference between Kseg0 and kseg1) All other exceptions 0x8000 0180 How MIPS acts when taking an ex
10、ception? 1. It sets up the EPC to point to the restart location. 2. CPU changes into kernel mode and disables the interrupts (BNN: MIPS does this by setting EXL bit of SR register) 3. Set up the Cause register to indicate which is wrong. So that software can tell the reason for the exception. If it
11、is for address exception, for example, TLB miss and so on, the BadVaddr register is also set. 4. CPU starts fetching instructions from the exception entry point and then goes to the exception handler. Returning from exceptions Up to MIPS III, we use the eret instruciton to return to the original loc
12、ation before falling into the exception. Note that eret behavior is: clear the SREXL bit and returns control to the adress stored in EPC. An important bit in SR for interrupt handling SRIE: This bit is used to enable/disable interrupts, including the timer interrupts. Of couse, when the SREXL bit is
13、 set, this bit has no effects. K0 and K1 registers: These two registers are mostly used by kernel as a temporary buffer to hold some values if necessary. So that you dont have to find some pre-defined memories for that purpose. One thing we should be careful is : When you are allowing the nested exc
14、eption/interrupt handling, you need take care of these two registers values as they will be over-written, for example. I dont encouarge people to use the AT register too often, even though you can use the .set noat directive. I have found a bug in mips-gcc, which will use the AT register anyway, eve
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MIPS体系结构剖析 编程与实践第4章 MIPS 异常和中断 体系结构 剖析 编程 实践 异常 中断
限制150内