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 

prx bug

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



Joined: 07 Dec 2008
Posts: 53

PostPosted: Tue Jan 27, 2009 6:00 am    Post subject: prx bug Reply with quote

I am making a prx in kernel mode and I use it as plugin. After functions such as sin(), cos() or read directory from memory stick, web browser doesnt work, and if I push on XMB videos, then psp hangs (well the wait icon is blinking and thats all, I can still use my prx... just XMB menu hangs). What could be wrong? maybe someone had such bug?
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Tue Jan 27, 2009 7:44 am    Post subject: Reply with quote

Perhaps blowing away all your memory in kernel space.
Back to top
View user's profile Send private message
hotter



Joined: 07 Dec 2008
Posts: 53

PostPosted: Tue Jan 27, 2009 7:53 pm    Post subject: Reply with quote

Might be. And how I should avoid this?
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Tue Jan 27, 2009 9:19 pm    Post subject: Reply with quote

Learn how to program. You're kernel plugin should avoid allocating any extra memory if possible. If you do don't exceed more than 100 or so KiB.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Wed Jan 28, 2009 4:53 am    Post subject: Reply with quote

A touch harsh :)

Try running the command 'psp-size your.prx' and see what its total memory footprint is. Don't allocate large global buffers, don't create many threads with large stack sizes, don't do allocations direct out of kernel memory, all those kinda of things. Also ideally don't use the libc, especially not newlib, you might get away with using libm (though it is probably not recommended). You can use a cut down internal libc by specifying a makefile option to reduce memory size.
Back to top
View user's profile Send private message
hotter



Joined: 07 Dec 2008
Posts: 53

PostPosted: Wed Jan 28, 2009 7:04 am    Post subject: Reply with quote

This is what I get after psp-size:
Code:

   text    data     bss     dec     hex filename
 109768    2360   28688  140816   22610 PSPconsole.prx

I guess it is realy big numbers for prx, yes?
well I dont use USE_KERNEL_LIBC=1 and USE_KERNEL_LIBS=1 in my make file because then such functions as time(), clock() and some other are undefined and I dont know why... And I need to use short integer array... Maybe there is other space where I could save my variables? some hint or examples would be cool....
well my programing skills is not realy high... I just know basics... :( But I am doing my best...
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10


Last edited by hotter on Wed Jan 28, 2009 7:08 am; edited 1 time in total
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Jan 28, 2009 7:07 am    Post subject: Reply with quote

Not using kernel libc will bloat your prx by around 84KiB.
However kernel libc is limited. You will just have to make do or write your own functions for those missing ones.

Just use the equivalent sce functions for time and stuff.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Wed Jan 28, 2009 7:56 am    Post subject: Reply with quote

Yah it looks like most of your bloat is in .text which means it is primarily code. 140k is quite large for a kernel executable. You really need to set the kernel libraries only and reimplement as touch says, tbh at least clock and time are implemented by the kernel just not in the libc, do a search :)
Back to top
View user's profile Send private message
hotter



Joined: 07 Dec 2008
Posts: 53

PostPosted: Sun Feb 01, 2009 6:23 am    Post subject: Reply with quote

