2014-07-04 01:55:09 -04:00
# pragma once
2008-01-15 20:27:44 +00:00
2012-10-21 02:08:14 +00:00
# include <memory>
2008-01-15 20:27:44 +00:00
# include <list>
2018-09-11 17:53:00 -04:00
# include <map>
2020-09-23 18:02:40 -04:00
# include <set>
2008-01-15 20:27:44 +00:00
# include "../MIPSAssembler.h"
# include "../MIPS.h"
# include "../ELF.h"
2009-01-28 23:06:08 +00:00
# include "../OsStructManager.h"
2015-11-04 01:03:32 -05:00
# include "../OsVariableWrapper.h"
2008-11-25 02:00:42 +00:00
# include "Iop_BiosBase.h"
2016-02-27 18:34:51 -05:00
# include "Iop_BiosStructs.h"
2008-11-10 01:46:02 +00:00
# include "Iop_SifMan.h"
2009-02-04 02:15:56 +00:00
# include "Iop_SifCmd.h"
2008-01-15 20:27:44 +00:00
# include "Iop_Ioman.h"
2009-04-28 01:20:03 +00:00
# include "Iop_Cdvdman.h"
2008-01-15 20:27:44 +00:00
# include "Iop_Stdio.h"
# include "Iop_Sysmem.h"
# include "Iop_Modload.h"
2012-10-24 06:39:29 +00:00
# include "Iop_Loadcore.h"
2015-02-07 23:06:08 -05:00
# include "Iop_LibSd.h"
2008-10-20 04:14:13 +00:00
# ifdef _IOP_EMULATE_MODULES
2015-01-26 03:39:44 -05:00
# include "Iop_FileIo.h"
2008-03-03 00:38:28 +00:00
# include "Iop_PadMan.h"
2016-01-16 18:43:41 -05:00
# include "Iop_MtapMan.h"
2008-11-10 01:46:02 +00:00
# include "Iop_Cdvdfsv.h"
2020-07-09 19:58:07 -04:00
# include "Iop_McServ.h"
2024-05-13 16:09:41 -04:00
# include "Iop_Usbd.h"
2022-03-16 14:12:20 +01:00
# include "Iop_PowerOff.h"
2018-12-20 12:37:47 -05:00
# endif
2012-05-26 18:31:31 +00:00
class CIopBios : public Iop : : CBiosBase
2008-01-15 20:27:44 +00:00
{
public :
2016-11-30 00:13:52 -05:00
enum KERNEL_RESULT_CODES
{
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_OK = 0 ,
KERNEL_RESULT_ERROR = - 1 ,
KERNEL_RESULT_ERROR_ILLEGAL_CONTEXT = - 100 ,
2016-11-30 00:13:52 -05:00
KERNEL_RESULT_ERROR_ILLEGAL_INTRCODE = - 101 ,
2023-09-26 14:29:27 -04:00
KERNEL_RESULT_ERROR_CPUDI = - 102 ,
2023-12-19 19:37:44 +00:00
KERNEL_RESULT_ERROR_INTRDISABLE = - 103 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_FOUND_HANDLER = - 104 ,
2016-11-30 00:13:52 -05:00
KERNEL_RESULT_ERROR_NOTFOUND_HANDLER = - 105 ,
2020-09-18 13:15:02 -04:00
KERNEL_RESULT_ERROR_NO_TIMER = - 150 ,
2020-10-29 09:33:43 -04:00
KERNEL_RESULT_ERROR_ILLEGAL_TIMERID = - 151 ,
2021-02-18 20:25:39 -05:00
KERNEL_RESULT_ERROR_UNKNOWN_MODULE = - 202 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_NO_MEMORY = - 400 ,
KERNEL_RESULT_ERROR_ILLEGAL_ATTR = - 401 ,
KERNEL_RESULT_ERROR_ILLEGAL_ENTRY = - 402 ,
2016-11-30 00:13:52 -05:00
KERNEL_RESULT_ERROR_ILLEGAL_PRIORITY = - 403 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_ILLEGAL_THID = - 406 ,
KERNEL_RESULT_ERROR_UNKNOWN_THID = - 407 ,
2018-05-05 12:00:47 -04:00
KERNEL_RESULT_ERROR_UNKNOWN_SEMAID = - 408 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_UNKNOWN_EVFID = - 409 ,
KERNEL_RESULT_ERROR_UNKNOWN_MBXID = - 410 ,
KERNEL_RESULT_ERROR_UNKNOWN_VPLID = - 411 ,
2019-04-28 18:07:48 -04:00
KERNEL_RESULT_ERROR_UNKNOWN_FPLID = - 412 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_NOT_DORMANT = - 414 ,
KERNEL_RESULT_ERROR_NOT_WAIT = - 416 ,
2018-05-05 12:00:47 -04:00
KERNEL_RESULT_ERROR_RELEASE_WAIT = - 418 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_SEMA_ZERO = - 419 ,
2019-05-13 19:17:35 -04:00
KERNEL_RESULT_ERROR_SEMA_OVF = - 420 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_EVF_CONDITION = - 421 ,
KERNEL_RESULT_ERROR_EVF_ILLEGAL_PAT = - 423 ,
KERNEL_RESULT_ERROR_MBX_NOMSG = - 424 ,
2018-05-05 12:00:47 -04:00
KERNEL_RESULT_ERROR_WAIT_DELETE = - 425 ,
2019-04-28 18:07:48 -04:00
KERNEL_RESULT_ERROR_ILLEGAL_MEMBLOCK = - 426 ,
2018-04-30 21:01:23 +01:00
KERNEL_RESULT_ERROR_ILLEGAL_MEMSIZE = - 427 ,
2016-11-30 00:13:52 -05:00
} ;
2012-03-30 05:41:11 +00:00
enum CONTROL_BLOCK
{
2018-04-30 21:01:23 +01:00
CONTROL_BLOCK_START = 0x100 ,
2019-11-27 00:41:10 +00:00
CONTROL_BLOCK_END = 0x10000 ,
2012-03-30 05:41:11 +00:00
} ;
struct THREADCONTEXT
{
2018-04-30 21:01:23 +01:00
uint32 gpr [ 0x20 ] ;
uint32 epc ;
uint32 delayJump ;
2012-03-30 05:41:11 +00:00
} ;
struct THREAD
{
2018-04-30 21:01:23 +01:00
uint32 isValid ;
uint32 id ;
uint32 initPriority ;
uint32 priority ;
uint32 optionData ;
uint32 attributes ;
uint32 threadProc ;
THREADCONTEXT context ;
uint32 status ;
uint32 waitSemaphore ;
uint32 waitEventFlag ;
uint32 waitEventFlagMode ;
uint32 waitEventFlagMask ;
uint32 waitEventFlagResultPtr ;
uint32 waitMessageBox ;
uint32 waitMessageBoxResultPtr ;
uint32 wakeupCount ;
uint32 stackBase ;
uint32 stackSize ;
uint32 nextThreadId ;
uint64 nextActivateTime ;
2012-03-30 05:41:11 +00:00
} ;
enum THREAD_STATUS
{
2018-04-30 21:01:23 +01:00
THREAD_STATUS_DORMANT = 1 ,
THREAD_STATUS_RUNNING = 2 ,
THREAD_STATUS_SLEEPING = 3 ,
THREAD_STATUS_WAITING_SEMAPHORE = 4 ,
THREAD_STATUS_WAITING_EVENTFLAG = 5 ,
THREAD_STATUS_WAITING_MESSAGEBOX = 6 ,
THREAD_STATUS_WAIT_VBLANK_START = 7 ,
THREAD_STATUS_WAIT_VBLANK_END = 8 ,
2020-11-13 12:00:51 -05:00
THREAD_STATUS_WAIT_CDSYNC = 9 ,
2012-09-12 04:03:41 +00:00
} ;
2015-10-25 22:03:15 -04:00
struct THREAD_INFO
2012-09-12 04:03:41 +00:00
{
2015-10-25 22:03:15 -04:00
uint32 attributes ;
uint32 option ;
uint32 status ;
uint32 entryPoint ;
uint32 stackAddr ;
uint32 stackSize ;
uint32 gp ;
uint32 initPriority ;
uint32 currentPriority ;
uint32 waitType ;
uint32 waitId ;
uint32 wakeupCount ;
uint32 regContextAddr ;
uint32 reserved [ 4 ] ;
2011-05-05 04:28:11 +00:00
} ;
2021-02-20 20:18:43 -05:00
2021-02-20 08:34:12 -05:00
struct MODULE_INFO
{
enum
{
MAX_NAME_SIZE = 56 ,
} ;
2021-02-20 20:18:43 -05:00
2021-02-20 08:34:12 -05:00
char name [ MAX_NAME_SIZE ] ;
uint16 version ;
uint16 flags ;
uint32 id ;
uint32 entryPoint ;
uint32 gp ;
uint32 textSectionAddr ;
uint32 textSectionSize ;
uint32 dataSectionSize ;
uint32 bssSectionSize ;
uint32 reserved [ 2 ] ;
} ;
2011-05-05 04:28:11 +00:00
2022-02-22 13:59:36 -05:00
enum class MODULESTARTREQUEST_SOURCE
{
LOCAL ,
REMOTE ,
} ;
2023-06-08 17:12:43 -04:00
CIopBios ( CMIPS & , uint8 * , uint8 * ) ;
2018-04-30 21:01:23 +01:00
virtual ~ CIopBios ( ) ;
2008-11-30 02:30:05 +00:00
2022-02-22 13:26:35 -05:00
int32 LoadModuleFromPath ( const char * , uint32 = ~ 0U , bool = true ) ;
int32 LoadModuleFromAddress ( uint32 , uint32 = ~ 0U , bool = true ) ;
2018-04-30 21:01:23 +01:00
int32 LoadModuleFromHost ( uint8 * ) ;
int32 UnloadModule ( uint32 ) ;
2022-02-22 13:59:36 -05:00
int32 StartModule ( MODULESTARTREQUEST_SOURCE , uint32 , const char * , const char * , uint32 ) ;
int32 StopModule ( MODULESTARTREQUEST_SOURCE , uint32 ) ;
2019-12-20 21:27:21 -05:00
bool CanStopModule ( uint32 ) const ;
2018-04-30 21:01:23 +01:00
bool IsModuleHle ( uint32 ) const ;
int32 SearchModuleByName ( const char * ) const ;
2021-02-20 08:34:12 -05:00
int32 ReferModuleStatus ( uint32 , uint32 ) ;
2018-04-30 21:01:23 +01:00
void ProcessModuleReset ( const std : : string & ) ;
2014-07-05 01:12:41 -04:00
2022-10-15 11:32:30 -04:00
void SetDefaultImageVersion ( uint32 ) ;
2018-04-30 21:01:23 +01:00
bool TryGetImageVersionFromPath ( const std : : string & , unsigned int * ) ;
bool TryGetImageVersionFromContents ( const std : : string & , unsigned int * ) ;
2015-10-24 21:12:42 -04:00
2018-04-30 21:01:23 +01:00
void HandleException ( ) override ;
void HandleInterrupt ( ) override ;
2008-01-15 20:27:44 +00:00
2018-04-30 21:01:23 +01:00
void Reschedule ( ) ;
2012-06-24 19:06:02 +00:00
2018-04-30 21:01:23 +01:00
void CountTicks ( uint32 ) override ;
2018-07-11 21:06:16 -04:00
uint64 GetCurrentTime ( ) const ;
2018-04-30 21:01:23 +01:00
uint64 MilliSecToClock ( uint32 ) ;
uint64 MicroSecToClock ( uint32 ) ;
uint64 ClockToMicroSec ( uint64 ) ;
2008-01-15 20:27:44 +00:00
2018-04-30 21:01:23 +01:00
void NotifyVBlankStart ( ) override ;
void NotifyVBlankEnd ( ) override ;
2008-11-07 23:50:47 +00:00
2023-06-08 17:12:43 -04:00
void Reset ( uint32 , const Iop : : SifManPtr & ) ;
2011-05-05 04:28:11 +00:00
2024-08-07 13:00:19 -04:00
void PreLoadState ( ) override ;
2018-04-30 21:01:23 +01:00
void SaveState ( Framework : : CZipArchiveWriter & ) override ;
void LoadState ( Framework : : CZipArchiveReader & ) override ;
2009-01-26 02:53:10 +00:00
2018-04-30 21:01:23 +01:00
bool IsIdle ( ) override ;
2009-01-26 02:53:10 +00:00
2019-09-15 15:45:48 -04:00
Iop : : CSysmem * GetSysmem ( ) ;
2018-04-30 21:01:23 +01:00
Iop : : CIoman * GetIoman ( ) ;
2022-10-03 18:46:38 -04:00
Iop : : CSifMan * GetSifman ( ) ;
2023-06-28 09:16:55 -04:00
Iop : : CSifCmd * GetSifcmd ( ) ;
2018-04-30 21:01:23 +01:00
Iop : : CCdvdman * GetCdvdman ( ) ;
Iop : : CLoadcore * GetLoadcore ( ) ;
2008-10-20 04:14:13 +00:00
# ifdef _IOP_EMULATE_MODULES
2018-04-30 21:01:23 +01:00
Iop : : CPadMan * GetPadman ( ) ;
Iop : : CCdvdfsv * GetCdvdfsv ( ) ;
2018-12-20 12:37:47 -05:00
Iop : : CMcServ * GetMcServ ( ) ;
2024-05-13 16:09:41 -04:00
Iop : : CUsbd * GetUsbd ( ) ;
2008-10-20 04:14:13 +00:00
# endif
2018-04-30 21:01:23 +01:00
bool RegisterModule ( const Iop : : ModulePtr & ) ;
2021-01-25 20:50:57 -05:00
bool ReleaseModule ( const std : : string & ) ;
2022-12-20 15:39:16 -05:00
2022-10-15 11:41:38 -04:00
void RegisterHleModuleReplacement ( const std : : string & , const Iop : : ModulePtr & ) ;
2018-04-30 21:01:23 +01:00
uint32 CreateThread ( uint32 , uint32 , uint32 , uint32 , uint32 ) ;
int32 DeleteThread ( uint32 ) ;
int32 StartThread ( uint32 , uint32 ) ;
int32 StartThreadArgs ( uint32 , uint32 , uint32 ) ;
void ExitThread ( ) ;
uint32 TerminateThread ( uint32 ) ;
int32 DelayThread ( uint32 ) ;
void DelayThreadTicks ( uint32 ) ;
uint32 SetAlarm ( uint32 , uint32 , uint32 ) ;
2023-12-22 11:29:52 -05:00
uint32 CancelAlarm ( uint32 , uint32 , bool ) ;
2018-04-30 21:01:23 +01:00
THREAD * GetThread ( uint32 ) ;
int32 GetCurrentThreadId ( ) ;
int32 GetCurrentThreadIdRaw ( ) const ;
int32 ChangeThreadPriority ( uint32 , uint32 ) ;
uint32 ReferThreadStatus ( uint32 , uint32 , bool ) ;
int32 SleepThread ( ) ;
uint32 WakeupThread ( uint32 , bool ) ;
int32 CancelWakeupThread ( uint32 , bool ) ;
2018-05-07 16:34:42 -04:00
int32 RotateThreadReadyQueue ( uint32 ) ;
2018-04-30 21:01:23 +01:00
int32 ReleaseWaitThread ( uint32 , bool ) ;
2018-07-17 12:41:13 -04:00
int32 RegisterVblankHandler ( uint32 , uint32 , uint32 , uint32 ) ;
2020-04-22 19:46:46 +02:00
int32 ReleaseVblankHandler ( uint32 , uint32 ) ;
int32 FindVblankHandlerByLineAndPtr ( uint32 startEnd , uint32 handlerPtr ) ;
2018-04-30 21:01:23 +01:00
void SleepThreadTillVBlankStart ( ) ;
void SleepThreadTillVBlankEnd ( ) ;
2021-11-19 17:25:42 -05:00
uint32 CreateSemaphore ( uint32 , uint32 , uint32 , uint32 ) ;
2018-04-30 21:01:23 +01:00
uint32 DeleteSemaphore ( uint32 ) ;
uint32 SignalSemaphore ( uint32 , bool ) ;
uint32 WaitSemaphore ( uint32 ) ;
uint32 PollSemaphore ( uint32 ) ;
uint32 ReferSemaphoreStatus ( uint32 , uint32 ) ;
2018-05-07 17:03:59 -04:00
bool SemaReleaseSingleThread ( uint32 , bool ) ;
2018-04-30 21:01:23 +01:00
uint32 CreateEventFlag ( uint32 , uint32 , uint32 ) ;
uint32 DeleteEventFlag ( uint32 ) ;
uint32 SetEventFlag ( uint32 , uint32 , bool ) ;
uint32 ClearEventFlag ( uint32 , uint32 ) ;
uint32 WaitEventFlag ( uint32 , uint32 , uint32 , uint32 ) ;
uint32 PollEventFlag ( uint32 , uint32 , uint32 , uint32 ) ;
uint32 ReferEventFlagStatus ( uint32 , uint32 ) ;
bool ProcessEventFlag ( uint32 , uint32 & , uint32 , uint32 * ) ;
uint32 CreateMessageBox ( ) ;
uint32 DeleteMessageBox ( uint32 ) ;
uint32 SendMessageBox ( uint32 , uint32 , bool ) ;
uint32 ReceiveMessageBox ( uint32 , uint32 ) ;
uint32 PollMessageBox ( uint32 , uint32 ) ;
uint32 ReferMessageBoxStatus ( uint32 , uint32 ) ;
2019-04-28 18:07:48 -04:00
uint32 CreateFpl ( uint32 ) ;
2022-08-22 20:00:33 -04:00
uint32 DeleteFpl ( uint32 ) ;
2019-04-28 18:07:48 -04:00
uint32 AllocateFpl ( uint32 ) ;
uint32 pAllocateFpl ( uint32 ) ;
uint32 FreeFpl ( uint32 , uint32 ) ;
2018-04-30 21:01:23 +01:00
uint32 CreateVpl ( uint32 ) ;
uint32 DeleteVpl ( uint32 ) ;
2024-11-11 12:17:33 -05:00
uint32 AllocateVpl ( uint32 , uint32 ) ;
2018-04-30 21:01:23 +01:00
uint32 pAllocateVpl ( uint32 , uint32 ) ;
uint32 FreeVpl ( uint32 , uint32 ) ;
uint32 ReferVplStatus ( uint32 , uint32 ) ;
uint32 GetVplFreeSize ( uint32 ) ;
2020-11-13 12:00:51 -05:00
void WaitCdSync ( ) ;
void ReleaseWaitCdSync ( ) ;
2018-04-30 21:01:23 +01:00
int32 RegisterIntrHandler ( uint32 , uint32 , uint32 , uint32 ) ;
int32 ReleaseIntrHandler ( uint32 ) ;
2022-06-22 18:36:53 -04:00
int32 FindIntrHandler ( uint32 ) ;
2018-04-30 21:01:23 +01:00
2022-02-24 11:37:55 -05:00
int32 TriggerCallback ( uint32 address , uint32 arg0 = 0 , uint32 arg1 = 0 , uint32 arg2 = 0 , uint32 arg3 = 0 ) ;
2014-12-12 20:20:51 +00:00
2014-07-04 01:55:09 -04:00
# ifdef DEBUGGER_INCLUDED
2018-04-30 21:01:23 +01:00
void LoadDebugTags ( Framework : : Xml : : CNode * ) override ;
void SaveDebugTags ( Framework : : Xml : : CNode * ) override ;
2014-07-04 01:55:09 -04:00
2018-04-30 21:01:23 +01:00
BiosDebugModuleInfoArray GetModulesDebugInfo ( ) const override ;
2022-09-07 19:58:01 -04:00
BiosDebugObjectInfoMap GetBiosObjectsDebugInfo ( ) const override ;
BiosDebugObjectArray GetBiosObjects ( uint32 ) const override ;
2014-07-04 01:55:09 -04:00
# endif
2020-04-03 08:50:55 -04:00
typedef Framework : : CSignal < void ( const char * ) > ModuleLoadedEvent ;
2019-06-20 00:40:28 +01:00
typedef Framework : : CSignal < void ( uint32 ) > ModuleStartedEvent ;
2015-07-03 22:17:22 -04:00
2020-04-03 08:50:55 -04:00
ModuleLoadedEvent OnModuleLoaded ;
2018-04-30 21:01:23 +01:00
ModuleStartedEvent OnModuleStarted ;
2015-07-03 22:17:22 -04:00
2008-01-15 20:27:44 +00:00
private :
2022-10-15 11:32:30 -04:00
enum
{
DEFAULT_IMAGE_VERSION = 1000 ,
} ;
2022-12-20 15:39:16 -05:00
2012-03-30 05:41:11 +00:00
enum DEFAULT_STACKSIZE
{
DEFAULT_STACKSIZE = 0x4000 ,
} ;
2008-01-15 20:27:44 +00:00
2012-03-30 05:41:11 +00:00
enum DEFAULT_PRIORITY
{
2012-05-27 00:54:16 +00:00
DEFAULT_PRIORITY = 64 ,
2012-03-30 05:41:11 +00:00
} ;
2008-01-15 20:27:44 +00:00
2015-10-17 00:11:03 -04:00
enum MODULE_INIT_PRIORITY
{
MODULE_INIT_PRIORITY = 8 ,
} ;
2015-06-27 04:20:14 -04:00
enum class MODULE_STATE : uint32
2015-06-27 01:42:04 -04:00
{
2015-06-27 19:21:13 -04:00
STOPPED ,
2016-01-16 20:46:14 -05:00
STARTED ,
HLE ,
2015-06-27 01:42:04 -04:00
} ;
2015-06-27 04:20:14 -04:00
enum class MODULE_RESIDENT_STATE : uint32
2015-06-27 01:42:04 -04:00
{
2018-04-30 21:01:23 +01:00
RESIDENT_END = 0 ,
NO_RESIDENT_END = 1 ,
REMOVABLE_RESIDENT_END = 2 ,
2015-06-27 01:42:04 -04:00
} ;
2009-01-28 23:06:08 +00:00
enum
{
2023-06-08 17:13:11 -04:00
MAX_THREAD = 96 ,
2021-11-10 08:07:51 -05:00
MAX_MEMORYBLOCK = 1024 ,
2018-04-30 21:01:23 +01:00
MAX_SEMAPHORE = 128 ,
2022-03-08 17:50:17 -05:00
MAX_EVENTFLAG = 128 ,
2018-04-30 21:01:23 +01:00
MAX_INTRHANDLER = 32 ,
2018-07-17 12:41:13 -04:00
MAX_VBLANKHANDLER = 8 ,
2018-04-30 21:01:23 +01:00
MAX_MESSAGEBOX = 32 ,
2019-04-28 18:07:48 -04:00
MAX_FPL = 16 ,
2018-04-30 21:01:23 +01:00
MAX_VPL = 16 ,
2021-12-01 14:32:18 -05:00
MAX_MODULESTARTREQUEST = 32 ,
2023-06-08 17:13:11 -04:00
MAX_LOADEDMODULE = 48 ,
2009-01-28 23:06:08 +00:00
} ;
2012-04-12 04:52:26 +00:00
enum WEF_FLAGS
{
2018-04-30 21:01:23 +01:00
WEF_AND = 0x00 ,
WEF_OR = 0x01 ,
WEF_CLEAR = 0x10 ,
2012-04-12 04:52:26 +00:00
} ;
2012-03-30 05:41:11 +00:00
struct SEMAPHORE
{
2018-04-30 21:01:23 +01:00
uint32 isValid ;
uint32 id ;
uint32 count ;
uint32 maxCount ;
uint32 waitCount ;
2021-11-19 17:25:42 -05:00
uint32 attrib ;
uint32 option ;
2012-03-30 05:41:11 +00:00
} ;
2016-02-28 15:57:08 -05:00
struct SEMAPHORE_STATUS
{
2018-04-30 21:01:23 +01:00
uint32 attrib ;
uint32 option ;
uint32 initCount ;
uint32 maxCount ;
uint32 currentCount ;
uint32 numWaitThreads ;
2016-02-28 15:57:08 -05:00
} ;
2012-04-12 04:52:26 +00:00
struct EVENTFLAG
{
2018-04-30 21:01:23 +01:00
uint32 isValid ;
uint32 id ;
uint32 attributes ;
uint32 options ;
uint32 value ;
2012-04-12 04:52:26 +00:00
} ;
2012-04-26 05:50:37 +00:00
struct EVENTFLAGINFO
{
2018-04-30 21:01:23 +01:00
uint32 attributes ;
uint32 options ;
uint32 initBits ;
uint32 currBits ;
uint32 numThreads ;
2012-04-26 05:50:37 +00:00
} ;
2012-03-30 05:41:11 +00:00
struct INTRHANDLER
{
2018-04-30 21:01:23 +01:00
uint32 isValid ;
uint32 line ;
uint32 mode ;
uint32 handler ;
uint32 arg ;
2012-03-30 05:41:11 +00:00
} ;
2018-07-17 12:41:13 -04:00
struct VBLANKHANDLER
{
uint32 isValid ;
uint32 type ;
uint32 handler ;
uint32 arg ;
} ;
static_assert ( sizeof ( VBLANKHANDLER ) = = 0x10 , " Size of VBLANKHANDLER must be 16 bytes. AssembleVblankHandler relies on this. " ) ;
2012-06-30 02:31:22 +00:00
struct MESSAGEBOX
{
2018-04-30 21:01:23 +01:00
uint32 isValid ;
uint32 nextMsgPtr ;
uint32 numMessage ;
2015-11-01 23:09:06 -05:00
} ;
2015-11-01 23:43:25 -05:00
struct MESSAGEBOX_STATUS
{
2018-04-30 21:01:23 +01:00
uint32 attr ;
uint32 option ;
uint32 numWaitThread ;
uint32 numMessage ;
uint32 messagePtr ;
uint32 unused [ 2 ] ;
2015-11-01 23:43:25 -05:00
} ;
2015-11-01 23:09:06 -05:00
struct MESSAGE_HEADER
{
2018-04-30 21:01:23 +01:00
uint32 nextMsgPtr ;
uint8 priority ;
uint8 unused [ 3 ] ;
2012-06-30 02:31:22 +00:00
} ;
2019-04-28 18:07:48 -04:00
enum FPL_ATTR
{
FPL_ATTR_THFIFO = 0x000 ,
FPL_ATTR_THPRI = 0x001 ,
FPL_ATTR_THMODE_MASK = 0x001 ,
FPL_ATTR_MEMBTM = 0x200 ,
FPL_ATTR_MEMMODE_MASK = 0x200 ,
FPL_ATTR_VALID_MASK = ( FPL_ATTR_THMODE_MASK | FPL_ATTR_MEMMODE_MASK )
} ;
struct FPL_PARAM
{
uint32 attr ;
uint32 option ;
uint32 blockSize ;
uint32 blockCount ;
} ;
struct FPL
{
uint32 isValid ;
uint32 attr ;
uint32 option ;
uint32 poolPtr ;
uint32 blockSize ;
uint32 blockCount ;
} ;
2016-02-28 15:55:45 -05:00
struct VPL
{
2018-04-30 21:01:23 +01:00
uint32 isValid ;
uint32 attr ;
uint32 option ;
uint32 poolPtr ;
uint32 size ;
uint32 headBlockId ;
2016-02-28 15:55:45 -05:00
} ;
enum VPL_ATTR
{
2018-04-30 21:01:23 +01:00
VPL_ATTR_THFIFO = 0x000 ,
VPL_ATTR_THPRI = 0x001 ,
VPL_ATTR_THMODE_MASK = 0x001 ,
VPL_ATTR_MEMBTM = 0x200 ,
2016-02-28 15:55:45 -05:00
VPL_ATTR_MEMMODE_MASK = 0x200 ,
2018-04-30 21:01:23 +01:00
VPL_ATTR_VALID_MASK = ( VPL_ATTR_THMODE_MASK | VPL_ATTR_MEMMODE_MASK )
2016-02-28 15:55:45 -05:00
} ;
struct VPL_PARAM
{
2018-04-30 21:01:23 +01:00
uint32 attr ;
uint32 option ;
uint32 size ;
2016-02-28 15:55:45 -05:00
} ;
struct VPL_STATUS
{
2018-04-30 21:01:23 +01:00
uint32 attr ;
uint32 option ;
uint32 size ;
uint32 freeSize ;
uint32 numWaitThreads ;
uint32 unused [ 3 ] ;
2016-02-28 15:55:45 -05:00
} ;
2015-06-27 00:38:30 -04:00
struct MODULESTARTREQUEST
2012-09-18 03:21:43 +00:00
{
2021-12-01 14:32:18 -05:00
enum
{
INVALID_PTR = - 1 ,
} ;
2018-04-30 21:01:23 +01:00
enum
2012-09-18 03:21:43 +00:00
{
MAX_PATH_SIZE = 256 ,
MAX_ARGS_SIZE = 256
} ;
2018-04-30 21:01:23 +01:00
uint32 nextPtr ;
uint32 moduleId ;
uint32 stopRequest ;
2022-02-22 13:59:36 -05:00
int32 requesterThreadId ;
2018-04-30 21:01:23 +01:00
char path [ MAX_PATH_SIZE ] ;
uint32 argsLength ;
char args [ MAX_ARGS_SIZE ] ;
2012-09-18 03:21:43 +00:00
} ;
2015-05-01 21:47:26 -04:00
struct LOADEDMODULE
2014-07-05 01:12:41 -04:00
{
enum
{
MAX_NAME_SIZE = 0x100 ,
} ;
2018-04-30 21:01:23 +01:00
uint32 isValid ;
char name [ MAX_NAME_SIZE ] ;
2021-02-20 08:34:12 -05:00
uint32 version ;
2018-04-30 21:01:23 +01:00
uint32 start ;
uint32 end ;
uint32 entryPoint ;
uint32 gp ;
2022-02-22 13:26:35 -05:00
uint32 ownsMemory ;
2018-04-30 21:01:23 +01:00
MODULE_STATE state ;
MODULE_RESIDENT_STATE residentState ;
2014-07-05 01:12:41 -04:00
} ;
2012-03-30 05:41:11 +00:00
struct IOPMOD
{
2018-04-30 21:01:23 +01:00
uint32 module ;
uint32 startAddress ;
uint32 gp ;
uint32 textSectionSize ;
uint32 dataSectionSize ;
uint32 bssSectionSize ;
2021-02-20 08:34:12 -05:00
uint16 moduleVersion ;
2018-04-30 21:01:23 +01:00
char moduleName [ 256 ] ;
2012-03-30 05:41:11 +00:00
} ;
enum
{
IOPMOD_SECTION_ID = 0x70000080 ,
} ;
2009-02-20 04:00:18 +00:00
2016-06-28 17:08:39 -04:00
enum
{
2018-04-30 21:01:23 +01:00
ET_SCE_IOPRELEXEC = 0xFF80 ,
2016-06-28 17:08:39 -04:00
ET_SCE_IOPRELEXEC2 = 0xFF81
} ;
enum
{
2018-04-30 21:01:23 +01:00
R_MIPSSCE_MHI16 = 0xFA ,
2016-06-28 17:08:39 -04:00
R_MIPSSCE_ADDEND = 0xFB
} ;
2019-11-26 13:19:31 +00:00
struct SYSTEM_INTRHANDLER
{
uint32 handler ;
uint32 paramPtr ;
} ;
static_assert ( sizeof ( SYSTEM_INTRHANDLER ) = = 0x8 , " Size of SYSTEM_INTRHANDLER must be 8 bytes. Fixed PS2 structure, and we use it for array magic iteration. " ) ;
2009-01-28 23:06:08 +00:00
typedef COsStructManager < THREAD > ThreadList ;
2016-02-27 18:34:51 -05:00
typedef COsStructManager < Iop : : MEMORYBLOCK > MemoryBlockList ;
2009-01-30 22:10:15 +00:00
typedef COsStructManager < SEMAPHORE > SemaphoreList ;
2012-04-12 04:52:26 +00:00
typedef COsStructManager < EVENTFLAG > EventFlagList ;
2009-01-30 22:10:15 +00:00
typedef COsStructManager < INTRHANDLER > IntrHandlerList ;
2018-07-17 12:41:13 -04:00
typedef COsStructManager < VBLANKHANDLER > VblankHandlerList ;
2012-06-30 02:31:22 +00:00
typedef COsStructManager < MESSAGEBOX > MessageBoxList ;
2019-04-28 18:07:48 -04:00
typedef COsStructManager < FPL > FplList ;
2016-02-28 15:55:45 -05:00
typedef COsStructManager < VPL > VplList ;
2015-05-01 21:47:26 -04:00
typedef COsStructManager < LOADEDMODULE > LoadedModuleList ;
2024-02-23 16:52:17 -05:00
typedef std : : map < std : : string , Iop : : ModulePtr , std : : less < > > IopModuleMapType ;
2020-09-23 18:02:40 -04:00
typedef std : : set < Iop : : CModule * > ModuleSet ;
2012-03-30 05:41:11 +00:00
typedef std : : pair < uint32 , uint32 > ExecutableRange ;
2018-04-30 21:01:23 +01:00
void LoadThreadContext ( uint32 ) ;
void SaveThreadContext ( uint32 ) ;
uint32 GetNextReadyThread ( ) ;
void ReturnFromException ( ) ;
2009-01-28 23:06:08 +00:00
2018-04-30 21:01:23 +01:00
void LinkThread ( uint32 ) ;
void UnlinkThread ( uint32 ) ;
2009-01-28 23:06:08 +00:00
2018-04-30 21:01:23 +01:00
uint32 & ThreadLinkHead ( ) const ;
uint64 & CurrentTime ( ) const ;
uint32 & ModuleStartRequestHead ( ) const ;
uint32 & ModuleStartRequestFree ( ) const ;
2012-03-30 05:41:11 +00:00
2022-07-22 17:01:59 -04:00
int32 LoadModule ( CELF32 & , const char * , uint32 , bool ) ;
uint32 LoadExecutable ( CELF32 & , ExecutableRange & , uint32 ) ;
unsigned int GetElfProgramToLoad ( CELF32 & ) ;
void RelocateElf ( CELF32 & , uint32 , uint32 ) ;
2024-07-17 09:04:31 -04:00
std : : string_view ReadModuleName ( const uint8 * ) ;
2024-02-23 16:52:17 -05:00
std : : string_view ReadModuleName ( uint32 ) ;
2018-04-30 21:01:23 +01:00
void DeleteModules ( ) ;
2012-05-24 05:57:31 +00:00
2022-10-30 21:46:14 -04:00
void UnloadUserComponents ( ) ;
2018-04-30 21:01:23 +01:00
int32 LoadHleModule ( const Iop : : ModulePtr & ) ;
2018-09-11 17:53:00 -04:00
void RegisterHleModule ( const Iop : : ModulePtr & ) ;
2016-01-16 20:46:14 -05:00
2020-09-23 18:02:40 -04:00
ModuleSet GetBuiltInModules ( ) const ;
2018-04-30 21:01:23 +01:00
uint32 AssembleThreadFinish ( CMIPSAssembler & ) ;
uint32 AssembleReturnFromException ( CMIPSAssembler & ) ;
uint32 AssembleIdleFunction ( CMIPSAssembler & ) ;
2022-02-24 11:37:55 -05:00
uint32 AssembleModuleStarterProc ( CMIPSAssembler & ) ;
2018-04-30 21:01:23 +01:00
uint32 AssembleAlarmThreadProc ( CMIPSAssembler & ) ;
2018-07-17 12:41:13 -04:00
uint32 AssembleVblankHandler ( CMIPSAssembler & ) ;
2012-09-18 03:21:43 +00:00
2018-04-30 21:01:23 +01:00
void InitializeModuleStarter ( ) ;
void ProcessModuleStart ( ) ;
void FinishModuleStart ( ) ;
2022-02-22 13:59:36 -05:00
void RequestModuleStart ( MODULESTARTREQUEST_SOURCE , bool , uint32 , const char * , const char * , unsigned int ) ;
2012-05-24 05:57:31 +00:00
2019-11-26 13:19:31 +00:00
void PopulateSystemIntcHandlers ( ) ;
2014-07-04 01:55:09 -04:00
# ifdef DEBUGGER_INCLUDED
2022-07-22 17:01:59 -04:00
void PrepareModuleDebugInfo ( CELF32 & , const ExecutableRange & , const std : : string & , const std : : string & ) ;
2018-04-30 21:01:23 +01:00
BiosDebugModuleInfoIterator FindModuleDebugInfo ( const std : : string & ) ;
BiosDebugModuleInfoIterator FindModuleDebugInfo ( uint32 , uint32 ) ;
2014-07-04 01:55:09 -04:00
# endif
2018-04-30 21:01:23 +01:00
CMIPS & m_cpu ;
uint8 * m_ram = nullptr ;
2023-06-08 17:12:43 -04:00
uint32 m_ramSize = 0 ;
2018-04-30 21:01:23 +01:00
uint8 * m_spr = nullptr ;
uint32 m_threadFinishAddress ;
uint32 m_returnFromExceptionAddress ;
uint32 m_idleFunctionAddress ;
2022-02-24 11:37:55 -05:00
uint32 m_moduleStarterProcAddress ;
2018-04-30 21:01:23 +01:00
uint32 m_alarmThreadProcAddress ;
2018-07-17 12:41:13 -04:00
uint32 m_vblankHandlerAddress ;
2018-04-30 21:01:23 +01:00
2022-10-15 11:32:30 -04:00
uint32 m_defaultImageVersion = DEFAULT_IMAGE_VERSION ;
2022-12-20 15:39:16 -05:00
2018-04-30 21:01:23 +01:00
bool m_rescheduleNeeded = false ;
ThreadList m_threads ;
MemoryBlockList m_memoryBlocks ;
SemaphoreList m_semaphores ;
EventFlagList m_eventFlags ;
IntrHandlerList m_intrHandlers ;
2018-07-17 12:41:13 -04:00
VblankHandlerList m_vblankHandlers ;
2018-04-30 21:01:23 +01:00
MessageBoxList m_messageBoxes ;
2019-04-28 18:07:48 -04:00
FplList m_fpls ;
2018-04-30 21:01:23 +01:00
VplList m_vpls ;
2023-05-02 08:56:25 -04:00
LoadedModuleList m_loadedModules ;
2018-04-30 21:01:23 +01:00
2021-12-01 14:32:18 -05:00
MODULESTARTREQUEST m_moduleStartRequests [ MAX_MODULESTARTREQUEST ] = { } ;
2018-04-30 21:01:23 +01:00
IopModuleMapType m_modules ;
OsVariableWrapper < uint32 > m_currentThreadId ;
2015-11-04 01:03:32 -05:00
2014-07-04 02:53:10 -04:00
# ifdef DEBUGGER_INCLUDED
2018-04-30 21:01:23 +01:00
BiosDebugModuleInfoArray m_moduleTags ;
2014-07-04 02:53:10 -04:00
# endif
2018-04-30 21:01:23 +01:00
Iop : : SifManPtr m_sifMan ;
Iop : : SifCmdPtr m_sifCmd ;
Iop : : StdioPtr m_stdio ;
Iop : : IomanPtr m_ioman ;
Iop : : CdvdmanPtr m_cdvdman ;
Iop : : SysmemPtr m_sysmem ;
Iop : : ModloadPtr m_modload ;
Iop : : LoadcorePtr m_loadcore ;
Iop : : ModulePtr m_libsd ;
2008-10-20 04:14:13 +00:00
# ifdef _IOP_EMULATE_MODULES
2018-04-30 21:01:23 +01:00
Iop : : FileIoPtr m_fileIo ;
Iop : : PadManPtr m_padman ;
Iop : : MtapManPtr m_mtapman ;
2020-07-09 19:58:07 -04:00
Iop : : McServPtr m_mcserv ;
2018-04-30 21:01:23 +01:00
Iop : : CdvdfsvPtr m_cdvdfsv ;
2022-03-16 14:12:20 +01:00
Iop : : PowerOffPtr m_powerOff ;
2024-05-13 16:09:41 -04:00
Iop : : UsbdPtr m_usbd ;
2018-09-11 17:53:00 -04:00
std : : map < std : : string , Iop : : ModulePtr > m_hleModules ;
2008-10-20 04:14:13 +00:00
# endif
2008-01-15 20:27:44 +00:00
} ;
2012-10-21 02:08:14 +00:00
typedef std : : shared_ptr < CIopBios > IopBiosPtr ;