diff --git a/External/FEXCore/CMakeLists.txt b/External/FEXCore/CMakeLists.txt index 9972e3648..c5ae4bf9f 100644 --- a/External/FEXCore/CMakeLists.txt +++ b/External/FEXCore/CMakeLists.txt @@ -48,7 +48,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include_directories(${CMAKE_SOURCE_DIR}/External/SonicUtils/include/SonicUtils) add_subdirectory(Source/) -add_subdirectory(Examples/) install (DIRECTORY include/FEXCore ${CMAKE_BINARY_DIR}/include/FEXCore DESTINATION include diff --git a/External/FEXCore/Examples/CMakeLists.txt b/External/FEXCore/Examples/CMakeLists.txt deleted file mode 100644 index 6ee01afe3..000000000 --- a/External/FEXCore/Examples/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -set (SRCS - SimpleCodeLoader.cpp) - -set (ExampleName SimpleCodeLoader) - -add_executable(${ExampleName} ${SRCS}) -target_link_libraries(${ExampleName} PRIVATE ${PROJECT_NAME} SonicUtils) - -set (SRCS - SimplePrint.cpp) - -set (ExampleName SimplePrint) - -add_executable(${ExampleName} ${SRCS}) -target_link_libraries(${ExampleName} PRIVATE ${PROJECT_NAME} SonicUtils) - - diff --git a/External/FEXCore/Examples/SimpleCodeLoader.cpp b/External/FEXCore/Examples/SimpleCodeLoader.cpp deleted file mode 100644 index 435a48fd8..000000000 --- a/External/FEXCore/Examples/SimpleCodeLoader.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "LogManager.h" -#include "SimpleCodeLoader.h" - -#include -#include -#include -#include - -void MsgHandler(LogMan::DebugLevels Level, const char *Message) { - const char *CharLevel{nullptr}; - - switch (Level) { - case LogMan::NONE: - CharLevel = "NONE"; - break; - case LogMan::ASSERT: - CharLevel = "ASSERT"; - break; - case LogMan::ERROR: - CharLevel = "ERROR"; - break; - case LogMan::DEBUG: - CharLevel = "DEBUG"; - break; - case LogMan::INFO: - CharLevel = "Info"; - break; - default: - CharLevel = "???"; - break; - } - printf("[%s] %s\n", CharLevel, Message); -} - -void AssertHandler(const char *Message) { - printf("[ASSERT] %s\n", Message); -} - -int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) { - LogMan::Throw::InstallHandler(AssertHandler); - LogMan::Msg::InstallHandler(MsgHandler); - - static constexpr uint8_t RawCode[] = { - 0x90, // NOP - 0xF4 // HLT - }; - - TestCode Test(RawCode, sizeof(RawCode)); - FEXCore::Context::InitializeStaticTables(); - auto SHM = FEXCore::SHM::AllocateSHMRegion(1ULL << 36); - auto CTX = FEXCore::Context::CreateNewContext(); - - FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_MAXBLOCKINST, 1); - FEXCore::Context::AddGuestMemoryRegion(CTX, SHM); - FEXCore::Context::InitCore(CTX, &Test); - - auto ShutdownReason = FEXCore::Context::RunUntilExit(CTX); - LogMan::Msg::D("Reason we left VM: %d", ShutdownReason); - - FEXCore::Context::DestroyContext(CTX); - FEXCore::SHM::DestroyRegion(SHM); - return 0; -} diff --git a/External/FEXCore/Examples/SimpleCodeLoader.h b/External/FEXCore/Examples/SimpleCodeLoader.h deleted file mode 100644 index 18e203a5a..000000000 --- a/External/FEXCore/Examples/SimpleCodeLoader.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -class TestCode final : public FEXCore::CodeLoader { -public: - - TestCode(uint8_t const *Code, size_t Size) - : CodePtr {Code} - , CodeSize {Size} { - } - - uint64_t StackSize() const override { - return STACK_SIZE; - } - - uint64_t SetupStack([[maybe_unused]] void *HostPtr, uint64_t GuestPtr) const override { - return GuestPtr + STACK_SIZE - 16; - } - - uint64_t DefaultRIP() const override { - return RIP; - } - - FEXCore::CodeLoader::MemoryLayout GetLayout() const override { - // Needs to be page aligned - constexpr uint64_t ConstCodeSize = 0x1000; - return std::make_tuple(CODE_START_RANGE, CODE_START_RANGE + ConstCodeSize, ConstCodeSize); - } - - void MapMemoryRegion(std::function Mapper) override { - } - - void LoadMemory(MemoryWriter Writer) override { - Writer(reinterpret_cast(CodePtr), 0, CodeSize); - } - - uint64_t GetFinalRIP() override { return CODE_START_RANGE + CodeSize; } - -private: - static constexpr uint64_t STACK_SIZE = 0x1000; - static constexpr uint64_t CODE_START_RANGE = 0x0; - static constexpr uint64_t RIP = 0; - - uint8_t const *CodePtr; - size_t CodeSize; - -}; - diff --git a/External/FEXCore/Examples/SimplePrint.cpp b/External/FEXCore/Examples/SimplePrint.cpp deleted file mode 100644 index 600e0e595..000000000 --- a/External/FEXCore/Examples/SimplePrint.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "LogManager.h" -#include "SimpleCodeLoader.h" - -#include -#include -#include -#include - -void MsgHandler(LogMan::DebugLevels Level, char const *Message) { - const char *CharLevel{nullptr}; - - switch (Level) { - case LogMan::NONE: - CharLevel = "NONE"; - break; - case LogMan::ASSERT: - CharLevel = "ASSERT"; - break; - case LogMan::ERROR: - CharLevel = "ERROR"; - break; - case LogMan::DEBUG: - CharLevel = "DEBUG"; - break; - case LogMan::INFO: - CharLevel = "Info"; - break; - case LogMan::STDERR: - CharLevel = "STDERR"; - break; - case LogMan::STDOUT: - CharLevel = "STDOUT"; - break; - default: - CharLevel = "???"; - break; - } - printf("[%s] %s\n", CharLevel, Message); -} - -void AssertHandler(char const *Message) { - printf("[ASSERT] %s\n", Message); -} - -int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) { - LogMan::Throw::InstallHandler(AssertHandler); - LogMan::Msg::InstallHandler(MsgHandler); - - // Set up a syscall to do a syscall WRITE to stdout - // Syscall handler catches writes to stdout/stderr and pumps it through LogManager - static constexpr uint8_t RawCode[] = { - 0X48, - 0XC7, - 0XC0, - 0X01, - 0X00, - 0X00, - 0X00, // MOV RAX, 0x1 - - 0X48, - 0XC7, - 0XC7, - 0X01, - 0X00, - 0X00, - 0X00, // MOV RDI, 0x1 - - 0X48, - 0XC7, - 0XC6, - 0X1F, - 0X00, - 0X00, - 0X00, // MOV RSI, 0x1F - - 0X48, - 0XC7, - 0XC2, - 0X01, - 0X00, - 0X00, - 0X00, // MOV RDX, 1 - - 0X0F, - 0X05, // SYSCALL - - 0XF4, // HLT - - 0X54, - 0X65, - 0X73, - 0X74, - 0X65, - 0X72, - 0X00, // 'Tester\0' - }; - - TestCode Test(RawCode, sizeof(RawCode)); - FEXCore::Context::InitializeStaticTables(); - auto SHM = FEXCore::SHM::AllocateSHMRegion(1ULL << 36); - auto CTX = FEXCore::Context::CreateNewContext(); - -// FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_MAXBLOCKINST, 1); - FEXCore::Context::AddGuestMemoryRegion(CTX, SHM); - FEXCore::Context::InitCore(CTX, &Test); - - auto ShutdownReason = FEXCore::Context::RunUntilExit(CTX); - LogMan::Msg::D("Reason we left VM: %d", ShutdownReason); - - FEXCore::Context::DestroyContext(CTX); - FEXCore::SHM::DestroyRegion(SHM); - return 0; -} diff --git a/External/FEXCore/Source/CMakeLists.txt b/External/FEXCore/Source/CMakeLists.txt index 36de3c8dd..90f514202 100644 --- a/External/FEXCore/Source/CMakeLists.txt +++ b/External/FEXCore/Source/CMakeLists.txt @@ -180,5 +180,3 @@ install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_shared ARCHIVE DESTINATION lib COMPONENT Libraries) - -add_subdirectory(Test/) diff --git a/External/FEXCore/Source/Test/CMakeLists.txt b/External/FEXCore/Source/Test/CMakeLists.txt deleted file mode 100644 index 84ccb0f17..000000000 --- a/External/FEXCore/Source/Test/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -set (NAME IRTest) -set (SRCS IRTest.cpp) - -add_executable(${NAME} ${SRCS}) -add_dependencies(${NAME} IR_INC) - -target_link_libraries(${NAME} ${PROJECT_NAME} SonicUtils) - -set (NAME LLVMIRTest) -set (SRCS LLVMIRTest.cpp) - -add_executable(${NAME} ${SRCS}) -add_dependencies(${NAME} IR_INC) - -target_link_libraries(${NAME} ${PROJECT_NAME} SonicUtils) - diff --git a/External/FEXCore/Source/Test/IRTest.cpp b/External/FEXCore/Source/Test/IRTest.cpp deleted file mode 100644 index 7b163df05..000000000 --- a/External/FEXCore/Source/Test/IRTest.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -#include "LogManager.h" -#include -#include -#include -#include - -int main(int argc, char **argv) { - printf("IR Test\n"); -} diff --git a/External/FEXCore/Source/Test/LLVMIRTest.cpp b/External/FEXCore/Source/Test/LLVMIRTest.cpp deleted file mode 100644 index c168a5084..000000000 --- a/External/FEXCore/Source/Test/LLVMIRTest.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -int main(int argc, char **argv) { - printf("LLVM Test\n"); - llvm::InitializeNativeTarget(); - llvm::InitializeNativeTargetAsmPrinter(); - - auto ContextRef = LLVMContextCreate(); - auto Con = *llvm::unwrap(&ContextRef); - auto MainModule = new llvm::Module("Main Module", *Con); - auto IRBuilder = new llvm::IRBuilder<>(*Con); - - using namespace llvm; - - Type *i64 = Type::getInt64Ty(*Con); - auto FunctionType = FunctionType::get(Type::getVoidTy(*Con), - { - i64, - }, false); - - - legacy::PassManager PM; - PassManagerBuilder PMBuilder; - PMBuilder.OptLevel = 3; - PMBuilder.populateModulePassManager(PM); - - std::string Empty; - auto start = std::chrono::high_resolution_clock::now(); - - for (int i = 0; i < 10000; ++i) - { - - auto Func = Function::Create(FunctionType, - Function::ExternalLinkage, - Empty, - MainModule); - Func->setCallingConv(CallingConv::C); - - { - auto Entry = BasicBlock::Create(*Con, Empty, Func); - IRBuilder->SetInsertPoint(Entry); - - auto ExitBlock = BasicBlock::Create(*Con, Empty, Func); - - IRBuilder->SetInsertPoint(ExitBlock); - IRBuilder->CreateRetVoid(); - - IRBuilder->SetInsertPoint(Entry); - IRBuilder->CreateBr(ExitBlock); - } - - //printf("i: %d\n", i); - PM.run(*MainModule); - - auto FunctionList = &MainModule->getFunctionList(); - FunctionList->clear(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto diff = end - start; - - printf("Took %ld(%ldms) nanoseconds\n", diff.count(), std::chrono::duration_cast(diff).count()); - return 0; -}