| View previous topic :: View next topic |
| Author |
Message |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sun Nov 02, 2008 6:05 am Post subject: Exporting functions from user mode prx to kernel mode prx |
|
|
Is it possible or not? I have tried multiple ways and I can't seem to get it working :/
I really need to export a function from user mode as the kernel LIBC is not the same as the user LIBC and some of the functions I Need are not included in the kernel LIBC.
I have two options, create my own functions or export the function from user mode. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Sun Nov 02, 2008 10:30 pm Post subject: |
|
|
I know that 0x0001 attrib is for export a function from kernel to kernel or user to user, and 0x4001 for export kernel to user!
I've never tried to export a function from a user to a kernel prx module...
Have you tried with these flags? _________________ Get Xplora! |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sun Nov 02, 2008 10:44 pm Post subject: |
|
|
Where do I use them?
The Only place I think of is the mode attribute _________________
Upgrade your PSP |
|
| Back to top |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
Posted: Sun Nov 02, 2008 10:51 pm Post subject: |
|
|
in the exports file.
PSP_EXPORT_START(libName, 0, 0x4001)
the 3rd param is where to put your flags _________________ Ciao! from Italy |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Sun Nov 02, 2008 11:34 pm Post subject: |
|
|
| phobox wrote: | in the exports file.
PSP_EXPORT_START(libName, 0, 0x4001)
the 3rd param is where to put your flags |
Thats only useful if he wants to use functions exported by a PRX which he made. It looks like he wants to call other sce user mode functions from the firmware PRX, from inside a kernel PRX.
I think the only way will be to use setddrmemoryprotection function to make the kernel memory as user mode, and then call your user mode function by getting the function address or something. You can't use any kernel function in that time. I'm just guessing, I'm no expert at this.
Generally it only causes various problems. User mode function should be called from user mode prx only, thats it. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sun Nov 02, 2008 11:36 pm Post subject: |
|
|
oops forgot about that.
Yeah it's currently set for kernel to user.
so 0x0001 is kernel > kernel and 0x4001 is kernel -> user, then 0x4000 should be user -> user ? tried it and did not work either
EDit:
torch I am exporting from a prx i made to another prx I made :) _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Nov 03, 2008 12:00 am Post subject: |
|
|
I guess you could do it like this:
Code the original function in a kernel PRX as kernel to kernel export. Then make a wrapper function for it in the same PRX as a kernel to user export.
Then you can call the kernel version from other kernel PRXs, as well as the user wrapper from other user PRXs.
Its impossible to directly call a kernel function from a user prx, so I assume the reverse is true as well. When you have a kernel to user export, it uses syscalls. I don't know if user to kernel export is possible like the way you want.. |
|
| Back to top |
|
 |
