1/* Miscellaneous BPABI functions.
2
3   Copyright (C) 2003, 2004, 2007, 2008, 2009  Free Software Foundation, Inc.
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
8   Free Software Foundation; either version 3, or (at your option) any
9   later version.
10
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
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/>.  */
24
25#ifdef L_aeabi_lcmp
26
27ARM_FUNC_START aeabi_lcmp
28	cmp	xxh, yyh
29	do_it	lt
30	movlt	r0, #-1
31	do_it	gt
32	movgt	r0, #1
33	do_it	ne
34	RETc(ne)
35	subs	r0, xxl, yyl
36	do_it	lo
37	movlo	r0, #-1
38	do_it	hi
39	movhi	r0, #1
40	RET
41	FUNC_END aeabi_lcmp
42
43#endif /* L_aeabi_lcmp */
44
45#ifdef L_aeabi_ulcmp
46
47ARM_FUNC_START aeabi_ulcmp
48	cmp	xxh, yyh
49	do_it	lo
50	movlo	r0, #-1
51	do_it	hi
52	movhi	r0, #1
53	do_it	ne
54	RETc(ne)
55	cmp	xxl, yyl
56	do_it	lo
57	movlo	r0, #-1
58	do_it	hi
59	movhi	r0, #1
60	do_it	eq
61	moveq	r0, #0
62	RET
63	FUNC_END aeabi_ulcmp
64
65#endif /* L_aeabi_ulcmp */
66
67.macro test_div_by_zero signed
68/* Tail-call to divide-by-zero handlers which may be overridden by the user,
69   so unwinding works properly.  */
70#if defined(__thumb2__)
71	cbnz	yyh, 1f
72	cbnz	yyl, 1f
73	cmp	xxh, #0
74	do_it	eq
75	cmpeq	xxl, #0
76	.ifc \signed, unsigned
77	beq	2f
78	mov	xxh, #0xffffffff
79	mov	xxl, xxh
802:
81	.else
82	do_it	lt, t
83	movlt	xxl, #0
84	movlt	xxh, #0x80000000
85	do_it	gt, t
86	movgt	xxh, #0x7fffffff
87	movgt	xxl, #0xffffffff
88	.endif
89	b	SYM (__aeabi_ldiv0) __PLT__
901:
91#else
92	/* Note: Thumb-1 code calls via an ARM shim on processors which
93	   support ARM mode.  */
94	cmp	yyh, #0
95	cmpeq	yyl, #0
96	bne	2f
97	cmp	xxh, #0
98	cmpeq	xxl, #0
99	.ifc \signed, unsigned
100	movne	xxh, #0xffffffff
101	movne	xxl, #0xffffffff
102	.else
103	movlt	xxh, #0x80000000
104	movlt	xxl, #0
105	movgt	xxh, #0x7fffffff
106	movgt	xxl, #0xffffffff
107	.endif
108	b	SYM (__aeabi_ldiv0) __PLT__
1092:
110#endif
111.endm
112
113#ifdef L_aeabi_ldivmod
114
115ARM_FUNC_START aeabi_ldivmod
116	test_div_by_zero signed
117
118	sub sp, sp, #8
119#if defined(__thumb2__)
120	mov ip, sp
121	push {ip, lr}
122#else
123	do_push {sp, lr}
124#endif
125	bl SYM(__gnu_ldivmod_helper) __PLT__
126	ldr lr, [sp, #4]
127	add sp, sp, #8
128	do_pop {r2, r3}
129	RET
130
131#endif /* L_aeabi_ldivmod */
132
133#ifdef L_aeabi_uldivmod
134
135ARM_FUNC_START aeabi_uldivmod
136	test_div_by_zero unsigned
137
138	sub sp, sp, #8
139#if defined(__thumb2__)
140	mov ip, sp
141	push {ip, lr}
142#else
143	do_push {sp, lr}
144#endif
145	bl SYM(__gnu_uldivmod_helper) __PLT__
146	ldr lr, [sp, #4]
147	add sp, sp, #8
148	do_pop {r2, r3}
149	RET
150
151#endif /* L_aeabi_divmod */
152
153