Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1998, 1999, 2000 by Ralf Baechle |
| 7 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 8 | * Copyright (C) 2007 by Maciej W. Rozycki |
| 9 | * Copyright (C) 2011, 2012 MIPS Technologies, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | #include <asm/asm.h> |
Sam Ravnborg | 048eb58 | 2005-09-09 22:32:31 +0200 | [diff] [blame] | 12 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/regdef.h> |
| 14 | |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 15 | #if LONGSIZE == 4 |
| 16 | #define LONG_S_L swl |
| 17 | #define LONG_S_R swr |
| 18 | #else |
| 19 | #define LONG_S_L sdl |
| 20 | #define LONG_S_R sdr |
| 21 | #endif |
| 22 | |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 23 | #ifdef CONFIG_CPU_MICROMIPS |
| 24 | #define STORSIZE (LONGSIZE * 2) |
| 25 | #define STORMASK (STORSIZE - 1) |
| 26 | #define FILL64RG t8 |
| 27 | #define FILLPTRG t7 |
| 28 | #undef LONG_S |
| 29 | #define LONG_S LONG_SP |
| 30 | #else |
| 31 | #define STORSIZE LONGSIZE |
| 32 | #define STORMASK LONGMASK |
| 33 | #define FILL64RG a1 |
| 34 | #define FILLPTRG t0 |
| 35 | #endif |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define EX(insn,reg,addr,handler) \ |
| 38 | 9: insn reg, addr; \ |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 39 | .section __ex_table,"a"; \ |
| 40 | PTR 9b, handler; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | .previous |
| 42 | |
| 43 | .macro f_fill64 dst, offset, val, fixup |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 44 | EX(LONG_S, \val, (\offset + 0 * STORSIZE)(\dst), \fixup) |
| 45 | EX(LONG_S, \val, (\offset + 1 * STORSIZE)(\dst), \fixup) |
| 46 | EX(LONG_S, \val, (\offset + 2 * STORSIZE)(\dst), \fixup) |
| 47 | EX(LONG_S, \val, (\offset + 3 * STORSIZE)(\dst), \fixup) |
| 48 | #if ((defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4)) || !defined(CONFIG_CPU_MICROMIPS)) |
| 49 | EX(LONG_S, \val, (\offset + 4 * STORSIZE)(\dst), \fixup) |
| 50 | EX(LONG_S, \val, (\offset + 5 * STORSIZE)(\dst), \fixup) |
| 51 | EX(LONG_S, \val, (\offset + 6 * STORSIZE)(\dst), \fixup) |
| 52 | EX(LONG_S, \val, (\offset + 7 * STORSIZE)(\dst), \fixup) |
| 53 | #endif |
| 54 | #if (!defined(CONFIG_CPU_MICROMIPS) && (LONGSIZE == 4)) |
| 55 | EX(LONG_S, \val, (\offset + 8 * STORSIZE)(\dst), \fixup) |
| 56 | EX(LONG_S, \val, (\offset + 9 * STORSIZE)(\dst), \fixup) |
| 57 | EX(LONG_S, \val, (\offset + 10 * STORSIZE)(\dst), \fixup) |
| 58 | EX(LONG_S, \val, (\offset + 11 * STORSIZE)(\dst), \fixup) |
| 59 | EX(LONG_S, \val, (\offset + 12 * STORSIZE)(\dst), \fixup) |
| 60 | EX(LONG_S, \val, (\offset + 13 * STORSIZE)(\dst), \fixup) |
| 61 | EX(LONG_S, \val, (\offset + 14 * STORSIZE)(\dst), \fixup) |
| 62 | EX(LONG_S, \val, (\offset + 15 * STORSIZE)(\dst), \fixup) |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 63 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | .endm |
| 65 | |
| 66 | /* |
| 67 | * memset(void *s, int c, size_t n) |
| 68 | * |
| 69 | * a0: start of area to clear |
| 70 | * a1: char to fill with |
| 71 | * a2: size of area to clear |
| 72 | */ |
| 73 | .set noreorder |
| 74 | .align 5 |
| 75 | LEAF(memset) |
| 76 | beqz a1, 1f |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 77 | move v0, a0 /* result */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | andi a1, 0xff /* spread fillword */ |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 80 | LONG_SLL t1, a1, 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | or a1, t1 |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 82 | LONG_SLL t1, a1, 16 |
| 83 | #if LONGSIZE == 8 |
| 84 | or a1, t1 |
| 85 | LONG_SLL t1, a1, 32 |
| 86 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | or a1, t1 |
| 88 | 1: |
| 89 | |
| 90 | FEXPORT(__bzero) |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 91 | sltiu t0, a2, STORSIZE /* very small region? */ |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 92 | bnez t0, .Lsmall_memset |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 93 | andi t0, a0, STORMASK /* aligned? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 95 | #ifdef CONFIG_CPU_MICROMIPS |
| 96 | move t8, a1 /* used by 'swp' instruction */ |
| 97 | move t9, a1 |
| 98 | #endif |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 99 | #ifndef CONFIG_CPU_DADDI_WORKAROUNDS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | beqz t0, 1f |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 101 | PTR_SUBU t0, STORSIZE /* alignment in bytes */ |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 102 | #else |
| 103 | .set noat |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 104 | li AT, STORSIZE |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 105 | beqz t0, 1f |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 106 | PTR_SUBU t0, AT /* alignment in bytes */ |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 107 | .set at |
| 108 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 110 | R10KCBARRIER(0(ra)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #ifdef __MIPSEB__ |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 112 | EX(LONG_S_L, a1, (a0), .Lfirst_fixup) /* make word/dword aligned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #endif |
| 114 | #ifdef __MIPSEL__ |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 115 | EX(LONG_S_R, a1, (a0), .Lfirst_fixup) /* make word/dword aligned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #endif |
| 117 | PTR_SUBU a0, t0 /* long align ptr */ |
| 118 | PTR_ADDU a2, t0 /* correct size */ |
| 119 | |
| 120 | 1: ori t1, a2, 0x3f /* # of full blocks */ |
| 121 | xori t1, 0x3f |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 122 | beqz t1, .Lmemset_partial /* no block to fill */ |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 123 | andi t0, a2, 0x40-STORSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | PTR_ADDU t1, a0 /* end address */ |
| 126 | .set reorder |
| 127 | 1: PTR_ADDIU a0, 64 |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 128 | R10KCBARRIER(0(ra)) |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 129 | f_fill64 a0, -64, FILL64RG, .Lfwd_fixup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | bne t1, a0, 1b |
| 131 | .set noreorder |
| 132 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 133 | .Lmemset_partial: |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 134 | R10KCBARRIER(0(ra)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | PTR_LA t1, 2f /* where to start */ |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 136 | #ifdef CONFIG_CPU_MICROMIPS |
| 137 | LONG_SRL t7, t0, 1 |
| 138 | #endif |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 139 | #if LONGSIZE == 4 |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 140 | PTR_SUBU t1, FILLPTRG |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 141 | #else |
| 142 | .set noat |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 143 | LONG_SRL AT, FILLPTRG, 1 |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 144 | PTR_SUBU t1, AT |
Maciej W. Rozycki | 619b6e1 | 2007-10-23 12:43:25 +0100 | [diff] [blame] | 145 | .set at |
Atsushi Nemoto | a583158 | 2006-12-18 00:07:40 +0900 | [diff] [blame] | 146 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | jr t1 |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 148 | PTR_ADDU a0, t0 /* dest ptr */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | .set push |
| 151 | .set noreorder |
| 152 | .set nomacro |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 153 | f_fill64 a0, -64, FILL64RG, .Lpartial_fixup /* ... but first do longs ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | 2: .set pop |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 155 | andi a2, STORMASK /* At most one long to go */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | beqz a2, 1f |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 158 | PTR_ADDU a0, a2 /* What's left */ |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 159 | R10KCBARRIER(0(ra)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | #ifdef __MIPSEB__ |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 161 | EX(LONG_S_R, a1, -1(a0), .Llast_fixup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | #endif |
| 163 | #ifdef __MIPSEL__ |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 164 | EX(LONG_S_L, a1, -1(a0), .Llast_fixup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #endif |
| 166 | 1: jr ra |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 167 | move a2, zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 169 | .Lsmall_memset: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | beqz a2, 2f |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 171 | PTR_ADDU t1, a0, a2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | 1: PTR_ADDIU a0, 1 /* fill bytewise */ |
Thomas Bogendoerfer | 930bff8 | 2007-11-25 11:47:56 +0100 | [diff] [blame] | 174 | R10KCBARRIER(0(ra)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | bne t1, a0, 1b |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 176 | sb a1, -1(a0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | 2: jr ra /* done */ |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 179 | move a2, zero |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | END(memset) |
| 181 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 182 | .Lfirst_fixup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | jr ra |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 184 | nop |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 186 | .Lfwd_fixup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | PTR_L t0, TI_TASK($28) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | andi a2, 0x3f |
Tony Wu | e5674ad | 2010-11-10 21:48:15 +0800 | [diff] [blame] | 189 | LONG_L t0, THREAD_BUADDR(t0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | LONG_ADDU a2, t1 |
| 191 | jr ra |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 192 | LONG_SUBU a2, t0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 194 | .Lpartial_fixup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | PTR_L t0, TI_TASK($28) |
Steven J. Hill | 26c5e07 | 2013-03-25 13:40:49 -0500 | [diff] [blame] | 196 | andi a2, STORMASK |
Tony Wu | e5674ad | 2010-11-10 21:48:15 +0800 | [diff] [blame] | 197 | LONG_L t0, THREAD_BUADDR(t0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | LONG_ADDU a2, t1 |
| 199 | jr ra |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 200 | LONG_SUBU a2, t0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Ralf Baechle | c5ec198 | 2008-01-29 10:14:59 +0000 | [diff] [blame] | 202 | .Llast_fixup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | jr ra |
Markos Chandras | 8483b14 | 2014-01-03 09:21:20 +0000 | [diff] [blame^] | 204 | andi v1, a2, STORMASK |