Annotation of sys/lib/libkern/arch/sh/udivsi3.S, Revision 1.1.1.1
1.1 nbrk 1: /* $NetBSD: udivsi3.S,v 1.7 2006/05/22 20:56:44 uwe Exp $ */
2:
3: /*-
4: * Copyright (c) 1990 The Regents of the University of California.
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to Berkeley by
8: * William Jolitz.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. Neither the name of the University nor the names of its contributors
19: * may be used to endorse or promote products derived from this software
20: * without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32: * SUCH DAMAGE.
33: *
34: * from: @(#)udivsi3.s 5.1 (Berkeley) 5/15/90
35: */
36:
37: #include <machine/asm.h>
38:
39: /*
40: * IMPORTANT: This function is special.
41: *
42: * This function is an auxiliary function that is referenced by the
43: * code generated by gcc for integer division. But gcc does NOT treat
44: * a call to this function as an ordinary function call w.r.t. the set
45: * of register this call clobbers. See the definition of "udivsi3_i1"
46: * in gcc/config/sh/sh.md.
47: *
48: * Any call to this function MUST NOT clobber any registers besides r4
49: * and r0, where the result is returned. At the time of the call the
50: * r4 contains the first argument, so we are only left with r0, and we
51: * cannot do anything meaningful using only one register. The
52: * consequences are:
53: *
54: * . this function cannot have _PROF_PROLOGUE
55: * . this function cannot be called via PLT
56: */
57:
58:
59: /* r0 <= r4 / r5 */
60: NENTRY(__udivsi3)
61: tst r5, r5
62: bt div_by_zero
63:
64: mov #0, r0
65: div0u
66: #define DIVSTEP rotcl r4; div1 r5, r0
67: /* repeat 32 times */
68: DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP;
69: DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP;
70: DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP;
71: DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP; DIVSTEP;
72: #undef DIVSTEP
73: rotcl r4
74:
75: rts
76: mov r4, r0
77:
78: div_by_zero:
79: #ifdef _KERNEL
80: rts
81: mov #0, r0
82: #else
83: mov.l r14, @-r15
84: sts.l pr, @-r15
85: mov r15, r14
86:
87: mov.l L_raise, r1
88: #ifdef PIC
89: 1: bsrf r1
90: #else
91: jsr @r1
92: #endif
93: mov #8, r4 /* delay slot. 8 <- SIGFPE. */
94: mov #0, r0
95:
96: lds.l @r15+, pr
97: rts
98: mov.l @r15+, r14
99:
100: .align 2
101: L_raise:
102: #ifdef PIC
103: .long _C_LABEL(raise)-(1b+4)
104: #else
105: .long _C_LABEL(raise)
106: #endif
107: #endif
CVSweb