Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Device File Virtualization Proof of Concept (Kernel+Preload)
[palacios.git] / gears / services / devfile / hcall.h
1 /* 
2    Device File Virtualization Guest Preload Library Helpers
3
4    (c) Akhil Guliani and William Gross, 2015
5      
6    Adapted from MPI module (c) 2012 Peter Dinda
7
8    Note that the calling convention here is a bit different
9    since we need to return errno 
10
11
12 */
13
14 #ifndef __HCALL__
15 #define __HCALL__
16
17 /*
18   Calling convention:
19
20 64 bit:
21   rax = hcall number
22   rbx = 0x6464646464646464...
23   rcx = 1st arg
24   rdx = 2nd arg
25   rsi = 3rd arg
26   rdi = 4th arg
27   r8  = 5th arg
28   r9  = 6th arg
29   r10 = 7th arg
30   r11 = 8th arg
31
32 32 bit:
33   eax = hcall number
34   ebx = 0x32323232
35   arguments on stack in C order (first argument is TOS)
36      arguments are also 32 bit
37
38 In this convention, 
39   RAX is assumed to be the return code from the system call
40   RBX is assumed to be the errno set by the system call
41
42   RAX comes back via rc
43   RBX comes back via overwrite of id
44 */
45 #define HCALL64(rc,id,a,b,c,d,e,f,g,h)                \
46   asm volatile ("movq %1, %%rax; "                    \
47                 "pushq %%rbx; "                       \
48                 "movq $0x6464646464646464, %%rbx; "   \
49                 "movq %2, %%rcx; "                    \
50                 "movq %3, %%rdx; "                    \
51                 "movq %4, %%rsi; "                    \
52                 "movq %5, %%rdi; "                    \
53                 "movq %6, %%r8 ; "                    \
54                 "movq %7, %%r9 ; "                    \
55                 "movq %8, %%r10; "                    \
56                 "movq %9, %%r11; "                    \
57                 "vmmcall ;       "                    \
58                 "movq %%rax, %0; "                    \
59                 "movq %%rbx, %1; "                    \
60                 "popq %%rbx; "                        \
61                 : "=m"(rc),"=m"(id)                   \
62                 : "m"(a), "m"(b), "m"(c), "m"(d),      \
63                   "m"(e), "m"(f), "m"(g), "m"(h)      \
64                 : "%rax","%rcx","%rdx","%rsi","%rdi", \
65                   "%r8","%r9","%r10","%r11"           \
66                 )
67
68 #define HCALL32(rc,id,a,b,c,d,e,f,g,h)                \
69   asm volatile ("movl %1, %%eax; "                    \
70                 "pushl %%ebx; "                       \
71                 "movl $0x32323232, %%ebx; "           \
72                 "pushl %9;"                           \
73                 "pushl %8;"                           \
74                 "pushl %7;"                           \
75                 "pushl %6;"                           \
76                 "pushl %5;"                           \
77                 "pushl %4;"                           \
78                 "pushl %3;"                           \
79                 "pushl %2;"                           \
80                 "vmmcall ;       "                    \
81                 "movl %%eax, %0; "                    \
82                 "movl %%ebx, %1; "                    \
83                 "addl $32, %%esp; "                   \
84                 "popl %%ebx; "                        \
85                 : "=m"(rc), "=m"(id)                  \
86                 : "m"(a), "m"(b), "m"(c), "m"(d),      \
87                 "m"(e), "m"(f), "m"(g), "m"(h)        \
88                 : "%eax"                              \
89                 )
90
91 #ifdef __x86_64__
92 #define HCALL(rc,id,a,b,c,d,e,f,g,h)  HCALL64(rc,id,a,b,c,d,e,f,g,h)
93 #else
94 #define HCALL(rc,id,a,b,c,d,e,f,g,h)  HCALL32(rc,id,a,b,c,d,e,f,g,h)   
95 #endif
96
97 #endif