Importing (ctrl) functions from KernelMode Prx

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
NintendoBoy13
Posts: 6
Joined: Mon Jan 18, 2010 8:41 am

Importing (ctrl) functions from KernelMode Prx

Post by NintendoBoy13 »

So, I'm trying to use kernelmode specific buttons in usermode on my psp in 5.xx kernel, and I am having many problems. I know that I have to import from a kernelmode prx ( to my usermode eboot.pbp) but it's not working. I will supply everything that I have done up until now. Btw this is just a test to get the buttons working.

What's happening is this :When I load my prx, the psp freezes, but when the prx is NOT loaded, none of the buttons I want (WLAN_UP, NOTE, SCREEN, HOME, VOL+, and VOL-)... ( I'm not sure if that's because the prx is not loading, or my code is incorrect, most likely is my code is incorrect ). Also no other buttons will work ( I tried with the cross button ).

KernelModePrx Stuff:
main.c :

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
 
PSP_MODULE_INFO&#40;"buttons", 0x1000, 1, 1&#41;;
PSP_HEAP_SIZE_KB&#40;32&#41;;
PSP_NO_CREATE_MAIN_THREAD&#40;&#41;;
 
unsigned int getbuttons&#40;&#41;
&#123;
u32 k1 = pspSdkGetK1&#40;&#41;;
 
pspSdkSetK1&#40;0&#41;;
 
SceCtrlData pad;
 
sceCtrlPeekBufferPositive&#40;&pad, 1&#41;;
 
pspSdkSetK1&#40;k1&#41;;

return pad.Buttons;
&#125;
 
int module_start&#40;&#41;
&#123;
return 0;
&#125;
 
int module_stop&#40;&#41;
&#123;
return 0;
&#125;
makefile :

Code: Select all

TARGET = test
OBJS = main.o


INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

BUILD_PRX = 1
PRX_EXPORTS = kstuff.exp 
 
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1 
 
LIBDIR =
LDFLAGS = -mno-ctr0 -nostartfiles
LIBS=$&#40;STDLIBS&#41;$&#40;YOURLIBS&#41;

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
kstuff.exp ( my exports file ) :

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END

# Export our function
PSP_EXPORT_START&#40;buttons, 0, 0x1001&#41;
PSP_EXPORT_FUNC_HASH&#40;getbuttons&#41;


PSP_EXPORT_END

PSP_END_EXPORTS
Then I build my prx ( namely test.prx ), and I issue this command in my cygwin bash shell : psp-build-exports -s kstuff.exp

Then I grab that .S file (buttons.S), here it is :

Code: Select all

	.set noreorder

#include "pspstub.s"

	STUB_START "buttons",0x10090000,0x00010005
	STUB_FUNC  0xE2D9AF83,getbuttons
	STUB_END
Next I grab my test.prx and my buttons.S and I add them to my Usermode .pbp source folder, and here is everything from that source :
main.c

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>

PSP_MODULE_INFO&#40;"button", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40; PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU &#41;;

unsigned int getbuttons&#40;&#41;;

int main&#40;&#41;
&#123;

pspDebugScreenInit&#40;&#41;;
//pspSdkLoadStartModule&#40;"test.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
//Taken out for now, seems to be freezing my psp...



pspDebugScreenPrintf&#40;"Well it didn't freeze before the while loop...\n"&#41;;

while&#40;1&#41;
&#123;
	unsigned int kernelButtons = getbuttons&#40;&#41;;

	if&#40;kernelButtons & PSP_CTRL_HOME&#41;
	&#123;
		pspDebugScreenPrintf&#40;"You are pressing home\n"&#41;;
	&#125;

	if&#40;kernelButtons & PSP_CTRL_VOLUP&#41;
	&#123;
		pspDebugScreenPrintf&#40;"You are pressing vol+\n"&#41;;
	&#125;

	if&#40;kernelButtons & PSP_CTRL_CROSS&#41;
	&#123;
		pspDebugScreenPrintf&#40;"You are pressing cross\n"&#41;;
	&#125;

&#125;


sceKernelSleepThread&#40;&#41;;
return 0;

&#125;
makefile :

Code: Select all

TARGET = Kmode_Buttons
OBJS = main.o buttons.o

BUILD_PRX = 1
 
INCDIR =
CFLAGS = -G4 -Wall -O2 
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

 
LIBDIR =
LDFLAGS =
STDLIBS=  -losl -lpng -lz \
  -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspgum -lpspaudiolib -lpspaudio -lm -lpspaudiocodec -ljpeg -lpspmpeg -lpspdebug -lpspdisplay -lpspge -lpspctrl -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lpsphprm -lpspusb -lpspusbstor
LIBS=$&#40;STDLIBS&#41;$&#40;YOURLIBS&#41;
 
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = KmodeButtons
#PSP_EBOOT_ICON = resources/icon0.png
#PSP_EBOOT_PIC1 = resources/pic1.png

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

When everything is finished I grab the EBOOT.PBP and the test.prx and put them in a folder, and put that in ms0:/PSP/GAME/FOLDERNAME, and it does as what I explained above.
Last edited by NintendoBoy13 on Tue Jan 19, 2010 9:53 am, edited 2 times in total.
Yes I can, but then again why should I?
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

Your eboot needs to be built as a prx to load a kernel module.
Also you should know that commenting out loading the prx wouldn't solve your problem.
NintendoBoy13
Posts: 6
Joined: Mon Jan 18, 2010 8:41 am

Post by NintendoBoy13 »

psPea wrote:Your eboot needs to be built as a prx to load a kernel module.
Also you should know that commenting out loading the prx wouldn't solve your problem.
Thanks I'll add that to the makefile. Also I know that it wouldn't solve it, was leaving it out to do some testing.
Yes I can, but then again why should I?
NintendoBoy13
Posts: 6
Joined: Mon Jan 18, 2010 8:41 am

Post by NintendoBoy13 »

Edit : Fixed thanks to InsertWittyName :) Problem was one digit in the exp file.
Yes I can, but then again why should I?
Davee
Posts: 43
Joined: Mon Jun 22, 2009 3:58 am

Post by Davee »

For anyone that gets this error in the future, the mistake was in

"PSP_EXPORT_START(buttons, 0, 0x1001) "

0x1001 signifies same level exporting, so a kernel PRX will export to kernel mode.

0x4001 however, is for kernel prx's wishing to export to user mode (via syscall).
NintendoBoy13
Posts: 6
Joined: Mon Jan 18, 2010 8:41 am

Post by NintendoBoy13 »

psPea wrote:Your eboot needs to be built as a prx to load a kernel module.
Also you should know that commenting out loading the prx wouldn't solve your problem.
As a side note this is not true. I successfully loaded the prx and used it's functions without building as a prx.
Yes I can, but then again why should I?
Post Reply