Subversion Repositories freemyipod

Rev

Rev 424 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 424 Rev 429
Line 1... Line 1...
1
/***************************************************************************
1
/***************************************************************************
2
 *             __________               __   ___.
2
 *             __________               __   ___.
3
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
3
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
4
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
5
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
6
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7
 *                     \/            \/     \/    \/            \/
7
 *                     \/            \/     \/    \/            \/
8
 * $Id$
8
 * $Id$
9
 *
9
 *
10
 * Copyright (C) 2006 Free Software Foundation, Inc.
10
 * Copyright (C) 2006 Free Software Foundation, Inc.
11
 * This file was originally part of the GNU C Library
11
 * This file was originally part of the GNU C Library
12
 * Contributed to glibc by MontaVista Software, Inc. (written by Nicolas Pitre)
12
 * Contributed to glibc by MontaVista Software, Inc. (written by Nicolas Pitre)
13
 * Adapted for Rockbox by Daniel Ankers
13
 * Adapted for Rockbox by Daniel Ankers
14
 *
14
 *
15
 * This program is free software; you can redistribute it and/or
15
 * This program is free software; you can redistribute it and/or
16
 * modify it under the terms of the GNU General Public License
16
 * modify it under the terms of the GNU General Public License
17
 * as published by the Free Software Foundation; either version 2
17
 * as published by the Free Software Foundation; either version 2
18
 * of the License, or (at your option) any later version.
18
 * of the License, or (at your option) any later version.
19
 *
19
 *
20
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
 * KIND, either express or implied.
21
 * KIND, either express or implied.
22
 *
22
 *
23
 ****************************************************************************/
23
 ****************************************************************************/
24
 
24
 
25
#define ASM_FILE
25
#define ASM_FILE
26
#include "global.h"
26
#include "global.h"
27
 
27
 
28
/* ARMv4T doesn't switch the T bit when popping pc directly, we must use BX */
28
/* ARMv4T doesn't switch the T bit when popping pc directly, we must use BX */
29
.macro ldmpc cond="", order="ia", regs
29
.macro ldmpc cond="", order="ia", regs
30
#if ARM_ARCH == 4 && defined(USE_THUMB)
30
#if ARM_ARCH == 4 && defined(USE_THUMB)
31
    ldm\cond\order sp!, { \regs, lr }
31
    ldm\cond\order sp!, { \regs, lr }
32
    bx\cond lr
32
    bx\cond lr
33
#else
33
#else
34
    ldm\cond\order sp!, { \regs, pc }
34
    ldm\cond\order sp!, { \regs, pc }
35
#endif
35
#endif
36
.endm
36
.endm
37
.macro ldrpc cond=""
37
.macro ldrpc cond=""
38
#if ARM_ARCH == 4 && defined(USE_THUMB)
38
#if ARM_ARCH == 4 && defined(USE_THUMB)
39
    ldr\cond lr, [sp], #4
39
    ldr\cond lr, [sp], #4
40
    bx\cond  lr
40
    bx\cond  lr
41
#else
41
#else
42
    ldr\cond pc, [sp], #4
42
    ldr\cond pc, [sp], #4
43
#endif
43
#endif
44
.endm
44
.endm
45
 
45
 
46
/*
46
/*
47
 * Endian independent macros for shifting bytes within registers.
47
 * Endian independent macros for shifting bytes within registers.
48
 */
48
 */
49
#ifndef __ARMEB__
49
#ifndef __ARMEB__
50
#define pull            lsr
50
#define pull            lsr
51
#define push            lsl
51
#define push            lsl
52
#else
52
#else
53
#define pull            lsl
53
#define pull            lsl
54
#define push            lsr
54
#define push            lsr
55
#endif
55
#endif
56
 
56
 
57
        .text
57
        .text
58
 
58
 
59
/*
59
/*
60
 * Prototype: void *memmove(void *dest, const void *src, size_t n);
60
 * Prototype: void *memmove(void *dest, const void *src, size_t n);
61
 *
61
 *
62
 * Note:
62
 * Note:
63
 *
63
 *
64
 * If the memory regions don't overlap, we simply branch to memcpy which is
64
 * If the memory regions don't overlap, we simply branch to memcpy which is
65
 * normally a bit faster. Otherwise the copy is done going downwards.
65
 * normally a bit faster. Otherwise the copy is done going downwards.
66
 */
66
 */
67
 
67
 
68
    .section    .icode,"ax",%progbits
68
    .section    .icode,"ax",%progbits
69
 
69
 
70
    .align      2
70
    .align      2
71
    .global     memmove
71
    .global     memmove
72
    .type       memmove,%function
72
    .type       memmove,%function
73
 
73
 
74
memmove:
74
memmove:
75
 
75
 
76
        subs    ip, r0, r1
76
        subs    ip, r0, r1
