中断分类和Gate



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; 来自cup之外的叫中断(Interrupt):

;           *可屏蔽中断(IRQs)

;           *不可屏蔽中断(NMI)

;      可屏蔽中断(IRQs) 可以由cli/sti 指令控制.

;      两者都可以被cpu外的硬件所屏蔽.

; 来自cup内部的叫异常(Exceptions):

;    **CUP 侦测到的异常:

;        *故障(Fault): 在当前指令执行前发生. 如除0, 非法操作码,page fault.

;        *陷阱(Trap): 在执行当前指令后发生. 程序指令int 产生的异常都是陷阱.

;        *Abort: 异常位置不可确定.如 double fault, coprocessor segment overrun.

;    **程序主动产生的异常 :

;        INT instruction

;        INT3 instruction

;        INTO instruction

;        BOUND instruction

;*************************************

;Intel 保留的32 个中断/异常:

;|Number | interrupt/exception|     notes

;+-----+----------------------+------------------------------------------------

;|  0  |   divide  error      | could be overflow as well as zero denominator

;+-----+----------------------+------------------------------------------------

;|  1  |   debug exception    |

;+-----+----------------------+-------------------------------------------------
;|  2  |    NMI               |

;+-----+----------------------+-------------------------------------------------

;|  3  |   INT3 instruction   | debugger breakpoint

;+-----+----------------------+-------------------------------------------------

;|  4  |   INTO instruction   | detected overflow 

;+-----+----------------------+-------------------------------------------------

;|  5  |  BOUND instruction   | detected overrange 

;+-----+----------------------+-------------------------------------------------

;|  6  |  invalid instruction |

;+-----+----------------------+-------------------------------------------------

;|     |   opcode             |

;+-----+----------------------+-------------------------------------------------

;|  7  |   no coprocessor     | ESC, WAIT instructions

;+-----+----------------------+-------------------------------------------------

;|  8  |   double fault       | possible for 386+ in real mode

;|     |                      |  if INT vector exceeds IDT limit

;+-----+----------------------+-------------------------------------------------

;|  9  |  coprocessor segment | not in real mode

;|     |   overrun            | 

;+-----+----------------------+-------------------------------------------------

;|  10 |   invalid task state |  not in real mode

;|     |   segment (TSS)      |

;+-----+----------------------+-------------------------------------------------

;|  11 |  segment not present |  not in real mode

;+-----+----------------------+-------------------------------------------------

;|  12 |   stack fault        |  possible in real mode if stack access

;|     |                      |  straddles offset 0 or FFFFh

;+-----+----------------------+-------------------------------------------------

;|  13 |   general protection | possible in real mode if non-stack memory access
straddles

;|     |    fault (GPF)       | 0 or FFFFh, or if instruction is longer than 15
bytes,

;|     |                      | or if a 32-bit address greater than FFFFh is used

;+-----+----------------------+-------------------------------------------------

;|  14 |   page fault         |  not in real mode

;+-----+----------------------+-------------------------------------------------

;|  15 |   (reserved) 

;+-----+----------------------+-------------------------------------------------

;|  16 |   coprocessor error  |  ESC, WAIT instructions

;+-----+----------------------+-------------------------------------------------

;|  17 |   alignment check    |  not in real mode; 486+ only

;+-----+----------------------+-------------------------------------------------

;|  18 |   machine check      |  Pentium+ only

;+-----+----------------------+-------------------------------------------------

;|19-31|  (reserved)          |

;+-----+----------------------+------------------------------------------------

;*****************************************

; interrupt/exception 发生后CPU 的动作

; 1. 如果伴随 pmode 特权级切换, CPU 从当前的TSS 中加载 SS (E)SP .

; 2. 如果伴随 pmode 特权级切换, 原来的 SS 和 (E)SP 入新堆栈.

; 3. CS, (E)IP, (E)FLAGS 入新栈. 一些异常可能还把一个错误码入新栈.

; 4. 如果通过一个中断门,CPU 清 IF . 

; 5. CPU 做一个 far jump; 从门中加载 CS and (E)IP .

;

; 中断/异常发生后可能形成10 种栈布局. 3 个16-bit 保护模式; 2个virtual 8086 模式.

; 还有一个16 bit 实模式. 对我们比较有意义的4个32位保护模式下的栈格式是:

;+--------------------------------+----------------------------------+

;|          无特权级切换          |           伴随特权级切换         |

;+----------------+---------------+-----------------+----------------+

;|  <- 32 bits -> | <- 32 bits -> |  <- 32 bits ->  |<- 32 bits
->   |

;|    ... ...     |   ... ...     |    ... ...      |   ...  ...     |

;|    ... ...     |   ... ...     |    ... ...      |   ... user SS  |

;|    ... ...     |   ... ...     |    ... user SS  |    user ESP    |

;|    ... ...     |   EFLAGS      |    user ESP     |    EFLAGS      |

;|    EFLAGS      |   ... CS      |     EFLAGS      |    ... CS      |

;|    ... CS      |    EIP        |    ... CS       |     EIP        |

;|      EIP       |  error code   |      EIP        |   error code   |

;+----------------+---------------+-----------------+----------------+

;|    无错误码    |   有错误码    |     无错误码    |   有错误码     |

;+----------------+---------------+-----------------+----------------+

;****************************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;中断门描述符格式 

;+31-----------------16|15 |14 13|12------8|7----------0-+ 

;|   Offset 31..16     | P   DPL   0 D 110   0000 0000   | 1 dword

;+---------------------+-------------------+-------------+

;+31-----------------16|15-----------------------------0-+

;|      Selector       |   Offset 15..0                  | 0 dword

;+---------------------+---------------------------------+

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Trap Gate

;+31-----------------16|15 |14 13|12------8|7----------0-+ 

;|   Offset 31..16     | P   DPL   0 D 111   0000 0000   | 1 dword

;+---------------------+-------------------+-------------+

;+31-----------------16|15-----------------------------0-+

;|      Selector       |   Offset 15..0                  | 0 dword

;+---------------------+---------------------------------+ align 3

;***********************

;DPL-------Descriptor Privilege Level

;Offset----Offset to procedure entry point

;P---------Segment Present flag

;Selector--Segment Selector for destination code segment

;D---------Size :1 = 32 bits; 0 = 16 bits

;***********************

; 1 dword 8---15bits 的典型值

; Interupt Gate (clear IF):8Eh or 0EEh (kernel/user)(32 bit)(用于中断或异常)

; Trap Gate(keep IF):      8Fh or 0EFh (kernel/user)(32 bit)(用于trap ?)

;***********************

;GATE     STRUC      ;门结构类型定义

;    OFFSETL  DW      0  ;32位偏移的低16位

;    SELECTOR DW      0  ;选择子

;    Reserve  DB      0 

;    GTYPE    DB      0  ;类型

;    OFFSETH  DW      0  ;32位偏移的高16位

;    GATE     ENDS

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值