diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6e66119 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libhc"] + path = libhc + url = https://github.com/panda-re/libhc.git diff --git a/hypercall.h b/hypercall.h deleted file mode 100644 index a5fcc42..0000000 --- a/hypercall.h +++ /dev/null @@ -1,125 +0,0 @@ -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 -} diff --git a/libhc b/libhc new file mode 160000 index 0000000..7fce376 --- /dev/null +++ b/libhc @@ -0,0 +1 @@ +Subproject commit 7fce37676725fe62544fdda3618ae9f680a9ecf5 diff --git a/package.sh b/package.sh index dacb41b..851cde7 100755 --- a/package.sh +++ b/package.sh @@ -9,42 +9,42 @@ mkdir /app/out SCRATCH=$(mktemp -d)/libnvram mkdir $SCRATCH -CC=arm-linux-musleabi-gcc make CFLAGS="-DCONFIG_ARM=1" libnvram.so -C /app +CC=arm-linux-musleabi-gcc make libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.armel mv libnvram.so $SCRATCH/libnvram.so.armel make clean -CC=arm-linux-musleabihf-gcc make CFLAGS="-DCONFIG_ARM=1 -mfloat-abi=hard" libnvram.so -C /app +CC=arm-linux-musleabihf-gcc make CFLAGS="-mfloat-abi=hard" libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.armelhf mv libnvram.so $SCRATCH/libnvram.so.armelhf make clean -CC=aarch64-linux-musl-gcc make CFLAGS="-DCONFIG_AARCH64=1" libnvram.so -C /app +CC=aarch64-linux-musl-gcc make libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.aarch64 mv libnvram.so $SCRATCH/libnvram.so.aarch64 make clean -CC=mipsel-linux-musl-gcc make CFLAGS="-DCONFIG_MIPS=1 -march=mips32r2" libnvram.so -C /app +CC=mipsel-linux-musl-gcc make CFLAGS="-march=mips32r2" libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.mipsel mv libnvram.so $SCRATCH/libnvram.so.mipsel make clean -CC=mipseb-linux-musl-gcc make CFLAGS="-DCONFIG_MIPS=1 -march=mips32r2" libnvram.so -C /app +CC=mipseb-linux-musl-gcc make CFLAGS="-march=mips32r2" libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.mipseb mv libnvram.so $SCRATCH/libnvram.so.mipseb make clean -CC=mips64eb-linux-musl-gcc make CFLAGS="-DCONFIG_MIPS=1 -march=mips64r2 -mabi=64" libnvram.so -C /app +CC=mips64eb-linux-musl-gcc make CFLAGS="-march=mips64r2 -mabi=64" libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.mips64eb mv libnvram.so $SCRATCH/libnvram.so.mips64eb make clean -CC=x86_64-linux-musl-gcc make CFLAGS="-DCONFIG_X86_64=1" libnvram.so -C /app +CC=x86_64-linux-musl-gcc make libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.x86_64 mv libnvram.so $SCRATCH/libnvram.so.x86_64 make clean -CC=i686-linux-musl-gcc make CFLAGS="-DCONFIG_I386=1" libnvram.so -C /app +CC=i686-linux-musl-gcc make libnvram.so -C /app mv nvram.o $SCRATCH/nvram.o.i386 mv libnvram.so $SCRATCH/libnvram.so.i386 make clean diff --git a/strings.h b/strings.h index 9f14b8a..cfa445e 100644 --- a/strings.h +++ b/strings.h @@ -1,7 +1,7 @@ #ifndef INCLUDE_STRINGS_H #define INCLUDE_STRINGS_H -#include "hypercall.h" +#include "libhc/hypercall.h" #include #define PAGE_IN(s) igloo_page_in_str((volatile const char *)(s))