Interrupt and Exception transfer methods

Source: Internet
Author: User

80386 the interrupt and exception transfer methods in real mode are the same as 8086. The interrupt and exception transfer method described here refers to the transfer method used to respond to interrupts and handle exceptions in protected mode (80386).

1. Interrupt Descriptor IDT

As with 8086/8088, in response to an interrupt or handle an exception, 80386 cycles the corresponding handler according to the interrupt vector number. However, in protected mode, 80386 does not use the interrupt vector table in real mode, but instead uses interrupt descriptor IDT. In protected mode, 80386 interrupts the vector number as the index of the descriptor in the Interrupt Descriptor table IDT, and is no longer the index of the interrupt vector in the interrupt vector tables. Like the global descriptor GDT, there is only one interrupt descriptor IDT in the entire system. The Interrupt Description Chart Register IDTR indicates the location of the IDT in memory. Since 80,386 recognizes only 256 interrupt vector numbers, the maximum length of the IDT is 2K. Interrupt Descriptor IDT contains only the interrupt door, trap door and task door. In other words, in protected mode, 80,386 can only be transferred to the corresponding interrupt or exception handler by interrupting the door, trap door, or task door. The format of the gate descriptor given in the previous article is visible, and the door descriptor contains a 48-bit full pointer consisting of a selector and an offset. In addition, the double digit digital segment is meaningless to interrupt door, trap door and task door.

2. Steps to interrupt response and exception handling

The steps for interrupt response and exception handling that are automatically implemented by hardware are as follows:

First, determine whether the gate descriptor to index the interrupt vector number exceeds the bounds of IDT. If the limit is exceeded, a general protection failure is caused, and the error code is the interrupt vector number multiplied by 8 plus 2. Secondly, the corresponding gate descriptor is obtained from the IDT, and the selection, offset and descriptor attribute types are decomposed and checked. Descriptor can only be task door, 286 interrupt door, 286 trap door, 386 interrupt door or 386 trap door, otherwise it will cause general protection fault, error code is interrupt vector number multiplied by 8 plus 2. If a transfer is caused by an int n instruction or into instruction, check to see if the DPL in the interrupt door, trap door, or task door descriptor satisfies the CPL<=DPL (the DPL in the door is ignored for other exceptions or interrupts). This check avoids the use of interrupt vector numbers assigned to various devices when the application executes int n directives. If the check does not pass, it causes a general protection failure, the error code is the interrupt vector number multiplied by 8 plus 2. The P-bit in the door descriptor must be 1, indicating that the gate descriptor is a valid term, otherwise it will cause the segment to not be faulted, and the error code is the interrupt vector number multiplied by 8 plus 2. Finally, depending on the gate descriptor type, the break or exception handler is transferred. For exception handling, the return point is determined according to the exception type before starting the above steps, and if there is an error code, an error code that conforms to the error code format is formed, and the error code is pressed into the stack before the exception handler is actually executed. To guarantee the double word boundary alignment of the stack, the 16-bit error code is pressed in at 32-bit value, where the high 16-bit values are undefined, as are the 16-bit segments.

3. By interrupting the transfer of door or trap door

If the interrupt vector number indicates a gate descriptor that is a 386 interrupt gate or 386 trap Gate, then control is transferred to a handler procedure for the current task, and the privilege level can be transformed. The 48-bit full pointer to the handler is obtained from the interrupt door and the trap door, as is the call instruction for other calling doors. The 16-bit selector is the selector for the corresponding handler or code snippet, indicating the code snippet descriptor in the global descriptor GDT or the local descriptor Ldt; The 32-bit offset indicates the offset of the handler entry point within the code snippet. The transfer process by interrupting the door or trap door is shown as follows, and the process is automatically performed by the hardware. (1) If the selector is empty, a general protection fault is generated, and (2) the corresponding descriptor is taken; (3) A general protection failure is generated if the memory segment descriptor is not present, (4) The DPL is switched to the inner stack if there is no consistent code segment and the segment exists, (5) Adjusts the Rpl=0, (6) loads the descriptor into CS; (7) If the inlet deviation crosses the bounds, the general protection Fault is generated, (8) The eflags is pressed into the stack; (9) The CS presses into the stack, the EIP presses into the stack, (11) causes the tf=0,nt=0, (12) if is the interruption gate, causes if=0, (13) if has the error code, then presses the error code into the stack; (14) Transfer to the handler. Visible by the above transfer process, an interrupt door or trap door indicates that the selector of the handler must point to a descriptor describing an executable code snippet. If the selector is empty, a generic protection failure occurs, and the error code is 0. If the descriptor is not a code snippet descriptor, a generic protection failure is caused, and the error code contains the selector. Interrupts or exceptions can be transferred to the same privilege level or to the inner-level privilege level. The type and the DPL field in the descriptor of the handler code snippet above determine whether a transfer within this same task will occur with a privilege level transformation. If it is an inconsistent code snippet, and dplcpl produces a generic protection exception. The sixth step in the above transfer process is to "load the descriptor into CS", is to load the descriptor of the specified handler segment into a high speed buffer register of CS, in which other checks similar to the transfer through the calling gate are performed on the descriptor, including whether the code snippet descriptor and the code snippet descriptor exist, etc. Therefore, the exception may occur again. When the descriptor is checked, the DPL that considers only the code snippet is implemented by adjusting the rpl=0 of the selector in the door (adjusted inside the processor without affecting the RPL field of the selector in the memory), regardless of the rpl of the selector in the door. After the descriptor is loaded into CS, it is also checked to see whether the offset of the handler code segment entry is out of bounds, that is, whether it exceeds the paragraph boundary. If it crosses the line, it causes a generic protection failure with an error code of 0. From the transfer process can also be seen, the mark registers and breakpoints into the stack of the practice and the order and the real mode is the same, but here each stack operation is a double word, CS is expanded into 32-bit. This is also true in the 16-digit paragraph. Put the TF into0, which means that handlers are not allowed to step in. The NT is set to 0, which means that the handler returns to the same task instead of a nested task when it returns with the interrupt return instruction Iret. It should be noted that any privileged program can change the NT bit so that the interrupt or trap handler can be used to complete the task switch. The difference between the interruption of the gate and the transfer through the trap door is only the processing of the IF sign. For the interrupt door, the if is placed 0 in the transfer process, INTR interrupts are shielded during the execution of the handler (of course, in the interrupt handler, you can open the interrupt by artificially setting the IF flag so that the response is allowed to be masked during the execution of the handler); for the trap door, keep the IF bit unchanged during the transfer process, That is, if the IF bit turns out to be 1, then the INTR interrupt is allowed after the trap door is transferred to the handler. Therefore, the interrupt door is most suitable for processing interrupts, while trap doors are suitable for handling exceptions. In the case of an error code, the error code is pressed into the stack before being transferred to the processing program. Only exception handling can have an error code. The following figure shows the stack when the door or trap door is transferred through the interrupt. (a) is the case where there is no transform privilege level and no error code, (b) is the case where there is no error code for the transform privilege level, and (c) is the case where the transform privilege level and the inner stack with no error code are encountered. (d) is an inner stack case that transforms the privilege level and has an error code. Note that each item in the diagram is a double word.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.