pspdev/sdk "sio" sample from 1.50 kernel to 3.xx k

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

Moderators: cheriff, TyRaNiD

mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

pspdev/sdk "sio" sample from 1.50 kernel to 3.xx k

Post by mypspdev »

Hi!
Because the debug/sio sample is only working under 1.50 kernel and crashing under 3.xx kernel, I'd like to modify it for compatibility.

Here is source:

Code: Select all

/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Basic sample to demonstrate the remote port sio.
 *
 * Copyright &#40;c&#41; 2005 James Forshaw <tyranid@gmail.com>
 *
 * $Id&#58; main.c 1095 2005-09-27 21&#58;02&#58;16Z jim $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>

PSP_MODULE_INFO&#40;"REMOTE", 0x1000, 1, 1&#41;;
/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

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

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;
	
	/* Initialise SIO and install a kprintf handler */
	pspDebugSioInit&#40;&#41;;
	pspDebugSioInstallKprintf&#40;&#41;;

	/* Install a stdout handler */
	pspDebugInstallStdoutHandler&#40;pspDebugSioPutData&#41;;

	Kprintf&#40;"Hi from %s!\n", "Kprintf"&#41;;
	printf&#40;"Also hi from stdio\r\n"&#41;;

	pspDebugScreenPrintf&#40;"Press X to exit, tap away on your terminal to echo\n"&#41;;
	sceDisplayWaitVblankStart&#40;&#41;;

	while&#40;1&#41;
	&#123;
		SceCtrlData pad;
		int ch;

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
		&#123;
			break;
		&#125;

		ch = pspDebugSioGetchar&#40;&#41;;
		if&#40;ch >= 0&#41;
		&#123;
			pspDebugScreenPrintf&#40;"Received %d\n", ch&#41;;
			if&#40;ch == '\r'&#41;
			&#123;
				pspDebugSioPutchar&#40;'\r'&#41;;
				pspDebugSioPutchar&#40;'\n'&#41;;
			&#125;
			else
			&#123;
				pspDebugSioPutchar&#40;ch&#41;;
			&#125;
		&#125;

		sceDisplayWaitVblankStart&#40;&#41;;
	&#125;

	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;
Here is Makefile:

Code: Select all

TARGET = sio
OBJS = main.o

USE_PSPSDK_LIBC = 1

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

LIBDIR =
LDFLAGS = 


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SIO Test

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

LIBS += -lpsphprm_driver
I'm assuming the following steps at least for porting:

- add callback setup as usual
- add to makefile PSP_FW_VERSION = 371

What else, please?

It's still not properly working, crashing under 3.xx kernel.

Is something wrong from libpspdebug ?

Or something not compatible for

pspDebugSioInit();
pspDebugSioInstallKprintf();

? Thanks in advance for your help
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Code: Select all

PSP_MODULE_INFO&#40;"REMOTE", 0x1000, 1, 1&#41;;
/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;0&#41;; 
Makes it a kernel mode app. You need to change it to user. Of course, then you'll need to move the kernel mode stuff into an external prx to access it. Find everything that HAS to be in kernel mode and put it into a separate prx, then load/start that prx from the user app. Like I tend to recommend, check the nanddumper example in the 3xxHEN SDK. It very clearly shows how to make, load, and call kernel functions from a user app with the prx. That means the main task is figuring out what should be moved to the prx.
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

Thanks very much, J.F, I'll try to do it and post solution or intermediate steps, if any, apologizing since now for eventual new help being asked.

Same porting need from 1.50 to 3.xx I have for

pspsdk/net/Wlanscan a wireless lan sniffer
and
pspsdk/net/simple a Client/Server

but these the samples are already .prx.

Thanks for now.
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

ok I've compiled sio as a prx:

Code: Select all

/*
 * PSP Software Development Kit - http&#58;//www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Basic sample to demonstrate the remote port sio.
 *
 * Copyright &#40;c&#41; 2005 James Forshaw <tyranid@gmail.com>
 *
 * $Id&#58; main.c 1095 2005-09-27 21&#58;02&#58;16Z jim $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>

PSP_MODULE_INFO&#40;"REMOTE", 0x1000, 1, 1&#41;;
/* Define the main thread's attribute value &#40;optional&#41; */
//PSP_MAIN_THREAD_ATTR&#40;0&#41;;

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

	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;
	
	/* Initialise SIO and install a kprintf handler */
	pspDebugSioInit&#40;&#41;;
	pspDebugSioInstallKprintf&#40;&#41;;

	/* Install a stdout handler */
	pspDebugInstallStdoutHandler&#40;pspDebugSioPutData&#41;;

	Kprintf&#40;"Hi from %s!\n", "Kprintf"&#41;;
	printf&#40;"Also hi from stdio\r\n"&#41;;

	pspDebugScreenPrintf&#40;"Press X to exit, tap away on your terminal to echo\n"&#41;;
	sceDisplayWaitVblankStart&#40;&#41;;

	while&#40;1&#41;
	&#123;
		SceCtrlData pad;
		int ch;

		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
		&#123;
			break;
		&#125;

		ch = pspDebugSioGetchar&#40;&#41;;
		if&#40;ch >= 0&#41;
		&#123;
			pspDebugScreenPrintf&#40;"Received %d\n", ch&#41;;
			if&#40;ch == '\r'&#41;
			&#123;
				pspDebugSioPutchar&#40;'\r'&#41;;
				pspDebugSioPutchar&#40;'\n'&#41;;
			&#125;
			else
			&#123;
				pspDebugSioPutchar&#40;ch&#41;;
			&#125;
		&#125;

		sceDisplayWaitVblankStart&#40;&#41;;
	&#125;

