Skip to content

Commit

Permalink
Switch to syscall abi (#13)
Browse files Browse the repository at this point in the history
* Switch to syscall abi
  • Loading branch information
caden-kline authored Jul 16, 2024
1 parent 73af6c9 commit 4b4856d
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions hypercall.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
static inline void igloo_hypercall(unsigned long num, unsigned long arg1) {
#if defined(CONFIG_MIPS)
register unsigned long a0 asm("a0") = num;
register unsigned long a1 asm("a1") = arg1;
register unsigned long v0 asm("v0") = num;
register unsigned long a0 asm("a0") = arg1;

asm volatile(
"movz $0, $0, $0"
: "+r"(a0) // Input and output in R0
: "r"(a1) // arg1 in register A1
: "+r"(v0)
: "r"(a0)
: "memory"
);

#elif defined(CONFIG_AARCH64)
register unsigned long long x0 asm("x0") = num;
register unsigned long long x1 asm("x1") = arg1;
register unsigned long long x0 asm("x8") = num;
register unsigned long long x1 asm("x0") = arg1;

asm volatile(
"mov x0, %0 \t\n\
mov x1, %1 \t\n\
"mov x8, %0 \t\n\
mov x0, %1 \t\n\
msr S0_0_c5_c0_0, xzr"
:
: "r"(x0), "r"(x1)
: "r"(x8), "r"(x0)
: "memory"
);
#elif defined(CONFIG_ARM)
register uint32_t r0 asm("r0") = num;
register uint32_t r1 asm("r1") = arg1;
register uint32_t r7 asm("r7") = num;
register uint32_t r0 asm("r0") = arg1;
asm volatile(
"mov r0, %0 \t\n\
mov r1, %1 \t\n\
"mov r7, %0 \t\n\
mov r0, %1 \t\n\
mcr p7, 0, r0, c0, c0, 0"
:
: "r"(r0), "r"(r1)
: "r"(r7), "r"(r0)
: "memory"
);
#else
Expand All @@ -40,22 +40,22 @@ static inline void igloo_hypercall(unsigned long num, unsigned long arg1) {

static inline unsigned long igloo_hypercall2(unsigned long num, unsigned long arg1, unsigned long arg2) {
#if defined(CONFIG_ARM)
register unsigned long r0 asm("r0") = num;
register unsigned long r1 asm("r1") = arg1;
register unsigned long r2 asm("r2") = arg2;
register unsigned long r7 asm("r7") = num;
register unsigned long r0 asm("r0") = arg1;
register unsigned long r1 asm("r1") = arg2;

asm volatile(
"mcr p7, 0, r0, c0, c0, 0"
: "+r"(r0) // Input and output
: "r"(r1), "r"(r2)
: "r"(r7), "r"(r1)
: "memory"
);

return r0;
#elif defined(CONFIG_AARCH64)
register unsigned long long x0 asm("x0") = num;
register unsigned long long x1 asm("x1") = arg1;
register unsigned long long x2 asm("x2") = arg2;
register unsigned long long x0 asm("x8") = num;
register unsigned long long x1 asm("x0") = arg1;
register unsigned long long x2 asm("x1") = arg2;

asm volatile(
"msr S0_0_c5_c0_0, xzr"
Expand All @@ -66,17 +66,17 @@ static inline unsigned long igloo_hypercall2(unsigned long num, unsigned long ar

return x0;
#elif defined(CONFIG_MIPS)
register unsigned long a0 asm("a0") = num;
register unsigned long a1 asm("a1") = arg1;
register unsigned long a2 asm("a2") = arg2;
register unsigned long v0 asm("v0") = num;
register unsigned long a0 asm("a0") = arg1;
register unsigned long a1 asm("a1") = arg2;

asm volatile(
"movz $0, $0, $0"
: "+r"(a0) // Input and output in R0
: "r"(a1) , "r" (a2)// arg1 in register A1
: "+r"(v0)
: "r"(a0) , "r" (a1)
: "memory"
);
return a0;
return v0;

#else
#error "No igloo_hypercall2 support for architecture"
Expand Down

0 comments on commit 4b4856d

Please sign in to comment.