early-access version 2777

This commit is contained in:
pineappleEA 2022-06-13 23:17:19 +02:00
parent 44556fe877
commit 0097b9671a
23 changed files with 344 additions and 96 deletions

View file

@ -1,8 +1,8 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 2774. This is the source code for early-access 2777.
## Legal Notice ## Legal Notice
yuzu is a GPLv3 program, which allows fully free redistribution of its source code. yuzu is a GPLv2 program, which allows fully free redistribution of its source code.

View file

@ -40,6 +40,11 @@ target_include_directories(mbedtls PUBLIC ./mbedtls/include)
add_library(microprofile INTERFACE) add_library(microprofile INTERFACE)
target_include_directories(microprofile INTERFACE ./microprofile) target_include_directories(microprofile INTERFACE ./microprofile)
# GCC bugs
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND MINGW)
target_compile_options(microprofile INTERFACE "-Wno-array-bounds")
endif()
# libusb # libusb
if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB) if (NOT LIBUSB_FOUND OR YUZU_USE_BUNDLED_LIBUSB)
add_subdirectory(libusb) add_subdirectory(libusb)

View file

@ -6,15 +6,11 @@
#include "common/settings.h" #include "common/settings.h"
void assert_check_condition(bool cond, std::function<void()>&& on_failure) { void assert_fail_impl() {
if (!cond) [[unlikely]] {
on_failure();
if (Settings::values.use_debug_asserts) { if (Settings::values.use_debug_asserts) {
Crash(); Crash();
} }
} }
}
[[noreturn]] void unreachable_impl() { [[noreturn]] void unreachable_impl() {
Crash(); Crash();

View file

@ -4,47 +4,36 @@
#pragma once #pragma once
#include <functional>
#include "common/logging/log.h" #include "common/logging/log.h"
// Sometimes we want to try to continue even after hitting an assert. // Sometimes we want to try to continue even after hitting an assert.
// However touching this file yields a global recompilation as this header is included almost // However touching this file yields a global recompilation as this header is included almost
// everywhere. So let's just move the handling of the failed assert to a single cpp file. // everywhere. So let's just move the handling of the failed assert to a single cpp file.
// For asserts we'd like to keep all the junk executed when an assert happens away from the void assert_fail_impl();
// important code in the function. One way of doing this is to put all the relevant code inside a
// lambda and force the compiler to not inline it.
void assert_check_condition(bool cond, std::function<void()>&& on_failure);
[[noreturn]] void unreachable_impl(); [[noreturn]] void unreachable_impl();
#ifdef _MSC_VER
#define NO_INLINE __declspec(noinline)
#else
#define NO_INLINE __attribute__((noinline))
#endif
#define ASSERT(_a_) \ #define ASSERT(_a_) \
do { \ ([&]() NO_INLINE { \
if (std::is_constant_evaluated()) { \ if (!(_a_)) [[unlikely]] { \
if (!(_a_)) { \ LOG_CRITICAL(Debug, "Assertion Failed!"); \
/* Will trigger compile error here */ \ assert_fail_impl(); \
assert_check_condition(bool(_a_), \
[] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \
} \ } \
} else { \ }())
assert_check_condition(bool(_a_), [] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \
} \
} while (0)
#define ASSERT_MSG(_a_, ...) \ #define ASSERT_MSG(_a_, ...) \
do { \ ([&]() NO_INLINE { \
if (std::is_constant_evaluated()) { \ if (!(_a_)) [[unlikely]] { \
if (!(_a_)) { \ LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \
/* Will trigger compile error here */ \ assert_fail_impl(); \
assert_check_condition(bool(_a_), \
[] { LOG_CRITICAL(Debug, "Assertion Failed!"); }); \
} \ } \
} else { \ }())
assert_check_condition( \
bool(_a_), [&] { LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); }); \
} \
} while (0)
#define UNREACHABLE() \ #define UNREACHABLE() \
do { \ do { \

View file

@ -493,6 +493,12 @@ void System::Shutdown() {
impl->Shutdown(); impl->Shutdown();
} }
void System::DetachDebugger() {
if (impl->debugger) {
impl->debugger->NotifyShutdown();
}
}
std::unique_lock<std::mutex> System::StallCPU() { std::unique_lock<std::mutex> System::StallCPU() {
return impl->StallCPU(); return impl->StallCPU();
} }

View file

@ -160,6 +160,9 @@ public:
/// Shutdown the emulated system. /// Shutdown the emulated system.
void Shutdown(); void Shutdown();
/// Forcibly detach the debugger if it is running.
void DetachDebugger();
std::unique_lock<std::mutex> StallCPU(); std::unique_lock<std::mutex> StallCPU();
void UnstallCPU(); void UnstallCPU();

View file

@ -42,6 +42,16 @@ static std::span<const u8> ReceiveInto(Readable& r, Buffer& buffer) {
return received_data; return received_data;
} }
enum class SignalType {
Stopped,
ShuttingDown,
};
struct SignalInfo {
SignalType type;
Kernel::KThread* thread;
};
namespace Core { namespace Core {
class DebuggerImpl : public DebuggerBackend { class DebuggerImpl : public DebuggerBackend {
@ -56,7 +66,7 @@ public:
ShutdownServer(); ShutdownServer();
} }
bool NotifyThreadStopped(Kernel::KThread* thread) { bool SignalDebugger(SignalInfo signal_info) {
std::scoped_lock lk{connection_lock}; std::scoped_lock lk{connection_lock};
if (stopped) { if (stopped) {
@ -64,9 +74,13 @@ public:
// It should be ignored. // It should be ignored.
return false; return false;
} }
stopped = true;
boost::asio::write(signal_pipe, boost::asio::buffer(&thread, sizeof(thread))); // Set up the state.
stopped = true;
info = signal_info;
// Write a single byte into the pipe to wake up the debug interface.
boost::asio::write(signal_pipe, boost::asio::buffer(&stopped, sizeof(stopped)));
return true; return true;
} }
@ -96,7 +110,7 @@ private:
connection_thread = std::jthread([&, port](std::stop_token stop_token) { connection_thread = std::jthread([&, port](std::stop_token stop_token) {
try { try {
// Initialize the listening socket and accept a new client. // Initialize the listening socket and accept a new client.
tcp::endpoint endpoint{boost::asio::ip::address_v4::loopback(), port}; tcp::endpoint endpoint{boost::asio::ip::address_v4::any(), port};
tcp::acceptor acceptor{io_context, endpoint}; tcp::acceptor acceptor{io_context, endpoint};
acceptor.async_accept(client_socket, [](const auto&) {}); acceptor.async_accept(client_socket, [](const auto&) {});
@ -124,7 +138,7 @@ private:
Common::SetCurrentThreadName("yuzu:Debugger"); Common::SetCurrentThreadName("yuzu:Debugger");
// Set up the client signals for new data. // Set up the client signals for new data.
AsyncReceiveInto(signal_pipe, active_thread, [&](auto d) { PipeData(d); }); AsyncReceiveInto(signal_pipe, pipe_data, [&](auto d) { PipeData(d); });
AsyncReceiveInto(client_socket, client_data, [&](auto d) { ClientData(d); }); AsyncReceiveInto(client_socket, client_data, [&](auto d) { ClientData(d); });
// Stop the emulated CPU. // Stop the emulated CPU.
@ -142,9 +156,28 @@ private:
} }
void PipeData(std::span<const u8> data) { void PipeData(std::span<const u8> data) {
switch (info.type) {
case SignalType::Stopped:
// Stop emulation.
AllCoreStop(); AllCoreStop();
// Notify the client.
active_thread = info.thread;
UpdateActiveThread(); UpdateActiveThread();
frontend->Stopped(active_thread); frontend->Stopped(active_thread);
break;
case SignalType::ShuttingDown:
frontend->ShuttingDown();
// Wait for emulation to shut down gracefully now.
suspend.reset();
signal_pipe.close();
client_socket.shutdown(boost::asio::socket_base::shutdown_both);
LOG_INFO(Debug_GDBStub, "Shut down server");
break;
}
} }
void ClientData(std::span<const u8> data) { void ClientData(std::span<const u8> data) {
@ -246,7 +279,9 @@ private:
boost::asio::ip::tcp::socket client_socket; boost::asio::ip::tcp::socket client_socket;
std::optional<std::unique_lock<std::mutex>> suspend; std::optional<std::unique_lock<std::mutex>> suspend;
SignalInfo info;
Kernel::KThread* active_thread; Kernel::KThread* active_thread;
bool pipe_data;
bool stopped; bool stopped;
std::array<u8, 4096> client_data; std::array<u8, 4096> client_data;
@ -263,7 +298,13 @@ Debugger::Debugger(Core::System& system, u16 port) {
Debugger::~Debugger() = default; Debugger::~Debugger() = default;
bool Debugger::NotifyThreadStopped(Kernel::KThread* thread) { bool Debugger::NotifyThreadStopped(Kernel::KThread* thread) {
return impl && impl->NotifyThreadStopped(thread); return impl && impl->SignalDebugger(SignalInfo{SignalType::Stopped, thread});
}
void Debugger::NotifyShutdown() {
if (impl) {
impl->SignalDebugger(SignalInfo{SignalType::ShuttingDown, nullptr});
}
} }
} // namespace Core } // namespace Core

View file

@ -35,6 +35,11 @@ public:
*/ */
bool NotifyThreadStopped(Kernel::KThread* thread); bool NotifyThreadStopped(Kernel::KThread* thread);
/**
* Notify the debugger that a shutdown is being performed now and disconnect.
*/
void NotifyShutdown();
private: private:
std::unique_ptr<DebuggerImpl> impl; std::unique_ptr<DebuggerImpl> impl;
}; };

View file

@ -66,6 +66,11 @@ public:
*/ */
virtual void Stopped(Kernel::KThread* thread) = 0; virtual void Stopped(Kernel::KThread* thread) = 0;
/**
* Called when emulation is shutting down.
*/
virtual void ShuttingDown() = 0;
/** /**
* Called when new data is asynchronously received on the client socket. * Called when new data is asynchronously received on the client socket.
* A list of actions to perform is returned. * A list of actions to perform is returned.

View file

@ -106,6 +106,8 @@ GDBStub::~GDBStub() = default;
void GDBStub::Connected() {} void GDBStub::Connected() {}
void GDBStub::ShuttingDown() {}
void GDBStub::Stopped(Kernel::KThread* thread) { void GDBStub::Stopped(Kernel::KThread* thread) {
SendReply(arch->ThreadStatus(thread, GDB_STUB_SIGTRAP)); SendReply(arch->ThreadStatus(thread, GDB_STUB_SIGTRAP));
} }

View file

@ -23,6 +23,7 @@ public:
void Connected() override; void Connected() override;
void Stopped(Kernel::KThread* thread) override; void Stopped(Kernel::KThread* thread) override;
void ShuttingDown() override;
std::vector<DebuggerAction> ClientData(std::span<const u8> data) override; std::vector<DebuggerAction> ClientData(std::span<const u8> data) override;
private: private:

View file

@ -212,7 +212,9 @@ struct KernelCore::Impl {
system_resource_limit = KResourceLimit::Create(system.Kernel()); system_resource_limit = KResourceLimit::Create(system.Kernel());
system_resource_limit->Initialize(&core_timing); system_resource_limit->Initialize(&core_timing);
const auto [total_size, kernel_size] = memory_layout->GetTotalAndKernelMemorySizes(); const auto sizes{memory_layout->GetTotalAndKernelMemorySizes()};
const auto total_size{sizes.first};
const auto kernel_size{sizes.second};
// If setting the default system values fails, then something seriously wrong has occurred. // If setting the default system values fails, then something seriously wrong has occurred.
ASSERT(system_resource_limit->SetLimitValue(LimitableResource::PhysicalMemory, total_size) ASSERT(system_resource_limit->SetLimitValue(LimitableResource::PhysicalMemory, total_size)

View file

@ -1,6 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <cstring>
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/ipc_helpers.h" #include "core/hle/ipc_helpers.h"
#include "core/hle/service/glue/notif.h" #include "core/hle/service/glue/notif.h"
@ -9,11 +14,11 @@ namespace Service::Glue {
NOTIF_A::NOTIF_A(Core::System& system_) : ServiceFramework{system_, "notif:a"} { NOTIF_A::NOTIF_A(Core::System& system_) : ServiceFramework{system_, "notif:a"} {
// clang-format off // clang-format off
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{500, nullptr, "RegisterAlarmSetting"}, {500, &NOTIF_A::RegisterAlarmSetting, "RegisterAlarmSetting"},
{510, nullptr, "UpdateAlarmSetting"}, {510, &NOTIF_A::UpdateAlarmSetting, "UpdateAlarmSetting"},
{520, &NOTIF_A::ListAlarmSettings, "ListAlarmSettings"}, {520, &NOTIF_A::ListAlarmSettings, "ListAlarmSettings"},
{530, nullptr, "LoadApplicationParameter"}, {530, &NOTIF_A::LoadApplicationParameter, "LoadApplicationParameter"},
{540, nullptr, "DeleteAlarmSetting"}, {540, &NOTIF_A::DeleteAlarmSetting, "DeleteAlarmSetting"},
{1000, &NOTIF_A::Initialize, "Initialize"}, {1000, &NOTIF_A::Initialize, "Initialize"},
}; };
// clang-format on // clang-format on
@ -23,21 +28,132 @@ NOTIF_A::NOTIF_A(Core::System& system_) : ServiceFramework{system_, "notif:a"} {
NOTIF_A::~NOTIF_A() = default; NOTIF_A::~NOTIF_A() = default;
void NOTIF_A::ListAlarmSettings(Kernel::HLERequestContext& ctx) { void NOTIF_A::RegisterAlarmSetting(Kernel::HLERequestContext& ctx) {
// Returns an array of AlarmSetting const auto alarm_setting_buffer_size = ctx.GetReadBufferSize(0);
constexpr s32 alarm_count = 0; const auto application_parameter_size = ctx.GetReadBufferSize(1);
LOG_WARNING(Service_NOTIF, "(STUBBED) called"); ASSERT_MSG(alarm_setting_buffer_size == sizeof(AlarmSetting),
"alarm_setting_buffer_size is not 0x40 bytes");
ASSERT_MSG(application_parameter_size <= sizeof(ApplicationParameter),
"application_parameter_size is bigger than 0x400 bytes");
AlarmSetting new_alarm{};
memcpy(&new_alarm, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting));
// TODO: Count alarms per game id
if (alarms.size() >= max_alarms) {
LOG_ERROR(Service_NOTIF, "Alarm limit reached");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
return;
}
new_alarm.alarm_setting_id = last_alarm_setting_id++;
alarms.push_back(new_alarm);
// TODO: Save application parameter data
LOG_WARNING(Service_NOTIF,
"(STUBBED) called, application_parameter_size={}, setting_id={}, kind={}, muted={}",
application_parameter_size, new_alarm.alarm_setting_id, new_alarm.kind,
new_alarm.muted);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
rb.Push(new_alarm.alarm_setting_id);
}
void NOTIF_A::UpdateAlarmSetting(Kernel::HLERequestContext& ctx) {
const auto alarm_setting_buffer_size = ctx.GetReadBufferSize(0);
const auto application_parameter_size = ctx.GetReadBufferSize(1);
ASSERT_MSG(alarm_setting_buffer_size == sizeof(AlarmSetting),
"alarm_setting_buffer_size is not 0x40 bytes");
ASSERT_MSG(application_parameter_size <= sizeof(ApplicationParameter),
"application_parameter_size is bigger than 0x400 bytes");
AlarmSetting alarm_setting{};
memcpy(&alarm_setting, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting));
const auto alarm_it = GetAlarmFromId(alarm_setting.alarm_setting_id);
if (alarm_it != alarms.end()) {
LOG_DEBUG(Service_NOTIF, "Alarm updated");
*alarm_it = alarm_setting;
// TODO: Save application parameter data
}
LOG_WARNING(Service_NOTIF,
"(STUBBED) called, application_parameter_size={}, setting_id={}, kind={}, muted={}",
application_parameter_size, alarm_setting.alarm_setting_id, alarm_setting.kind,
alarm_setting.muted);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
void NOTIF_A::ListAlarmSettings(Kernel::HLERequestContext& ctx) {
LOG_INFO(Service_NOTIF, "called, alarm_count={}", alarms.size());
// TODO: Only return alarms of this game id
ctx.WriteBuffer(alarms);
IPC::ResponseBuilder rb{ctx, 3}; IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
rb.Push(alarm_count); rb.Push(static_cast<u32>(alarms.size()));
}
void NOTIF_A::LoadApplicationParameter(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto alarm_setting_id{rp.Pop<AlarmSettingId>()};
const auto alarm_it = GetAlarmFromId(alarm_setting_id);
if (alarm_it == alarms.end()) {
LOG_ERROR(Service_NOTIF, "Invalid alarm setting id={}", alarm_setting_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultUnknown);
return;
}
// TODO: Read application parameter related to this setting id
ApplicationParameter application_parameter{};
LOG_WARNING(Service_NOTIF, "(STUBBED) called, alarm_setting_id={}", alarm_setting_id);
ctx.WriteBuffer(application_parameter);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
rb.Push(static_cast<u32>(application_parameter.size()));
}
void NOTIF_A::DeleteAlarmSetting(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto alarm_setting_id{rp.Pop<AlarmSettingId>()};
std::erase_if(alarms, [alarm_setting_id](const AlarmSetting& alarm) {
return alarm.alarm_setting_id == alarm_setting_id;
});
LOG_INFO(Service_NOTIF, "called, alarm_setting_id={}", alarm_setting_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
} }
void NOTIF_A::Initialize(Kernel::HLERequestContext& ctx) { void NOTIF_A::Initialize(Kernel::HLERequestContext& ctx) {
// TODO: Load previous alarms from config
LOG_WARNING(Service_NOTIF, "(STUBBED) called"); LOG_WARNING(Service_NOTIF, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
} }
std::vector<NOTIF_A::AlarmSetting>::iterator NOTIF_A::GetAlarmFromId(
AlarmSettingId alarm_setting_id) {
return std::find_if(alarms.begin(), alarms.end(),
[alarm_setting_id](const AlarmSetting& alarm) {
return alarm.alarm_setting_id == alarm_setting_id;
});
}
} // namespace Service::Glue } // namespace Service::Glue

View file

@ -3,6 +3,10 @@
#pragma once #pragma once
#include <array>
#include <vector>
#include "common/uuid.h"
#include "core/hle/service/service.h" #include "core/hle/service/service.h"
namespace Core { namespace Core {
@ -17,8 +21,52 @@ public:
~NOTIF_A() override; ~NOTIF_A() override;
private: private:
static constexpr std::size_t max_alarms = 8;
// This is nn::notification::AlarmSettingId
using AlarmSettingId = u16;
static_assert(sizeof(AlarmSettingId) == 0x2, "AlarmSettingId is an invalid size");
using ApplicationParameter = std::array<u8, 0x400>;
static_assert(sizeof(ApplicationParameter) == 0x400, "ApplicationParameter is an invalid size");
struct DailyAlarmSetting {
s8 hour;
s8 minute;
};
static_assert(sizeof(DailyAlarmSetting) == 0x2, "DailyAlarmSetting is an invalid size");
struct WeeklyScheduleAlarmSetting {
INSERT_PADDING_BYTES(0xA);
std::array<DailyAlarmSetting, 0x7> day_of_week;
};
static_assert(sizeof(WeeklyScheduleAlarmSetting) == 0x18,
"WeeklyScheduleAlarmSetting is an invalid size");
// This is nn::notification::AlarmSetting
struct AlarmSetting {
AlarmSettingId alarm_setting_id;
u8 kind;
u8 muted;
INSERT_PADDING_BYTES(0x4);
Common::UUID account_id;
u64 application_id;
INSERT_PADDING_BYTES(0x8);
WeeklyScheduleAlarmSetting schedule;
};
static_assert(sizeof(AlarmSetting) == 0x40, "AlarmSetting is an invalid size");
void RegisterAlarmSetting(Kernel::HLERequestContext& ctx);
void UpdateAlarmSetting(Kernel::HLERequestContext& ctx);
void ListAlarmSettings(Kernel::HLERequestContext& ctx); void ListAlarmSettings(Kernel::HLERequestContext& ctx);
void LoadApplicationParameter(Kernel::HLERequestContext& ctx);
void DeleteAlarmSetting(Kernel::HLERequestContext& ctx);
void Initialize(Kernel::HLERequestContext& ctx); void Initialize(Kernel::HLERequestContext& ctx);
std::vector<AlarmSetting>::iterator GetAlarmFromId(AlarmSettingId alarm_setting_id);
std::vector<AlarmSetting> alarms{};
AlarmSettingId last_alarm_setting_id{};
}; };
} // namespace Service::Glue } // namespace Service::Glue

View file

@ -128,11 +128,10 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core::
// Apply patches if necessary // Apply patches if necessary
if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) { if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) {
std::vector<u8> pi_header; std::vector<u8> pi_header(sizeof(NSOHeader) + program_image.size());
pi_header.insert(pi_header.begin(), reinterpret_cast<u8*>(&nso_header), std::memcpy(pi_header.data(), &nso_header, sizeof(NSOHeader));
reinterpret_cast<u8*>(&nso_header) + sizeof(NSOHeader)); std::memcpy(pi_header.data() + sizeof(NSOHeader), program_image.data(),
pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.data(), program_image.size());
program_image.data() + program_image.size());
pi_header = pm->PatchNSO(pi_header, nso_file.GetName()); pi_header = pm->PatchNSO(pi_header, nso_file.GetName());

View file

@ -13,11 +13,11 @@
namespace InputCommon { namespace InputCommon {
namespace { namespace {
std::string GetGUID(SDL_Joystick* joystick) { Common::UUID GetGUID(SDL_Joystick* joystick) {
const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick); const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
char guid_str[33]; std::array<u8, 16> data{};
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); std::memcpy(data.data(), guid.data, sizeof(data));
return guid_str; return Common::UUID{data};
} }
} // Anonymous namespace } // Anonymous namespace
@ -31,9 +31,9 @@ static int SDLEventWatcher(void* user_data, SDL_Event* event) {
class SDLJoystick { class SDLJoystick {
public: public:
SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick, SDLJoystick(Common::UUID guid_, int port_, SDL_Joystick* joystick,
SDL_GameController* game_controller) SDL_GameController* game_controller)
: guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose}, : guid{guid_}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose},
sdl_controller{game_controller, &SDL_GameControllerClose} { sdl_controller{game_controller, &SDL_GameControllerClose} {
EnableMotion(); EnableMotion();
} }
@ -120,7 +120,7 @@ public:
*/ */
const PadIdentifier GetPadIdentifier() const { const PadIdentifier GetPadIdentifier() const {
return { return {
.guid = Common::UUID{guid}, .guid = guid,
.port = static_cast<std::size_t>(port), .port = static_cast<std::size_t>(port),
.pad = 0, .pad = 0,
}; };
@ -129,7 +129,7 @@ public:
/** /**
* The guid of the joystick * The guid of the joystick
*/ */
const std::string& GetGUID() const { const Common::UUID& GetGUID() const {
return guid; return guid;
} }
@ -228,7 +228,7 @@ public:
} }
private: private:
std::string guid; Common::UUID guid;
int port; int port;
std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick; std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller; std::unique_ptr<SDL_GameController, decltype(&SDL_GameControllerClose)> sdl_controller;
@ -240,7 +240,7 @@ private:
BasicMotion motion; BasicMotion motion;
}; };
std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) { std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const Common::UUID& guid, int port) {
std::scoped_lock lock{joystick_map_mutex}; std::scoped_lock lock{joystick_map_mutex};
const auto it = joystick_map.find(guid); const auto it = joystick_map.find(guid);
@ -259,9 +259,13 @@ std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string&
return joystick_map[guid].emplace_back(std::move(joystick)); return joystick_map[guid].emplace_back(std::move(joystick));
} }
std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) {
return GetSDLJoystickByGUID(Common::UUID{guid}, port);
}
std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) { std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl_id) {
auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id); auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id);
const std::string guid = GetGUID(sdl_joystick); const auto guid = GetGUID(sdl_joystick);
std::scoped_lock lock{joystick_map_mutex}; std::scoped_lock lock{joystick_map_mutex};
const auto map_it = joystick_map.find(guid); const auto map_it = joystick_map.find(guid);
@ -295,7 +299,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
return; return;
} }
const std::string guid = GetGUID(sdl_joystick); const auto guid = GetGUID(sdl_joystick);
std::scoped_lock lock{joystick_map_mutex}; std::scoped_lock lock{joystick_map_mutex};
if (joystick_map.find(guid) == joystick_map.end()) { if (joystick_map.find(guid) == joystick_map.end()) {
@ -324,7 +328,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
} }
void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) { void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) {
const std::string guid = GetGUID(sdl_joystick); const auto guid = GetGUID(sdl_joystick);
std::scoped_lock lock{joystick_map_mutex}; std::scoped_lock lock{joystick_map_mutex};
// This call to guid is safe since the joystick is guaranteed to be in the map // This call to guid is safe since the joystick is guaranteed to be in the map
@ -470,7 +474,7 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
devices.emplace_back(Common::ParamPackage{ devices.emplace_back(Common::ParamPackage{
{"engine", GetEngineName()}, {"engine", GetEngineName()},
{"display", std::move(name)}, {"display", std::move(name)},
{"guid", joystick->GetGUID()}, {"guid", joystick->GetGUID().RawString()},
{"port", std::to_string(joystick->GetPort())}, {"port", std::to_string(joystick->GetPort())},
}); });
if (joystick->IsJoyconLeft()) { if (joystick->IsJoyconLeft()) {
@ -493,8 +497,8 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
devices.emplace_back(Common::ParamPackage{ devices.emplace_back(Common::ParamPackage{
{"engine", GetEngineName()}, {"engine", GetEngineName()},
{"display", std::move(name)}, {"display", std::move(name)},
{"guid", joystick->GetGUID()}, {"guid", joystick->GetGUID().RawString()},
{"guid2", joystick2->GetGUID()}, {"guid2", joystick2->GetGUID().RawString()},
{"port", std::to_string(joystick->GetPort())}, {"port", std::to_string(joystick->GetPort())},
}); });
} }
@ -557,50 +561,50 @@ void SDLDriver::SendVibrations() {
} }
} }
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid, Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
s32 axis, float value) const { s32 axis, float value) const {
Common::ParamPackage params{}; Common::ParamPackage params{};
params.Set("engine", GetEngineName()); params.Set("engine", GetEngineName());
params.Set("port", port); params.Set("port", port);
params.Set("guid", std::move(guid)); params.Set("guid", guid.RawString());
params.Set("axis", axis); params.Set("axis", axis);
params.Set("threshold", "0.5"); params.Set("threshold", "0.5");
params.Set("invert", value < 0 ? "-" : "+"); params.Set("invert", value < 0 ? "-" : "+");
return params; return params;
} }
Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, std::string guid, Common::ParamPackage SDLDriver::BuildButtonParamPackageForButton(int port, const Common::UUID& guid,
s32 button) const { s32 button) const {
Common::ParamPackage params{}; Common::ParamPackage params{};
params.Set("engine", GetEngineName()); params.Set("engine", GetEngineName());
params.Set("port", port); params.Set("port", port);
params.Set("guid", std::move(guid)); params.Set("guid", guid.RawString());
params.Set("button", button); params.Set("button", button);
return params; return params;
} }
Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, std::string guid, s32 hat, Common::ParamPackage SDLDriver::BuildHatParamPackageForButton(int port, const Common::UUID& guid,
u8 value) const { s32 hat, u8 value) const {
Common::ParamPackage params{}; Common::ParamPackage params{};
params.Set("engine", GetEngineName()); params.Set("engine", GetEngineName());
params.Set("port", port); params.Set("port", port);
params.Set("guid", std::move(guid)); params.Set("guid", guid.RawString());
params.Set("hat", hat); params.Set("hat", hat);
params.Set("direction", GetHatButtonName(value)); params.Set("direction", GetHatButtonName(value));
return params; return params;
} }
Common::ParamPackage SDLDriver::BuildMotionParam(int port, std::string guid) const { Common::ParamPackage SDLDriver::BuildMotionParam(int port, const Common::UUID& guid) const {
Common::ParamPackage params{}; Common::ParamPackage params{};
params.Set("engine", GetEngineName()); params.Set("engine", GetEngineName());
params.Set("motion", 0); params.Set("motion", 0);
params.Set("port", port); params.Set("port", port);
params.Set("guid", std::move(guid)); params.Set("guid", guid.RawString());
return params; return params;
} }
Common::ParamPackage SDLDriver::BuildParamPackageForBinding( Common::ParamPackage SDLDriver::BuildParamPackageForBinding(
int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const { int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const {
switch (binding.bindType) { switch (binding.bindType) {
case SDL_CONTROLLER_BINDTYPE_NONE: case SDL_CONTROLLER_BINDTYPE_NONE:
break; break;

View file

@ -47,6 +47,7 @@ public:
* Check how many identical joysticks (by guid) were connected before the one with sdl_id and so * Check how many identical joysticks (by guid) were connected before the one with sdl_id and so
* tie it to a SDLJoystick with the same guid and that port * tie it to a SDLJoystick with the same guid and that port
*/ */
std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const Common::UUID& guid, int port);
std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port);
std::vector<Common::ParamPackage> GetInputDevices() const override; std::vector<Common::ParamPackage> GetInputDevices() const override;
@ -79,18 +80,18 @@ private:
/// Takes all vibrations from the queue and sends the command to the controller /// Takes all vibrations from the queue and sends the command to the controller
void SendVibrations(); void SendVibrations();
Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, Common::ParamPackage BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
float value = 0.1f) const; s32 axis, float value = 0.1f) const;
Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid, Common::ParamPackage BuildButtonParamPackageForButton(int port, const Common::UUID& guid,
s32 button) const; s32 button) const;
Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, s32 hat, Common::ParamPackage BuildHatParamPackageForButton(int port, const Common::UUID& guid, s32 hat,
u8 value) const; u8 value) const;
Common::ParamPackage BuildMotionParam(int port, std::string guid) const; Common::ParamPackage BuildMotionParam(int port, const Common::UUID& guid) const;
Common::ParamPackage BuildParamPackageForBinding( Common::ParamPackage BuildParamPackageForBinding(
int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const; int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const;
Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x, Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x,
int axis_y, float offset_x, int axis_y, float offset_x,
@ -120,7 +121,7 @@ private:
Common::SPSCQueue<VibrationRequest> vibration_queue; Common::SPSCQueue<VibrationRequest> vibration_queue;
/// Map of GUID of a list of corresponding virtual Joysticks /// Map of GUID of a list of corresponding virtual Joysticks
std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; std::unordered_map<Common::UUID, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
std::mutex joystick_map_mutex; std::mutex joystick_map_mutex;
bool start_thread = false; bool start_thread = false;

View file

@ -411,7 +411,7 @@ void MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) {
Xbyak::Label end; Xbyak::Label end;
auto value = Compile_GetRegister(opcode.src_a, eax); auto value = Compile_GetRegister(opcode.src_a, eax);
test(value, value); cmp(value, 0); // test(value, value);
if (optimizer.has_delayed_pc) { if (optimizer.has_delayed_pc) {
switch (opcode.branch_condition) { switch (opcode.branch_condition) {
case Macro::BranchCondition::Zero: case Macro::BranchCondition::Zero:

View file

@ -1591,6 +1591,7 @@ void GMainWindow::ShutdownGame() {
AllowOSSleep(); AllowOSSleep();
system->DetachDebugger();
discord_rpc->Pause(); discord_rpc->Pause();
emu_thread->RequestStop(); emu_thread->RequestStop();

View file

@ -344,6 +344,8 @@ void Config::ReadValues() {
ReadSetting("Debugging", Settings::values.use_debug_asserts); ReadSetting("Debugging", Settings::values.use_debug_asserts);
ReadSetting("Debugging", Settings::values.use_auto_stub); ReadSetting("Debugging", Settings::values.use_auto_stub);
ReadSetting("Debugging", Settings::values.disable_macro_jit); ReadSetting("Debugging", Settings::values.disable_macro_jit);
ReadSetting("Debugging", Settings::values.use_gdbstub);
ReadSetting("Debugging", Settings::values.gdbstub_port);
const auto title_list = sdl2_config->Get("AddOns", "title_ids", ""); const auto title_list = sdl2_config->Get("AddOns", "title_ids", "");
std::stringstream ss(title_list); std::stringstream ss(title_list);

View file

@ -437,6 +437,11 @@ disable_macro_jit=false
# Presents guest frames as they become available. Experimental. # Presents guest frames as they become available. Experimental.
# false: Disabled (default), true: Enabled # false: Disabled (default), true: Enabled
disable_fps_limit=false disable_fps_limit=false
# Determines whether to enable the GDB stub and wait for the debugger to attach before running.
# false: Disabled (default), true: Enabled
use_gdbstub=false
# The port to use for the GDB server, if it is enabled.
gdbstub_port=6543
[WebService] [WebService]
# Whether or not to enable telemetry # Whether or not to enable telemetry

View file

@ -162,7 +162,15 @@ void EmuWindow_SDL2::WaitEvent() {
SDL_Event event; SDL_Event event;
if (!SDL_WaitEvent(&event)) { if (!SDL_WaitEvent(&event)) {
LOG_CRITICAL(Frontend, "SDL_WaitEvent failed: {}", SDL_GetError()); const char* error = SDL_GetError();
if (!error || strcmp(error, "") == 0) {
// https://github.com/libsdl-org/SDL/issues/5780
// Sometimes SDL will return without actually having hit an error condition;
// just ignore it in this case.
return;
}
LOG_CRITICAL(Frontend, "SDL_WaitEvent failed: {}", error);
exit(1); exit(1);
} }

View file

@ -217,10 +217,19 @@ int main(int argc, char** argv) {
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {}); [](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
} }
system.RegisterExitCallback([&] {
// Just exit right away.
exit(0);
});
void(system.Run()); void(system.Run());
if (system.DebuggerEnabled()) {
system.InitializeDebugger();
}
while (emu_window->IsOpen()) { while (emu_window->IsOpen()) {
emu_window->WaitEvent(); emu_window->WaitEvent();
} }
system.DetachDebugger();
void(system.Pause()); void(system.Pause());
system.Shutdown(); system.Shutdown();