1245548Sandrew/* 2245548Sandrew * Copyright (C) 2012 Andrew Turner 3245548Sandrew * All rights reserved. 4245548Sandrew * 5245548Sandrew * Redistribution and use in source and binary forms, with or without 6245548Sandrew * modification, are permitted provided that the following conditions 7245548Sandrew * are met: 8245548Sandrew * 1. Redistributions of source code must retain the above copyright 9245548Sandrew * notice, this list of conditions and the following disclaimer. 10245548Sandrew * 2. Redistributions in binary form must reproduce the above copyright 11245548Sandrew * notice, this list of conditions and the following disclaimer in the 12245548Sandrew * documentation and/or other materials provided with the distribution. 13245548Sandrew * 14245548Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15245548Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16245548Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17245548Sandrew * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18245548Sandrew * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19245548Sandrew * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20245548Sandrew * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21245548Sandrew * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22245548Sandrew * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23245548Sandrew * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24245548Sandrew * SUCH DAMAGE. 25245548Sandrew * 26245548Sandrew */ 27245548Sandrew 28245548Sandrew#include <machine/asm.h> 29245548Sandrew__FBSDID("$FreeBSD$"); 30245548Sandrew 31245548Sandrew#ifdef __ARM_EABI__ 32245548Sandrew 33245548Sandrew/* 34245548Sandrew * These calculate: 35245548Sandrew * q = n / m 36245548Sandrew * With a remainer r. 37245548Sandrew * 38245548Sandrew * They take n in {r0, r1} and m in {r2, r3} then pass them into the 39245548Sandrew * helper function. The hepler functions return q in {r0, r1} as 40245548Sandrew * required by the API spec however r is returned on the stack. The 41245548Sandrew * ABI required us to return r in {r2, r3}. 42245548Sandrew * 43245548Sandrew * We need to allocate 8 bytes on the stack to store r, the link 44245548Sandrew * register, and a pointer to the space where the helper function 45245548Sandrew * will write r to. After returning from the helper fuinction we load 46245548Sandrew * the old link register and r from the stack and return. 47245548Sandrew */ 48245548SandrewENTRY_NP(__aeabi_ldivmod) 49245548Sandrew sub sp, sp, #8 /* Space for the remainder */ 50245548Sandrew stmfd sp!, {sp, lr} /* Save a pointer to the above space and lr */ 51245548Sandrew bl PIC_SYM(_C_LABEL(__kern_ldivmod), PLT) 52245548Sandrew ldr lr, [sp, #4] /* Restore lr */ 53245548Sandrew add sp, sp, #8 /* Move sp to the remainder value */ 54245548Sandrew ldmfd sp!, {r2, r3} /* Load the remainder */ 55245548Sandrew RET 56248367SandrewEND(__aeabi_ldivmod) 57245548Sandrew 58245548SandrewENTRY_NP(__aeabi_uldivmod) 59245548Sandrew sub sp, sp, #8 /* Space for the remainder */ 60245548Sandrew stmfd sp!, {sp, lr} /* Save a pointer to the above space and lr */ 61245548Sandrew bl PIC_SYM(_C_LABEL(__qdivrem), PLT) 62245548Sandrew ldr lr, [sp, #4] /* Restore lr */ 63245548Sandrew add sp, sp, #8 /* Move sp to the remainder value */ 64245548Sandrew ldmfd sp!, {r2, r3} /* Load the remainder */ 65245548Sandrew RET 66248367SandrewEND(__aeabi_uldivmod) 67245548Sandrew 68245548Sandrew#endif 69245548Sandrew 70