iPXE
xen.h
Go to the documentation of this file.
00001 #ifndef _BITS_XEN_H
00002 #define _BITS_XEN_H
00003 
00004 /** @file
00005  *
00006  * Xen interface
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 /* Hypercall registers */
00013 #ifdef __x86_64__
00014 #define XEN_REG1 "rdi"
00015 #define XEN_REG2 "rsi"
00016 #define XEN_REG3 "rdx"
00017 #define XEN_REG4 "r10"
00018 #define XEN_REG5 "r8"
00019 #else
00020 #define XEN_REG1 "ebx"
00021 #define XEN_REG2 "ecx"
00022 #define XEN_REG3 "edx"
00023 #define XEN_REG4 "esi"
00024 #define XEN_REG5 "edi"
00025 #endif
00026 
00027 /** A hypercall entry point */
00028 struct xen_hypercall {
00029         /** Code generated by hypervisor */
00030         uint8_t code[32];
00031 } __attribute__ (( packed ));
00032 
00033 /**
00034  * Issue hypercall with one argument
00035  *
00036  * @v xen               Xen hypervisor
00037  * @v hypercall         Hypercall number
00038  * @v arg1              First argument
00039  * @ret retval          Return value
00040  */
00041 static inline __attribute__ (( always_inline )) unsigned long
00042 xen_hypercall_1 ( struct xen_hypervisor *xen, unsigned int hypercall,
00043                   unsigned long arg1 ) {
00044         register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
00045         unsigned long retval;
00046 
00047         __asm__ __volatile__ ( "call *%2"
00048                                : "=a" ( retval ), "+r" ( reg1 )
00049                                : "r" ( &xen->hypercall[hypercall] )
00050                                : XEN_REG2, XEN_REG3, XEN_REG4, XEN_REG5,
00051                                  "memory" );
00052         return retval;
00053 }
00054 
00055 /**
00056  * Issue hypercall with two arguments
00057  *
00058  * @v xen               Xen hypervisor
00059  * @v hypercall         Hypercall number
00060  * @v arg1              First argument
00061  * @v arg2              Second argument
00062  * @ret retval          Return value
00063  */
00064 static inline __attribute__ (( always_inline )) unsigned long
00065 xen_hypercall_2 ( struct xen_hypervisor *xen, unsigned int hypercall,
00066                   unsigned long arg1, unsigned long arg2 ) {
00067         register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
00068         register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
00069         unsigned long retval;
00070 
00071         __asm__ __volatile__ ( "call *%3"
00072                                : "=a" ( retval ), "+r" ( reg1 ), "+r" ( reg2 )
00073                                : "r" ( &xen->hypercall[hypercall] )
00074                                : XEN_REG3, XEN_REG4, XEN_REG5, "memory" );
00075         return retval;
00076 }
00077 
00078 /**
00079  * Issue hypercall with three arguments
00080  *
00081  * @v xen               Xen hypervisor
00082  * @v hypercall         Hypercall number
00083  * @v arg1              First argument
00084  * @v arg2              Second argument
00085  * @v arg3              Third argument
00086  * @ret retval          Return value
00087  */
00088 static inline __attribute__ (( always_inline )) unsigned long
00089 xen_hypercall_3 ( struct xen_hypervisor *xen, unsigned int hypercall,
00090                   unsigned long arg1, unsigned long arg2, unsigned long arg3 ) {
00091         register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
00092         register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
00093         register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
00094         unsigned long retval;
00095 
00096         __asm__ __volatile__ ( "call *%4"
00097                                : "=a" ( retval ), "+r" ( reg1 ), "+r" ( reg2 ),
00098                                  "+r" ( reg3 )
00099                                : "r" ( &xen->hypercall[hypercall] )
00100                                : XEN_REG4, XEN_REG5, "memory" );
00101         return retval;
00102 }
00103 
00104 /**
00105  * Issue hypercall with four arguments
00106  *
00107  * @v xen               Xen hypervisor
00108  * @v hypercall         Hypercall number
00109  * @v arg1              First argument
00110  * @v arg2              Second argument
00111  * @v arg3              Third argument
00112  * @v arg4              Fourth argument
00113  * @ret retval          Return value
00114  */
00115 static inline __attribute__ (( always_inline )) unsigned long
00116 xen_hypercall_4 ( struct xen_hypervisor *xen, unsigned int hypercall,
00117                   unsigned long arg1, unsigned long arg2, unsigned long arg3,
00118                   unsigned long arg4 ) {
00119         register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
00120         register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
00121         register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
00122         register unsigned long reg4 asm ( XEN_REG4 ) = arg4;
00123         unsigned long retval;
00124 
00125         __asm__ __volatile__ ( "call *%5"
00126                                : "=a" ( retval ), "+r" ( reg1 ), "+r" ( reg2 ),
00127                                  "+r" ( reg3 ), "+r" ( reg4 )
00128                                : "r" ( &xen->hypercall[hypercall] )
00129                                : XEN_REG5, "memory" );
00130         return retval;
00131 }
00132 
00133 /**
00134  * Issue hypercall with five arguments
00135  *
00136  * @v xen               Xen hypervisor
00137  * @v hypercall         Hypercall number
00138  * @v arg1              First argument
00139  * @v arg2              Second argument
00140  * @v arg3              Third argument
00141  * @v arg4              Fourth argument
00142  * @v arg5              Fifth argument
00143  * @ret retval          Return value
00144  */
00145 static inline __attribute__ (( always_inline )) unsigned long
00146 xen_hypercall_5 ( struct xen_hypervisor *xen, unsigned int hypercall,
00147                   unsigned long arg1, unsigned long arg2, unsigned long arg3,
00148                   unsigned long arg4, unsigned long arg5 ) {
00149         register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
00150         register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
00151         register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
00152         register unsigned long reg4 asm ( XEN_REG4 ) = arg4;
00153         register unsigned long reg5 asm ( XEN_REG5 ) = arg5;
00154         unsigned long retval;
00155 
00156         __asm__ __volatile__ ( "call *%6"
00157                                : "=a" ( retval ), "+r" ( reg1 ), "+r" ( reg2 ),
00158                                  "+r" ( reg3 ), "+r" ( reg4 ), "+r" ( reg5 )
00159                                : "r" ( &xen->hypercall[hypercall] )
00160                                : "memory" );
00161         return retval;
00162 }
00163 
00164 #endif /* _BITS_XEN_H */