Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 1 | /* |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 2 | * Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1996-2000 Russell King |
| 5 | * Copyright (C) 2012 ARM Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | #ifndef __ASSEMBLY__ |
| 20 | #error "Only include this from assembly code" |
| 21 | #endif |
| 22 | |
Marc Zyngier | f3e3927 | 2015-02-20 13:53:13 +0000 | [diff] [blame] | 23 | #ifndef __ASM_ASSEMBLER_H |
| 24 | #define __ASM_ASSEMBLER_H |
| 25 | |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 26 | #include <asm/asm-offsets.h> |
Andre Przywara | 823066d | 2016-06-28 18:07:29 +0100 | [diff] [blame] | 27 | #include <asm/cpufeature.h> |
Julien Thierry | e28cc02 | 2017-10-25 10:04:32 +0100 | [diff] [blame] | 28 | #include <asm/debug-monitors.h> |
Geoff Levand | 5003dbd | 2016-04-27 17:47:10 +0100 | [diff] [blame] | 29 | #include <asm/page.h> |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 30 | #include <asm/pgtable-hwdef.h> |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 31 | #include <asm/ptrace.h> |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 32 | #include <asm/thread_info.h> |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 33 | |
James Morse | 0fbeb31 | 2017-11-02 12:12:34 +0000 | [diff] [blame] | 34 | .macro save_and_disable_daif, flags |
| 35 | mrs \flags, daif |
| 36 | msr daifset, #0xf |
| 37 | .endm |
| 38 | |
| 39 | .macro disable_daif |
| 40 | msr daifset, #0xf |
| 41 | .endm |
| 42 | |
| 43 | .macro enable_daif |
| 44 | msr daifclr, #0xf |
| 45 | .endm |
| 46 | |
| 47 | .macro restore_daif, flags:req |
| 48 | msr daif, \flags |
| 49 | .endm |
| 50 | |
James Morse | b55a5a1 | 2017-11-02 12:12:39 +0000 | [diff] [blame] | 51 | /* Only on aarch64 pstate, PSR_D_BIT is different for aarch32 */ |
| 52 | .macro inherit_daif, pstate:req, tmp:req |
| 53 | and \tmp, \pstate, #(PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) |
| 54 | msr daif, \tmp |
| 55 | .endm |
| 56 | |
James Morse | b282e1c | 2017-11-02 12:12:41 +0000 | [diff] [blame] | 57 | /* IRQ is the lowest priority flag, unconditionally unmask the rest. */ |
| 58 | .macro enable_da_f |
| 59 | msr daifclr, #(8 | 4 | 1) |
| 60 | .endm |
| 61 | |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 62 | /* |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 63 | * Enable and disable interrupts. |
| 64 | */ |
| 65 | .macro disable_irq |
| 66 | msr daifset, #2 |
| 67 | .endm |
| 68 | |
| 69 | .macro enable_irq |
| 70 | msr daifclr, #2 |
| 71 | .endm |
| 72 | |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 73 | .macro save_and_disable_irq, flags |
| 74 | mrs \flags, daif |
| 75 | msr daifset, #2 |
| 76 | .endm |
| 77 | |
| 78 | .macro restore_irq, flags |
| 79 | msr daif, \flags |
| 80 | .endm |
| 81 | |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 82 | .macro enable_dbg |
| 83 | msr daifclr, #8 |
| 84 | .endm |
| 85 | |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 86 | .macro disable_step_tsk, flgs, tmp |
| 87 | tbz \flgs, #TIF_SINGLESTEP, 9990f |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 88 | mrs \tmp, mdscr_el1 |
Julien Thierry | e28cc02 | 2017-10-25 10:04:32 +0100 | [diff] [blame] | 89 | bic \tmp, \tmp, #DBG_MDSCR_SS |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 90 | msr mdscr_el1, \tmp |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 91 | isb // Synchronise with enable_dbg |
| 92 | 9990: |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 93 | .endm |
| 94 | |
James Morse | 84d0fb1 | 2017-11-02 12:12:38 +0000 | [diff] [blame] | 95 | /* call with daif masked */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 96 | .macro enable_step_tsk, flgs, tmp |
| 97 | tbz \flgs, #TIF_SINGLESTEP, 9990f |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 98 | mrs \tmp, mdscr_el1 |
Julien Thierry | e28cc02 | 2017-10-25 10:04:32 +0100 | [diff] [blame] | 99 | orr \tmp, \tmp, #DBG_MDSCR_SS |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 100 | msr mdscr_el1, \tmp |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 101 | 9990: |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 102 | .endm |
| 103 | |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 104 | /* |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 105 | * SMP data memory barrier |
| 106 | */ |
| 107 | .macro smp_dmb, opt |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 108 | dmb \opt |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 109 | .endm |
| 110 | |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 111 | /* |
Will Deacon | f99a250 | 2016-09-06 16:40:23 +0100 | [diff] [blame] | 112 | * NOP sequence |
| 113 | */ |
| 114 | .macro nops, num |
| 115 | .rept \num |
| 116 | nop |
| 117 | .endr |
| 118 | .endm |
| 119 | |
| 120 | /* |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 121 | * Emit an entry into the exception table |
| 122 | */ |
| 123 | .macro _asm_extable, from, to |
| 124 | .pushsection __ex_table, "a" |
| 125 | .align 3 |
| 126 | .long (\from - .), (\to - .) |
| 127 | .popsection |
| 128 | .endm |
| 129 | |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 130 | #define USER(l, x...) \ |
| 131 | 9999: x; \ |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 132 | _asm_extable 9999b, l |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Register aliases. |
| 136 | */ |
| 137 | lr .req x30 // link register |
Marc Zyngier | dc637f1 | 2012-10-19 17:37:35 +0100 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * Vector entry |
| 141 | */ |
| 142 | .macro ventry label |
| 143 | .align 7 |
| 144 | b \label |
| 145 | .endm |
Matthew Leach | e68beda | 2013-10-11 14:52:15 +0100 | [diff] [blame] | 146 | |
| 147 | /* |
| 148 | * Select code when configured for BE. |
| 149 | */ |
| 150 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 151 | #define CPU_BE(code...) code |
| 152 | #else |
| 153 | #define CPU_BE(code...) |
| 154 | #endif |
| 155 | |
| 156 | /* |
| 157 | * Select code when configured for LE. |
| 158 | */ |
| 159 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 160 | #define CPU_LE(code...) |
| 161 | #else |
| 162 | #define CPU_LE(code...) code |
| 163 | #endif |
| 164 | |
Matthew Leach | 55b8954 | 2013-10-11 14:52:13 +0100 | [diff] [blame] | 165 | /* |
| 166 | * Define a macro that constructs a 64-bit value by concatenating two |
| 167 | * 32-bit registers. Note that on big endian systems the order of the |
| 168 | * registers is swapped. |
| 169 | */ |
| 170 | #ifndef CONFIG_CPU_BIG_ENDIAN |
| 171 | .macro regs_to_64, rd, lbits, hbits |
| 172 | #else |
| 173 | .macro regs_to_64, rd, hbits, lbits |
| 174 | #endif |
| 175 | orr \rd, \lbits, \hbits, lsl #32 |
| 176 | .endm |
Marc Zyngier | f3e3927 | 2015-02-20 13:53:13 +0000 | [diff] [blame] | 177 | |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 178 | /* |
| 179 | * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 180 | * <symbol> is within the range +/- 4 GB of the PC when running |
| 181 | * in core kernel context. In module context, a movz/movk sequence |
| 182 | * is used, since modules may be loaded far away from the kernel |
| 183 | * when KASLR is in effect. |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 184 | */ |
| 185 | /* |
| 186 | * @dst: destination register (64 bit wide) |
| 187 | * @sym: name of the symbol |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 188 | */ |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 189 | .macro adr_l, dst, sym |
| 190 | #ifndef MODULE |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 191 | adrp \dst, \sym |
| 192 | add \dst, \dst, :lo12:\sym |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 193 | #else |
| 194 | movz \dst, #:abs_g3:\sym |
| 195 | movk \dst, #:abs_g2_nc:\sym |
| 196 | movk \dst, #:abs_g1_nc:\sym |
| 197 | movk \dst, #:abs_g0_nc:\sym |
| 198 | #endif |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 199 | .endm |
| 200 | |
| 201 | /* |
| 202 | * @dst: destination register (32 or 64 bit wide) |
| 203 | * @sym: name of the symbol |
| 204 | * @tmp: optional 64-bit scratch register to be used if <dst> is a |
| 205 | * 32-bit wide register, in which case it cannot be used to hold |
| 206 | * the address |
| 207 | */ |
| 208 | .macro ldr_l, dst, sym, tmp= |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 209 | #ifndef MODULE |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 210 | .ifb \tmp |
| 211 | adrp \dst, \sym |
| 212 | ldr \dst, [\dst, :lo12:\sym] |
| 213 | .else |
| 214 | adrp \tmp, \sym |
| 215 | ldr \dst, [\tmp, :lo12:\sym] |
| 216 | .endif |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 217 | #else |
| 218 | .ifb \tmp |
| 219 | adr_l \dst, \sym |
| 220 | ldr \dst, [\dst] |
| 221 | .else |
| 222 | adr_l \tmp, \sym |
| 223 | ldr \dst, [\tmp] |
| 224 | .endif |
| 225 | #endif |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 226 | .endm |
| 227 | |
| 228 | /* |
| 229 | * @src: source register (32 or 64 bit wide) |
| 230 | * @sym: name of the symbol |
| 231 | * @tmp: mandatory 64-bit scratch register to calculate the address |
| 232 | * while <src> needs to be preserved. |
| 233 | */ |
| 234 | .macro str_l, src, sym, tmp |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 235 | #ifndef MODULE |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 236 | adrp \tmp, \sym |
| 237 | str \src, [\tmp, :lo12:\sym] |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 238 | #else |
| 239 | adr_l \tmp, \sym |
| 240 | str \src, [\tmp] |
| 241 | #endif |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 242 | .endm |
| 243 | |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 244 | /* |
Ard Biesheuvel | 8ea41b1 | 2017-07-15 17:23:13 +0100 | [diff] [blame] | 245 | * @dst: Result of per_cpu(sym, smp_processor_id()), can be SP for |
| 246 | * non-module code |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 247 | * @sym: The name of the per-cpu variable |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 248 | * @tmp: scratch register |
| 249 | */ |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 250 | .macro adr_this_cpu, dst, sym, tmp |
Ard Biesheuvel | 8ea41b1 | 2017-07-15 17:23:13 +0100 | [diff] [blame] | 251 | #ifndef MODULE |
| 252 | adrp \tmp, \sym |
| 253 | add \dst, \tmp, #:lo12:\sym |
| 254 | #else |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 255 | adr_l \dst, \sym |
Ard Biesheuvel | 8ea41b1 | 2017-07-15 17:23:13 +0100 | [diff] [blame] | 256 | #endif |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame^] | 257 | alternative_if_not ARM64_HAS_VIRT_HOST_EXTN |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 258 | mrs \tmp, tpidr_el1 |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame^] | 259 | alternative_else |
| 260 | mrs \tmp, tpidr_el2 |
| 261 | alternative_endif |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 262 | add \dst, \dst, \tmp |
| 263 | .endm |
| 264 | |
| 265 | /* |
| 266 | * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id())) |
| 267 | * @sym: The name of the per-cpu variable |
| 268 | * @tmp: scratch register |
| 269 | */ |
| 270 | .macro ldr_this_cpu dst, sym, tmp |
| 271 | adr_l \dst, \sym |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame^] | 272 | alternative_if_not ARM64_HAS_VIRT_HOST_EXTN |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 273 | mrs \tmp, tpidr_el1 |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame^] | 274 | alternative_else |
| 275 | mrs \tmp, tpidr_el2 |
| 276 | alternative_endif |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 277 | ldr \dst, [\dst, \tmp] |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 278 | .endm |
| 279 | |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 280 | /* |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 281 | * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm) |
| 282 | */ |
| 283 | .macro vma_vm_mm, rd, rn |
| 284 | ldr \rd, [\rn, #VMA_VM_MM] |
| 285 | .endm |
| 286 | |
| 287 | /* |
| 288 | * mmid - get context id from mm pointer (mm->context.id) |
| 289 | */ |
| 290 | .macro mmid, rd, rn |
| 291 | ldr \rd, [\rn, #MM_CONTEXT_ID] |
| 292 | .endm |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 293 | /* |
| 294 | * read_ctr - read CTR_EL0. If the system has mismatched |
| 295 | * cache line sizes, provide the system wide safe value |
| 296 | * from arm64_ftr_reg_ctrel0.sys_val |
| 297 | */ |
| 298 | .macro read_ctr, reg |
| 299 | alternative_if_not ARM64_MISMATCHED_CACHE_LINE_SIZE |
| 300 | mrs \reg, ctr_el0 // read CTR |
| 301 | nop |
| 302 | alternative_else |
| 303 | ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL |
| 304 | alternative_endif |
| 305 | .endm |
| 306 | |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 307 | |
| 308 | /* |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 309 | * raw_dcache_line_size - get the minimum D-cache line size on this CPU |
| 310 | * from the CTR register. |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 311 | */ |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 312 | .macro raw_dcache_line_size, reg, tmp |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 313 | mrs \tmp, ctr_el0 // read CTR |
| 314 | ubfm \tmp, \tmp, #16, #19 // cache line size encoding |
| 315 | mov \reg, #4 // bytes per word |
| 316 | lsl \reg, \reg, \tmp // actual cache line size |
| 317 | .endm |
| 318 | |
| 319 | /* |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 320 | * dcache_line_size - get the safe D-cache line size across all CPUs |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 321 | */ |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 322 | .macro dcache_line_size, reg, tmp |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 323 | read_ctr \tmp |
| 324 | ubfm \tmp, \tmp, #16, #19 // cache line size encoding |
| 325 | mov \reg, #4 // bytes per word |
| 326 | lsl \reg, \reg, \tmp // actual cache line size |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 327 | .endm |
| 328 | |
| 329 | /* |
| 330 | * raw_icache_line_size - get the minimum I-cache line size on this CPU |
| 331 | * from the CTR register. |
| 332 | */ |
| 333 | .macro raw_icache_line_size, reg, tmp |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 334 | mrs \tmp, ctr_el0 // read CTR |
| 335 | and \tmp, \tmp, #0xf // cache line size encoding |
| 336 | mov \reg, #4 // bytes per word |
| 337 | lsl \reg, \reg, \tmp // actual cache line size |
| 338 | .endm |
| 339 | |
| 340 | /* |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 341 | * icache_line_size - get the safe I-cache line size across all CPUs |
| 342 | */ |
| 343 | .macro icache_line_size, reg, tmp |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 344 | read_ctr \tmp |
| 345 | and \tmp, \tmp, #0xf // cache line size encoding |
| 346 | mov \reg, #4 // bytes per word |
| 347 | lsl \reg, \reg, \tmp // actual cache line size |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 348 | .endm |
| 349 | |
| 350 | /* |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 351 | * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map |
| 352 | */ |
| 353 | .macro tcr_set_idmap_t0sz, valreg, tmpreg |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 354 | ldr_l \tmpreg, idmap_t0sz |
| 355 | bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 356 | .endm |
| 357 | |
| 358 | /* |
Kristina Martsenko | 787fd1d | 2017-12-13 17:07:17 +0000 | [diff] [blame] | 359 | * tcr_compute_pa_size - set TCR.(I)PS to the highest supported |
| 360 | * ID_AA64MMFR0_EL1.PARange value |
| 361 | * |
| 362 | * tcr: register with the TCR_ELx value to be updated |
| 363 | * pos: PARange bitfield position |
| 364 | * tmp{0,1}: temporary registers |
| 365 | */ |
| 366 | .macro tcr_compute_pa_size, tcr, pos, tmp0, tmp1 |
| 367 | mrs \tmp0, ID_AA64MMFR0_EL1 |
| 368 | // Narrow PARange to fit the PS field in TCR_ELx |
| 369 | ubfx \tmp0, \tmp0, #ID_AA64MMFR0_PARANGE_SHIFT, #3 |
| 370 | mov \tmp1, #ID_AA64MMFR0_PARANGE_MAX |
| 371 | cmp \tmp0, \tmp1 |
| 372 | csel \tmp0, \tmp1, \tmp0, hi |
| 373 | bfi \tcr, \tmp0, \pos, #3 |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 374 | .endm |
| 375 | |
| 376 | /* |
| 377 | * Macro to perform a data cache maintenance for the interval |
| 378 | * [kaddr, kaddr + size) |
| 379 | * |
| 380 | * op: operation passed to dc instruction |
| 381 | * domain: domain used in dsb instruciton |
| 382 | * kaddr: starting virtual address of the region |
| 383 | * size: size of the region |
| 384 | * Corrupts: kaddr, size, tmp1, tmp2 |
| 385 | */ |
| 386 | .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2 |
| 387 | dcache_line_size \tmp1, \tmp2 |
| 388 | add \size, \kaddr, \size |
| 389 | sub \tmp2, \tmp1, #1 |
| 390 | bic \kaddr, \kaddr, \tmp2 |
Andre Przywara | 823066d | 2016-06-28 18:07:29 +0100 | [diff] [blame] | 391 | 9998: |
| 392 | .if (\op == cvau || \op == cvac) |
| 393 | alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE |
| 394 | dc \op, \kaddr |
| 395 | alternative_else |
| 396 | dc civac, \kaddr |
| 397 | alternative_endif |
Robin Murphy | d50e071 | 2017-07-25 11:55:42 +0100 | [diff] [blame] | 398 | .elseif (\op == cvap) |
| 399 | alternative_if ARM64_HAS_DCPOP |
| 400 | sys 3, c7, c12, 1, \kaddr // dc cvap |
| 401 | alternative_else |
| 402 | dc cvac, \kaddr |
| 403 | alternative_endif |
Andre Przywara | 823066d | 2016-06-28 18:07:29 +0100 | [diff] [blame] | 404 | .else |
| 405 | dc \op, \kaddr |
| 406 | .endif |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 407 | add \kaddr, \kaddr, \tmp1 |
| 408 | cmp \kaddr, \size |
| 409 | b.lo 9998b |
| 410 | dsb \domain |
| 411 | .endm |
| 412 | |
| 413 | /* |
| 414 | * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present |
| 415 | */ |
| 416 | .macro reset_pmuserenr_el0, tmpreg |
| 417 | mrs \tmpreg, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer |
| 418 | sbfx \tmpreg, \tmpreg, #8, #4 |
| 419 | cmp \tmpreg, #1 // Skip if no PMU present |
| 420 | b.lt 9000f |
| 421 | msr pmuserenr_el0, xzr // Disable PMU access from EL0 |
| 422 | 9000: |
| 423 | .endm |
| 424 | |
| 425 | /* |
Geoff Levand | 5003dbd | 2016-04-27 17:47:10 +0100 | [diff] [blame] | 426 | * copy_page - copy src to dest using temp registers t1-t8 |
| 427 | */ |
| 428 | .macro copy_page dest:req src:req t1:req t2:req t3:req t4:req t5:req t6:req t7:req t8:req |
| 429 | 9998: ldp \t1, \t2, [\src] |
| 430 | ldp \t3, \t4, [\src, #16] |
| 431 | ldp \t5, \t6, [\src, #32] |
| 432 | ldp \t7, \t8, [\src, #48] |
| 433 | add \src, \src, #64 |
| 434 | stnp \t1, \t2, [\dest] |
| 435 | stnp \t3, \t4, [\dest, #16] |
| 436 | stnp \t5, \t6, [\dest, #32] |
| 437 | stnp \t7, \t8, [\dest, #48] |
| 438 | add \dest, \dest, #64 |
| 439 | tst \src, #(PAGE_SIZE - 1) |
| 440 | b.ne 9998b |
| 441 | .endm |
| 442 | |
| 443 | /* |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 444 | * Annotate a function as position independent, i.e., safe to be called before |
| 445 | * the kernel virtual mapping is activated. |
| 446 | */ |
| 447 | #define ENDPIPROC(x) \ |
| 448 | .globl __pi_##x; \ |
| 449 | .type __pi_##x, %function; \ |
| 450 | .set __pi_##x, x; \ |
| 451 | .size __pi_##x, . - x; \ |
| 452 | ENDPROC(x) |
| 453 | |
Mark Rutland | ed84b4e | 2017-07-26 16:05:20 +0100 | [diff] [blame] | 454 | /* |
| 455 | * Annotate a function as being unsuitable for kprobes. |
| 456 | */ |
| 457 | #ifdef CONFIG_KPROBES |
| 458 | #define NOKPROBE(x) \ |
| 459 | .pushsection "_kprobe_blacklist", "aw"; \ |
| 460 | .quad x; \ |
| 461 | .popsection; |
| 462 | #else |
| 463 | #define NOKPROBE(x) |
| 464 | #endif |
Ard Biesheuvel | 6ad1fe5 | 2015-12-26 13:48:02 +0100 | [diff] [blame] | 465 | /* |
| 466 | * Emit a 64-bit absolute little endian symbol reference in a way that |
| 467 | * ensures that it will be resolved at build time, even when building a |
| 468 | * PIE binary. This requires cooperation from the linker script, which |
| 469 | * must emit the lo32/hi32 halves individually. |
| 470 | */ |
| 471 | .macro le64sym, sym |
| 472 | .long \sym\()_lo32 |
| 473 | .long \sym\()_hi32 |
| 474 | .endm |
| 475 | |
Ard Biesheuvel | 30b5ba5 | 2016-04-18 17:09:44 +0200 | [diff] [blame] | 476 | /* |
| 477 | * mov_q - move an immediate constant into a 64-bit register using |
| 478 | * between 2 and 4 movz/movk instructions (depending on the |
| 479 | * magnitude and sign of the operand) |
| 480 | */ |
| 481 | .macro mov_q, reg, val |
| 482 | .if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff) |
| 483 | movz \reg, :abs_g1_s:\val |
| 484 | .else |
| 485 | .if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff) |
| 486 | movz \reg, :abs_g2_s:\val |
| 487 | .else |
| 488 | movz \reg, :abs_g3:\val |
| 489 | movk \reg, :abs_g2_nc:\val |
| 490 | .endif |
| 491 | movk \reg, :abs_g1_nc:\val |
| 492 | .endif |
| 493 | movk \reg, :abs_g0_nc:\val |
| 494 | .endm |
| 495 | |
Catalin Marinas | f33bcf0 | 2016-07-01 15:48:55 +0100 | [diff] [blame] | 496 | /* |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 497 | * Return the current thread_info. |
| 498 | */ |
| 499 | .macro get_thread_info, rd |
| 500 | mrs \rd, sp_el0 |
| 501 | .endm |
| 502 | |
| 503 | /* |
Kristina Martsenko | 529c4b0 | 2017-12-13 17:07:18 +0000 | [diff] [blame] | 504 | * Arrange a physical address in a TTBR register, taking care of 52-bit |
| 505 | * addresses. |
| 506 | * |
| 507 | * phys: physical address, preserved |
| 508 | * ttbr: returns the TTBR value |
| 509 | */ |
| 510 | .macro phys_to_ttbr, phys, ttbr |
| 511 | #ifdef CONFIG_ARM64_PA_BITS_52 |
| 512 | orr \ttbr, \phys, \phys, lsr #46 |
| 513 | and \ttbr, \ttbr, #TTBR_BADDR_MASK_52 |
| 514 | #else |
| 515 | mov \ttbr, \phys |
| 516 | #endif |
| 517 | .endm |
| 518 | |
Marc Zyngier | f3e3927 | 2015-02-20 13:53:13 +0000 | [diff] [blame] | 519 | #endif /* __ASM_ASSEMBLER_H */ |