matt-kempster / m2c

A MIPS and PowerPC decompiler.
GNU General Public License v3.0
386 stars 46 forks source link

Recognize MWCCEPPC 1.3.2-specific `_savegpr_*`/`_restgpr_*` runtime helpers #242

Closed r-burns closed 1 year ago

r-burns commented 1 year ago

MWCC EPPC 1.3.2 inserts calls to _savegpr_*/_restgpr_* helper jump points to save/restore callee-save registers. Example:

https://github.com/doldecomp/kar/blob/45ef055d8ed7b6f0479564d8b4c9c5c1f225f1e5/asm/sysdolphin/tobj.s#L42

These runtime "functions" are defined here:

https://github.com/doldecomp/kar/blob/45ef055d8ed7b6f0479564d8b4c9c5c1f225f1e5/asm/runtime/runtime.s#L89-L209

Note that these are not ordinary functions as they preserve all caller-save registers. Essentially, m2c needs to know that

bl _savegpr_27

is exactly equivalent to

stw r27, -0x14(r11)
stw r28, -0x10(r11)
stw r29, -0xc(r11)
stw r30, -8(r11)
stw r31, -4(r11)

(and so forth for the other save/restore helpers)