Media Engine?

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

Moderators: cheriff, TyRaNiD

crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Media Engine?

Post by crazyc »

Some people might want to use the codecs in mebooter but I'd rather use the Media Engine as an extra CPU. To that end i've written a crappy sample that seems to work that runs a counter on the me. If anyone is interested i'll post it here.
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Yes indeed, would be interesting. Does it have access to main memory?
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

ector wrote:Yes indeed, would be interesting. Does it have access to main memory?
I havn't investigated directly, but from looking at mebooter, it's local ram appears to be at 0x88300000 and visible from both CPU's. I'm not sure if it can see the main CPU's ram but I suspect it can and wouldn't be hard to check. Anyway, to the code.

Code: Select all

#include <psptypes.h>
#include <string.h>
#include <pspkernel.h>
#include <pspdebug.h>

void *me_run&#40;&#41;;
void *me_end&#40;&#41;;
void &#40;*sceSysregMeResetEnable&#41;&#40;&#41;;
void &#40;*sceSysregMeResetDisable&#41;&#40;&#41;;
void &#40;*sceSysreg_unk1&#41;&#40;&#41;;
void &#40;*sceSysregVmeResetDisable&#41;&#40;&#41;;

PSP_MODULE_INFO&#40;"ME_test", 0x1000, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int main&#40;int param1, int param2&#41;
&#123;
	SceModuleInfo *sysreg_driver;
	pspDebugInstallErrorHandler&#40;NULL&#41;;
	pspDebugScreenInit&#40;&#41;;
	pspDebugScreenPrintf&#40;"start\n"&#41;;
	memcpy&#40;&#40;void *&#41;0xbfc00040, me_run, &#40;int&#41;&#40;me_end - me_run&#41;&#41;;
	sysreg_driver = pspDebugFindModule&#40;"sceSYSREG_Driver"&#41;;
	sceSysregMeResetEnable = pspDebugFindExportedFunction&#40;sysreg_driver, "sceSysreg_driver", 0xde59dacb&#41;;
	sceSysregMeResetDisable = pspDebugFindExportedFunction&#40;sysreg_driver, "sceSysreg_driver", 0x2db0eb28&#41;;
	sceSysreg_unk1 = pspDebugFindExportedFunction&#40;sysreg_driver, "sceSysreg_driver", 0x44f6cda7&#41;;
	sceSysregVmeResetDisable =  pspDebugFindExportedFunction&#40;sysreg_driver, "sceSysreg_driver",0x7558064a&#41;; 
	sceKernelDcacheWritebackInvalidateAll&#40;&#41;;
	&#40;*sceSysregMeResetEnable&#41;&#40;&#41;;
	&#40;*sceSysreg_unk1&#41;&#40;&#41;;
	&#40;*sceSysregMeResetDisable&#41;&#40;&#41;;
	&#40;*sceSysregVmeResetDisable&#41;&#40;&#41;;
	
	while&#40;1&#41;
	&#123;
		sceKernelDcacheWritebackInvalidateAll&#40;&#41;;
		pspDebugScreenPrintf&#40;"%08x", *&#40;unsigned int *&#41;0xbfc00060&#41;;	
	&#125;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;	

Code: Select all

#include <machine/regdef.h>
	.globl me_run
	.globl me_end

me_run&#58;

	li v0, 0xbfc00060
	li v1, 0
a&#58;
	addiu v1, v1, 1
	sw v1, 0&#40;v0&#41;
	b a

me_end&#58;
MDoggie
Posts: 1
Joined: Fri Jul 15, 2005 8:39 am

Post by MDoggie »

Nice work! I have a question about the Media Engine that I hope you'd answer for those of us who are still in the shallow waters of PSP programming :) How much, so far, has the Media Engine been implemented in the most popular homebrew programs? (Such as the many versions of Snes9x, NesterJ, etc).

Keep up the great work everyone, and now I will return to my mostly-lurker status, and continue to play catch-up from some of you guys about a half-mile back :)
Last edited by MDoggie on Fri Jul 15, 2005 9:08 am, edited 2 times in total.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Um this is the first publically available ME code anyone has seen.

