I am doing some exercises with prx and kernel mode and I am stuck on on the following issue:
I want to read the name of all the files and directories in flash0: and writes them in a file (dir.txt) which is on ms0:.
a) If I run the eboot in user mode I can't see what is in kd/ etc .. (which is normal, I guess, due to firmware protection)
b) If I run the eboot in kernel mode I can see everything,
But setting the eboot in kernel mode is not very elegant. So I decided to put the functions that should run in kernel mode in a prx (in kernel mode) and call them from my eboot which is in user mode.
It runs, I can have my dir.txt but it acts as if I were in case a), I can't see what's in kd/...
I probably missing something which is evident ....
Any help would be appreciated.
Here are my files:
the prx part:
main.c :
Code: Select all
#include <pspkernel.h>
#include <pspmodulemgr_kernel.h>
#include <pspsdk.h>
#include <pspiofilemgr.h>
#include <pspiofilemgr_dirent.h>
#include <string.h>
/* Define the module info section */
#define MY_HOMEBREW_MAJOR_VERSION 0
#define MY_HOMEBREW_MINOR_VERSION 42
PSP_MODULE_INFO("myprx", PSP_MODULE_KERNEL, MY_HOMEBREW_MAJOR_VERSION, MY_HOMEBREW_MINOR_VERSION);
PSP_MAIN_THREAD_ATTR(0);
//those two functions are madatory !
int module_start(SceSize args, void *argp)
{
return 0;
}
int module_stop()
{
return 0;
}
//the functions i want to run in kernel mode
SceUID EXTsceIoDopen( const char * name)
{
SceUID ret;
u32 k1;
k1 = pspSdkSetK1(0);
ret = sceIoDopen(name);
pspSdkSetK1(k1);
return ret;
}
int EXTsceIoDread(SceUID uid, SceIoDirent *pDirEnt)
{
SceUID ret;
u32 k1;
k1 = pspSdkSetK1(0);
ret = sceIoDread(uid, pDirEnt);
pspSdkSetK1(k1);
return ret;
}
int EXTsceIoGetstat( const char *name, SceIoStat *pD_stat)
{
SceUID ret;
u32 k1;
k1 = pspSdkSetK1(0);
ret = sceIoGetstat( name, pD_stat);
pspSdkSetK1(k1);
return ret;
}
int EXTsceIoDclose( SceUID uid)
{
SceUID ret;
u32 k1;
k1 = pspSdkSetK1(0);
ret = sceIoDclose(uid);
pspSdkSetK1(k1);
return ret;
}
prx makefile :
Code: Select all
TARGET = myprx
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
PSP_FW_VERSION=371
BUILD_PRX = 1
PRX_EXPORTS = myprx.exp
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1
LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS =
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
(export file) myprx.exp:
Code: Select all
# Define the exports for the prx
PSP_BEGIN_EXPORTS
# These four lines are mandatory (although you can add other functions like module_stop)
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END
PSP_EXPORT_START(myprx, 0, 0x4001)
PSP_EXPORT_FUNC(EXTsceIoDopen)
PSP_EXPORT_FUNC(EXTsceIoDread)
PSP_EXPORT_FUNC(EXTsceIoGetstat)
PSP_EXPORT_FUNC(EXTsceIoDclose)
PSP_EXPORT_END
PSP_END_EXPORTS
the loader part
main.c:
Code: Select all
#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>
#include <pspsdk.h>
/* Define the module info section */
#define MY_HOMEBREW_MAJOR_VERSION 0
#define MY_HOMEBREW_MINOR_VERSION 42
PSP_MODULE_INFO("myEBOOT", PSP_MODULE_USER, MY_HOMEBREW_MAJOR_VERSION, MY_HOMEBREW_MINOR_VERSION);
//PSP_HEAP_SIZE_MAX();
PSP_HEAP_SIZE_KB( 8192);
/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
int sceInit(void);
/* here are the functions that have been put in the prx*/
SceUID EXTsceIoDopen( const char * name);
int EXTsceIoDread(SceUID uid, SceIoDirent *pDirEnt);
int EXTsceIoGetstat( const char *name, SceIoStat *pD_stat);
int EXTsceIoDclose( SceUID uid);
/* the real main function (recursive) which loads the files and directories name then write them it a file*/
void printDirectory( const char *name, SceUID hdDir)
{
SceUID uid;
struct SceIoDirent dirEnt;
SceIoStat d_stat;
char fullname[512];
//we open the "directory"
uid = EXTsceIoDopen(name);
dirEnt.d_private=NULL; //if not done the at the first use of dirEnt in sceIoDread => crash
//2) for all the enties
while(EXTsceIoDread(uid, &dirEnt)>0)
{
//create the full name (tha absolute name)
strcpy( fullname, name);
strcat( fullname,"/");
strcat( fullname, dirEnt.d_name);
//we write the name of the entry in the file
sceIoWrite( hdDir, fullname, strlen( fullname));
sceIoWrite( hdDir,"\r\n", 2); //to be able to read the file on windows
//we laod the info on the file, to check if it's a directory, if so we do a recursive call to printDirectory
//in order to explore the directory
EXTsceIoGetstat( fullname, &d_stat);//we load the file information
if( (FIO_S_IFDIR & d_stat.st_mode) && (strcmp(dirEnt.d_name,".")!=0)&& (strcmp(dirEnt.d_name,"..")!=0))
{
printDirectory( fullname, hdDir); //recursive call
}
}
//we close the directory
EXTsceIoDclose(uid);
}
int main( void)
{
//System initilization
sceInit(); //set exit callback
pspDebugScreenInit(); //init the screen in a special mode that allow us to print on it easily
//reset the screen
pspDebugScreenClear();
SceUID mod = pspSdkLoadStartModule("myprx.prx", PSP_MEMORY_PARTITION_KERNEL);
if (mod < 0)
{
pspDebugScreenPrintf("Error 0x%08X loading/starting myprx.prx.\n", mod);
}
else
{
//we open (create) the file dir.txt, that will contain the list of the dirs and files of flash0
SceUID hdDir = sceIoOpen("ms0:/PSP/GAME/test/dir.txt", PSP_O_RDWR | PSP_O_CREAT| PSP_O_TRUNC, 0777);
if(hdDir <=0)
{
pspDebugScreenPuts("Can't create ms0:/PSP/GAME/test/dir.txt");
}
else
{
//Prints the name of all files and directories located at the root of flash0:
printDirectory("flash0:/", hdDir);
sceIoClose(hdDir);
}
pspDebugScreenPuts("End !!");
}
sceKernelSleepThread(); //suspend the system, waiting for the user to press "home" key
return 0;
}
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return (int)0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int sceInit(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
makefile:
Code: Select all
TARGET = myEBOOT
PSP_FW_VERSION = 371
OBJS = myprx.o main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
LIBDIR =
LIBS =
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = "TEST"
PSP_EBOOT_ICON=NULL
PSP_EBOOT_UNKPNG=NULL
PSP_EBOOT_PIC1=NULL
PSP_EBOOT_SND0=NULL
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak