Skip to content

Commit

Permalink
Add RISCV support in libafl_qemu.h (#2380)
Browse files Browse the repository at this point in the history
* Add riscv support in libafl qemu header

---------

Co-authored-by: Romain Malmain <[email protected]>
  • Loading branch information
nine-point-eight-p and rmalmain authored Nov 4, 2024
1 parent 99a156f commit 97a8e4c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions libafl_qemu/runtime/libafl_qemu_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,56 @@
: "=r"(ret) \
: "r"(action), "r"(arg1), "r"(arg2) \
: "x0", "x1", "x2" \
); \
return ret; \
} \
#elif defined(__riscv) \
#define LIBAFL_DEFINE_FUNCTIONS(name, opcode) \
libafl_word LIBAFL_CALLING_CONVENTION _libafl_##name##_call0( \
libafl_word action) { \
libafl_word ret; \
__asm__ volatile ( \
"mv a0, %1\n" \
".word " XSTRINGIFY(opcode) "\n" \
"mv a0, a0\n" \
: "=r"(ret) \
: "r"(action) \
: "a0" \
); \
return ret; \
} \
\
libafl_word LIBAFL_CALLING_CONVENTION _libafl_##name##_call1( \
libafl_word action, libafl_word arg1) { \
libafl_word ret; \
__asm__ volatile ( \
"mv a0, %1\n" \
"mv a1, %2\n" \
".word " XSTRINGIFY(opcode) "\n" \
"mv %0, a0\n" \
: "=r"(ret) \
: "r"(action), "r"(arg1) \
: "a0", "a1" \
); \
return ret; \
} \
\
libafl_word LIBAFL_CALLING_CONVENTION _libafl_##name##_call2( \
libafl_word action, libafl_word arg1, libafl_word arg2) { \
libafl_word ret; \
__asm__ volatile ( \
"mv a0, %1\n" \
"mv a1, %2\n" \
"mv a2, %3\n" \
".word " XSTRINGIFY(opcode) "\n" \
"mv %0, a0\n" \
: "=r"(ret) \
: "r"(action), "r"(arg1), "r"(arg2) \
: "a0", "a1", "a2" \
); \
return ret; \
}

#else
#warning "LibAFL QEMU Runtime does not support your architecture yet, please leave an issue."
#endif
Expand Down

0 comments on commit 97a8e4c

Please sign in to comment.