On 2019年04月25日 19:00, Borislav Petkov wrote:
On Thu, Apr 25, 2019 at 06:16:02PM +0800, Zhao, Yakui wrote:
The parameter register for the VMCALL is predefined in ACRN hypervisor. Now
the R8 is used to pass the hcall_id.
It seems that there is no special constraint for R8~R15.
So the explicit register variable is used so that the R8 can be passed.

If you're going to use the constraint "D" for param1, you can just as
well do

        "=a" (result)

everywhere since you have the letter constraint for %rax instead of
declaring it with "register".

Also, you can completely get rid of those "register" declarations
and let gcc have all the freedom to pass in hcall_id and the other
parameters:
Thanks Borislav for providing the code.

It seems that it is seldom used in kernel although the explicit register variable is supported by GCC and makes the code look simpler. And it seems that the explicit register variable is not suppoorted by CLAG.


So the explicit register variable will be removed. I will follow the asm code from Borislav. Of course one minor change is that the "movq" is used instead of "mov".

Is this ok?

Thanks


        unsigned long result;

         asm volatile("mov %[hcall_id], %%r8\n\t"
                      "vmcall\n\t"
                      : "=a" (result)
                      : [hcall_id] "g" (hcall_id)
                      : "r8");

         return result;

and %r8 will be in the clobber list so gcc will reload it if needed.

gcc turns it into

0000000000001040 <main>:
     1040:       4c 8b 05 e1 2f 00 00    mov    0x2fe1(%rip),%r8        # 4028 
<hcall_id>
     1047:       0f 01 c1                vmcall
     104a:       c3                      retq
     104b:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)

here.

Reply via email to