From 3e8618a9de53340aa7ad3aaf211a58cfb6f1e220 Mon Sep 17 00:00:00 2001 From: jamcleod Date: Wed, 1 Nov 2023 02:28:27 -0400 Subject: [PATCH 1/2] Move from hypercall.h to libhc as a submodule --- .gitmodules | 3 + include/hypercall.h | 193 ------------------------------------------ include/libhc | 1 + libhypernvram/nvram.c | 2 +- tests/hc_test.c | 2 +- 5 files changed, 6 insertions(+), 195 deletions(-) create mode 100644 .gitmodules delete mode 100644 include/hypercall.h create mode 160000 include/libhc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5bc42b5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "include/libhc"] + path = include/libhc + url = https://github.com/panda-re/libhc diff --git a/include/hypercall.h b/include/hypercall.h deleted file mode 100644 index ea34b64..0000000 --- a/include/hypercall.h +++ /dev/null @@ -1,193 +0,0 @@ -#ifndef MAGIC_VALUE -#error Needs MAGIC_VALUE -#endif -#define RETRY 0xDEADBEEF -// #if defined(__x86_64__) -#if defined(__x86_64__) -static inline int hc(int hc_type, void **s,int len) { - uint64_t eax = hc_type; - uint64_t ret = hc_type; - int y = 0; - do { - ret = MAGIC_VALUE; - volatile int x = 0; - for(int i = 0; i< len; i++) { - x |= *(((int*)s[i])+y); - } - asm __volatile__( - "movq %1, %%rax \t\n\ - movq %2, %%rdi \t\n\ - movq %3, %%rsi \t\n\ - cpuid \t\n\ - mov %%rax, %0 \t\n" - : "=m" (ret) /* output operand */ - : "g" (eax), "g" (hc_type), "g" (len), "g" (s) /* input operands */ - : "rdi", "rsi", "rdx", "eax" /* clobbered registers */ - ); - } while (ret == RETRY); - // #ifdef CONTROL - // if (ret & CONTROL == CONTROL) { - // control(ret & CONTROL_MASK); - // } - // #endif - return ret; -} -#elif defined(__i386__) && !defined(__x86_64__) -static inline int hc(int hc_type,void **s,int len) { - int eax = MAGIC_VALUE; - int ret = MAGIC_VALUE; - int y = 0; - do { - ret = MAGIC_VALUE; - volatile int x = 0; - for(int i = 0; i< len; i++) { - x |= *(((int*)s[i])+y); - } - y++; - asm __volatile__( - "mov %1, %%eax \t\n\ - mov %2, %%ebx \t\n\ - mov %3, %%ecx \t\n\ - mov %4, %%edx \t\n\ - cpuid \t\n\ - mov %%eax, %0 \t\n" - : "=g" (ret) /* output operand */ - : "g" (eax), "g" (hc_type), "g" (len), "g" (s) /* input operands */ - : "eax", "ebx", "ecx", "edx" /* clobbered registers */ - ); - } while (ret == RETRY); - // #ifdef CONTROL - // if (ret & CONTROL == CONTROL) { - // control(ret & CONTROL_MASK); - // } - // #endif - return ret; -} -#elif defined(__arm__) -static inline __attribute__((always_inline)) int hc(int hc_type, void **s, int len) { - int ret = MAGIC_VALUE; - int y = 0; - do { - ret = MAGIC_VALUE; - volatile int x = 0; - for (int i = 0; i < len; i++) { - x |= *(((int*) s[i]) + y); - } - y++; - asm __volatile__( - "mov %%r7, %1 \t\n\ - mov %%r0, %2 \t\n\ - mov %%r1, %3 \t\n\ - mov %%r2, %4 \t\n\ - mov %%r3, %5 \t\n\ - mcr p7, 0, r0, c0, c0, 0 \t\n\ - mov %0, %%r0 \t\n" - : "=g"(ret) /* no output registers */ - : "r" (MAGIC_VALUE), "r" (hc_type), "r" (s), "r" (len), "r" (0) /* input registers */ - : "r0", "r1", "r2", "r3", "r4", "r7" /* clobbered registers */); - } while (ret == RETRY); - // #ifdef CONTROL - // if (ret & CONTROL == CONTROL) { - // control(ret & CONTROL_MASK); - // } - // #endif - return ret; -} -#elif defined(__mips64) -static inline int hc(int hc_type, void **s, int len) { - int ret = MAGIC_VALUE; - volatile int x = 0; - int y = 0; - do { - ret = MAGIC_VALUE; - volatile int x = 0; - for(int i = 0; i < len; i++) { - x |= *(((int*)s[i]) + y); - } - y++; - - asm __volatile__( - "move $2, %1\t\n" - "move $4, %2\t\n" - "move $5, %3\t\n" - "move $6, %4\t\n" - "movz $0, $0, $0\t\n" - "move %0, $2\t\n" - : "=g"(ret) /* output operand */ - : "r" (MAGIC_VALUE), "r" (hc_type), "r" (s), "r" (len) /* input operands */ - : "a0", "a1", "a2", "a3" /* clobbered registers */ - ); - } while (ret == RETRY); - // #ifdef CONTROL - // if (ret & CONTROL == CONTROL) { - // control(ret & CONTROL_MASK); - // } - // #endif - return ret; -} -#elif defined(mips) || defined(__mips__) || defined(__mips) -static inline int hc(int hc_type,void **s,int len) { - int ret; - int y = 0; - do { - ret = MAGIC_VALUE; - volatile int x = 0; - y++; - for(int i = 0; i < len; i++) { - x |= *(((int*) s[i]) + y); - } - - asm __volatile__( - "move $2, %1\t\n" - "move $4, %2\t\n" - "move $5, %3\t\n" - "move $6, %4\t\n" - "movz $0, $0, $0\t\n" - "move %0, $2\t\n" - : "=g"(ret) /* output operand */ - : "r" (MAGIC_VALUE), "r" (hc_type), "r" (s), "r" (len) /* input operands */ - : "a0", "a1", "a2", "a3" /* clobbered registers */ - ); - } while (ret == RETRY); - // #ifdef CONTROL - // if (ret & CONTROL == CONTROL) { - // control(ret & CONTROL_MASK); - // } - // #endif - return ret; -} -#elif defined(__aarch64__) -static inline __attribute__((always_inline)) int hc(int hc_type, void **s,int len) { - int ret = MAGIC_VALUE; - int y = 0; - do { - ret = MAGIC_VALUE; - volatile int x = 0; - for(int i = 0; i < len; i++) { - x |= *(((int*) s[i]) + y); - } - asm __volatile__("stp x0, x1, [sp, #-16]! \t\n\ - stp x2, x3, [sp, #-16]! \t\n\ - mov x8, %1 \t\n\ - mov x0, %2 \t\n\ - mov x1, %3 \t\n\ - mov x2, %4 \t\n\ - msr S0_0_c5_c0_0, xzr \t\n\ - mov %0, x0 \t\n\ - ldp x0, x1, [sp], #16 \t\n\ - ldp x2, x3, [sp], #16 \t\n" - : "=g"(ret) /* no output registers */ - : "r" (MAGIC_VALUE), "r" (hc_type), "r" (s), "r" (len), "r" (0) /* input registers */ - : "x0", "x1", "x2", "x3", "x4" /* clobbered registers */ - ); - } while (ret == RETRY); - // #ifdef CONTROL - // if (ret & CONTROL == CONTROL) { - // control(ret & CONTROL_MASK); - // } - // #endif - return ret; -} -#else -#error Unsupported platform. -#endif diff --git a/include/libhc b/include/libhc new file mode 160000 index 0000000..252d804 --- /dev/null +++ b/include/libhc @@ -0,0 +1 @@ +Subproject commit 252d804be35532a415d81d8b8daf90dc6be170c6 diff --git a/libhypernvram/nvram.c b/libhypernvram/nvram.c index e3e5570..04a92ae 100644 --- a/libhypernvram/nvram.c +++ b/libhypernvram/nvram.c @@ -17,7 +17,7 @@ #include "alias.h" #include "nvram.h" #include "config.h" -#include "hypercall.h" +#include "libhc/hypercall.h" /* Generate variable declarations for external NVRAM data. */ #define NATIVE(a, b) diff --git a/tests/hc_test.c b/tests/hc_test.c index 4023979..d4e6f5e 100644 --- a/tests/hc_test.c +++ b/tests/hc_test.c @@ -1,6 +1,6 @@ #include #define MAGIC_VALUE 5 -#include "hypercall.h" +#include "libhc/hypercall.h" #include #include From d18a4e6bc6b0caebc8449f798c97ca5327b49880 Mon Sep 17 00:00:00 2001 From: jamcleod Date: Wed, 1 Nov 2023 02:40:23 -0400 Subject: [PATCH 2/2] Fix CI not checking out submodules --- .github/workflows/build.yml | 3 ++- .github/workflows/tests.yml | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bca6e82..39437ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,7 @@ jobs: - name: Build run: | + git submodule update --init docker run --rm -v $PWD:/app -w /app ghcr.io/panda-re/embedded-toolchains:latest /app/build.sh tar -czvf build.tar.gz build @@ -52,4 +53,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - id: ${{ steps.create_release.outputs.id }} \ No newline at end of file + id: ${{ steps.create_release.outputs.id }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8c670cd..f3d29c2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,8 +12,10 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + submodules: true - name: Build run: | docker run --rm -v $PWD:/app -w /app ghcr.io/panda-re/embedded-toolchains:latest /app/build.sh - \ No newline at end of file +