From 8480c350dead8e55e64675f94d5da446c05ebfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:26:28 -0300 Subject: [PATCH 1/2] [irx loader] add an IRX equivalent of `strerror()` returns a string describibg an IRX module startup error based on the return value and ID value (being the last one actually an error returned by MODLOAD.IRX if it is < 0) --- engine/src/irx/irx_loader.cpp | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/engine/src/irx/irx_loader.cpp b/engine/src/irx/irx_loader.cpp index ec7f77d0..a4847fb0 100644 --- a/engine/src/irx/irx_loader.cpp +++ b/engine/src/irx/irx_loader.cpp @@ -54,6 +54,92 @@ IrxLoader::IrxLoader() { IrxLoader::~IrxLoader() {} + +std::mapIrxLoader::IOPErrors = { + {-1, "Unknown error"}, + {-101, "Illegal intrcode"}, + {-102, "CPU ID"}, + {-103, "Interrupt disabled"}, + {-104, "Found handler"}, + {-105, "Handler not found"}, + {-150, "No timer"}, + {-151, "Illegal timer ID"}, + {-152, "Illegal source"}, + {-153, "Illegal prescale"}, + {-154, "Timer busy"}, + {-155, "Timer not setup"}, + {-156, "Timer not in use"}, + {-160, "Unit used"}, + {-161, "Unit not used"}, + {-162, "No ROMDIR"}, + {-200, "Linker error (missing driver dependency/imports)"}, + {-201, "Illegal object"}, + {-202, "Unknown Module"}, + {-203, "No such file"}, + {-204, "File error"}, + {-205, "Memory in use"}, + {-206, "Already started"}, + {-207, "Not started"}, + {-208, "Module already stopped"}, + {-209, "Cannot stop module"}, + {-210, "Module not stopped"}, + {-211, "Module not removable"}, + {-212, "Library found"}, + {-213, "Library not found"}, + {-214, "Illegal library"}, + {-215, "Library in use"}, + {-216, "Already stopping"}, + {-217, "Illegal offset"}, + {-218, "Illegal position"}, + {-219, "Illegal access"}, + {-220, "Illegal flag"}, + {-400, "NO MEMORY"}, + {-401, "Illegal attribute"}, + {-402, "Illegal entry"}, + {-403, "Illegal priority"}, + {-404, "Illegal stack size"}, + {-405, "Illegal mode"}, + {-406, "Illegal THID"}, + {-407, "Unknown THID"}, + {-408, "Unknown SEMID"}, + {-409, "Unknown EVFID"}, + {-410, "Unknown MBXID"}, + {-411, "Unknown VPLID"}, + {-412, "Unknown FPLID"}, + {-413, "Dormant"}, + {-414, "Not dormant"}, + {-415, "Not suspend"}, + {-416, "Not Waiting"}, + {-417, "Cannot wait"}, + {-418, "KE_RELEASE_WAIT"}, + {-419, "KE_SEMA_ZERO"}, + {-420, "KE_SEMA_OVF"}, + {-421, "KE_EVF_COND"}, + {-422, "KE_EVF_MULTI"}, + {-423, "KE_EVF_ILPAT"}, + {-424, "KE_MBOX_NOMSG"}, + {-425, "Wait delete"}, + {-426, "Illegal memblock"}, + {-427, "Illegal memsize"}, + {-428, "Illegal SPAD addr"}, + {-429, "SPAD in use"}, + {-430, "SPAD not in use"}, + {-431, "Illegal type"}, + {-432, "Illegal size"}, +}; + +/** + * @brief an equivalent of C standard `strerror()` for the IOP error codes + * @note although this is intended for checking IRX module error status. it can be used to evaluate return values from any operation requested to the IOP. such as module unload request. simply pass the error number to the ID parameter + * @param ID module ID or IOP related return value + * @param RET module return value obtained by the last parameter of `SifExecModuleBuffer` + * @return description of an IOP error or IRX startup error + */ +std::string IrxLoader::GetIrxErrorDescription(const int ID, const int RET = 0) { + if (RET == 1) return "Module willingly requested to be unloaded from IOP"; + return IOPErrors[ID] +} + void IrxLoader::loadAll(const bool& withUsb, const bool& isLoggingToFile) { if (isLoaded) { TYRA_LOG("IRX modules already loaded!"); From 9f497c8b4d890e65465bf30b7c0a635fdea5c778 Mon Sep 17 00:00:00 2001 From: Matias Israelson <57065102+israpps@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:25:31 -0300 Subject: [PATCH 2/2] [irx loader] fix irx load error check and use the error description --- engine/inc/irx/irx_loader.hpp | 3 +++ engine/src/irx/irx_loader.cpp | 38 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/engine/inc/irx/irx_loader.hpp b/engine/inc/irx/irx_loader.hpp index 168797e6..8e7b5381 100644 --- a/engine/inc/irx/irx_loader.hpp +++ b/engine/inc/irx/irx_loader.hpp @@ -11,6 +11,7 @@ #pragma once #include +#include namespace Tyra { @@ -34,6 +35,8 @@ class IrxLoader { int applyRpcPatches(); void waitUntilUsbDeviceIsReady(); void delay(int count); + std::string GetIrxErrorDescription(const int ID, const int RET); + std::mapIOPErrors; }; } // namespace Tyra diff --git a/engine/src/irx/irx_loader.cpp b/engine/src/irx/irx_loader.cpp index a4847fb0..f52dda86 100644 --- a/engine/src/irx/irx_loader.cpp +++ b/engine/src/irx/irx_loader.cpp @@ -137,7 +137,7 @@ std::mapIrxLoader::IOPErrors = { */ std::string IrxLoader::GetIrxErrorDescription(const int ID, const int RET = 0) { if (RET == 1) return "Module willingly requested to be unloaded from IOP"; - return IOPErrors[ID] + return IrxLoader::IOPErrors[ID] } void IrxLoader::loadAll(const bool& withUsb, const bool& isLoggingToFile) { @@ -186,26 +186,26 @@ int IrxLoader::applyRpcPatches() { void IrxLoader::loadLibsd(const bool& verbose) { if (verbose) TYRA_LOG("IRX: Loading libsd..."); - int ret; - SifExecModuleBuffer(&libsd_irx, size_libsd_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: libsd_irx"); + int ret, id; + id = SifExecModuleBuffer(&libsd_irx, size_libsd_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: libsd_irx", IrxLoader::GetIrxErrorDescription(id, ret)); if (verbose) TYRA_LOG("IRX: Libsd loaded!"); } void IrxLoader::loadIO(const bool& verbose) { - int ret; + int ret, id; if (verbose) TYRA_LOG("IRX: Loading iomanX..."); - SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: iomanX_irx"); + id = SifExecModuleBuffer(&iomanX_irx, size_iomanX_irx, 0, nullptr, &ret); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: iomanX_irx", IrxLoader::GetIrxErrorDescription(id, ret)); if (verbose) TYRA_LOG("IRX: iomanX loaded!"); if (verbose) TYRA_LOG("IRX: Loading fileXio..."); SifExecModuleBuffer(&fileXio_irx, size_fileXio_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: fileXio_irx"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: fileXio_irx", IrxLoader::GetIrxErrorDescription(id, ret)); if (verbose) TYRA_LOG("IRX: fileXio_irx loaded!"); @@ -214,19 +214,19 @@ void IrxLoader::loadIO(const bool& verbose) { void IrxLoader::loadUsbModules(const bool& verbose) { if (verbose) TYRA_LOG("IRX: Loading usb modules..."); - int ret; + int ret, id; SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: usbd_irx"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: usbd_irx", IrxLoader::GetIrxErrorDescription(id, ret)); SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: bdm_irx"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: bdm_irx", IrxLoader::GetIrxErrorDescription(id, ret)); SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: bdmfs_fatfs"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: bdmfs_fatfs_irx", IrxLoader::GetIrxErrorDescription(id, ret)); SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: usbmass"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: usbmass_bd_irx", IrxLoader::GetIrxErrorDescription(id, ret)); waitUntilUsbDeviceIsReady(); @@ -236,9 +236,9 @@ void IrxLoader::loadUsbModules(const bool& verbose) { void IrxLoader::loadAudsrv(const bool& verbose) { if (verbose) TYRA_LOG("IRX: Loading audsrv..."); - int ret; + int ret, id; SifExecModuleBuffer(&audsrv_irx, size_audsrv_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: audsrv_irx"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: audsrv_irx", IrxLoader::GetIrxErrorDescription(id, ret)); if (verbose) TYRA_LOG("IRX: Audsrv loaded!"); } @@ -246,9 +246,9 @@ void IrxLoader::loadAudsrv(const bool& verbose) { void IrxLoader::loadSio2man(const bool& verbose) { if (verbose) TYRA_LOG("IRX: Loading sio2man..."); - int ret; + int ret, id; SifExecModuleBuffer(&sio2man_irx, size_sio2man_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: sio2man_irx"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: sio2man_irx", IrxLoader::GetIrxErrorDescription(id, ret)); if (verbose) TYRA_LOG("IRX: Sio2man loaded!"); } @@ -256,9 +256,9 @@ void IrxLoader::loadSio2man(const bool& verbose) { void IrxLoader::loadPadman(const bool& verbose) { if (verbose) TYRA_LOG("IRX: Loading padman..."); - int ret; + int ret, id; SifExecModuleBuffer(&padman_irx, size_padman_irx, 0, nullptr, &ret); - TYRA_ASSERT(ret >= 0, "Failed to load module: padman_irx"); + TYRA_ASSERT(ret == 1 || id < 0, "Failed to load module: padman_irx", IrxLoader::GetIrxErrorDescription(id, ret)); if (verbose) TYRA_LOG("IRX: Padman loaded!"); }