views:

287

answers:

3

I am trying to understand this inline assembly code which comes from _hypercall0 here.

asm volatile ("call hypercall_page+%c[offset]" \
        : "=r" (__res) \
        : [offset] "i" (__HYPERVISOR_##name * sizeof(hypercall_page[0])) \
        : "memory", "edi", "esi", "edx", "ecx", "ebx", "eax")

I am having trouble finding information on what %c in the first line means. I did not find any information in the most obvious section of the GCC manual, which explains %[name], but not %c[name]. Is there any other place I should look at?

A: 

Maybe this is useful: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

Zee Prime
I already looked at this. This HOWTO is quite old and doesn't say anything about the new syntax for operands, i.e. %[name]. I can't find anything about %c[name] either.
sigjuice
+2  A: 

Check the assembly output (with gcc -S, or maybe disassemble the object file) and it may be clearer.

My guess is that it stands for constant. hypercall_page looks like a table of instructions that each do a syscall. Maybe this will generate a call hypercall_page + {constant based on the expression given}, essentially having computed the address of this offset at compile time.

As an aside, this __HYPERVISOR##name stuff really reminds me of the __NR_name_of_syscall type convention you see for syscalls in Linux's <asm/unistd.h> and similar places.

asveikau
+7  A: 

From the GCC internals documentation:

`%c*digit*' can be used to substitute an operand that is a constant value without the syntax that normally indicates an immediate operand.

Ned