diff options
Diffstat (limited to 'debug/risc-v-gsp-rm-vm/sdk/injected_demo.c')
| -rw-r--r-- | debug/risc-v-gsp-rm-vm/sdk/injected_demo.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/debug/risc-v-gsp-rm-vm/sdk/injected_demo.c b/debug/risc-v-gsp-rm-vm/sdk/injected_demo.c new file mode 100644 index 0000000..8d836fe --- /dev/null +++ b/debug/risc-v-gsp-rm-vm/sdk/injected_demo.c @@ -0,0 +1,41 @@ +/* Example green-eye injected service. + * + * Position-independent, no globals, no libc: safe to load at any address. + * Commands (matching the demo firmware's injected command range): + * 1: xor a0 with 0xbeef + * 2: a0 + a1 + * 3: rotate a0 left by (a1 & 63) + * 4: a0 * 3 + 7 + * 5: min(a0, a1) + * 6: max(a0, a1) + * default: ~cmd + */ +#include "greeneye_service.h" + +__attribute__((noinline)) ge_u64 ge_demo_service_dispatch(ge_u64 cmd, ge_u64 a0, ge_u64 a1) +{ + switch (cmd) { + case 1: + return a0 ^ 0xbeefu; + case 2: + return a0 + a1; + case 3: { + unsigned int shift = (unsigned int)(a1 & 63u); + return shift ? ((a0 << shift) | (a0 >> (64u - shift))) : a0; + } + case 4: + return a0 * 3u + 7u; + case 5: + return a0 < a1 ? a0 : a1; + case 6: + return a0 > a1 ? a0 : a1; + default: + return ~cmd; + } +} + +/* A second entry point, to demonstrate multi-function services. */ +__attribute__((noinline)) ge_u64 ge_demo_service_answer(void) +{ + return 42; +} |