//	sceKernelExitGame&#40;&#41;;
	sceKernelSleepThread&#40;&#41;;

	return 0;
&#125;
/* Exported function returns the address of module_info */
void* getModuleInfo&#40;void&#41;
&#123;
	return &#40;void *&#41; &module_info;
&#125;
Makefile :

Code: Select all

TARGET = sio
OBJS = main.o

# Define to build this as a prx &#40;instead of a static elf&#41;
BUILD_PRX=1
# Define the name of our custom exports &#40;minus the .exp extension&#41;
# PRX_EXPORTS=exports.exp

USE_PSPSDK_LIBC = 1

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

LIBDIR =
LDFLAGS = 

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

LIBS += -lpsphprm_driver
[/code]

A compiled a prx loader:

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>

PSP_MODULE_INFO&#40;"sio_prx", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;

u8 block&#91;32*32*528&#93;;

int ReadBlock&#40;u32 page, u8 *buffer&#41;;

#define printf pspDebugScreenPrintf

int main&#40;&#41; 
&#123;
	pspDebugScreenInit&#40;&#41;;
	
	SceUID mod = pspSdkLoadStartModule&#40;"sio.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;

	if &#40;mod < 0&#41;
	&#123;
		printf&#40;"Error 0x%08X loading/starting sio.prx.\n", mod&#41;;
	&#125;

	else
	&#123;
	&#125;

	sceKernelDelayThread&#40;5*1000*1000&#41;;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;
Or another way, with callbacks:

Code: Select all

/*
 * PSP Software Development Kit - http&#58;//www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Basic harness for loading prxes &#40;for proving a point&#41;
 *
 * Copyright &#40;c&#41; 2005 Marcus R. Brown <mrbrown@ocgnet.org>
 * Copyright &#40;c&#41; 2005 James Forshaw <tyranid@gmail.com>
 * Copyright &#40;c&#41; 2005 John Kelley <ps2dev@kelley.ca>
 *
 * $Id&#58; main.c 1095 2005-09-27 21&#58;02&#58;16Z jim $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <string.h>

PSP_MODULE_INFO&#40;"PRXLOADER", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

/* Define printf, just to make typing easier */
#define printf	pspDebugScreenPrintf

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *arg&#41;
&#123;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
void CallbackThread&#40;void *arg&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", &#40;void*&#41; CallbackThread, 0x11, 0xFA0, 0xa0000000, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

SceUID load_module&#40;const char *path, int flags, int type&#41;
&#123;
	SceKernelLMOption option;
	SceUID mpid;

	/* If the type is 0, then load the module in the kernel partition, otherwise load it
	   in the user partition. */
	if &#40;type == 0&#41; &#123;
		mpid = 1;
	&#125; else &#123;
		mpid = 2;
	&#125;

	memset&#40;&option, 0, sizeof&#40;option&#41;&#41;;
	option.size = sizeof&#40;option&#41;;
	option.mpidtext = mpid;
	option.mpiddata = mpid;
	option.position = 0;
	option.access = 1;

	return sceKernelLoadModule&#40;path, flags, type > 0 ? &option &#58; NULL&#41;;
&#125;

/* Imported function */
void *getModuleInfo&#40;void&#41;;

int main&#40;void&#41;
&#123;
	SceUID modid;
	SceModule *mod;
	int i;
	int ret;
	int fd;

	pspDebugScreenInit&#40;&#41;;

	SetupCallbacks&#40;&#41;;

	/* Start mymodule.prx and dump its information */
	printf&#40;"\nStart my module\n"&#41;;
	modid = load_module&#40;"./sio.prx", 0, 0&#41;;
	printf&#40;"Module ID %08X\n", modid&#41;;
	mod = sceKernelFindModuleByUID&#40;modid&#41;;
	printf&#40;"mod %p\n", mod&#41;;

	/* Let's bug out */
	sceKernelExitDeleteThread&#40;0&#41;;

	return 0;
&#125;

PRX Loader Makefile:

Code: Select all

TARGET = Myprxloader
OBJS = main.o

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

LIBDIR =
LDFLAGS =
LIBS= 

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Myprxloader

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

But the PRX Loader, both of them, do run and work properly only if under GAME150, not GAME3xx.

I'd like to run sio under 3.xx.

Please where am I wrong?

Thanks
coldbit
Posts: 1
Joined: Wed Sep 26, 2007 6:36 am

Post by coldbit »

You have to use:

Code: Select all

kuKernelLoadModule
(see kubridge.h in the SDK of 3.71 M33 release)
rather than:

Code: Select all

sceKernelLoadModule
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

coldbit wrote:You have to use:

Code: Select all

kuKernelLoadModule
(see kubridge.h in the SDK of 3.71 M33 release)
rather than:

Code: Select all

