当前位置:网站首页>x86 exception handling and interrupt mechanism (2) interrupt vector table

x86 exception handling and interrupt mechanism (2) interrupt vector table

2022-08-09 11:15:00 XV_

补充:Events not only contains the interrupt and abnormal,还包含系统调用,This belongs to the user active request events.

上一节,There is only one exceptions,那么,如果Many abnormal、中断呢?(中断向量表)

另外,之前0The address can only be stored two instructions,If you need further instructions how to do?(Address of the location and the corresponding program size should be more flexible)

注意,中断服务程序包含(保存现场,调用处理方法(主体),恢复现场)

We meet after interruption,需要执行的步骤,我们简化一下

  1. CPUDo some hardware processing work(识别中断源,关中断,当前指令(或下一条指令)地址压栈,FLAGS寄存器压栈)
  2. To deal with interrupt program address(Here is the interrupt service routine)
  3. 执行中断服务程序(Contains the protection field,执行处理程序(This is the main part),恢复现场,返回原程序)
  4. 继续To perform the original program

在不同的时代,Interrupt handling are the process,It's just every specific process execution has changed,且越来越复杂,我们依次看一下.

1 时代1:UNIVAC时代,Only a fixed address interrupt handling

In the original computer age,Only a few internal interrupt and external interrupt.
在这里插入图片描述In a time of the interrupt service routine,是固定的地址,And the program is relatively limited the size of the.

For example the arithmetic overflow,那么就会跳转到地址0执行中断服务程序.

在这里插入图片描述
不仅如此,When the interrupt service routine is almost

  • 固定地址
  • 固定大小

Therefore flexibility is poor,But with little,所以还好.

到了后来,Interrupt more and more,因此就有了中断向量表,下面看看8086时代吧.

2 时代2:8086时代,实模式 + 中断向量表

这个时代,Have more,Also more flexible management interrupt way.

在这里插入图片描述
8086Is the real mode,也就是说,进入CPU指令中的地址,就是实际的物理地址.

在8086的1MB内存中,有Dedicated interrupt to scale area,从地址0开始的1K字节,它用于存放Interrupt service routine address,也就是存放CS:IP.

每对CS:IP占用4个字节,因此1KB的空间,最多可以支持256种中断.
在这里插入图片描述
CS:IP,CS在前,IP在后,因此CS在高地址,IP在低地址,又因为是小端模式,因此IPHigh byte is high,The low byte is low;CS同理.

这样一来,The location of the actual interrupt service routine,According to theseCS:IPThe value of certain,And they can be modified in memory,因此

  • The location of the interrupt service routine variable
  • The size of the program can be changed

And the location of the interrupt service routine is arbitrary,As long as you can and interrupt to it on a scale corresponds to.

同时,Different interrupt service routine,There is no connection position,Where is ok.In real mode8086之下,只需要CS:IPCan determine the location of the actual memory.
在这里插入图片描述
在这个时代,The location of the interrupt service routine size more flexible,变成了间接获取,Because with an interrupt to the scale.

在这里插入图片描述
注意,这个时候有5种类型的中断,并不是5个中断,This time involving internal interrupt have4个,外部中断有1个,While the external interrupt,是8259A芯片发出的,The chip can connect many peripherals outside.

在这里插入图片描述
Let's take a look at this era interrupt processing sketch.

在这里插入图片描述

3 时代3:80386时代,保护模式 + 中断向量表

This time is a little complicated,引入了保护模式,At the same time adds some interrupt type,这也是Linux 0.11The kernel correspondingCPU.

在这里插入图片描述The circled part is80386支持的中断类型,int0 ~ int16,其中int15未定义,Can check it on the manual.
在这里插入图片描述

3.1 Protection mode of addressing mode

首先,保护模式下,依然是CS:EIP的形式,但是由于EIPAddressing enough4GB,因此CSNo longer as digits extension function,Its function has changed.

