From 926fc83f75a9f02932ab3e0a30750a3b85de609a Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 11:46:53 +0100 Subject: [PATCH 1/9] improved headers from adrenaline --- src/ctrl/pspctrl.h | 36 +++-- src/kernel/pspamctrl.h | 77 ++++++++++ src/kernel/pspinit.h | 255 +++++++++++++++++++++++++++---- src/kernel/psploadcore.h | 151 ++++++++++++++++++ src/kernel/pspmodulemgr_kernel.h | 22 +++ src/kernel/pspsysmem_kernel.h | 88 ++++++++--- src/usb/pspusbcam.h | 17 +++ src/user/pspmodulemgr.h | 7 + src/user/pspsysmem.h | 2 + 9 files changed, 596 insertions(+), 59 deletions(-) create mode 100644 src/kernel/pspamctrl.h diff --git a/src/ctrl/pspctrl.h b/src/ctrl/pspctrl.h index 149c87a9c0..da5990623c 100644 --- a/src/ctrl/pspctrl.h +++ b/src/ctrl/pspctrl.h @@ -40,10 +40,13 @@ extern "C" { * @see ::SceCtrlData * @see ::SceCtrlLatch */ -enum PspCtrlButtons -{ +enum PspCtrlButtons { /** Select button. */ PSP_CTRL_SELECT = 0x000001, + /** L3 button. */ + PSP_CTRL_L3 = 0x000002, + /** R3 button. */ + PSP_CTRL_R3 = 0x000004, /** Start button. */ PSP_CTRL_START = 0x000008, /** Up D-Pad button. */ @@ -58,6 +61,14 @@ enum PspCtrlButtons PSP_CTRL_LTRIGGER = 0x000100, /** Right trigger. */ PSP_CTRL_RTRIGGER = 0x000200, + /** L2 button. */ + PSP_CTRL_L2 = 0x000100, + /** R2 button. */ + PSP_CTRL_R2 = 0x000200, + /** L1 button. */ + PSP_CTRL_L1 = 0x000400, + /** R1 button. */ + PSP_CTRL_R1 = 0x000800, /** Triangle button. */ PSP_CTRL_TRIANGLE = 0x001000, /** Circle button. */ @@ -66,28 +77,25 @@ enum PspCtrlButtons PSP_CTRL_CROSS = 0x004000, /** Square button. */ PSP_CTRL_SQUARE = 0x008000, - /** - * Kernel mode: Home button state. - * User mode: Exit dialog visible. - */ + /** Home button. In user mode this bit is set if the exit dialog is visible. */ PSP_CTRL_HOME = 0x010000, /** Hold button. */ PSP_CTRL_HOLD = 0x020000, - /** Music note button - kernel mode only.*/ + /** Music Note button. */ PSP_CTRL_NOTE = 0x800000, - /** Screen button - kernel mode only.*/ + /** Screen button. */ PSP_CTRL_SCREEN = 0x400000, - /** Volume up button - kernel mode only.*/ + /** Volume up button. */ PSP_CTRL_VOLUP = 0x100000, - /** Volume down button - kernel mode only.*/ + /** Volume down button. */ PSP_CTRL_VOLDOWN = 0x200000, - /** Wlan switch up - kernel mode only.*/ + /** Wlan switch up. */ PSP_CTRL_WLAN_UP = 0x040000, - /** Remote hold position - kernel mode only.*/ + /** Remote hold position. */ PSP_CTRL_REMOTE = 0x080000, - /** Disc present - kernel mode only.*/ + /** Disc present. */ PSP_CTRL_DISC = 0x1000000, - /** Memory stick present - kernel mode only.*/ + /** Memory stick present. */ PSP_CTRL_MS = 0x2000000, }; diff --git a/src/kernel/pspamctrl.h b/src/kernel/pspamctrl.h new file mode 100644 index 0000000000..3e482ee6d7 --- /dev/null +++ b/src/kernel/pspamctrl.h @@ -0,0 +1,77 @@ +/* + * PSP Software Development Kit - http://www.pspdev.org + * ----------------------------------------------------------------------- + * Licensed under the BSD license, see LICENSE in PSPSDK root for details. + * + * pspamctrl.h - Prototypes for the sceAmctrl_driver library. + * + * Copyright (c) 2024 GrayJack + * + * TODO: Contribute this header to PSPSDK + */ + +#ifndef AM_CTRL_H +#define AM_CTRL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + + +typedef struct SceMacKey { + int type; + u8 key[16]; + u8 pad[16]; + int pad_size; +} SceMacKey; + +typedef struct SceCipherKey { + u32 type; + u32 seed; + u8 key[16]; +} SceCipherKey; + +enum SceMacKeyType { + MAC_KEY_TYPE_UNK0 = 0, + MAC_KEY_TYPE_UNK1 = 1, + /** Use fuse ID */ + MAC_KEY_TYPE_FUSE_ID = 2, + /** Use fixed key. MAC will need to encrypt again. */ + MAC_KEY_TYPE_FIXED = 3, + MAC_KEY_TYPE_UNK6 = 6, +}; + +enum SceCipherKeyType { + /** Use fixed key */ + CIPHER_KEY_TYPE_FIXED = 1, + /** Use fuse ID */ + CIPHER_KEY_TYPE_FUSE_ID = 2, +}; + +enum SceCipherKeyMode { + CIPHER_KEY_MODE_ENCRYPT = 1, + CIPHER_KEY_MODE_DECRYPT = 2, +}; + +#ifdef __KERNEL__ + +int sceDrmBBMacInit(SceMacKey *mac_key, int type); +int sceDrmBBMacUpdate(SceMacKey *mac_key, u8 *buf, int size); +int sceAmctrl_driver_9227EA79(SceMacKey *mac_key, u8 *buf, int size); +int sceDrmBBMacFinal(SceMacKey *mac_key, u8 *buf, u8 *version_key); +int sceDrmBBMacFinal2(SceMacKey *mac_key, u8 *buf, u8 *version_key); + +int sceDrmBBCipherInit(SceCipherKey *cipher_key, int type, int mode, u8 *header_key, u8 *version_key, int seed); +int sceDrmBBCipherUpdate(SceCipherKey *cipher_key, u8 *buf, int size); +int sceAmctrl_driver_E04ADD4C(SceCipherKey *cipher_key, u8 *buf, int size); +int sceDrmBBCipherFinal(SceCipherKey *cipher_key); + +#endif // __KERNEL__ + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // AM_CTRL_H \ No newline at end of file diff --git a/src/kernel/pspinit.h b/src/kernel/pspinit.h index d0715c6ebd..28688c5f3e 100644 --- a/src/kernel/pspinit.h +++ b/src/kernel/pspinit.h @@ -11,32 +11,224 @@ #ifndef __PSPINIT_H__ #define __PSPINIT_H__ -enum PSPBootFrom -{ - PSP_BOOT_FLASH = 0, /* ? */ - PSP_BOOT_DISC = 0x20, - PSP_BOOT_MS = 0x40, -}; - -enum PSPInitApitype -{ - PSP_INIT_APITYPE_DISC = 0x120, - PSP_INIT_APITYPE_DISC_UPDATER = 0x121, - PSP_INIT_APITYPE_MS1 = 0x140, - PSP_INIT_APITYPE_MS2 = 0x141, - PSP_INIT_APITYPE_MS3 = 0x142, - PSP_INIT_APITYPE_MS4 = 0x143, - PSP_INIT_APITYPE_MS5 = 0x144, - PSP_INIT_APITYPE_VSH1 = 0x210, /* ExitGame */ - PSP_INIT_APITYPE_VSH2 = 0x220, /* ExitVSH */ -}; - -enum PSPKeyConfig -{ - PSP_INIT_KEYCONFIG_VSH = 0x100, - PSP_INIT_KEYCONFIG_GAME = 0x200, - PSP_INIT_KEYCONFIG_POPS = 0x300, -}; +#include + +/** + * The possible boot medium types for an executable. + */ +typedef enum PSPBootFrom { + /** The executable was booted via Flash 0 (1, 2). */ + PSP_BOOT_FLASH = 0, + /** The executable was booted via a Disc medium. */ + PSP_BOOT_DISC = 0x20, + /** The executable was booted via a Game-sharing medium. */ + PSP_BOOT_USBWLAN = 0x30, + /** The executable was booted via the Memory Stick medium. */ + PSP_BOOT_MS = 0x40, + /** The executable was booted via an unknown medium. */ + PSP_BOOT_EF = 0x50, + /** The executable was booted via Flash 3.*/ + PSP_BOOT_FLASH3 = 0x80, +} PSPBootFrom; + +/** + * API types of an executable. + * + * `sceKernelLoadModuleWithApitype` + */ +typedef enum PSPInitApitype { + PSP_INIT_APITYPE_KERNEL = 0, /* ModuleMgrForKernel */ + PSP_INIT_APITYPE_BUFFER_KERNEL = 0x02, + PSP_INIT_APITYPE_KERNEL_BLOCK = 0x03, + PSP_INIT_APITYPE_USER = 0x10, /* ModuleMgrForUser */ + PSP_INIT_APITYPE_DNAS = 0x13, + PSP_INIT_APITYPE_NPDRM = 0x14, + PSP_INIT_APITYPE_VSH = 0x20, + PSP_INIT_APITYPE_BUFFER_VSH = 0x21, + PSP_INIT_APITYPE_BUFFER_USBWLAN = 0x30, + PSP_INIT_APITYPE_BUFFER_MS = 0x42, + PSP_INIT_APITYPE_BUFFER_APP = 0x43, + PSP_INIT_APITYPE_BUFFER_BOOT_INIT_BTCNF = 0x51, + PSP_INIT_APITYPE_BUFFER_BOOT_INIT_CONFIG = 0x52, + PSP_INIT_APITYPE_BUFFER_DECI = 0x70, + + /** GAME EBOOT. */ + PSP_INIT_APITYPE_GAME_EBOOT = 0x110, + /** GAME BOOT. */ + PSP_INIT_APITYPE_GAME_BOOT = 0x111, + /** Emulated EBOOT Memory-Stick. */ + PSP_INIT_APITYPE_EMU_EBOOT_MS = 0x112, + /** Emulated BOOT Memory-Stick. */ + PSP_INIT_APITYPE_EMU_BOOT_MS = 0x113, + /** Emulated EBOOT EF. */ + PSP_INIT_APITYPE_EMU_EBOOT_EF = 0x114, + /** Emulated BOOT EF. */ + PSP_INIT_APITYPE_EMU_BOOT_EF = 0x115, + /** NP-DRM Memory-Stick. */ + PSP_INIT_APITYPE_NPDRM_MS = 0x116, /* Distributed programs and data through the Playstation Store. */ + /** Unknown. */ + PSP_INIT_APITYPE_UNK117 = 0x117, + /** NP-DRM EF. */ + PSP_INIT_APITYPE_NPDRM_EF = 0x118, /* NP-DRM: PlayStation Network Platform Digital Rights Management */ + /** Unknown. */ + PSP_INIT_APITYPE_UNK119 = 0x119, + /** Executable on a disc. */ + PSP_INIT_APITYPE_UMD = 0x120, + /** Updater executable on a disc. */ + PSP_INIT_APITYPE_UMD_UPDATER = 0x121, + /** Disc debugger. */ + PSP_INIT_APITYPE_UMD_DEBUG = 0x122, + /** NP-9660 game on Memory Stick. */ + PSP_INIT_APITYPE_UMD_EMU_MS1 = 0x123, + /** NP-9660 game with update/DLC (`PBOOT.PBP`) on Memory Stick. */ + PSP_INIT_APITYPE_UMD_EMU_MS2 = 0x124, + /** NP-9660 game on internal memory (`ef0:`). */ + PSP_INIT_APITYPE_UMD_EMU_EF1 = 0x125, + /** NP-9660 game with update/DLC (`PBOOT.PBP`) on internal memory (`ef0:`). */ + PSP_INIT_APITYPE_UMD_EMU_EF2 = 0x126, + /** Game-sharing executable. */ + PSP_INIT_APITYPE_USBWLAN = 0x130, + /** Unknown. */ + PSP_INIT_APITYPE_USBWLAN_DEBUG = 0x131, + /** Updater executable on a PBP in the Memory Stick. */ + PSP_INIT_APITYPE_MS1 = 0x140, + /** PSP executable on a PBP in the Memory Stick. */ + PSP_INIT_APITYPE_MS2 = 0x141, + /** Unknown. */ + PSP_INIT_APITYPE_MS3 = 0x142, + /** Applications (i.e. Comic Reader) executable on a PBP in the Memory Stick. */ + PSP_INIT_APITYPE_MS4 = 0x143, + /** Playstation One executable on a PBP in the Memory Stick. */ + PSP_INIT_APITYPE_MS5 = 0x144, + /** Unknown. Licensed games? */ + PSP_INIT_APITYPE_MS6 = 0x145, + /** Updater executable on a PBP in the internal memory (`ef0:`). */ + PSP_INIT_APITYPE_EF1 = 0x151, + /** PSP executable on a PBP in the internal memory (`ef0:`). */ + PSP_INIT_APITYPE_EF2 = 0x152, + /** Unknown. Probably the same as MS3 but loading form `ef0`. */ + PSP_INIT_APITYPE_EF3 = 0x153, + /** Applications (i.e. Comic Reader) executable on a PBP in the internal memory (`ef0:`). */ + PSP_INIT_APITYPE_EF4 = 0x154, + /** Playstation One executable on a PBP in the internal memory (`ef0:`). */ + PSP_INIT_APITYPE_EF5 = 0x155, + /** Unknown. Probably the same as MS6 but loading form `ef0`. */ + PSP_INIT_APITYPE_EF6 = 0x156, + /** Game/APP with update/DLC on a disc. */ + PSP_INIT_APITYPE_UMD2 = 0x160, + /** Unknown. */ + PSP_INIT_APITYPE_UNK161 = 0x161, + /** MerlinDRM Applications on Memory Stick */ + PSP_INIT_APITYPE_MLNAPP_MS = 0x170, + /** MerlinDRM Applications on internal memory (`ef0:`). */ + PSP_INIT_APITYPE_MLNAPP_EF = 0x171, + /** Exit VSH Kernel. */ + PSP_INIT_APITYPE_VSH_KERNEL = 0x200, + /** Exit Game. */ + PSP_INIT_APITYPE_VSH1 = 0x210, + /** Exit VSH. */ + PSP_INIT_APITYPE_VSH2 = 0x220, + /** Kernel reboot. */ + PSP_INIT_APITYPE_KERNEL_REBOOT = 0x300, + /** Debug. Doesn't start reboot. */ + PSP_INIT_APITYPE_DEBUG = 0x420, /* doesn't start reboot */ + + // Alias + PSP_INIT_APITYPE_DISC = PSP_INIT_APITYPE_UMD, + PSP_INIT_APITYPE_DISC2 = PSP_INIT_APITYPE_UMD2, + PSP_INIT_APITYPE_DISC_UPDATER = PSP_INIT_APITYPE_UMD_UPDATER, + PSP_INIT_APITYPE_DISC_DEBUG = PSP_INIT_APITYPE_UMD_DEBUG, + PSP_INIT_APITYPE_DISC_EMU_MS1 = PSP_INIT_APITYPE_UMD_EMU_MS1, + PSP_INIT_APITYPE_DISC_EMU_MS2 = PSP_INIT_APITYPE_UMD_EMU_MS2, + PSP_INIT_APITYPE_DISC_EMU_EF1 = PSP_INIT_APITYPE_UMD_EMU_EF1, + PSP_INIT_APITYPE_DISC_EMU_EF2 = PSP_INIT_APITYPE_UMD_EMU_EF2, + PSP_INIT_APITYPE_MS_UPDATER = PSP_INIT_APITYPE_MS1, + PSP_INIT_APITYPE_MS_GAME = PSP_INIT_APITYPE_MS2, + PSP_INIT_APITYPE_MS_APP = PSP_INIT_APITYPE_MS4, + PSP_INIT_APITYPE_MS_PS1 = PSP_INIT_APITYPE_MS5, + PSP_INIT_APITYPE_EF_UPDATER = PSP_INIT_APITYPE_EF1, + PSP_INIT_APITYPE_EF_GAME = PSP_INIT_APITYPE_EF2, + PSP_INIT_APITYPE_EF_APP = PSP_INIT_APITYPE_EF4, + PSP_INIT_APITYPE_EF_PS1 = PSP_INIT_APITYPE_EF5, + PSP_INIT_APITYPE_VSH_EXITGAME = PSP_INIT_APITYPE_VSH1, /* ExitGame */ + PSP_INIT_APITYPE_VSH_EXITVSH = PSP_INIT_APITYPE_VSH2, /* ExitVSH */ +} PSPInitApitype; + +/** + * Application types of an executable. + */ +typedef enum PSPKeyConfig { + /** The application is a VSH application (i.e. VSH modules). */ + PSP_INIT_KEYCONFIG_VSH = 0x100, + /** The application is an updater. */ + PSP_INIT_KEYCONFIG_UPDATER = 0x110, + /** The application is a PSP game. */ + PSP_INIT_KEYCONFIG_GAME = 0x200, + /** The application is a Playstation One game. */ + PSP_INIT_KEYCONFIG_POPS = 0x300, + /** The application is a PSP application (i.e. Skype). */ + PSP_INIT_KEYCONFIG_APP = 0x400, +} PSPKeyConfig; + +/** + * This structure represents a boot callback belonging to a module. + */ +typedef struct SceBootCallback { + /** The boot callback function. */ + void *boot_callback_func; + /** Global pointer value of the module. */ + u32 gp; +} SceBootCallback; + +/** + * This structure represents an Init control block. It holds information about the + * currently booted module by Init. + */ +typedef struct SceInit { + /** The API type of the currently loaded module. One of ::SceInitApiType. */ + s32 apitype; //0 + /** The address of a memory protection block of type ::SCE_PROTECT_INFO_TYPE_FILE_NAME. */ + void *file_mod_addr; //4 + /** The address of a memory protection block of type ::SCE_PROTECT_INFO_TYPE_DISC_IMAGE. */ + void *disc_mod_addr; //8 + /** VSH parameters. Used to reboot the kernel. */ + struct SceKernelLoadExecVSHParam vsh_param; //12 + /** Unknown. */ + s32 unk60; + /** Unknown. */ + s32 unk64; + /** Unknown. */ + s32 unk68; + /** Unknown. */ + s32 unk72; + /** Unknown. */ + s32 unk76; + /** Unknown. */ + s32 unk80; + /** Unknown. */ + s32 unk84; + /** Unknown. */ + s32 unk88; + /** The application type of the currently loaded module. One of ::SceApplicationType. */ + u32 application_type; //92 + /** The number of power locks used by Init. */ + s32 num_power_locks; //96 + /** The address of a memory protection block of type ::SCE_PROTECT_INFO_TYPE_PARAM_SFO. */ + void *param_sfo_base; //100 + /** The size of of the memory block pointed to by ::paramSfoBase. */ + SceSize param_sfo_size; //104 + /** Unknown. */ + s32 lpt_summary; //108 + /** Pointer to boot callbacks of modules. */ + SceBootCallback *boot_callbacks1; //112 + /** The current boot callback 1 slot used to hold the registered boot callback. */ + SceBootCallback *cur_boot_callback1; //116 + /** Pointer to boot callbacks of modules. */ + SceBootCallback *boot_callbacks2; //120 + /** The current boot callback 2 slot used to hold the registered boot callback. */ + SceBootCallback *cur_boot_callback2; //124 +} SceInit; + /** * Gets the api type @@ -65,9 +257,16 @@ int sceKernelBootFrom(); * * @return the key configuration code, one of PSPKeyConfig values */ -int InitForKernel_7233B5BC(); +int sceKernelApplicationType(); +#define sceKernelInitKeyConfig sceKernelApplicationType -#define sceKernelInitKeyConfig InitForKernel_7233B5BC +/** + * Retrieve Init's internal control block. This control block manages execution details of an + * executable, like its API type, its boot medium and its application type. + * + * @return A pointer to Init's internal control block. + */ +SceInit *sceKernelQueryInitCB(void); #endif diff --git a/src/kernel/psploadcore.h b/src/kernel/psploadcore.h index e6ba09d70d..37224a186d 100644 --- a/src/kernel/psploadcore.h +++ b/src/kernel/psploadcore.h @@ -26,6 +26,7 @@ extern "C" { /** @addtogroup LoadCore Interface to the LoadCoreForKernel library. */ /**@{*/ +#define SCE_KERNEL_MAX_MODULE_SEGMENT (4) /** Reboot preparation functions */ typedef s32 (*SceKernelRebootBeforeForKernel)(void *arg1, s32 arg2, s32 arg3, s32 arg4); @@ -195,6 +196,17 @@ typedef struct SceModule { u32 compute_text_segment_checksum; } SceModule; +typedef struct { + char *name; + void *buf; + int size; + int unk_12; + int attr; + int unk_20; + int argSize; + int argPartId; +} SceLoadCoreBootModuleInfo; + /** Defines a library and its exported functions and variables. Use the len member to determine the real size of the table (size = len * 4). */ typedef struct SceLibraryEntryTable { @@ -238,6 +250,107 @@ typedef struct SceLibraryStubTable { void * vstubtable; } SceLibraryStubTable; +typedef struct SceLoadCoreExecFileInfo { + /** Unknown. */ + u32 unk0; + /** The mode attribute of the executable file. One of ::SceExecFileModeAttr. */ + u32 mode_attr; //4 + /** The API type. */ + u32 api_type; //8 + /** Unknown. */ + u32 unk12; + /** The size of the executable, including the ~PSP header. */ + SceSize exec_size; //16 + /** The maximum size needed for the decompression. */ + SceSize max_alloc_size; //20 + /** The memory ID of the decompression buffer. */ + SceUID decompression_mem_id; //24 + /** Pointer to the compressed module data. */ + void *file_base; //28 + /** Indicates the ELF type of the executable. One of ::SceExecFileElfType. */ + u32 elf_type; //32 + /** The start address of the TEXT segment of the executable in memory. */ + void *top_addr; //36 + /** + * The entry address of the module. It is the offset from the start of the TEXT segment to the + * program's entry point. + */ + u32 entry_addr; //40 + /** Unknown. */ + u32 unk44; + /** + * The size of the largest module segment. Should normally be "textSize", but technically can + * be any other segment. + */ + SceSize largest_seg_size; //48 + /** The size of the TEXT segment. */ + SceSize text_size; //52 + /** The size of the DATA segment. */ + SceSize data_size; //56 + /** The size of the BSS segment. */ + SceSize bss_size; //60 + /** The memory partition of the executable. */ + u32 partition_id; //64 + /** + * Indicates whether the executable is a kernel module or not. Set to 1 for kernel module, + * 0 for user module. + */ + u32 is_kernel_mod; //68 + /** + * Indicates whether the executable is decrypted or not. Set to 1 if it is successfully decrypted, + * 0 for encrypted. + */ + u32 is_decrypted; //72 + /** The offset from the start address of the TEXT segment to the SceModuleInfo section. */ + u32 module_info_offset; //76 + /** The pointer to the module's SceModuleInfo section. */ + SceModuleInfo *module_info; //80 + /** Indicates whether the module is compressed or not. Set to 1 if it is compressed, otherwise 0.*/ + u32 is_compressed; //84 + /** The module's attributes. One or more of ::SceModuleAttribute and ::SceModulePrivilegeLevel. */ + u16 mod_info_attribute; //88 + /** The attributes of the executable file. One of ::SceExecFileAttr. */ + u16 exec_attribute; //90 + /** The size of the decompressed module, including its headers. */ + SceSize dec_size; //92 + /** Indicates whether the module is decompressed or not. Set to 1 for decompressed, otherwise 0. */ + u32 is_decompressed; //96 + /** + * Indicates whether the module was signChecked or not. Set to 1 for signChecked, otherwise 0. + * A signed module has a "mangled" executable header, in other words, the "~PSP" signature can't + * be seen. + */ + u32 is_sign_checked; //100 + /** Unknown. */ + u32 unk104; + /** The size of the GZIP compression overlap. */ + SceSize overlap_size; //108 + /** Pointer to the first resident library entry table of the module. */ + void *exports_info; //112 + /** The size of all resident library entry tables of the module. */ + SceSize exports_size; //116 + /** Pointer to the first stub library entry table of the module. */ + void *imports_info; //120 + /** The size of all stub library entry tables of the module. */ + SceSize imports_size; //124 + /** Pointer to the string table section. */ + void *strtab_offset; //128 + /** The number of segments in the executable. */ + u8 num_segments; //132 + /** Reserved. */ + u8 padding[3]; //133 + /** An array containing the start address of each segment. */ + u32 segment_addr[SCE_KERNEL_MAX_MODULE_SEGMENT]; //136 + /** An array containing the size of each segment. */ + u32 segment_size[SCE_KERNEL_MAX_MODULE_SEGMENT]; //152 + /** The ID of the ELF memory block containing the TEXT, DATA and BSS segment. */ + SceUID mem_block_id; //168 + /** An array containing the alignment information of each segment. */ + u32 segment_align[SCE_KERNEL_MAX_MODULE_SEGMENT]; //172 + /** The largest value of the segment_align array. */ + u32 max_seg_align; //188 +} SceLoadCoreExecFileInfo; + /** * Find a module by it's name. @@ -278,6 +391,44 @@ int sceKernelModuleCount(void); */ void sceKernelIcacheClearAll(void); +/** + * Check an executable file. This contains scanning its ELF header and ~PSP header (if it has one) + * and filling the execInfo structure with basic information, like the ELF type, segment information, + * the size of the executable. The file is also uncompressed, if it was compressed before. + * + * @param buf Pointer to the file's contents. + * @param execInfo Pointer to the executionInfo belonging to that executable. + * + * @return 0 on success. + */ +int sceKernelCheckExecFile(void *buf, SceLoadCoreExecFileInfo *execInfo); + +/** + * Probe an executable file. This contains calculating the sizes for the three segments TEXT, DATA + * and BSS, filling the execInfo structure with information about the location and sizes of the + * resident/stub library entry tables. + * + * Furthermore, it is checked whether the executable has valid API type or not. + * + * @param buf Pointer to the file's contents. + * @param execInfo Pointer to the executionInfo belonging to that executable. + * + * @return 0 on success. + */ +int sceKernelProbeExecutableObject(void *buf, SceLoadCoreExecFileInfo *execInfo); + +/** + * Receive a list of UIDs of loaded modules. + * + * @param mod_id_list Pointer to a SceUID array which will receive the UIDs of the loaded modules. + * @param size Size of mod_id_list. Specifies the number of entries that can be stored into mod_id_list. + * @param mod_count A pointer which will receive the total number of loaded modules. + * @param user_mods_only Set to 1 to only receive UIDs from user mode modules. Set to 0 to receive UIDs from all loaded modules. + * + * @return 0 on success. + */ +int sceKernelGetModuleIdListForKernel(SceUID *mod_id_list, u32 size, u32 *mod_count, u32 user_mods_only); + /**@}*/ #ifdef __cplusplus diff --git a/src/kernel/pspmodulemgr_kernel.h b/src/kernel/pspmodulemgr_kernel.h index e031b0f88b..1f3b46129d 100644 --- a/src/kernel/pspmodulemgr_kernel.h +++ b/src/kernel/pspmodulemgr_kernel.h @@ -59,6 +59,28 @@ int sceKernelModuleCount(void); */ SceUID sceKernelLoadModuleBuffer(void *buf, SceSize bufsize, int flags, SceKernelLMOption *option); +/** + * Alias for `sceKernelLoadModuleForLoadExecForUser` + * + * @attention Needs to link to `pspmodulemgr_kernel` stub. + */ +SceUID sceKernelLoadModuleWithApitype2(int apitype, const char *path, int flags, SceKernelLMOption *option); + +/** + * Load a module from a buffer with the Boot Init BTCNF apitype (0x051). + * + * @param bufsize - Size (in bytes) of the buffer pointed to by buf. + * @param buf - Pointer to a buffer containing the module to load. The buffer must reside at an + * address that is a multiple to 64 bytes. + * @param flags - Unused, always 0. + * @param option - Pointer to an optional ::SceKernelLMOption structure. + * + * @returns The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. + * + * @attention Needs to link to `pspmodulemgr_kernel` stub. + */ +SceUID sceKernelLoadModuleBufferBootInitBtcnf(int bufsize, void *buf, int flags, SceKernelLMOption *option); + /**@}*/ #ifdef __cplusplus diff --git a/src/kernel/pspsysmem_kernel.h b/src/kernel/pspsysmem_kernel.h index 9f7de9b12e..e4d36a45be 100644 --- a/src/kernel/pspsysmem_kernel.h +++ b/src/kernel/pspsysmem_kernel.h @@ -39,6 +39,44 @@ typedef struct _PspSysmemPartitionInfo unsigned int attr; } PspSysmemPartitionInfo; +typedef struct SceGameInfo { + u32 size; // 0 + u32 flags; // 4 + char umd_data_string[16]; // 8 + char expect_umd_data[16]; // 24 + char qtgp2[8]; // 40 + char qtgp3[16]; // 48 + u32 allow_replace_umd; // 64 + char title_id[16]; // 68 + u32 parental_level; // 84 + char vsh_version[8]; // 88 + u32 umd_cache_on; // 96 + u32 compiled_sdk_version; // 100 + u32 compiler_version; // 104 + u32 dnas; // 108 + u32 utility_location; // 112 + char vsh_bootfilename[64]; // 116 + char gamedata_id[16]; // 180 + char app_ver[8]; // 196 + char subscription_validity[8]; // 204 + int bootable; // 212 + int opnssmp_ver; // 216 +} SceGameInfo; + +/** Structure of a UID control block */ +struct SceUidControlBlock { + struct SceUidControlBlock *parent; + struct SceUidControlBlock *nextChild; + struct SceUidControlBlock *type; //(0x8) + u32 UID; //(0xC) + char *name; //(0x10) + unsigned char unk; + unsigned char size; // Size in words + short attribute; + struct SceUidControlBlock *nextEntry; +} __attribute__((packed)); +typedef struct SceUidControlBlock SceUidControlBlock; + /** * Query the parition information * @@ -143,20 +181,6 @@ int sceKernelDeleteHeap(SceUID heapid); */ SceSize sceKernelHeapTotalFreeSize(SceUID heapid); -/** Structure of a UID control block */ -struct _uidControlBlock { - struct _uidControlBlock *parent; - struct _uidControlBlock *nextChild; - struct _uidControlBlock *type; //(0x8) - u32 UID; //(0xC) - char *name; //(0x10) - unsigned char unk; - unsigned char size; // Size in words - short attribute; - struct _uidControlBlock *nextEntry; -} __attribute__((packed)); -typedef struct _uidControlBlock uidControlBlock; - /** * Get a UID control block * @@ -165,7 +189,7 @@ typedef struct _uidControlBlock uidControlBlock; * * @return 0 on success */ -int sceKernelGetUIDcontrolBlock(SceUID uid, uidControlBlock** block); +int sceKernelGetSceUidControlBlock(SceUID uid, SceUidControlBlock** block); /** * Get a UID control block on a particular type @@ -176,14 +200,14 @@ int sceKernelGetUIDcontrolBlock(SceUID uid, uidControlBlock** block); * * @return 0 on success */ -int sceKernelGetUIDcontrolBlockWithType(SceUID uid, uidControlBlock* type, uidControlBlock** block); +int sceKernelGetSceUidControlBlockWithType(SceUID uid, SceUidControlBlock* type, SceUidControlBlock** block); /** * Get the root of the UID tree (1.5+ only) * * @return Pointer to the UID tree root */ -uidControlBlock* SysMemForKernel_536AD5E1(void); +SceUidControlBlock* SysMemForKernel_536AD5E1(void); /** * Delete a UID @@ -216,6 +240,36 @@ int sceKernelSetCompiledSdkVersion(int version); */ int sceKernelGetCompiledSdkVersion(void); +/** + * Gets the information of the game. (2.00+ ?) + * + * @returns Pointer to the game information on success. NULL otherwise. + * + * @attention Needs to link to `pspsysmem_kernel` stub. + */ +SceGameInfo *sceKernelGetGameInfo(); + +/** + * Gets the current status of the system. + * + * @returns The status of the system. + * + * @attention Needs to link to `pspsysmem_kernel` stub. + */ +int sceKernelGetSystemStatus(); + +/** + * Get a UID control block + * + * @param uid - The UID to find + * @param block - Pointer to hold the pointer to the block + * + * @return 0 on success + * + * @attention Needs to link to `pspsysmem_kernel` stub. + */ +int sceKernelGetUIDcontrolBlock(SceUID uid, SceUidControlBlock** block); + #ifdef __cplusplus } #endif diff --git a/src/usb/pspusbcam.h b/src/usb/pspusbcam.h index 06232339f2..05cd280507 100644 --- a/src/usb/pspusbcam.h +++ b/src/usb/pspusbcam.h @@ -247,6 +247,23 @@ typedef struct PspUsbCamSetupVideoExParam { int evlevel; } PspUsbCamSetupVideoExParam; +typedef struct PspUsbCamSetupMicParam { + int size; + int alc; + int gain; + int noize; + int freq; +} PspUsbCamSetupMicParam; + +typedef struct PspUsbCamSetupMicExParam { + int size; + int alc; + int gain; + u32 unk2[4]; // noize/hold/decay/attack? + int freq; + int unk3; +} PspUsbCamSetupMicExParam; + /** * Setups the parameters to take a still image. * diff --git a/src/user/pspmodulemgr.h b/src/user/pspmodulemgr.h index cc208450cc..eb0d8c17ab 100644 --- a/src/user/pspmodulemgr.h +++ b/src/user/pspmodulemgr.h @@ -79,6 +79,13 @@ SceUID sceKernelLoadModule(const char *path, int flags, SceKernelLMOption *optio */ SceUID sceKernelLoadModuleMs(const char *path, int flags, SceKernelLMOption *option); +/** + * Alias for `sceKernelLoadModuleForLoadExecVSHMs2` + * + * @attention Needs to link to `pspmodulemgr_kernel` stub. + */ +SceUID sceKernelLoadModuleMs2(int apitype, const char *path, int flags, SceKernelLMOption *option); + /** * Load a module from the given file UID. * diff --git a/src/user/pspsysmem.h b/src/user/pspsysmem.h index 4eb1ca41e0..0c86933cd5 100644 --- a/src/user/pspsysmem.h +++ b/src/user/pspsysmem.h @@ -130,6 +130,8 @@ int sceKernelSetCompiledSdkVersion(int version); */ int sceKernelGetCompiledSdkVersion(void); + + #ifdef __cplusplus } #endif From 56ece7ca9785e625644fb49409d8c03b422a921f Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 12:35:49 +0100 Subject: [PATCH 2/9] add missing defs --- src/kernel/InitForKernel.S | 24 ++++++++++++------------ src/usb/pspusbcam.h | 2 ++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/kernel/InitForKernel.S b/src/kernel/InitForKernel.S index 8eee6bdbc2..bb5ef99cda 100644 --- a/src/kernel/InitForKernel.S +++ b/src/kernel/InitForKernel.S @@ -6,35 +6,35 @@ IMPORT_START "InitForKernel",0x00090000 #endif #ifdef F_InitForKernel_0001 - IMPORT_FUNC "InitForKernel",0x1D3256BA,sceKernelRegisterChunk + IMPORT_FUNC "InitForKernel",0x1D3256BA,sceKernelRegisterChunk #endif #ifdef F_InitForKernel_0002 - IMPORT_FUNC "InitForKernel",0x27932388,sceKernelBootFrom + IMPORT_FUNC "InitForKernel",0x27932388,sceKernelBootFrom #endif #ifdef F_InitForKernel_0003 - IMPORT_FUNC "InitForKernel",0x2C6E9FE9,sceKernelGetChunk + IMPORT_FUNC "InitForKernel",0x2C6E9FE9,sceKernelGetChunk #endif #ifdef F_InitForKernel_0004 - IMPORT_FUNC "InitForKernel",0x33D30F49,InitForKernel_33D30F49 + IMPORT_FUNC "InitForKernel",0x33D30F49,InitForKernel_33D30F49 #endif #ifdef F_InitForKernel_0005 - IMPORT_FUNC "InitForKernel",0x7233B5BC,InitForKernel_7233B5BC + IMPORT_FUNC_WITH_ALIAS "InitForKernel",0x7233B5BC,sceKernelApplicationType,sceKernelInitKeyConfig #endif #ifdef F_InitForKernel_0006 - IMPORT_FUNC "InitForKernel",0x7A2333AD,sceKernelInitApitype + IMPORT_FUNC "InitForKernel",0x7A2333AD,sceKernelInitApitype #endif #ifdef F_InitForKernel_0007 - IMPORT_FUNC "InitForKernel",0x9F9AE99C,InitForKernel_9F9AE99C + IMPORT_FUNC "InitForKernel",0x9F9AE99C,InitForKernel_9F9AE99C #endif #ifdef F_InitForKernel_0008 - IMPORT_FUNC "InitForKernel",0xA6E71B93,sceKernelInitFileName + IMPORT_FUNC "InitForKernel",0xA6E71B93,sceKernelInitFileName #endif #ifdef F_InitForKernel_0009 - IMPORT_FUNC "InitForKernel",0xC4F1BA33,InitForKernel_C4F1BA33 + IMPORT_FUNC "InitForKernel",0xC4F1BA33,InitForKernel_C4F1BA33 #endif #ifdef F_InitForKernel_0010 - IMPORT_FUNC "InitForKernel",0xCE88E870,sceKernelReleaseChunk + IMPORT_FUNC "InitForKernel",0xCE88E870,sceKernelReleaseChunk #endif #ifdef F_InitForKernel_0011 - IMPORT_FUNC "InitForKernel",0xFD0F25AD,InitForKernel_FD0F25AD -#endif + IMPORT_FUNC "InitForKernel",0xFD0F25AD,InitForKernel_FD0F25AD +#endif diff --git a/src/usb/pspusbcam.h b/src/usb/pspusbcam.h index 05cd280507..f1fba59ef8 100644 --- a/src/usb/pspusbcam.h +++ b/src/usb/pspusbcam.h @@ -584,6 +584,8 @@ int sceUsbCamGetAutoImageReverseState(void); */ int sceUsbCamGetLensDirection(void); +int sceUsbCamSetupMic(void *param, void *workarea, int wasize); + #ifdef __cplusplus } #endif From 5eaed58041c0e561c966a8b5853c15f7d7580151 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 12:41:17 +0100 Subject: [PATCH 3/9] fix --- src/kernel/Makefile.am | 3 ++- src/kernel/pspamctrl.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/kernel/Makefile.am b/src/kernel/Makefile.am index 6948ea3af1..774a66b1eb 100644 --- a/src/kernel/Makefile.am +++ b/src/kernel/Makefile.am @@ -72,7 +72,8 @@ libpspkernelinclude_HEADERS = \ pspexception.h \ pspsysclib.h \ pspimpose_driver.h \ - pspinit.h \ + pspinit.h \ + pspamctrl.h \ pspaudiorouting.h lib_LIBRARIES = libpspkernel.a diff --git a/src/kernel/pspamctrl.h b/src/kernel/pspamctrl.h index 3e482ee6d7..8cdccc5142 100644 --- a/src/kernel/pspamctrl.h +++ b/src/kernel/pspamctrl.h @@ -10,8 +10,8 @@ * TODO: Contribute this header to PSPSDK */ -#ifndef AM_CTRL_H -#define AM_CTRL_H +#ifndef _PSP_AM_CTRL_H +#define _PSP_AM_CTRL_H #include @@ -74,4 +74,4 @@ int sceDrmBBCipherFinal(SceCipherKey *cipher_key); } #endif // __cplusplus -#endif // AM_CTRL_H \ No newline at end of file +#endif // AM_CTRL_H From 1735f894b96ea1cc44fb5bb5b1c3cc83c9ef8e18 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 12:43:21 +0100 Subject: [PATCH 4/9] fix build --- src/kernel/psploadcore.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kernel/psploadcore.h b/src/kernel/psploadcore.h index 37224a186d..f3a2938d71 100644 --- a/src/kernel/psploadcore.h +++ b/src/kernel/psploadcore.h @@ -15,6 +15,7 @@ #define PSPLOADCORE_H #include +#include /** @defgroup LoadCore Interface to the LoadCoreForKernel library. */ From d120960b79fe86192b998782016617ac894878aa Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 12:48:28 +0100 Subject: [PATCH 5/9] cleanup/fix --- src/kernel/psploadcore.h | 3 +++ src/sdk/modulemgr_patches.c | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/kernel/psploadcore.h b/src/kernel/psploadcore.h index f3a2938d71..850a13a486 100644 --- a/src/kernel/psploadcore.h +++ b/src/kernel/psploadcore.h @@ -430,6 +430,9 @@ int sceKernelProbeExecutableObject(void *buf, SceLoadCoreExecFileInfo *execInfo) */ int sceKernelGetModuleIdListForKernel(SceUID *mod_id_list, u32 size, u32 *mod_count, u32 user_mods_only); + +int sceKernelCheckPspConfig(void *buf, int size, int flag); + /**@}*/ #ifdef __cplusplus diff --git a/src/sdk/modulemgr_patches.c b/src/sdk/modulemgr_patches.c index e34dd3e426..189217b775 100644 --- a/src/sdk/modulemgr_patches.c +++ b/src/sdk/modulemgr_patches.c @@ -77,16 +77,12 @@ int pspSdkInstallNoDeviceCheckPatch(void) #define LOAD_EXEC_PLAIN_CHECK 0x4000B000 /* mfc0 *, $22 */ #define LOAD_EXEC_PLAIN_PATCH 0x34000001 /* li *, 1 */ - -extern u32 sceKernelProbeExecutableObject; -extern u32 sceKernelCheckPspConfig; - int pspSdkInstallNoPlainModuleCheckPatch(void) { u32 *addr; int i; - addr = (u32*) (0x80000000 | ((sceKernelProbeExecutableObject & 0x03FFFFFF) << 2)); + addr = (u32*) (0x80000000 | (((u32)sceKernelProbeExecutableObject & 0x03FFFFFF) << 2)); //printf("sceKernelProbeExecutableObject %p\n", addr); for(i = 0; i < 100; i++) { @@ -97,7 +93,7 @@ int pspSdkInstallNoPlainModuleCheckPatch(void) } } - addr = (u32*) (0x80000000 | ((sceKernelCheckPspConfig & 0x03FFFFFF) << 2)); + addr = (u32*) (0x80000000 | (((u32)sceKernelCheckPspConfig & 0x03FFFFFF) << 2)); //printf("sceCheckPspConfig %p\n", addr); for(i = 0; i < 100; i++) { From 45c671e61d34d86cec9c28a4dd1b397b8916b922 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 12:55:37 +0100 Subject: [PATCH 6/9] refacotr/fix --- src/samples/debug/prxdecrypt/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/samples/debug/prxdecrypt/main.c b/src/samples/debug/prxdecrypt/main.c index 44ec2be564..2957570b9b 100644 --- a/src/samples/debug/prxdecrypt/main.c +++ b/src/samples/debug/prxdecrypt/main.c @@ -60,9 +60,6 @@ int SetupCallbacks(void) return thid; } -/* ptr is a pointer to the file to decrypt, check is undocumented, look at decrypt_file to see how to use */ -int sceKernelCheckExecFile(void *ptr, void *check); - char g_data[0x400000] __attribute__((aligned(64))); char g_decrypt_buf[0x400000] __attribute__((aligned(64))); @@ -80,20 +77,20 @@ int extract_file(const char* name, const char* dstname) sceIoClose(fd); if(bytes_read > 0) { - u8 check[0x100]; + SceLoadCoreExecFileInfo check; u32 size; char *output; memset(check, 0, sizeof(check)); sceKernelCheckExecFile(g_data, check); /* Get size of data block */ - size = *(unsigned int *) (check+0x5C); + size = check->dec_size; /* Check if we managed to decrypt the file */ - if(*(unsigned short *)(check+0x5a) & 1) + if(check->mod_info_attribute & 1) { /* Set decrypt buffer pointer */ - *(unsigned int*)(check+0x24) = (unsigned int) g_decrypt_buf; + check->top_addr = g_decrypt_buf; sceKernelCheckExecFile(g_data, check); output = g_decrypt_buf; } From ef03b3b21559e3c969f6e73e061b1fb637ce6416 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 12:58:36 +0100 Subject: [PATCH 7/9] fix --- src/samples/debug/prxdecrypt/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/samples/debug/prxdecrypt/main.c b/src/samples/debug/prxdecrypt/main.c index 2957570b9b..9dff938779 100644 --- a/src/samples/debug/prxdecrypt/main.c +++ b/src/samples/debug/prxdecrypt/main.c @@ -82,16 +82,16 @@ int extract_file(const char* name, const char* dstname) char *output; memset(check, 0, sizeof(check)); - sceKernelCheckExecFile(g_data, check); + sceKernelCheckExecFile(g_data, &check); /* Get size of data block */ - size = check->dec_size; + size = check.dec_size; /* Check if we managed to decrypt the file */ - if(check->mod_info_attribute & 1) + if(check.mod_info_attribute & 1) { /* Set decrypt buffer pointer */ - check->top_addr = g_decrypt_buf; - sceKernelCheckExecFile(g_data, check); + check.top_addr = g_decrypt_buf; + sceKernelCheckExecFile(g_data, &check); output = g_decrypt_buf; } else From b8b57edb23cf30bb5ec97defef488fd05e1cec93 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 13:00:09 +0100 Subject: [PATCH 8/9] fix --- src/samples/debug/prxdecrypt/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/samples/debug/prxdecrypt/main.c b/src/samples/debug/prxdecrypt/main.c index 9dff938779..afdf41a81e 100644 --- a/src/samples/debug/prxdecrypt/main.c +++ b/src/samples/debug/prxdecrypt/main.c @@ -81,7 +81,7 @@ int extract_file(const char* name, const char* dstname) u32 size; char *output; - memset(check, 0, sizeof(check)); + memset(&check, 0, sizeof(check)); sceKernelCheckExecFile(g_data, &check); /* Get size of data block */ size = check.dec_size; From 4bedc48754866a819262e4dbc081e41e8b7ba2a4 Mon Sep 17 00:00:00 2001 From: JoseAaronLopezGarcia Date: Sun, 11 Jan 2026 13:07:25 +0100 Subject: [PATCH 9/9] fix for compat --- src/kernel/pspsysmem_kernel.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/kernel/pspsysmem_kernel.h b/src/kernel/pspsysmem_kernel.h index e4d36a45be..3e7a3a0fab 100644 --- a/src/kernel/pspsysmem_kernel.h +++ b/src/kernel/pspsysmem_kernel.h @@ -64,18 +64,19 @@ typedef struct SceGameInfo { } SceGameInfo; /** Structure of a UID control block */ -struct SceUidControlBlock { - struct SceUidControlBlock *parent; - struct SceUidControlBlock *nextChild; - struct SceUidControlBlock *type; //(0x8) +struct _uidControlBlock { + struct _uidControlBlock *parent; + struct _uidControlBlock *nextChild; + struct _uidControlBlock *type; //(0x8) u32 UID; //(0xC) char *name; //(0x10) unsigned char unk; unsigned char size; // Size in words short attribute; - struct SceUidControlBlock *nextEntry; + struct _uidControlBlock *nextEntry; } __attribute__((packed)); -typedef struct SceUidControlBlock SceUidControlBlock; +typedef struct _uidControlBlock SceUidControlBlock; +typedef struct _uidControlBlock uidControlBlock; // for compat reasons /** * Query the parition information