Great work crazyc.
User avatar
EdwardFMA
Posts: 40
Joined: Wed Jul 06, 2005 11:47 am

Post by EdwardFMA »

This is awesome now will this work like a second CPU can the Main Core and Media Core work together to get faster speeds on snes9x and other Games?
EdwardFMA/IchigoKurosaki - PSP Expert
Athlon 64 - Socket 939 - 3000+
1GB 333 DDR-Ram
Geforce 6600 GT PCI-Express

Orbis PSP Development
Open-Source Development
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

I just stuck this code at the beginning of snes9x to see if anything would break and as for as I can tell nothing did. So it seems we should be able to do just about anything with it.
This is awesome now will this work like a second CPU can the Main Core and Media Core work together to get faster speeds on snes9x and other Games?
Eventually. Some RPC system would have to be developed. Also, there may be a way to use the mebooter code to load homebrew code with the advantage of using the existing libraries. I looked, though, and it seems to me that the mebooter just contains a simple RPC system for just controlling the codecs and the VME.
User avatar
EdwardFMA
Posts: 40
Joined: Wed Jul 06, 2005 11:47 am

Post by EdwardFMA »

... *Crawls back into corner* ....
EdwardFMA/IchigoKurosaki - PSP Expert
Athlon 64 - Socket 939 - 3000+
1GB 333 DDR-Ram
Geforce 6600 GT PCI-Express

Orbis PSP Development
Open-Source Development
lebron23
Posts: 1
Joined: Sat Jul 16, 2005 11:01 am

Post by lebron23 »

[DELETED]
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

lebron23 wrote:[DELETED]
No software requests.
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

I've written a bootstrap and loader that will load an elf binary into the me address space and jump to the entry. There is a sample program included and a shell script to build it.

http://home.wi.rr.com/crazyz/meloader.tgz

Edit: better
yoyofr
Posts: 23
Joined: Sat Jun 25, 2005 7:08 pm
Location: paris
Contact:

Post by yoyofr »

am I the only one testing this ? ;-)

it seems it cannot compile with latest svn (update a few hours ago).
the debugfindmodule,... functions cannot be found.
same for kprintf sample ....

anyway, if we can get this to work it will be a major boost for lots of
homebrew here (codec, emulator core like snes'apu, ....)...
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

yoyofr wrote:am I the only one testing this ? ;-)
At least someone else is interested in it. :)
yoyofr wrote: it seems it cannot compile with latest svn (update a few hours ago).
the debugfindmodule,... functions cannot be found.
same for kprintf sample ....
That is in modmgr.c which was removed for some reason.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

modmgr.c was removed because you can just create a stub which defines the kernel calls and call the functions directly, no more hackery required. I was going to quickly port acrosss crazyc's small example to pspsdk for people to play with, that would obviously bring the stubs in as well.
yoyofr
Posts: 23
Joined: Sat Jun 25, 2005 7:08 pm
Location: paris
Contact:

Post by yoyofr »

ok, thx.
I'll play with it a bit now...

did you try to access main cpu memory from me ?
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

yoyofr wrote:ok, thx.
I'll play with it a bit now...

did you try to access main cpu memory from me ?
I've had problems with this. I'm working on cache flush to hopefully make it easier. Maybe it would be a good idea to make two new libraries in svn, maybe libmeinit for cpu side bootstrap and libme for a utility library and me specific libc functions.
Warren
Posts: 175
Joined: Sat Jan 24, 2004 8:26 am
Location: San Diego, CA

Post by Warren »

I'm very interested in the ME and other processors/accelerators in the PSP but I'm busy with work and getting Net stuff into PSPSDK. I will however work on getting ME stuff into PSPSDK after net stuff is in. I think it would be nice to have some more things done/figured out for ME before we put it in though, especially a good sample.
yoyofr
Posts: 23
Joined: Sat Jun 25, 2005 7:08 pm
Location: paris
Contact:

Post by yoyofr »

good.
right now I'm quite busy with psp gu... I'll have a look at me when
it will be in pspsdk then
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

