csapp分类:
Exception(异常),分为同步异常和异步异常,本质都是将控制交给kernel解决的。
异步异常,也称为中断(Interrupt)指由处理器外部的事引起的,计时器中断和I/O中断时最常见的两种;
同步异常,由执行某条指令导致的,分为Trap(陷阱,比如syscall),Fault(故障,比如页故障page fault)和Abort(终止)三种情况。Trap和中断都会返回下一条指令,故障是重新执行之前触发事件的指令。

xv6 textbook中分类方式是syscall,exception和interrupt,其实可以理解为syscall,同步中断和异步中断??。在大多数处理器中这三种事件都是用一种硬件机制处理的。

Intel Chapter 9 这里分类是这样的,和xv6 book相同,按照处理器内部和外部检测分类中断和异常,理解一下其实和csapp说法类似,只不过似乎csapp里把中断称作异步异常

中断: 外部,异步
可屏蔽中断:通过INTR线向CPU请求中断,主要是外部设备如硬盘,打印机,网卡等。
bit 9 of FLAG register is IF(Interrupt-Enable Flag) and IF = 0,屏蔽,IF = 1,不屏蔽。CLI和STI可以显式的清楚和设置IF位(只有CPL <= IOPL才可以执行)。RESET可以清除IF。此外还有隐式的更改。
不可屏蔽中断:通过NMI线向CPU请求中断,如电源掉电,硬件线路故障等,当一个NMI handler在执行的时候,其余的来自NMI的中断信号会被忽略直到下一个IRET指令执行。

异常: 内部,同步,处理器自己在执行指令过程中检测到的
处理器检测到的:trap(总是返回到下一条指令),fault(可恢复的错误比如除法错误,0号异常,可能返回到当前指令),abort(不可恢复的错误)
Programmed:虽然是software interrupts,例如INTO,INT 3,INT n,BOUND,但是处理器把它们当作异常处理

trap和interrupt的区别: traps are caused by the current process running on a processor (e.g., the process makes a system call and as a result generates a trap), and interrupts are caused by devices and may not be related to the currently running process

优先级处理问题:
如果在一个指令边界有不止一个中断或异常挂起,处理器只能一次处理他们中的一个。中断和异常之间的优先级被表9-2显示。处理器最先处理优先级最高的中断或异常类型,把控制转移到最高优先级的中断处理程序里的第一条指令。低优先级的异常将被丢弃。低优先级的中断将被挂起。丢弃的异常将在返回到引起中断的指令处再次被发现。
Table 9-2. Priority Among Simultaneous Interrupts and Exceptions

Priority Class of Interrupt or Exception

HIGHEST Faults except debug faults
Trap instructions INTO, INT n, INT 3
Debug traps for this instruction
Debug faults for next instruction
NMI interrupt
LOWEST INTR interrupt

LIDT和SIDT指令:
LIDT从图9-1所示内存中加载linear address BASE and LIMIT到IDTR中
SIDT则相反
LIDT必须是CPL = 0才能执行,SIDT在任何优先级下都能执行

IDT Descriptors

三种:Task gates,Interrupt gates,Trap gates

Interrupt procedures

the IRET instruction
pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack to the EIP, CS, and EFLAGS registers, respectively, and then resumes execution of the interrupted program or procedure.
If the return is to another privilege level, the IRET instruction also pops the stack pointer and SS from the stack, before resuming program execution

如下链接是EFLAGS:
http://www.c-jump.com/CIS77/ASM/Instructions/I77_0070_eflags_bits.htm
Interrupt procedure 期间 TF 会被设置为0(注意不包含通过的Task gate哦),以避免single-step activity影响
如果是通过Interrupt gate还会重置 IF 从而避免其余Interrupts的影响
但是以上标志都会在IRET的时候恢复。

Return from an Interrupt procedure:
IRET is similar to RET except that IRET increments ESP by an extra four bytes (because of the flags on the stack) and moves the saved flags into the EFLAGS register. The IOPL field of EFLAGS is changed only if the CPL is zero. The IF flag is changed only if CPL <= IOPL.


Protection in Interrupt Procedures

中断过程(interrupt procedure)和过程调用一样:
the CPU does not permit an interrupt to transfer control to a procedure in a segment of lesser privilege (numerically greater privilege level) than the current privilege level. An attempt to violate this rule results in a general protection exception.(不允许特权级变低)

the privilege rule mentioned above effectively imposes restrictions on the privilege levels at which interrupt and exception handling procedures can execute.Either of the following strategies can be employed to ensure that the privilege rule is never violated

1、 Place the handler in a conforming segment. This strategy suits the handlers for certain exceptions (divide error, for example). Such a handler must use only the data available to it from the stack. If it needed data from a data segment, the data segment would have to have privilege level three, thereby making it unprotected

什么是conforming segment:
An executable segment whose descriptor has the conforming bit set is called a conforming segment. The conforming-segment mechanism permits sharing of procedures that may be called from various privilege levels but should execute at the privilege level of the calling procedure.

2、 Place the handler procedure in a privilege level zero segment.

Interrupt Tasks


https://pdos.csail.mit.edu/6.828/2018/readings/i386/s09_06.htm
看上面链接最后一段,没太理解细节,还要看链接对应的书里的chapter 7

