Division functionality for cores that dont have divide hardware.
authorUsama Arif <usama.arif@arm.com>
Wed, 12 Dec 2018 17:08:33 +0000 (17:08 +0000)
committerUsama Arif <usama.arif@arm.com>
Tue, 19 Feb 2019 17:07:48 +0000 (17:07 +0000)
Cortex a5 doesnt support hardware division such as sdiv and udiv commands.
This commit adds a software division function in assembly as well as include
appropriate files for software divison.

The software division algorithm is a modified version obtained from:
http://www.keil.com/support/man/docs/armasm/armasm_dom1359731155623.htm

Change-Id: Ib405a330da5f1cea1e68e07e7b520edeef9e2652
Signed-off-by: Usama Arif <usama.arif@arm.com>
drivers/arm/pl011/aarch32/pl011_console.S
include/arch/aarch32/asm_macros.S

index ae613b1345bc3da2da79f970f4a1f56cab4a7633..e9f95f2899f5981350f4f7209216e3cba1ae9978 100644 (file)
@@ -63,7 +63,14 @@ func console_pl011_core_init
        /* Program the baudrate */
        /* Divisor =  (Uart clock * 4) / baudrate */
        lsl     r1, r1, #2
+#if (ARM_ARCH_MAJOR == 7) && !defined(ARMV7_SUPPORTS_VIRTUALIZATION)
+       push    {r0,r3}
+       softudiv        r0,r1,r2,r3
+       mov     r1, r0
+       pop     {r0,r3}
+#else
        udiv    r2, r1, r2
+#endif
        /* IBRD = Divisor >> 6 */
        lsr     r1, r2, #6
        /* Write the IBRD */
index 8408804fbd91df7622a8cf43ee2b6c8f824aae6b..8cfa21231a9fffb0de5b1a43e0ab126b8e06b9dd 100644 (file)
@@ -78,7 +78,7 @@
         * Clobber: r14, r1, r2
         */
        .macro get_my_mp_stack _name, _size
-       bl  plat_my_core_pos
+       bl      plat_my_core_pos
        ldr r2, =(\_name + \_size)
        mov r1, #\_size
        mla r0, r0, r1, r2
                .endif
        .endm
 
+       /*
+        * Helper macro for carrying out division in software when
+        * hardware division is not suported. \top holds the dividend
+        * in the function call and the remainder after
+        * the function is executed. \bot holds the divisor. \div holds
+        * the quotient and \temp is a temporary registed used in calcualtion.
+        * The division algorithm has been obtained from:
+        * http://www.keil.com/support/man/docs/armasm/armasm_dom1359731155623.htm
+        */
+       .macro  softudiv        div:req,top:req,bot:req,temp:req
+
+       mov     \temp, \bot
+       cmp     \temp, \top, lsr #1
+div1:
+       movls   \temp, \temp, lsl #1
+       cmp     \temp, \top, lsr #1
+       bls     div1
+       mov     \div, #0
+
+div2:
+       cmp     \top, \temp
+       subcs   \top, \top,\temp
+       ADC     \div, \div, \div
+       mov     \temp, \temp, lsr #1
+       cmp     \temp, \bot
+       bhs     div2
+       .endm
 #endif /* ASM_MACROS_S */