2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2017-02-24 17:59:41 +00:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
2013-09-28 07:32:45 +00:00
|
|
|
#include <set>
|
2017-12-19 14:38:18 +00:00
|
|
|
#include <chrono>
|
2017-02-27 20:57:46 +00:00
|
|
|
#include <mutex>
|
2017-12-19 14:38:18 +00:00
|
|
|
#include <condition_variable>
|
2013-12-30 09:17:11 +00:00
|
|
|
|
2020-10-04 08:30:18 +00:00
|
|
|
#include "Common/System/NativeApp.h"
|
|
|
|
#include "Common/System/System.h"
|
2020-10-04 08:10:55 +00:00
|
|
|
#include "Common/System/Display.h"
|
2020-08-15 18:53:08 +00:00
|
|
|
#include "Common/TimeUtil.h"
|
2020-10-01 07:27:25 +00:00
|
|
|
#include "Common/Thread/ThreadUtil.h"
|
2020-10-04 08:04:01 +00:00
|
|
|
#include "Common/Profiler/Profiler.h"
|
2013-03-29 17:50:08 +00:00
|
|
|
|
2018-05-02 14:14:46 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2020-07-04 18:30:05 +00:00
|
|
|
#include "Common/Log.h"
|
2013-03-29 17:50:08 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
2018-05-02 14:14:46 +00:00
|
|
|
#include "Core/Host.h"
|
2013-03-29 17:50:08 +00:00
|
|
|
#include "Core/MemMap.h"
|
2013-09-15 01:43:23 +00:00
|
|
|
#include "Core/SaveState.h"
|
2013-03-29 17:50:08 +00:00
|
|
|
#include "Core/System.h"
|
2018-05-02 14:14:46 +00:00
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
2013-03-29 17:50:08 +00:00
|
|
|
#include "Core/MIPS/MIPS.h"
|
2018-06-16 20:53:41 +00:00
|
|
|
#include "GPU/Debugger/Stepping.h"
|
2013-12-29 23:11:29 +00:00
|
|
|
|
2013-02-18 22:25:06 +00:00
|
|
|
#ifdef _WIN32
|
2018-02-25 09:27:59 +00:00
|
|
|
#include "Common/CommonWindows.h"
|
2013-03-29 19:51:14 +00:00
|
|
|
#include "Windows/InputDevice.h"
|
2013-02-18 22:25:06 +00:00
|
|
|
#endif
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2015-03-01 06:20:14 +00:00
|
|
|
// Time until we stop considering the core active without user input.
|
|
|
|
// Should this be configurable? 2 hours currently.
|
|
|
|
static const double ACTIVITY_IDLE_TIMEOUT = 2.0 * 3600.0;
|
|
|
|
|
2017-12-19 14:38:18 +00:00
|
|
|
static std::condition_variable m_StepCond;
|
2017-02-27 20:57:46 +00:00
|
|
|
static std::mutex m_hStepMutex;
|
2017-12-19 14:38:18 +00:00
|
|
|
static std::condition_variable m_InactiveCond;
|
2017-02-27 20:57:46 +00:00
|
|
|
static std::mutex m_hInactiveMutex;
|
2013-09-15 01:43:23 +00:00
|
|
|
static bool singleStepPending = false;
|
2018-04-20 04:14:01 +00:00
|
|
|
static int steppingCounter = 0;
|
2018-06-11 21:54:42 +00:00
|
|
|
static std::set<CoreLifecycleFunc> lifecycleFuncs;
|
|
|
|
static std::set<CoreStopRequestFunc> stopFuncs;
|
2014-06-29 11:11:06 +00:00
|
|
|
static bool windowHidden = false;
|
2015-03-01 06:20:14 +00:00
|
|
|
static double lastActivity = 0.0;
|
|
|
|
static double lastKeepAwake = 0.0;
|
2015-12-31 15:59:40 +00:00
|
|
|
static GraphicsContext *graphicsContext;
|
2016-07-25 00:04:06 +00:00
|
|
|
static bool powerSaving = false;
|
2013-02-23 20:59:40 +00:00
|
|
|
|
2020-07-04 18:57:05 +00:00
|
|
|
static ExceptionInfo g_exceptionInfo;
|
|
|
|
|
2016-01-01 13:08:23 +00:00
|
|
|
void Core_SetGraphicsContext(GraphicsContext *ctx) {
|
2016-07-25 00:04:06 +00:00
|
|
|
graphicsContext = ctx;
|
2016-10-01 18:22:53 +00:00
|
|
|
PSP_CoreParameter().graphicsContext = graphicsContext;
|
2016-01-01 13:08:23 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 11:11:06 +00:00
|
|
|
void Core_NotifyWindowHidden(bool hidden) {
|
|
|
|
windowHidden = hidden;
|
|
|
|
// TODO: Wait until we can react?
|
|
|
|
}
|
|
|
|
|
2015-03-01 06:20:14 +00:00
|
|
|
void Core_NotifyActivity() {
|
|
|
|
lastActivity = time_now_d();
|
|
|
|
}
|
|
|
|
|
2018-04-22 15:33:22 +00:00
|
|
|
void Core_ListenLifecycle(CoreLifecycleFunc func) {
|
2018-06-11 21:54:42 +00:00
|
|
|
lifecycleFuncs.insert(func);
|
2013-09-28 07:32:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 15:33:22 +00:00
|
|
|
void Core_NotifyLifecycle(CoreLifecycle stage) {
|
2018-06-11 21:54:42 +00:00
|
|
|
for (auto func : lifecycleFuncs) {
|
|
|
|
func(stage);
|
2013-10-12 08:44:12 +00:00
|
|
|
}
|
2013-09-28 07:32:45 +00:00
|
|
|
}
|
|
|
|
|
2018-06-11 21:54:42 +00:00
|
|
|
void Core_ListenStopRequest(CoreStopRequestFunc func) {
|
|
|
|
stopFuncs.insert(func);
|
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_Stop() {
|
2020-07-13 04:27:24 +00:00
|
|
|
g_exceptionInfo.type = ExceptionType::NONE;
|
2013-02-23 20:59:40 +00:00
|
|
|
Core_UpdateState(CORE_POWERDOWN);
|
2018-06-11 21:54:42 +00:00
|
|
|
for (auto func : stopFuncs) {
|
|
|
|
func();
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
bool Core_IsStepping() {
|
2012-11-01 15:19:01 +00:00
|
|
|
return coreState == CORE_STEPPING || coreState == CORE_POWERDOWN;
|
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
bool Core_IsActive() {
|
2013-06-08 00:32:07 +00:00
|
|
|
return coreState == CORE_RUNNING || coreState == CORE_NEXTFRAME || coreStatePending;
|
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
bool Core_IsInactive() {
|
2013-02-23 20:59:40 +00:00
|
|
|
return coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME && !coreStatePending;
|
|
|
|
}
|
2013-02-23 21:21:28 +00:00
|
|
|
|
2018-05-01 01:59:48 +00:00
|
|
|
static inline void Core_StateProcessed() {
|
|
|
|
if (coreStatePending) {
|
|
|
|
std::lock_guard<std::mutex> guard(m_hInactiveMutex);
|
|
|
|
coreStatePending = false;
|
|
|
|
m_InactiveCond.notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_WaitInactive() {
|
|
|
|
while (Core_IsActive()) {
|
2017-12-19 14:38:18 +00:00
|
|
|
std::unique_lock<std::mutex> guard(m_hInactiveMutex);
|
|
|
|
m_InactiveCond.wait(guard);
|
2013-10-12 08:44:12 +00:00
|
|
|
}
|
2013-02-23 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_WaitInactive(int milliseconds) {
|
|
|
|
if (Core_IsActive()) {
|
2017-12-19 14:38:18 +00:00
|
|
|
std::unique_lock<std::mutex> guard(m_hInactiveMutex);
|
|
|
|
m_InactiveCond.wait_for(guard, std::chrono::milliseconds(milliseconds));
|
2013-10-12 08:44:12 +00:00
|
|
|
}
|
2013-02-23 21:21:28 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 00:04:06 +00:00
|
|
|
void Core_SetPowerSaving(bool mode) {
|
|
|
|
powerSaving = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Core_GetPowerSaving() {
|
|
|
|
return powerSaving;
|
|
|
|
}
|
|
|
|
|
2017-01-17 10:21:00 +00:00
|
|
|
static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
|
|
|
|
// Can't take this from config as it will not be set if windows is maximized.
|
2017-08-07 11:18:19 +00:00
|
|
|
int w = (int)(pixelWidth * g_dpi_scale_x);
|
|
|
|
int h = (int)(pixelHeight * g_dpi_scale_y);
|
2017-01-17 10:21:00 +00:00
|
|
|
return g_Config.IsPortrait() ? (h < 480 + 80) : (w < 480 + 80);
|
|
|
|
}
|
|
|
|
|
2017-01-16 12:08:26 +00:00
|
|
|
// TODO: Feels like this belongs elsewhere.
|
2017-01-17 10:21:00 +00:00
|
|
|
bool UpdateScreenScale(int width, int height) {
|
|
|
|
bool smallWindow;
|
2020-01-05 07:46:27 +00:00
|
|
|
#if defined(USING_QT_UI)
|
|
|
|
g_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI);
|
|
|
|
float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI);
|
|
|
|
g_dpi_scale_x = g_logical_dpi / g_dpi;
|
|
|
|
g_dpi_scale_y = g_logical_dpi / g_dpi;
|
|
|
|
#elif PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
|
2020-01-05 17:04:07 +00:00
|
|
|
g_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI);
|
2017-08-07 11:18:19 +00:00
|
|
|
g_dpi_scale_x = 96.0f / g_dpi;
|
|
|
|
g_dpi_scale_y = 96.0f / g_dpi;
|
2017-01-16 12:08:26 +00:00
|
|
|
#else
|
2017-08-07 10:16:08 +00:00
|
|
|
g_dpi = 96.0f;
|
2017-08-07 11:18:19 +00:00
|
|
|
g_dpi_scale_x = 1.0f;
|
|
|
|
g_dpi_scale_y = 1.0f;
|
2017-01-16 12:08:26 +00:00
|
|
|
#endif
|
2017-08-07 11:18:19 +00:00
|
|
|
g_dpi_scale_real_x = g_dpi_scale_x;
|
|
|
|
g_dpi_scale_real_y = g_dpi_scale_y;
|
2017-03-12 19:17:35 +00:00
|
|
|
|
2017-01-17 12:02:47 +00:00
|
|
|
smallWindow = IsWindowSmall(width, height);
|
2017-01-17 10:21:00 +00:00
|
|
|
if (smallWindow) {
|
2017-03-17 12:29:22 +00:00
|
|
|
g_dpi /= 2.0f;
|
2017-08-07 11:18:19 +00:00
|
|
|
g_dpi_scale_x *= 2.0f;
|
|
|
|
g_dpi_scale_y *= 2.0f;
|
2017-01-17 10:21:00 +00:00
|
|
|
}
|
2017-08-07 11:18:19 +00:00
|
|
|
pixel_in_dps_x = 1.0f / g_dpi_scale_x;
|
|
|
|
pixel_in_dps_y = 1.0f / g_dpi_scale_y;
|
2014-12-28 21:19:19 +00:00
|
|
|
|
2017-08-07 11:18:19 +00:00
|
|
|
int new_dp_xres = width * g_dpi_scale_x;
|
|
|
|
int new_dp_yres = height * g_dpi_scale_y;
|
2014-12-28 21:19:19 +00:00
|
|
|
|
|
|
|
bool dp_changed = new_dp_xres != dp_xres || new_dp_yres != dp_yres;
|
|
|
|
bool px_changed = pixel_xres != width || pixel_yres != height;
|
|
|
|
|
|
|
|
if (dp_changed || px_changed) {
|
|
|
|
dp_xres = new_dp_xres;
|
|
|
|
dp_yres = new_dp_yres;
|
|
|
|
pixel_xres = width;
|
|
|
|
pixel_yres = height;
|
2020-08-15 14:13:24 +00:00
|
|
|
INFO_LOG(G3D, "pixel_res: %dx%d. Calling NativeResized()", pixel_xres, pixel_yres);
|
2014-12-28 21:19:19 +00:00
|
|
|
NativeResized();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-03-29 17:50:08 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 01:08:41 +00:00
|
|
|
// Note: not used on Android.
|
2017-03-15 05:01:18 +00:00
|
|
|
void UpdateRunLoop() {
|
2014-06-30 17:04:44 +00:00
|
|
|
if (windowHidden && g_Config.bPauseWhenMinimized) {
|
2014-07-01 03:29:39 +00:00
|
|
|
sleep_ms(16);
|
2014-06-29 14:17:34 +00:00
|
|
|
return;
|
2014-07-01 03:29:39 +00:00
|
|
|
}
|
2017-03-15 05:01:18 +00:00
|
|
|
NativeUpdate();
|
2020-12-23 13:32:24 +00:00
|
|
|
NativeRender(graphicsContext);
|
2013-10-12 08:40:33 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 16:59:00 +00:00
|
|
|
void KeepScreenAwake() {
|
2018-02-05 15:21:39 +00:00
|
|
|
#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP)
|
2017-12-19 16:59:00 +00:00
|
|
|
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-15 05:01:18 +00:00
|
|
|
void Core_RunLoop(GraphicsContext *ctx) {
|
2015-12-31 15:59:40 +00:00
|
|
|
graphicsContext = ctx;
|
2014-06-22 07:38:46 +00:00
|
|
|
while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) {
|
2018-05-01 01:59:48 +00:00
|
|
|
// In case it was pending, we're not in game anymore. We won't get to Core_Run().
|
|
|
|
Core_StateProcessed();
|
2013-10-12 08:40:33 +00:00
|
|
|
double startTime = time_now_d();
|
2017-03-15 05:01:18 +00:00
|
|
|
UpdateRunLoop();
|
2013-10-12 08:40:33 +00:00
|
|
|
|
2013-03-29 17:50:08 +00:00
|
|
|
// Simple throttling to not burn the GPU in the menu.
|
2013-10-12 08:40:33 +00:00
|
|
|
double diffTime = time_now_d() - startTime;
|
2014-07-15 15:03:25 +00:00
|
|
|
int sleepTime = (int)(1000.0 / 60.0) - (int)(diffTime * 1000.0);
|
2013-10-12 08:40:33 +00:00
|
|
|
if (sleepTime > 0)
|
2017-12-20 09:22:15 +00:00
|
|
|
sleep_ms(sleepTime);
|
2014-06-29 11:11:06 +00:00
|
|
|
if (!windowHidden) {
|
2015-12-31 15:59:40 +00:00
|
|
|
ctx->SwapBuffers();
|
2014-06-29 11:11:06 +00:00
|
|
|
}
|
2013-10-12 08:40:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 17:58:30 +00:00
|
|
|
while ((coreState == CORE_RUNNING || coreState == CORE_STEPPING) && GetUIState() == UISTATE_INGAME) {
|
2017-03-15 05:01:18 +00:00
|
|
|
UpdateRunLoop();
|
2014-07-01 03:29:39 +00:00
|
|
|
if (!windowHidden && !Core_IsStepping()) {
|
2015-12-31 15:59:40 +00:00
|
|
|
ctx->SwapBuffers();
|
2015-03-01 06:20:14 +00:00
|
|
|
|
|
|
|
// Keep the system awake for longer than normal for cutscenes and the like.
|
|
|
|
const double now = time_now_d();
|
|
|
|
if (now < lastActivity + ACTIVITY_IDLE_TIMEOUT) {
|
|
|
|
// Only resetting it ever prime number seconds in case the call is expensive.
|
|
|
|
// Using a prime number to ensure there's no interaction with other periodic events.
|
|
|
|
if (now - lastKeepAwake > 89.0 || now < lastKeepAwake) {
|
2017-12-19 16:59:00 +00:00
|
|
|
KeepScreenAwake();
|
2015-03-01 06:20:14 +00:00
|
|
|
lastKeepAwake = now;
|
|
|
|
}
|
|
|
|
}
|
2013-03-30 07:34:27 +00:00
|
|
|
}
|
2013-02-18 22:25:06 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_DoSingleStep() {
|
2018-04-30 01:08:41 +00:00
|
|
|
std::lock_guard<std::mutex> guard(m_hStepMutex);
|
2013-09-15 01:43:23 +00:00
|
|
|
singleStepPending = true;
|
2018-04-20 04:04:47 +00:00
|
|
|
m_StepCond.notify_all();
|
2013-09-15 01:43:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_UpdateSingleStep() {
|
2018-04-30 01:08:41 +00:00
|
|
|
std::lock_guard<std::mutex> guard(m_hStepMutex);
|
2018-04-20 04:04:47 +00:00
|
|
|
m_StepCond.notify_all();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_SingleStep() {
|
2020-07-13 04:27:24 +00:00
|
|
|
g_exceptionInfo.type = ExceptionType::NONE;
|
2012-11-01 15:19:01 +00:00
|
|
|
currentMIPS->SingleStep();
|
2018-04-30 01:38:17 +00:00
|
|
|
if (coreState == CORE_STEPPING)
|
|
|
|
steppingCounter++;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 01:38:17 +00:00
|
|
|
static inline bool Core_WaitStepping() {
|
2018-04-30 01:08:41 +00:00
|
|
|
std::unique_lock<std::mutex> guard(m_hStepMutex);
|
2018-06-23 17:58:30 +00:00
|
|
|
// We only wait 16ms so that we can still draw UI or react to events.
|
2018-04-30 01:08:41 +00:00
|
|
|
if (!singleStepPending && coreState == CORE_STEPPING)
|
2018-06-23 17:58:30 +00:00
|
|
|
m_StepCond.wait_for(guard, std::chrono::milliseconds(16));
|
2018-04-30 01:38:17 +00:00
|
|
|
|
|
|
|
bool result = singleStepPending;
|
|
|
|
singleStepPending = false;
|
|
|
|
return result;
|
2018-04-30 01:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core_ProcessStepping() {
|
2018-05-01 01:59:48 +00:00
|
|
|
Core_StateProcessed();
|
2018-04-30 01:08:41 +00:00
|
|
|
|
|
|
|
// Check if there's any pending save state actions.
|
|
|
|
SaveState::Process();
|
|
|
|
if (coreState != CORE_STEPPING) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-16 20:53:41 +00:00
|
|
|
// Or any GPU actions.
|
|
|
|
GPUStepping::SingleStep();
|
|
|
|
|
2018-05-02 05:18:33 +00:00
|
|
|
// We're not inside jit now, so it's safe to clear the breakpoints.
|
2018-06-23 17:58:30 +00:00
|
|
|
static int lastSteppingCounter = -1;
|
|
|
|
if (lastSteppingCounter != steppingCounter) {
|
|
|
|
CBreakPoints::ClearTemporaryBreakPoints();
|
|
|
|
host->UpdateDisassembly();
|
|
|
|
host->UpdateMemView();
|
|
|
|
lastSteppingCounter = steppingCounter;
|
|
|
|
}
|
2018-04-30 01:08:41 +00:00
|
|
|
|
|
|
|
// Need to check inside the lock to avoid races.
|
2018-04-30 01:38:17 +00:00
|
|
|
bool doStep = Core_WaitStepping();
|
2018-04-30 01:08:41 +00:00
|
|
|
|
|
|
|
// We may still be stepping without singleStepPending to process a save state.
|
2018-04-30 01:38:17 +00:00
|
|
|
if (doStep && coreState == CORE_STEPPING) {
|
2018-04-30 01:08:41 +00:00
|
|
|
Core_SingleStep();
|
|
|
|
// Update disasm dialog.
|
|
|
|
host->UpdateDisassembly();
|
|
|
|
host->UpdateMemView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 14:42:18 +00:00
|
|
|
// Many platforms, like Android, do not call this function but handle things on their own.
|
2017-12-19 16:59:00 +00:00
|
|
|
// Instead they simply call NativeRender and NativeUpdate directly.
|
2017-12-19 14:42:18 +00:00
|
|
|
void Core_Run(GraphicsContext *ctx) {
|
2012-11-01 15:19:01 +00:00
|
|
|
host->UpdateDisassembly();
|
2017-12-19 16:59:00 +00:00
|
|
|
while (true) {
|
2014-06-22 07:38:46 +00:00
|
|
|
if (GetUIState() != UISTATE_INGAME) {
|
2018-05-01 01:59:48 +00:00
|
|
|
Core_StateProcessed();
|
2014-06-22 07:38:46 +00:00
|
|
|
if (GetUIState() == UISTATE_EXIT) {
|
2018-02-07 14:52:19 +00:00
|
|
|
UpdateRunLoop();
|
2013-10-12 08:40:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-15 05:01:18 +00:00
|
|
|
Core_RunLoop(ctx);
|
2013-10-12 08:40:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-12-19 16:59:00 +00:00
|
|
|
switch (coreState) {
|
2012-11-01 15:19:01 +00:00
|
|
|
case CORE_RUNNING:
|
2018-04-30 01:38:17 +00:00
|
|
|
case CORE_STEPPING:
|
2013-09-15 01:43:23 +00:00
|
|
|
// enter a fast runloop
|
2017-03-15 05:01:18 +00:00
|
|
|
Core_RunLoop(ctx);
|
2018-04-30 01:38:17 +00:00
|
|
|
if (coreState == CORE_POWERDOWN) {
|
2018-05-01 01:59:48 +00:00
|
|
|
Core_StateProcessed();
|
2013-09-15 04:19:10 +00:00
|
|
|
return;
|
2018-04-30 01:38:17 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
break;
|
|
|
|
|
2013-11-10 04:56:11 +00:00
|
|
|
case CORE_POWERUP:
|
2012-11-01 15:19:01 +00:00
|
|
|
case CORE_POWERDOWN:
|
2020-07-04 18:19:56 +00:00
|
|
|
case CORE_BOOT_ERROR:
|
|
|
|
case CORE_RUNTIME_ERROR:
|
2013-09-15 01:43:23 +00:00
|
|
|
// Exit loop!!
|
2018-05-01 01:59:48 +00:00
|
|
|
Core_StateProcessed();
|
2013-03-23 17:30:52 +00:00
|
|
|
|
2013-02-23 20:59:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case CORE_NEXTFRAME:
|
2012-11-01 15:19:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-12 08:44:12 +00:00
|
|
|
void Core_EnableStepping(bool step) {
|
|
|
|
if (step) {
|
2012-11-01 15:19:01 +00:00
|
|
|
host->SetDebugMode(true);
|
2013-02-23 20:59:40 +00:00
|
|
|
Core_UpdateState(CORE_STEPPING);
|
2018-04-20 04:14:01 +00:00
|
|
|
steppingCounter++;
|
2013-10-12 08:44:12 +00:00
|
|
|
} else {
|
2012-11-01 15:19:01 +00:00
|
|
|
host->SetDebugMode(false);
|
2020-07-13 04:27:24 +00:00
|
|
|
// Clear the exception if we resume.
|
|
|
|
g_exceptionInfo.type = ExceptionType::NONE;
|
2012-11-01 15:19:01 +00:00
|
|
|
coreState = CORE_RUNNING;
|
2013-02-23 20:59:40 +00:00
|
|
|
coreStatePending = false;
|
2018-04-20 04:04:47 +00:00
|
|
|
m_StepCond.notify_all();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-20 04:14:01 +00:00
|
|
|
|
2020-07-04 18:57:05 +00:00
|
|
|
bool Core_NextFrame() {
|
|
|
|
if (coreState == CORE_RUNNING) {
|
|
|
|
coreState = CORE_NEXTFRAME;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 04:14:01 +00:00
|
|
|
int Core_GetSteppingCounter() {
|
|
|
|
return steppingCounter;
|
|
|
|
}
|
2020-07-04 18:30:05 +00:00
|
|
|
|
2019-02-12 12:29:37 +00:00
|
|
|
const char *ExceptionTypeAsString(ExceptionType type) {
|
2020-07-04 18:57:05 +00:00
|
|
|
switch (type) {
|
2019-02-12 12:29:37 +00:00
|
|
|
case ExceptionType::MEMORY: return "Invalid Memory Access";
|
2020-07-04 18:57:05 +00:00
|
|
|
case ExceptionType::BREAK: return "Break";
|
2020-07-04 21:45:03 +00:00
|
|
|
case ExceptionType::BAD_EXEC_ADDR: return "Bad Execution Address";
|
2020-07-04 18:57:05 +00:00
|
|
|
default: return "N/A";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 12:29:37 +00:00
|
|
|
const char *MemoryExceptionTypeAsString(MemoryExceptionType type) {
|
2020-07-04 18:30:05 +00:00
|
|
|
switch (type) {
|
2020-07-13 07:17:42 +00:00
|
|
|
case MemoryExceptionType::UNKNOWN: return "Unknown";
|
2020-07-04 18:57:05 +00:00
|
|
|
case MemoryExceptionType::READ_WORD: return "Read Word";
|
|
|
|
case MemoryExceptionType::WRITE_WORD: return "Write Word";
|
|
|
|
case MemoryExceptionType::READ_BLOCK: return "Read Block";
|
|
|
|
case MemoryExceptionType::WRITE_BLOCK: return "Read/Write Block";
|
|
|
|
default:
|
|
|
|
return "N/A";
|
2020-07-04 18:30:05 +00:00
|
|
|
}
|
2020-07-04 18:57:05 +00:00
|
|
|
}
|
2020-07-04 18:30:05 +00:00
|
|
|
|
2020-07-13 04:59:08 +00:00
|
|
|
const char *ExecExceptionTypeAsString(ExecExceptionType type) {
|
|
|
|
switch (type) {
|
|
|
|
case ExecExceptionType::JUMP: return "CPU Jump";
|
|
|
|
case ExecExceptionType::THREAD: return "Thread switch";
|
|
|
|
default:
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-04 18:57:05 +00:00
|
|
|
void Core_MemoryException(u32 address, u32 pc, MemoryExceptionType type) {
|
2019-02-12 12:29:37 +00:00
|
|
|
const char *desc = MemoryExceptionTypeAsString(type);
|
2020-07-04 18:30:05 +00:00
|
|
|
// In jit, we only flush PC when bIgnoreBadMemAccess is off.
|
|
|
|
if (g_Config.iCpuCore == (int)CPUCore::JIT && g_Config.bIgnoreBadMemAccess) {
|
|
|
|
WARN_LOG(MEMMAP, "%s: Invalid address %08x", desc, address);
|
|
|
|
} else {
|
|
|
|
WARN_LOG(MEMMAP, "%s: Invalid address %08x PC %08x LR %08x", desc, address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_Config.bIgnoreBadMemAccess) {
|
2019-02-12 12:29:37 +00:00
|
|
|
ExceptionInfo &e = g_exceptionInfo;
|
|
|
|
e = {};
|
|
|
|
e.type = ExceptionType::MEMORY;
|
|
|
|
e.info = "";
|
|
|
|
e.memory_type = type;
|
|
|
|
e.address = address;
|
|
|
|
e.pc = pc;
|
2020-07-04 18:30:05 +00:00
|
|
|
Core_EnableStepping(true);
|
|
|
|
host->SetDebugMode(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 10:38:05 +00:00
|
|
|
void Core_MemoryExceptionInfo(u32 address, u32 pc, MemoryExceptionType type, std::string additionalInfo) {
|
|
|
|
const char *desc = MemoryExceptionTypeAsString(type);
|
|
|
|
// In jit, we only flush PC when bIgnoreBadMemAccess is off.
|
|
|
|
if (g_Config.iCpuCore == (int)CPUCore::JIT && g_Config.bIgnoreBadMemAccess) {
|
|
|
|
WARN_LOG(MEMMAP, "%s: Invalid address %08x. %s", desc, address, additionalInfo.c_str());
|
|
|
|
} else {
|
|
|
|
WARN_LOG(MEMMAP, "%s: Invalid address %08x PC %08x LR %08x %s", desc, address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA], additionalInfo.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_Config.bIgnoreBadMemAccess) {
|
|
|
|
ExceptionInfo &e = g_exceptionInfo;
|
|
|
|
e = {};
|
|
|
|
e.type = ExceptionType::MEMORY;
|
|
|
|
e.info = additionalInfo;
|
|
|
|
e.memory_type = type;
|
|
|
|
e.address = address;
|
|
|
|
e.pc = pc;
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
host->SetDebugMode(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 04:59:08 +00:00
|
|
|
void Core_ExecException(u32 address, u32 pc, ExecExceptionType type) {
|
|
|
|
const char *desc = ExecExceptionTypeAsString(type);
|
|
|
|
WARN_LOG(MEMMAP, "%s: Invalid destination %08x PC %08x LR %08x", desc, address, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]);
|
|
|
|
|
|
|
|
if (!g_Config.bIgnoreBadMemAccess) {
|
|
|
|
ExceptionInfo &e = g_exceptionInfo;
|
|
|
|
e = {};
|
|
|
|
e.type = ExceptionType::BAD_EXEC_ADDR;
|
|
|
|
e.info = "";
|
|
|
|
e.exec_type = type;
|
|
|
|
e.address = address;
|
|
|
|
e.pc = pc;
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
host->SetDebugMode(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-04 18:30:05 +00:00
|
|
|
void Core_Break() {
|
|
|
|
ERROR_LOG(CPU, "BREAK!");
|
2020-07-04 18:57:05 +00:00
|
|
|
|
|
|
|
ExceptionInfo &e = g_exceptionInfo;
|
|
|
|
e = {};
|
|
|
|
e.type = ExceptionType::BREAK;
|
|
|
|
e.info = "";
|
|
|
|
|
2020-07-04 18:30:05 +00:00
|
|
|
if (!g_Config.bIgnoreBadMemAccess) {
|
|
|
|
Core_EnableStepping(true);
|
|
|
|
host->SetDebugMode(true);
|
|
|
|
}
|
|
|
|
}
|
2020-07-04 18:57:05 +00:00
|
|
|
|
2019-02-12 12:29:37 +00:00
|
|
|
const ExceptionInfo &Core_GetExceptionInfo() {
|
2020-07-04 18:57:05 +00:00
|
|
|
return g_exceptionInfo;
|
|
|
|
}
|