udivsi3.S 3.3 KB

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