xref: /OK3568_Linux_fs/kernel/arch/m68k/lib/divsi3.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun/* libgcc1 routines for 68000 w/o floating-point hardware.
2*4882a593Smuzhiyun   Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunThis file is part of GNU CC.
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunGNU CC is free software; you can redistribute it and/or modify it
7*4882a593Smuzhiyununder the terms of the GNU General Public License as published by the
8*4882a593SmuzhiyunFree Software Foundation; either version 2, or (at your option) any
9*4882a593Smuzhiyunlater version.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIn addition to the permissions in the GNU General Public License, the
12*4882a593SmuzhiyunFree Software Foundation gives you unlimited permission to link the
13*4882a593Smuzhiyuncompiled version of this file with other programs, and to distribute
14*4882a593Smuzhiyunthose programs without any restriction coming from the use of this
15*4882a593Smuzhiyunfile.  (The General Public License restrictions do apply in other
16*4882a593Smuzhiyunrespects; for example, they cover modification of the file, and
17*4882a593Smuzhiyundistribution when not linked into another program.)
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunThis file is distributed in the hope that it will be useful, but
20*4882a593SmuzhiyunWITHOUT ANY WARRANTY; without even the implied warranty of
21*4882a593SmuzhiyunMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22*4882a593SmuzhiyunGeneral Public License for more details. */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun/* As a special exception, if you link this library with files
25*4882a593Smuzhiyun   compiled with GCC to produce an executable, this does not cause
26*4882a593Smuzhiyun   the resulting executable to be covered by the GNU General Public License.
27*4882a593Smuzhiyun   This exception does not however invalidate any other reasons why
28*4882a593Smuzhiyun   the executable file might be covered by the GNU General Public License.  */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun/* Use this one for any 680x0; assumes no floating point hardware.
31*4882a593Smuzhiyun   The trailing " '" appearing on some lines is for ANSI preprocessors.  Yuk.
32*4882a593Smuzhiyun   Some of this code comes from MINIX, via the folks at ericsson.
33*4882a593Smuzhiyun   D. V. Henkel-Wallace (gumby@cygnus.com) Fete Bastille, 1992
34*4882a593Smuzhiyun*/
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun#include <asm/export.h>
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun/* These are predefined by new versions of GNU cpp.  */
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun#ifndef __USER_LABEL_PREFIX__
41*4882a593Smuzhiyun#define __USER_LABEL_PREFIX__ _
42*4882a593Smuzhiyun#endif
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun#ifndef __REGISTER_PREFIX__
45*4882a593Smuzhiyun#define __REGISTER_PREFIX__
46*4882a593Smuzhiyun#endif
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun#ifndef __IMMEDIATE_PREFIX__
49*4882a593Smuzhiyun#define __IMMEDIATE_PREFIX__ #
50*4882a593Smuzhiyun#endif
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun/* ANSI concatenation macros.  */
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun#define CONCAT1(a, b) CONCAT2(a, b)
55*4882a593Smuzhiyun#define CONCAT2(a, b) a ## b
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun/* Use the right prefix for global labels.  */
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun/* Use the right prefix for registers.  */
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun/* Use the right prefix for immediate values.  */
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun#define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun#define d0 REG (d0)
70*4882a593Smuzhiyun#define d1 REG (d1)
71*4882a593Smuzhiyun#define d2 REG (d2)
72*4882a593Smuzhiyun#define d3 REG (d3)
73*4882a593Smuzhiyun#define d4 REG (d4)
74*4882a593Smuzhiyun#define d5 REG (d5)
75*4882a593Smuzhiyun#define d6 REG (d6)
76*4882a593Smuzhiyun#define d7 REG (d7)
77*4882a593Smuzhiyun#define a0 REG (a0)
78*4882a593Smuzhiyun#define a1 REG (a1)
79*4882a593Smuzhiyun#define a2 REG (a2)
80*4882a593Smuzhiyun#define a3 REG (a3)
81*4882a593Smuzhiyun#define a4 REG (a4)
82*4882a593Smuzhiyun#define a5 REG (a5)
83*4882a593Smuzhiyun#define a6 REG (a6)
84*4882a593Smuzhiyun#define fp REG (fp)
85*4882a593Smuzhiyun#define sp REG (sp)
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun	.text
88*4882a593Smuzhiyun	.proc
89*4882a593Smuzhiyun	.globl	SYM (__divsi3)
90*4882a593SmuzhiyunSYM (__divsi3):
91*4882a593Smuzhiyun	movel	d2, sp@-
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun	moveq	IMM (1), d2	/* sign of result stored in d2 (=1 or =-1) */
94*4882a593Smuzhiyun	movel	sp@(12), d1	/* d1 = divisor */
95*4882a593Smuzhiyun	jpl	L1
96*4882a593Smuzhiyun	negl	d1
97*4882a593Smuzhiyun#if !(defined(__mcf5200__) || defined(__mcoldfire__))
98*4882a593Smuzhiyun	negb	d2		/* change sign because divisor <0  */
99*4882a593Smuzhiyun#else
100*4882a593Smuzhiyun	negl	d2		/* change sign because divisor <0  */
101*4882a593Smuzhiyun#endif
102*4882a593SmuzhiyunL1:	movel	sp@(8), d0	/* d0 = dividend */
103*4882a593Smuzhiyun	jpl	L2
104*4882a593Smuzhiyun	negl	d0
105*4882a593Smuzhiyun#if !(defined(__mcf5200__) || defined(__mcoldfire__))
106*4882a593Smuzhiyun	negb	d2
107*4882a593Smuzhiyun#else
108*4882a593Smuzhiyun	negl	d2
109*4882a593Smuzhiyun#endif
110*4882a593Smuzhiyun
111*4882a593SmuzhiyunL2:	movel	d1, sp@-
112*4882a593Smuzhiyun	movel	d0, sp@-
113*4882a593Smuzhiyun	jbsr	SYM (__udivsi3)	/* divide abs(dividend) by abs(divisor) */
114*4882a593Smuzhiyun	addql	IMM (8), sp
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun	tstb	d2
117*4882a593Smuzhiyun	jpl	L3
118*4882a593Smuzhiyun	negl	d0
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunL3:	movel	sp@+, d2
121*4882a593Smuzhiyun	rts
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun	EXPORT_SYMBOL(__divsi3)
124