简体   繁体   English

x86_64内联汇编中%c的用途是什么?

[英]What's use of %c in x86_64 inline assembly?

I'm reading KVM source code and confronted with x86_64 inline assembly. 我正在阅读KVM源代码,并遇到了x86_64内联汇编。 In the following code, what's use of "%c"? 在以下代码中,“%c”的用途是什么? It it new feature in x86_64 inline assembly? 它是x86_64内联汇编中的新功能吗? Any reference for new features in x86_64 inline assembly in gcc? 对gcc x86_64内联汇编中的新功能有任何参考吗?

Many thanks 非常感谢

    /* Check if vmlaunch of vmresume is needed */
    "cmp $0, %1 \n\t"
    /* Load guest registers.  Don't clobber flags. */
#ifdef CONFIG_X86_64
    "mov %c[cr2](%3), %%rax \n\t"
    "mov %%rax, %%cr2 \n\t"
    "mov %c[rax](%3), %%rax \n\t"
    "mov %c[rbx](%3), %%rbx \n\t"
    "mov %c[rdx](%3), %%rdx \n\t"

You can see how this works at the end of the asm statement: 您可以在asm语句的末尾看到它的工作方式:

      : : "c"(vmx), "d"((unsigned long)HOST_RSP),
    [launched]"i"(offsetof(struct vcpu_vmx, launched)),
    [fail]"i"(offsetof(struct vcpu_vmx, fail)),
    [rax]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RAX])),
    [rbx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBX])),

The %3 (it's %0 in the my source tree) is a reference to the local variable vmx , and %c[rax] , %c[cr2] etc are the integer constant offsets of the corresponding values within the struct vcpu_vmx that vmx points to ( %c meaning "constant"). %3 (在我的源代码树中为%0 )是对局部变量vmx的引用, %c[rax]%c[cr2]等是vmxstruct vcpu_vmx中对应值的整数常量偏移量指向( %c表示“常量”)。

So the line: 所以这行:

mov %c[cr2](%0), %%rax

is moving the contents of vmx->vcpu.arch.cr2 into %rax . 正在将vmx->vcpu.arch.cr2的内容移动到%rax

It's an operand . 这是一个操作数 Basically lets you tie a C variable to a register. 基本上,您可以将C变量绑定到寄存器。 Should be valid for 32-bit as well, but there is probably some application-specific reason here to only use it for 64-bit. 对于32位也应该有效,但是这里可能有一些特定于应用程序的原因仅将其用于64位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM