Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "include/linux/libhc"]
path = include/linux/libhc
url = https://github.com/panda-re/libhc.git
107 changes: 2 additions & 105 deletions include/linux/hypercall.h
Original file line number Diff line number Diff line change
@@ -1,108 +1,5 @@
#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
Comment on lines 1 to +5

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

1 change: 1 addition & 0 deletions include/linux/libhc
Submodule libhc added at 7fce37