-
Notifications
You must be signed in to change notification settings - Fork 0
add libhc #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main_4.10
Are you sure you want to change the base?
add libhc #16
Conversation
#ifndef HYPERCALL_H | ||
#define HYPERCALL_H | ||
#include "linux/types.h" | ||
|
||
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_ARM64) | ||
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", "ebx", "ecx", "edx" // No clobber | ||
); | ||
#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_ARM64) | ||
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", "ebx", "ecx", "edx" | ||
); | ||
|
||
return reg0; | ||
#else | ||
#error "No igloo_hypercall2 support for architecture" | ||
#endif | ||
} | ||
|
||
#endif | ||
#include "libhc/hypercall.h" | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this file still exist? Shouldn't you just make all the places that include hypercall.h include libhc/hypercall.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The header guard and linux/types.h requirement is unique to the kernel. Though I'm now double checking that the linux types.h is true. If it's not then I'll just add the the header guard to libhc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types is no longer required for reasons I don't know.
No description provided.