RISC异常/中断的属性:5种 User Within vs. Synchronous vs. User request maskable vs. between Resume vs. Exception type asynchronous vs.coerced nonmaskable instructions terminate 1/O device request Asynchronous Coerced Nonmaskable Between Resume Invoke operating system Synchronous User request Nonmaskable Between Resume Tracing instruction execution Synchronous User request User maskable Between Resume Breakpoint Synchronous User request User maskable Between Resume Integer arithmetic overflow Synchronous Coerced User maskable Within Resume Floating-point arithmetic Synchronous Coerced User maskable Within Resume overflow or underflow Page fault Synchronous Coerced Nonmaskable Within Resume Misaligned memory accesses Synchronous Coerced User maskable Within Resume Memory protection violations Synchronous Coerced Nonmaskable Within Resume Using undefined instructions Synchronous Coerced Nonmaskable Within Terminate Hardware malfunctions Asynchronous Coerced Nonmaskable Within Terminate Power failure Asynchronous Coerced Nonmaskable Within Terminate H&PCA图A.27 IF ID EX MEM WB
RISC异常/中断的属性:5种 H&P CA图A.27
指令异常响应模式 可恢复异常:访存指令缺页,OS处理后重新执行当前指令,如图“故障” 不可恢复异常:当前异常无法修复,交用户处理,如图“异常中止” 陷阱(软中断/系统调用):系统调用指令触发请求,返回下一条指令 程序执行 程序执行 程序执行 当前指令 当前指令 异岁入 发生异常 处理 当前指令 处理 发现故障 触发陷阱 当前指令 常 异常 下一条指令 故障处理程序执行 下一条指令 陷阱处理积序执行 星常 异常处理程序执行 下一条指令 返可 程序终止 故障处理 陷阱处理 异常中止
7 指令异常响应模式 • 可恢复异常:访存指令缺页,OS处理后重新执行当前指令,如图“故障” • 不可恢复异常:当前异常无法修复,交用户处理 ,如图“异常中止” • 陷阱(软中断/系统调用):系统调用指令触发请求,返回下一条指令
系统调用:应用程序调用0OS服务 Ring 3 Ring 2 Least privileged Application Ring 1 execution Ring 0 stream Exception First-level handler Kemel Set supervisor(kernel)privilege level Most privileged Device drivers Save interrupt return register(IRR) Save kernel state Device drivers Applications Identify exception/interrupt Set correct privilege level 用户态 内核态 Jump to handler Real handler system call: Service interrupt xyzO IDT sys xyz sys xyzsys"call table{ Fix what caused the exception xyzO int 0x80 (for exceptions) ret_from sys call:"... Jump back to lower-level handler iret Restore kernel state Set original privilege level 在应用程序在1ibc标准库 系统调用 系统调用 调用中的 中的封装例程 处理程序 服务例程 RFI(return from interrupt,jump to IRR) 系统调用 Application execution stream
系统调用:应用程序调用OS服务
不可恢复异常:异常终止 Kernel32 This program has pertormed an illegal operation Close and will be shut down. If the problem persists,contact the program Debug vendor. Detal KERNEL32 caused an invalid page fault in module KERNEL32.DLL at 0137:bft74966. Registers: EAX=5f402d8cCg=0137EIP=bfE74966EF1Cg=00010246 BBX=00000000SS=013fBgP=0181fad4EB2=0181fh00 ECX=00000002DS=013fESI=00000000FS=2717 EDX=815ae794E$=013fEDI=514cb008C8=0000 Bytes at CS:EIP: 66648e2d0c00000065f6051600000020
不可恢复异常:异常终止
外部中断:中断源,类型,处理机构 MIPS32®Core ● 处理器异常处理 Vector Number Offset Interrupt EPC,CAUSE Exception Priority Level Interrupt Controller Execution unit Requests (Exception Handling) CSR:中断禁止 Shadow Set Number 抢占与嵌套 Core Interrupt Events Instruction Data ■■■■■■■■■■■■■■■■■■■■■■■■■ Cache Cache 外部中断源:外设,核间通信 Multi-Layer 可屏蔽: System Bus ·时钟、 键盘、鼠标、硬盘 不可屏蔽 。 访存、设备错、电源 Prefetch Buffer Data 中断控制器:中断源管理 SRAM Peripherals Interrupt Events Program ◆ 判优,屏蔽挂起pending Flash
外部中断:中断源,类型,处理机构 • 外部中断源:外设,核间通信 – 可屏蔽: • 时钟、键盘、鼠标、硬盘 – 不可屏蔽 • 访存、设备错、电源 • 中断控制器:中断源管理 – 判优,屏蔽挂起pending • 处理器异常处理 – EPC,CAUSE – CSR:中断禁止 – 抢占与嵌套