⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lb1sf68.asm

📁 gcc-you can use this code to learn something about gcc, and inquire further into linux,
💻 ASM
📖 第 1 页 / 共 5 页
字号:
/* libgcc routines for 68000 w/o floating-point hardware.   Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2, or (at your option) anylater version.In addition to the permissions in the GNU General Public License, theFree Software Foundation gives you unlimited permission to link thecompiled version of this file with other programs, and to distributethose programs without any restriction coming from the use of thisfile.  (The General Public License restrictions do apply in otherrespects; for example, they cover modification of the file, anddistribution when not linked into another program.)This file is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  *//* As a special exception, if you link this library with files   compiled with GCC to produce an executable, this does not cause   the resulting executable to be covered by the GNU General Public License.   This exception does not however invalidate any other reasons why   the executable file might be covered by the GNU General Public License.  *//* Use this one for any 680x0; assumes no floating point hardware.   The trailing " '" appearing on some lines is for ANSI preprocessors.  Yuk.   Some of this code comes from MINIX, via the folks at ericsson.   D. V. Henkel-Wallace (gumby@cygnus.com) Fete Bastille, 1992*//* These are predefined by new versions of GNU cpp.  */#ifndef __USER_LABEL_PREFIX__#define __USER_LABEL_PREFIX__ _#endif#ifndef __REGISTER_PREFIX__#define __REGISTER_PREFIX__#endif#ifndef __IMMEDIATE_PREFIX__#define __IMMEDIATE_PREFIX__ ##endif/* ANSI concatenation macros.  */#define CONCAT1(a, b) CONCAT2(a, b)#define CONCAT2(a, b) a ## b/* Use the right prefix for global labels.  */#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)/* Use the right prefix for registers.  */#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)/* Use the right prefix for immediate values.  */#define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)#define d0 REG (d0)#define d1 REG (d1)#define d2 REG (d2)#define d3 REG (d3)#define d4 REG (d4)#define d5 REG (d5)#define d6 REG (d6)#define d7 REG (d7)#define a0 REG (a0)#define a1 REG (a1)#define a2 REG (a2)#define a3 REG (a3)#define a4 REG (a4)#define a5 REG (a5)#define a6 REG (a6)#define fp REG (fp)#define sp REG (sp)#ifdef L_floatex| This is an attempt at a decent floating point (single, double and | extended double) code for the GNU C compiler. It should be easy to| adapt to other compilers (but beware of the local labels!).| Starting date: 21 October, 1990| It is convenient to introduce the notation (s,e,f) for a floating point| number, where s=sign, e=exponent, f=fraction. We will call a floating| point number fpn to abbreviate, independently of the precision.| Let MAX_EXP be in each case the maximum exponent (255 for floats, 1023 | for doubles and 16383 for long doubles). We then have the following | different cases:|  1. Normalized fpns have 0 < e < MAX_EXP. They correspond to |     (-1)^s x 1.f x 2^(e-bias-1).|  2. Denormalized fpns have e=0. They correspond to numbers of the form|     (-1)^s x 0.f x 2^(-bias).|  3. +/-INFINITY have e=MAX_EXP, f=0.|  4. Quiet NaN (Not a Number) have all bits set.|  5. Signaling NaN (Not a Number) have s=0, e=MAX_EXP, f=1.|=============================================================================|                                  exceptions|=============================================================================| This is the floating point condition code register (_fpCCR):|| struct {|   short _exception_bits;	|   short _trap_enable_bits;	|   short _sticky_bits;|   short _rounding_mode;|   short _format;|   short _last_operation;|   union {|     float sf;|     double df;|   } _operand1;|   union {|     float sf;|     double df;|   } _operand2;| } _fpCCR;	.data	.even	.globl	SYM (_fpCCR)	SYM (_fpCCR):__exception_bits:	.word	0__trap_enable_bits:	.word	0__sticky_bits:	.word	0__rounding_mode:	.word	ROUND_TO_NEAREST__format:	.word	NIL__last_operation:	.word	NOOP__operand1:	.long	0	.long	0__operand2:	.long 	0	.long	0| Offsets:EBITS  = __exception_bits - SYM (_fpCCR)TRAPE  = __trap_enable_bits - SYM (_fpCCR)STICK  = __sticky_bits - SYM (_fpCCR)ROUND  = __rounding_mode - SYM (_fpCCR)FORMT  = __format - SYM (_fpCCR)LASTO  = __last_operation - SYM (_fpCCR)OPER1  = __operand1 - SYM (_fpCCR)OPER2  = __operand2 - SYM (_fpCCR)| The following exception types are supported:INEXACT_RESULT 		= 0x0001UNDERFLOW 		= 0x0002OVERFLOW 		= 0x0004DIVIDE_BY_ZERO 		= 0x0008INVALID_OPERATION 	= 0x0010| The allowed rounding modes are:UNKNOWN           = -1ROUND_TO_NEAREST  = 0 | round result to nearest representable valueROUND_TO_ZERO     = 1 | round result towards zeroROUND_TO_PLUS     = 2 | round result towards plus infinityROUND_TO_MINUS    = 3 | round result towards minus infinity| The allowed values of format are:NIL          = 0SINGLE_FLOAT = 1DOUBLE_FLOAT = 2LONG_FLOAT   = 3| The allowed values for the last operation are:NOOP         = 0ADD          = 1MULTIPLY     = 2DIVIDE       = 3NEGATE       = 4COMPARE      = 5EXTENDSFDF   = 6TRUNCDFSF    = 7|=============================================================================|                           __clear_sticky_bits|=============================================================================| The sticky bits are normally not cleared (thus the name), whereas the | exception type and exception value reflect the last computation. | This routine is provided to clear them (you can also write to _fpCCR,| since it is globally visible).	.globl  SYM (__clear_sticky_bit)	.text	.even| void __clear_sticky_bits(void);SYM (__clear_sticky_bit):			lea	SYM (_fpCCR),a0#ifndef __mcf5200__	movew	IMM (0),a0@(STICK)#else	clr.w	a0@(STICK)#endif	rts|=============================================================================|                           $_exception_handler|=============================================================================	.globl  $_exception_handler	.text	.even| This is the common exit point if an exception occurs.| NOTE: it is NOT callable from C!| It expects the exception type in d7, the format (SINGLE_FLOAT,| DOUBLE_FLOAT or LONG_FLOAT) in d6, and the last operation code in d5.| It sets the corresponding exception and sticky bits, and the format. | Depending on the format if fills the corresponding slots for the | operands which produced the exception (all this information is provided| so if you write your own exception handlers you have enough information| to deal with the problem).| Then checks to see if the corresponding exception is trap-enabled, | in which case it pushes the address of _fpCCR and traps through | trap FPTRAP (15 for the moment).FPTRAP = 15$_exception_handler:	lea	SYM (_fpCCR),a0	movew	d7,a0@(EBITS)	| set __exception_bits#ifndef __mcf5200__	orw	d7,a0@(STICK)	| and __sticky_bits#else	movew	a0@(STICK),d4	orl	d7,d4	movew	d4,a0@(STICK)#endif	movew	d6,a0@(FORMT)	| and __format	movew	d5,a0@(LASTO)	| and __last_operation| Now put the operands in place:#ifndef __mcf5200__	cmpw	IMM (SINGLE_FLOAT),d6#else	cmpl	IMM (SINGLE_FLOAT),d6#endif	beq	1f	movel	a6@(8),a0@(OPER1)	movel	a6@(12),a0@(OPER1+4)	movel	a6@(16),a0@(OPER2)	movel	a6@(20),a0@(OPER2+4)	bra	2f1:	movel	a6@(8),a0@(OPER1)	movel	a6@(12),a0@(OPER2)2:| And check whether the exception is trap-enabled:#ifndef __mcf5200__	andw	a0@(TRAPE),d7	| is exception trap-enabled?#else	clrl	d6	movew	a0@(TRAPE),d6	andl	d6,d7#endif	beq	1f		| no, exit	pea	SYM (_fpCCR)	| yes, push address of _fpCCR	trap	IMM (FPTRAP)	| and trap#ifndef __mcf5200__1:	moveml	sp@+,d2-d7	| restore data registers#else1:	moveml	sp@,d2-d7	| XXX if frame pointer is ever removed, stack pointer must	| be adjusted here.#endif	unlk	a6		| and return	rts#endif /* L_floatex */#ifdef  L_mulsi3	.text	.proc	.globl	SYM (__mulsi3)SYM (__mulsi3):	movew	sp@(4), d0	/* x0 -> d0 */	muluw	sp@(10), d0	/* x0*y1 */	movew	sp@(6), d1	/* x1 -> d1 */	muluw	sp@(8), d1	/* x1*y0 */#ifndef __mcf5200__	addw	d1, d0#else	addl	d1, d0#endif	swap	d0	clrw	d0	movew	sp@(6), d1	/* x1 -> d1 */	muluw	sp@(10), d1	/* x1*y1 */	addl	d1, d0	rts#endif /* L_mulsi3 */#ifdef  L_udivsi3	.text	.proc	.globl	SYM (__udivsi3)SYM (__udivsi3):#ifndef __mcf5200__	movel	d2, sp@-	movel	sp@(12), d1	/* d1 = divisor */	movel	sp@(8), d0	/* d0 = dividend */	cmpl	IMM (0x10000), d1 /* divisor >= 2 ^ 16 ?   */	jcc	L3		/* then try next algorithm */	movel	d0, d2	clrw	d2	swap	d2	divu	d1, d2          /* high quotient in lower word */	movew	d2, d0		/* save high quotient */	swap	d0	movew	sp@(10), d2	/* get low dividend + high rest */	divu	d1, d2		/* low quotient */	movew	d2, d0	jra	L6L3:	movel	d1, d2		/* use d2 as divisor backup */L4:	lsrl	IMM (1), d1	/* shift divisor */	lsrl	IMM (1), d0	/* shift dividend */	cmpl	IMM (0x10000), d1 /* still divisor >= 2 ^ 16 ?  */	jcc	L4	divu	d1, d0		/* now we have 16 bit divisor */	andl	IMM (0xffff), d0 /* mask out divisor, ignore remainder *//* Multiply the 16 bit tentative quotient with the 32 bit divisor.  Because of   the operand ranges, this might give a 33 bit product.  If this product is   greater than the dividend, the tentative quotient was too large. */	movel	d2, d1	mulu	d0, d1		/* low part, 32 bits */	swap	d2	mulu	d0, d2		/* high part, at most 17 bits */	swap	d2		/* align high part with low part */	tstw	d2		/* high part 17 bits? */	jne	L5		/* if 17 bits, quotient was too large */	addl	d2, d1		/* add parts */	jcs	L5		/* if sum is 33 bits, quotient was too large */	cmpl	sp@(8), d1	/* compare the sum with the dividend */	jls	L6		/* if sum > dividend, quotient was too large */L5:	subql	IMM (1), d0	/* adjust quotient */L6:	movel	sp@+, d2	rts#else /* __mcf5200__ *//* Coldfire implementation of non-restoring division algorithm from   Hennessy & Patterson, Appendix A. */	link	a6,IMM (-12)	moveml	d2-d4,sp@	movel	a6@(8),d0	movel	a6@(12),d1	clrl	d2		| clear p	moveq	IMM (31),d4L1:	addl	d0,d0		| shift reg pair (p,a) one bit left	addxl	d2,d2	movl	d2,d3		| subtract b from p, store in tmp.	subl	d1,d3	jcs	L2		| if no carry,	bset	IMM (0),d0	| set the low order bit of a to 1,	movl	d3,d2		| and store tmp in p.L2:	subql	IMM (1),d4	jcc	L1	moveml	sp@,d2-d4	| restore data registers	unlk	a6		| and return	rts#endif /* __mcf5200__ */#endif /* L_udivsi3 */#ifdef  L_divsi3	.text	.proc	.globl	SYM (__divsi3)SYM (__divsi3):	movel	d2, sp@-	moveq	IMM (1), d2	/* sign of result stored in d2 (=1 or =-1) */	movel	sp@(12), d1	/* d1 = divisor */	jpl	L1	negl	d1#ifndef __mcf5200__	negb	d2		/* change sign because divisor <0  */#else	negl	d2		/* change sign because divisor <0  */#endifL1:	movel	sp@(8), d0	/* d0 = dividend */	jpl	L2	negl	d0#ifndef __mcf5200__	negb	d2#else	negl	d2#endifL2:	movel	d1, sp@-	movel	d0, sp@-	jbsr	SYM (__udivsi3)	/* divide abs(dividend) by abs(divisor) */	addql	IMM (8), sp	tstb	d2	jpl	L3	negl	d0L3:	movel	sp@+, d2	rts#endif /* L_divsi3 */#ifdef  L_umodsi3	.text	.proc	.globl	SYM (__umodsi3)SYM (__umodsi3):	movel	sp@(8), d1	/* d1 = divisor */	movel	sp@(4), d0	/* d0 = dividend */	movel	d1, sp@-	movel	d0, sp@-	jbsr	SYM (__udivsi3)	addql	IMM (8), sp	movel	sp@(8), d1	/* d1 = divisor */#ifndef __mcf5200__	movel	d1, sp@-	movel	d0, sp@-	jbsr	SYM (__mulsi3)	/* d0 = (a/b)*b */	addql	IMM (8), sp#else	mulsl	d1,d0#endif	movel	sp@(4), d1	/* d1 = dividend */	subl	d0, d1		/* d1 = a - (a/b)*b */	movel	d1, d0	rts#endif /* L_umodsi3 */#ifdef  L_modsi3	.text	.proc	.globl	SYM (__modsi3)SYM (__modsi3):	movel	sp@(8), d1	/* d1 = divisor */	movel	sp@(4), d0	/* d0 = dividend */	movel	d1, sp@-	movel	d0, sp@-	jbsr	SYM (__divsi3)	addql	IMM (8), sp	movel	sp@(8), d1	/* d1 = divisor */#ifndef __mcf5200__	movel	d1, sp@-	movel	d0, sp@-	jbsr	SYM (__mulsi3)	/* d0 = (a/b)*b */	addql	IMM (8), sp#else	mulsl	d1,d0#endif	movel	sp@(4), d1	/* d1 = dividend */	subl	d0, d1		/* d1 = a - (a/b)*b */	movel	d1, d0	rts#endif /* L_modsi3 */#ifdef  L_double	.globl	SYM (_fpCCR)	.globl  $_exception_handlerQUIET_NaN      = 0xffffffffD_MAX_EXP      = 0x07ffD_BIAS         = 1022DBL_MAX_EXP    = D_MAX_EXP - D_BIASDBL_MIN_EXP    = 1 - D_BIASDBL_MANT_DIG   = 53INEXACT_RESULT 		= 0x0001UNDERFLOW 		= 0x0002OVERFLOW 		= 0x0004DIVIDE_BY_ZERO 		= 0x0008INVALID_OPERATION 	= 0x0010DOUBLE_FLOAT = 2NOOP         = 0ADD          = 1MULTIPLY     = 2DIVIDE       = 3NEGATE       = 4COMPARE      = 5EXTENDSFDF   = 6TRUNCDFSF    = 7UNKNOWN           = -1ROUND_TO_NEAREST  = 0 | round result to nearest representable valueROUND_TO_ZERO     = 1 | round result towards zeroROUND_TO_PLUS     = 2 | round result towards plus infinityROUND_TO_MINUS    = 3 | round result towards minus infinity| Entry points:	.globl SYM (__adddf3)	.globl SYM (__subdf3)	.globl SYM (__muldf3)	.globl SYM (__divdf3)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -