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