Skip to content

Commit

Permalink
Add RISCVM_SILENT_PANIC option
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Jun 20, 2024
1 parent 53f0fe9 commit e3bf776
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 7 additions & 0 deletions riscvm/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions riscvm/cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RISCVM_DIRECT_DISPATCH = false
RISCVM_CODE_ENCRYPTION = true
RISCVM_OPCODE_SHUFFLING = true
RISCVM_DEBUG_SYSCALLS = true
RISCVM_SILENT_PANIC = false

[target.riscvm]
type = "executable"
Expand All @@ -17,6 +18,7 @@ RISCVM_DIRECT_DISPATCH.compile-definitions = ["DIRECT_DISPATCH"]
RISCVM_CODE_ENCRYPTION.compile-definitions = ["CODE_ENCRYPTION"]
RISCVM_OPCODE_SHUFFLING.compile-definitions = ["OPCODE_SHUFFLING"]
RISCVM_DEBUG_SYSCALLS.compile-definitions = ["DEBUG_SYSCALLS"]
RISCVM_SILENT_PANIC.compile-definitions = ["SILENT_PANIC"]
clang-cl.compile-options = ["/clang:-fno-jump-tables", "/clang:-mno-sse"]
clang.compile-options = ["-fno-jump-tables", "-mno-sse"]
msvc.link-options = ["/DYNAMICBASE:NO", "/INCREMENTAL:NO"]
Expand Down
18 changes: 11 additions & 7 deletions riscvm/riscvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ extern bool g_trace;
#define log(...)
#define logw(...)

#define panic(...) __debugbreak();
#if defined(SILENT_PANIC)
#define panic(...) return false
#else
#define panic(...) __debugbreak()
#endif

#if defined(__GNUC__) || defined(__clang__)
#define ALWAYS_INLINE [[gnu::always_inline]]
Expand Down Expand Up @@ -82,7 +86,7 @@ struct riscvm
uint64_t regs[32];

#ifdef _DEBUG
FILE* trace;
FILE* trace;
int64_t rebase;
#endif // _DEBUG

Expand Down Expand Up @@ -252,27 +256,27 @@ enum RegIndex
#include "opcodes.h"
#endif // OPCODE_SHUFFLING

template <typename T> ALWAYS_INLINE static T riscvm_read(uint64_t addr)
template <typename T> ALWAYS_INLINE T riscvm_read(uint64_t addr)
{
T data;
memcpy(&data, (const void*)addr, sizeof(data));
return data;
}

template <typename T> ALWAYS_INLINE static void riscvm_write(uint64_t addr, T val)
template <typename T> ALWAYS_INLINE void riscvm_write(uint64_t addr, T val)
{
memcpy((void*)addr, &val, sizeof(val));
}

ALWAYS_INLINE static void* riscvm_getptr(riscvm_ptr self, uint64_t addr)
ALWAYS_INLINE inline void* riscvm_getptr(riscvm_ptr self, uint64_t addr)
{
return (void*)addr;
}

ALWAYS_INLINE static int32_t bit_signer(uint32_t field, uint32_t size)
ALWAYS_INLINE inline int32_t bit_signer(uint32_t field, uint32_t size)
{
return (field & (1U << (size - 1))) ? (int32_t)(field | (0xFFFFFFFFU << size)) : (int32_t)field;
}

void riscvm_loadfile(riscvm_ptr self, const char* filename);
void riscvm_run(riscvm_ptr self);
extern "C" __declspec(dllexport) void riscvm_run(riscvm_ptr self);

0 comments on commit e3bf776

Please sign in to comment.