sceKernelLoadModule
It doesn't work ...
To use remote controller/SIO I need Flat PSP with at present 3.52M-33.
I do try it on S&L with 3.71M-33, even if nothing to do with SIO/Remote controller: it does'n load sio.prx on S&L as well as on Flat .
Prx Loader only works under 1.50, which I do want to avoid.

Thanks.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Okay, let's review the high points of the nanddumper example app...

First, let's start with the external prx. This is no more than a library to be loaded and called by the main app. ALL kernel code must go into these for 3.xx. Here's the main.c file for the nanddumper.prx:

main.c

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspnand_driver.h>
#include <string.h>

PSP_MODULE_INFO&#40;"NandDumper", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int nandLocked = 0;

void LockNand&#40;&#41; 
&#123;
	if &#40;!nandLocked&#41;
		sceNandLock&#40;0&#41;;
	
	nandLocked = 1;
&#125;


void UnlockNand&#40;&#41; 
&#123;
	if &#40;nandLocked&#41;
		sceNandUnlock&#40;&#41;;

	nandLocked = 0;
&#125;

int ReadBlock&#40;u32 page, u8 *buffer&#41;
&#123;
	u32 i, j;
	u32 k1;

	k1 = pspSdkSetK1&#40;0&#41;;

	LockNand&#40;&#41;;

	if &#40;sceNandIsBadBlock&#40;page&#41;&#41;
	&#123;
		memset&#40;buffer, 0xFF, 528&#41;;
		UnlockNand&#40;&#41;;
		pspSdkSetK1&#40;k1&#41;;		
		return -1;
	&#125;

	for &#40;i = 0; i < 32; i++&#41;
	&#123;
		for &#40;j = 0; j < 4; j++&#41;
		&#123;
			sceNandReadPagesRawAll&#40;page, buffer, NULL, 1&#41;;
			sceNandReadExtraOnly&#40;page, buffer+512, 1&#41;;
		&#125;

		page++;
		buffer += 528;
	&#125;

	UnlockNand&#40;&#41;;
	pspSdkSetK1&#40;k1&#41;;

	return 0;
&#125;


int module_start&#40;SceSize args, void *argp&#41; 
&#123;
	return 0;
&#125;

int module_stop&#40;&#41;
&#123;
	return 0;
&#125;
Notice its header:

Code: Select all

PSP_MODULE_INFO&#40;"NandDumper", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;
This shows this is a kernel mode prx. Notice how it has module_start() and module_stop(), both needed for external libs. Notice how it has a number of functions and no main() entry point. Notice the use of pspSdkSetK1(). Setting K1 to 0 around functions prevents the kernel from faulting when accessing areas like user-mode memory.

Its makefile appears this way:

makefile

Code: Select all

TARGET = nanddumper
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 = nanddumper.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspnand_driver2


PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Notice how it uses no-crt0 and nostartfiles... that's because this is a plain lib, not an app. It doesn't need either of those. Notice the use of the kernel libs. Notice that there is a file called "nanddumper.exp" - that is where you declare which functions are seen externally when this prx is loaded.

Here's what that file looks like:

nanddumper.exp

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

PSP_EXPORT_START&#40;NandDumper, 0, 0x4001&#41;
PSP_EXPORT_FUNC&#40;ReadBlock&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
The lines must always be like that except for the PSP_EXPORT_FUNC() lines. That is where you set the exported functions from this lib. Oh, the NandDumper in the start line should match the NandDumper in the PSP_MODULE_INFO in main.c. Change both identically to make a different name. This file is also used to generate the .S file that you use in the main app to access these functions. To make the .S file, from a shell set to the directory with these files, run

Code: Select all

psp-build-exports -s nanddumper.exp
Copy that .S file to the same directory as the source for the main app, along with the .prx file you get when you run make.

That is all you do for the prx part. The above gives you a kernel-mode lib that does all the stuff you need via exported functions. Now let's move on to the main app.

main.c

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>

PSP_MODULE_INFO&#40;"NandDumperMain", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;

u8 block&#91;32*32*528&#93;;

int ReadBlock&#40;u32 page, u8 *buffer&#41;;

#define printf pspDebugScreenPrintf

int main&#40;&#41; 
&#123;
	pspDebugScreenInit&#40;&#41;;
	
	SceUID mod = pspSdkLoadStartModule&#40;"nanddumper.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;

	if &#40;mod < 0&#41;
	&#123;
		printf&#40;"Error 0x%08X loading/starting naddumper.prx.\n", mod&#41;;
	&#125;

	else
	&#123;

		SceUID fd = sceIoOpen&#40;"ms0&#58;/nanddump.flash", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;

		printf&#40;"Dumping...\n"&#41;;

		int i, j;

		for &#40;i = 0; i < &#40;2048*32&#41;; &#41;
		&#123;			
			u8 *p = block;
			memset&#40;block, 0xff, sizeof&#40;block&#41;&#41;;

			for &#40;j = 0; j < 32; j++&#41;
			&#123;

				if &#40;ReadBlock&#40;i, p&#41; < 0&#41;
				&#123;
					printf&#40;"bad block at page %d block %d\n", i, i/32&#41;;
				&#125;

				i += 32;
				p += &#40;528*32&#41;;
			&#125;
			
			sceIoWrite&#40;fd, block, sizeof&#40;block&#41;&#41;;			
		&#125;

		sceIoClose&#40;fd&#41;;

		printf&#40;"Done. Exiting in 5 seconds\n"&#41;;
	&#125;

	sceKernelDelayThread&#40;5*1000*1000&#41;;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;
