initForKernel library: Added library code files into src/modulemgr and added its documentation in include/modulemgr_init.h

This commit is contained in:
Felix 2013-05-04 00:44:17 +02:00
parent 7dcc9eca88
commit 79b14ee97a
3 changed files with 490 additions and 23 deletions

View File

@ -7,8 +7,39 @@
#include "loadcore.h"
#include "loadexec_kernel.h"
/** @defgroup ModuleManager Module Manager
* Module Management.
*/
/** @defgroup InitForKernel Init For Kernel
* @ingroup ModuleManager
* The InitForKernel library.
* @{
*/
#ifndef MODULEMGR_INIT_H
#define MODULEMGR_INIT_H
/**
* Application types.
* The possible boot medium types for an executable.
*/
enum SceBootMediumType {
/** The executable was booted via Flash 0 (1, 2). */
SCE_INIT_BOOT_FLASH = 0,
/** The executable was booted via a Disc medium. */
SCE_INIT_BOOT_DISC = 0x20,
/** The executable was booted via a Game-sharing medium. */
SCE_INIT_BOOT_USBWLAN = 0x30,
/** The executable was booted via the Memory Stick medium. */
SCE_INIT_BOOT_MS = 0x40,
/** The executable was booted via an unknown medium. */
SCE_INIT_BOOT_EF = 0x50,
/** The executable was booted via Flash 3.*/
SCE_INIT_BOOT_FLASH3 = 0x80,
};
/**
* Application types of an executable.
*/
enum SceApplicationType {
/** The application is a VSH application (i.e. VSH modules). */
@ -23,49 +54,91 @@ enum SceApplicationType {
SCE_INIT_APPLICATION_APP = 0x400,
};
/**
* API types of an executable.
*/
enum SceInitApiType {
/** Unknown. */
SCE_INIT_APITYPE_UNK0x100 = 0x100,
/* User */
/** GAME EBOOT. */
SCE_INIT_APITYPE_GAME_EBOOT = 0x110,
/** GAME BOOT. */
SCE_INIT_APITYPE_GAME_BOOT = 0x111,
/** Emulated EBOOT Memory-Stick. */
SCE_INIT_APITYPE_EMU_EBOOT_MS = 0x112,
/** Emulated BOOT Memory-Stick. */
SCE_INIT_APITYPE_EMU_BOOT_MS = 0x113,
/** Emulated EBOOT EF. */
SCE_INIT_APITYPE_EMU_EBOOT_EF = 0x114,
/** Emulated BOOT EF. */
SCE_INIT_APITYPE_EMU_BOOT_EF = 0x115,
/* Kernel only */
/** NP-DRM Memory-Stick. */
SCE_INIT_APITYPE_NPDRM_MS = 0x116, /* Distributed programs and data through the Playstation Store. */
/** NP-DRM EF. */
SCE_INIT_APITYPE_NPDRM_EF = 0x118, /* NP-DRM: PlayStation Network Platform Digital Rights Management */
/** Executable on a disc. */
SCE_INIT_APITYPE_DISC = 0x120,
/** Updater executable on a disc.*/
SCE_INIT_APITYPE_DISC_UPDATER = 0x121,
/** Disc debugger. */
SCE_INIT_APITYPE_DISC_DEBUG = 0x122,
SCE_INIT_APITYPE_DISC_EMU_MS1 = 0x123, /* np9660 game */
/** NP-9660 game. */
SCE_INIT_APITYPE_DISC_EMU_MS1 = 0x123,
/** Unknown. */
SCE_INIT_APITYPE_DISC_EMU_MS2 = 0x124,
/** Unknown. */
SCE_INIT_APITYPE_DISC_EMU_EF1 = 0x125,
/** Unknown. */
SCE_INIT_APITYPE_DISC_EMU_EF2 = 0x126,
SCE_INIT_APITYPE_USBWLAN = 0x130, /* Game sharing */
/** Game-sharing executable. */
SCE_INIT_APITYPE_USBWLAN = 0x130,
/** Unknown. */
SCE_INIT_APITYPE_USBWLAN_DEBUG = 0x131,
/** Unknown. */
SCE_INIT_APITYPE_UNK = 0x132,
/** Unknown. */
SCE_INIT_APITYPE_UNK_DEBUG = 0x133,
/** Unknown. */
SCE_INIT_APITYPE_MS1 = 0x140,
/** Unknown. */
SCE_INIT_APITYPE_MS2 = 0x141,
/** Unknown. */
SCE_INIT_APITYPE_MS3 = 0x142,
SCE_INIT_APITYPE_MS4 = 0x143, /* comic reader */
SCE_INIT_APITYPE_MS5 = 0x144, /* pops */
/** Applications (i.e. Comic Reader) */
SCE_INIT_APITYPE_MS4 = 0x143,
/** Playstation One executable. */
SCE_INIT_APITYPE_MS5 = 0x144,
/** Unknown. */
SCE_INIT_APITYPE_MS6 = 0x145,
/** Unknown. */
SCE_INIT_APITYPE_EF1 = 0x151,
/** Unknown. */
SCE_INIT_APITYPE_EF2 = 0x152,
/** Unknown. */
SCE_INIT_APITYPE_EF3 = 0x153,
/** Unknown. */
SCE_INIT_APITYPE_EF4 = 0x154,
/** Unknown. */
SCE_INIT_APITYPE_EF5 = 0x155,
/** Unknown. */
SCE_INIT_APITYPE_EF6 = 0x156,
/** Unknown. */
SCE_INIT_APITYPE_UNK_GAME1 = 0x160,
/** Unknown. */
SCE_INIT_APITYPE_UNK_GAME2 = 0x161,
/** Unknown. */
SCE_INIT_APITYPE_MLNAPP_MS = 0x170,
/** Unknown. */
SCE_INIT_APITYPE_MLNAPP_EF = 0x171,
/** Unknown. */
SCE_INIT_APITYPE_KERNEL_1 = 0x200,
SCE_INIT_APITYPE_VSH_1 = 0x210, /* ExitGame */
SCE_INIT_APITYPE_VSH_2 = 0x220, /* ExitVSH */
/** Exit Game. */
SCE_INIT_APITYPE_VSH_1 = 0x210,
/** Exit VSH. */
SCE_INIT_APITYPE_VSH_2 = 0x220,
/** Kernel reboot. */
SCE_INIT_APITYPE_KERNEL_REBOOT = 0x300,
/** Debug. */
SCE_INIT_APITYPE_DEBUG = 0x420 /* doesn't start reboot */
};
@ -100,24 +173,38 @@ typedef struct {
s32 unk88;
/** The application type of the currently loaded module. One of ::SceApplicationType. */
u32 applicationType; //92
/** The number of power locks used by init. */
s32 numPowerLocks;
/** The number of power locks used by Init. */
s32 numPowerLocks; //96
/** The address of a memory protection block of type ::SCE_PROTECT_INFO_TYPE_PARAM_SFO. */
void *paramSfoBase; //100
/** The size of of the memory block pointed to by ::paramSfoBase. */
SceSize paramSfoSize; //104
/** Unknown. */
s32 lptSummary;
s32 lptSummary; //108
/** Pointer to boot callbacks of modules. */
SceBootCallback *bootCallbacks1;
/** Unknown. */
void *unk116;
SceBootCallback *bootCallbacks1; //112
/** The current boot callback 1 slot used to hold the registered boot callback. */
SceBootCallback *curBootCallback1; //116
/** Pointer to boot callbacks of modules. */
SceBootCallback *bootCallbacks2; //120
/** Unknown. */
void *unk124;
/** The current boot callback 2 slot used to hold the registered boot callback. */
SceBootCallback *curBootCallback2; //124
} SceInit;
/**
* Get the boot medium of the executable calling this function.
*
* @return The boot medium type. One of ::SceBootMediumType.
*/
s32 sceKernelBootFrom(void);
/**
* Get the boot medium of the executable calling this function. For PSP-GO only?
*
* @return The boot medium type. One of ::SceBootMediumType.
*/
s32 InitForKernel_9D33A110(void);
/**
* Get the application type of a module.
*
@ -132,13 +219,114 @@ s32 sceKernelApplicationType(void);
*/
s32 sceKernelInitApitype(void);
s32 sceKernelRegisterChunk(SceUID chunkId, int unk1);
/**
* Set a boot callback. Call this function during a module boot process.
*
* @param bootCBFunc The boot callback function to execute once the module has been loaded by the Init
* module.
* @param flag Defines the execute order of the callbacks. Pass 0 for earliest execution, 3 for latest.
* 1 and 2 are between these two. Pass 4 - 7 for execution after Init loaded all modules, again
* 4 is earliest, 7 is latest.
* @param status The returned status of bootCBFunc in case it was executed directly.
*
* @return SCE_ERROR_OK for directly executing the boot callback function. SCE_BOOT_CALLBACK_FUNCTION_QUEUED
* indicates boot callback function was enqueued into other existing boot callbacks and will be called
* when Init boots the rest of the system modules.
*/
u32 sceKernelSetInitCallback(SceKernelBootCallbackFunction bootCBFunc, u32 flag, s32 *status);
/**
* Disabled debug function.
*
* @return SCE_ERROR_OK.
*/
u32 sceKernelStartIntrLogging(void);
/**
* Disabled debug function.
*
* @return SCE_ERROR_OK.
*/
u32 sceKernelShowIntrHandlerInfo(void);
/**
* Disabled debug function.
*
* @return SCE_ERROR_OK.
*/
u32 sceKernelShowIntrMaskTime(void);
/**
* 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);
/**
* Get the file name of the currently booted executable.
*
* @return The file name.
*/
char *sceKernelInitFileName(void);
/**
* Get the disc image of the currently booted executable.
*
* @return The disc image. Return null if there is no disc image.
*/
void *sceKernelInitDiscImage(void);
/**
* Get information about a paramSfo block of a module to boot.
*
* @param size The size of the paramSfo block.
*
* @return A pointer to the head address of the paramSfo block.
*/
void *sceKernelInitParamSfo(SceSize *size);
/**
* Get the LPT summary. Unknown.
*
* @return The LPT summary of the system.
*/
s32 sceKernelInitLptSummary(void);
/**
* Get a chunk's memory block ID.
*
* @param chunkId The ID of the chunk which memory block ID you want to receive.
* Between 0 - 15.
*
* @return The memory block ID on success (greater than or equal to 0) or
* SCE_ERROR_KERNEL_ILLEGAL_CHUNK_ID.
*/
SceUID sceKernelGetChunk(SceUID chunkId);
s32 sceKernelBootFrom(void);
int sceKernelSetInitCallback(void *, int, int);
/**
* Register a chunk in the system.
*
* @param chunkId The ID of the chunk to hold the memory block ID. Between 0 - 15.
* @param blockId The memory block ID to register.
*
* @return The blockId stored into the chunk on success, otherwise
* SCE_ERROR_KERNEL_ILLEGAL_CHUNK_ID.
*/
SceUID sceKernelRegisterChunk(SceUID chunkId, SceUID blockId);
SceInit *sceKernelQueryInitCB(void); //InitForKernel_040C934B
void *InitForKernel_D83A9BD7(void *);
s32 InitForKernel_9D33A110(void);
/**
* Release a used chunk.
*
* @param chunkId The ID of the chunk to release. Between 0 -15.
*
* @return The new value of the chunk, typically -1, on success, otherwise
* SCE_ERROR_KERNEL_ILLEGAL_CHUNK_ID.
*/
SceUID sceKernelReleaseChunk(SceUID chunkId);
#endif /* MODULEMGR_INIT_H */
/** @} */

50
src/modulemgr/chunk.c Normal file
View File

@ -0,0 +1,50 @@
/* Copyright (C) 2011, 2012, 2013 The uOFW team
See the file COPYING for copying permission.
*/
#include <common_imp.h>
/* The total number of available chunks. */
#define INIT_NUM_CHUNKS (16)
/* The slot of the highest available chunk. */
#define INIT_MAX_CHUNK (INIT_NUM_CHUNKS - 1)
/* Indicates a chunk is currently not used by the system. */
#define INIT_CHUNK_NOT_USED (-1)
/* The group of chunks to be used by the system. */
s32 chunks[INIT_NUM_CHUNKS]; //0x00009A48
//sub_000086C0
static void ChunkInit(void)
{
u32 i;
for (i = 0; i < INIT_NUM_CHUNKS; i++)
chunks[i] = INIT_CHUNK_NOT_USED;
}
SceUID sceKernelGetChunk(SceUID chunkId)
{
if (chunkId < 0 || chunkId > INIT_MAX_CHUNK)
return SCE_ERROR_KERNEL_ILLEGAL_CHUNK_ID;
return chunks[chunkId];
}
SceUID sceKernelRegisterChunk(SceUID chunkId, SceUID blockId)
{
if (chunkId < 0 || chunkId > INIT_MAX_CHUNK)
return SCE_ERROR_KERNEL_ILLEGAL_CHUNK_ID;
chunks[chunkId] = blockId;
return blockId;
}
SceUID sceKernelReleaseChunk(SceUID chunkId)
{
if (chunkId < 0 || chunkId > INIT_MAX_CHUNK)
return SCE_ERROR_KERNEL_ILLEGAL_CHUNK_ID;
chunks[chunkId] = INIT_CHUNK_NOT_USED;
return INIT_CHUNK_NOT_USED;
}

229
src/modulemgr/init.c Normal file
View File

@ -0,0 +1,229 @@
/* Copyright (C) 2011, 2012, 2013 The uOFW team
See the file COPYING for copying permission.
*/
#include <common_imp.h>
#include <loadcore.h>
#include <modulemgr_init.h>
/*
* uofw/src/modulemgr/init.c
*
* init - InitForKernel library
*
* Its purpose s to provide information about an executable which is
* being launched, or which was recently launched, by the system. The
* information includes the API type of the executable, its application
* type, its file name, and the boot medium which was used to boot the
* executable.
*
* While originally placed inside the Init module, this library was later
* removed from it and implemented in the module manager module instead.
* This is done because InitForKernel is a resident library whereas the Init
* module isn't a resident module. To guarantee the availability of the
* exported InitForKernel functions, this library was moved to module manager,
* a resident module.
*/
SceInit g_init; //0x000099A0
u32 sceKernelBootFrom(void)
{
switch (g_init.apiType) {
case SCE_INIT_APITYPE_GAME_EBOOT: //0x00004D20
case SCE_INIT_APITYPE_GAME_BOOT:
case SCE_INIT_APITYPE_EMU_EBOOT_MS:
case SCE_INIT_APITYPE_EMU_BOOT_MS:
case SCE_INIT_APITYPE_EMU_EBOOT_EF:
case SCE_INIT_APITYPE_EMU_BOOT_EF:
case SCE_INIT_APITYPE_NPDRM_MS:
case 0x117:
case SCE_INIT_APITYPE_NPDRM_EF:
case 0x119:
case SCE_INIT_APITYPE_DISC:
case SCE_INIT_APITYPE_DISC_UPDATER:
case SCE_INIT_APITYPE_DISC_DEBUG:
case SCE_INIT_APITYPE_DISC_EMU_MS1:
case SCE_INIT_APITYPE_DISC_EMU_MS2:
case SCE_INIT_APITYPE_DISC_EMU_EF1:
case SCE_INIT_APITYPE_DISC_EMU_EF2:
case SCE_INIT_APITYPE_UNK_GAME1: //0x00004DD4
case SCE_INIT_APITYPE_UNK_GAME2:
case SCE_INIT_APITYPE_MLNAPP_MS: //0x00004DC8
case SCE_INIT_APITYPE_MLNAPP_EF:
return SCE_INIT_BOOT_DISC; //0x00004D20 | 0x00004D38
case SCE_INIT_APITYPE_USBWLAN:
case SCE_INIT_APITYPE_USBWLAN_DEBUG:
case 0x132:
case 0x133:
return SCE_INIT_BOOT_USBWLAN; //0x00004CFC
case SCE_INIT_APITYPE_MS1:
case SCE_INIT_APITYPE_MS2:
case SCE_INIT_APITYPE_MS3:
case SCE_INIT_APITYPE_MS5:
case SCE_INIT_APITYPE_MS6:
return SCE_INIT_BOOT_MS; //0x00004CE8 | 0x00004D50
case SCE_INIT_APITYPE_MS4:
char *fileName = sceKernelInitFileName(); //0x00004D58
if (strncmp(fileName, "flash3:", strlen("flash3:")) == 0) //0x00004D6C & 0x00004D7C
return SCE_INIT_BOOT_FLASH3;
return SCE_INIT_BOOT_MS;
case SCE_INIT_APITYPE_EF1:
case SCE_INIT_APITYPE_EF2:
case SCE_INIT_APITYPE_EF3:
case SCE_INIT_APITYPE_EF4:
case SCE_INIT_APITYPE_EF5:
case SCE_INIT_APITYPE_EF6:
return SCE_INIT_BOOT_EF; //0x00004D98
default:
return SCE_INIT_BOOT_FLASH;
}
}
//Subroutine InitForKernel_9D33A110 - Address 0x00004DDC
u32 InitForKernel_9D33A110(void)
{
switch (g_init.apiType) {
case SCE_INIT_APITYPE_GAME_EBOOT:
case SCE_INIT_APITYPE_GAME_BOOT:
case SCE_INIT_APITYPE_DISC:
case SCE_INIT_APITYPE_DISC_UPDATER:
case SCE_INIT_APITYPE_DISC_DEBUG: //0x00004E70
return SCE_INIT_BOOT_DISC; //0x00004E2C
case SCE_INIT_APITYPE_USBWLAN: //0x00004E9C
case SCE_INIT_APITYPE_USBWLAN_DEBUG:
case 0x132:
case 0x133:
return SCE_INIT_BOOT_USBWLAN;
case SCE_INIT_APITYPE_EMU_EBOOT_MS:
case SCE_INIT_APITYPE_EMU_BOOT_MS:
case SCE_INIT_APITYPE_NPDRM_MS: //0x00004E64
case 0x117:
case SCE_INIT_APITYPE_DISC_EMU_MS1: //0x00004DF8
case SCE_INIT_APITYPE_DISC_EMU_MS2:
case SCE_INIT_APITYPE_MS1: //0x00004EC4
case SCE_INIT_APITYPE_MS2:
case SCE_INIT_APITYPE_MS3:
case SCE_INIT_APITYPE_MS5: //0x00004EEC
case SCE_INIT_APITYPE_MS6:
case SCE_INIT_APITYPE_MLNAPP_MS: //0x00004F10
return SCE_INIT_BOOT_MS; //0x00004E30
case SCE_INIT_APITYPE_MS4:
char *fileName = sceKernelInitFileName(); //0x00004F14
if (strncmp(fileName, "flash3:", strlen("flash3:")) == 0) //0x00004F28 & 0x00004F38
return SCE_INIT_BOOT_FLASH3;
return SCE_INIT_BOOT_MS;
case SCE_INIT_APITYPE_EMU_EBOOT_EF:
case SCE_INIT_APITYPE_EMU_BOOT_EF:
case SCE_INIT_APITYPE_NPDRM_EF:
case 0x119:
case SCE_INIT_APITYPE_DISC_EMU_EF1: //0x00004EB0
case SCE_INIT_APITYPE_DISC_EMU_EF2:
case SCE_INIT_APITYPE_EF1: //0x00004ED4
case SCE_INIT_APITYPE_EF2:
case SCE_INIT_APITYPE_EF3:
case SCE_INIT_APITYPE_EF4:
case SCE_INIT_APITYPE_EF5:
case SCE_INIT_APITYPE_EF6:
case SCE_INIT_APITYPE_MLNAPP_EF: //0x00004EF0
return SCE_INIT_BOOT_EF; //0x00004E10
default:
return SCE_INIT_BOOT_FLASH;
}
}
char *sceKernelInitFileName(void)
{
return (char *)g_init.fileModAddr;
}
u32 sceKernelSetInitCallback(SceKernelBootCallbackFunction bootCBFunc, u32 flag, s32 *status)
{
s32 result;
SceBootCallback *curBootCallback;
if (flag < 4) { //0x00004F64
if (g_init.bootCallbacks1 == NULL) { //0x00004F78
result = bootCBFunc(1, 0, NULL); //0x00004FC8
if (status != NULL) //0x00004FD0
*status = result;
return SCE_ERROR_OK;
}
curBootCallback = g_init.curBootCallback1; //0x00004F80
curBootCallback->bootCBFunc = (flag & 0x3) + bootCBFunc; //0x00004F90
g_init.curBootCallback1 += 1; //0x00004FA0
g_init.curBootCallback1->bootCBFunc = NULL; //0x00004FA8
} else {
if (g_init.bootCallbacks2 == NULL) { //0x00004FEC
result = bootCBFunc(1, 0, NULL); //0x00004FC8
if (status != NULL) //0x00004FD0
*status = result;
return SCE_ERROR_OK;
}
curBootCallback = g_init.curBootCallback2; //0x00004FF4
curBootCallback->bootCBFunc = (flag & 0x3) + bootCBFunc; //0x00005004
g_init.curBootCallback2 += 1; //0x00005010
g_init.curBootCallback2->bootCBFunc = NULL; //0x00004FA8
}
curBootCallback->gp = sceKernelGetModuleGPByAddressForKernel(bootCBFunc); //0x00004F8C & 0x00004FA4
return SCE_BOOT_CALLBACK_FUNCTION_QUEUED;
}
u32 sceKernelStartIntrLogging(void)
{
return SCE_ERROR_OK;
}
u32 sceKernelShowIntrHandlerInfo(void)
{
return SCE_ERROR_OK;
}
u32 sceKernelShowIntrMaskTime(void)
{
return SCE_ERROR_OK;
}
SceInit *sceKernelQueryInitCB(void)
{
return g_init;
}
s32 sceKernelInitApitype(void)
{
return g_init.apiType;
}
s32 sceKernelApplicationType(void)
{
return g_init.applicationType;
}
void *sceKernelInitDiscImage(void)
{
return g_init.discModAddr;
}
s32 sceKernelInitLptSummary(void)
{
return g_init.lptSummary;
}
void *sceKernelInitParamSfo(SceSize *size)
{
if (size != NULL)
*size = g_init.paramSfoSize;
return g_init.paramSfoBase;
}