The realization of an operating system-transfer between different privilege levels

The occurrence of program transfer can be caused by the instruction jmp call ret sysenter sysexit int n or iret, or by interrupt and exception mechanism. This arm single-chip microcomputer is different. The essence of arm single-chip task switching is interrupt.

The jmp and call instructions can achieve the following 4 kinds of transfers:
1. The target operand contains the segment selector of the target code segment
2. The target operand points to a call gate descriptor that contains the target code segment selector
3. The target operand points to a target code segment. TSS of the code segment selector
4. The target operand points to a task gate, which points to a TSS containing the target code segment selector

From the description of CPL DPL in the previous section, there are too many restrictions on direct transfer through jmp and call, so the help of gate and TSS is needed.

BYTE7 BYTE6 BYTE5 BYTE4 BYTE3 BYTE2 BYTE1 BYTE0
31..16 Offset Attributes etc. Selector 15..0 offset

A gate describes the linear address specified by a selector and an offset, and the program is transferred through this address

The following code realizes that the target operand points to a call gate descriptor containing the selector of the target code segment

pmtest4.asm

This example is not very well reflected in the door and call the advantage over direct calls where
Suppose we want to transfer from Code A to Code B, use a call gate G, that is, call the target gate G of the code to point B of selectors Section, in fact, we have involved CPL, RPL, DPL of code B, (denoted as DPL_B), and DPL of the call gate (denoted as DPL_G).

A's access to the call gate of G is equivalent to accessing a data segment, requiring CPL and RPL to be higher than DPL_G.

Then G calls to visit B, you need to compare CPL and DPL_B.
If B is a code segment, requires less DPL_B CPL , i.e. B CPL privilege level is lower than
non-B if the code segment, when calling the call instruction, requires less DPL_B CPL
when calling the jmp instruction, only DPL_B = CPL

In summary, it can be seen that through the call gate and the call instruction, the transfer from low privilege level to high privilege level can be realized, regardless of whether the target code segment is consistent or inconsistent

At the same time, the change of privilege level also means that the stack will also change

Guess you like

Origin blog.csdn.net/u012323667/article/details/79373709
Recommended