--- /dev/null
+/*
+ Device File Virtualization Guest Preload Library Helpers
+
+ (c) Akhil Guliani and William Gross, 2015
+
+ Adapted from MPI module (c) 2012 Peter Dinda
+
+ Note that the calling convention here is a bit different
+ since we need to return errno
+
+
+*/
+
+#ifndef __HCALL__
+#define __HCALL__
+
+/*
+ Calling convention:
+
+64 bit:
+ rax = hcall number
+ rbx = 0x6464646464646464...
+ rcx = 1st arg
+ rdx = 2nd arg
+ rsi = 3rd arg
+ rdi = 4th arg
+ r8 = 5th arg
+ r9 = 6th arg
+ r10 = 7th arg
+ r11 = 8th arg
+
+32 bit:
+ eax = hcall number
+ ebx = 0x32323232
+ arguments on stack in C order (first argument is TOS)
+ arguments are also 32 bit
+
+In this convention,
+ RAX is assumed to be the return code from the system call
+ RBX is assumed to be the errno set by the system call
+
+ RAX comes back via rc
+ RBX comes back via overwrite of id
+*/
+#define HCALL64(rc,id,a,b,c,d,e,f,g,h) \
+ asm volatile ("movq %1, %%rax; " \
+ "pushq %%rbx; " \
+ "movq $0x6464646464646464, %%rbx; " \
+ "movq %2, %%rcx; " \
+ "movq %3, %%rdx; " \
+ "movq %4, %%rsi; " \
+ "movq %5, %%rdi; " \
+ "movq %6, %%r8 ; " \
+ "movq %7, %%r9 ; " \
+ "movq %8, %%r10; " \
+ "movq %9, %%r11; " \
+ "vmmcall ; " \
+ "movq %%rax, %0; " \
+ "movq %%rbx, %1; " \
+ "popq %%rbx; " \
+ : "=m"(rc),"=m"(id) \
+ : "m"(a), "m"(b), "m"(c), "m"(d), \
+ "m"(e), "m"(f), "m"(g), "m"(h) \
+ : "%rax","%rcx","%rdx","%rsi","%rdi", \
+ "%r8","%r9","%r10","%r11" \
+ )
+
+#define HCALL32(rc,id,a,b,c,d,e,f,g,h) \
+ asm volatile ("movl %1, %%eax; " \
+ "pushl %%ebx; " \
+ "movl $0x32323232, %%ebx; " \
+ "pushl %9;" \
+ "pushl %8;" \
+ "pushl %7;" \
+ "pushl %6;" \
+ "pushl %5;" \
+ "pushl %4;" \
+ "pushl %3;" \
+ "pushl %2;" \
+ "vmmcall ; " \
+ "movl %%eax, %0; " \
+ "movl %%ebx, %1; " \
+ "addl $32, %%esp; " \
+ "popl %%ebx; " \
+ : "=m"(rc), "=m"(id) \
+ : "m"(a), "m"(b), "m"(c), "m"(d), \
+ "m"(e), "m"(f), "m"(g), "m"(h) \
+ : "%eax" \
+ )
+
+#ifdef __x86_64__
+#define HCALL(rc,id,a,b,c,d,e,f,g,h) HCALL64(rc,id,a,b,c,d,e,f,g,h)
+#else
+#define HCALL(rc,id,a,b,c,d,e,f,g,h) HCALL32(rc,id,a,b,c,d,e,f,g,h)
+#endif
+
+#endif