Elf/Dol loader stub

Discussion in 'Wii - Emulation and Homebrew' started by arasium, Aug 11, 2009.

Aug 11, 2009

Elf/Dol loader stub by arasium at 10:46 AM (1,033 Views / 0 Likes) 4 replies

  1. arasium
    OP

    Member arasium GBAtemp Regular

    Joined:
    Mar 19, 2009
    Messages:
    187
    Location:
    Paris
    Country:
    France
    Hi, i've post a message on wiibrew but it seems that nobody on their forum can answer to me.

    Here is my problem:

    I've done a file browser that can load elf/dol files. The stub seems good because, when i want to quit the browser (wich is the loader), i return to the browser. I think everithing is normal:


    The boot app load the stub in 0x80001800 and the browser in 0x81330000.
    The boot app launch the code at the address 0x80001800 (so, the stub) wich itself load the code at 0x81330000 (the browser)
    The browser call "exit(0)" wich load the code at 0x80001800 (the stub). The stub is loading the browser so i return to the browser. Everything is OK.

    But, when i want to load an app from the loader, i load the binary code to 0x92000000 (MEM2). The dol/elf is succesfully loaded and launched. But, if i want to quit this homebrew with an "exit(0)", i've a DSI Exception ?!?!
    After some research, i think i've lost the stub or the browser from memory (i don't know how or why).
    Does someone know when the memory at 0x80001800 or 0x81330000 (So in MEM1) has been modified? Or, do i need to change my memory areas (for exemple, put the browser in mem 2 and load dol/elf in mem1)?
     
  2. WiiCrazy

    Member WiiCrazy Be water my friend!

    Joined:
    May 8, 2008
    Messages:
    2,391
    Location:
    Istanbul
    Country:
    Turkey
    Hmm, how do you put the loaded dol into mem2? Every dol already specifies where it wants to be laid out... I guess instead you are using MEM2 temporarily which is the proper way. You need to have some kind of relocation going on...

    Logically it seems to me, everything should be like this.

    1. Load dol using your browser into mem2
    2. Leave control from the browser (deinit stuff)
    3. Relocate the loaded dol using the stub (since dol may use the memory browser is using)
    4. Launch dol using stub
    5. Exit from homebrew will leave control to the stub
    6. Reload your browser using the stub
     
  3. arasium
    OP

    Member arasium GBAtemp Regular

    Joined:
    Mar 19, 2009
    Messages:
    187
    Location:
    Paris
    Country:
    France
    Thank you WiiCrazy [​IMG]

    I use the loadmii code to load my browser. So my boot app contains my browser and stub app (two arrays of bytes, done with bin2s). And it copies these bytes in specified addresses.

    I was thinking about something like you say. My english isn't very good so i will sum up with my words to be sure i've understood what you mean.

    An homebrew specifies itself the physical address he will use. So, it will still use the MEM1 memory instead of using the MEM2.
    So my browser will be overriden. To patch this, my stub need to reload the browser before launching it.

    You say i need to use the stub to load a dol. But i also need to use the stub to load thoe browser. So how can i know what element i need to load, the browser or the dol!

    So, i need to put my dol file into my sd (for exemple under sd:/testLoader/Browser.dol) and my stub has to open this file and copy it the the MEM1 before launching it.

    Do you have a sample code, because i think loadmii isn't very good?
     
  4. WiiCrazy

    Member WiiCrazy Be water my friend!

    Joined:
    May 8, 2008
    Messages:
    2,391
    Location:
    Istanbul
    Country:
    Turkey
    Well actually loadmii works as much as how you want it to work. Question is, in what aspect are you changing it? To put it another way, what feature are you integrating into loadmii that breaks it?

    I guess loadmii can't reload itself if an app uses MEM2, can't see any fat code in the stub. Homebrew channel stub on the other way reloads itself from nand.

    It seems loadmii has two parts.... reloadingstub and loader... those two are binary injected into another application... boot app, this just copies loader to mem2 and stub to 0x80001800 area and calls the stub...
    stub then loads the loader from MEM2 into MEM1...

    But... how an exit from the loaded dol causes the reloading stub to execute... that I don't know... possibly stub has special settings in the makefile so that ogc calls the stub when the loaded dol exits...

    If the loader dol still in MEM2 then there is no problem for the stub to load the loader...

    So to answer your original question, you need to modify the stub so that it doesn't rely on a copy of the loader being on MEM2. Maybe using self contained fat code or making your application a channel and using nand access... dunno...
     
  5. arasium
    OP

    Member arasium GBAtemp Regular

    Joined:
    Mar 19, 2009
    Messages:
    187
    Location:
    Paris
    Country:
    France
    Ok, i understand.

    I will report here my results.

    Thank you WiiCrazy, your answer will help us a lot.
     

Share This Page