77
        cmphi   r2, ip
77
        cmphi   r2, ip
78
        bls memcpy
78
        bls memcpy
79
 
79
 
80
        stmfd   sp!, {r0, r4, lr}
80
        stmfd   sp!, {r0, r4, lr}
81
        add r1, r1, r2
81
        add r1, r1, r2
82
        add r0, r0, r2
82
        add r0, r0, r2
83
        subs    r2, r2, #4
83
        subs    r2, r2, #4
84
        blt 8f
84
        blt 8f
85
        ands    ip, r0, #3
85
        ands    ip, r0, #3
86
        bne 9f
86
        bne 9f
87
        ands    ip, r1, #3
87
        ands    ip, r1, #3
88
        bne 10f
88
        bne 10f
89
 
89
 
90
1:      subs    r2, r2, #(28)
90
1:      subs    r2, r2, #(28)
91
        stmfd   sp!, {r5 - r8}
91
        stmfd   sp!, {r5 - r8}
92
        blt 5f
92
        blt 5f
93
 
93
 
94
2:
94
2:
95
3:
95
3:
96
4:      ldmdb   r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
96
4:      ldmdb   r1!, {r3, r4, r5, r6, r7, r8, ip, lr}
97
        subs    r2, r2, #32
97
        subs    r2, r2, #32
98
        stmdb   r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
98
        stmdb   r0!, {r3, r4, r5, r6, r7, r8, ip, lr}
99
        bge 3b
99
        bge 3b
100
 
100
 
101
5:      ands    ip, r2, #28
101
5:      ands    ip, r2, #28
102
        rsb ip, ip, #32
102
        rsb ip, ip, #32
103
        addne   pc, pc, ip      @ C is always clear here
103
        addne   pc, pc, ip      @ C is always clear here
104
        b   7f
104
        b   7f
