[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: [RFC][PATCH] Hypercalls from HVM guests (2/2) - Update



Here is an update to the previously posted test program for HVM hypercalls.
Just replace the previous version of this file with this version.

Signed-off-by: Steve Ofsthun <sofsthun@xxxxxxxxxxxxxxx>

Steve
--
Steve Ofsthun - Virtual Iron Software, Inc.
/******************************************************************************
 * hypercall.h
 *
 * Copyright (C) 2006, Virtual Iron Software, Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 */

#include <linux/version.h>
#include <asm/hypervisor.h>
#include <xen/interface/xen.h>

static inline int
check_amd(void)
{
        char id[12];

        __asm__ __volatile__(
                "cpuid"
                : "=b" (*(int *)(&id[0])),
                  "=c" (*(int *)(&id[8])),
                  "=d" (*(int *)(&id[4]))
                : "a" (0)
        );
        return __builtin_memcmp(id, "AuthenticAMD", 12) == 0;
}

#define VMCALL_INSTR    0x0f,0x01,0xc1
#define VMMCALL_INSTR   0x0f,0x01,0xd9

#define NR_hypercalls (PAGE_SIZE/32)

static inline void hypercall_page_init(void *hypercall_page)
{
    int i;
    char *p;
    char vmcall[3] = { VMCALL_INSTR };
    char vmmcall[3] = { VMMCALL_INSTR };
    int amd = check_amd();

    for ( i = 0; i < NR_hypercalls; i++ )
    {
        p = (char *)(hypercall_page + (i * 32));
        /*
         * This call sequence works for 32-bit and 64-bit guests.
         */
        memset(p, 0xcc, 32);
        *(u8  *)(p+ 0) = 0xb8;          /* mov $<i>,%eax */
        *(u32 *)(p+ 1) = i;
        if (amd) {
            *(u8  *)(p+ 5) = vmmcall[0];
            *(u8  *)(p+ 6) = vmmcall[1];
            *(u8  *)(p+ 7) = vmmcall[2];
        } else {
            *(u8  *)(p+ 5) = vmcall[0];
            *(u8  *)(p+ 6) = vmcall[1];
            *(u8  *)(p+ 7) = vmcall[2];
        }
        *(u8  *)(p+ 8) = 0xc3;          /* ret */
    }
}
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.