| Class | Voodoo::MIPSGasGenerator |
| In: |
voodoo/generators/mips_gas_generator.rb
|
| Parent: | CommonCodeGenerator |
The MIPS code generator generates assembly code for use with the GNU assembler.
The first four arguments are passed in the registers $4 through $7. Any additional arguments are passed on the stack, starting at $sp + 16. Words $sp through $sp + 12 will be available for the called function to use. $sp will always be a multiple of 8.
The return address for the called function is passed in $31.
When performing a position-independent call, the address of the called function is passed in $25.
The called function will store its return value in $2.
The called function is required to preserve the values of registers $16 through $23 and register $30.
This calling convention is compatible with the System V ELF ABI.
Call frames have the following layout:
When a function is called, it receives a stack frame that looks like the following:
: old frame argn : arg4 empty3 empty2 empty1 empty0 <-- $sp points here
The function prologue of functions generated by this code generator creates activation frames that look as follows:
: old frame argn : arg4 arg3 arg2 arg1 arg0 return address pointer to Global Offset Table local0 : local7 local8 : localn padding <— $sp points here
In words:
The four empty slots provided by the caller are used to store arguments 0 through 3 (originally passed in $4 through $7), if necessary.
The stack frame created below the four slots provided by the caller contains the following data, in order:
In accordance with the System V ELF ABI for MIPS, the pointer to the global offset table is calculated as follows:
$gp = _gp_disp + $25
where $gp is the register to store the pointer, $25 is the register holding the address of the called function, and _gp_disp is the offset between the beginning of the function and the global offset table.
Return the register in which the nth (0-based) argument is stored, or nil if not stored in a register
Load a value into a register. Returns the name of the register. If the value was already in a register, the name of that register is returned. Else, the value is loaded into a register and the name of that register is returned. The register to use in that case may be specified using the optional second argument.
Return the offset from $sp at which the nth (0-based) local variable is stored. For register locals this is the offset at which the saved value (from the calling function) is stored.