Chinaunix

标题: 关于vmx_vcpu_run中ASM_VMX_VMWRITE_RSP_RDX的疑惑 [打印本页]

作者: littlenewer    时间: 2014-12-28 17:41
标题: 关于vmx_vcpu_run中ASM_VMX_VMWRITE_RSP_RDX的疑惑
vmx_vcpu_run在vmlaunch之前保存主机状态,如果说"mov %%" _ASM_SP ", %c[host_rsp](%0) \n\t"是把主机的rsp寄存器保存到vmcs中,那下一句ASM_VMX_VMWRITE_RSP_RDX起什么作用呢?

我查了下intel手册,vmwrite指令的功能是Writes the contents of a primary source operand (register or memory) to a specified field in a VMCS。从这个宏的名字看这两个操作数应该就是rsp和rdx,但这个时候rdx的值又是并不确定的。实在是想不明白。哪位大牛解释下

                "push %%" _ASM_DX "; push %%" _ASM_BP ";"
                "push %%" _ASM_CX " \n\t" /* placeholder for guest rcx */
                "push %%" _ASM_CX " \n\t"
                "cmp %%" _ASM_SP ", %c[host_rsp](%0) \n\t"
                "je 1f \n\t"
                "mov %%" _ASM_SP ", %c[host_rsp](%0) \n\t"
                __ex(ASM_VMX_VMWRITE_RSP_RDX) "\n\t"

作者: humjb_1983    时间: 2014-12-29 10:18
没看懂兄弟的问题。rdx不确定有啥问题呢?呵呵
作者: fanwenyi0529    时间: 2014-12-31 16:07
> 如果说"mov %%" _ASM_SP ", %c[host_rsp](%0) \n\t"是把主机的rsp寄存器保存到vmcs中

Absolutely wrong. 这句把rsp保存到vmx->host_rsp了

> ASM_VMX_VMWRITE_RSP_RDX起什么作用呢?

这句是把rsp的值写vmcs,field是HOST_RSP。
要注意后面的约束:
                ".global vmx_return \n\t"
                "vmx_return: " _ASM_PTR " 2b \n\t"
                ".popsection"
              : : "c"(vmx), "d"((unsigned long)HOST_RSP),
其中,"d"((unsigned long)HOST_RSP这句起到了确定rdx的作用,
gcc会在inline asm之前自动把rdx设置为HOST_RSP,同时rcx
设置为vmx的值。





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2