Notice the header.

Code: Select all

PSP_MODULE_INFO&#40;"NandDumperMain", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;
This is a user-mode app. That is what you need for HEN and 3.xx on the slim. You may also need to set the heap size if you need to allocate lots of memory in the app. That would be done by putting a line after the above two lines that looks like this:

Code: Select all

PSP_HEAP_SIZE_KB&#40;2500&#41;;
That sets the size of the heap in kBytes. So that line sets it to about 2.5 MB. Notice that the app also has declarations for all the functions that will be imported, as so:

Code: Select all

int ReadBlock&#40;u32 page, u8 *buffer&#41;;
Note how the prx is loaded:

Code: Select all

	SceUID mod = pspSdkLoadStartModule&#40;"nanddumper.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
Notice in that line how it's loaded into the kernel partition since it's a kernel mode lib. Also notice that you simply call the functions as normal. The .S file function entries will take care of switching back and forth between user and kernel mode.

DON'T FORGET!! All created threads must be USER threads. Set the attr arg in the createthread function to PSP_THREAD_ATTR_USER!

Now look at the makefile:

makefile

Code: Select all

release&#58; all
	mksfo 'NandDumper' PARAM.SFO
	pack-pbp EBOOT.PBP PARAM.SFO NULL NULL NULL NULL NULL nanddumpermain.prx NULL


TARGET = nanddumpermain
OBJS = main.o NandDumper.o

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

BUILD_PRX = 1

LIBDIR =
LIBS = 
LDFLAGS =

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
That's an "old-style" makefile as seen from it's use of mksfo and pack-pbp. You can instead use the newer makefile style as such:

makefile

Code: Select all

TARGET = nanddumpermain
OBJS = main.o NandDumper.o

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

BUILD_PRX = 1

LIBDIR =
LIBS =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = NandDumper
PSP_EBOOT_ICON="icon0.png"
PSP_EBOOT_PIC1="pic1.png"
PSP_EBOOT_SND0="snd0.at3"

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Note how the new style doesn't directly use mksfo or pack-pbp, but uses EXTRA_TARGETS and PSP_EBOOT_XXXX instead. It's equivalent, but easier to specify without goofing up the arguments to mksfo or pack-pbp. All those PSP_EBOOT_XXXX lines are optional.

Note that the makefile has "BUILD_PRX = 1". That seems to be the key for getting it to run as a 3xx app. notice how the .S file is included in the object list.

Doing all this gives you the two files you want: nanddumper.prx (the external prx library) and EBOOT.PBP (the main app). Copy those to a folder in PSP/GAME/ and you're all set.

I hope this brief review has given you some insight into how you make a user-mode app which call a kernel mode external library.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)

Many thanks J.F. for the explanation...I was just looking at the nanddumper sample, but I'm experiencing problems.
Can you please help me?

I'm just trying to make a prx with the functions to set and get the display brightness (just to test some kernel functions).
I think I followed all your advices but the app still gives me "Library not found" error.

Here's my code:

Main.c

Code: Select all

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

PSP_MODULE_INFO&#40;"Test_CF352", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;
PSP_HEAP_SIZE_KB&#40;2500&#41;;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions imported from prx&#58;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getBrightness&#40;void&#41;;
void setBrightness&#40;int brightness&#41;;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Globals&#58;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main&#58;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main&#40;&#41;&#123;
	SceUID modid;
	SceModule *mod;
	int ret;
	int fd;

	pspDebugScreenInit&#40;&#41;; 

    pspDebugScreenPrintf&#40;"Eboot test\n"&#41;;
    pspDebugScreenPrintf&#40;"Press X to quit\n"&#41;;

	modid = pspSdkLoadStartModule&#40;"myLib.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
	if &#40;modid < 0&#41;&#123;
		pspDebugScreenPrintf&#40;"Error 0x%08X loading/starting test352.prx.\n", modid&#41;;
        sceKernelDelayThread&#40;5*1000*1000&#41;;
        return -1;
	&#125;

	pspDebugScreenPrintf&#40;"Module ID %08X\n", modid&#41;;
	mod = sceKernelFindModuleByUID&#40;modid&#41;;
	pspDebugScreenPrintf&#40;"mod %p\n", mod&#41;;
	ret = sceKernelStartModule&#40;modid, 0, NULL, &fd, NULL&#41;;
	pspDebugScreenPrintf&#40;"Brightness level %i\n", getBrightness&#40;&#41;&#41;;

    SceCtrlData pad;
    while&#40;1&#41;&#123;
        sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
        if &#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
            break;
        &#125;
    &#125;
	sceKernelExitGame&#40;&#41;;
    return 0;

&#125;
Makefile:

Code: Select all

TARGET = Test_CF352
OBJS = main.o myLib.o

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

BUILD_PRX = 1

LIBDIR =
LIBS =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test_CF352
#PSP_EBOOT_ICON="icon0.png"
#PSP_EBOOT_PIC1="pic1.png"
#PSP_EBOOT_SND0="snd0.at3"

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
And there's my prx source code.
Main.c

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdisplay_kernel.h>

