mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-07 21:00:18 +02:00
Instead of having the configuration being loaded and stored in to a frontend system. First moves the backing store of the configuration in to FEXCore. Each layer that is constructed then loads its particular configuration. After the layers are loaded, then a meta layer is constructed that merges the layers flat. This means we will no longer hit the problem where a configuration is stored in the "main" configuration file, then environment and arguments passed manage to overwrite it. The order of the layers going from inner most layer to outer most, with outermost overwriting previous layer configurations is as follows: Main < Global application < Local application < Arguments < Environment One step that needs to be changed in the future is that FEXCore can then just load its configuration from the layers directly since the data is in FEXCore now. This will be reserved for a future change so we are less disruptive.
177 lines
5.5 KiB
C++
177 lines
5.5 KiB
C++
#include "Common/ArgumentLoader.h"
|
|
#include "Common/EnvironmentLoader.h"
|
|
#include "Common/Config.h"
|
|
#include "HarnessHelpers.h"
|
|
#include "IRLoader/Loader.h"
|
|
|
|
#include <FEXCore/Config/Config.h>
|
|
#include <FEXCore/Core/CodeLoader.h>
|
|
#include <FEXCore/Core/Context.h>
|
|
#include <FEXCore/Memory/SharedMem.h>
|
|
#include <FEXCore/Utils/LogManager.h>
|
|
|
|
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::STDOUT:
|
|
CharLevel = "STDOUT";
|
|
break;
|
|
case LogMan::STDERR:
|
|
CharLevel = "STDERR";
|
|
break;
|
|
default:
|
|
CharLevel = "???";
|
|
break;
|
|
}
|
|
|
|
printf("[%s] %s\n", CharLevel, Message);
|
|
fflush(stdout);
|
|
}
|
|
|
|
void AssertHandler(char const *Message) {
|
|
printf("[ASSERT] %s\n", Message);
|
|
fflush(stdout);
|
|
}
|
|
|
|
|
|
class IRCodeLoader final : public FEXCore::CodeLoader {
|
|
public:
|
|
IRCodeLoader(FEX::IRLoader::Loader *Loader)
|
|
: IR {Loader} {
|
|
}
|
|
|
|
uint64_t StackSize() const override {
|
|
return STACK_SIZE;
|
|
}
|
|
|
|
void SetMemoryBase(uint64_t Base, bool Unified) override {
|
|
MemoryBase = Base;
|
|
}
|
|
|
|
uint64_t SetupStack([[maybe_unused]] void *HostPtr, uint64_t GuestPtr) const override {
|
|
return GuestPtr + STACK_SIZE - 16;
|
|
}
|
|
|
|
uint64_t DefaultRIP() const override {
|
|
return IR->GetEntryRIP();
|
|
}
|
|
|
|
void MapMemoryRegion(std::function<void*(uint64_t, uint64_t, bool, bool)> Mapper) override {
|
|
// Map the memory regions the test file asks for
|
|
IR->MapRegions(Mapper);
|
|
}
|
|
|
|
void LoadMemory(MemoryWriter Writer) override {
|
|
IR->LoadMemory(MemoryBase, Writer);
|
|
}
|
|
|
|
uint64_t GetFinalRIP() override { return 0; }
|
|
|
|
virtual void AddIR(IRHandler Handler) override {
|
|
Handler(IR->GetEntryRIP(), IR);
|
|
}
|
|
|
|
private:
|
|
FEX::IRLoader::Loader *IR;
|
|
constexpr static uint64_t STACK_SIZE = 8 * 1024 * 1024;
|
|
uint64_t MemoryBase = 0;
|
|
};
|
|
|
|
int main(int argc, char **argv, char **const envp) {
|
|
LogMan::Throw::InstallHandler(AssertHandler);
|
|
LogMan::Msg::InstallHandler(MsgHandler);
|
|
|
|
FEXCore::Config::Initialize();
|
|
FEXCore::Config::AddLayer(std::make_unique<FEX::Config::MainLoader>());
|
|
FEXCore::Config::AddLayer(std::make_unique<FEX::ArgLoader::ArgLoader>(argc, argv));
|
|
FEXCore::Config::AddLayer(std::make_unique<FEX::Config::EnvLoader>(envp));
|
|
FEXCore::Config::Load();
|
|
|
|
FEXCore::Config::Value<uint8_t> CoreConfig{FEXCore::Config::CONFIG_DEFAULTCORE, 0};
|
|
FEXCore::Config::Value<uint64_t> BlockSizeConfig{FEXCore::Config::CONFIG_MAXBLOCKINST, 1};
|
|
FEXCore::Config::Value<bool> SingleStepConfig{FEXCore::Config::CONFIG_SINGLESTEP, false};
|
|
FEXCore::Config::Value<bool> MultiblockConfig{FEXCore::Config::CONFIG_MULTIBLOCK, false};
|
|
FEXCore::Config::Value<bool> GdbServerConfig{FEXCore::Config::CONFIG_GDBSERVER, false};
|
|
FEXCore::Config::Value<std::string> LDPath{FEXCore::Config::CONFIG_ROOTFSPATH, ""};
|
|
FEXCore::Config::Value<bool> UnifiedMemory{FEXCore::Config::CONFIG_UNIFIED_MEMORY, false};
|
|
|
|
auto Args = FEX::ArgLoader::Get();
|
|
auto ParsedArgs = FEX::ArgLoader::GetParsedArgs();
|
|
|
|
LogMan::Throw::A(Args.size() > 1, "Not enough arguments");
|
|
|
|
FEXCore::Context::InitializeStaticTables();
|
|
auto SHM = FEXCore::SHM::AllocateSHMRegion(1ULL << 36);
|
|
auto CTX = FEXCore::Context::CreateNewContext();
|
|
FEXCore::Context::InitializeContext(CTX);
|
|
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_DEFAULTCORE, CoreConfig() > 3 ? FEXCore::Config::CONFIG_CUSTOM : CoreConfig());
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_MULTIBLOCK, MultiblockConfig());
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_SINGLESTEP, SingleStepConfig());
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_MAXBLOCKINST, BlockSizeConfig());
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_GDBSERVER, GdbServerConfig());
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_ROOTFSPATH, LDPath());
|
|
FEXCore::Config::SetConfig(CTX, FEXCore::Config::CONFIG_UNIFIED_MEMORY, UnifiedMemory());
|
|
|
|
FEXCore::Context::AddGuestMemoryRegion(CTX, SHM);
|
|
|
|
FEX::IRLoader::InitializeStaticTables();
|
|
FEX::IRLoader::Loader Loader(Args[0], Args[1]);
|
|
|
|
int Return{};
|
|
|
|
if (Loader.IsValid()) {
|
|
IRCodeLoader CodeLoader{&Loader};
|
|
FEXCore::Context::InitCore(CTX, &CodeLoader);
|
|
FEXCore::Context::ExitReason ShutdownReason = FEXCore::Context::ExitReason::EXIT_SHUTDOWN;
|
|
|
|
// There might already be an exit handler, leave it installed
|
|
if(!FEXCore::Context::GetExitHandler(CTX)) {
|
|
FEXCore::Context::SetExitHandler(CTX, [&](uint64_t thread, FEXCore::Context::ExitReason reason) {
|
|
if (reason != FEXCore::Context::ExitReason::EXIT_DEBUG) {
|
|
ShutdownReason = reason;
|
|
FEXCore::Context::Stop(CTX);
|
|
}
|
|
});
|
|
}
|
|
|
|
FEXCore::Context::RunUntilExit(CTX);
|
|
|
|
LogMan::Msg::D("Reason we left VM: %d", ShutdownReason);
|
|
|
|
// Just re-use compare state. It also checks against the expected values in config.
|
|
FEXCore::Core::CPUState State;
|
|
FEXCore::Context::GetCPUState(CTX, &State);
|
|
bool Passed = Loader.CompareStates(&State);
|
|
|
|
LogMan::Msg::I("Passed? %s\n", Passed ? "Yes" : "No");
|
|
|
|
Return = Passed ? 0 : -1;
|
|
}
|
|
else {
|
|
LogMan::Msg::E("Couldn't load IR");
|
|
Return = -1;
|
|
}
|
|
|
|
FEXCore::Context::DestroyContext(CTX);
|
|
FEXCore::SHM::DestroyRegion(SHM);
|
|
|
|
return Return;
|
|
}
|