Skip to content

Conversation

caden-kline
Copy link
Contributor

No description provided.

Comment on lines 1 to +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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants