GP2X Dangerous Linux Hacking Code

Discussion in 'General Discussions' started by Squidge, Jun 20, 2006.

  1. Franxis

    Franxis MAME 4 ALL

    Joined:
    Aug 22, 2004
    Messages:
    788
    Location:
    Spain
    I haven't measured it exactly but it is visually noticeable and easy to add to your code... It is only needed to call the MMU hacking table function after all mmap() done in your application. In Rlyeh minimal library it is needed to add the call at the end of the minimal library initialization function.

    In MAME memory access to
    - Video buffers.
    - Extended memory (when loading biggest NeoGeo games).
    changes from not cached to cached memory.

    B)
     
    Last edited by a moderator: Dec 17, 2015
  2. synkro

    synkro 0xdeadbeef

    Joined:
    Aug 26, 2003
    Messages:
    779
    Location:
    Germany
    is this already summed up in the wiki?
     
  3. pepone

    pepone Pouet! Pouet! Do want!

    Joined:
    Oct 14, 2005
    Messages:
    504
    Damn, after getting it correctly working, it give me a boost of 10 to 20fps in gngeo :blink:
     
  4. dockthepod

    dockthepod Member

    Joined:
    Jun 15, 2006
    Messages:
    250
    :D
     
    Last edited by a moderator: Dec 17, 2015
  5. pepone

    pepone Pouet! Pouet! Do want!

    Joined:
    Oct 14, 2005
    Messages:
    504
    But...
    It work very well when I launch gngeo from a telnet, but it crash very often when I use Selector or Rage2x :(
     
    Last edited by a moderator: Dec 17, 2015
  6. Vimacs

    Vimacs Don't be evil!

    Joined:
    Oct 23, 2003
    Messages:
    5,211
    Location:
    Germany
    10-20fps? OMFG!
    I wouldnt ever have guessed it would do so much of a difference.
    I hope you get the issues sorted out.
     
  7. pepone

    pepone Pouet! Pouet! Do want!

    Joined:
    Oct 14, 2005
    Messages:
    504
    Yes, I'm really surprised too. it seems that blitting a software surface to the screen have big penalty.
    But to be useful, I have to make it more stable.
     
    Last edited by a moderator: Dec 17, 2015
  8. DaveC

    DaveC Internal Development

    Joined:
    Mar 4, 2004
    Messages:
    9,208

    10-20 fps? holy shit!

    Sounds awesome..
     
    Last edited by a moderator: Dec 17, 2015
  9. yaustar

    yaustar UK GP32 & GP2X Owner

    Joined:
    Oct 18, 2003
    Messages:
    2,714
    Location:
    UK
    Isnt that almost 30% speed increase?
     
  10. gaterooze

    gaterooze Coltrane Sundia

    Joined:
    Aug 7, 2004
    Messages:
    2,723
    You hackin' dudes are crazy-cool B)
     
  11. pepone

    pepone Pouet! Pouet! Do want!

    Joined:
    Oct 14, 2005
    Messages:
    504
    I think I've got it working correctly, without crash.
    What I've do is to put a 1sec pause at a specefic point:

    Code:
    lseek (gp2x_dev_mem, 0x6ec00, SEEK_SET);
    write (gp2x_dev_mem, &newc1, 4);
    write (gp2x_dev_mem, &newc2, 4);	
    
    SDL_Delay(1000);
    
    ttb = myuname(name);
    
    
    I didn't get any crash with that :D

    a beta is available here:
    http://m.peponas.free.fr/gngeo/download/gngeo2x_0.6.12c.zip

    PS: initial loading can be a little long (3/5 sec) and if the mmu patch fail, then you will no get no performance gain.
     
  12. Franxis

    Franxis MAME 4 ALL

    Joined:
    Aug 22, 2004
    Messages:
    788
    Location:
    Spain
    Great! The initial loading will be a lot faster if you comment the trace to the terminal (//printf()...).
     
    Last edited by a moderator: Dec 17, 2015
  13. Franxis

    Franxis MAME 4 ALL

    Joined:
    Aug 22, 2004
    Messages:
    788
    Location:
    Spain
    I'm having troubles patching the mmu table. Sometimes the read() in DecodeCoarse is ok and sometimes bad... :(

    Still investigating... :unsure:
     
  14. pepone

    pepone Pouet! Pouet! Do want!

    Joined:
    Oct 14, 2005
    Messages:
    504
    try the delay trick I use (just before ttb=myuname), it's seems that there is some sort of cache that prevent the uname routine to be correctly overwrited. I tested it with a delay of 200ms and it work great so far.
     
    Last edited by a moderator: Dec 17, 2015
  15. Waninkoko

    Waninkoko Still Fresh

    Joined:
    Jan 26, 2006
    Messages:
    25
    Wow! 15 fps more with this hack!
    CONGRATULATIONS SQUIDGE

    I don't know if I have used this hack correctly. I have made a function that's executed only one time after SDL is initialised.

    Code:
    void mmuhack()
    {
    				initphys();
    		volatile unsigned int *myBuf = trymmap((void *)0, 65536, 3, 1, memfd, 0x03000000);
    		volatile unsigned int *secbuf = (unsigned int *)malloc(204800);
    
    		printf("mmaped 0x03000000 buffer @ VA: %08X malloc'd buffer @ VA: %08X\n", myBuf, secbuf);
    
    		hackpgtable();
    
    It's this correct?
    And yes, I can improve it a bit xDD

    PD: I'm using MMap function written in ASM by Dzz.
     
  16. rlyeh

    rlyeh Certified Guru

    Joined:
    Mar 25, 2003
    Messages:
    277
    Location:
    49°9' East latitude, 126°43' South longitude: in y

    Will this work too? I cant test it right now, im not at home

    Code:
    
    volatile u32 temp1,temp2;
    
    lseek (gp2x_dev_mem, 0x6ec00, SEEK_SET);
    read (gp2x_dev_mem, &temp1, 4);
    read (gp2x_dev_mem, &temp2, 4);
    
    lseek (gp2x_dev_mem, 0x6ec00, SEEK_SET);
    write (gp2x_dev_mem, &newc1, 4);
    write (gp2x_dev_mem, &newc2, 4);	
    
    while(temp1 != newc1 && temp2 != newc2);
    
    ttb = myuname(name);
    
    

    PS: Squidge, amazing work as usual :) Congrats!
     
    Last edited by a moderator: Dec 17, 2015
  17. Squidge

    Squidge Certified Guru

    Joined:
    Nov 16, 2003
    Messages:
    8,495
    Location:
    UK
    :)

    rlyeh: I don't think that'll work. I believe the problem to be something to do with caching, and Linux seems to do a task swap every 50ms, so you can either wait 100ms to be on the safe side, or flush the caches yourself using one of the special swi calls in the 0x9f000 range - check the kernel source for the exact number and the parameters. Of the two, I'd say waiting 100ms or so is the easiest :)
     
  18. Franxis

    Franxis MAME 4 ALL

    Joined:
    Aug 22, 2004
    Messages:
    788
    Location:
    Spain
    I surrender... It runs randomly for me... :(
     
  19. pepone

    pepone Pouet! Pouet! Do want!

    Joined:
    Oct 14, 2005
    Messages:
    504
    Something else I did to get it to work: I've put the myuname function in a separate asm file. It seems that with -02 or -03, gcc does some weird thing with it, and then myuname doesn't return the correct ttb.
     
    Last edited by a moderator: Dec 17, 2015
  20. Drag

    Drag Member

    Joined:
    Jan 11, 2004
    Messages:
    371
    Location:
    USA
    Good work, Squidge!

    Unfortunately, I have pretty much 0 experience with anything outside of game programming with SDL, so I have no idea how to implement this into an SDL program. Would Waninkoko's solution work for me?
     

Share This Page

Loading...