PSP_MODULE_INFO&#40;"myLib", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int getBrightness&#40;&#41;&#123;
    int currentBrightness = 0;
    u32 k1; 

    k1 = pspSdkSetK1&#40;0&#41;;
    sceDisplayGetBrightness&#40;&currentBrightness, 0&#41;;
    pspSdkSetK1&#40;k1&#41;;
    return currentBrightness;
&#125;

void setBrightness&#40;int brightness&#41;&#123;
    u32 k1; 

    k1 = pspSdkSetK1&#40;0&#41;;
    sceDisplaySetBrightness&#40;brightness, 0&#41;;
    pspSdkSetK1&#40;k1&#41;;
&#125;

int module_start&#40;SceSize args, void *argp&#41; 
&#123;
	return 0;
&#125;

int module_stop&#40;&#41;
&#123;
	return 0;
&#125;
Makefile:

Code: Select all

TARGET = mylib
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 = mylib.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspdisplay_driver


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

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;myLib, 0, 0x4001&#41;
PSP_EXPORT_FUNC&#40;getBrightness&#41;
PSP_EXPORT_FUNC&#40;setBrightness&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
I really cannot understand what's wrong.
I'm on CF 3.52 update 4 and I put the resulting eboot and prx in PSP/GAME352

Ciaooo
Sakya
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Look at the example again - this part is TOTALLY unnecessary.

Code: Select all

   mod = sceKernelFindModuleByUID&#40;modid&#41;;
   pspDebugScreenPrintf&#40;"mod %p\n", mod&#41;;
   ret = sceKernelStartModule&#40;modid, 0, NULL, &fd, NULL&#41;;
The pspSdkLoadStartModule() already did all that. Just pspSdkLoadStartModule() then start using the the functions.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Post by sakya »

Hi! :)
J.F. wrote:Look at the example again - this part is TOTALLY unnecessary.

Code: Select all

   mod = sceKernelFindModuleByUID&#40;modid&#41;;
   pspDebugScreenPrintf&#40;"mod %p\n", mod&#41;;
   ret = sceKernelStartModule&#40;modid, 0, NULL, &fd, NULL&#41;;
The pspSdkLoadStartModule() already did all that. Just pspSdkLoadStartModule() then start using the the functions.
OMG, I'm very sorry for my mistake!
Just removed those lines and the app works perfectly. :)

Many thanks
Ciaooo
Sakya
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

sakya wrote: Makefile:

Code: Select all

TARGET = Test_CF352
OBJS = main.o myLib.o

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

BUILD_PRX = 1

LIBDIR =
LIBS =
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test_CF352
#PSP_EBOOT_ICON="icon0.png"
#PSP_EBOOT_PIC1="pic1.png"
#PSP_EBOOT_SND0="snd0.at3"

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
Thanks to both Sakya and J.F for these lessons.

Please in the Makefile of the main program you put

OBJS = ... MyLib.o

as well as in the NandDumper.o in the example.

Does it refer to the MyLib.s and NandDumper.s generated from *.exp?

How is it *.S generated?

Does it require this command from cygwin prompt?

Code: Select all

psp-build-exports -s MyLib.exp
Here on this PC I have only pspdev not full cygwin/psptoolchain.
In case I'll try again at home.

Thanks for explanation.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

sakya wrote:Hi! :)
J.F. wrote:Look at the example again - this part is TOTALLY unnecessary.

Code: Select all

   mod = sceKernelFindModuleByUID&#40;modid&#41;;
   pspDebugScreenPrintf&#40;"mod %p\n", mod&#41;;
   ret = sceKernelStartModule&#40;modid, 0, NULL, &fd, NULL&#41;;
The pspSdkLoadStartModule() already did all that. Just pspSdkLoadStartModule() then start using the the functions.
OMG, I'm very sorry for my mistake!
Just removed those lines and the app works perfectly. :)

Many thanks
Ciaooo
Sakya
No problem... easy enough to miss. Glad to hear it's working now. That's the main thing.
mypspdev wrote:Thanks to both Sakya and J.F for these lessons.

Please in the Makefile of the main program you put

OBJS = ... MyLib.o

as well as in the NandDumper.o in the example.

Does it refer to the MyLib.s and NandDumper.s generated from *.exp?

How is it *.S generated?

Does it require this command from cygwin prompt?

Code: Select all

psp-build-exports -s MyLib.exp

Here on this PC I have only pspdev not full cygwin/psptoolchain.
In case I'll try again at home.

Thanks for explanation.

Code: Select all

psp-build-exports -s MyLib.exp
makes MyLib.S. Putting MyLib.o into the objects line of the app's makefile has psp-gcc compile MyLib.S into MyLib.o, and link it with the other objects.
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

About exports.exp and exports.S and .o:

I saw on ModulTutorialv1.pdf the following first lines in a Makefile (for supervisor):

Code: Select all

release&#58; all
 psp-build-exports -k supervisor_exp.exp
 psp-build-exports -s -k -v supervisor_exp.exp
...... 
Does it mean in our examples that the statement for building exports.S from exports.exp

Code: Select all

psp-build-exports -s exports.exp
must be included into the makefile?

Or is it an external statement to be run at cygwin prompt?

The handbook is explaining:

