11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* libgcc1 routines for 68000 w/o floating-point hardware.
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsThis file is part of GNU CC.
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsGNU CC is free software; you can redistribute it and/or modify it
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsunder the terms of the GNU General Public License as published by the
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsFree Software Foundation; either version 2, or (at your option) any
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldslater version.
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsIn addition to the permissions in the GNU General Public License, the
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsFree Software Foundation gives you unlimited permission to link the
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldscompiled version of this file with other programs, and to distribute
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsthose programs without any restriction coming from the use of this
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsfile.  (The General Public License restrictions do apply in other
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsrespects; for example, they cover modification of the file, and
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdistribution when not linked into another program.)
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsThis file is distributed in the hope that it will be useful, but
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsWITHOUT ANY WARRANTY; without even the implied warranty of
211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsGeneral Public License for more details.
231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsYou should have received a copy of the GNU General Public License
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsalong with this program; see the file COPYING.  If not, write to
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsthe Free Software Foundation, 59 Temple Place - Suite 330,
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsBoston, MA 02111-1307, USA.  */
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* As a special exception, if you link this library with files
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   compiled with GCC to produce an executable, this does not cause
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   the resulting executable to be covered by the GNU General Public License.
321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   This exception does not however invalidate any other reasons why
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   the executable file might be covered by the GNU General Public License.  */
341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Use this one for any 680x0; assumes no floating point hardware.
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   The trailing " '" appearing on some lines is for ANSI preprocessors.  Yuk.
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   Some of this code comes from MINIX, via the folks at ericsson.
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   D. V. Henkel-Wallace (gumby@cygnus.com) Fete Bastille, 1992
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* These are predefined by new versions of GNU cpp.  */
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __USER_LABEL_PREFIX__
441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __USER_LABEL_PREFIX__ _
451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __REGISTER_PREFIX__
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __REGISTER_PREFIX__
491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __IMMEDIATE_PREFIX__
521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __IMMEDIATE_PREFIX__ #
531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ANSI concatenation macros.  */
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CONCAT1(a, b) CONCAT2(a, b)
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define CONCAT2(a, b) a ## b
591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Use the right prefix for global labels.  */
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Use the right prefix for registers.  */
651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Use the right prefix for immediate values.  */
691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)
711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d0 REG (d0)
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d1 REG (d1)
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d2 REG (d2)
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d3 REG (d3)
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d4 REG (d4)
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d5 REG (d5)
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d6 REG (d6)
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define d7 REG (d7)
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a0 REG (a0)
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a1 REG (a1)
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a2 REG (a2)
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a3 REG (a3)
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a4 REG (a4)
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a5 REG (a5)
861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define a6 REG (a6)
871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define fp REG (fp)
881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define sp REG (sp)
891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.text
911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.proc
921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	.globl	SYM (__divsi3)
931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsSYM (__divsi3):
941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	movel	d2, sp@-
951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	moveq	IMM (1), d2	/* sign of result stored in d2 (=1 or =-1) */
971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	movel	sp@(12), d1	/* d1 = divisor */
981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jpl	L1
991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negl	d1
1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if !(defined(__mcf5200__) || defined(__mcoldfire__))
1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negb	d2		/* change sign because divisor <0  */
1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negl	d2		/* change sign because divisor <0  */
1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsL1:	movel	sp@(8), d0	/* d0 = dividend */
1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jpl	L2
1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negl	d0
1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if !(defined(__mcf5200__) || defined(__mcoldfire__))
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negb	d2
1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negl	d2
1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsL2:	movel	d1, sp@-
1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	movel	d0, sp@-
1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jbsr	SYM (__udivsi3)	/* divide abs(dividend) by abs(divisor) */
1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	addql	IMM (8), sp
1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	tstb	d2
1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	jpl	L3
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	negl	d0
1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsL3:	movel	sp@+, d2
1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds	rts
1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
126