/*1* Copyright (C) 2012 Andrew Turner2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25*/2627#include <machine/asm.h>28/*29* These calculate:30* q = n / m31* With a remainer r.32*33* They take n in {r0, r1} and m in {r2, r3} then pass them into the34* helper function. The hepler functions return q in {r0, r1} as35* required by the API spec however r is returned on the stack. The36* ABI required us to return r in {r2, r3}.37*38* We need to allocate 8 bytes on the stack to store r, the link39* register, and a pointer to the space where the helper function40* will write r to. After returning from the helper fuinction we load41* the old link register and r from the stack and return.42*/43ENTRY_NP(__aeabi_ldivmod)44sub sp, sp, #8 /* Space for the remainder */45stmfd sp!, {sp, lr} /* Save a pointer to the above space and lr */46bl PIC_SYM(_C_LABEL(__kern_ldivmod), PLT)47ldr lr, [sp, #4] /* Restore lr */48add sp, sp, #8 /* Move sp to the remainder value */49ldmfd sp!, {r2, r3} /* Load the remainder */50RET51END(__aeabi_ldivmod)5253ENTRY_NP(__aeabi_uldivmod)54sub sp, sp, #8 /* Space for the remainder */55stmfd sp!, {sp, lr} /* Save a pointer to the above space and lr */56bl PIC_SYM(_C_LABEL(__qdivrem), PLT)57ldr lr, [sp, #4] /* Restore lr */58add sp, sp, #8 /* Move sp to the remainder value */59ldmfd sp!, {r2, r3} /* Load the remainder */60RET61END(__aeabi_uldivmod)626364