105
6:      nop
105
6:      nop
106
        ldr r3, [r1, #-4]!
106
        ldr r3, [r1, #-4]!
107
        ldr r4, [r1, #-4]!
107
        ldr r4, [r1, #-4]!
108
        ldr r5, [r1, #-4]!
108
        ldr r5, [r1, #-4]!
109
        ldr r6, [r1, #-4]!
109
        ldr r6, [r1, #-4]!
110
        ldr r7, [r1, #-4]!
110
        ldr r7, [r1, #-4]!
111
        ldr r8, [r1, #-4]!
111
        ldr r8, [r1, #-4]!
112
        ldr lr, [r1, #-4]!
112
        ldr lr, [r1, #-4]!
113
 
113
 
114
        add pc, pc, ip
114
        add pc, pc, ip
115
        nop
115
        nop
116
        nop
116
        nop
117
        str r3, [r0, #-4]!
117
        str r3, [r0, #-4]!
118
        str r4, [r0, #-4]!
118
        str r4, [r0, #-4]!
119
        str r5, [r0, #-4]!
119
        str r5, [r0, #-4]!
120
        str r6, [r0, #-4]!
120
        str r6, [r0, #-4]!
121
        str r7, [r0, #-4]!
121
        str r7, [r0, #-4]!
122
        str r8, [r0, #-4]!
122
        str r8, [r0, #-4]!
123
        str lr, [r0, #-4]!
123
        str lr, [r0, #-4]!
124
 
124
 
125
7:      ldmfd   sp!, {r5 - r8}
125
7:      ldmfd   sp!, {r5 - r8}
126
 
126
 
127
8:      movs    r2, r2, lsl #31
127
8:      movs    r2, r2, lsl #31
128
        ldrneb  r3, [r1, #-1]!
128
        ldrneb  r3, [r1, #-1]!
129
        ldrcsb  r4, [r1, #-1]!
129
        ldrcsb  r4, [r1, #-1]!
130
        ldrcsb  ip, [r1, #-1]
130
        ldrcsb  ip, [r1, #-1]
131
        strneb  r3, [r0, #-1]!
131
        strneb  r3, [r0, #-1]!
132
        strcsb  r4, [r0, #-1]!
132
        strcsb  r4, [r0, #-1]!
133
        strcsb  ip, [r0, #-1]
133
        strcsb  ip, [r0, #-1]
134
        ldmpc   regs="r0, r4"
134
        ldmpc   regs="r0, r4"
135
 
135
 
136
9:      cmp ip, #2
136
9:      cmp ip, #2
137
        ldrgtb  r3, [r1, #-1]!
137
        ldrgtb  r3, [r1, #-1]!
138
        ldrgeb  r4, [r1, #-1]!
138
        ldrgeb  r4, [r1, #-1]!
139
        ldrb    lr, [r1, #-1]!
139
        ldrb    lr, [r1, #-1]!
140
        strgtb  r3, [r0, #-1]!
140
        strgtb  r3, [r0, #-1]!
141
        strgeb  r4, [r0, #-1]!
141
        strgeb  r4, [r0, #-1]!
142
        subs    r2, r2, ip
142
        subs    r2, r2, ip
143
        strb    lr, [r0, #-1]!
143
        strb    lr, [r0, #-1]!
144
        blt 8b
144
        blt 8b
145
        ands    ip, r1, #3
145
        ands    ip, r1, #3
146
        beq 1b
146
        beq 1b
147
 
147
 
148
10:     bic r1, r1, #3
148
10:     bic r1, r1, #3
149
        cmp ip, #2
149
        cmp ip, #2
150
        ldr r3, [r1, #0]
150
        ldr r3, [r1, #0]
151
        beq 17f
151
        beq 17f
152
        blt 18f
152
        blt 18f
153
 
153
 
154
 
154
 
155
        .macro  backward_copy_shift push pull
155
        .macro  backward_copy_shift push pull
156
 
156
 
157
        subs    r2, r2, #28
157
        subs    r2, r2, #28
158
        blt 14f
158
        blt 14f
159
 
159
 
160
11:     stmfd   sp!, {r5 - r9}
160
11:     stmfd   sp!, {r5 - r9}
161
 
161
 
162
12:
162
12:
163
13:     ldmdb   r1!, {r7, r8, r9, ip}
163
13:     ldmdb   r1!, {r7, r8, r9, ip}
164
        mov     lr, r3, push #\push
164
        mov     lr, r3, push #\push
165
        subs    r2, r2, #32
165
        subs    r2, r2, #32
166
        ldmdb   r1!, {r3, r4, r5, r6}
166
        ldmdb   r1!, {r3, r4, r5, r6}
167
        orr     lr, lr, ip, pull #\pull
167
        orr     lr, lr, ip, pull #\pull
168
        mov     ip, ip, push #\push
168
        mov     ip, ip, push #\push
169
        orr     ip, ip, r9, pull #\pull
169
        orr     ip, ip, r9, pull #\pull
170
        mov     r9, r9, push #\push
170
        mov     r9, r9, push #\push
171
        orr     r9, r9, r8, pull #\pull
171
        orr     r9, r9, r8, pull #\pull
172
        mov     r8, r8, push #\push
172
        mov     r8, r8, push #\push
173
        orr     r8, r8, r7, pull #\pull
173
        orr     r8, r8, r7, pull #\pull
174
        mov     r7, r7, push #\push
174
        mov     r7, r7, push #\push
175
        orr     r7, r7, r6, pull #\pull
175
        orr     r7, r7, r6, pull #\pull
176
        mov     r6, r6, push #\push
176
        mov     r6, r6, push #\push
177
        orr     r6, r6, r5, pull #\pull
177
        orr     r6, r6, r5, pull #\pull
178
        mov     r5, r5, push #\push
178
        mov     r5, r5, push #\push
179
        orr     r5, r5, r4, pull #\pull
179
        orr     r5, r5, r4, pull #\pull
180
        mov     r4, r4, push #\push
180
        mov     r4, r4, push #\push
181
        orr     r4, r4, r3, pull #\pull
181
        orr     r4, r4, r3, pull #\pull
182
        stmdb   r0!, {r4 - r9, ip, lr}
182
        stmdb   r0!, {r4 - r9, ip, lr}
183
        bge 12b
183
        bge 12b
184
 
184
 
185
        ldmfd   sp!, {r5 - r9}
185
        ldmfd   sp!, {r5 - r9}
186
 
186
 
187
14:     ands    ip, r2, #28
187
14:     ands    ip, r2, #28
188
        beq 16f
188
        beq 16f
189
 
189
 
190
15:     mov     lr, r3, push #\push
190
15:     mov     lr, r3, push #\push
191
        ldr r3, [r1, #-4]!
191
        ldr r3, [r1, #-4]!
192
        subs    ip, ip, #4
192
        subs    ip, ip, #4
193
        orr lr, lr, r3, pull #\pull
193
        orr lr, lr, r3, pull #\pull
194
        str lr, [r0, #-4]!
194
        str lr, [r0, #-4]!
195
        bgt 15b
195
        bgt 15b
196
 
196
 
197
16:     add r1, r1, #(\pull / 8)
197
16:     add r1, r1, #(\pull / 8)
198
        b   8b
198
        b   8b
199
 
199
 
200
        .endm
200
        .endm
201
 
201
 
202
 
202
 
203
        backward_copy_shift push=8  pull=24
203
        backward_copy_shift push=8  pull=24
204
 
204
 
205
17:     backward_copy_shift push=16 pull=16
205
17:     backward_copy_shift push=16 pull=16
206
 
206
 
207
18:     backward_copy_shift push=24 pull=8
207
18:     backward_copy_shift push=24 pull=8
208
 
208
 
209
 
209