backend/rv64: Add biscuit as the assembler

This commit is contained in:
Yang Liu 2023-12-31 18:09:00 +08:00 committed by Merry
parent a4b9b431b0
commit 4324b262aa
11 changed files with 86 additions and 22 deletions

View file

@ -130,6 +130,7 @@ message(STATUS "Target architecture: ${ARCHITECTURE}")
# Forced use of individual bundled libraries for non-REQUIRED library is possible with e.g. cmake -DCMAKE_DISABLE_FIND_PACKAGE_fmt=ON ...
if (DYNARMIC_USE_BUNDLED_EXTERNALS)
set(CMAKE_DISABLE_FIND_PACKAGE_biscuit ON)
set(CMAKE_DISABLE_FIND_PACKAGE_Catch2 ON)
set(CMAKE_DISABLE_FIND_PACKAGE_fmt ON)
set(CMAKE_DISABLE_FIND_PACKAGE_mcl ON)
@ -148,6 +149,10 @@ if ("arm64" IN_LIST ARCHITECTURE OR DYNARMIC_TESTS)
find_package(oaknut 2.0.1 CONFIG)
endif()
if ("riscv" IN_LIST ARCHITECTURE)
find_package(biscuit 0.9.1 QUIET)
endif()
if ("x86_64" IN_LIST ARCHITECTURE)
find_package(xbyak 7 CONFIG)
find_package(Zydis 4 CONFIG)

View file

@ -14,6 +14,10 @@ if (NOT @BUILD_SHARED_LIBS@)
find_dependency(oaknut 2.0.1)
endif()
if ("riscv" IN_LIST ARCHITECTURE)
find_dependency(biscuit 0.9.1)
endif()
if ("x86_64" IN_LIST ARCHITECTURE)
find_dependency(xbyak 7)
find_dependency(Zydis 4)

View file

@ -216,6 +216,23 @@ dynarmic is under a 0BSD license. See LICENSE.txt for more details.
dynarmic uses several other libraries, whose licenses are included below:
### biscuit
```
Copyright 2021 Lioncash/Lioncache
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
```
### catch
```

View file

@ -15,6 +15,14 @@ set(BUILD_TESTING OFF)
# simply add the directory to that file as a subdirectory
# to have CMake automatically recognize them.
# biscuit
if (NOT TARGET biscuit::biscuit)
if ("riscv" IN_LIST ARCHITECTURE)
add_subdirectory(biscuit)
endif()
endif()
# catch
if (NOT TARGET Catch2::Catch2WithMain)

3
externals/README.md vendored
View file

@ -3,6 +3,7 @@ This repository uses subtrees to manage some of its externals.
## Initial setup
```
git remote add externals-biscuit https://github.com/lioncash/biscuit.git --no-tags
git remote add externals-catch https://github.com/catchorg/Catch2.git --no-tags
git remote add externals-fmt https://github.com/fmtlib/fmt.git --no-tags
git remote add externals-mcl https://github.com/merryhime/mcl.git --no-tags
@ -18,6 +19,7 @@ git remote add externals-zydis https://github.com/zyantific/zydis.git --no-tags
Change `<ref>` to refer to the appropriate git reference.
```
git fetch externals-biscuit
git fetch externals-catch
git fetch externals-fmt
git fetch externals-mcl
@ -26,6 +28,7 @@ git fetch externals-robin-map
git fetch externals-xbyak
git fetch externals-zycore
git fetch externals-zydis
git subtree pull --squash --prefix=externals/biscuit externals-biscuit <ref>
git subtree pull --squash --prefix=externals/catch externals-catch <ref>
git subtree pull --squash --prefix=externals/fmt externals-fmt <ref>
git subtree pull --squash --prefix=externals/mcl externals-mcl <ref>

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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);

View 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

View file

@ -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