1/* libgcc routines for Toshiba Media Processor.
2   Copyright (C) 2001-2015 Free Software Foundation, Inc.
3
4This file is free software; you can redistribute it and/or modify it
5under the terms of the GNU General Public License as published by the
6Free Software Foundation; either version 3 of the License, or (at your
7option) any later version.
8
9This file is distributed in the hope that it will be useful, but
10WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12General Public License for more details.
13
14Under Section 7 of GPL version 3, you are granted additional
15permissions described in the GCC Runtime Library Exception, version
163.1, as published by the Free Software Foundation.
17
18You should have received a copy of the GNU General Public License and
19a copy of the GCC Runtime Library Exception along with this program;
20see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
21<http://www.gnu.org/licenses/>.  */
22
23#define SAVEALL \
24	add3	$sp, $sp, -16*4 ; \
25	sw	$0, ($sp) ; \
26	sw	$1, 4($sp) ; \
27	sw	$2, 8($sp) ; \
28	sw	$3, 12($sp) ; \
29	sw	$4, 16($sp) ; \
30	sw	$5, 20($sp) ; \
31	sw	$6, 24($sp) ; \
32	sw	$7, 28($sp) ; \
33	sw	$8, 32($sp) ; \
34	sw	$9, 36($sp) ; \
35	sw	$10, 40($sp) ; \
36	sw	$11, 44($sp) ; \
37	sw	$12, 48($sp) ; \
38	sw	$13, 52($sp) ; \
39	sw	$14, 56($sp) ; \
40	ldc	$5, $lp	; \
41	add	$5, 3 ; \
42	mov	$6, -4 ; \
43	and	$5, $6
44
45#define RESTOREALL \
46	stc	$5, $lp ; \
47	lw	$14, 56($sp) ; \
48	lw	$13, 52($sp) ; \
49	lw	$12, 48($sp) ; \
50	lw	$11, 44($sp) ; \
51	lw	$10, 40($sp) ; \
52	lw	$9, 36($sp) ; \
53	lw	$8, 32($sp) ; \
54	lw	$7, 28($sp) ; \
55	lw	$6, 24($sp) ; \
56	lw	$5, 20($sp) ; \
57	lw	$4, 16($sp) ; \
58	lw	$3, 12($sp) ; \
59	lw	$2, 8($sp) ; \
60	lw	$1, 4($sp) ; \
61	lw	$0, ($sp) ; \
62	add3	$sp, $sp, 16*4 ; \
63	ret
64
65#ifdef L_mep_profile
66	.text
67	.global __mep_mcount
68__mep_mcount:
69	SAVEALL
70	ldc	$1, $lp
71	mov	$2, $0
72	bsr	__mep_mcount_2
73	RESTOREALL
74#endif
75
76#ifdef L_mep_bb_init_trace
77	.text
78	.global __mep_bb_init_trace_func
79__mep_bb_init_trace_func:
80	SAVEALL
81	lw	$1, ($5)
82	lw	$2, 4($5)
83	add	$5, 8
84	bsr	__bb_init_trace_func
85	RESTOREALL
86#endif
87
88#ifdef L_mep_bb_init
89	.text
90	.global __mep_bb_init_func
91__mep_bb_init_func:
92	SAVEALL
93	lw	$1, ($5)
94	add	$5, 4
95	bsr	__bb_init_func
96	RESTOREALL
97#endif
98
99#ifdef L_mep_bb_trace
100	.text
101	.global __mep_bb_trace_func
102__mep_bb_trace_func:
103	SAVEALL
104	movu	$3, __bb
105	lw	$1, ($5)
106	sw	$1, ($3)
107	lw	$2, 4($5)
108	sw	$2, 4($3)
109	add	$5, 8
110	bsr	__bb_trace_func
111	RESTOREALL
112#endif
113
114#ifdef L_mep_bb_increment
115	.text
116	.global __mep_bb_increment_func
117__mep_bb_increment_func:
118	SAVEALL
119	lw	$1, ($5)
120	lw	$0, ($1)
121	add	$0, 1
122	sw	$0, ($1)
123	add	$5, 4
124	RESTOREALL
125#endif
126