Thanks Torch.
Here's the code, I'm trying to follow your advice:
Code: Select all
#include <pspsdk.h>
#include <pspkernel.h>
#include <string.h>
#include <stdio.h>
PSP_MODULE_INFO("nanofe", 0x1007, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
int plugin_thread (SceSize argc, void* argp)
{
char buf[100];
SceUID fd = sceIoOpen ("host0:/plugin_pspain.dat",
PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
if (fd < 0)
return -1;
SceKernelLMOption option;
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = 2;
option.mpiddata = 2;
option.position = 0;
option.access = 1;
char args[2048];
u32 k1 = pspSdkSetK1(0);
//SceUID (* sceKernelLoadModule_k)(const char *path, int flags, SceKernelLMOption *option);
//sceKernelLoadModule_k = (void *)FindProc("sceModuleManager", "ModuleMgrForKernel", 0x977de386);
sceKernelDelayThread(1000 * 1000);
while(!sceKernelFindModuleByName("sceKernelLibrary")) sceKernelDelayThread(100 * 1000);
SceUID modid = sceKernelLoadModule("ms0:/PSP/GAME/meminfo-prx-large/hello.prx", 0, NULL);
sceIoWrite (fd, "modid=", 7);
sprintf(buf, "%p\n", modid);
sceIoWrite (fd, buf, 100);
int mresult;
sceKernelStartModule(modid, 0, args, &mresult, NULL);
sceIoWrite (fd, "end\n", 4);
pspSdkSetK1(k1);
sceIoClose (fd);
// Completely free all memory
sceKernelSelfStopUnloadModule(1, 0, NULL);
return 0;
}
int
module_start (SceSize argc, void* argp)
{
u32 func = 0x80000000 | (u32)plugin_thread;
SceUID thread = sceKernelCreateThread("plugin_thread",
(void*)func, 0x30, 0x10000, 0, NULL);
if (thread >= 0) {
sceKernelStartThread (thread, argc, argp);
}
return 0;
}
and Makefile:
Code: Select all
PSP_LARGE_MEMORY=1
TARGET = plugin
OBJS = module.o
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LDFLAGS += -mno-crt0 -nostartfiles
BUILD_PRX=1
PSP_FW_VERSION=303
#USE_PSPSDK_LIBC=1
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = plugin
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Torch wrote:First of all when making a kernel module always use USE_KERNEL_LIBS=1 and USE_KERNEL_LIBC=1 or you'll end up with bloated code like 100KiB for a kernel module which would normally be 2KiB.
Hmm, I get a 72kB .prx.
Torch wrote:And you're ideally not supposed to use user functions from kernel mode either. Find a way without the user functions.
Well I don't have a clue about loading the module otherwise. Any lead?
Torch wrote:
Regarding your problem:
The cwd may not be set. Give the full path for hello.prx
It doesn't help, but in fact even specifying "blah" will return 0x80020149.
The &options struct may not be set properly. Anyway it's not necessary for simple loading so make it NULL..
Neither :/
It may not work from inside module_start and some non-thread contexts. Make sure you are calling it from a thread.
It's in a thread already.