"The stub file ... .S can be generated from the exp file using "psp-build-exports -s -k -v *.exp" or the PRX directly (although using the latter the liiteral name of the function is lost)."

Could anybody explain better what it means?

Thanks a lot, sorry for not having yet understood what doing.
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

the make file way is simply to do it automatically very time you make but is more make file related rather then psp dev.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

mypspdev wrote:About exports.exp and exports.S and .o:

I saw on ModulTutorialv1.pdf the following first lines in a Makefile (for supervisor):

Code: Select all

release&#58; all
 psp-build-exports -k supervisor_exp.exp
 psp-build-exports -s -k -v supervisor_exp.exp
...... 
Does it mean in our examples that the statement for building exports.S from exports.exp

Code: Select all

psp-build-exports -s exports.exp
must be included into the makefile?

Or is it an external statement to be run at cygwin prompt?

The handbook is explaining:

"The stub file ... .S can be generated from the exp file using "psp-build-exports -s -k -v *.exp" or the PRX directly (although using the latter the liiteral name of the function is lost)."

Could anybody explain better what it means?

Thanks a lot, sorry for not having yet understood what doing.
You COULD put it into the makefile, but I normally don't since you really only need to run it once - unless you change the functions being exported. As long as the functions don't change, neither will the .exp or .S files, so there's no need to make them every single time.

I don't know what all the various options on psp-build-exports do, but the -s option generates the .S file kernel mode prx libs need for user mode apps to access their functions. I tried other options I'd heard were supposedly the ones to use, but the .S files were unusable. Only -s by itself generated the proper file for the use being made of it here.
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

@J.F.
Notice the use of the kernel libs
How can I tell if a lib is a kernel lib and where can I find the names of the kernel libs? Also are there kernel versions for every user version, if not should I use the user version or am I just not allowed to use it at all?
nanddumper.exp

Code: Select all

PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;

PSP_EXPORT_START&#40;NandDumper, 0, 0x4001&#41;
Do the 0x8000 and 0x4001 mean anything? What if I wanted to load a second prx into my app, would I use 0x8001 and 0x4002 so the numbers are different?

Is there a way to unload modules after using pspSdkLoadStartModule? Also how big is the PSP_MEMORY_PARTITION_KERNEL? This is so I can know the maximum size of the kernel prx and the maximum amount of memory I can put in PSP_HEAP_SIZE_KB().
DON'T FORGET!! All created threads must be USER threads.
So you aren't allowed to create kernel mode threads inside the kernel mode prx? If you mean creating threads from the user mode program then don't they automatically start as user mode anyway?

Something you didn't mention but I found in ModuleTutorialv1.pdf, should I be using PSP_NO_CREATE_MAIN_THREAD(); in the kernel prx?


@mypspdev
"The stub file ... .S can be generated from the exp file using "psp-build-exports -s -k -v *.exp" or the PRX directly (although using the latter the liiteral name of the function is lost)."
I think what "losing the literal name" means is if you do psp-build-exports -s mykernelmodule.prx you will end up with stuff like mykernelmodule_3ea42f1c instead of mykernelmoduleMyFunction so inside your user main.c you would have to do:

Code: Select all

#define mykernelmoduleMyFunction mykernelmodule_3ea42f1c

void mykernelmoduleMyFunction&#40;void&#41;;
I haven't tried it myself, but I've seen other code using something like this.
(+[__]%)
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

Just an interesting observation...

I spent a couple of hours trying to make the sio sample run under 3.xx in M33 3.51-4 but the code would always crap out @ pspDebugSioInit() even though all kernel stuff was moved to a separate prx..
Then I ran same code on the slim 3.71 (finally got the remote control thingie for the slim)... and it worked like a charm..

Interestingly enough the sio sample still runs ok under 1.5 kernel in m33 3.51-4

So, i guess, some of 3.xx porting problems may be due to faulty firmware...
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

I'm still getting errors or crashes even if with original sakya example.

debug/Sio, net/wlanscan, net/simple I tried to port to prx's are still not working.

on 3.71m-33 (on slim) it gives an error and return back to xmb.

on 3.52m-33-4 (on flat) it crashes both under game352 and game150.

something is clear from "lessons" results are not going on properly up to me.
deniska
Posts: 71
Joined: Mon Oct 17, 2005 1:38 pm
Location: New York

Post by deniska »

@mypspdev:
Below is somewhat modified code for sio sample that you should be able to run in 3.71 on slim...
main.c

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>

PSP_MODULE_INFO&#40;"SIO_TESTER", 0, 1, 1&#41;;
/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;

