Trampoline implementation for MIPS

kernel coder lhrkernelcoder@gmail.com
Fri Sep 29 09:07:00 GMT 2006


hi,
    I'm having some trouble while understanding the generated assembly
code for trampoline by mips back-end.

Following is the code for which i'm trying to undertsand the generated
trampoline code.

int foo(int (*f)()){
        (*f)();
}
main(){
        int i;
        int g(){printf("hello,%d",i);}
        foo(g);
}

Parts of generated assembly code which are confusing are

$LTRAMP0:
        .word   0x03e00821              # move   $1,$31
        .word   0x04110001              # bgezal $0,.+8
        .word   0x00000000              # nop
        .word   0x8fe30014              # lw     $3,20($31)
        .word   0x8fe20018              # lw     $2,24($31)
        .word   0x0060c821              # move   $25,$3 (abicalls)
        .word   0x00600008              # jr     $3
        .word   0x0020f821              # move   $31,$1
        .word   0x00000000              # <function address>
        .word   0x00000000              # <static chain value>
        .globl  _flush_cache

main:
        - - - - - - - - - - - -
        addiu   $sp,$sp,-80
        sw      $31,72($sp)
        sw      $fp,68($sp)
        sw      $16,64($sp)
        move    $fp,$sp
        addiu   $2,$fp,20
        addiu   $16,$2,4
        lui     $2,%hi($LTRAMP0)
        move    $3,$16
        addiu   $2,$2,%lo($LTRAMP0)
        li      $5,40                   # 0x28
        move    $4,$2
        jal     memcpy
        nop

        lui     $2,%hi(g.1238)
        addiu   $2,$2,%lo(g.1238)
        sw      $2,32($16)
        move    $3,$16
        li      $4,40                   # 0x28
        li      $5,3                    # 0x3
        jal     _flush_cache
        nop

        addiu   $2,$fp,20
        addiu   $2,$2,4
        move    $3,$2
        jal     foo
        nop


A bit of explaination of above code will be helpful



More information about the Gcc mailing list