6

This is code snipper from header.S file in kernel code. I could not understand what the lretw instruction does. I've checked out so many online sources for the instruction.

# We will have entered with %cs = %ds+0x20, normalize %cs so
# it is on par with the other segments.
        pushw   %ds 
        pushw   $6f 
        lretw

Can any one help me in understanding this instruction?

4

1 回答 1

6

ret是从过程返回的指令。所以基本上它将返回地址从堆栈中弹出到 EIP 寄存器中。

前缀在l这里表明它与过程相去甚远。在这种情况下,指令首先将堆栈中的一个值弹出到 EIP 寄存器中,然后将第二个值弹出到 CS 寄存器中。

后缀在w这里是因为在这一步我们在实模式下运行,操作数是 16 位宽。

确切的代码是:

    pushw   %ds
    pushw   $6f
    lretw
6:

这里6:非常重要。那么它的作用是:将 ds 的值压入堆栈,将6标签的地址压入堆栈,然后触发这lretw条指令。所以基本上,它将标签的地址加载6到指令指针寄存器中,并将cs寄存器的值加载到ds寄存器中。因此,这只是通过6更改cs寄存器值在标签处继续执行的技巧。

您应该下载http://www.intel.com/design/intarch/manuals/243191.htm,它提供了所有指令的精确详细信息,包括详细说明每条指令正在执行的操作的伪代码。

于 2011-09-08T07:43:11.777 回答