Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / arch / arm / lib / memset_rpi.S
1 /*
2 Copyright (c) 2013, Raspberry Pi Foundation
3 Copyright (c) 2013, RISC OS Open Ltd
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8     * Redistributions of source code must retain the above copyright
9       notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright
11       notice, this list of conditions and the following disclaimer in the
12       documentation and/or other materials provided with the distribution.
13     * Neither the name of the copyright holder nor the
14       names of its contributors may be used to endorse or promote products
15       derived from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <linux/linkage.h>
30 #include "arm-mem.h"
31
32 /* Prevent the stack from becoming executable */
33 #if defined(__linux__) && defined(__ELF__)
34 .section .note.GNU-stack,"",%progbits
35 #endif
36
37     .text
38     .arch armv6
39     .object_arch armv4
40     .arm
41     .altmacro
42     .p2align 2
43
44 /*
45  *  void *memset(void *s, int c, size_t n);
46  *  On entry:
47  *  a1 = pointer to buffer to fill
48  *  a2 = byte pattern to fill with (caller-narrowed)
49  *  a3 = number of bytes to fill
50  *  On exit:
51  *  a1 preserved
52  */
53 ENTRY(mmioset)
54 ENTRY(memset)
55 ENTRY(__memset)
56
57         S       .req    a1
58         DAT0    .req    a2
59         N       .req    a3
60         DAT1    .req    a4
61         DAT2    .req    ip
62         DAT3    .req    lr
63
64         orr     DAT0, DAT0, DAT0, lsl #8
65         orr     DAT0, DAT0, DAT0, lsl #16
66
67 ENTRY(__memset32)
68         mov     DAT1, DAT0
69
70 ENTRY(__memset64)
71         push    {S, lr}
72
73         /* See if we're guaranteed to have at least one 16-byte aligned 16-byte write */
74         cmp     N, #31
75         blo     170f
76
77 161:    sub     N, N, #16     /* simplifies inner loop termination */
78         /* Leading words and bytes */
79         tst     S, #15
80         beq     164f
81         rsb     DAT3, S, #0   /* bits 0-3 = number of leading bytes until aligned */
82         movs    DAT2, DAT3, lsl #31
83         submi   N, N, #1
84         strmib  DAT0, [S], #1
85         subcs   N, N, #2
86         strcsh  DAT0, [S], #2
87         movs    DAT2, DAT3, lsl #29
88         submi   N, N, #4
89         strmi   DAT0, [S], #4
90         subcs   N, N, #8
91         stmcsia S!, {DAT0, DAT1}
92 164:    /* Delayed set up of DAT2 and DAT3 so we could use them as scratch registers above */
93         mov     DAT2, DAT0
94         mov     DAT3, DAT1
95         /* Now the inner loop of 16-byte stores */
96 165:    stmia   S!, {DAT0, DAT1, DAT2, DAT3}
97         subs    N, N, #16
98         bhs     165b
99 166:    /* Trailing words and bytes */
100         movs    N, N, lsl #29
101         stmcsia S!, {DAT0, DAT1}
102         strmi   DAT0, [S], #4
103         movs    N, N, lsl #2
104         strcsh  DAT0, [S], #2
105         strmib  DAT0, [S]
106 199:    pop     {S, pc}
107
108 170:    /* Short case */
109         mov     DAT2, DAT0
110         mov     DAT3, DAT1
111         tst     S, #3
112         beq     174f
113 172:    subs    N, N, #1
114         blo     199b
115         strb    DAT0, [S], #1
116         tst     S, #3
117         bne     172b
118 174:    tst     N, #16
119         stmneia S!, {DAT0, DAT1, DAT2, DAT3}
120         b       166b
121
122         .unreq  S
123         .unreq  DAT0
124         .unreq  N
125         .unreq  DAT1
126         .unreq  DAT2
127         .unreq  DAT3
128 ENDPROC(__memset64)
129 ENDPROC(__memset32)
130 ENDPROC(__memset)
131 ENDPROC(memset)
132 ENDPROC(mmioset)