well everything seems to work better now, I just have problems with float and double type variables, they are = 0; but when I try to print them I get letter "f". why? :( before adding thouse two lines in make file these variables worked fine....

P.S. what are pros and cons of making a prx in kernel mode, user mode or other? maybe user mode can use more memory? well I guess the first cons would be that just in kernel mode i couldnt use syscall...
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sun Feb 01, 2009 1:03 pm    Post subject: Reply with quote

The kernel libc's printf doesn't support printing of floats or doubles, you have to write code to convert the float yourself to a string then print that.

As for advantages/disadvantages for plugins while you have more user ram if nothing is using it games will almost always use as much as possible so you will find some games won't run if your plugin was user mode. As for syscalls except for a small set of functions all core stuff should be accessible in kernel mode directly, main think you can't as easily access is networking.
Back to top
View user's profile Send private message
hotter



Joined: 07 Dec 2008
Posts: 53

PostPosted: Mon Feb 02, 2009 6:50 pm    Post subject: Reply with quote

I guess user mode would be better for me because my prx is usable in XMB menu, not in games. But how to disable XMB buttons from user mode? maybe there is a way to start prx in kernel mode and after patchsyscall make it user mode something like that?
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Mon Feb 02, 2009 7:05 pm    Post subject: Reply with quote

hotter wrote:
I guess user mode would be better for me because my prx is usable in XMB menu, not in games. But how to disable XMB buttons from user mode? maybe there is a way to start prx in kernel mode and after patchsyscall make it user mode something like that?


Even in the XMB, the Phat will run out of memory and crash if you consume more than 100-150KiB. On coldboot at the XMB (without opening anything) there is around 2740KiB free. This will reduce as you open stuff in the XMB.

In the Slim XMB you can simply allocate user memory with malloc or whatever and it will take it from the heap which includes the extra 32MiB without needing to do anything special.

In game mode (official games) on the Slim you need to explicitly allocate into the last 32MiB. In homebrew, depending on whether the EBOOT has used the extra memory you may not be able to allocate from it.

To disable XMB buttons you have to use a kernel prx to hook the vshCtrlReadBufferPositive and zero the SceCtrlPad.Buttons to disable them.

You can still normally call sceCtrlReadBufferPositive from your user prx.
Back to top
View user's profile Send private message
hotter



Joined: 07 Dec 2008
Posts: 53

PostPosted: Wed Feb 04, 2009 6:29 am    Post subject: Reply with quote

what if I leave my prx as is in kernel mode and just add PSP_HEAP_SIZE_KB(1024); ? will there be more memory bugs with this?
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Wed Feb 04, 2009 6:30 am    Post subject: Reply with quote

hotter wrote:
what if I leave my prx as is in kernel mode and just add PSP_HEAP_SIZE_KB(1024); ? will there be more memory bugs with this?


Please DON'T allocate a big heap in kernel mode. You would just take a precious chunk out of it and leave most of it unused. Use the sceKernelAllocPartition functions to allocate the exact required amount from kernel memory.
Back to top
View user's profile Send private message
hotter



Joined: 07 Dec 2008
Posts: 53

PostPosted: Fri Feb 06, 2009 3:52 am    Post subject: Reply with quote

Thx Torch, I am trying to use sceKernelAllocPartition function :)

I allocated memory for some chars..... but how to allocate memory for double array?
Code:

//short int ar[60][34];
SceUID mem = sceKernelAllocPartitionMemory(2, "mem", 0, sizeof(short int) * 60 * 34, NULL);
short int * ar = (short int *)sceKernelGetBlockHeadAddr(mem);

this doesnt work :(
_________________
Pragramming with:
Microsoft Visual C 2008 + pspsdk MINPSPW 0.8.10
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Fri Feb 06, 2009 4:02 am    Post subject: Reply with quote

It only returns a pointer to a contiguous memory block, so i don't think you can directly call like ar[row][column] after allocation because the compiler won't know the dimensions. There's probably some macro or something to access it like a 2d array but I don't know.

Code:

//short int ar[60][34];
SceUID mem = sceKernelAllocPartitionMemory(2, "mem", 0, sizeof(short int)*60*34, NULL);
short int * ar = (short int *)sceKernelGetBlockHeadAddr(mem);

//access like ar[34*row + column] to get ar[row][column]
Back to top
View user's profile Send private message
Bubbletune



Joined: 03 Jan 2009
Posts: 28

PostPosted: Sun Feb 08, 2009 7:11 pm    Post subject: Reply with quote

Torch wrote:
There's probably some macro or something to access it like a 2d array but I don't know.

Code:
short int (*ar)[60]; // note the ( and )
SceUID blockid = sceKernelAllocPartitionMemory(2, "mem", 0, sizeof(ar)*34, NULL);

if (blockid >= 0)
{
   ar = (void *)sceKernelGetBlockHeadAddr(mem);
}
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