I'm reading KVM source code and confronted with x86_64 inline assembly. In the following code, what's use of "%c"? It it new feature in x86_64 inline assembly? Any reference for new features in x86_64 inline assembly in gcc?
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:
: : "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").
So the line:
mov %c[cr2](%0), %%rax
is moving the contents of vmx->vcpu.arch.cr2
into %rax
.
It's an operand . Basically lets you tie a C variable to a register. Should be valid for 32-bit as well, but there is probably some application-specific reason here to only use it for 64-bit.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.