Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 31 | #include <arch.h> |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 32 | #include <asm_macros.S> |
Achin Gupta | 4a826dd | 2013-11-25 14:00:56 +0000 | [diff] [blame] | 33 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 34 | .globl enable_irq |
| 35 | .globl disable_irq |
| 36 | |
| 37 | .globl enable_fiq |
| 38 | .globl disable_fiq |
| 39 | |
| 40 | .globl enable_serror |
| 41 | .globl disable_serror |
| 42 | |
Sandrine Bailleux | 3738274 | 2013-11-18 17:26:59 +0000 | [diff] [blame] | 43 | .globl enable_debug_exceptions |
| 44 | .globl disable_debug_exceptions |
| 45 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 46 | .globl read_daif |
| 47 | .globl write_daif |
| 48 | |
| 49 | .globl read_spsr |
| 50 | .globl read_spsr_el1 |
| 51 | .globl read_spsr_el2 |
| 52 | .globl read_spsr_el3 |
| 53 | |
| 54 | .globl write_spsr |
| 55 | .globl write_spsr_el1 |
| 56 | .globl write_spsr_el2 |
| 57 | .globl write_spsr_el3 |
| 58 | |
| 59 | .globl read_elr |
| 60 | .globl read_elr_el1 |
| 61 | .globl read_elr_el2 |
| 62 | .globl read_elr_el3 |
| 63 | |
| 64 | .globl write_elr |
| 65 | .globl write_elr_el1 |
| 66 | .globl write_elr_el2 |
| 67 | .globl write_elr_el3 |
| 68 | |
| 69 | .globl get_afflvl_shift |
| 70 | .globl mpidr_mask_lower_afflvls |
| 71 | .globl dsb |
| 72 | .globl isb |
| 73 | .globl sev |
| 74 | .globl wfe |
| 75 | .globl wfi |
| 76 | .globl eret |
| 77 | .globl smc |
| 78 | |
Sandrine Bailleux | 65f546a | 2013-11-28 09:43:06 +0000 | [diff] [blame] | 79 | .globl zeromem16 |
| 80 | .globl memcpy16 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 81 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 82 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 83 | func get_afflvl_shift |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 84 | cmp x0, #3 |
| 85 | cinc x0, x0, eq |
| 86 | mov x1, #MPIDR_AFFLVL_SHIFT |
| 87 | lsl x0, x0, x1 |
| 88 | ret |
| 89 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 90 | func mpidr_mask_lower_afflvls |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 91 | cmp x1, #3 |
| 92 | cinc x1, x1, eq |
| 93 | mov x2, #MPIDR_AFFLVL_SHIFT |
| 94 | lsl x2, x1, x2 |
| 95 | lsr x0, x0, x2 |
| 96 | lsl x0, x0, x2 |
| 97 | ret |
| 98 | |
| 99 | /* ----------------------------------------------------- |
| 100 | * Asynchronous exception manipulation accessors |
| 101 | * ----------------------------------------------------- |
| 102 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 103 | func enable_irq |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 104 | msr daifclr, #DAIF_IRQ_BIT |
| 105 | ret |
| 106 | |
| 107 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 108 | func enable_fiq |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 109 | msr daifclr, #DAIF_FIQ_BIT |
| 110 | ret |
| 111 | |
| 112 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 113 | func enable_serror |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 114 | msr daifclr, #DAIF_ABT_BIT |
| 115 | ret |
| 116 | |
| 117 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 118 | func enable_debug_exceptions |
Sandrine Bailleux | 3738274 | 2013-11-18 17:26:59 +0000 | [diff] [blame] | 119 | msr daifclr, #DAIF_DBG_BIT |
| 120 | ret |
| 121 | |
| 122 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 123 | func disable_irq |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 124 | msr daifset, #DAIF_IRQ_BIT |
| 125 | ret |
| 126 | |
| 127 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 128 | func disable_fiq |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 129 | msr daifset, #DAIF_FIQ_BIT |
| 130 | ret |
| 131 | |
| 132 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 133 | func disable_serror |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | msr daifset, #DAIF_ABT_BIT |
| 135 | ret |
| 136 | |
| 137 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 138 | func disable_debug_exceptions |
Sandrine Bailleux | 3738274 | 2013-11-18 17:26:59 +0000 | [diff] [blame] | 139 | msr daifset, #DAIF_DBG_BIT |
| 140 | ret |
| 141 | |
| 142 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 143 | func read_daif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 144 | mrs x0, daif |
| 145 | ret |
| 146 | |
| 147 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 148 | func write_daif |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 149 | msr daif, x0 |
| 150 | ret |
| 151 | |
| 152 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 153 | func read_spsr |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 154 | mrs x0, CurrentEl |
| 155 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 156 | b.eq read_spsr_el1 |
| 157 | cmp x0, #(MODE_EL2 << MODE_EL_SHIFT) |
| 158 | b.eq read_spsr_el2 |
| 159 | cmp x0, #(MODE_EL3 << MODE_EL_SHIFT) |
| 160 | b.eq read_spsr_el3 |
| 161 | |
| 162 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 163 | func read_spsr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 164 | mrs x0, spsr_el1 |
| 165 | ret |
| 166 | |
| 167 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 168 | func read_spsr_el2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 169 | mrs x0, spsr_el2 |
| 170 | ret |
| 171 | |
| 172 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 173 | func read_spsr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 174 | mrs x0, spsr_el3 |
| 175 | ret |
| 176 | |
| 177 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 178 | func write_spsr |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 179 | mrs x1, CurrentEl |
| 180 | cmp x1, #(MODE_EL1 << MODE_EL_SHIFT) |
| 181 | b.eq write_spsr_el1 |
| 182 | cmp x1, #(MODE_EL2 << MODE_EL_SHIFT) |
| 183 | b.eq write_spsr_el2 |
| 184 | cmp x1, #(MODE_EL3 << MODE_EL_SHIFT) |
| 185 | b.eq write_spsr_el3 |
| 186 | |
| 187 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 188 | func write_spsr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 189 | msr spsr_el1, x0 |
| 190 | isb |
| 191 | ret |
| 192 | |
| 193 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 194 | func write_spsr_el2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 195 | msr spsr_el2, x0 |
| 196 | isb |
| 197 | ret |
| 198 | |
| 199 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 200 | func write_spsr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 201 | msr spsr_el3, x0 |
| 202 | isb |
| 203 | ret |
| 204 | |
| 205 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 206 | func read_elr |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 207 | mrs x0, CurrentEl |
| 208 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 209 | b.eq read_elr_el1 |
| 210 | cmp x0, #(MODE_EL2 << MODE_EL_SHIFT) |
| 211 | b.eq read_elr_el2 |
| 212 | cmp x0, #(MODE_EL3 << MODE_EL_SHIFT) |
| 213 | b.eq read_elr_el3 |
| 214 | |
| 215 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 216 | func read_elr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 217 | mrs x0, elr_el1 |
| 218 | ret |
| 219 | |
| 220 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 221 | func read_elr_el2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 222 | mrs x0, elr_el2 |
| 223 | ret |
| 224 | |
| 225 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 226 | func read_elr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 227 | mrs x0, elr_el3 |
| 228 | ret |
| 229 | |
| 230 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 231 | func write_elr |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 232 | mrs x1, CurrentEl |
| 233 | cmp x1, #(MODE_EL1 << MODE_EL_SHIFT) |
| 234 | b.eq write_elr_el1 |
| 235 | cmp x1, #(MODE_EL2 << MODE_EL_SHIFT) |
| 236 | b.eq write_elr_el2 |
| 237 | cmp x1, #(MODE_EL3 << MODE_EL_SHIFT) |
| 238 | b.eq write_elr_el3 |
| 239 | |
| 240 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 241 | func write_elr_el1 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 242 | msr elr_el1, x0 |
| 243 | isb |
| 244 | ret |
| 245 | |
| 246 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 247 | func write_elr_el2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 248 | msr elr_el2, x0 |
| 249 | isb |
| 250 | ret |
| 251 | |
| 252 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 253 | func write_elr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 254 | msr elr_el3, x0 |
| 255 | isb |
| 256 | ret |
| 257 | |
| 258 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 259 | func dsb |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 260 | dsb sy |
| 261 | ret |
| 262 | |
| 263 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 264 | func isb |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 265 | isb |
| 266 | ret |
| 267 | |
| 268 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 269 | func sev |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 270 | sev |
| 271 | ret |
| 272 | |
| 273 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 274 | func wfe |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 275 | wfe |
| 276 | ret |
| 277 | |
| 278 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 279 | func wfi |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 280 | wfi |
| 281 | ret |
| 282 | |
| 283 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 284 | func eret |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 285 | eret |
| 286 | |
| 287 | |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 288 | func smc |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 289 | smc #0 |
Sandrine Bailleux | 65f546a | 2013-11-28 09:43:06 +0000 | [diff] [blame] | 290 | |
| 291 | /* ----------------------------------------------------------------------- |
| 292 | * void zeromem16(void *mem, unsigned int length); |
| 293 | * |
| 294 | * Initialise a memory region to 0. |
| 295 | * The memory address must be 16-byte aligned. |
| 296 | * ----------------------------------------------------------------------- |
| 297 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 298 | func zeromem16 |
Sandrine Bailleux | 65f546a | 2013-11-28 09:43:06 +0000 | [diff] [blame] | 299 | add x2, x0, x1 |
| 300 | /* zero 16 bytes at a time */ |
| 301 | z_loop16: |
| 302 | sub x3, x2, x0 |
| 303 | cmp x3, #16 |
| 304 | b.lt z_loop1 |
| 305 | stp xzr, xzr, [x0], #16 |
| 306 | b z_loop16 |
| 307 | /* zero byte per byte */ |
| 308 | z_loop1: |
| 309 | cmp x0, x2 |
| 310 | b.eq z_end |
| 311 | strb wzr, [x0], #1 |
| 312 | b z_loop1 |
| 313 | z_end: ret |
| 314 | |
| 315 | |
| 316 | /* -------------------------------------------------------------------------- |
| 317 | * void memcpy16(void *dest, const void *src, unsigned int length) |
| 318 | * |
| 319 | * Copy length bytes from memory area src to memory area dest. |
| 320 | * The memory areas should not overlap. |
| 321 | * Destination and source addresses must be 16-byte aligned. |
| 322 | * -------------------------------------------------------------------------- |
| 323 | */ |
Andrew Thoelke | 38bde41 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 324 | func memcpy16 |
Sandrine Bailleux | 65f546a | 2013-11-28 09:43:06 +0000 | [diff] [blame] | 325 | /* copy 16 bytes at a time */ |
| 326 | m_loop16: |
| 327 | cmp x2, #16 |
| 328 | b.lt m_loop1 |
| 329 | ldp x3, x4, [x1], #16 |
| 330 | stp x3, x4, [x0], #16 |
| 331 | sub x2, x2, #16 |
| 332 | b m_loop16 |
| 333 | /* copy byte per byte */ |
| 334 | m_loop1: |
| 335 | cbz x2, m_end |
| 336 | ldrb w3, [x1], #1 |
| 337 | strb w3, [x0], #1 |
| 338 | subs x2, x2, #1 |
| 339 | b.ne m_loop1 |
| 340 | m_end: ret |