]>
Commit | Line | Data |
---|---|---|
b3f8d95d MM |
1 | /* Miscellaneous BPABI functions. |
2 | ||
5624e564 | 3 | Copyright (C) 2003-2015 Free Software Foundation, Inc. |
b3f8d95d MM |
4 | Contributed by CodeSourcery, LLC. |
5 | ||
6 | This file is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU General Public License as published by the | |
748086b7 | 8 | Free Software Foundation; either version 3, or (at your option) any |
b3f8d95d MM |
9 | later version. |
10 | ||
b3f8d95d MM |
11 | This file is distributed in the hope that it will be useful, but |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | Under Section 7 of GPL version 3, you are granted additional |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
b3f8d95d | 24 | |
158ef346 CB |
25 | .cfi_sections .debug_frame |
26 | ||
6f0668cf RE |
27 | #ifdef __ARM_EABI__ |
28 | /* Some attributes that are common to all routines in this file. */ | |
29 | /* Tag_ABI_align_needed: This code does not require 8-byte | |
30 | alignment from the caller. */ | |
31 | /* .eabi_attribute 24, 0 -- default setting. */ | |
32 | /* Tag_ABI_align_preserved: This code preserves 8-byte | |
33 | alignment in any callee. */ | |
34 | .eabi_attribute 25, 1 | |
35 | #endif /* __ARM_EABI__ */ | |
36 | ||
b3f8d95d MM |
37 | #ifdef L_aeabi_lcmp |
38 | ||
39 | ARM_FUNC_START aeabi_lcmp | |
ad1ec76f PB |
40 | cmp xxh, yyh |
41 | do_it lt | |
42 | movlt r0, #-1 | |
43 | do_it gt | |
44 | movgt r0, #1 | |
45 | do_it ne | |
46 | RETc(ne) | |
47 | subs r0, xxl, yyl | |
48 | do_it lo | |
49 | movlo r0, #-1 | |
50 | do_it hi | |
51 | movhi r0, #1 | |
b3f8d95d MM |
52 | RET |
53 | FUNC_END aeabi_lcmp | |
54 | ||
55 | #endif /* L_aeabi_lcmp */ | |
56 | ||
57 | #ifdef L_aeabi_ulcmp | |
58 | ||
59 | ARM_FUNC_START aeabi_ulcmp | |
60 | cmp xxh, yyh | |
5b3e6663 | 61 | do_it lo |
b3f8d95d | 62 | movlo r0, #-1 |
5b3e6663 | 63 | do_it hi |
b3f8d95d | 64 | movhi r0, #1 |
5b3e6663 | 65 | do_it ne |
b3f8d95d MM |
66 | RETc(ne) |
67 | cmp xxl, yyl | |
5b3e6663 | 68 | do_it lo |
b3f8d95d | 69 | movlo r0, #-1 |
5b3e6663 | 70 | do_it hi |
b3f8d95d | 71 | movhi r0, #1 |
5b3e6663 | 72 | do_it eq |
b3f8d95d MM |
73 | moveq r0, #0 |
74 | RET | |
75 | FUNC_END aeabi_ulcmp | |
76 | ||
77 | #endif /* L_aeabi_ulcmp */ | |
78 | ||
0c23e1be JB |
79 | .macro test_div_by_zero signed |
80 | /* Tail-call to divide-by-zero handlers which may be overridden by the user, | |
81 | so unwinding works properly. */ | |
82 | #if defined(__thumb2__) | |
83 | cbnz yyh, 1f | |
84 | cbnz yyl, 1f | |
85 | cmp xxh, #0 | |
86 | do_it eq | |
87 | cmpeq xxl, #0 | |
88 | .ifc \signed, unsigned | |
89 | beq 2f | |
90 | mov xxh, #0xffffffff | |
91 | mov xxl, xxh | |
92 | 2: | |
93 | .else | |
94 | do_it lt, t | |
95 | movlt xxl, #0 | |
96 | movlt xxh, #0x80000000 | |
97 | do_it gt, t | |
98 | movgt xxh, #0x7fffffff | |
99 | movgt xxl, #0xffffffff | |
100 | .endif | |
101 | b SYM (__aeabi_ldiv0) __PLT__ | |
102 | 1: | |
103 | #else | |
104 | /* Note: Thumb-1 code calls via an ARM shim on processors which | |
105 | support ARM mode. */ | |
106 | cmp yyh, #0 | |
107 | cmpeq yyl, #0 | |
108 | bne 2f | |
109 | cmp xxh, #0 | |
110 | cmpeq xxl, #0 | |
111 | .ifc \signed, unsigned | |
112 | movne xxh, #0xffffffff | |
113 | movne xxl, #0xffffffff | |
114 | .else | |
115 | movlt xxh, #0x80000000 | |
116 | movlt xxl, #0 | |
117 | movgt xxh, #0x7fffffff | |
118 | movgt xxl, #0xffffffff | |
119 | .endif | |
120 | b SYM (__aeabi_ldiv0) __PLT__ | |
121 | 2: | |
122 | #endif | |
123 | .endm | |
124 | ||
c9dae335 CB |
125 | /* we can use STRD/LDRD on v5TE and later, and any Thumb-2 architecture. */ |
126 | #if (defined(__ARM_EABI__) \ | |
127 | && (defined(__thumb2__) \ | |
128 | || (__ARM_ARCH >= 5 && defined(__TARGET_FEATURE_DSP)))) | |
129 | #define CAN_USE_LDRD 1 | |
130 | #else | |
131 | #define CAN_USE_LDRD 0 | |
132 | #endif | |
133 | ||
134 | /* set up stack from for call to __udivmoddi4. At the end of the macro the | |
135 | stack is arranged as follows: | |
136 | sp+12 / space for remainder | |
137 | sp+8 \ (written by __udivmoddi4) | |
138 | sp+4 lr | |
139 | sp+0 sp+8 [rp (remainder pointer) argument for __udivmoddi4] | |
140 | ||
141 | */ | |
142 | .macro push_for_divide fname | |
143 | #if defined(__thumb2__) && CAN_USE_LDRD | |
144 | sub ip, sp, #8 | |
145 | strd ip, lr, [sp, #-16]! | |
146 | #else | |
147 | sub sp, sp, #8 | |
148 | do_push {sp, lr} | |
149 | #endif | |
158ef346 CB |
150 | .cfi_adjust_cfa_offset 16 |
151 | .cfi_offset 14, -12 | |
c9dae335 CB |
152 | .endm |
153 | ||
154 | /* restore stack */ | |
155 | .macro pop_for_divide | |
156 | ldr lr, [sp, #4] | |
157 | #if CAN_USE_LDRD | |
158 | ldrd r2, r3, [sp, #8] | |
159 | add sp, sp, #16 | |
160 | #else | |
161 | add sp, sp, #8 | |
162 | do_pop {r2, r3} | |
163 | #endif | |
158ef346 CB |
164 | .cfi_restore 14 |
165 | .cfi_adjust_cfa_offset 0 | |
c9dae335 CB |
166 | .endm |
167 | ||
b3f8d95d MM |
168 | #ifdef L_aeabi_ldivmod |
169 | ||
6857b807 CB |
170 | /* Perform 64 bit signed division. |
171 | Inputs: | |
172 | r0:r1 numerator | |
173 | r2:r3 denominator | |
174 | Outputs: | |
175 | r0:r1 quotient | |
176 | r2:r3 remainder | |
177 | */ | |
b3f8d95d | 178 | ARM_FUNC_START aeabi_ldivmod |
158ef346 | 179 | .cfi_startproc |
f21d8faa | 180 | test_div_by_zero signed |
0c23e1be | 181 | |
f493def1 | 182 | push_for_divide __aeabi_ldivmod |
13381189 CB |
183 | cmp xxh, #0 |
184 | blt 1f | |
185 | cmp yyh, #0 | |
186 | blt 2f | |
187 | /* arguments in (r0:r1), (r2:r3) and *sp */ | |
188 | bl SYM(__udivmoddi4) __PLT__ | |
158ef346 | 189 | .cfi_remember_state |
13381189 CB |
190 | pop_for_divide |
191 | RET | |
192 | ||
193 | 1: /* xxh:xxl is negative */ | |
158ef346 | 194 | .cfi_restore_state |
13381189 CB |
195 | negs xxl, xxl |
196 | sbc xxh, xxh, xxh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
197 | cmp yyh, #0 | |
198 | blt 3f | |
199 | /* arguments in (r0:r1), (r2:r3) and *sp */ | |
200 | bl SYM(__udivmoddi4) __PLT__ | |
158ef346 | 201 | .cfi_remember_state |
13381189 CB |
202 | pop_for_divide |
203 | negs xxl, xxl | |
204 | sbc xxh, xxh, xxh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
205 | negs yyl, yyl | |
206 | sbc yyh, yyh, yyh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
207 | RET | |
208 | ||
209 | 2: /* only yyh:yyl is negative */ | |
158ef346 | 210 | .cfi_restore_state |
13381189 CB |
211 | negs yyl, yyl |
212 | sbc yyh, yyh, yyh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
213 | /* arguments in (r0:r1), (r2:r3) and *sp */ | |
214 | bl SYM(__udivmoddi4) __PLT__ | |
158ef346 | 215 | .cfi_remember_state |
13381189 CB |
216 | pop_for_divide |
217 | negs xxl, xxl | |
218 | sbc xxh, xxh, xxh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
219 | RET | |
220 | ||
221 | 3: /* both xxh:xxl and yyh:yyl are negative */ | |
158ef346 | 222 | .cfi_restore_state |
13381189 CB |
223 | negs yyl, yyl |
224 | sbc yyh, yyh, yyh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
f493def1 | 225 | /* arguments in (r0:r1), (r2:r3) and *sp */ |
13381189 | 226 | bl SYM(__udivmoddi4) __PLT__ |
f493def1 | 227 | pop_for_divide |
13381189 CB |
228 | negs yyl, yyl |
229 | sbc yyh, yyh, yyh, lsl #1 /* Thumb-2 has no RSC, so use X - 2X */ | |
b3f8d95d | 230 | RET |
13381189 | 231 | |
158ef346 | 232 | .cfi_endproc |
b3f8d95d MM |
233 | |
234 | #endif /* L_aeabi_ldivmod */ | |
235 | ||
236 | #ifdef L_aeabi_uldivmod | |
237 | ||
6857b807 CB |
238 | /* Perform 64 bit signed division. |
239 | Inputs: | |
240 | r0:r1 numerator | |
241 | r2:r3 denominator | |
242 | Outputs: | |
243 | r0:r1 quotient | |
244 | r2:r3 remainder | |
245 | */ | |
b3f8d95d | 246 | ARM_FUNC_START aeabi_uldivmod |
158ef346 | 247 | .cfi_startproc |
f21d8faa | 248 | test_div_by_zero unsigned |
0c23e1be | 249 | |
c9dae335 CB |
250 | push_for_divide __aeabi_uldivmod |
251 | /* arguments in (r0:r1), (r2:r3) and *sp */ | |
0b227df4 | 252 | bl SYM(__udivmoddi4) __PLT__ |
c9dae335 | 253 | pop_for_divide |
b3f8d95d | 254 | RET |
158ef346 | 255 | .cfi_endproc |
34652576 | 256 | |
b3f8d95d MM |
257 | #endif /* L_aeabi_divmod */ |
258 |