Error Code

EX :whether an event external to the program caused the exception.
I:if the index portion of the error code refers to a gate descriptor in the IDT.
TI:when I = 0,TI = 0=>GDT,TI = 1=>LDT
In some cases the error code on the stack is null, i.e., all bits in the low-order word are zero.

MIT6.828 异常和中断学习笔记相关推荐

  1. LINUX中断学习笔记【转】

    转自:http://blog.chinaunix.net/uid-14825809-id-2381330.html 1.中断的注册与释放: 在 , 实现中断注册接口: int request_irq( ...

  2. 《C++ Primer Plus》第15章 友元、异常和其他 学习笔记

    友元使得能够为类开发更灵活的接口.类可以将其他函数.其他类和其他类的成员函数作为友元.在某些情况下,可能需要前向声明,需要特别注意类和方法声明的顺序,以正确地组合友元. 潜逃类是在其他类中生命的类,它 ...

  3. MSP430单片机中断学习笔记(一)

    目录 一.中断的基本概念 1.1中断的定义 1.2中断源 1.3中断向量表 1.4中断优先级 1.5断电 1.6中断现场 二.中断源 2.1系统复位中断源 2.1.1断电复位信号(BOR) 2.2.2 ...

  4. 【嵌入式linux】imx6ul中断学习笔记

    imx6ul中断处理过程 1.中断号 2.中断服务函数 3.注册中断函数 4.总结 1.中断号   当中断发生时,程序根据启动文件最前面的中断向量表跳转至相应的中断执行位置. _start:ldr p ...

  5. 机器学习之其他常用方法——异常检测(学习笔记)

    文章目录 异常检测 1. 应用 2.定义 3.简介 异常检测 1. 应用 1.在工业上的应用 当检测设备是否处于异常工作状态时,可以由上图分析得到:那些零散的点对应的数据是异常数据.因为设备大多数时候 ...

  6. RT_Thread按键中断学习笔记

    以下通过pin驱动来大概介绍rtthread驱动程序的编写方法 1.  RT_thread提供了下面的几个函数(PIN设备管理接口)来访问GPIO,如下: 函数    描述 rt_pin_mode() ...

  7. 嵌入式linux 添加中断,《嵌入式linux应用程序开发完全手册》中断控制器操作(外部中断)学习笔记...

    <嵌入式linux应用程序开发完全手册>中断控制器操作(外部中断)学习笔记 一.ARM中断体系 当一个"异常"发生时,或者说当收到一个中断触发信号时,ARM9将会自动完 ...

  8. MIT6.828 32位操作系统笔记(3)----系统的启动和初始化

    MIT EDU 6.828 实验源代码 分类 MIT6.828 32位操作系统实验笔记 实验完善代码 LAB2-4下载链接 提取码:79t8 系统的启动过程 物理内存的分布 首先分析PC 开机以后的默 ...

  9. 2022年Java学习笔记目录

    一.2022年Java任务驱动课程 任务驱动,统摄知识点:2022年Java程序设计讲课笔记 二.2022年Java学习笔记 (一)踏上Java开发之旅 Java学习笔记1.1.1 搭建Java开发环 ...

最新文章

  1. 用Vue撸一个『A-Z字母滑动检索菜单』
  2. DocRepair 3.0
  3. 中外教育专家“支招”中国学生如何接轨国际教育
  4. vc6.0打开工程出现程序崩了的原因
  5. VTK:Filtering之VectorFieldNonZeroExtraction
  6. 机器学习笔记——K-means
  7. WCF 之 消息契约(MessageContract)
  8. 【Java线程】多线程实现简单的一对一聊天
  9. Material Design学习之 Snackbars(详细分析,Toast的加强版)
  10. linux python版本升级和系统更新_Linux 下升级python和安装pip
  11. python学习之random
  12. JVM快速调优手册v1.0之三:内存分配策略
  13. k2pbreed刷高恪教程_【转载】斐讯K1、K2、K2P 大部分官方固件刷机、刷入Breed 辅助工具教程工具...
  14. android 微博功能实现,android 新浪微博实现分享功能
  15. CentOS7 网络安装版本 设置基础软件仓库出错
  16. 基于遗传算法的神经网络,遗传算法训练神经网络
  17. poj 1673(EXOCENTER OF A TRIANGLE) (垂心证明)
  18. idea的git报错You have not concluded your merge
  19. 人生苦短,我用Python;平台无限多,最棒大蟒蛇anaconda!
  20. 用OLED显示屏显示文字

热门文章

  1. 音乐播放器从0到读取手机内的音乐文件——Android Studio小白实训笔记
  2. 看图猜成语小程序源码
  3. 【FNN预测】基于Jaya优化JAYA前馈神经网络FNN研究附Matlab代码
  4. comsol三相变压器仿真建模教程
  5. ForkLift 3.5.6 远程/本地文件管理利器
  6. chrome同步书签实现
  7. idea打开文件关联目录
  8. 【可解释性机器学习】详解Python的可解释机器学习库:SHAP
  9. 信息系统项目管理师必背核心考点(七十)安全审计功能
  10. MT 256 Advice of Non-Payment of Cheques非支付支票通知