phobox
Joined: 24 Mar 2008 Posts: 140
|
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Nov 03, 2008 12:13 am Post subject: |
|
|
0x0001 means direct jump to address. It works for user to user or kernel to kernel I think.
0x4001 means use syscall. AFAIK this is only for calling a kernel to user export from a user prx. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 12:47 am Post subject: |
|
|
I think you haven't read my first pos torch.
kernel LIBC does not have fopen, fwrite, fclose, fprintf, etc and I need them for my function as the library I am using makes of those functions.
The only way to use that function is exporting from a user prx to a kernel prx (which needs kernel mode to work).
Of course I can the user prx to execute the function when it gets loaded but that's not what I want.
@phobox I already read that file some time ago :) but of course I don't remember everything _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Nov 03, 2008 1:43 am Post subject: |
|
|
Does it compiles with USE_KERNEL_LIBC=0 ? That might provide the functions you need.
Are you writing a plugin or an EBOOT?
You only need to worry about user modules if you are writing a plugin.
If you are writing an EBOOT, the correct way IS to have the function executed from a user module. All your main working code should be user mode. You only need to load a kernel prx to do, well, kernel stuff.
If you are writing a plugin however, then you have no choice but to use various tricks to get user mode code working.
Have the user module continuously 'poll' the kernel prx for various commands. I mean export a function get_commands() from your kernel prx. The user prx should keep calling this function to see if the kernel prx needs something done. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 1:55 am Post subject: |
|
|
I am writing a prx of course, otherwise I would not need to export a user function from a user prx and I could do it a from a EBOOT.PBP (as it must be user mode to be executed).
graphics.prx is the user prx.
patchexit_driver.prx is the kernel prx.
patchexit_driver.prx works perfectly since NervOS 2.1 (it's a shell) but now for 2.3 I am working on some new features and I need patchexit_driver.prx to call a user mode function.
patchexit_driver.prx only works with KERNEL_LIBC and KERNEL_LIBS set to 1.
This means I cannot use the stdio.h functions. I have already created the stdio.c and stdio.h and malloc.c and malloc.h with the necessary functions but I still need time() and I couldn't find time.c anywhere so I gave up and deleted my new code.
I am trying graphics.prx in kernel mode with user LIBC but with kernel LIBS and the only error I am getting is:
| Code: | /usr/local/pspdev/lib/gcc/psp/4.3.1/../../../../psp/lib/libc.a(_sbrk.o): In function `_sbrk':
../../../../../../newlib/libc/sys/psp/libcglue.c:549: undefined reference to `sceKernelMaxFreeMemSize'
collect2: ld returned 1 exit status
make: *** [graphics.elf] Error 1
|
I've tried adding -lpspsysmem_user/kernel to my LIBS and using the .a and .h that comes with the m33 sdk but didn't work.
Edit:
adding -lc as the first library worked. :) time to test the prx _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Nov 03, 2008 1:58 am Post subject: |
|
|
| Delete the output files every time you recompile. Usually when you change the makefile, it doesn't reflect the next time you compile it unless you clean up previous output files. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 2:01 am Post subject: |
|
|
that's why I use do make clean before make :P
It exports the function :now, it crashed when doing fopen I think but no problem, I will find a way to fix it.
Thank you all _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Nov 03, 2008 2:14 am Post subject: |
|
|
Can you give me you're "clean" section of the makefile?
I've tried to write one before but failed. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 2:27 am Post subject: |
|
|
I am not using user mode anymore. I just managed to get graphics.prx (in kernel mode) using standard I/O functions and exporting functions at the same time.
Here's my makefile:
| Code: | TARGET = graphics
OBJS = main.o exports.o
PSPLIBSDIR = $(PSPSDK)/..
USE_KERNEL_LIBS=1
INCDIR = ../../../sdk/include
CFLAGS = -Os -G0 -Wall -g
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
#LDFLAGS += -mno-crt0 -nostartfiles
BUILD_PRX = 1
PRX_EXPORTS = exports.exp
#USE_KERNEL_LIBC = 1
#USE_USER_LIBC = 1
PSP_FW_VERSION = 500
LIBDIR = ../../../sdk/lib
LIBS = -lc -ljpeg -lpspkernel -lz -lm -lpsploadexec_kernel -lpspsystemctrl_kernel -lpspmodulemgr_kernel -lpspumd -lpspkubridge
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build_prx.mak
|
I am going to do some debug now to see where it is crashing in my code. It may be crashing due to STD I/O functions _________________
Upgrade your PSP |
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Mon Nov 03, 2008 3:29 am Post subject: |
|
|
I don't know if it works in latest firmwares but I remember long ago it worked using flags 0x0001, which causes functions to resolve as jumps. But that is very propense to cause inestability and finally crash, as the user functions are being executed in kernel mode and they are programmed as user functions.
I remember I did the first version of nethostfs like that, it was a kernel prx that called user functions (net ones), and that's probably the reason why it was so unstable. Later Ahman improved it and I think he used user mode.
Anyways, I don't know if since then Sony has made more checks to make this not possible. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 3:40 am Post subject: |
|
|
Ok thanks moonlight. Did Ahman ever released the source for NetHostFS PC and PSP ? I know you did but I don't know about him
I managed to get the standard I/O to work anyway :)
Using a custom stdio.c and stdio.h _________________
Upgrade your PSP |
|
| Back to top |
|
 |
KickinAezz
Joined: 03 Jun 2007 Posts: 328
|
Posted: Mon Nov 03, 2008 3:47 am Post subject: |
|
|
LOL!
pspiofilemgr_kernel.h.
LIBS = -lpspiofilemgr_kernel (not required since it's already in BUILD.MAK) _________________ Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 3:59 am Post subject: |
|
|
| KickinAezz wrote: | LOL!
pspiofilemgr_kernel.h.
LIBS = -lpspiofilemgr_kernel (not required since it's already in BUILD.MAK) |
what the fu*k are you talking about?
I guess you did not read all posts otherwise you would have not said what you said.
THE STANDARD I/O FUNCTIONS ARE CRASHING. (this means it's stdio.c/h)
They use sceIo functions yes but they got a #ifdef before which makes the functions not being able to be used when LIBC or LIBC (i dont know) are set for kernel. So now I removed the necessary #ifdef #endif from the custom stdio.c and stdio.h I have here and it works.
I hope you can read it better now. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
whistler
Joined: 04 Mar 2008 Posts: 40
|
Posted: Mon Nov 03, 2008 4:07 am Post subject: |
|
|
| Torch wrote: | Can you give me you're "clean" section of the makefile?
I've tried to write one before but failed. |
it's already in build.mak. you can also use make rebuild which is quicker than typing make clean, make |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Nov 03, 2008 4:12 am Post subject: |
|
|
I thought he meant "clean" as makefile without unneeded things lol.
not the clean "section"
"make clean" is a linux command Torch. Sorry for misunderstanding
Edit:
you can also use this:
| Code: | all: myfile.prx
rm -f /home/username/project/*.o |
this will clean all .o files in the specified path everytime you hit make.
rm means remove and the option -f means force. myfile.prx is your prx file. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Nov 03, 2008 2:25 pm Post subject: |
|
|
| No I meant sometimes the makefile has a section "clean:' just like "all:" which is used to remove specific files if a general rm -f *.o isn't sufficient. |
|
| Back to top |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Tue Nov 04, 2008 12:24 am Post subject: |
|
|
A simple make clean remove all the objs file, the target and the extra targets like pbp's and related sfo...
Last edited by ne0h on Tue Nov 04, 2008 12:25 am; edited 1 time in total |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Tue Nov 04, 2008 12:25 am Post subject: |
|
|
@torch I think you cannot use clean: anymore. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
|