1 /* SPDX-License-Identifier: GPL-2.0 */ !! 1 /* 2 /* linux/arch/sparc/lib/memset.S: Sparc optimi !! 2 * This file is subject to the terms and conditions of the GNU General Public 3 * Copyright (C) 1991,1996 Free Software Found !! 3 * License. See the file "COPYING" in the main directory of this archive 4 * Copyright (C) 1996,1997 Jakub Jelinek (jj@s !! 4 * for more details. 5 * Copyright (C) 1996 David S. Miller (davem@c << 6 * 5 * 7 * Calls to memset returns initial %o0. Calls !! 6 * Copyright (C) 1998, 1999, 2000 by Ralf Baechle 8 * number of bytes not yet set if exception oc !! 7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 9 * clear_user. !! 8 * Copyright (C) 2007 Maciej W. Rozycki 10 */ 9 */ >> 10 #include <asm/asm.h> >> 11 #include <asm/asm-offsets.h> >> 12 #include <asm/regdef.h> >> 13 >> 14 #if LONGSIZE == 4 >> 15 #define LONG_S_L swl >> 16 #define LONG_S_R swr >> 17 #else >> 18 #define LONG_S_L sdl >> 19 #define LONG_S_R sdr >> 20 #endif >> 21 >> 22 #define EX(insn,reg,addr,handler) \ >> 23 9: insn reg, addr; \ >> 24 .section __ex_table,"a"; \ >> 25 PTR 9b, handler; \ >> 26 .previous >> 27 >> 28 .macro f_fill64 dst, offset, val, fixup >> 29 EX(LONG_S, \val, (\offset + 0 * LONGSIZE)(\dst), \fixup) >> 30 EX(LONG_S, \val, (\offset + 1 * LONGSIZE)(\dst), \fixup) >> 31 EX(LONG_S, \val, (\offset + 2 * LONGSIZE)(\dst), \fixup) >> 32 EX(LONG_S, \val, (\offset + 3 * LONGSIZE)(\dst), \fixup) >> 33 EX(LONG_S, \val, (\offset + 4 * LONGSIZE)(\dst), \fixup) >> 34 EX(LONG_S, \val, (\offset + 5 * LONGSIZE)(\dst), \fixup) >> 35 EX(LONG_S, \val, (\offset + 6 * LONGSIZE)(\dst), \fixup) >> 36 EX(LONG_S, \val, (\offset + 7 * LONGSIZE)(\dst), \fixup) >> 37 #if LONGSIZE == 4 >> 38 EX(LONG_S, \val, (\offset + 8 * LONGSIZE)(\dst), \fixup) >> 39 EX(LONG_S, \val, (\offset + 9 * LONGSIZE)(\dst), \fixup) >> 40 EX(LONG_S, \val, (\offset + 10 * LONGSIZE)(\dst), \fixup) >> 41 EX(LONG_S, \val, (\offset + 11 * LONGSIZE)(\dst), \fixup) >> 42 EX(LONG_S, \val, (\offset + 12 * LONGSIZE)(\dst), \fixup) >> 43 EX(LONG_S, \val, (\offset + 13 * LONGSIZE)(\dst), \fixup) >> 44 EX(LONG_S, \val, (\offset + 14 * LONGSIZE)(\dst), \fixup) >> 45 EX(LONG_S, \val, (\offset + 15 * LONGSIZE)(\dst), \fixup) >> 46 #endif >> 47 .endm 11 48 12 #include <linux/export.h> !! 49 /* 13 #include <asm/ptrace.h> !! 50 * memset(void *s, int c, size_t n) 14 !! 51 * 15 /* Work around cpp -rob */ !! 52 * a0: start of area to clear 16 #define ALLOC #alloc !! 53 * a1: char to fill with 17 #define EXECINSTR #execinstr !! 54 * a2: size of area to clear 18 #define EX(x,y,a,b) !! 55 */ 19 98: x,y; !! 56 .set noreorder 20 .section .fixup,ALLOC,EXECINSTR; !! 57 .align 5 21 .align 4; !! 58 LEAF(memset) 22 99: retl; !! 59 beqz a1, 1f 23 a, b, %o0; !! 60 move v0, a0 /* result */ 24 .section __ex_table,ALLOC; !! 61 25 .align 4; !! 62 andi a1, 0xff /* spread fillword */ 26 .word 98b, 99b; !! 63 LONG_SLL t1, a1, 8 27 .text; !! 64 or a1, t1 28 .align 4 !! 65 LONG_SLL t1, a1, 16 29 !! 66 #if LONGSIZE == 8 30 #define STORE(source, base, offset, n) !! 67 or a1, t1 31 98: std source, [base + offset + n]; !! 68 LONG_SLL t1, a1, 32 32 .section .fixup,ALLOC,EXECINSTR; !! 69 #endif 33 .align 4; !! 70 or a1, t1 34 99: ba 30f; << 35 sub %o3, n - offset, %o3; << 36 .section __ex_table,ALLOC; << 37 .align 4; << 38 .word 98b, 99b; << 39 .text; << 40 .align 4; << 41 << 42 #define STORE_LAST(source, base, offset, n) << 43 EX(std source, [base - offset - n], << 44 add %o1, offset + n); << 45 << 46 /* Please don't change these macros, unless yo << 47 * in the .fixup section below as well. << 48 * Store 64 bytes at (BASE + OFFSET) using val << 49 #define ZERO_BIG_BLOCK(base, offset, source) << 50 STORE(source, base, offset, 0x00); << 51 STORE(source, base, offset, 0x08); << 52 STORE(source, base, offset, 0x10); << 53 STORE(source, base, offset, 0x18); << 54 STORE(source, base, offset, 0x20); << 55 STORE(source, base, offset, 0x28); << 56 STORE(source, base, offset, 0x30); << 57 STORE(source, base, offset, 0x38); << 58 << 59 #define ZERO_LAST_BLOCKS(base, offset, source) << 60 STORE_LAST(source, base, offset, 0x38) << 61 STORE_LAST(source, base, offset, 0x30) << 62 STORE_LAST(source, base, offset, 0x28) << 63 STORE_LAST(source, base, offset, 0x20) << 64 STORE_LAST(source, base, offset, 0x18) << 65 STORE_LAST(source, base, offset, 0x10) << 66 STORE_LAST(source, base, offset, 0x08) << 67 STORE_LAST(source, base, offset, 0x00) << 68 << 69 .text << 70 .align 4 << 71 << 72 .globl __bzero_begin << 73 __bzero_begin: << 74 << 75 .globl __bzero << 76 .type __bzero,#function << 77 .globl memset << 78 EXPORT_SYMBOL(__bzero) << 79 EXPORT_SYMBOL(memset) << 80 memset: << 81 mov %o0, %g1 << 82 mov 1, %g4 << 83 and %o1, 0xff, %g3 << 84 sll %g3, 8, %g2 << 85 or %g3, %g2, %g3 << 86 sll %g3, 16, %g2 << 87 or %g3, %g2, %g3 << 88 b 1f << 89 mov %o2, %o1 << 90 3: << 91 cmp %o2, 3 << 92 be 2f << 93 EX(stb %g3, [%o0], sub %o1, 0) << 94 << 95 cmp %o2, 2 << 96 be 2f << 97 EX(stb %g3, [%o0 + 0x01], sub %o1, 1) << 98 << 99 EX(stb %g3, [%o0 + 0x02], sub %o1, 2) << 100 2: << 101 sub %o2, 4, %o2 << 102 add %o1, %o2, %o1 << 103 b 4f << 104 sub %o0, %o2, %o0 << 105 << 106 __bzero: << 107 clr %g4 << 108 mov %g0, %g3 << 109 1: 71 1: 110 cmp %o1, 7 << 111 bleu 7f << 112 andcc %o0, 3, %o2 << 113 << 114 bne 3b << 115 4: << 116 andcc %o0, 4, %g0 << 117 << 118 be 2f << 119 mov %g3, %g2 << 120 << 121 EX(st %g3, [%o0], sub %o1, 0) << 122 sub %o1, 4, %o1 << 123 add %o0, 4, %o0 << 124 2: << 125 andcc %o1, 0xffffff80, %o3 ! Now << 126 be 9f << 127 andcc %o1, 0x78, %o2 << 128 10: << 129 ZERO_BIG_BLOCK(%o0, 0x00, %g2) << 130 subcc %o3, 128, %o3 << 131 ZERO_BIG_BLOCK(%o0, 0x40, %g2) << 132 bne 10b << 133 add %o0, 128, %o0 << 134 << 135 orcc %o2, %g0, %g0 << 136 9: << 137 be 13f << 138 andcc %o1, 7, %o1 << 139 << 140 srl %o2, 1, %o3 << 141 set 13f, %o4 << 142 sub %o4, %o3, %o4 << 143 jmp %o4 << 144 add %o0, %o2, %o0 << 145 << 146 ZERO_LAST_BLOCKS(%o0, 0x48, %g2) << 147 ZERO_LAST_BLOCKS(%o0, 0x08, %g2) << 148 13: << 149 be 8f << 150 andcc %o1, 4, %g0 << 151 72 152 be 1f !! 73 FEXPORT(__bzero) 153 andcc %o1, 2, %g0 !! 74 sltiu t0, a2, LONGSIZE /* very small region? */ >> 75 bnez t0, .Lsmall_memset >> 76 andi t0, a0, LONGMASK /* aligned? */ >> 77 >> 78 #ifndef CONFIG_CPU_DADDI_WORKAROUNDS >> 79 beqz t0, 1f >> 80 PTR_SUBU t0, LONGSIZE /* alignment in bytes */ >> 81 #else >> 82 .set noat >> 83 li AT, LONGSIZE >> 84 beqz t0, 1f >> 85 PTR_SUBU t0, AT /* alignment in bytes */ >> 86 .set at >> 87 #endif >> 88 >> 89 R10KCBARRIER(0(ra)) >> 90 #ifdef __MIPSEB__ >> 91 EX(LONG_S_L, a1, (a0), .Lfirst_fixup) /* make word/dword aligned */ >> 92 #endif >> 93 #ifdef __MIPSEL__ >> 94 EX(LONG_S_R, a1, (a0), .Lfirst_fixup) /* make word/dword aligned */ >> 95 #endif >> 96 PTR_SUBU a0, t0 /* long align ptr */ >> 97 PTR_ADDU a2, t0 /* correct size */ >> 98 >> 99 1: ori t1, a2, 0x3f /* # of full blocks */ >> 100 xori t1, 0x3f >> 101 beqz t1, .Lmemset_partial /* no block to fill */ >> 102 andi t0, a2, 0x40-LONGSIZE >> 103 >> 104 PTR_ADDU t1, a0 /* end address */ >> 105 .set reorder >> 106 1: PTR_ADDIU a0, 64 >> 107 R10KCBARRIER(0(ra)) >> 108 f_fill64 a0, -64, a1, .Lfwd_fixup >> 109 bne t1, a0, 1b >> 110 .set noreorder >> 111 >> 112 .Lmemset_partial: >> 113 R10KCBARRIER(0(ra)) >> 114 PTR_LA t1, 2f /* where to start */ >> 115 #if LONGSIZE == 4 >> 116 PTR_SUBU t1, t0 >> 117 #else >> 118 .set noat >> 119 LONG_SRL AT, t0, 1 >> 120 PTR_SUBU t1, AT >> 121 .set at >> 122 #endif >> 123 jr t1 >> 124 PTR_ADDU a0, t0 /* dest ptr */ >> 125 >> 126 .set push >> 127 .set noreorder >> 128 .set nomacro >> 129 f_fill64 a0, -64, a1, .Lpartial_fixup /* ... but first do longs ... */ >> 130 2: .set pop >> 131 andi a2, LONGMASK /* At most one long to go */ >> 132 >> 133 beqz a2, 1f >> 134 PTR_ADDU a0, a2 /* What's left */ >> 135 R10KCBARRIER(0(ra)) >> 136 #ifdef __MIPSEB__ >> 137 EX(LONG_S_R, a1, -1(a0), .Llast_fixup) >> 138 #endif >> 139 #ifdef __MIPSEL__ >> 140 EX(LONG_S_L, a1, -1(a0), .Llast_fixup) >> 141 #endif >> 142 1: jr ra >> 143 move a2, zero >> 144 >> 145 .Lsmall_memset: >> 146 beqz a2, 2f >> 147 PTR_ADDU t1, a0, a2 >> 148 >> 149 1: PTR_ADDIU a0, 1 /* fill bytewise */ >> 150 R10KCBARRIER(0(ra)) >> 151 bne t1, a0, 1b >> 152 sb a1, -1(a0) >> 153 >> 154 2: jr ra /* done */ >> 155 move a2, zero >> 156 END(memset) 154 157 155 EX(st %g3, [%o0], and %o1, 7) !! 158 .Lfirst_fixup: 156 add %o0, 4, %o0 !! 159 jr ra 157 1: << 158 be 1f << 159 andcc %o1, 1, %g0 << 160 << 161 EX(sth %g3, [%o0], and %o1, 3) << 162 add %o0, 2, %o0 << 163 1: << 164 bne,a 8f << 165 EX(stb %g3, [%o0], and %o1, 1) << 166 8: << 167 b 0f << 168 nop << 169 7: << 170 be 13b << 171 orcc %o1, 0, %g0 << 172 << 173 be 0f << 174 8: << 175 add %o0, 1, %o0 << 176 subcc %o1, 1, %o1 << 177 bne 8b << 178 EX(stb %g3, [%o0 - 1], add %o1, 1) << 179 0: << 180 andcc %g4, 1, %g0 << 181 be 5f << 182 nop 160 nop 183 retl << 184 mov %g1, %o0 << 185 5: << 186 retl << 187 clr %o0 << 188 << 189 .section .fixup,#alloc,#execinstr << 190 .align 4 << 191 30: << 192 and %o1, 0x7f, %o1 << 193 retl << 194 add %o3, %o1, %o0 << 195 161 196 .globl __bzero_end !! 162 .Lfwd_fixup: 197 __bzero_end: !! 163 PTR_L t0, TI_TASK($28) >> 164 LONG_L t0, THREAD_BUADDR(t0) >> 165 andi a2, 0x3f >> 166 LONG_ADDU a2, t1 >> 167 jr ra >> 168 LONG_SUBU a2, t0 >> 169 >> 170 .Lpartial_fixup: >> 171 PTR_L t0, TI_TASK($28) >> 172 LONG_L t0, THREAD_BUADDR(t0) >> 173 andi a2, LONGMASK >> 174 LONG_ADDU a2, t1 >> 175 jr ra >> 176 LONG_SUBU a2, t0 >> 177 >> 178 .Llast_fixup: >> 179 jr ra >> 180 andi v1, a2, LONGMASK
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.