[4c622e5] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief bsp_start_memcpy() implementation. |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /* |
---|
| 8 | * Copyright (c) 2008-2011 embedded brains GmbH. All rights reserved. |
---|
| 9 | * |
---|
| 10 | * embedded brains GmbH |
---|
| 11 | * Obere Lagerstr. 30 |
---|
| 12 | * 82178 Puchheim |
---|
| 13 | * Germany |
---|
| 14 | * <rtems@embedded-brains.de> |
---|
| 15 | * |
---|
| 16 | * The license and distribution terms for this file may be |
---|
| 17 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 18 | * http://www.rtems.org/license/LICENSE. |
---|
[4c622e5] | 19 | */ |
---|
| 20 | |
---|
| 21 | #include <rtems/asm.h> |
---|
| 22 | #include <rtems/system.h> |
---|
| 23 | #include <rtems/score/cpu.h> |
---|
| 24 | |
---|
| 25 | .section ".bsp_start_text", "ax" |
---|
| 26 | |
---|
| 27 | #if defined(ARM_MULTILIB_ARCH_V4) |
---|
| 28 | |
---|
| 29 | DEFINE_FUNCTION_ARM(bsp_start_memcpy) |
---|
| 30 | |
---|
| 31 | /* Return if dest == src */ |
---|
| 32 | cmp r0, r1 |
---|
| 33 | #ifdef __thumb__ |
---|
| 34 | bxeq lr |
---|
| 35 | #else |
---|
| 36 | moveq pc, lr |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /* Return if length is zero */ |
---|
| 40 | mov r3, #0 |
---|
| 41 | cmp r3, r2 |
---|
| 42 | #ifdef __thumb__ |
---|
| 43 | bxeq lr |
---|
| 44 | #else |
---|
| 45 | moveq pc, lr |
---|
| 46 | #endif |
---|
| 47 | |
---|
| 48 | /* Save non-volatile registers */ |
---|
| 49 | push {r4-r8, lr} |
---|
| 50 | |
---|
| 51 | /* Copy worker routine to stack */ |
---|
| 52 | adr ip, worker_begin |
---|
| 53 | ldm ip, {r3-r8} |
---|
| 54 | push {r3-r8} |
---|
| 55 | |
---|
| 56 | /* Execute worker routine */ |
---|
| 57 | mov r3, #0 |
---|
| 58 | mov ip, sp |
---|
| 59 | mov lr, pc |
---|
| 60 | #ifdef __thumb__ |
---|
| 61 | bx ip |
---|
| 62 | #else |
---|
| 63 | mov pc, ip |
---|
| 64 | #endif |
---|
| 65 | |
---|
| 66 | /* Restore stack and non-volatile registers */ |
---|
| 67 | add sp, sp, #24 |
---|
| 68 | pop {r4-r8, lr} |
---|
| 69 | |
---|
| 70 | /* Return */ |
---|
| 71 | #ifdef __thumb__ |
---|
| 72 | bx lr |
---|
| 73 | #else |
---|
| 74 | mov pc, lr |
---|
| 75 | #endif |
---|
| 76 | |
---|
| 77 | worker_begin: |
---|
| 78 | |
---|
| 79 | /* Worker routine */ |
---|
| 80 | ldr ip, [r1, r3] |
---|
| 81 | str ip, [r0, r3] |
---|
| 82 | add r3, r3, #4 |
---|
| 83 | cmp r3, r2 |
---|
| 84 | bcc worker_begin |
---|
| 85 | #ifdef __thumb__ |
---|
| 86 | bx lr |
---|
| 87 | #else |
---|
| 88 | mov pc, lr |
---|
| 89 | #endif |
---|
| 90 | |
---|
| 91 | #elif defined(ARM_MULTILIB_ARCH_V7M) |
---|
| 92 | |
---|
| 93 | .syntax unified |
---|
| 94 | |
---|
| 95 | .align 2 |
---|
| 96 | .globl bsp_start_memcpy |
---|
| 97 | .thumb |
---|
| 98 | .thumb_func |
---|
| 99 | .type bsp_start_memcpy, %function |
---|
| 100 | |
---|
| 101 | bsp_start_memcpy: |
---|
| 102 | |
---|
| 103 | /* Return if dest == src */ |
---|
| 104 | cmp r0, r1 |
---|
| 105 | beq return |
---|
| 106 | |
---|
| 107 | /* Return if length is zero */ |
---|
| 108 | movs r3, #0 |
---|
| 109 | cmp r3, r2 |
---|
| 110 | beq return |
---|
| 111 | |
---|
| 112 | /* Save non-volatile registers */ |
---|
| 113 | push {r4-r7, lr} |
---|
| 114 | |
---|
| 115 | /* Copy worker routine to stack */ |
---|
| 116 | adr r3, worker_begin |
---|
| 117 | ldm r3, {r4-r7} |
---|
| 118 | push {r4-r7} |
---|
| 119 | |
---|
| 120 | /* Execute worker routine */ |
---|
| 121 | add r3, sp, #1 |
---|
| 122 | adds r2, r2, #3 |
---|
| 123 | bic r2, r2, #3 |
---|
| 124 | adds r2, r2, r1 |
---|
| 125 | blx r3 |
---|
| 126 | |
---|
| 127 | /* Restore stack and non-volatile registers */ |
---|
| 128 | add sp, sp, #16 |
---|
| 129 | pop {r4-r7, lr} |
---|
| 130 | |
---|
| 131 | return: |
---|
| 132 | |
---|
| 133 | /* Return */ |
---|
| 134 | bx lr |
---|
| 135 | |
---|
| 136 | .align 2 |
---|
| 137 | |
---|
| 138 | worker_begin: |
---|
| 139 | |
---|
| 140 | /* Worker routine */ |
---|
| 141 | ldr r3, [r1], #4 |
---|
| 142 | cmp r2, r1 |
---|
| 143 | str r3, [r0], #4 |
---|
| 144 | bne worker_begin |
---|
| 145 | bx lr |
---|
| 146 | |
---|
| 147 | #endif /* defined(ARM_MULTILIB_ARCH_V7M) */ |
---|