forked from firmadyne/libnvram
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hypercall.h
125 lines (110 loc) · 3.5 KB
/
hypercall.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
static inline void igloo_hypercall(unsigned long num, unsigned long arg1) {
#if defined(CONFIG_MIPS)
register unsigned long reg0 asm("v0") = num;
register unsigned long reg1 asm("a0") = arg1;
asm volatile(
"movz $0, $0, $0"
: "+r"(reg0)
: "r"(reg1) // num in register v0
: "memory"
);
#elif defined(CONFIG_AARCH64)
register unsigned long reg0 asm("x8") = num;
register unsigned long reg1 asm("x0") = arg1;
asm volatile(
"msr S0_0_c5_c0_0, xzr \n"
: "+r"(reg1)
: "r"(reg0)
: "memory"
);
#elif defined(CONFIG_ARM)
register unsigned long reg0 asm("r7") = num;
register unsigned long reg1 asm("r0") = arg1;
asm volatile(
"mcr p7, 0, r0, c0, c0, 0"
: "+r"(reg1)
: "r"(reg0)
: "memory"
);
#elif defined(CONFIG_X86_64)
register unsigned long reg0 asm("rax") = num;
register unsigned long reg1 asm("rdi") = arg1;
asm volatile(
"cpuid"
: "+r"(reg0) // hypercall num + return value in rax
: "r"(reg1) // arguments
: "memory", "rbx", "rcx", "rdx"
);
#elif defined(CONFIG_I386)
register unsigned long reg0 asm("eax") = num;
register unsigned long reg1 asm("edi") = arg1;
asm volatile(
"cpuid"
: "+r"(reg0) // hypercall num + return value in rax
: "r"(reg1) // arguments
: "memory", "ebx", "ecx", "edx"
);
#else
#error "No igloo_hypercall support for architecture"
#endif
}
static inline unsigned long igloo_hypercall2(unsigned long num, unsigned long arg1, unsigned long arg2) {
#if defined(CONFIG_AARCH64)
register unsigned long reg0 asm("x8") = num;
register unsigned long reg1 asm("x0") = arg1;
register unsigned long reg2 asm("x1") = arg2;
asm volatile(
"msr S0_0_c5_c0_0, xzr \n"
: "+r"(reg1) // Input and output
: "r"(reg0), "r"(reg2)
: "memory"
);
return reg1;
#elif defined(CONFIG_ARM)
register unsigned long reg0 asm("r7") = num;
register unsigned long reg1 asm("r0") = arg1;
register unsigned long reg2 asm("r1") = arg2;
asm volatile(
"mcr p7, 0, r0, c0, c0, 0"
: "+r"(reg1) // Input and output
: "r"(reg0), "r"(reg2)
: "memory"
);
return reg1;
#elif defined(CONFIG_MIPS)
register unsigned long reg0 asm("v0") = num;
register unsigned long reg1 asm("a0") = arg1;
register unsigned long reg2 asm("a1") = arg2;
asm volatile(
"movz $0, $0, $0"
: "+r"(reg0) // Input and output in R0
: "r"(reg1) , "r" (reg2)// arg2 in register A1
: "memory"
);
return reg0;
#elif defined(CONFIG_X86_64)
register unsigned long reg0 asm("rax") = num;
register unsigned long reg1 asm("rdi") = arg1;
register unsigned long reg2 asm("rsi") = arg2;
asm volatile(
"cpuid"
: "+r"(reg0) // hypercall num + return value in rax
: "r"(reg1), "r"(reg2) // arguments
: "memory", "rbx", "rcx", "rdx"
);
return reg0;
#elif defined(CONFIG_I386)
register unsigned long reg0 asm("eax") = num;
register unsigned long reg1 asm("edi") = arg1;
register unsigned long reg2 asm("esi") = arg2;
asm volatile(
"cpuid"
: "+r"(reg0) // hypercall num + return value in rax
: "r"(reg1), "r"(reg2) // arguments
: "memory", "ebx", "ecx", "edx"
);
return reg0;
#else
#error "No igloo_hypercall2 support for architecture"
#endif
}