Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 113 additions & 3 deletions tm_common/flashemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ char path[260];
FileHandler file_handler[MAX_FILES];
#endif

#if defined FLASH_EMU_TOO_MANY_FILES_FIX && PSP_FW_VERSION < 660
#if defined FLASH_EMU_TOO_MANY_FILES_FIX && PSP_FW_VERSION < 500
int (* df_open)(s32 a0, char* path, s32 a2, s32 a3);
int (* df_dopen)(s32 a0, char* path, s32 a2);
int (* df_devctl)(s32 a0, s32 a1, s32 a2, s32 a3);
Expand All @@ -35,7 +35,17 @@ SceUID flashemuThid;
int msNotReady = 1;
int installed = 0;

#if PSP_FW_VERSION < 500
extern PspSysEventHandler sysEventHandler;
#else
int SysEventHandler(int eventId, char *eventName, void *param, int *result);
PspSysEventHandler sysEventHandler =
{
.size = sizeof(PspSysEventHandler),
.name = "",
.type_mask = 0x00FFFF00,
.handler = SysEventHandler};
#endif

#define Lock() sceKernelWaitSema(flashemu_sema, 1, NULL)
#define UnLock() sceKernelSignalSema(flashemu_sema, 1)
Expand Down Expand Up @@ -152,6 +162,19 @@ int InstallFlashEmu()

int UninstallFlashEmu()
{
#if PSP_FW_VERSION >= 500
SceUInt timeout = 500000;
sceKernelWaitSema(flashemu_sema, 1, &timeout);
sceKernelDeleteSema(flashemu_sema);

sceIoUnassign("flash0:");
sceIoUnassign("flash1:");
sceIoUnassign("flash2:");
sceIoUnassign("flash3:");

sceKernelUnregisterSysEventHandler(&sysEventHandler);
#endif

return 0;
}

Expand Down Expand Up @@ -965,7 +988,7 @@ int CloseOpenFile(int *argv)
return 0x80010018;
}

#if PSP_FW_VERSION < 660
#if PSP_FW_VERSION < 500
int df_dopenPatched(s32 a0, char* path, s32 a2)
{
while(1) {
Expand Down Expand Up @@ -1021,6 +1044,69 @@ int df_devctlPatched(s32 a0, s32 a1, s32 a2, s32 a3)

return res;
}
#else
int df_dopenPatched(int type, void * cb, void *arg)
{
int res;

while(1) {
res = sceKernelExtendKernelStack(type, cb, arg);
if (res != 0x80010018)
return res;

if (*(int *)(arg + 4) == 0)
continue;

if (memcmp((void *)(*(int *)(arg + 4) + 4), TM_PATH_W, sizeof(TM_PATH_W)) == 0)
continue;

res = sceKernelExtendKernelStack(0x4000, (void *)CloseOpenFile, 0);
if (res < 0)
break;
}
return res;
}

int df_openPatched(int type, void * cb, void *arg)
{
int res;

while(1) {
res = sceKernelExtendKernelStack(type, cb, arg);
if (res != 0x80010018)
return res;

if (*(int *)(arg + 4) == 0)
continue;

if (memcmp((void *)(*(int *)(arg + 4) + 4), TM_PATH_W, sizeof(TM_PATH_W)) == 0)
continue;

res = sceKernelExtendKernelStack(0x4000, (void *)CloseOpenFile, 0);
if (res < 0)
break;
}
return res;
}

int df_devctlPatched(int type, void *cb, void *arg)
{
int res;

while(1)
{
res = sceKernelExtendKernelStack(type, cb, arg);
if (res != 0x80010018)
break;

res = sceKernelExtendKernelStack(0x4000, (void *)CloseOpenFile, 0);

if (res < 0)
break;
}

return res;
}
#endif
#endif

Expand Down Expand Up @@ -1092,4 +1178,28 @@ int SceLfatfsAssign()
int sceLfatfsStop()
{
return 0;
}
}

#if PSP_FW_VERSION >= 500
int SysEventHandler(int eventId, char *eventName, void *param, int *result)
{
if (eventId == 0x4000) //suspend
{
#ifdef FLASH_EMU_TOO_MANY_FILES_FIX
int i;
for(i = 0; i < MAX_FILES; i++)
{
if(file_handler[i].opened && file_handler[i].unk_8 == 0 && file_handler[i].flags != DIR_FLAG)
{
file_handler[i].offset = sceIoLseek(file_handler[i].fd, 0, PSP_SEEK_CUR);
file_handler[i].unk_8 = 1;
sceIoClose(file_handler[i].fd);
}
}
#endif
}
else if (eventId == 0x10009) // resume
msNotReady = 1;
return 0;
}
#endif
6 changes: 6 additions & 0 deletions tm_common/include/flashemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ typedef struct

