linux-0.11 stack switch for kernel tasks

Source: Internet
Author: User

http://blog.163.com/[email protected]/blog/static/86118492201212534924900/

Two problems that have been intertwined: how to identify the kernel stack and the user stack? How do I switch between the kernel-state stack and the user-state stack?

User-State stack pointers: SS and ESP;

Kernel-State stack pointers: Ss0 and esp0;

Both are located in the TSS structure of the task. The task here is to refer to Common tasks except tasks 0 and 1.

When the CPU switches from the user-state stack to the kernel-state stack, the CPU acquires the new stack's segment selector and offset value from TSS in the task status segment of the current task, which is obtained from the SS0 and Esp0 fields of the TSS, after locating the new stack (the kernel-state stack), The CPU first presses the original user-state stack pointer SS and ESP into the kernel-state stack and then presses the flag register eflags content and return position CS, and the EIP into the kernel-state stack.

When a task invokes a system call, it enters the kernel and executes the interrupt service code in the kernel, where the kernel code uses the kernel-state stack of the task to do so. The user-state stack and eflags are restored when the execution Iret exits the kernel program and returns to the user program.

TSS structure of the task:

linux-0.11 stack switch for kernel tasks

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.