Switch between user stack and kernel stack in case of interruption

Source: Internet
Author: User

If the task is in the user State when an interruption occursCodeIf the CPU is interrupted, the CPU privilege level changes from 3 to 0. At this time, the CPU will run the switch operation from user-mode stack to kernel-mode stack. The CPU obtains the segment selection and offset of the new stack from the task status segment TSS of the current task. Service InterruptionProgramIn the kernel, the Code belongs to the level 0 privileged level, so the 48-bit kernel state Stack pointer will be obtained from the ss0 and esp0 fields of the TSS. After locating the new stack (kernel state stack), the CPU will first press the original user State Stack pointer SS and ESP into the kernel state stack, then, the content of the eflags and the returned Location CS and EIP are pushed into the kernel state stack.
The system call of the kernel is a software interruption. Therefore, when the task calls the system call, it enters the kernel and executes the interrupt service code in the kernel. In this case, the kernel code will use the kernel state stack of the task for operations. Similarly, when you enter the kernel program, the stack segment, stack pointer, and eflags of the user State stack will be stored in the kernel state stack of the task due to a change in the privilege level. When iret is executed to exit the kernel program and return to the user program, the user State stack and eflags will be restored.
If a task is running in kernel state, stack switching is no longer required if the CPU response is interrupted. At this time, the kernel code running this task is already using the kernel state stack and does not involve changes in the priority level. Therefore, the CPU only pushes eflags and the returned pointer CS to the current kernel state stack, then, the service is interrupted.

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.