2019-2020-1 20199305 "Linux kernel principle and Analysis" in the fifth week of work

Three-tier mechanism (on) system calls

(A) user mode and kernel mode interrupts

(1) Intel x86 CPU There are four different levels of execution

0,1,2,3, respectively, the smaller the number, the higher the privilege. Linux Caozuojitong employed in which only the two privilege levels 0 and 3, corresponding to the kernel mode and user mode. A very significant discrimination method is a user mode and kernel mode CS: EIP point range, when the kernel mode, CS: EIP values ​​may be arbitrary address, and in the user mode, this value is restricted. Interrupt handling is the main way to enter the kernel mode from user mode, the system calls a special interrupt. When the user mode to kernel mode is switched from the interrupt / int instruction register context saving state on user stack, wherein the stack comprises a user mode address, then the status word, then cs: eip values, as well as kernel-mode stack address, the status word kernel mode interrupt handler entry.

(2) a user mode and kernel mode:

  • User Mode: low-level instruction;

  • Kernel mode: execute a privileged instruction, accessing any physical address;

    Switch from user mode to kernel mode, there is generally the following three cases:

  • Of course, a system call;

  • Unusual events: When the CPU is executing the program running in user mode, some previously unknown anomalous events occur suddenly, this time turning kernel mode execution will trigger abnormal events associated with the current process from user mode execution, such as the typical page-missing fault;

    - Peripheral Interrupt: When a user requests the peripheral device to complete the operation, the CPU will issue an interrupt signal like, this time, the CPU executing the next instruction will be suspended is about to be performed, instead to execute the interrupt handler corresponding to the signal, If the instruction was previously executed in user mode, the user naturally transitions from state to state occur kernel.

Guess you like

Origin www.cnblogs.com/20199305yizihan/p/11707236.html