mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-02-19 22:59:36 +00:00
backend/rv64: Add biscuit as the assembler
This commit is contained in:
@@ -400,6 +400,8 @@ if ("arm64" IN_LIST ARCHITECTURE)
|
||||
endif()
|
||||
|
||||
if ("riscv" IN_LIST ARCHITECTURE)
|
||||
target_link_libraries(dynarmic PRIVATE biscuit::biscuit)
|
||||
|
||||
if ("A32" IN_LIST DYNARMIC_FRONTENDS)
|
||||
target_sources(dynarmic PRIVATE
|
||||
backend/riscv64/a32_address_space.cpp
|
||||
@@ -408,7 +410,6 @@ if ("riscv" IN_LIST ARCHITECTURE)
|
||||
backend/riscv64/a32_interface.cpp
|
||||
backend/riscv64/a32_jitstate.cpp
|
||||
backend/riscv64/a32_jitstate.h
|
||||
backend/riscv64/dummy_code_block.h
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class CodeBlock;
|
||||
} // namespace oaknut
|
||||
#elif defined(MCL_ARCHITECTURE_RISCV)
|
||||
namespace Dynarmic::Backend::RV64 {
|
||||
class DummyCodeBlock;
|
||||
class CodeBlock;
|
||||
} // namespace Dynarmic::Backend::RV64
|
||||
#else
|
||||
# error "Invalid architecture"
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
#elif defined(MCL_ARCHITECTURE_ARM64)
|
||||
void Register(oaknut::CodeBlock& mem, std::size_t mem_size);
|
||||
#elif defined(MCL_ARCHITECTURE_RISCV)
|
||||
void Register(RV64::DummyCodeBlock& mem, std::size_t mem_size);
|
||||
void Register(RV64::CodeBlock& mem, std::size_t mem_size);
|
||||
#else
|
||||
# error "Invalid architecture"
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@ void ExceptionHandler::Register(oaknut::CodeBlock&, std::size_t) {
|
||||
// Do nothing
|
||||
}
|
||||
#elif defined(MCL_ARCHITECTURE_RISCV)
|
||||
void ExceptionHandler::Register(RV64::DummyCodeBlock&, std::size_t) {
|
||||
void ExceptionHandler::Register(RV64::CodeBlock&, std::size_t) {
|
||||
// Do nothing
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
# include "dynarmic/backend/arm64/abi.h"
|
||||
#elif defined(MCL_ARCHITECTURE_RISCV)
|
||||
# include "dynarmic/backend/riscv64/dummy_code_block.h"
|
||||
# include "dynarmic/backend/riscv64/code_block.h"
|
||||
#else
|
||||
# error "Invalid architecture"
|
||||
#endif
|
||||
@@ -313,7 +313,7 @@ void ExceptionHandler::Register(oaknut::CodeBlock& mem, std::size_t size) {
|
||||
impl = std::make_unique<Impl>(code_begin, code_end);
|
||||
}
|
||||
#elif defined(MCL_ARCHITECTURE_RISCV)
|
||||
void ExceptionHandler::Register(RV64::DummyCodeBlock& mem, std::size_t size) {
|
||||
void ExceptionHandler::Register(RV64::CodeBlock& mem, std::size_t size) {
|
||||
const u64 code_begin = mcl::bit_cast<u64>(mem.ptr());
|
||||
const u64 code_end = code_begin + size;
|
||||
impl = std::make_unique<Impl>(code_begin, code_end);
|
||||
|
||||
42
src/dynarmic/backend/riscv64/code_block.h
Normal file
42
src/dynarmic/backend/riscv64/code_block.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* This file is part of the dynarmic project.
|
||||
* Copyright (c) 2024 MerryMage
|
||||
* SPDX-License-Identifier: 0BSD
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <new>
|
||||
|
||||
#include <biscuit/assembler.hpp>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace Dynarmic::Backend::RV64 {
|
||||
|
||||
class CodeBlock {
|
||||
public:
|
||||
explicit CodeBlock(std::size_t size)
|
||||
: memsize(size) {
|
||||
mem = (std::uint32_t*)mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
|
||||
if (mem == nullptr)
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
|
||||
~CodeBlock() {
|
||||
if (mem == nullptr)
|
||||
return;
|
||||
|
||||
munmap(mem, memsize);
|
||||
}
|
||||
|
||||
std::uint32_t* ptr() const {
|
||||
return mem;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::uint32_t* mem;
|
||||
std::size_t memsize = 0;
|
||||
biscuit::Assembler as;
|
||||
};
|
||||
} // namespace Dynarmic::Backend::RV64
|
||||
@@ -1,16 +0,0 @@
|
||||
/* This file is part of the dynarmic project.
|
||||
* Copyright (c) 2024 MerryMage
|
||||
* SPDX-License-Identifier: 0BSD
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Dynarmic::Backend::RV64 {
|
||||
|
||||
class DummyCodeBlock {
|
||||
public:
|
||||
DummyCodeBlock() {}
|
||||
|
||||
void* ptr() { return nullptr; }
|
||||
};
|
||||
} // namespace Dynarmic::Backend::RV64
|
||||
Reference in New Issue
Block a user