JMP & call & RET privileged transfer & Process Scheduling

Source: Internet
Author: User

① JMP is not responsible for scheduling. It does not save any information, and it does not consider turning back. Skip this step.
② Call, save EIP, and so on, so that the program can jump back. RET is the inverse process of call and the process of turning back. This is an inherent CPU command, so we do not need to save the information. Run the command directly.
③ Privilege-level transfer within the same task, which is similar to ②, but you need to prepare a TSS and load it, and then call the door.
④ Process scheduling: the boundaries of processes are manually added. The CPU does not know that the process is to be switched or there are no specific process commands. Therefore, we need to save the process status ourselves.
The relationship above seems to be building a house. The higher the building, the more complicated the building.

 

JMP and call

The JMP command only redirects the execution process and does not save the return address.

The return address is saved before the call command is redirected to the target code, so that the RET command can be used to return to the next instruction of the Call Command for further execution. During intra-segment redirection, only the EIP is saved. For inter-segment redirection, CS is also saved.

For a jump using the Call Command (whether directly or through the call door), if the privilege level changes after the jump (always from low to high, you can see from the above 2nd points, the task status segment TSS must be prepared before the call command is executed. The redirection process is as follows: (1) Saving the caller's SS and ESP to the called Stack (2) the called parameters are saved in the called Stack first, and then copied to the called Stack (3) the current CS and EIP are saved to the called Stack. In a jump with a changed privilege level through call, the stack will be switched. In this case, the current stack pointer (SS: ESP) will be saved, and the current command pointer (Cs: EIP) will be saved) save to the new stack (called Stack), which is different from redirection without changing the privilege level. When no privilege level changes, you do not need to save SS: esp. There is no replication of call parameters, and there is no stack switching.


 

RET and retf

The functions of these two commands are called and returned.

(1) only EIP is obtained from the stack when RET is returned; F in retf indicates far, that is, Inter-segment transfer return. eip and Cs are obtained from the stack.

(2) Both commands can contain parameters, indicating the number of parameters when a process call occurs. to return a result, You need to exit the corresponding number of parameters from the stack.

(3) When Cs is restored, if the privilege level changes (the current low 2 bits of Cs are not equal to the two bits of the new Cs value obtained from the stack. From the above 2nd points, we know that only when the jump to a non-consistent code segment will the privileged level change, and only when the return from the non-consistent code segment will the privileged level return occur ), the ESP and SS are also obtained from the caller stack and restored to the corresponding register, that is, the caller stack is restored.

Task status segment TSS

To avoid mutual interference, different stacks must be used for code running at different privileged levels, that is, stack segments must be switched when the privileged levels change. The stack pointers of the 0, 1, and 2 privileged levels are stored in TSS. When the stack pointer jumps to the corresponding level, the corresponding Stack pointer is retrieved from the TSS for Stack switching. Because a new stack pointer must be obtained from TSS only when the stack pointer is redirected from the low-privilege level to the high-privilege level, there is no stack pointer of the lowest-privilege level 3 in TSS.

 

To sum up, there is only one complexity: CPL changes only when the caller jumps from the low-privilege level to the high-privilege level inconsistent code segment, stack switching occurs only when TSS is ready (a new stack pointer is obtained from the TSS before the call; the original Stack pointer is obtained from the called Stack for restoration when the call is returned ).

JMP & call & RET privileged transfer & Process Scheduling

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.