在这里插入图片描述
在保护模式下,段寄存器依然是16位,它们变成了段选择子寄存器,Start with the simplest way to describeAddress generation approach

  1. 通过段选择子寄存器找到8- byte segment descriptor
  2. 根据The content of the segment descriptor获取段基址(32位)
  3. 段基址EIP组合(==Should be together?==基址 + 偏移地址),得到地址
  4. 注意: Can currently known to this address is forCPU看的,It should be a virtual address,现在先不管,As a first pass this address will be able to access to the memory of the specified position.

Is much more complicated than the real mode,下面,Further details.

Through the segment selector register(Since then onCS举例说明),How to find the corresponding segment descriptor?在这里插入图片描述

  1. The computer boot into real mode
  2. 填好GDT
  3. 设置好GDTThe initial address inGDTR寄存器中

在保护模式下, CS + GDTRTo obtain the corresponding descriptors(0~8191),这样,We can get the code segment descriptor.

Let's take a look at this descriptor

  1. This descriptor is8192个,也就是2^13,While a descriptor with2^3 = 8个字节,So the total occupied2^16个内存单元,也就是64KB,CS寄存器是16位的,This is that it can access limit,这样,通过GDTR基址 + CS偏移的方式,Have access to each descriptor table.
  2. Look at the structure of each descriptor
    在这里插入图片描述
    它有8个字节的大小,There are four bytes is段基址,This is the base andEIP组合,Form the final to access memory(虚拟)地址.Other also involves authority and boundaries of ourselves,First, no matter what.

What is the content of the segment descriptor,How to get section b

上面已经说明了.

3.2 Protection mode interrupt operation

上面一小节,Through a series of complex process,Finally illustrates theProtection mode how to address,Really complicated……The following descriptions interrupt operation process.Actually the main description of orInterrupt service routines to position the process.

在这里插入图片描述
在保护模式下,也有一个IDTR中断描述符表寄存器,还有一个IDT中断描述符.

这个IDT同样是支持256Types of interrupt,Each descriptor table item of8个字节,Therefore a total footprint2KB.

IDTR提供的是IDT的基址,然后CPUAfter get interrupt number,根据中断号 * 8 + IDTRLocate the corresponding descriptors.

To interrupt descriptor

  • 字节0167Four bytes corresponding is that32位地址,也就是EIP的值
  • 字节23对应的是CS的值
  • 有了CS:EIPYou can through the way of the previous section to find the address of the corresponding,To find the interrupt service routine入口地址
    (The process and actuallyCS:IP类似,Just a little trouble)

For such a big circle,Finally found the interrupt service routine……

3.3 小结

这个太复杂了,We simply summarize.

首先,Protected mode under the way of addressing more complicated,Introduced the global descriptor table,虽然依然是CS:EIP,But its calculation is more complicated.

其次,Protection mode of the interrupt handling more complicated

  • A fixed position before interruption to scale,变成了Any position of the interrupt descriptor tableIDT,通过IDTR中断类型号Calculate the interrupt descriptor
  • Through the content of the interrupt descriptor forCS:EIP,To obtain the corresponding interrupt service routine entry address

我们可以看到,Pattern is more and more complex,Indirect degree is higher and higher,Set of degrees of freedom improve,安全性也提高了.

在这里插入图片描述

思想:Fixed too rigid to do?Add a fixed station!By changing the station,To achieve flexible allocation of

The development process of several times,To say the hub in more and more,越来越复杂,灵活度越来越高.

小结

本篇内容,To implement the interrupt processingLooking for the interrupt service routine的过程.

可以看到

  1. UNIVACTime is very direct to find the address
  2. 8086Era provides a fixed position interrupts to scale,间接地找到CS:IP,Addressing mode is direct
  3. 80386Era provides any position of the interrupt descriptor table,Indirect access toCS:EIP,Addressing mode is also indirectly,Through the global descriptor tableGDT获取段基址,Get the memory address to

不管怎样,The development of The Times to make根据中断类型号,Find the interrupt service routineThis process is more and more complex,Flexibility is becoming more and more high.

Later introduced interrupt handling other process,最后结合Linux 0.11内核源代码,So that the software and hardware on the corresponding.

原网站

版权声明
本文为[XV_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091103199225.html