yoyofr wrote:good.
right now I'm quite busy with psp gu... I'll have a look at me when
it will be in pspsdk then
Thanks to TyRaNiD, a very basic test, which compiles with PSPSDK, is in svn now. I've fixed a bug, now the loop runs more than once :-) but more research is needed.
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

I've gotten cache flush working and as expected, system ram is mapped at 0x88000000 and is all accessable. Local ram is mapped at 0x80000000. Video ram appears to be inaccessable, at least at the usual address.

Edit: and despite what sony's block diagram shows, the me has an fpu.
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

crazyc wrote:...
Edit: and despite what sony's block diagram shows, the me has an fpu.
could it be possible that both cores share one FPU. or did you check already (write to FPU register from main core, read the same FPU register from ME)?
infj
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Saotome wrote:
crazyc wrote:...
Edit: and despite what sony's block diagram shows, the me has an fpu.
could it be possible that both cores share one FPU. or did you check already (write to FPU register from main core, read the same FPU register from ME)?
You can't share the FPU, it's a coprocessor attached to each CPU individually.
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

Ok. I was just wondering, because of the block diagram. But maybe they just wanted to keep the diagram simple ;)
infj
Warren
Posts: 175
Joined: Sat Jan 24, 2004 8:26 am
Location: San Diego, CA

Post by Warren »

crazyc wrote:I've gotten cache flush working and as expected, system ram is mapped at 0x88000000 and is all accessable. Local ram is mapped at 0x80000000. Video ram appears to be inaccessable, at least at the usual address.

Edit: and despite what sony's block diagram shows, the me has an fpu.
Please keep the memory map in the wiki up to date as you discover new things.

http://wiki.ps2dev.org/psp:memory_map
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

Here's a tarball with a sample to dump the chunks of address space. It also includes the start of libraries for me init and C code running on the me. No psp libraries can be used on the me, due to the lack of kernel functions, except psplibc (not right now though, becuase sbrk is incompatible; until that is resolved, use newlib).

http://home.wi.rr.com/crazyz/melib.tgz
Klimru
Posts: 34
Joined: Sat Apr 09, 2005 7:29 am

Post by Klimru »

is this processor fast enough to say, play an mp3? i'm not aware of the specs on it
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Easily. It runs the same speed as the main CPU, unless I have misunderstood something.
Klimru
Posts: 34
Joined: Sat Apr 09, 2005 7:29 am

Post by Klimru »

maybe i'll try and get libmad to work on it
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Post by crazyc »

It's well suited to things like background music because of the lack of cache coherency. I haven't been able to tell if the audio hardware is directly accessable from it though. Note the sbrk in tarball is broken, here is a correction.

Code: Select all

#include <psptypes.h>
#include <sys/unistd.h>
#include <errno.h>

#define ME_HEAP_BOTTOM &#40;void *&#41;0x80000000
#define ME_HEAP_TOP &#40;void *&#41;0x80200000

extern int _me_stack_size;
static void *_me_heap_ptr = ME_HEAP_BOTTOM;

void *_sbrk&#40;ptrdiff_t incr&#41;
&#123;
	void *new_brk, *prev_brk = _me_heap_ptr;
	if&#40;incr&#41;
	&#123;
		new_brk = _me_heap_ptr + incr;
		if&#40;&#40;new_brk + _me_stack_size&#41; > ME_HEAP_TOP&#41;
		&#123;
			errno = ENOMEM;
			return &#40;void *&#41;-1;
		&#125;
		if&#40;new_brk < ME_HEAP_BOTTOM&#41;
			new_brk = ME_HEAP_BOTTOM;
		_me_heap_ptr = new_brk;
	&#125;
	return prev_brk;
&#125;
Edit: it looks like the exception handler location is set by loading cop0 register 25 (usually perfcnt) with the address of your handler.
Last edited by crazyc on Thu Jul 28, 2005 3:51 am, edited 1 time in total.
Klimru
Posts: 34
Joined: Sat Apr 09, 2005 7:29 am

Post by Klimru »

thats pretty much all i want it for is background music... hopefully an mp3. The decoding of the mp3 just kills the processing in the game i'm working on, so, running it on a seperate processor all together would be perfect assuming its fast enough.
Post Reply