Upload Tizen:Base source
[external/binutils.git] / ld / testsuite / ld-mips-elf / mips16-pic-1.inc
1         # Declare a function called NAME and an __fn_NAME stub for it.
2         # Make the stub use la_TYPE to load the the target address into $2.
3         .macro  stub,name,type
4         .set    nomips16
5         .section .mips16.fn.\name, "ax", @progbits
6         .ent    __fn_\name
7 __fn_\name:
8         la_\type \name
9         mfc1    $4,$f12
10         jr      $2
11         nop
12         .end    __fn_\name
13
14         .set    mips16
15         .text
16         .ent    \name
17 \name:
18 __fn_local_\name:
19         jr      $31
20         nop
21         .end    \name
22         .endm
23
24         # Like stub, but ensure NAME is a local symbol.
25         .macro  lstub,name,type
26         stub    \name, \type
27         .equ    local_\name,1
28         .endm
29
30         # Like stub, but ensure NAME is a hidden symbol.
31         .macro  hstub,name,type
32         .globl  \name
33         .hidden \name
34         stub    \name, \type
35         .endm
36
37         # Like lstub, but make the MIPS16 function global rather than local.
38         .macro  gstub,name,type
39         .globl  \name
40         stub    \name, \type
41         .endm
42
43         # Use an absolute sequence to load NAME into a register.
44         .macro  la_noshared,name
45         lui     $2,%hi(\name)
46         addiu   $2,$2,%lo(\name)
47         .endm
48
49         # Use the normal PIC sequence to load __fn_local_NAME into $2
50         # and emit a dummy relocation against NAME.  This macro is always
51         # used at the start of a function.
52         .macro  la_shared,name
53         .reloc  0,R_MIPS_NONE,\name
54         .cpload $25
55         la      $2,__fn_local_\name
56         .endm
57
58         # Use TYPE (either LSTUB, HSTUB or GSTUB) to define functions
59         # called a_NAME and b_NAME.  The former uses absolute accesses
60         # and the latter uses PIC accesses.
61         .macro  decl,name,type
62         \type   a_\name, noshared
63         \type   b_\name, shared
64         .endm
65
66         # Emit the MIPS16 PIC sequence for setting $28 from $25.
67         # Make the value of $25 available in $2 as well.
68         .macro  cpload_mips16
69         li      $2,%hi(_gp_disp)
70         addiu   $3,$pc,%lo(_gp_disp)
71         sll     $2,16
72         addu    $2,$2,$3
73         move    $28,$2
74         .endm
75
76         # Likewise, but for non-MIPS16 code.
77         .macro  cpload_nomips16
78         .cpload $25
79         move    $2,$28
80         .endm
81
82         # Start a PIC function in ISA mode MODE, which is either "mips16"
83         # or "nomips16".
84         .macro  pic_prologue,mode
85         cpload_\mode
86         addiu   $sp,$sp,-32
87         sw      $2,16($sp)
88         sw      $31,20($sp)
89         .endm
90
91         # Use a PIC function to call NAME.
92         .macro  pic_call,name,mode
93         .ifdef  local_\name
94         .ifc    \mode,mips16
95         lw      $2,%got(__fn_local_\name)($2)
96         addiu   $2,%lo(__fn_local_\name)
97         .else
98         lw      $2,%got(\name)($2)
99         addiu   $2,%lo(\name)
100         .endif
101         .else
102         lw      $2,%call16(\name)($2)
103         .endif
104         jalr    $2
105         move    $25,$2
106         lw      $2,16($sp)
107         move    $28,$2
108         .endm
109
110         # Finish a PIC function started by pic_prologue.
111         .macro  pic_epilogue
112         lw      $2,20($sp)
113         jr      $2
114         addiu   $sp,$sp,32
115         .endm
116
117         # Use PIC %call16 sequences to call a_NAME and b_NAME.
118         # MODE selects the ISA mode of the code: either "mips16"
119         # or "nomips16".
120         .macro  callpic,name,mode
121         .text
122         .set    \mode
123         .ent    callpic_\name\()_\mode
124 callpic_\name\()_\mode:
125         pic_prologue \mode
126         pic_call     a_\name,\mode
127         pic_call     b_\name,\mode
128         pic_epilogue
129         .end    callpic_\name\()_\mode
130         .endm
131
132         # Use absolute jals to call a_NAME and b_NAME.  MODE selects the
133         # ISA mode of the code: either "mips16" or "nomips16".
134         .macro  jals,name,mode
135         .text
136         .set    \mode
137         .ent    jals_\name\()_\mode
138 jals_\name\()_\mode:
139         .option pic0
140         jal     a_\name
141         nop
142
143         jal     b_\name
144         nop
145         .option pic2
146         .end    jals_\name\()_\mode
147         .endm