#endif

#if PSP_FW_VERSION >= 500
int df_dopenPatched(int type, void * cb, void *arg);
int df_openPatched(int type, void * cb, void *arg);
int df_devctlPatched(int type, void *cb, void *arg);
#endif

#endif
3 changes: 3 additions & 0 deletions tm_firmware/500/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
project(tm_500 VERSION 1.0 LANGUAGES C CXX ASM)

add_compile_definitions(PSP_FW_VERSION=500 TM_PATH="/TM/DC8" TM_PATH_W=L"\\\\TM\\\\DC8\\\\")

add_subdirectory(common)
add_subdirectory(ipl_payload)
add_subdirectory(tmctrl)
5 changes: 5 additions & 0 deletions tm_firmware/500/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_library(500rebootpatches INTERFACE)
add_library(tm500_common::rebootpatches ALIAS 500rebootpatches)

target_include_directories(500rebootpatches INTERFACE include)
target_sources(500rebootpatches INTERFACE rebootPatches.cpp)
165 changes: 165 additions & 0 deletions tm_firmware/500/common/include/rebootPatches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Based on payloadex_patch_addr.h/rebootex_patch_addr.h from minimum edition - https://github.com/PSP-Archive/minimum_edition
*/

#pragma once

#include <psptypes.h>

struct RebootPatches {
u32 BootLfatMountPatch;
u32 BootLfatOpenPatch;
u32 BootLfatReadPatch;
u32 BootLfatClosePatch;
u32 CheckPspConfigPatch;
u32 KdebugPatchAddr;
u32 BtHeaderPatchAddr;
u32 LfatMountPatchAddr;
u32 LfatSeekPatchAddr1;
u32 LfatSeekPatchAddr2;
u32 LoadCorePatchAddr;
u32 HashCheckPatchAddr;
u32 SigcheckPatchAddr;
};

struct LoadCorePatches {
u32 ModuleOffsetAddr;
u32 SigcheckPatchAddr1;
u32 SigcheckPatchAddr2;
u32 SigcheckPatchAddr3;
u32 SigcheckFuncAddr;
u32 DecryptPatchAddr;
u32 DecryptPatchAddr2;
u32 DecryptFuncAddr;
};

struct Patches {
struct RebootPatches rebootPatches;
struct LoadCorePatches loadCorePatches;
};

struct MsLfatFuncs {
void *msMount;
void *msOpen;
void *msRead;
void *msClose;
};

