forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Importing (ctrl) functions from KernelMode Prx

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
NintendoBoy13



Joined: 18 Jan 2010
Posts: 6

PostPosted: Mon Jan 18, 2010 8:58 am    Post subject: Importing (ctrl) functions from KernelMode Prx Reply with quote

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:
#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
 
PSP_MODULE_INFO("buttons", 0x1000, 1, 1);
PSP_HEAP_SIZE_KB(32);
PSP_NO_CREATE_MAIN_THREAD();
 
unsigned int getbuttons()
{
u32 k1 = pspSdkGetK1();
 
pspSdkSetK1(0);
 
SceCtrlData pad;
 
sceCtrlPeekBufferPositive(&pad, 1);
 
pspSdkSetK1(k1);

return pad.Buttons;
}
 
int module_start()
{
return 0;
}
 
int module_stop()
{
return 0;
}


makefile :

Code:
TARGET = test
OBJS = main.o


INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

BUILD_PRX = 1
PRX_EXPORTS = kstuff.exp
 
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1
 
LIBDIR =
LDFLAGS = -mno-ctr0 -nostartfiles
LIBS=$(STDLIBS)$(YOURLIBS)

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


kstuff.exp ( my exports file ) :

Code:
# 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

# Export our function
PSP_EXPORT_START(buttons, 0, 0x1001)
PSP_EXPORT_FUNC_HASH(getbuttons)


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:
   .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:
#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>

PSP_MODULE_INFO("button", 0, 1, 1);
PSP_MAIN_THREAD_ATTR( PSP_THREAD_ATTR_USER | PSP_THREAD_ATTR_VFPU );

unsigned int getbuttons();

int main()
{

pspDebugScreenInit();
//pspSdkLoadStartModule("test.prx", PSP_MEMORY_PARTITION_KERNEL);
//Taken out for now, seems to be freezing my psp...



pspDebugScreenPrintf("Well it didn't freeze before the while loop...\n");

while(1)
{
   unsigned int kernelButtons = getbuttons();

   if(kernelButtons & PSP_CTRL_HOME)
   {
      pspDebugScreenPrintf("You are pressing home\n");
   }

   if(kernelButtons & PSP_CTRL_VOLUP)
   {
      pspDebugScreenPrintf("You are pressing vol+\n");
   }

   if(kernelButtons & PSP_CTRL_CROSS)
   {
      pspDebugScreenPrintf("You are pressing cross\n");
   }

}


sceKernelSleepThread();
return 0;

}


makefile :

Code:
TARGET = Kmode_Buttons
OBJS = main.o buttons.o

BUILD_PRX = 1
 
INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

 
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=$(STDLIBS)$(YOURLIBS)
 
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = KmodeButtons
#PSP_EBOOT_ICON = resources/icon0.png
#PSP_EBOOT_PIC1 = resources/pic1.png

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/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.
_________________
Yes I can, but then again why should I?


Last edited by NintendoBoy13 on Tue Jan 19, 2010 9:53 am; edited 2 times in total
Back to top
View user's profile Send private message
psPea



Joined: 01 Sep 2007
Posts: 64

PostPosted: Mon Jan 18, 2010 4:55 pm    Post subject: Reply with quote

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.
_________________
Click ME!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
NintendoBoy13



Joined: 18 Jan 2010
Posts: 6

PostPosted: Mon Jan 18, 2010 5:20 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
NintendoBoy13



Joined: 18 Jan 2010
Posts: 6

PostPosted: Mon Jan 18, 2010 6:05 pm    Post subject: Reply with quote

Edit : Fixed thanks to InsertWittyName :) Problem was one digit in the exp file.
_________________
Yes I can, but then again why should I?
Back to top
View user's profile Send private message
Davee



Joined: 22 Jun 2009
Posts: 59

PostPosted: Fri Jan 22, 2010 8:45 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
NintendoBoy13



Joined: 18 Jan 2010
Posts: 6

PostPosted: Sat Jan 23, 2010 9:57 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group