146d741dcSAndrew Turner/* 246d741dcSAndrew Turner * Copyright (C) 2012 Andrew Turner 346d741dcSAndrew Turner * All rights reserved. 446d741dcSAndrew Turner * 546d741dcSAndrew Turner * Redistribution and use in source and binary forms, with or without 646d741dcSAndrew Turner * modification, are permitted provided that the following conditions 746d741dcSAndrew Turner * are met: 846d741dcSAndrew Turner * 1. Redistributions of source code must retain the above copyright 946d741dcSAndrew Turner * notice, this list of conditions and the following disclaimer. 1046d741dcSAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright 1146d741dcSAndrew Turner * notice, this list of conditions and the following disclaimer in the 1246d741dcSAndrew Turner * documentation and/or other materials provided with the distribution. 1346d741dcSAndrew Turner * 1446d741dcSAndrew Turner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1546d741dcSAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1646d741dcSAndrew Turner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1746d741dcSAndrew Turner * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1846d741dcSAndrew Turner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1946d741dcSAndrew Turner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2046d741dcSAndrew Turner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2146d741dcSAndrew Turner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2246d741dcSAndrew Turner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2346d741dcSAndrew Turner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2446d741dcSAndrew Turner * SUCH DAMAGE. 2546d741dcSAndrew Turner * 2646d741dcSAndrew Turner */ 2746d741dcSAndrew Turner 2846d741dcSAndrew Turner#include <machine/asm.h> 2946d741dcSAndrew Turner/* 3046d741dcSAndrew Turner * These calculate: 3146d741dcSAndrew Turner * q = n / m 3246d741dcSAndrew Turner * With a remainer r. 3346d741dcSAndrew Turner * 3446d741dcSAndrew Turner * They take n in {r0, r1} and m in {r2, r3} then pass them into the 3546d741dcSAndrew Turner * helper function. The hepler functions return q in {r0, r1} as 3646d741dcSAndrew Turner * required by the API spec however r is returned on the stack. The 3746d741dcSAndrew Turner * ABI required us to return r in {r2, r3}. 3846d741dcSAndrew Turner * 3946d741dcSAndrew Turner * We need to allocate 8 bytes on the stack to store r, the link 4046d741dcSAndrew Turner * register, and a pointer to the space where the helper function 4146d741dcSAndrew Turner * will write r to. After returning from the helper fuinction we load 4246d741dcSAndrew Turner * the old link register and r from the stack and return. 4346d741dcSAndrew Turner */ 4446d741dcSAndrew TurnerENTRY_NP(__aeabi_ldivmod) 4546d741dcSAndrew Turner sub sp, sp, #8 /* Space for the remainder */ 4646d741dcSAndrew Turner stmfd sp!, {sp, lr} /* Save a pointer to the above space and lr */ 4746d741dcSAndrew Turner bl PIC_SYM(_C_LABEL(__kern_ldivmod), PLT) 4846d741dcSAndrew Turner ldr lr, [sp, #4] /* Restore lr */ 4946d741dcSAndrew Turner add sp, sp, #8 /* Move sp to the remainder value */ 5046d741dcSAndrew Turner ldmfd sp!, {r2, r3} /* Load the remainder */ 5146d741dcSAndrew Turner RET 52*a2dee2adSAndrew TurnerEND(__aeabi_ldivmod) 5346d741dcSAndrew Turner 5446d741dcSAndrew TurnerENTRY_NP(__aeabi_uldivmod) 5546d741dcSAndrew Turner sub sp, sp, #8 /* Space for the remainder */ 5646d741dcSAndrew Turner stmfd sp!, {sp, lr} /* Save a pointer to the above space and lr */ 5746d741dcSAndrew Turner bl PIC_SYM(_C_LABEL(__qdivrem), PLT) 5846d741dcSAndrew Turner ldr lr, [sp, #4] /* Restore lr */ 5946d741dcSAndrew Turner add sp, sp, #8 /* Move sp to the remainder value */ 6046d741dcSAndrew Turner ldmfd sp!, {r2, r3} /* Load the remainder */ 6146d741dcSAndrew Turner RET 62*a2dee2adSAndrew TurnerEND(__aeabi_uldivmod) 63