// this asm prints HELLO! to uart followed by a line feed
// was compiled with GCC
static unsigned int size_execbin = 96;
static unsigned char execbin[] = {
	0x7d, 0x88, 0x02, 0xa6, 0x38, 0x60, 0x00, 0x68, 0x48, 0x00, 0x00, 0x3d, 0x38, 0x60, 0x00, 0x65, 
	0x48, 0x00, 0x00, 0x35, 0x38, 0x60, 0x00, 0x6c, 0x48, 0x00, 0x00, 0x2d, 0x38, 0x60, 0x00, 0x6c, 
	0x48, 0x00, 0x00, 0x25, 0x38, 0x60, 0x00, 0x6f, 0x48, 0x00, 0x00, 0x1d, 0x38, 0x60, 0x00, 0x21, 
	0x48, 0x00, 0x00, 0x15, 0x38, 0x60, 0x00, 0x0a, 0x48, 0x00, 0x00, 0x0d, 0x7d, 0x88, 0x03, 0xa6, 
	0x4e, 0x80, 0x00, 0x20, 0x3c, 0x80, 0x7f, 0xea, 0x54, 0x63, 0xc0, 0x0e, 0x90, 0x64, 0x10, 0x14, 
	0x80, 0x64, 0x10, 0x18, 0x54, 0x63, 0x01, 0x8d, 0x41, 0x82, 0xff, 0xf8, 0x4e, 0x80, 0x00, 0x20, 
};

UINT32 __declspec(naked) JumpFunct(u32* dest)
{
	__asm
	{
		mtctr r3
		bctr
	}
}

// there are various ways to get code into image space for execution from a xex
// which happens to be (virtual) from 0x80000000 to 0x9FFFFFFF
VOID tryExec()
{
	// direct jump into the buffer above
	 cprintf("addr: %08x\n", execbin);
	JumpFunct((u32*)(execbin)); // direct jump works!

	// encrypted alloc, copy buffer above to XEncryptedAlloc buffer works too
	// but there is CPU hit to call HV to allocate and L2 hit when changing data in this buffer
	u32* encPtr = (u32*)XEncryptedAlloc(0x10000);
	XMemCpy(encPtr, execbin, size_execbin);
	__dcbst(0, encPtr);
	__sync();
	cprintf("encr addr: %08x\n", encPtr);
	JumpFunct(encPtr);

	// using PSP VRAM lib from Raphael to manage a static buffer that is compiled
	// globally thus is a part of image memory space
	// *** SEE bram.cpp defines near the top if you need to have more memory or bigger block/alignment sizes!!! ***
	u32* bPtr = (u32*)balloc(0x10000);
	XMemCpy(bPtr, execbin, size_execbin);
	__dcbst(0, bPtr);
	__sync();
	cprintf("bPtr addr: %08x\n", bPtr);
	JumpFunct(bPtr);
}
