PS3 MAPI Dynarec Lib

Building on @TheRouLetteBoi's page_allocate additions in Mamba/Cobra, I've also added support for page freeing which fixes the issue where program crashes on exit. Any program that uses page_allocate will need to keep track of a page_table which is the kernel page address to user process page address mapping. See below code example of its usage that's based off of TheRouLetteBoi's and Crystal's example.

Code:
#include <sys/process.h>
#include <ps3mapi_ps3_lib.h>

#define KB(n) (1024*n)
#define MB(n) (1048576*n)

char fret5[32] = {0xfb, 0xe1, 0xff, 0xf8, 0xf8, 0x21, 0xff, 0xc1, 0x7c, 0x3f, 0x0b, 0x78, 0x39, 0x20, 0x00, 0x05,
          0x7d, 0x23, 0x4b, 0x78, 0x38, 0x3f, 0x00, 0x40, 0xeb, 0xe1, 0xff, 0xf8, 0x4e, 0x80, 0x00, 0x20};

uint64_t page_table[2];

int main(int argc, char *argv[]) {

  int ret = ps3mapi_page_allocate(sysProcessGetPid(), KB(650), PAGE_SIZE_AUTO, 0x2F, 1, page_table);

  // After ps3mapi_page_allocate return
  // page_table[0] holds program page_address mapping
  // page_table[1] holds kernel page_address allocation

  if (ret != 0)
  {
    printf("failed to allocate page\n");
    return;
  }

  memcpy(page_table[0], fret5, sizeof(char)*32);
  int(*func)() = (int (*)())&page_table[0];
  int result = func();
  printf("fret5 result: %d\n", result);

  ps3mapi_process_page_free(sysProcessGetPid(), 0x2F, page_table);

  return 0;
}

With some minor modifications to Retroarch's picodrive, I was able to get dynarec working which significantly sped up performance for 32x and Sega CD.

Star Wars Arcade runs at full speed no problem :)
GvpwT3x.png


Source code for these changes can be found below. Note that you will need the Mamba payload changes to get it to run after compiling.

https://github.com/OsirizX/Mamba/tree/page_table
https://github.com/OsirizX/ps3mapi-lib/tree/page_free
https://github.com/OsirizX/picodrive/tree/ps3_dynarec

credits: @TheRouLetteBoi, @Crystal, @bucanero

@aldostools Could you make that changes to your Mamba?
 
Building on @TheRouLetteBoi's page_allocate additions in Mamba/Cobra, I've also added support for page freeing which fixes the issue where program crashes on exit. Any program that uses page_allocate will need to keep track of a page_table which is the kernel page address to user process page address mapping. See below code example of its usage that's based off of TheRouLetteBoi's and Crystal's example.

Code:
#include <sys/process.h>
#include <ps3mapi_ps3_lib.h>

#define KB(n) (1024*n)
#define MB(n) (1048576*n)

char fret5[32] = {0xfb, 0xe1, 0xff, 0xf8, 0xf8, 0x21, 0xff, 0xc1, 0x7c, 0x3f, 0x0b, 0x78, 0x39, 0x20, 0x00, 0x05,
          0x7d, 0x23, 0x4b, 0x78, 0x38, 0x3f, 0x00, 0x40, 0xeb, 0xe1, 0xff, 0xf8, 0x4e, 0x80, 0x00, 0x20};

uint64_t page_table[2];

int main(int argc, char *argv[]) {

  int ret = ps3mapi_page_allocate(sysProcessGetPid(), KB(650), PAGE_SIZE_AUTO, 0x2F, 1, page_table);

  // After ps3mapi_page_allocate return
  // page_table[0] holds program page_address mapping
  // page_table[1] holds kernel page_address allocation

  if (ret != 0)
  {
    printf("failed to allocate page\n");
    return;
  }

  memcpy(page_table[0], fret5, sizeof(char)*32);
  int(*func)() = (int (*)())&page_table[0];
  int result = func();
  printf("fret5 result: %d\n", result);

  ps3mapi_process_page_free(sysProcessGetPid(), 0x2F, page_table);

  return 0;
}

With some minor modifications to Retroarch's picodrive, I was able to get dynarec working which significantly sped up performance for 32x and Sega CD.

Star Wars Arcade runs at full speed no problem :)
GvpwT3x.png


Source code for these changes can be found below. Note that you will need the Mamba payload changes to get it to run after compiling.

https://github.com/OsirizX/Mamba/tree/page_table
https://github.com/OsirizX/ps3mapi-lib/tree/page_free
https://github.com/OsirizX/picodrive/tree/ps3_dynarec

credits: @TheRouLetteBoi, @Crystal, @bucanero

well done OsirisX, ps3mapi_process_page_free was long over due.
 
@OsirisX
"Should work once the system has been updated with the latest Cobra changes."

Do you mean a CFW update? I prefer to stay on Rebug 4.86 considering the issues I've heard about the EvilNat CFW.
 
@OsirisX
"Should work once the system has been updated with the latest Cobra changes."

Do you mean a CFW update? I prefer to stay on Rebug 4.86 considering the issues I've heard about the EvilNat CFW.

yes, it will require a CFW update, or more accurate, your CFW will need to be updated to have a new COBRA payload. For example you have Cobra 8.2 with rebug 4.86, someone would have to build a rebug 4.86 with "Cobra 8.4" with the new PS3MAPI call that OsirisX added.

The same for HEN ps3s, you'll need a new HEN payload with the updated Cobra that includes this ps3mapi change. With HEN it should be easier as you'd only need to update the HEN package and that's all.
 
what about the new cobra 8.4 on 4.84.x drex/rex/etc? (4.84.5?)
evilnat 4.89.x hasn't been tested by me yet...
hope to have more info soon(TM)
 
Like the one in ManaGuns?

In the past I have unloaded it, and doing so caused webMAN games to disappear.

webMAN Games disappear when you start XMB with Cobra disabled.
But if you load MAMBA at startup using /dev_hdd0/boot_plugins_kernel_nocobra.txt the system acts like booting Cobra but using a different payload.

EDIT:
I corrected the file name.
 
@OsirisX , assuming that PAGE_SIZE_AUTO is 0x100 (from a previous post of @TheRouLetteBoi ) i compiled pico drive for RetraoArchCE. Now i have to update my PS3...
Do you have compiled using:
Code:
make -f Makefile.libretro platform=ps3 use_sh2drc=1
?
use_sh2drc turn on dynarec....
 
I have updated my ps3mapidyn.h (it works with old Sony SDK, too) to compile pico with dynarec by @OsirisX.
@OsirisX , @aldostools, @bucanero where is defined PAGE_SIZE_AUTO, i can't find it....
Code:
ps3mapi_process_page_allocate(sysProcessGetPid(), size, PAGE_SIZE_AUTO, 0x2F, 1, page_table);

the PAGE_SIZE_AUTO value is defined in the ps3mapi library include. I have merged OsirisX PR so now it's available on the main brach:
https://github.com/bucanero/ps3mapi...d81a2825de8bb0/include/ps3mapi_ps3_lib.h#L140

btw, the value is PAGE_SIZE_AUTO = 0
 
Last edited:
where is defined PAGE_SIZE_AUTO, i can't find it....
Code:
ps3mapi_process_page_allocate(sysProcessGetPid(), size, PAGE_SIZE_AUTO, 0x2F, 1, page_table);

#define PAGE_SIZE_AUTO 0

The parameter is page_size. When it is 0, the payload calculates the size of the memory to allocate based on the variable size.

upload_2022-11-17_9-54-0.png
 
Back
Top