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 | |
| 31 | #include <arch_helpers.h> |
Achin Gupta | 4a826dd | 2013-11-25 14:00:56 +0000 | [diff] [blame] | 32 | #include <runtime_svc.h> |
| 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 | |
| 82 | .section .text, "ax" |
| 83 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 84 | get_afflvl_shift: ; .type get_afflvl_shift, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 85 | cmp x0, #3 |
| 86 | cinc x0, x0, eq |
| 87 | mov x1, #MPIDR_AFFLVL_SHIFT |
| 88 | lsl x0, x0, x1 |
| 89 | ret |
| 90 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 91 | mpidr_mask_lower_afflvls: ; .type mpidr_mask_lower_afflvls, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 92 | cmp x1, #3 |
| 93 | cinc x1, x1, eq |
| 94 | mov x2, #MPIDR_AFFLVL_SHIFT |
| 95 | lsl x2, x1, x2 |
| 96 | lsr x0, x0, x2 |
| 97 | lsl x0, x0, x2 |
| 98 | ret |
| 99 | |
| 100 | /* ----------------------------------------------------- |
| 101 | * Asynchronous exception manipulation accessors |
| 102 | * ----------------------------------------------------- |
| 103 | */ |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 104 | enable_irq: ; .type enable_irq, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 105 | msr daifclr, #DAIF_IRQ_BIT |
| 106 | ret |
| 107 | |
| 108 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 109 | enable_fiq: ; .type enable_fiq, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 110 | msr daifclr, #DAIF_FIQ_BIT |
| 111 | ret |
| 112 | |
| 113 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 114 | enable_serror: ; .type enable_serror, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | msr daifclr, #DAIF_ABT_BIT |
| 116 | ret |
| 117 | |
| 118 | |
Sandrine Bailleux | 3738274 | 2013-11-18 17:26:59 +0000 | [diff] [blame] | 119 | enable_debug_exceptions: |
| 120 | msr daifclr, #DAIF_DBG_BIT |
| 121 | ret |
| 122 | |
| 123 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 124 | disable_irq: ; .type disable_irq, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 125 | msr daifset, #DAIF_IRQ_BIT |
| 126 | ret |
| 127 | |
| 128 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 129 | disable_fiq: ; .type disable_fiq, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 130 | msr daifset, #DAIF_FIQ_BIT |
| 131 | ret |
| 132 | |
| 133 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 134 | disable_serror: ; .type disable_serror, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 135 | msr daifset, #DAIF_ABT_BIT |
| 136 | ret |
| 137 | |
| 138 | |
Sandrine Bailleux | 3738274 | 2013-11-18 17:26:59 +0000 | [diff] [blame] | 139 | disable_debug_exceptions: |
| 140 | msr daifset, #DAIF_DBG_BIT |
| 141 | ret |
| 142 | |
| 143 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 144 | read_daif: ; .type read_daif, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 145 | mrs x0, daif |
| 146 | ret |
| 147 | |
| 148 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 149 | write_daif: ; .type write_daif, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 150 | msr daif, x0 |
| 151 | ret |
| 152 | |
| 153 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 154 | read_spsr: ; .type read_spsr, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 155 | mrs x0, CurrentEl |
| 156 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 157 | b.eq read_spsr_el1 |
| 158 | cmp x0, #(MODE_EL2 << MODE_EL_SHIFT) |
| 159 | b.eq read_spsr_el2 |
| 160 | cmp x0, #(MODE_EL3 << MODE_EL_SHIFT) |
| 161 | b.eq read_spsr_el3 |
| 162 | |
| 163 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 164 | read_spsr_el1: ; .type read_spsr_el1, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 165 | mrs x0, spsr_el1 |
| 166 | ret |
| 167 | |
| 168 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 169 | read_spsr_el2: ; .type read_spsr_el2, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 170 | mrs x0, spsr_el2 |
| 171 | ret |
| 172 | |
| 173 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 174 | read_spsr_el3: ; .type read_spsr_el3, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 175 | mrs x0, spsr_el3 |
| 176 | ret |
| 177 | |
| 178 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 179 | write_spsr: ; .type write_spsr, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 180 | mrs x1, CurrentEl |
| 181 | cmp x1, #(MODE_EL1 << MODE_EL_SHIFT) |
| 182 | b.eq write_spsr_el1 |
| 183 | cmp x1, #(MODE_EL2 << MODE_EL_SHIFT) |
| 184 | b.eq write_spsr_el2 |
| 185 | cmp x1, #(MODE_EL3 << MODE_EL_SHIFT) |
| 186 | b.eq write_spsr_el3 |
| 187 | |
| 188 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 189 | write_spsr_el1: ; .type write_spsr_el1, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 190 | msr spsr_el1, x0 |
| 191 | isb |
| 192 | ret |
| 193 | |
| 194 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 195 | write_spsr_el2: ; .type write_spsr_el2, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 196 | msr spsr_el2, x0 |
| 197 | isb |
| 198 | ret |
| 199 | |
| 200 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 201 | write_spsr_el3: ; .type write_spsr_el3, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 202 | msr spsr_el3, x0 |
| 203 | isb |
| 204 | ret |
| 205 | |
| 206 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 207 | read_elr: ; .type read_elr, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 208 | mrs x0, CurrentEl |
| 209 | cmp x0, #(MODE_EL1 << MODE_EL_SHIFT) |
| 210 | b.eq read_elr_el1 |
| 211 | cmp x0, #(MODE_EL2 << MODE_EL_SHIFT) |
| 212 | b.eq read_elr_el2 |
| 213 | cmp x0, #(MODE_EL3 << MODE_EL_SHIFT) |
| 214 | b.eq read_elr_el3 |
| 215 | |
| 216 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 217 | read_elr_el1: ; .type read_elr_el1, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 218 | mrs x0, elr_el1 |
| 219 | ret |
| 220 | |
| 221 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 222 | read_elr_el2: ; .type read_elr_el2, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 223 | mrs x0, elr_el2 |
| 224 | ret |
| 225 | |
| 226 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 227 | read_elr_el3: ; .type read_elr_el3, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 228 | mrs x0, elr_el3 |
| 229 | ret |
| 230 | |
| 231 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 232 | write_elr: ; .type write_elr, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 233 | mrs x1, CurrentEl |
| 234 | cmp x1, #(MODE_EL1 << MODE_EL_SHIFT) |
| 235 | b.eq write_elr_el1 |
| 236 | cmp x1, #(MODE_EL2 << MODE_EL_SHIFT) |
| 237 | b.eq write_elr_el2 |
| 238 | cmp x1, #(MODE_EL3 << MODE_EL_SHIFT) |
| 239 | b.eq write_elr_el3 |
| 240 | |
| 241 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 242 | write_elr_el1: ; .type write_elr_el1, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 243 | msr elr_el1, x0 |
| 244 | isb |
| 245 | ret |
| 246 | |
| 247 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 248 | write_elr_el2: ; .type write_elr_el2, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 249 | msr elr_el2, x0 |
| 250 | isb |
| 251 | ret |
| 252 | |
| 253 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 254 | write_elr_el3: ; .type write_elr_el3, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 255 | msr elr_el3, x0 |
| 256 | isb |
| 257 | ret |
| 258 | |
| 259 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 260 | dsb: ; .type dsb, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 261 | dsb sy |
| 262 | ret |
| 263 | |
| 264 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 265 | isb: ; .type isb, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 266 | isb |
| 267 | ret |
| 268 | |
| 269 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 270 | sev: ; .type sev, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 271 | sev |
| 272 | ret |
| 273 | |
| 274 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 275 | wfe: ; .type wfe, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 276 | wfe |
| 277 | ret |
| 278 | |
| 279 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 280 | wfi: ; .type wfi, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | wfi |
| 282 | ret |
| 283 | |
| 284 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 285 | eret: ; .type eret, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 286 | eret |
| 287 | |
| 288 | |
Jeenu Viswambharan | 3a4cae0 | 2014-01-16 17:30:39 +0000 | [diff] [blame] | 289 | smc: ; .type smc, %function |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 290 | smc #0 |
Sandrine Bailleux | 65f546a | 2013-11-28 09:43:06 +0000 | [diff] [blame] | 291 | |
| 292 | /* ----------------------------------------------------------------------- |
| 293 | * void zeromem16(void *mem, unsigned int length); |
| 294 | * |
| 295 | * Initialise a memory region to 0. |
| 296 | * The memory address must be 16-byte aligned. |
| 297 | * ----------------------------------------------------------------------- |
| 298 | */ |
| 299 | zeromem16: |
| 300 | add x2, x0, x1 |
| 301 | /* zero 16 bytes at a time */ |
| 302 | z_loop16: |
| 303 | sub x3, x2, x0 |
| 304 | cmp x3, #16 |
| 305 | b.lt z_loop1 |
| 306 | stp xzr, xzr, [x0], #16 |
| 307 | b z_loop16 |
| 308 | /* zero byte per byte */ |
| 309 | z_loop1: |
| 310 | cmp x0, x2 |
| 311 | b.eq z_end |
| 312 | strb wzr, [x0], #1 |
| 313 | b z_loop1 |
| 314 | z_end: ret |
| 315 | |
| 316 | |
| 317 | /* -------------------------------------------------------------------------- |
| 318 | * void memcpy16(void *dest, const void *src, unsigned int length) |
| 319 | * |
| 320 | * Copy length bytes from memory area src to memory area dest. |
| 321 | * The memory areas should not overlap. |
| 322 | * Destination and source addresses must be 16-byte aligned. |
| 323 | * -------------------------------------------------------------------------- |
| 324 | */ |
| 325 | memcpy16: |
| 326 | /* copy 16 bytes at a time */ |
| 327 | m_loop16: |
| 328 | cmp x2, #16 |
| 329 | b.lt m_loop1 |
| 330 | ldp x3, x4, [x1], #16 |
| 331 | stp x3, x4, [x0], #16 |
| 332 | sub x2, x2, #16 |
| 333 | b m_loop16 |
| 334 | /* copy byte per byte */ |
| 335 | m_loop1: |
| 336 | cbz x2, m_end |
| 337 | ldrb w3, [x1], #1 |
| 338 | strb w3, [x0], #1 |
| 339 | subs x2, x2, #1 |
| 340 | b.ne m_loop1 |
| 341 | m_end: ret |