static const struct Patches patches = {
#if PSP_MODEL == 0
#if defined PAYLOADEX
.rebootPatches = {
.BootLfatMountPatch = 0x88603394,
.BootLfatOpenPatch = 0x886033a4,
.BootLfatReadPatch = 0x8860340c,
.BootLfatClosePatch = 0x8860342c,
.CheckPspConfigPatch = 0x8860a308,
.KdebugPatchAddr = 0x8860c1a0,
.LfatMountPatchAddr = 0x8860339c,
.LfatSeekPatchAddr1 = 0x886033ec,
.LfatSeekPatchAddr2 = 0x886033fc,
.LoadCorePatchAddr = 0x88602908,
.HashCheckPatchAddr = 0x88602e68,
.SigcheckPatchAddr = 0x886009c4,
},
#elif defined REBOOTEX
.rebootPatches = {
.BootLfatMountPatch = 0x88601f44,
.BootLfatOpenPatch = 0x88601f58,
.BootLfatReadPatch = 0x88601fc8,
.BootLfatClosePatch = 0x88601ff4,
.CheckPspConfigPatch = 0x88604f68,
.KdebugPatchAddr = 0x88603018,
.LfatMountPatchAddr = 0x88601f50,
.LfatSeekPatchAddr1 = 0x88601fa4,
.LfatSeekPatchAddr2 = 0x88601fbc,
.LoadCorePatchAddr = 0x88604e20,
.HashCheckPatchAddr = 0x88606c68,
.SigcheckPatchAddr = 0x8860133c,
},
#endif

#elif (PSP_MODEL == 1)
#if defined PAYLOADEX
.rebootPatches = {
.BootLfatMountPatch = 0x88603468,
.BootLfatOpenPatch = 0x88603478,
.BootLfatReadPatch = 0x886034e0,
.BootLfatClosePatch = 0x88603500,
.CheckPspConfigPatch = 0x8860a3dc,
.KdebugPatchAddr = 0x8860c274,
.LfatMountPatchAddr = 0x88603470,
.LfatSeekPatchAddr1 = 0x886034c0,
.LfatSeekPatchAddr2 = 0x886034d0,
.LoadCorePatchAddr = 0x886029d0,
.HashCheckPatchAddr = 0x88602f3c,
.SigcheckPatchAddr = 0x88600a54,
},
#elif defined REBOOTEX
.rebootPatches = {
.BootLfatMountPatch = 0x8860200c,
.BootLfatOpenPatch = 0x88602020,
.BootLfatReadPatch = 0x88602090,
.BootLfatClosePatch = 0x886020bc,
.CheckPspConfigPatch = 0x88605030,
.KdebugPatchAddr = 0x886030e0,
.LfatMountPatchAddr = 0x88602018,
.LfatSeekPatchAddr1 = 0x8860206c,
.LfatSeekPatchAddr2 = 0x88602084,
.LoadCorePatchAddr = 0x88604ee8,
.HashCheckPatchAddr = 0x88606d38,
.SigcheckPatchAddr = 0x886013cc,
},
#endif

#elif (PSP_MODEL == 2)
#if defined PAYLOADEX
.rebootPatches = {
.BootLfatMountPatch = 0x88603494,
.BootLfatOpenPatch = 0x886034a4,
.BootLfatReadPatch = 0x8860350c,
.BootLfatClosePatch = 0x8860352c,
.CheckPspConfigPatch = 0x8860a408,
.KdebugPatchAddr = 0x8860c2a0,
.LfatMountPatchAddr = 0x8860349c,
.LfatSeekPatchAddr1 = 0x886034ec,
.LfatSeekPatchAddr2 = 0x886034fc,
.LoadCorePatchAddr = 0x886029d0,
.HashCheckPatchAddr = 0x88602f68,
.SigcheckPatchAddr = 0x88600a54,
},
#elif defined REBOOTEX
.rebootPatches = {
.BootLfatMountPatch = 0x8860200c,
.BootLfatOpenPatch = 0x88602020,
.BootLfatReadPatch = 0x88602090,
.BootLfatClosePatch = 0x886020bc,
.CheckPspConfigPatch = 0x88605030,
.KdebugPatchAddr = 0x886030e0,
.LfatMountPatchAddr = 0x88602018,
.LfatSeekPatchAddr1 = 0x8860206c,
.LfatSeekPatchAddr2 = 0x88602084,
.LoadCorePatchAddr = 0x88604ee8,
.HashCheckPatchAddr = 0x88606d38,
.SigcheckPatchAddr = 0x886013cc,
},
#endif

#endif
.loadCorePatches = {
.ModuleOffsetAddr = 0x00000c74,
.SigcheckPatchAddr1 = 0x0000691c,
.SigcheckPatchAddr2 = 0x0000694c,
.SigcheckPatchAddr3 = 0x000069e4,
.SigcheckFuncAddr = 0x000081b4,
.DecryptPatchAddr = 0x000041d0,
.DecryptPatchAddr2 = 0x000068f8,
.DecryptFuncAddr = 0x000081d4,
},
};

#ifdef PAYLOADEX
void patchIplPayload(MsLfatFuncs *funcs);
#elif defined REBOOTEX
void patchRebootBin(MsLfatFuncs *funcs);
#endif
29 changes: 29 additions & 0 deletions tm_firmware/500/common/include/rebootex_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Based on rebootex_config.h from minimum edition - https://github.com/PSP-Archive/minimum_edition
*/

#ifndef __REBOOTEX_CONFIG_H__
#define __REBOOTEX_CONFIG_H__

#include <psptypes.h>

#define REBOOTEX_FILELEN_MAX 0x50
#define REBOOTEX_PARAM_OFFSET 0x88FB0000

typedef struct RebootexParam {
char file[REBOOTEX_FILELEN_MAX];//0
u32 config[0x70/4];//0x50
int reboot_index;//0xc0
int mem2;
int mem8;
int k150_flag;
void* on_reboot_after;
void* on_reboot_buf;
int on_reboot_size;
int on_reboot_flag;
} RebootexParam;

// *(u32 *)0x88FB00F0 = size_systemctrl;//

#endif

Loading