modsi3.S revision 1.4
11.4Srin/* $NetBSD: modsi3.S,v 1.4 2020/04/23 03:12:49 rin Exp $ */ 21.1Sfredette 31.1Sfredette/*- 41.3Srin * Copyright (c) 1990 The Regents of the University of California. 51.1Sfredette * All rights reserved. 61.1Sfredette * 71.3Srin * This code is derived from software contributed to Berkeley by 81.3Srin * the Systems Programming Group of the University of Utah Computer 91.3Srin * Science Department. 101.1Sfredette * 111.1Sfredette * Redistribution and use in source and binary forms, with or without 121.1Sfredette * modification, are permitted provided that the following conditions 131.1Sfredette * are met: 141.1Sfredette * 1. Redistributions of source code must retain the above copyright 151.1Sfredette * notice, this list of conditions and the following disclaimer. 161.1Sfredette * 2. Redistributions in binary form must reproduce the above copyright 171.1Sfredette * notice, this list of conditions and the following disclaimer in the 181.1Sfredette * documentation and/or other materials provided with the distribution. 191.3Srin * 3. Neither the name of the University nor the names of its contributors 201.3Srin * may be used to endorse or promote products derived from this software 211.3Srin * without specific prior written permission. 221.1Sfredette * 231.3Srin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.3Srin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.3Srin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.3Srin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.3Srin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.3Srin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.3Srin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.3Srin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.3Srin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.3Srin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.3Srin * SUCH DAMAGE. 341.1Sfredette */ 351.1Sfredette 361.1Sfredette#include <machine/asm.h> 371.1Sfredette 381.1Sfredette#if defined(LIBC_SCCS) && !defined(lint) 391.3Srin#if 0 401.3Srin RCSID("from: @(#)modsi3.s 5.1 (Berkeley) 6/7/90") 411.3Srin#else 421.4Srin RCSID("$NetBSD: modsi3.S,v 1.4 2020/04/23 03:12:49 rin Exp $") 431.3Srin#endif 441.1Sfredette#endif /* LIBC_SCCS and not lint */ 451.1Sfredette 461.3Srin/* int % int */ 471.3Srin#ifndef __mc68010__ 481.4Srin/* XXX sun3 need this for bootloader */ 491.3SrinENTRY(__modsi3) 501.3Srin movel 4(%sp),%d1 511.3Srin#ifdef __mcoldfire__ 521.3Srin remsl 8(%sp),%d0:%d1 531.3Srin divsl 8(%sp),%d1 541.3Srin#else 551.3Srin divsll 8(%sp),%d0:%d1 561.3Srin#endif 571.3Srin rts 581.3SrinEND(__modsi3) 591.3Srin#else 601.1SfredetteENTRY(__modsi3) 611.1Sfredette| NB: this requires that __udivsi3 preserve %a0 and return 621.1Sfredette| the modulus in %d1: 631.3Srin movel (%sp)+, %a0 | pop return address 641.3Srin movel 4(%sp), %d1 | load the divisor 651.1Sfredette bpl 1f 661.3Srin negl 4(%sp) | store abs(divisor) 671.3Srin1: movel (%sp), %d0 | load the dividend 681.3Srin pea (.Lret,%pc) | push our return address 691.1Sfredette bpl 2f 701.3Srin negl 4(%sp) | store abs(dividend) 711.3Srin subql #2, (%sp) | adjust return address 721.1Sfredette2: jmp _C_LABEL(__udivsi3) 731.1Sfredette negl %d1 | negate modulus 741.3Srin.Lret: movl %d1, %d0 | move modulus into %d0 751.3Srin jmp (%a0) 761.3SrinEND(__modsi3) 771.3Srin#endif /* __mc68010__ */ 78