int main&#40;void&#41;
&#123;
        int baud=1200;
        pspDebugScreenInit&#40;&#41;;
        pspDebugScreenPrintf&#40;"PSP GPSlim 236 test - Press X to exit\n"&#41;;
        pspDebugScreenPrintf&#40;"Press UP/DOWN to change baud\n"&#41;;
        sceDisplayWaitVblankStart&#40;&#41;;
        sceCtrlSetSamplingCycle&#40;0&#41;;
        sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;

         SceUID mod = pspSdkLoadStartModule&#40;"pspremoteprx.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
    if &#40;mod < 0&#41;
    &#123;
        pspDebugScreenPrintf&#40;" Error 0x%08X loading/starting pspremoteprx.prx.\n", mod&#41;;
        sceKernelDelayThread&#40;3*1000*1000&#41;;
        sceKernelExitGame&#40;&#41;;
    &#125;


        pspDebugScreenPrintf&#40;"module loaded !!!\n"&#41;;
        sioInit&#40;&#41;;
        pspDebugScreenPrintf&#40;"INIT DONE!!!\n"&#41;;

        while&#40;1&#41;
        &#123;
        SceCtrlData pad;

                sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
                if&#40;pad.Buttons & PSP_CTRL_UP&#41; &#123;
                        baud*=2;
                        pspDebugScreenPrintf&#40;"setting baud to&#58; %d\n", baud&#41;;
                        sioSetBaud&#40;baud&#41;;
                        sceKernelDelayThread&#40;500000&#41;;
                &#125;
                if&#40;pad.Buttons & PSP_CTRL_DOWN&#41; &#123;
                        baud/=2;
                        pspDebugScreenPrintf&#40;"setting baud to&#58; %d\n", baud&#41;;
                        sioSetBaud&#40;baud&#41;;
                        sceKernelDelayThread&#40;500000&#41;;
                &#125;
                if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
                &#123;
                        break;
                &#125;

                int ch = sioGetchar&#40;&#41;;
                if&#40;&#40;ch >= 0&#41; && &#40;ch != '\r'&#41;&#41;
                &#123;
                        pspDebugScreenPrintf&#40;"%c", ch&#41;;
                &#125;

        &#125;

        sceKernelExitGame&#40;&#41;;
        return 0;
&#125;
Makefile:

Code: Select all

TARGET = pspgpslim236
OBJS = main.o pspremoteprx.o

#USE_PSPSDK_LIBC = 1

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

LIBDIR =
LDFLAGS =


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = GPSlim236

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

#LIBS += -lpsphprm_driver
-------------------------------------------------------------------
pspremoteprx:: main.c

Code: Select all

#include <pspsdk.h>

PSP_MODULE_INFO&#40;"pspremoteprx", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

#define PSP_UART4_FIFO 0xBE500000
#define PSP_UART4_STAT 0xBE500018
#define PSP_UART4_DIV1 0xBE500024
#define PSP_UART4_DIV2 0xBE500028
#define PSP_UART4_CTRL 0xBE50002C
#define PSP_UART_CLK   96000000
#define PSP_UART_TXFULL  0x20
#define PSP_UART_RXEMPTY 0x10


void sioInit&#40;void&#41;
&#123;
        sceHprmEnd&#40;&#41;;
        sceSysregUartIoEnable&#40;4&#41;;
        sceSysconCtrlHRPower&#40;1&#41;;

&#125;

void sioSetBaud&#40;int baud&#41;
&#123;
        int div1, div2;

        div1 = PSP_UART_CLK / baud;
        div2 = div1 & 0x3F;
        div1 >>= 6;

        _sw&#40;div1, PSP_UART4_DIV1&#41;;
        _sw&#40;div2, PSP_UART4_DIV2&#41;;
        _sw&#40;0x60, PSP_UART4_CTRL&#41;;

&#125;


int  sioGetchar&#40;&#41; &#123;
        return pspDebugSioGetchar&#40;&#41;;
&#125;




int module_start&#40;SceSize args, void *argp&#41;
&#123;
        return 0;
&#125;

int module_stop&#40;&#41;
&#123;
        return 0;
&#125;
pspremoteprx.exp:

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

PSP_EXPORT_START&#40;pspremoteprx, 0, 0x4001&#41;
PSP_EXPORT_FUNC&#40;sioInit&#41;
PSP_EXPORT_FUNC&#40;sioSetBaud&#41;
PSP_EXPORT_FUNC&#40;sioGetchar&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
Makefile:

Code: Select all

TARGET = pspremoteprx
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 = pspremoteprx.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspdebug  -lpspsdk    -lpsphprm_driver

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

all&#58;
        echo "$PSPSDK"
        psp-build-exports -s    pspremoteprx.exp
        cp *.S ../
        cp *.prx ../

clean&#58;
        rm -f $&#40;FINAL_TARGET&#41; $&#40;EXTRA_CLEAN&#41; $&#40;OBJS&#41; $&#40;PSP_EBOOT_SFO&#41; $&#40;PSP_EBOOT&#41; $&#40;EXTRA_TARGETS&#41;
        rm -f *.S

mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

I'd like to invite all of you for a beer and a dinner in any steakhouse around J.F. four corner area .....

Thanks to all, I'll try to reply your lessons here...

Let me tell about some stupid issues for whos is still like me on the way of a learning curve...

- Do not run "make" if you have *.S already in the directory: you'll become mad for duplicate declarations...
- Do not try to use stupid printf / pspDebugScreenPrinf because USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1
are forbidden them for some reasons ...

That's why I was stopped ... Now I've MyPRX and MyLoadPRX... and try to port Sio, Wlanscan, and Server/simple from pspdevsdk.

Thanks

[edit]
SIO on Slim:
it doesn't matter to have it under 3.71 on slim: this PSP has no more a sio connector input. Where is the sio input on the slim?

I need sio on the flat under a 3.52 application.

[edit 2]
Thanks, sio now is working on Fat 3.52.
I had to change the makefile.
Some problems with exit by CROSS.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

USE_KERNEL_LIBC is the main culprit for certain things not working in kernel mode. It indicates using a minimal libc specifically for keeping memory usage down for kernel mode prx's. You should use the SDK libc for more extensive prx's.

Quite a bit happened while I was away from the computer today. :)

The Slim has serial as it has a remote control... which communicates with the PSP via serial. However, the pinout for the header changed because of the TV out. If you look at a recent thread, I documented the pins for the component cable. As soon as I can get a remote, I'll be doing some checking into that as well. It's possible the hardware location of the serial stuff changed in the slim. I don't think anyone has looked that closely at the slim yet.
mypspdev
Posts: 178
Joined: Wed Jul 11, 2007 10:30 pm

Post by mypspdev »

@Deniska:

thanks very much for your souces on SIO prx porting to 3.xx.

I'm experiencing a crash with

Code: Select all

sioInit&#40;&#41;
with fat PSP under 3.52M33-4.

I'm not able to solve it.

Thanks for help
[/code]
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

You should use the SDK libc for more extensive prx's.
That said if you kernel prx is really extensive then it probably shouldn't be in kernel mode in the first place.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

TyRaNiD wrote:
You should use the SDK libc for more extensive prx's.
That said if you kernel prx is really extensive then it probably shouldn't be in kernel mode in the first place.
:)

Yeah, there is that. Do as little as humanly possible in kernel mode... just the things that NEED to be done in kernel mode. If you can't get by on the kernel libc, you're probably trying to do too much in kernel mode. I think people got spoiled by the 1.50/1.50-based cfw... running the entire program in kernel mode. It's too easy to do something truly awful in kernel mode. There's a reason people are supposed to run in user mode and use the libraries.
quadrizo
Posts: 21
Joined: Thu Aug 23, 2007 10:21 pm

Post by quadrizo »

thanks J.F. for your tuto :)
J.F. wrote:USE_KERNEL_LIBC is the main culprit for certain things not working in kernel mode.
i've tried to do a basic prx which works well but when i tried to load a module

Code: Select all

 
SceUID mod =pspSdkLoadStartModule&#40;"flash0&#58;/kd/audiocodec.prx",PSP_MEMORY_PARTITION_KERNEL&#41;;
trouble during liking :
with USE_KERNEL_LIBC=1:
->snprintf indefined reference
with USE_PSPSDK_LIBC=1
->sceKernelMaxFreeMemSize indefined reference

an idea how to resolve this problem ?
Last edited by quadrizo on Thu Nov 08, 2007 10:17 am, edited 1 time in total.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

quadrizo wrote:thanks J.F. for your tuto :)
J.F. wrote:USE_KERNEL_LIBC is the main culprit for certain things not working in kernel mode.
i've tried to do a basic prx which works well but when i tried to load a module

Code: Select all

 
SceUID mod =pspSdkLoadStartModule&#40;"flash0&#58;/kd/audiocodec.prx",PSP_MEMORY_PARTITION_KERNEL&#41;;
trouble during liking :
with USE_PSPSDK_LIBC=1:
->snprintf indefined reference
with USE_PSPSDK_LIBC=1
->sceKernelMaxFreeMemSize indefined reference

an idea how to resolve this problem ?
You need to use USE_KERNEL_LIBC for a kernel mode prx. My warning above was not to tell people not to use the kernel libc, only that they may need to rewrite their code to work with it rather than the regular user-mode libc.
quadrizo
Posts: 21
Joined: Thu Aug 23, 2007 10:21 pm

Post by quadrizo »

trouble during liking :
with USE_KERNEL_LIBC=1:
->snprintf undefined reference
with USE_PSPSDK_LIBC=1
->sceKernelMaxFreeMemSize undefined reference
sorry copy paste error
i've tried USE_KERNEL_LIBC=1 (snprintf undefined ...)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

quadrizo wrote:
trouble during liking :
with USE_KERNEL_LIBC=1:
->snprintf undefined reference
with USE_PSPSDK_LIBC=1
->sceKernelMaxFreeMemSize undefined reference
sorry copy paste error
i've tried USE_KERNEL_LIBC=1 (snprintf undefined ...)
First, let's get straight what's what. Is the error in the user app or the kernel prx? If it's in the kernel prx, why are you even using that there? With kernel prxs, you want to do the kernel function and return. Do nothing that isn't absolutely needed.

If it's in the user app, make sure you have the proper libs linked and in the proper order (yes, order matters). If it's in the user app, you WOULD be using one of the user libc's, either newlib or psplibc.
quadrizo
Posts: 21
Joined: Thu Aug 23, 2007 10:21 pm

Post by quadrizo »

ok
to be clear :
i try to load audiocodec and atrac libs and i'm not sure i could call
pspSdkLoadStartModule("flash0:/kd/audiocodec.prx",PSP_MEMORY_PARTITION_KERNEL);
in user mode right ? that's why i would make a prx to load these libs

but if an another and easier way exist ...;-)
makefile :

Code: Select all

TARGET = testprx
OBJS = main.o
PSP_FW_VERSION=371
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

BUILD_PRX = 1
PRX_EXPORTS = testprx.exp

USE_PSPSDK_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = 


PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak 
snprintf should not be include in libc ?
Post Reply