Welcome! Log In Create A New Profile

Advanced

try to understant loadmii stub

Posted by arasium 
try to understant loadmii stub
August 05, 2009 05:12PM
Hi, i've read the loadmii stub and i don't understand the stub very well.

This stub doesn't contains a classic main entry. Can we use a classic main like "int main()" or do we absolutely need to use a function that return a void?

And then, if i need a void instead of an int, how can i compile this? When i try, i've a linker error!!

Thank you.
Re: try to understant loadmii stub
August 05, 2009 05:30PM
if you can post the actual error that'd be more helpful. My wii main functions always return ints so it doesn't have to be a void

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

int main(int argc, char **argv)
void main(int argc, char **argv)

should all work just fine
Re: try to understant loadmii stub
August 05, 2009 10:00PM
You can find the code in loadmii (google code). It's the stub code.

In the code, there is only :

void _main()
{
  ...
}

So, no main function.... It can be compiled with the makefile delivered in with loadmii, but i don't understand this makefile.
So i've tried with a classic makefile and the error say that no main method was found (for me it's normal :)). So i want to understand why loadmii do like that and how he can compile.
Re: try to understant loadmii stub
August 06, 2009 02:39PM
The reloading stub has some assembly code files. One of these, crt0.S is what's calling "_main"

        # Clear the BSS section!
        lis             r3,__sbss_start@h
        ori             r3,r3,__sbss_start@l
        li              r4,0
        lis             r5,__bss_end@h
        ori             r5,r5,__bss_end@l
        sub             r5,r5,r3
        bl              _memset

        bl      __bat_config
        bl      _main # Branch to the user code!

libogc includes a crt0.S file which is automatically linked against your program. In this case, he supplied his own most likely being that the libogc one doesn't satisfy the needs for his application. But then, I don't know for sure. Anyway, that's the reason the function is called _main.

edit: oh and another reason, since the stub is linked to the loader, this prevents the whole .dol from having two main() functions since the loader has one. That's probably why it's named "_main" in the first place



Edited 1 time(s). Last edit at 08/06/2009 02:48PM by MrPeanut.
Re: try to understant loadmii stub
August 06, 2009 02:44PM
ok, thank you.

So, know my question his: does someone know why :) ?
Re: try to understant loadmii stub
August 10, 2009 03:38PM
So, up :)

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?
Sorry, only registered users may post in this forum.

Click here to login