1/* libgcc routines for NEC V850.
2   Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11In addition to the permissions in the GNU General Public License, the
12Free Software Foundation gives you unlimited permission to link the
13compiled version of this file into combinations with other programs,
14and to distribute those combinations without any restriction coming
15from the use of this file.  (The General Public License restrictions
16do apply in other respects; for example, they cover modification of
17the file, and distribution when not linked into a combine
18executable.)
19
20This file is distributed in the hope that it will be useful, but
21WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program; see the file COPYING.  If not, write to
27the Free Software Foundation, 59 Temple Place - Suite 330,
28Boston, MA 02111-1307, USA.  */
29
30#ifdef L_mulsi3
31	.text
32	.globl ___mulsi3
33	.type  ___mulsi3,@function
34___mulsi3:
35#ifdef __v850__
36/*
37   #define SHIFT 12
38   #define MASK ((1 << SHIFT) - 1)
39
40   #define STEP(i, j)                               \
41   ({                                               \
42       short a_part = (a >> (i)) & MASK;            \
43       short b_part = (b >> (j)) & MASK;            \
44       int res = (((int) a_part) * ((int) b_part)); \
45       res;                                         \
46   })
47
48   int
49   __mulsi3 (unsigned a, unsigned b)
50   {
51      return STEP (0, 0) +
52          ((STEP (SHIFT, 0) + STEP (0, SHIFT)) << SHIFT) +
53          ((STEP (0, 2 * SHIFT) + STEP (SHIFT, SHIFT) + STEP (2 * SHIFT, 0))
54           << (2 * SHIFT));
55   }
56*/
57        mov   r6, r14
58        movea lo(32767), r0, r10
59        and   r10, r14
60        mov   r7,  r15
61        and   r10, r15
62        shr   15,  r6
63        mov   r6,  r13
64        and   r10, r13
65        shr   15,  r7
66        mov   r7,  r12
67        and   r10, r12
68        shr   15,  r6
69        shr   15,  r7
70        mov   r14, r10
71        mulh  r15, r10
72        mov   r14, r11
73        mulh  r12, r11
74        mov   r13, r16
75        mulh  r15, r16
76        mulh  r14, r7
77        mulh  r15, r6
78        add   r16, r11
79        mulh  r13, r12
80        shl   15,  r11
81        add   r11, r10
82        add   r12, r7
83        add   r6,  r7
84        shl   30,  r7
85        add   r7,  r10
86        jmp   [r31]
87#endif /* __v850__ */
88#if defined(__v850e__) || defined(__v850ea__)
89        /* This routine is almost unneccesarry because gcc
90           generates the MUL instruction for the RTX mulsi3.
91           But if someone wants to link his application with
92           previsously compiled v850 objects then they will
93	   need this function.  */
94
95        /* It isn't good to put the inst sequence as below;
96              mul r7, r6,
97              mov r6, r10, r0
98           In this case, there is a RAW hazard between them.
99           MUL inst takes 2 cycle in EX stage, then MOV inst
100           must wait 1cycle.  */
101        mov   r7, r10
102        mul   r6, r10, r0
103        jmp   [r31]
104#endif /* __v850e__ */
105	.size ___mulsi3,.-___mulsi3
106#endif /* L_mulsi3 */
107
108
109#ifdef L_udivsi3
110	.text
111	.global ___udivsi3
112	.type	___udivsi3,@function
113___udivsi3:
114#ifdef __v850__
115	mov 1,r12
116	mov 0,r10
117	cmp r6,r7
118	bnl .L12
119	movhi hi(-2147483648),r0,r13
120	cmp r0,r7
121	blt .L12
122.L4:
123	shl 1,r7
124	shl 1,r12
125	cmp r6,r7
126	bnl .L12
127	cmp r0,r12
128	be .L8
129	mov r7,r19
130	and r13,r19
131	be .L4
132	br .L12
133.L9:
134	cmp r7,r6
135	bl .L10
136	sub r7,r6
137	or r12,r10
138.L10:
139	shr 1,r12
140	shr 1,r7
141.L12:
142	cmp r0,r12
143	bne .L9
144.L8:
145	jmp [r31]
146
147#else /* defined(__v850e__) */
148
149	/* See comments at end of __mulsi3.  */
150	mov   r6, r10
151	divu  r7, r10, r0
152	jmp   [r31]
153
154#endif /* __v850e__ */
155
156	.size ___udivsi3,.-___udivsi3
157#endif
158
159#ifdef L_divsi3
160	.text
161	.globl ___divsi3
162	.type  ___divsi3,@function
163___divsi3:
164#ifdef __v850__
165	add -8,sp
166	st.w r31,4[sp]
167	st.w r22,0[sp]
168	mov 1,r22
169	tst r7,r7
170	bp .L3
171	subr r0,r7
172	subr r0,r22
173.L3:
174	tst r6,r6
175	bp .L4
176	subr r0,r6
177	subr r0,r22
178.L4:
179	jarl ___udivsi3,r31
180	cmp r0,r22
181	bp .L7
182	subr r0,r10
183.L7:
184	ld.w 0[sp],r22
185	ld.w 4[sp],r31
186	add 8,sp
187	jmp [r31]
188
189#else /* defined(__v850e__) */
190
191	/* See comments at end of __mulsi3.  */
192	mov   r6, r10
193	div   r7, r10, r0
194	jmp   [r31]
195
196#endif /* __v850e__ */
197
198	.size ___divsi3,.-___divsi3
199#endif
200
201#ifdef  L_umodsi3
202	.text
203	.globl ___umodsi3
204	.type  ___umodsi3,@function
205___umodsi3:
206#ifdef __v850__
207	add -12,sp
208	st.w r31,8[sp]
209	st.w r7,4[sp]
210	st.w r6,0[sp]
211	jarl ___udivsi3,r31
212	ld.w 4[sp],r7
213	mov r10,r6
214	jarl ___mulsi3,r31
215	ld.w 0[sp],r6
216	subr r6,r10
217	ld.w 8[sp],r31
218	add 12,sp
219	jmp [r31]
220
221#else /* defined(__v850e__) */
222
223	/* See comments at end of __mulsi3.  */
224	divu  r7, r6, r10
225	jmp   [r31]
226
227#endif /* __v850e__ */
228
229	.size ___umodsi3,.-___umodsi3
230#endif /* L_umodsi3 */
231
232#ifdef  L_modsi3
233	.text
234	.globl ___modsi3
235	.type  ___modsi3,@function
236___modsi3:
237#ifdef __v850__
238	add -12,sp
239	st.w r31,8[sp]
240	st.w r7,4[sp]
241	st.w r6,0[sp]
242	jarl ___divsi3,r31
243	ld.w 4[sp],r7
244	mov r10,r6
245	jarl ___mulsi3,r31
246	ld.w 0[sp],r6
247	subr r6,r10
248	ld.w 8[sp],r31
249	add 12,sp
250	jmp [r31]
251
252#else /* defined(__v850e__) */
253
254	/* See comments at end of __mulsi3.  */
255	div  r7, r6, r10
256	jmp [r31]
257
258#endif /* __v850e__ */
259
260	.size ___modsi3,.-___modsi3
261#endif /* L_modsi3 */
262
263#ifdef	L_save_2
264	.text
265	.align	2
266	.globl	__save_r2_r29
267	.type	__save_r2_r29,@function
268	/* Allocate space and save registers 2, 20 .. 29 on the stack */
269	/* Called via:	jalr __save_r2_r29,r10 */
270__save_r2_r29:
271	mov	ep,r1
272	addi	-44,sp,sp
273	mov	sp,ep
274	sst.w	r29,0[ep]
275	sst.w	r28,4[ep]
276	sst.w	r27,8[ep]
277	sst.w	r26,12[ep]
278	sst.w	r25,16[ep]
279	sst.w	r24,20[ep]
280	sst.w	r23,24[ep]
281	sst.w	r22,28[ep]
282	sst.w	r21,32[ep]
283	sst.w	r20,36[ep]
284	sst.w	r2,40[ep]
285	mov	r1,ep
286	jmp	[r10]
287	.size	__save_r2_r29,.-__save_r2_r29
288
289	/* Restore saved registers, deallocate stack and return to the user */
290	/* Called via:	jr __return_r2_r29 */
291	.align	2
292	.globl	__return_r2_r29
293	.type	__return_r2_r29,@function
294__return_r2_r29:
295	mov	ep,r1
296	mov	sp,ep
297	sld.w	0[ep],r29
298	sld.w	4[ep],r28
299	sld.w	8[ep],r27
300	sld.w	12[ep],r26
301	sld.w	16[ep],r25
302	sld.w	20[ep],r24
303	sld.w	24[ep],r23
304	sld.w	28[ep],r22
305	sld.w	32[ep],r21
306	sld.w	36[ep],r20
307	sld.w	40[ep],r2
308	addi	44,sp,sp
309	mov	r1,ep
310	jmp	[r31]
311	.size	__return_r2_r29,.-__return_r2_r29
312#endif /* L_save_2 */
313
314#ifdef	L_save_20
315	.text
316	.align	2
317	.globl	__save_r20_r29
318	.type	__save_r20_r29,@function
319	/* Allocate space and save registers 20 .. 29 on the stack */
320	/* Called via:	jalr __save_r20_r29,r10 */
321__save_r20_r29:
322	mov	ep,r1
323	addi	-40,sp,sp
324	mov	sp,ep
325	sst.w	r29,0[ep]
326	sst.w	r28,4[ep]
327	sst.w	r27,8[ep]
328	sst.w	r26,12[ep]
329	sst.w	r25,16[ep]
330	sst.w	r24,20[ep]
331	sst.w	r23,24[ep]
332	sst.w	r22,28[ep]
333	sst.w	r21,32[ep]
334	sst.w	r20,36[ep]
335	mov	r1,ep
336	jmp	[r10]
337	.size	__save_r20_r29,.-__save_r20_r29
338
339	/* Restore saved registers, deallocate stack and return to the user */
340	/* Called via:	jr __return_r20_r29 */
341	.align	2
342	.globl	__return_r20_r29
343	.type	__return_r20_r29,@function
344__return_r20_r29:
345	mov	ep,r1
346	mov	sp,ep
347	sld.w	0[ep],r29
348	sld.w	4[ep],r28
349	sld.w	8[ep],r27
350	sld.w	12[ep],r26
351	sld.w	16[ep],r25
352	sld.w	20[ep],r24
353	sld.w	24[ep],r23
354	sld.w	28[ep],r22
355	sld.w	32[ep],r21
356	sld.w	36[ep],r20
357	addi	40,sp,sp
358	mov	r1,ep
359	jmp	[r31]
360	.size	__return_r20_r29,.-__return_r20_r29
361#endif /* L_save_20 */
362
363#ifdef	L_save_21
364	.text
365	.align	2
366	.globl	__save_r21_r29
367	.type	__save_r21_r29,@function
368	/* Allocate space and save registers 21 .. 29 on the stack */
369	/* Called via:	jalr __save_r21_r29,r10 */
370__save_r21_r29:
371	mov	ep,r1
372	addi	-36,sp,sp
373	mov	sp,ep
374	sst.w	r29,0[ep]
375	sst.w	r28,4[ep]
376	sst.w	r27,8[ep]
377	sst.w	r26,12[ep]
378	sst.w	r25,16[ep]
379	sst.w	r24,20[ep]
380	sst.w	r23,24[ep]
381	sst.w	r22,28[ep]
382	sst.w	r21,32[ep]
383	mov	r1,ep
384	jmp	[r10]
385	.size	__save_r21_r29,.-__save_r21_r29
386
387	/* Restore saved registers, deallocate stack and return to the user */
388	/* Called via:	jr __return_r21_r29 */
389	.align	2
390	.globl	__return_r21_r29
391	.type	__return_r21_r29,@function
392__return_r21_r29:
393	mov	ep,r1
394	mov	sp,ep
395	sld.w	0[ep],r29
396	sld.w	4[ep],r28
397	sld.w	8[ep],r27
398	sld.w	12[ep],r26
399	sld.w	16[ep],r25
400	sld.w	20[ep],r24
401	sld.w	24[ep],r23
402	sld.w	28[ep],r22
403	sld.w	32[ep],r21
404	addi	36,sp,sp
405	mov	r1,ep
406	jmp	[r31]
407	.size	__return_r21_r29,.-__return_r21_r29
408#endif /* L_save_21 */
409
410#ifdef	L_save_22
411	.text
412	.align	2
413	.globl	__save_r22_r29
414	.type	__save_r22_r29,@function
415	/* Allocate space and save registers 22 .. 29 on the stack */
416	/* Called via:	jalr __save_r22_r29,r10 */
417__save_r22_r29:
418	mov	ep,r1
419	addi	-32,sp,sp
420	mov	sp,ep
421	sst.w	r29,0[ep]
422	sst.w	r28,4[ep]
423	sst.w	r27,8[ep]
424	sst.w	r26,12[ep]
425	sst.w	r25,16[ep]
426	sst.w	r24,20[ep]
427	sst.w	r23,24[ep]
428	sst.w	r22,28[ep]
429	mov	r1,ep
430	jmp	[r10]
431	.size	__save_r22_r29,.-__save_r22_r29
432
433	/* Restore saved registers, deallocate stack and return to the user */
434	/* Called via:	jr __return_r22_r29 */
435	.align	2
436	.globl	__return_r22_r29
437	.type	__return_r22_r29,@function
438__return_r22_r29:
439	mov	ep,r1
440	mov	sp,ep
441	sld.w	0[ep],r29
442	sld.w	4[ep],r28
443	sld.w	8[ep],r27
444	sld.w	12[ep],r26
445	sld.w	16[ep],r25
446	sld.w	20[ep],r24
447	sld.w	24[ep],r23
448	sld.w	28[ep],r22
449	addi	32,sp,sp
450	mov	r1,ep
451	jmp	[r31]
452	.size	__return_r22_r29,.-__return_r22_r29
453#endif /* L_save_22 */
454
455#ifdef	L_save_23
456	.text
457	.align	2
458	.globl	__save_r23_r29
459	.type	__save_r23_r29,@function
460	/* Allocate space and save registers 23 .. 29 on the stack */
461	/* Called via:	jalr __save_r23_r29,r10 */
462__save_r23_r29:
463	mov	ep,r1
464	addi	-28,sp,sp
465	mov	sp,ep
466	sst.w	r29,0[ep]
467	sst.w	r28,4[ep]
468	sst.w	r27,8[ep]
469	sst.w	r26,12[ep]
470	sst.w	r25,16[ep]
471	sst.w	r24,20[ep]
472	sst.w	r23,24[ep]
473	mov	r1,ep
474	jmp	[r10]
475	.size	__save_r23_r29,.-__save_r23_r29
476
477	/* Restore saved registers, deallocate stack and return to the user */
478	/* Called via:	jr __return_r23_r29 */
479	.align	2
480	.globl	__return_r23_r29
481	.type	__return_r23_r29,@function
482__return_r23_r29:
483	mov	ep,r1
484	mov	sp,ep
485	sld.w	0[ep],r29
486	sld.w	4[ep],r28
487	sld.w	8[ep],r27
488	sld.w	12[ep],r26
489	sld.w	16[ep],r25
490	sld.w	20[ep],r24
491	sld.w	24[ep],r23
492	addi	28,sp,sp
493	mov	r1,ep
494	jmp	[r31]
495	.size	__return_r23_r29,.-__return_r23_r29
496#endif /* L_save_23 */
497
498#ifdef	L_save_24
499	.text
500	.align	2
501	.globl	__save_r24_r29
502	.type	__save_r24_r29,@function
503	/* Allocate space and save registers 24 .. 29 on the stack */
504	/* Called via:	jalr __save_r24_r29,r10 */
505__save_r24_r29:
506	mov	ep,r1
507	addi	-24,sp,sp
508	mov	sp,ep
509	sst.w	r29,0[ep]
510	sst.w	r28,4[ep]
511	sst.w	r27,8[ep]
512	sst.w	r26,12[ep]
513	sst.w	r25,16[ep]
514	sst.w	r24,20[ep]
515	mov	r1,ep
516	jmp	[r10]
517	.size	__save_r24_r29,.-__save_r24_r29
518
519	/* Restore saved registers, deallocate stack and return to the user */
520	/* Called via:	jr __return_r24_r29 */
521	.align	2
522	.globl	__return_r24_r29
523	.type	__return_r24_r29,@function
524__return_r24_r29:
525	mov	ep,r1
526	mov	sp,ep
527	sld.w	0[ep],r29
528	sld.w	4[ep],r28
529	sld.w	8[ep],r27
530	sld.w	12[ep],r26
531	sld.w	16[ep],r25
532	sld.w	20[ep],r24
533	addi	24,sp,sp
534	mov	r1,ep
535	jmp	[r31]
536	.size	__return_r24_r29,.-__return_r24_r29
537#endif /* L_save_24 */
538
539#ifdef	L_save_25
540	.text
541	.align	2
542	.globl	__save_r25_r29
543	.type	__save_r25_r29,@function
544	/* Allocate space and save registers 25 .. 29 on the stack */
545	/* Called via:	jalr __save_r25_r29,r10 */
546__save_r25_r29:
547	mov	ep,r1
548	addi	-20,sp,sp
549	mov	sp,ep
550	sst.w	r29,0[ep]
551	sst.w	r28,4[ep]
552	sst.w	r27,8[ep]
553	sst.w	r26,12[ep]
554	sst.w	r25,16[ep]
555	mov	r1,ep
556	jmp	[r10]
557	.size	__save_r25_r29,.-__save_r25_r29
558
559	/* Restore saved registers, deallocate stack and return to the user */
560	/* Called via:	jr __return_r25_r29 */
561	.align	2
562	.globl	__return_r25_r29
563	.type	__return_r25_r29,@function
564__return_r25_r29:
565	mov	ep,r1
566	mov	sp,ep
567	sld.w	0[ep],r29
568	sld.w	4[ep],r28
569	sld.w	8[ep],r27
570	sld.w	12[ep],r26
571	sld.w	16[ep],r25
572	addi	20,sp,sp
573	mov	r1,ep
574	jmp	[r31]
575	.size	__return_r25_r29,.-__return_r25_r29
576#endif /* L_save_25 */
577
578#ifdef	L_save_26
579	.text
580	.align	2
581	.globl	__save_r26_r29
582	.type	__save_r26_r29,@function
583	/* Allocate space and save registers 26 .. 29 on the stack */
584	/* Called via:	jalr __save_r26_r29,r10 */
585__save_r26_r29:
586	mov	ep,r1
587	add	-16,sp
588	mov	sp,ep
589	sst.w	r29,0[ep]
590	sst.w	r28,4[ep]
591	sst.w	r27,8[ep]
592	sst.w	r26,12[ep]
593	mov	r1,ep
594	jmp	[r10]
595	.size	__save_r26_r29,.-__save_r26_r29
596
597	/* Restore saved registers, deallocate stack and return to the user */
598	/* Called via:	jr __return_r26_r29 */
599	.align	2
600	.globl	__return_r26_r29
601	.type	__return_r26_r29,@function
602__return_r26_r29:
603	mov	ep,r1
604	mov	sp,ep
605	sld.w	0[ep],r29
606	sld.w	4[ep],r28
607	sld.w	8[ep],r27
608	sld.w	12[ep],r26
609	addi	16,sp,sp
610	mov	r1,ep
611	jmp	[r31]
612	.size	__return_r26_r29,.-__return_r26_r29
613#endif /* L_save_26 */
614
615#ifdef	L_save_27
616	.text
617	.align	2
618	.globl	__save_r27_r29
619	.type	__save_r27_r29,@function
620	/* Allocate space and save registers 27 .. 29 on the stack */
621	/* Called via:	jalr __save_r27_r29,r10 */
622__save_r27_r29:
623	add	-12,sp
624	st.w	r29,0[sp]
625	st.w	r28,4[sp]
626	st.w	r27,8[sp]
627	jmp	[r10]
628	.size	__save_r27_r29,.-__save_r27_r29
629
630	/* Restore saved registers, deallocate stack and return to the user */
631	/* Called via:	jr __return_r27_r29 */
632	.align	2
633	.globl	__return_r27_r29
634	.type	__return_r27_r29,@function
635__return_r27_r29:
636	ld.w	0[sp],r29
637	ld.w	4[sp],r28
638	ld.w	8[sp],r27
639	add	12,sp
640	jmp	[r31]
641	.size	__return_r27_r29,.-__return_r27_r29
642#endif /* L_save_27 */
643
644#ifdef	L_save_28
645	.text
646	.align	2
647	.globl	__save_r28_r29
648	.type	__save_r28_r29,@function
649	/* Allocate space and save registers 28,29 on the stack */
650	/* Called via:	jalr __save_r28_r29,r10 */
651__save_r28_r29:
652	add	-8,sp
653	st.w	r29,0[sp]
654	st.w	r28,4[sp]
655	jmp	[r10]
656	.size	__save_r28_r29,.-__save_r28_r29
657
658	/* Restore saved registers, deallocate stack and return to the user */
659	/* Called via:	jr __return_r28_r29 */
660	.align	2
661	.globl	__return_r28_r29
662	.type	__return_r28_r29,@function
663__return_r28_r29:
664	ld.w	0[sp],r29
665	ld.w	4[sp],r28
666	add	8,sp
667	jmp	[r31]
668	.size	__return_r28_r29,.-__return_r28_r29
669#endif /* L_save_28 */
670
671#ifdef	L_save_29
672	.text
673	.align	2
674	.globl	__save_r29
675	.type	__save_r29,@function
676	/* Allocate space and save register 29 on the stack */
677	/* Called via:	jalr __save_r29,r10 */
678__save_r29:
679	add	-4,sp
680	st.w	r29,0[sp]
681	jmp	[r10]
682	.size	__save_r29,.-__save_r29
683
684	/* Restore saved register 29, deallocate stack and return to the user */
685	/* Called via:	jr __return_r29 */
686	.align	2
687	.globl	__return_r29
688	.type	__return_r29,@function
689__return_r29:
690	ld.w	0[sp],r29
691	add	4,sp
692	jmp	[r31]
693	.size	__return_r29,.-__return_r29
694#endif /* L_save_28 */
695
696#ifdef	L_save_2c
697	.text
698	.align	2
699	.globl	__save_r2_r31
700	.type	__save_r2_r31,@function
701	/* Allocate space and save registers 20 .. 29, 31 on the stack */
702	/* Also allocate space for the argument save area */
703	/* Called via:	jalr __save_r2_r31,r10 */
704__save_r2_r31:
705	mov	ep,r1
706	addi	-64,sp,sp
707	mov	sp,ep
708	sst.w	r29,16[ep]
709	sst.w	r28,20[ep]
710	sst.w	r27,24[ep]
711	sst.w	r26,28[ep]
712	sst.w	r25,32[ep]
713	sst.w	r24,36[ep]
714	sst.w	r23,40[ep]
715	sst.w	r22,44[ep]
716	sst.w	r21,48[ep]
717	sst.w	r20,52[ep]
718	sst.w	r2,56[ep]
719	sst.w	r31,60[ep]
720	mov	r1,ep
721	jmp	[r10]
722	.size	__save_r2_r31,.-__save_r2_r31
723
724	/* Restore saved registers, deallocate stack and return to the user */
725	/* Called via:	jr __return_r20_r31 */
726	.align	2
727	.globl	__return_r2_r31
728	.type	__return_r2_r31,@function
729__return_r2_r31:
730	mov	ep,r1
731	mov	sp,ep
732	sld.w	16[ep],r29
733	sld.w	20[ep],r28
734	sld.w	24[ep],r27
735	sld.w	28[ep],r26
736	sld.w	32[ep],r25
737	sld.w	36[ep],r24
738	sld.w	40[ep],r23
739	sld.w	44[ep],r22
740	sld.w	48[ep],r21
741	sld.w	52[ep],r20
742	sld.w	56[ep],r2
743	sld.w	60[ep],r31
744	addi	64,sp,sp
745	mov	r1,ep
746	jmp	[r31]
747	.size	__return_r2_r31,.-__return_r2_r31
748#endif /* L_save_2c */
749
750#ifdef	L_save_20c
751	.text
752	.align	2
753	.globl	__save_r20_r31
754	.type	__save_r20_r31,@function
755	/* Allocate space and save registers 20 .. 29, 31 on the stack */
756	/* Also allocate space for the argument save area */
757	/* Called via:	jalr __save_r20_r31,r10 */
758__save_r20_r31:
759	mov	ep,r1
760	addi	-60,sp,sp
761	mov	sp,ep
762	sst.w	r29,16[ep]
763	sst.w	r28,20[ep]
764	sst.w	r27,24[ep]
765	sst.w	r26,28[ep]
766	sst.w	r25,32[ep]
767	sst.w	r24,36[ep]
768	sst.w	r23,40[ep]
769	sst.w	r22,44[ep]
770	sst.w	r21,48[ep]
771	sst.w	r20,52[ep]
772	sst.w	r31,56[ep]
773	mov	r1,ep
774	jmp	[r10]
775	.size	__save_r20_r31,.-__save_r20_r31
776
777	/* Restore saved registers, deallocate stack and return to the user */
778	/* Called via:	jr __return_r20_r31 */
779	.align	2
780	.globl	__return_r20_r31
781	.type	__return_r20_r31,@function
782__return_r20_r31:
783	mov	ep,r1
784	mov	sp,ep
785	sld.w	16[ep],r29
786	sld.w	20[ep],r28
787	sld.w	24[ep],r27
788	sld.w	28[ep],r26
789	sld.w	32[ep],r25
790	sld.w	36[ep],r24
791	sld.w	40[ep],r23
792	sld.w	44[ep],r22
793	sld.w	48[ep],r21
794	sld.w	52[ep],r20
795	sld.w	56[ep],r31
796	addi	60,sp,sp
797	mov	r1,ep
798	jmp	[r31]
799	.size	__return_r20_r31,.-__return_r20_r31
800#endif /* L_save_20c */
801
802#ifdef	L_save_21c
803	.text
804	.align	2
805	.globl	__save_r21_r31
806	.type	__save_r21_r31,@function
807	/* Allocate space and save registers 21 .. 29, 31 on the stack */
808	/* Also allocate space for the argument save area */
809	/* Called via:	jalr __save_r21_r31,r10 */
810__save_r21_r31:
811	mov	ep,r1
812	addi	-56,sp,sp
813	mov	sp,ep
814	sst.w	r29,16[ep]
815	sst.w	r28,20[ep]
816	sst.w	r27,24[ep]
817	sst.w	r26,28[ep]
818	sst.w	r25,32[ep]
819	sst.w	r24,36[ep]
820	sst.w	r23,40[ep]
821	sst.w	r22,44[ep]
822	sst.w	r21,48[ep]
823	sst.w	r31,52[ep]
824	mov	r1,ep
825	jmp	[r10]
826	.size	__save_r21_r31,.-__save_r21_r31
827
828	/* Restore saved registers, deallocate stack and return to the user */
829	/* Called via:	jr __return_r21_r31 */
830	.align	2
831	.globl	__return_r21_r31
832	.type	__return_r21_r31,@function
833__return_r21_r31:
834	mov	ep,r1
835	mov	sp,ep
836	sld.w	16[ep],r29
837	sld.w	20[ep],r28
838	sld.w	24[ep],r27
839	sld.w	28[ep],r26
840	sld.w	32[ep],r25
841	sld.w	36[ep],r24
842	sld.w	40[ep],r23
843	sld.w	44[ep],r22
844	sld.w	48[ep],r21
845	sld.w	52[ep],r31
846	addi	56,sp,sp
847	mov	r1,ep
848	jmp	[r31]
849	.size	__return_r21_r31,.-__return_r21_r31
850#endif /* L_save_21c */
851
852#ifdef	L_save_22c
853	.text
854	.align	2
855	.globl	__save_r22_r31
856	.type	__save_r22_r31,@function
857	/* Allocate space and save registers 22 .. 29, 31 on the stack */
858	/* Also allocate space for the argument save area */
859	/* Called via:	jalr __save_r22_r31,r10 */
860__save_r22_r31:
861	mov	ep,r1
862	addi	-52,sp,sp
863	mov	sp,ep
864	sst.w	r29,16[ep]
865	sst.w	r28,20[ep]
866	sst.w	r27,24[ep]
867	sst.w	r26,28[ep]
868	sst.w	r25,32[ep]
869	sst.w	r24,36[ep]
870	sst.w	r23,40[ep]
871	sst.w	r22,44[ep]
872	sst.w	r31,48[ep]
873	mov	r1,ep
874	jmp	[r10]
875	.size	__save_r22_r31,.-__save_r22_r31
876
877	/* Restore saved registers, deallocate stack and return to the user */
878	/* Called via:	jr __return_r22_r31 */
879	.align	2
880	.globl	__return_r22_r31
881	.type	__return_r22_r31,@function
882__return_r22_r31:
883	mov	ep,r1
884	mov	sp,ep
885	sld.w	16[ep],r29
886	sld.w	20[ep],r28
887	sld.w	24[ep],r27
888	sld.w	28[ep],r26
889	sld.w	32[ep],r25
890	sld.w	36[ep],r24
891	sld.w	40[ep],r23
892	sld.w	44[ep],r22
893	sld.w	48[ep],r31
894	addi	52,sp,sp
895	mov	r1,ep
896	jmp	[r31]
897	.size	__return_r22_r31,.-__return_r22_r31
898#endif /* L_save_22c */
899
900#ifdef	L_save_23c
901	.text
902	.align	2
903	.globl	__save_r23_r31
904	.type	__save_r23_r31,@function
905	/* Allocate space and save registers 23 .. 29, 31 on the stack */
906	/* Also allocate space for the argument save area */
907	/* Called via:	jalr __save_r23_r31,r10 */
908__save_r23_r31:
909	mov	ep,r1
910	addi	-48,sp,sp
911	mov	sp,ep
912	sst.w	r29,16[ep]
913	sst.w	r28,20[ep]
914	sst.w	r27,24[ep]
915	sst.w	r26,28[ep]
916	sst.w	r25,32[ep]
917	sst.w	r24,36[ep]
918	sst.w	r23,40[ep]
919	sst.w	r31,44[ep]
920	mov	r1,ep
921	jmp	[r10]
922	.size	__save_r23_r31,.-__save_r23_r31
923
924	/* Restore saved registers, deallocate stack and return to the user */
925	/* Called via:	jr __return_r23_r31 */
926	.align	2
927	.globl	__return_r23_r31
928	.type	__return_r23_r31,@function
929__return_r23_r31:
930	mov	ep,r1
931	mov	sp,ep
932	sld.w	16[ep],r29
933	sld.w	20[ep],r28
934	sld.w	24[ep],r27
935	sld.w	28[ep],r26
936	sld.w	32[ep],r25
937	sld.w	36[ep],r24
938	sld.w	40[ep],r23
939	sld.w	44[ep],r31
940	addi	48,sp,sp
941	mov	r1,ep
942	jmp	[r31]
943	.size	__return_r23_r31,.-__return_r23_r31
944#endif /* L_save_23c */
945
946#ifdef	L_save_24c
947	.text
948	.align	2
949	.globl	__save_r24_r31
950	.type	__save_r24_r31,@function
951	/* Allocate space and save registers 24 .. 29, 31 on the stack */
952	/* Also allocate space for the argument save area */
953	/* Called via:	jalr __save_r24_r31,r10 */
954__save_r24_r31:
955	mov	ep,r1
956	addi	-44,sp,sp
957	mov	sp,ep
958	sst.w	r29,16[ep]
959	sst.w	r28,20[ep]
960	sst.w	r27,24[ep]
961	sst.w	r26,28[ep]
962	sst.w	r25,32[ep]
963	sst.w	r24,36[ep]
964	sst.w	r31,40[ep]
965	mov	r1,ep
966	jmp	[r10]
967	.size	__save_r24_r31,.-__save_r24_r31
968
969	/* Restore saved registers, deallocate stack and return to the user */
970	/* Called via:	jr __return_r24_r31 */
971	.align	2
972	.globl	__return_r24_r31
973	.type	__return_r24_r31,@function
974__return_r24_r31:
975	mov	ep,r1
976	mov	sp,ep
977	sld.w	16[ep],r29
978	sld.w	20[ep],r28
979	sld.w	24[ep],r27
980	sld.w	28[ep],r26
981	sld.w	32[ep],r25
982	sld.w	36[ep],r24
983	sld.w	40[ep],r31
984	addi	44,sp,sp
985	mov	r1,ep
986	jmp	[r31]
987	.size	__return_r24_r31,.-__return_r24_r31
988#endif /* L_save_24c */
989
990#ifdef	L_save_25c
991	.text
992	.align	2
993	.globl	__save_r25_r31
994	.type	__save_r25_r31,@function
995	/* Allocate space and save registers 25 .. 29, 31 on the stack */
996	/* Also allocate space for the argument save area */
997	/* Called via:	jalr __save_r25_r31,r10 */
998__save_r25_r31:
999	mov	ep,r1
1000	addi	-40,sp,sp
1001	mov	sp,ep
1002	sst.w	r29,16[ep]
1003	sst.w	r28,20[ep]
1004	sst.w	r27,24[ep]
1005	sst.w	r26,28[ep]
1006	sst.w	r25,32[ep]
1007	sst.w	r31,36[ep]
1008	mov	r1,ep
1009	jmp	[r10]
1010	.size	__save_r25_r31,.-__save_r25_r31
1011
1012	/* Restore saved registers, deallocate stack and return to the user */
1013	/* Called via:	jr __return_r25_r31 */
1014	.align	2
1015	.globl	__return_r25_r31
1016	.type	__return_r25_r31,@function
1017__return_r25_r31:
1018	mov	ep,r1
1019	mov	sp,ep
1020	sld.w	16[ep],r29
1021	sld.w	20[ep],r28
1022	sld.w	24[ep],r27
1023	sld.w	28[ep],r26
1024	sld.w	32[ep],r25
1025	sld.w	36[ep],r31
1026	addi	40,sp,sp
1027	mov	r1,ep
1028	jmp	[r31]
1029	.size	__return_r25_r31,.-__return_r25_r31
1030#endif /* L_save_25c */
1031
1032#ifdef	L_save_26c
1033	.text
1034	.align	2
1035	.globl	__save_r26_r31
1036	.type	__save_r26_r31,@function
1037	/* Allocate space and save registers 26 .. 29, 31 on the stack */
1038	/* Also allocate space for the argument save area */
1039	/* Called via:	jalr __save_r26_r31,r10 */
1040__save_r26_r31:
1041	mov	ep,r1
1042	addi	-36,sp,sp
1043	mov	sp,ep
1044	sst.w	r29,16[ep]
1045	sst.w	r28,20[ep]
1046	sst.w	r27,24[ep]
1047	sst.w	r26,28[ep]
1048	sst.w	r31,32[ep]
1049	mov	r1,ep
1050	jmp	[r10]
1051	.size	__save_r26_r31,.-__save_r26_r31
1052
1053	/* Restore saved registers, deallocate stack and return to the user */
1054	/* Called via:	jr __return_r26_r31 */
1055	.align	2
1056	.globl	__return_r26_r31
1057	.type	__return_r26_r31,@function
1058__return_r26_r31:
1059	mov	ep,r1
1060	mov	sp,ep
1061	sld.w	16[ep],r29
1062	sld.w	20[ep],r28
1063	sld.w	24[ep],r27
1064	sld.w	28[ep],r26
1065	sld.w	32[ep],r31
1066	addi	36,sp,sp
1067	mov	r1,ep
1068	jmp	[r31]
1069	.size	__return_r26_r31,.-__return_r26_r31
1070#endif /* L_save_26c */
1071
1072#ifdef	L_save_27c
1073	.text
1074	.align	2
1075	.globl	__save_r27_r31
1076	.type	__save_r27_r31,@function
1077	/* Allocate space and save registers 27 .. 29, 31 on the stack */
1078	/* Also allocate space for the argument save area */
1079	/* Called via:	jalr __save_r27_r31,r10 */
1080__save_r27_r31:
1081	mov	ep,r1
1082	addi	-32,sp,sp
1083	mov	sp,ep
1084	sst.w	r29,16[ep]
1085	sst.w	r28,20[ep]
1086	sst.w	r27,24[ep]
1087	sst.w	r31,28[ep]
1088	mov	r1,ep
1089	jmp	[r10]
1090	.size	__save_r27_r31,.-__save_r27_r31
1091
1092	/* Restore saved registers, deallocate stack and return to the user */
1093	/* Called via:	jr __return_r27_r31 */
1094	.align	2
1095	.globl	__return_r27_r31
1096	.type	__return_r27_r31,@function
1097__return_r27_r31:
1098	mov	ep,r1
1099	mov	sp,ep
1100	sld.w	16[ep],r29
1101	sld.w	20[ep],r28
1102	sld.w	24[ep],r27
1103	sld.w	28[ep],r31
1104	addi	32,sp,sp
1105	mov	r1,ep
1106	jmp	[r31]
1107	.size	__return_r27_r31,.-__return_r27_r31
1108#endif /* L_save_27c */
1109
1110#ifdef	L_save_28c
1111	.text
1112	.align	2
1113	.globl	__save_r28_r31
1114	.type	__save_r28_r31,@function
1115	/* Allocate space and save registers 28 .. 29, 31 on the stack */
1116	/* Also allocate space for the argument save area */
1117	/* Called via:	jalr __save_r28_r31,r10 */
1118__save_r28_r31:
1119	addi	-28,sp,sp
1120	st.w	r29,16[sp]
1121	st.w	r28,20[sp]
1122	st.w	r31,24[sp]
1123	jmp	[r10]
1124	.size	__save_r28_r31,.-__save_r28_r31
1125
1126	/* Restore saved registers, deallocate stack and return to the user */
1127	/* Called via:	jr __return_r28_r31 */
1128	.align	2
1129	.globl	__return_r28_r31
1130	.type	__return_r28_r31,@function
1131__return_r28_r31:
1132	ld.w	16[sp],r29
1133	ld.w	20[sp],r28
1134	ld.w	24[sp],r31
1135	addi	28,sp,sp
1136	jmp	[r31]
1137	.size	__return_r28_r31,.-__return_r28_r31
1138#endif /* L_save_28c */
1139
1140#ifdef	L_save_29c
1141	.text
1142	.align	2
1143	.globl	__save_r29_r31
1144	.type	__save_r29_r31,@function
1145	/* Allocate space and save registers 29 & 31 on the stack */
1146	/* Also allocate space for the argument save area */
1147	/* Called via:	jalr __save_r29_r31,r10 */
1148__save_r29_r31:
1149	addi	-24,sp,sp
1150	st.w	r29,16[sp]
1151	st.w	r31,20[sp]
1152	jmp	[r10]
1153	.size	__save_r29_r31,.-__save_r29_r31
1154
1155	/* Restore saved registers, deallocate stack and return to the user */
1156	/* Called via:	jr __return_r29_r31 */
1157	.align	2
1158	.globl	__return_r29_r31
1159	.type	__return_r29_r31,@function
1160__return_r29_r31:
1161	ld.w	16[sp],r29
1162	ld.w	20[sp],r31
1163	addi	24,sp,sp
1164	jmp	[r31]
1165	.size	__return_r29_r31,.-__return_r29_r31
1166#endif /* L_save_29c */
1167
1168#ifdef	L_save_31c
1169	.text
1170	.align	2
1171	.globl	__save_r31
1172	.type	__save_r31,@function
1173	/* Allocate space and save register 31 on the stack.  */
1174	/* Also allocate space for the argument save area.  */
1175	/* Called via:	jalr __save_r31,r10 */
1176__save_r31:
1177	addi	-20,sp,sp
1178	st.w	r31,16[sp]
1179	jmp	[r10]
1180	.size	__save_r31,.-__save_r31
1181
1182	/* Restore saved registers, deallocate stack and return to the user.  */
1183	/* Called via:	jr __return_r31 */
1184	.align	2
1185	.globl	__return_r31
1186	.type	__return_r31,@function
1187__return_r31:
1188	ld.w	16[sp],r31
1189	addi	20,sp,sp
1190	jmp	[r31]
1191        .size   __return_r31,.-__return_r31
1192#endif /* L_save_31c */
1193
1194#ifdef L_save_varargs
1195	.text
1196	.align	2
1197	.globl	__save_r6_r9
1198	.type	__save_r6_r9,@function
1199	/* Save registers 6 .. 9 on the stack for variable argument functions.  */
1200	/* Called via:	jalr __save_r6_r9,r10 */
1201__save_r6_r9:
1202	mov	ep,r1
1203	mov	sp,ep
1204	sst.w	r6,0[ep]
1205	sst.w	r7,4[ep]
1206	sst.w	r8,8[ep]
1207	sst.w	r9,12[ep]
1208	mov	r1,ep
1209	jmp	[r10]
1210	.size	__save_r6_r9,.-__save_r6_r9
1211#endif /* L_save_varargs */
1212
1213#ifdef	L_save_interrupt
1214	.text
1215	.align	2
1216	.globl	__save_interrupt
1217	.type	__save_interrupt,@function
1218	/* Save registers r1, r4 on stack and load up with expected values.  */
1219	/* Note, 12 bytes of stack have already been allocated.  */
1220	/* Called via:	jalr __save_interrupt,r10 */
1221__save_interrupt:
1222	st.w	ep,0[sp]
1223	st.w	gp,4[sp]
1224	st.w	r1,8[sp]
1225	movhi	hi(__ep),r0,ep
1226	movea	lo(__ep),ep,ep
1227	movhi	hi(__gp),r0,gp
1228	movea	lo(__gp),gp,gp
1229	jmp	[r10]
1230	.size	__save_interrupt,.-__save_interrupt
1231
1232	/* Restore saved registers, deallocate stack and return from the interrupt.  */
1233	/* Called via:	jr __return_interrupt */
1234	.align	2
1235	.globl	__return_interrupt
1236	.type	__return_interrupt,@function
1237__return_interrupt:
1238	ld.w	0[sp],ep
1239	ld.w	4[sp],gp
1240	ld.w	8[sp],r1
1241	ld.w	12[sp],r10
1242	addi	16,sp,sp
1243	reti
1244	.size	__return_interrupt,.-__return_interrupt
1245#endif /* L_save_interrupt */
1246
1247#ifdef L_save_all_interrupt
1248	.text
1249	.align	2
1250	.globl	__save_all_interrupt
1251	.type	__save_all_interrupt,@function
1252	/* Save all registers except for those saved in __save_interrupt.  */
1253	/* Allocate enough stack for all of the registers & 16 bytes of space.  */
1254	/* Called via:	jalr __save_all_interrupt,r10 */
1255__save_all_interrupt:
1256	addi	-120,sp,sp
1257	mov	ep,r1
1258	mov	sp,ep
1259	sst.w	r31,116[ep]
1260	sst.w	r2,112[ep]
1261	sst.w	gp,108[ep]
1262	sst.w	r6,104[ep]
1263	sst.w	r7,100[ep]
1264	sst.w	r8,96[ep]
1265	sst.w	r9,92[ep]
1266	sst.w	r11,88[ep]
1267	sst.w	r12,84[ep]
1268	sst.w	r13,80[ep]
1269	sst.w	r14,76[ep]
1270	sst.w	r15,72[ep]
1271	sst.w	r16,68[ep]
1272	sst.w	r17,64[ep]
1273	sst.w	r18,60[ep]
1274	sst.w	r19,56[ep]
1275	sst.w	r20,52[ep]
1276	sst.w	r21,48[ep]
1277	sst.w	r22,44[ep]
1278	sst.w	r23,40[ep]
1279	sst.w	r24,36[ep]
1280	sst.w	r25,32[ep]
1281	sst.w	r26,28[ep]
1282	sst.w	r27,24[ep]
1283	sst.w	r28,20[ep]
1284	sst.w	r29,16[ep]
1285	mov	r1,ep
1286	jmp	[r10]
1287	.size	__save_all_interrupt,.-__save_all_interrupt
1288
1289	.globl	__restore_all_interrupt
1290	.type	__restore_all_interrupt,@function
1291	/* Restore all registers saved in __save_all_interrupt and
1292	   deallocate the stack space.  */
1293	/* Called via:	jalr __restore_all_interrupt,r10 */
1294__restore_all_interrupt:
1295	mov	ep,r1
1296	mov	sp,ep
1297	sld.w	116[ep],r31
1298	sld.w	112[ep],r2
1299	sld.w	108[ep],gp
1300	sld.w	104[ep],r6
1301	sld.w	100[ep],r7
1302	sld.w	96[ep],r8
1303	sld.w	92[ep],r9
1304	sld.w	88[ep],r11
1305	sld.w	84[ep],r12
1306	sld.w	80[ep],r13
1307	sld.w	76[ep],r14
1308	sld.w	72[ep],r15
1309	sld.w	68[ep],r16
1310	sld.w	64[ep],r17
1311	sld.w	60[ep],r18
1312	sld.w	56[ep],r19
1313	sld.w	52[ep],r20
1314	sld.w	48[ep],r21
1315	sld.w	44[ep],r22
1316	sld.w	40[ep],r23
1317	sld.w	36[ep],r24
1318	sld.w	32[ep],r25
1319	sld.w	28[ep],r26
1320	sld.w	24[ep],r27
1321	sld.w	20[ep],r28
1322	sld.w	16[ep],r29
1323	mov	r1,ep
1324	addi	120,sp,sp
1325	jmp	[r10]
1326	.size	__restore_all_interrupt,.-__restore_all_interrupt
1327#endif /* L_save_all_interrupt */
1328
1329
1330#if defined __v850e__
1331#ifdef	L_callt_save_r2_r29
1332	/* Put these functions into the call table area.  */
1333	.call_table_text
1334
1335	/* Allocate space and save registers 2, 20 .. 29 on the stack.  */
1336	/* Called via:	callt ctoff(__callt_save_r2_r29).  */
1337	.align	2
1338.L_save_r2_r29:
1339	add	-4, sp
1340	st.w	r2, 0[sp]
1341	prepare {r20 - r29}, 0
1342	ctret
1343
1344	/* Restore saved registers, deallocate stack and return to the user.  */
1345	/* Called via:	callt ctoff(__callt_return_r2_r29).  */
1346	.align	2
1347.L_return_r2_r29:
1348	dispose 0, {r20-r29}
1349	ld.w    0[sp], r2
1350	add	4, sp
1351	jmp     [r31]
1352
1353	/* Place the offsets of the start of these routines into the call table.  */
1354	.call_table_data
1355
1356	.global	__callt_save_r2_r29
1357	.type	__callt_save_r2_r29,@function
1358__callt_save_r2_r29:	.short ctoff(.L_save_r2_r29)
1359
1360	.global	__callt_return_r2_r29
1361	.type	__callt_return_r2_r29,@function
1362__callt_return_r2_r29:	.short ctoff(.L_return_r2_r29)
1363
1364#endif /* L_callt_save_r2_r29 */
1365
1366#ifdef	L_callt_save_r2_r31
1367	/* Put these functions into the call table area.  */
1368	.call_table_text
1369
1370	/* Allocate space and save registers 2 and 20 .. 29, 31 on the stack.  */
1371	/* Also allocate space for the argument save area.  */
1372	/* Called via:	callt ctoff(__callt_save_r2_r31).  */
1373	.align	2
1374.L_save_r2_r31:
1375	add	-4, sp
1376	st.w	r2, 0[sp]
1377	prepare {r20 - r29, r31}, 4
1378	ctret
1379
1380	/* Restore saved registers, deallocate stack and return to the user.  */
1381	/* Called via:	callt ctoff(__callt_return_r2_r31).  */
1382	.align	2
1383.L_return_r2_r31:
1384	dispose 4, {r20 - r29, r31}
1385	ld.w    0[sp], r2
1386	addi	4, sp, sp
1387	jmp     [r31]
1388
1389	/* Place the offsets of the start of these routines into the call table.  */
1390	.call_table_data
1391
1392	.global	__callt_save_r2_r31
1393	.type	__callt_save_r2_r31,@function
1394__callt_save_r2_r31:	.short ctoff(.L_save_r2_r31)
1395
1396	.global	__callt_return_r2_r31
1397	.type	__callt_return_r2_r31,@function
1398__callt_return_r2_r31:	.short ctoff(.L_return_r2_r31)
1399
1400#endif /* L_callt_save_r2_r31 */
1401
1402
1403#ifdef L_callt_save_r6_r9
1404	/* Put these functions into the call table area.  */
1405	.call_table_text
1406
1407	/* Save registers r6 - r9 onto the stack in the space reserved for them.
1408	   Use by variable argument functions.
1409	   Called via:	callt ctoff(__callt_save_r6_r9).  */
1410	.align	2
1411.L_save_r6_r9:
1412	mov	ep,r1
1413	mov	sp,ep
1414	sst.w	r6,0[ep]
1415	sst.w	r7,4[ep]
1416	sst.w	r8,8[ep]
1417	sst.w	r9,12[ep]
1418	mov	r1,ep
1419	ctret
1420
1421	/* Place the offsets of the start of this routines into the call table.  */
1422	.call_table_data
1423
1424	.global	__callt_save_r6_r9
1425	.type	__callt_save_r6_r9,@function
1426__callt_save_r6_r9:	.short ctoff(.L_save_r6_r9)
1427#endif /* L_callt_save_r6_r9 */
1428
1429
1430#ifdef	L_callt_save_interrupt
1431	/* Put this functions into the call table area */
1432	.call_table_text
1433
1434	/* Save registers r1, ep, gp, r10 on stack and load up with expected values.  */
1435	/* Called via:	callt ctoff(__callt_save_interrupt).  */
1436	.align	2
1437.L_save_interrupt:
1438        /* SP has already been moved before callt ctoff(_save_interrupt).  */
1439        /* addi -24, sp, sp  */
1440        st.w    ep,  0[sp]
1441        st.w    gp,  4[sp]
1442        st.w    r1,  8[sp]
1443        /* R10 has alread been saved bofore callt ctoff(_save_interrupt).  */
1444        /* st.w    r10, 12[sp]  */
1445	mov	hilo(__ep),ep
1446	mov	hilo(__gp),gp
1447	ctret
1448
1449        /* Place the offsets of the start of the routine into the call table.  */
1450        .call_table_data
1451        .global __callt_save_interrupt
1452        .type   __callt_save_interrupt,@function
1453__callt_save_interrupt: .short ctoff(.L_save_interrupt)
1454
1455        .call_table_text
1456
1457	/* Restore saved registers, deallocate stack and return from the interrupt.  */
1458        /* Called via:  callt ctoff(__callt_restore_itnerrupt).  */
1459	.text
1460	.align	2
1461	.globl	__return_interrupt
1462	.type	__return_interrupt,@function
1463.L_return_interrupt:
1464        ld.w    20[sp], r1
1465        ldsr    r1,     ctpsw
1466        ld.w    16[sp], r1
1467        ldsr    r1,     ctpc
1468        ld.w    12[sp], r10
1469        ld.w     8[sp], r1
1470        ld.w     4[sp], gp
1471        ld.w     0[sp], ep
1472        addi    24, sp, sp
1473        reti
1474
1475	/* Place the offsets of the start of the routine into the call table.  */
1476	.call_table_data
1477
1478        .global __callt_return_interrupt
1479        .type   __callt_return_interrupt,@function
1480__callt_return_interrupt:       .short ctoff(.L_return_interrupt)
1481
1482#endif /* L_callt_save_interrupt */
1483
1484#ifdef L_callt_save_all_interrupt
1485	/* Put this functions into the call table area.  */
1486	.call_table_text
1487
1488	/* Save all registers except for those saved in __save_interrupt.  */
1489	/* Allocate enough stack for all of the registers & 16 bytes of space.  */
1490	/* Called via:	callt ctoff(__callt_save_all_interrupt).  */
1491	.align	2
1492.L_save_all_interrupt:
1493	addi	-60, sp, sp
1494	mov	ep,  r1
1495	mov	sp,  ep
1496	sst.w	r2,  56[ep]
1497	sst.w	r5,  52[ep]
1498	sst.w	r6,  48[ep]
1499	sst.w	r7,  44[ep]
1500	sst.w	r8,  40[ep]
1501	sst.w	r9,  36[ep]
1502	sst.w	r11, 32[ep]
1503	sst.w	r12, 28[ep]
1504	sst.w	r13, 24[ep]
1505	sst.w	r14, 20[ep]
1506	sst.w	r15, 16[ep]
1507	sst.w	r16, 12[ep]
1508	sst.w	r17, 8[ep]
1509	sst.w	r18, 4[ep]
1510	sst.w	r19, 0[ep]
1511	mov	r1,  ep
1512
1513	prepare {r20 - r29, r31}, 4
1514	ctret
1515
1516	/* Restore all registers saved in __save_all_interrupt
1517	   deallocate the stack space.  */
1518	/* Called via:	callt ctoff(__callt_restore_all_interrupt).  */
1519	.align 2
1520.L_restore_all_interrupt:
1521	dispose 4, {r20 - r29, r31}
1522
1523	mov	ep, r1
1524	mov	sp, ep
1525	sld.w	0 [ep], r19
1526	sld.w	4 [ep], r18
1527	sld.w	8 [ep], r17
1528	sld.w	12[ep], r16
1529	sld.w	16[ep], r15
1530	sld.w	20[ep], r14
1531	sld.w	24[ep], r13
1532	sld.w	28[ep], r12
1533	sld.w	32[ep], r11
1534	sld.w	36[ep], r9
1535	sld.w	40[ep], r8
1536	sld.w	44[ep], r7
1537	sld.w	48[ep], r6
1538	sld.w	52[ep], r5
1539	sld.w	56[ep], r2
1540	mov	r1, ep
1541	addi	60, sp, sp
1542	ctret
1543
1544	/* Place the offsets of the start of these routines into the call table.  */
1545	.call_table_data
1546
1547	.global	__callt_save_all_interrupt
1548	.type	__callt_save_all_interrupt,@function
1549__callt_save_all_interrupt:	.short ctoff(.L_save_all_interrupt)
1550
1551	.global	__callt_restore_all_interrupt
1552	.type	__callt_restore_all_interrupt,@function
1553__callt_restore_all_interrupt:	.short ctoff(.L_restore_all_interrupt)
1554
1555#endif /* L_callt_save_all_interrupt */
1556
1557
1558#define MAKE_CALLT_FUNCS( START )						\
1559	.call_table_text							;\
1560	.align	2								;\
1561	/* Allocate space and save registers START .. r29 on the stack.  */	;\
1562	/* Called via:	callt ctoff(__callt_save_START_r29).  */		;\
1563.L_save_##START##_r29:								;\
1564	prepare { START - r29 }, 0						;\
1565	ctret									;\
1566										;\
1567	/* Restore saved registers, deallocate stack and return.  */		;\
1568	/* Called via:	callt ctoff(__return_START_r29) */			;\
1569	.align	2								;\
1570.L_return_##START##_r29:							;\
1571	dispose 0, { START - r29 }, r31						;\
1572										;\
1573	/* Place the offsets of the start of these funcs into the call table.  */;\
1574	.call_table_data							;\
1575										;\
1576	.global	__callt_save_##START##_r29					;\
1577	.type	__callt_save_##START##_r29,@function				;\
1578__callt_save_##START##_r29:	.short ctoff(.L_save_##START##_r29 )		;\
1579										;\
1580	.global	__callt_return_##START##_r29					;\
1581	.type	__callt_return_##START##_r29,@function				;\
1582__callt_return_##START##_r29:	.short ctoff(.L_return_##START##_r29 )
1583
1584
1585#define MAKE_CALLT_CFUNCS( START )						\
1586	.call_table_text							;\
1587	.align	2								;\
1588	/* Allocate space and save registers START .. r31 on the stack.  */	;\
1589	/* Called via:	callt ctoff(__callt_save_START_r31c).  */		;\
1590.L_save_##START##_r31c:								;\
1591	prepare { START - r29, r31}, 4						;\
1592	ctret									;\
1593										;\
1594	/* Restore saved registers, deallocate stack and return.  */		;\
1595	/* Called via:	callt ctoff(__return_START_r31c).  */			;\
1596	.align	2								;\
1597.L_return_##START##_r31c:							;\
1598	dispose 4, { START - r29, r31}, r31					;\
1599										;\
1600	/* Place the offsets of the start of these funcs into the call table.  */;\
1601	.call_table_data							;\
1602										;\
1603	.global	__callt_save_##START##_r31c					;\
1604	.type	__callt_save_##START##_r31c,@function				;\
1605__callt_save_##START##_r31c:    .short ctoff(.L_save_##START##_r31c )		;\
1606										;\
1607	.global	__callt_return_##START##_r31c					;\
1608	.type	__callt_return_##START##_r31c,@function				;\
1609__callt_return_##START##_r31c:  .short ctoff(.L_return_##START##_r31c )
1610
1611
1612#ifdef	L_callt_save_20
1613	MAKE_CALLT_FUNCS (r20)
1614#endif
1615#ifdef	L_callt_save_21
1616	MAKE_CALLT_FUNCS (r21)
1617#endif
1618#ifdef	L_callt_save_22
1619	MAKE_CALLT_FUNCS (r22)
1620#endif
1621#ifdef	L_callt_save_23
1622	MAKE_CALLT_FUNCS (r23)
1623#endif
1624#ifdef	L_callt_save_24
1625	MAKE_CALLT_FUNCS (r24)
1626#endif
1627#ifdef	L_callt_save_25
1628	MAKE_CALLT_FUNCS (r25)
1629#endif
1630#ifdef	L_callt_save_26
1631	MAKE_CALLT_FUNCS (r26)
1632#endif
1633#ifdef	L_callt_save_27
1634	MAKE_CALLT_FUNCS (r27)
1635#endif
1636#ifdef	L_callt_save_28
1637	MAKE_CALLT_FUNCS (r28)
1638#endif
1639#ifdef	L_callt_save_29
1640	MAKE_CALLT_FUNCS (r29)
1641#endif
1642
1643#ifdef	L_callt_save_20c
1644	MAKE_CALLT_CFUNCS (r20)
1645#endif
1646#ifdef	L_callt_save_21c
1647	MAKE_CALLT_CFUNCS (r21)
1648#endif
1649#ifdef	L_callt_save_22c
1650	MAKE_CALLT_CFUNCS (r22)
1651#endif
1652#ifdef	L_callt_save_23c
1653	MAKE_CALLT_CFUNCS (r23)
1654#endif
1655#ifdef	L_callt_save_24c
1656	MAKE_CALLT_CFUNCS (r24)
1657#endif
1658#ifdef	L_callt_save_25c
1659	MAKE_CALLT_CFUNCS (r25)
1660#endif
1661#ifdef	L_callt_save_26c
1662	MAKE_CALLT_CFUNCS (r26)
1663#endif
1664#ifdef	L_callt_save_27c
1665	MAKE_CALLT_CFUNCS (r27)
1666#endif
1667#ifdef	L_callt_save_28c
1668	MAKE_CALLT_CFUNCS (r28)
1669#endif
1670#ifdef	L_callt_save_29c
1671	MAKE_CALLT_CFUNCS (r29)
1672#endif
1673
1674
1675#ifdef	L_callt_save_31c
1676	.call_table_text
1677	.align	2
1678	/* Allocate space and save register r31 on the stack.  */
1679	/* Called via:	callt ctoff(__callt_save_r31c).  */
1680.L_callt_save_r31c:
1681	prepare {r31}, 4
1682	ctret
1683
1684	/* Restore saved registers, deallocate stack and return.  */
1685	/* Called via:	callt ctoff(__return_r31c).  */
1686	.align	2
1687.L_callt_return_r31c:
1688	dispose 4, {r31}, r31
1689
1690	/* Place the offsets of the start of these funcs into the call table.  */
1691	.call_table_data
1692
1693	.global	__callt_save_r31c
1694	.type	__callt_save_r31c,@function
1695__callt_save_r31c:	.short ctoff(.L_callt_save_r31c)
1696
1697	.global	__callt_return_r31c
1698	.type	__callt_return_r31c,@function
1699__callt_return_r31c:	.short ctoff(.L_callt_return_r31c)
1700#endif
1701
1702#endif /* __v850e__ */
1703
1704/*  libgcc2 routines for NEC V850.  */
1705/*  Double Integer Arithmetical Operation.  */
1706
1707#ifdef L_negdi2
1708	.text
1709	.global ___negdi2
1710	.type   ___negdi2, @function
1711___negdi2:
1712	not	r6, r10
1713	add	1,  r10
1714	setf	l,  r6
1715	not	r7, r11
1716	add	r6, r11
1717	jmp	[lp]
1718
1719	.size ___negdi2,.-___negdi2
1720#endif
1721
1722#ifdef L_cmpdi2
1723	.text
1724	.global ___cmpdi2
1725	.type	___cmpdi2,@function
1726___cmpdi2:
1727	# Signed comparison bitween each high word.
1728	cmp	r9, r7
1729	be	.L_cmpdi_cmp_low
1730	setf	ge, r10
1731	setf	gt, r6
1732	add	r6, r10
1733	jmp	[lp]
1734.L_cmpdi_cmp_low:
1735	# Unsigned comparigon bitween each low word.
1736	cmp     r8, r6
1737	setf	nl, r10
1738	setf	h,  r6
1739	add	r6, r10
1740	jmp	[lp]
1741	.size ___cmpdi2, . - ___cmpdi2
1742#endif
1743
1744#ifdef L_ucmpdi2
1745	.text
1746	.global ___ucmpdi2
1747	.type	___ucmpdi2,@function
1748___ucmpdi2:
1749	cmp	r9, r7  # Check if each high word are same.
1750	be	.L_ucmpdi_check_psw
1751	cmp     r8, r6  # Compare the word.
1752.L_ucmpdi_check_psw:
1753	setf	nl, r10 #
1754	setf	h,  r6  #
1755	add	r6, r10 # Add the result of comparison NL and comparison H.
1756	jmp	[lp]
1757	.size ___ucmpdi2, . - ___ucmpdi2
1758#endif
1759
1760#ifdef L_muldi3
1761	.text
1762	.global ___muldi3
1763	.type	___muldi3,@function
1764___muldi3:
1765#ifdef __v850__
1766        jarl  __save_r26_r31, r10
1767        addi  16,  sp, sp
1768        mov   r6,  r28
1769        shr   15,  r28
1770        movea lo(32767), r0, r14
1771        and   r14, r28
1772        mov   r8,  r10
1773        shr   15,  r10
1774        and   r14, r10
1775        mov   r6,  r19
1776        shr   30,  r19
1777        mov   r7,  r12
1778        shl   2,   r12
1779        or    r12, r19
1780        and   r14, r19
1781        mov   r8,  r13
1782        shr   30,  r13
1783        mov   r9,  r12
1784        shl   2,   r12
1785        or    r12, r13
1786        and   r14, r13
1787        mov   r7,  r11
1788        shr   13,  r11
1789        and   r14, r11
1790        mov   r9,  r31
1791        shr   13,  r31
1792        and   r14, r31
1793        mov   r7,  r29
1794        shr   28,  r29
1795        and   r14, r29
1796        mov   r9,  r12
1797        shr   28,  r12
1798        and   r14, r12
1799        and   r14, r6
1800        and   r14, r8
1801        mov   r6,  r14
1802        mulh  r8,  r14
1803        mov   r6,  r16
1804        mulh  r10, r16
1805        mov   r6,  r18
1806        mulh  r13, r18
1807        mov   r6,  r15
1808        mulh  r31, r15
1809        mulh  r12, r6
1810        mov   r28,  r17
1811        mulh  r10, r17
1812        add   -16, sp
1813        mov   r28,  r12
1814        mulh  r8,  r12
1815        add   r17, r18
1816        mov   r28,  r17
1817        mulh  r31, r17
1818        add   r12, r16
1819        mov   r28,  r12
1820        mulh  r13, r12
1821        add   r17, r6
1822        mov   r19, r17
1823        add   r12, r15
1824        mov   r19, r12
1825        mulh  r8,  r12
1826        mulh  r10, r17
1827        add   r12, r18
1828        mov   r19, r12
1829        mulh  r13, r12
1830        add   r17, r15
1831        mov   r11, r13
1832        mulh  r8,  r13
1833        add   r12, r6
1834        mov   r11, r12
1835        mulh  r10, r12
1836        add   r13, r15
1837        mulh  r29, r8
1838        add   r12, r6
1839        mov   r16, r13
1840        shl   15,  r13
1841        add   r14, r13
1842        mov   r18, r12
1843        shl   30,  r12
1844        mov   r13, r26
1845        add   r12, r26
1846        shr   15,  r14
1847        movhi hi(131071), r0,  r12
1848        movea lo(131071), r12, r13
1849        and   r13, r14
1850        mov   r16, r12
1851        and   r13, r12
1852        add   r12, r14
1853        mov   r18, r12
1854        shl   15,  r12
1855        and   r13, r12
1856        add   r12, r14
1857        shr   17,  r14
1858        shr   17,  r16
1859        add   r14, r16
1860        shl   13,  r15
1861        shr   2,   r18
1862        add   r18, r15
1863        add   r15, r16
1864        mov   r16, r27
1865        add   r8,  r6
1866        shl   28,  r6
1867        add   r6,  r27
1868        mov   r26, r10
1869        mov   r27, r11
1870        jr    __return_r26_r31
1871#endif /* __v850__ */
1872#if defined(__v850e__) || defined(__v850ea__)
1873	/*  (Ahi << 32 + Alo) * (Bhi << 32 + Blo) */
1874	/*   r7           r6      r9         r8   */
1875	mov  r8, r10
1876	mulu r7, r8,  r0		/* Ahi * Blo */
1877	mulu r6, r9,  r0		/* Alo * Bhi */
1878	mulu r6, r10, r11		/* Alo * Blo */
1879	add  r8, r11
1880	add  r9, r11
1881	jmp  [r31]
1882
1883#endif /* defined(__v850e__)  || defined(__v850ea__) */
1884	.size ___muldi3, . - ___muldi3
1885#endif
1886