Linux system calls and interrupts resolution

Linux system calls and interrupts resolution

Structure diagram of the system calls and interrupts

Author: tomato flavor BAK
link: https://www.zhihu.com/question/30432536/answer/54998416
Source: know almost
copyrighted by the author. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

Interrupt : also known as asynchronous interrupts , other hardware in accordance with the CPU clock signal generated randomly 's. Interruption has been divided into maskable hardware interrupts and non-maskable interrupts . Computer courses in principle, there are two processor pins NMI and INTR responsible for receiving an interrupt signal, as well as Advanced Programmable Interrupt Controller (APIC), such as the 8259A management interrupt signal. Hardware interrupts may be shielded: Any INTR to the processor or by a local APIC interrupt signals are referred maskable hardware interrupt, IRQ (Interrupt ReQuest) generated by the IO devices are maskable hardware interrupt. However, by passing the INTR pin maskable hardware interrupt may be defined using the Intel architecture the interrupt vector (0-255), and some local APIC transmitted using only a vector number 16-255. If the interrupt signal is transmitted over the pin NMI, it occurs is a non-maskable interrupt.

Like our common, keyboard, network card input is asynchronous interrupts , asynchronous interrupts (hardware interrupt) processing in assembly language we have learned a

Once the non-maskable interrupt request source, cpu must unconditionally respond, and for the maskable interrupt request source, cpu response, may not respond. cpu interrupt request is generally provided two input lines: Maskable interrupt request INTR (Interrupt Require) and a non-maskable interrupt request NMI (Nonmaskable Interrupt). For maskable interrupts, itself controlled by the addition of mask bits, but also are subject to an overall control, i.e., interrupt control register enable flag IF (Interrupt Flag) flags in the CPU, the IF bit is 1, can be obtained CPU response, otherwise, no response. IF bit can be user-controlled, or STI instruction Enable Turbo c of () function, the 1 (on break) IF position, the Disable command of CLI or Turbo_c () function, the IF bit to 0 (off interrupt).

Typical examples of non-maskable interrupt source is power failure , once there, you must respond immediately and unconditionally, or perform any other work is meaningless.

Typical examples of maskable interrupt source is interrupt printer , printer response to CPU interrupt request can be faster, can also be slower because the printer waits for children to make is entirely possible.
----------------
Disclaimer: This article is CSDN blogger "lidandan2016 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https://blog.csdn.net/lidandan2016/java/article/details/53437273

Abnormal : also known as synchronous interrupts , when the instruction is executed CPU control unit produces , and is called synchronous, because the CPU will be issued only after executing one instruction interrupt termination. At the same time without losing the continuity of the implementation process, caused by abnormal instruction whether to re-execute, and according to the way they were reported, disorders fall into error , trap , and terminate three cases.

Error : an error can be corrected generally be abnormal, once corrected, the program can then be executed without loss of continuity. When reporting an error occurs, the processor will restore the machine state to the state prior to execution errors. From the instruction after the error handling routine return address pointing to a wrong instruction, rather than the error command. Such as page errors.

Trap : When the instruction that caused the trap to occur, immediately generating the exception. Trap allow the program to continue without losing continuity. Trap handling routine instruction that caused the trap return address pointing to the next instruction (the difference in nature of the error). Such as overflow.

Termination : it does not always produce the report to determine the position command exception, not allowed to cause the termination of the process or re-execute the task. Such as bus errors cause abnormal termination.


Linux in the interrupt vector:

0-19 interrupt vector corresponding to the non-maskable interrupt and exception.

20-31Intel reserved

32-127 Maskable hardware interrupts

Abnormal programmable for system calls 128

129-238 Maskable hardware interrupts

239 local APIC timer interrupt

240 local APIC interrupt high temperature

241-250 reserved for future use by the Linux

Inter-processor interrupt 251-253

254 local APIC error interrupt

Local APIC 255 dummy interrupt (CPU when an interrupt is generated in the mask)

Also known as soft interrupt programming abnormalities, mainly for system calls, ie * int 0x80 * debugger and to inform a specific event, so a soft interrupt is abnormal, are synchronous interrupt.

Our system call is implemented based soft interrupt: Note that I say is based on soft interrupt system calls are implemented, not that soft system call is interrupted! This point of view the system call the following principles will know

Linux systems process interrupts and calls

After we focus on system calls, exceptions and other hardware interrupts, so we put in after referred to as interrupt hardware interrupt, also use exceptions, system call to show distinction

Interrupts, exceptions and system calls the process flow

With this pair of figure we can see, the interaction between user and kernel mainly through the system call, and between the kernel and device mainly through external hardware interrupt

Execution of system calls

  1. Issuing a system call (int 0x80, sysenter, syscall) Certain instructions

    The int 0x80 is a programmable system calls for exception , of course, this is just one of the ways to achieve, due to the poor performance of the system calls initiated by the interrupt mode, the CPU and the newer kernels support the use of these two syscall sysenter and special instructions to initiate a system call. Wherein sysenter using 32-bit system, the corresponding instruction to exit sysexit; syscall in 64-bit system, the corresponding instruction exit sysret.

  2. CPU is switched from user mode to kernel mode, some registers and environmental settings

  3. System_call kernel function call, the system call number by the system call table acquiring a corresponding service routine

  4. System call handler

  5. Using a specific instruction calls return to user mode (iret, sysexit, sysret) from the system

We can see, and different hardware interrupt, software interrupt basically by the operating system kernel process. And all the system calls only use one interrupt vector

Execution hardware interrupts

  1. The drive device its own interrupt handler into the kernel, the kernel is loaded when the interrupt vector table initialization, interrupt vector table function has a driver in the interrupt vector interrupt processing

Interrupt Vector: is an interrupt service routine entry address offset with the segment base value, a 4-byte interrupt vector occupies space. Interrupt vector table is the most low-end system memory 8088 1K bytes of space, its role is in accordance with the type of interrupt number in ascending order of storage corresponding interrupt vector, a total of 256 interrupt vectors stored. In the interrupt process, the CPU by calculating the interrupt type number (interrupt vector number) interface circuit corresponding to the acquired position vector in the table of interrupt, and obtain the interrupt vector from the interrupt vector table, the program flow to the interrupt service routine entry address.

  1. In the CPU instruction execution week ending cycle of detection to check interrupt, the interrupt cycle has entered interrupt request and can handle, start doing the preparatory work, save breakpoints, determine the interrupt vector (interrupt handler entry address), and then set to PC, then it is fetched and executed.

  2. The bottom of the external device and the computer used for communication is interrupted: hardware (for example, pressed the keyboard) triggers an electrical signal, the signal through the break to reach the interrupt controller i8259A, i8259A after this signal is received, the CPU sends INT signal application CPU to perform just the hardware operations, and will interrupt type number was also sent to CPU

  3. After the CPU interrupt to check the interrupt vector table, find the interrupt service routine, routine calls the communication between the corresponding device driver with an external device

It can be seen in the basic hardware interrupts the CPU work, relates in part to the operating system kernel rarely

As well as details about the interrupt vector to achieve, you can look at this article: https://www.cnblogs.com/frankyou/p/8649435.html

Reference

  1. https://blog.csdn.net/weixin_41376979/article/details/83756975?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
  2. https://www.cnblogs.com/answercard/p/4288431.html
  3. https://www.zhihu.com/question/30432536
  4. https://blog.csdn.net/dillanzhou/java/article/details/82733562
  5. https://www.cnblogs.com/frankyou/p/8649435.html

Guess you like

Origin www.cnblogs.com/jiading/p/12606978.html