7b076ccd1a54d9a6c3a5da45b5d8795cd1f41f5b
[linux-2.6-microblaze.git] / arch / arm64 / include / asm / assembler.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S
4  *
5  * Copyright (C) 1996-2000 Russell King
6  * Copyright (C) 2012 ARM Ltd.
7  */
8 #ifndef __ASSEMBLY__
9 #error "Only include this from assembly code"
10 #endif
11
12 #ifndef __ASM_ASSEMBLER_H
13 #define __ASM_ASSEMBLER_H
14
15 #include <asm-generic/export.h>
16
17 #include <asm/asm-offsets.h>
18 #include <asm/cpufeature.h>
19 #include <asm/cputype.h>
20 #include <asm/debug-monitors.h>
21 #include <asm/page.h>
22 #include <asm/pgtable-hwdef.h>
23 #include <asm/ptrace.h>
24 #include <asm/thread_info.h>
25
26         /*
27          * Provide a wxN alias for each wN register so what we can paste a xN
28          * reference after a 'w' to obtain the 32-bit version.
29          */
30         .irp    n,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
31         wx\n    .req    w\n
32         .endr
33
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
51         /* IRQ is the lowest priority flag, unconditionally unmask the rest. */
52         .macro enable_da_f
53         msr     daifclr, #(8 | 4 | 1)
54         .endm
55
56 /*
57  * Save/restore interrupts.
58  */
59         .macro  save_and_disable_irq, flags
60         mrs     \flags, daif
61         msr     daifset, #2
62         .endm
63
64         .macro  restore_irq, flags
65         msr     daif, \flags
66         .endm
67
68         .macro  enable_dbg
69         msr     daifclr, #8
70         .endm
71
72         .macro  disable_step_tsk, flgs, tmp
73         tbz     \flgs, #TIF_SINGLESTEP, 9990f
74         mrs     \tmp, mdscr_el1
75         bic     \tmp, \tmp, #DBG_MDSCR_SS
76         msr     mdscr_el1, \tmp
77         isb     // Synchronise with enable_dbg
78 9990:
79         .endm
80
81         /* call with daif masked */
82         .macro  enable_step_tsk, flgs, tmp
83         tbz     \flgs, #TIF_SINGLESTEP, 9990f
84         mrs     \tmp, mdscr_el1
85         orr     \tmp, \tmp, #DBG_MDSCR_SS
86         msr     mdscr_el1, \tmp
87 9990:
88         .endm
89
90 /*
91  * RAS Error Synchronization barrier
92  */
93         .macro  esb
94 #ifdef CONFIG_ARM64_RAS_EXTN
95         hint    #16
96 #else
97         nop
98 #endif
99         .endm
100
101 /*
102  * Value prediction barrier
103  */
104         .macro  csdb
105         hint    #20
106         .endm
107
108 /*
109  * Speculation barrier
110  */
111         .macro  sb
112 alternative_if_not ARM64_HAS_SB
113         dsb     nsh
114         isb
115 alternative_else
116         SB_BARRIER_INSN
117         nop
118 alternative_endif
119         .endm
120
121 /*
122  * NOP sequence
123  */
124         .macro  nops, num
125         .rept   \num
126         nop
127         .endr
128         .endm
129
130 /*
131  * Emit an entry into the exception table
132  */
133         .macro          _asm_extable, from, to
134         .pushsection    __ex_table, "a"
135         .align          3
136         .long           (\from - .), (\to - .)
137         .popsection
138         .endm
139
140 #define USER(l, x...)                           \
141 9999:   x;                                      \
142         _asm_extable    9999b, l
143
144 /*
145  * Register aliases.
146  */
147 lr      .req    x30             // link register
148
149 /*
150  * Vector entry
151  */
152          .macro ventry  label
153         .align  7
154         b       \label
155         .endm
156
157 /*
158  * Select code when configured for BE.
159  */
160 #ifdef CONFIG_CPU_BIG_ENDIAN
161 #define CPU_BE(code...) code
162 #else
163 #define CPU_BE(code...)
164 #endif
165
166 /*
167  * Select code when configured for LE.
168  */
169 #ifdef CONFIG_CPU_BIG_ENDIAN
170 #define CPU_LE(code...)
171 #else
172 #define CPU_LE(code...) code
173 #endif
174
175 /*
176  * Define a macro that constructs a 64-bit value by concatenating two
177  * 32-bit registers. Note that on big endian systems the order of the
178  * registers is swapped.
179  */
180 #ifndef CONFIG_CPU_BIG_ENDIAN
181         .macro  regs_to_64, rd, lbits, hbits
182 #else
183         .macro  regs_to_64, rd, hbits, lbits
184 #endif
185         orr     \rd, \lbits, \hbits, lsl #32
186         .endm
187
188 /*
189  * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
190  * <symbol> is within the range +/- 4 GB of the PC.
191  */
192         /*
193          * @dst: destination register (64 bit wide)
194          * @sym: name of the symbol
195          */
196         .macro  adr_l, dst, sym
197         adrp    \dst, \sym
198         add     \dst, \dst, :lo12:\sym
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=
209         .ifb    \tmp
210         adrp    \dst, \sym
211         ldr     \dst, [\dst, :lo12:\sym]
212         .else
213         adrp    \tmp, \sym
214         ldr     \dst, [\tmp, :lo12:\sym]
215         .endif
216         .endm
217
218         /*
219          * @src: source register (32 or 64 bit wide)
220          * @sym: name of the symbol
221          * @tmp: mandatory 64-bit scratch register to calculate the address
222          *       while <src> needs to be preserved.
223          */
224         .macro  str_l, src, sym, tmp
225         adrp    \tmp, \sym
226         str     \src, [\tmp, :lo12:\sym]
227         .endm
228
229         /*
230          * @dst: destination register
231          */
232 #if defined(__KVM_NVHE_HYPERVISOR__) || defined(__KVM_VHE_HYPERVISOR__)
233         .macro  this_cpu_offset, dst
234         mrs     \dst, tpidr_el2
235         .endm
236 #else
237         .macro  this_cpu_offset, dst
238 alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
239         mrs     \dst, tpidr_el1
240 alternative_else
241         mrs     \dst, tpidr_el2
242 alternative_endif
243         .endm
244 #endif
245
246         /*
247          * @dst: Result of per_cpu(sym, smp_processor_id()) (can be SP)
248          * @sym: The name of the per-cpu variable
249          * @tmp: scratch register
250          */
251         .macro adr_this_cpu, dst, sym, tmp
252         adrp    \tmp, \sym
253         add     \dst, \tmp, #:lo12:\sym
254         this_cpu_offset \tmp
255         add     \dst, \dst, \tmp
256         .endm
257
258         /*
259          * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id()))
260          * @sym: The name of the per-cpu variable
261          * @tmp: scratch register
262          */
263         .macro ldr_this_cpu dst, sym, tmp
264         adr_l   \dst, \sym
265         this_cpu_offset \tmp
266         ldr     \dst, [\dst, \tmp]
267         .endm
268
269 /*
270  * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
271  */
272         .macro  vma_vm_mm, rd, rn
273         ldr     \rd, [\rn, #VMA_VM_MM]
274         .endm
275
276 /*
277  * read_ctr - read CTR_EL0. If the system has mismatched register fields,
278  * provide the system wide safe value from arm64_ftr_reg_ctrel0.sys_val
279  */
280         .macro  read_ctr, reg
281 alternative_if_not ARM64_MISMATCHED_CACHE_TYPE
282         mrs     \reg, ctr_el0                   // read CTR
283         nop
284 alternative_else
285         ldr_l   \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL
286 alternative_endif
287         .endm
288
289
290 /*
291  * raw_dcache_line_size - get the minimum D-cache line size on this CPU
292  * from the CTR register.
293  */
294         .macro  raw_dcache_line_size, reg, tmp
295         mrs     \tmp, ctr_el0                   // read CTR
296         ubfm    \tmp, \tmp, #16, #19            // cache line size encoding
297         mov     \reg, #4                        // bytes per word
298         lsl     \reg, \reg, \tmp                // actual cache line size
299         .endm
300
301 /*
302  * dcache_line_size - get the safe D-cache line size across all CPUs
303  */
304         .macro  dcache_line_size, reg, tmp
305         read_ctr        \tmp
306         ubfm            \tmp, \tmp, #16, #19    // cache line size encoding
307         mov             \reg, #4                // bytes per word
308         lsl             \reg, \reg, \tmp        // actual cache line size
309         .endm
310
311 /*
312  * raw_icache_line_size - get the minimum I-cache line size on this CPU
313  * from the CTR register.
314  */
315         .macro  raw_icache_line_size, reg, tmp
316         mrs     \tmp, ctr_el0                   // read CTR
317         and     \tmp, \tmp, #0xf                // cache line size encoding
318         mov     \reg, #4                        // bytes per word
319         lsl     \reg, \reg, \tmp                // actual cache line size
320         .endm
321
322 /*
323  * icache_line_size - get the safe I-cache line size across all CPUs
324  */
325         .macro  icache_line_size, reg, tmp
326         read_ctr        \tmp
327         and             \tmp, \tmp, #0xf        // cache line size encoding
328         mov             \reg, #4                // bytes per word
329         lsl             \reg, \reg, \tmp        // actual cache line size
330         .endm
331
332 /*
333  * tcr_set_t0sz - update TCR.T0SZ so that we can load the ID map
334  */
335         .macro  tcr_set_t0sz, valreg, t0sz
336         bfi     \valreg, \t0sz, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH
337         .endm
338
339 /*
340  * tcr_set_t1sz - update TCR.T1SZ
341  */
342         .macro  tcr_set_t1sz, valreg, t1sz
343         bfi     \valreg, \t1sz, #TCR_T1SZ_OFFSET, #TCR_TxSZ_WIDTH
344         .endm
345
346 /*
347  * tcr_compute_pa_size - set TCR.(I)PS to the highest supported
348  * ID_AA64MMFR0_EL1.PARange value
349  *
350  *      tcr:            register with the TCR_ELx value to be updated
351  *      pos:            IPS or PS bitfield position
352  *      tmp{0,1}:       temporary registers
353  */
354         .macro  tcr_compute_pa_size, tcr, pos, tmp0, tmp1
355         mrs     \tmp0, ID_AA64MMFR0_EL1
356         // Narrow PARange to fit the PS field in TCR_ELx
357         ubfx    \tmp0, \tmp0, #ID_AA64MMFR0_PARANGE_SHIFT, #3
358         mov     \tmp1, #ID_AA64MMFR0_PARANGE_MAX
359         cmp     \tmp0, \tmp1
360         csel    \tmp0, \tmp1, \tmp0, hi
361         bfi     \tcr, \tmp0, \pos, #3
362         .endm
363
364 /*
365  * Macro to perform a data cache maintenance for the interval
366  * [kaddr, kaddr + size)
367  *
368  *      op:             operation passed to dc instruction
369  *      domain:         domain used in dsb instruciton
370  *      kaddr:          starting virtual address of the region
371  *      size:           size of the region
372  *      Corrupts:       kaddr, size, tmp1, tmp2
373  */
374         .macro __dcache_op_workaround_clean_cache, op, kaddr
375 alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE
376         dc      \op, \kaddr
377 alternative_else
378         dc      civac, \kaddr
379 alternative_endif
380         .endm
381
382         .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2
383         dcache_line_size \tmp1, \tmp2
384         add     \size, \kaddr, \size
385         sub     \tmp2, \tmp1, #1
386         bic     \kaddr, \kaddr, \tmp2
387 9998:
388         .ifc    \op, cvau
389         __dcache_op_workaround_clean_cache \op, \kaddr
390         .else
391         .ifc    \op, cvac
392         __dcache_op_workaround_clean_cache \op, \kaddr
393         .else
394         .ifc    \op, cvap
395         sys     3, c7, c12, 1, \kaddr   // dc cvap
396         .else
397         .ifc    \op, cvadp
398         sys     3, c7, c13, 1, \kaddr   // dc cvadp
399         .else
400         dc      \op, \kaddr
401         .endif
402         .endif
403         .endif
404         .endif
405         add     \kaddr, \kaddr, \tmp1
406         cmp     \kaddr, \size
407         b.lo    9998b
408         dsb     \domain
409         .endm
410
411 /*
412  * Macro to perform an instruction cache maintenance for the interval
413  * [start, end)
414  *
415  *      start, end:     virtual addresses describing the region
416  *      label:          A label to branch to on user fault.
417  *      Corrupts:       tmp1, tmp2
418  */
419         .macro invalidate_icache_by_line start, end, tmp1, tmp2, label
420         icache_line_size \tmp1, \tmp2
421         sub     \tmp2, \tmp1, #1
422         bic     \tmp2, \start, \tmp2
423 9997:
424 USER(\label, ic ivau, \tmp2)                    // invalidate I line PoU
425         add     \tmp2, \tmp2, \tmp1
426         cmp     \tmp2, \end
427         b.lo    9997b
428         dsb     ish
429         isb
430         .endm
431
432 /*
433  * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present
434  */
435         .macro  reset_pmuserenr_el0, tmpreg
436         mrs     \tmpreg, id_aa64dfr0_el1
437         sbfx    \tmpreg, \tmpreg, #ID_AA64DFR0_PMUVER_SHIFT, #4
438         cmp     \tmpreg, #1                     // Skip if no PMU present
439         b.lt    9000f
440         msr     pmuserenr_el0, xzr              // Disable PMU access from EL0
441 9000:
442         .endm
443
444 /*
445  * reset_amuserenr_el0 - reset AMUSERENR_EL0 if AMUv1 present
446  */
447         .macro  reset_amuserenr_el0, tmpreg
448         mrs     \tmpreg, id_aa64pfr0_el1        // Check ID_AA64PFR0_EL1
449         ubfx    \tmpreg, \tmpreg, #ID_AA64PFR0_AMU_SHIFT, #4
450         cbz     \tmpreg, .Lskip_\@              // Skip if no AMU present
451         msr_s   SYS_AMUSERENR_EL0, xzr          // Disable AMU access from EL0
452 .Lskip_\@:
453         .endm
454 /*
455  * copy_page - copy src to dest using temp registers t1-t8
456  */
457         .macro copy_page dest:req src:req t1:req t2:req t3:req t4:req t5:req t6:req t7:req t8:req
458 9998:   ldp     \t1, \t2, [\src]
459         ldp     \t3, \t4, [\src, #16]
460         ldp     \t5, \t6, [\src, #32]
461         ldp     \t7, \t8, [\src, #48]
462         add     \src, \src, #64
463         stnp    \t1, \t2, [\dest]
464         stnp    \t3, \t4, [\dest, #16]
465         stnp    \t5, \t6, [\dest, #32]
466         stnp    \t7, \t8, [\dest, #48]
467         add     \dest, \dest, #64
468         tst     \src, #(PAGE_SIZE - 1)
469         b.ne    9998b
470         .endm
471
472 /*
473  * Annotate a function as being unsuitable for kprobes.
474  */
475 #ifdef CONFIG_KPROBES
476 #define NOKPROBE(x)                             \
477         .pushsection "_kprobe_blacklist", "aw"; \
478         .quad   x;                              \
479         .popsection;
480 #else
481 #define NOKPROBE(x)
482 #endif
483
484 #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
485 #define EXPORT_SYMBOL_NOKASAN(name)
486 #else
487 #define EXPORT_SYMBOL_NOKASAN(name)     EXPORT_SYMBOL(name)
488 #endif
489
490         /*
491          * Emit a 64-bit absolute little endian symbol reference in a way that
492          * ensures that it will be resolved at build time, even when building a
493          * PIE binary. This requires cooperation from the linker script, which
494          * must emit the lo32/hi32 halves individually.
495          */
496         .macro  le64sym, sym
497         .long   \sym\()_lo32
498         .long   \sym\()_hi32
499         .endm
500
501         /*
502          * mov_q - move an immediate constant into a 64-bit register using
503          *         between 2 and 4 movz/movk instructions (depending on the
504          *         magnitude and sign of the operand)
505          */
506         .macro  mov_q, reg, val
507         .if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff)
508         movz    \reg, :abs_g1_s:\val
509         .else
510         .if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff)
511         movz    \reg, :abs_g2_s:\val
512         .else
513         movz    \reg, :abs_g3:\val
514         movk    \reg, :abs_g2_nc:\val
515         .endif
516         movk    \reg, :abs_g1_nc:\val
517         .endif
518         movk    \reg, :abs_g0_nc:\val
519         .endm
520
521 /*
522  * Return the current task_struct.
523  */
524         .macro  get_current_task, rd
525         mrs     \rd, sp_el0
526         .endm
527
528 /*
529  * Offset ttbr1 to allow for 48-bit kernel VAs set with 52-bit PTRS_PER_PGD.
530  * orr is used as it can cover the immediate value (and is idempotent).
531  * In future this may be nop'ed out when dealing with 52-bit kernel VAs.
532  *      ttbr: Value of ttbr to set, modified.
533  */
534         .macro  offset_ttbr1, ttbr, tmp
535 #ifdef CONFIG_ARM64_VA_BITS_52
536         mrs_s   \tmp, SYS_ID_AA64MMFR2_EL1
537         and     \tmp, \tmp, #(0xf << ID_AA64MMFR2_LVA_SHIFT)
538         cbnz    \tmp, .Lskipoffs_\@
539         orr     \ttbr, \ttbr, #TTBR1_BADDR_4852_OFFSET
540 .Lskipoffs_\@ :
541 #endif
542         .endm
543
544 /*
545  * Perform the reverse of offset_ttbr1.
546  * bic is used as it can cover the immediate value and, in future, won't need
547  * to be nop'ed out when dealing with 52-bit kernel VAs.
548  */
549         .macro  restore_ttbr1, ttbr
550 #ifdef CONFIG_ARM64_VA_BITS_52
551         bic     \ttbr, \ttbr, #TTBR1_BADDR_4852_OFFSET
552 #endif
553         .endm
554
555 /*
556  * Arrange a physical address in a TTBR register, taking care of 52-bit
557  * addresses.
558  *
559  *      phys:   physical address, preserved
560  *      ttbr:   returns the TTBR value
561  */
562         .macro  phys_to_ttbr, ttbr, phys
563 #ifdef CONFIG_ARM64_PA_BITS_52
564         orr     \ttbr, \phys, \phys, lsr #46
565         and     \ttbr, \ttbr, #TTBR_BADDR_MASK_52
566 #else
567         mov     \ttbr, \phys
568 #endif
569         .endm
570
571         .macro  phys_to_pte, pte, phys
572 #ifdef CONFIG_ARM64_PA_BITS_52
573         /*
574          * We assume \phys is 64K aligned and this is guaranteed by only
575          * supporting this configuration with 64K pages.
576          */
577         orr     \pte, \phys, \phys, lsr #36
578         and     \pte, \pte, #PTE_ADDR_MASK
579 #else
580         mov     \pte, \phys
581 #endif
582         .endm
583
584         .macro  pte_to_phys, phys, pte
585 #ifdef CONFIG_ARM64_PA_BITS_52
586         ubfiz   \phys, \pte, #(48 - 16 - 12), #16
587         bfxil   \phys, \pte, #16, #32
588         lsl     \phys, \phys, #16
589 #else
590         and     \phys, \pte, #PTE_ADDR_MASK
591 #endif
592         .endm
593
594 /*
595  * tcr_clear_errata_bits - Clear TCR bits that trigger an errata on this CPU.
596  */
597         .macro  tcr_clear_errata_bits, tcr, tmp1, tmp2
598 #ifdef CONFIG_FUJITSU_ERRATUM_010001
599         mrs     \tmp1, midr_el1
600
601         mov_q   \tmp2, MIDR_FUJITSU_ERRATUM_010001_MASK
602         and     \tmp1, \tmp1, \tmp2
603         mov_q   \tmp2, MIDR_FUJITSU_ERRATUM_010001
604         cmp     \tmp1, \tmp2
605         b.ne    10f
606
607         mov_q   \tmp2, TCR_CLEAR_FUJITSU_ERRATUM_010001
608         bic     \tcr, \tcr, \tmp2
609 10:
610 #endif /* CONFIG_FUJITSU_ERRATUM_010001 */
611         .endm
612
613 /**
614  * Errata workaround prior to disable MMU. Insert an ISB immediately prior
615  * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0.
616  */
617         .macro pre_disable_mmu_workaround
618 #ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041
619         isb
620 #endif
621         .endm
622
623         /*
624          * frame_push - Push @regcount callee saved registers to the stack,
625          *              starting at x19, as well as x29/x30, and set x29 to
626          *              the new value of sp. Add @extra bytes of stack space
627          *              for locals.
628          */
629         .macro          frame_push, regcount:req, extra
630         __frame         st, \regcount, \extra
631         .endm
632
633         /*
634          * frame_pop  - Pop the callee saved registers from the stack that were
635          *              pushed in the most recent call to frame_push, as well
636          *              as x29/x30 and any extra stack space that may have been
637          *              allocated.
638          */
639         .macro          frame_pop
640         __frame         ld
641         .endm
642
643         .macro          __frame_regs, reg1, reg2, op, num
644         .if             .Lframe_regcount == \num
645         \op\()r         \reg1, [sp, #(\num + 1) * 8]
646         .elseif         .Lframe_regcount > \num
647         \op\()p         \reg1, \reg2, [sp, #(\num + 1) * 8]
648         .endif
649         .endm
650
651         .macro          __frame, op, regcount, extra=0
652         .ifc            \op, st
653         .if             (\regcount) < 0 || (\regcount) > 10
654         .error          "regcount should be in the range [0 ... 10]"
655         .endif
656         .if             ((\extra) % 16) != 0
657         .error          "extra should be a multiple of 16 bytes"
658         .endif
659         .ifdef          .Lframe_regcount
660         .if             .Lframe_regcount != -1
661         .error          "frame_push/frame_pop may not be nested"
662         .endif
663         .endif
664         .set            .Lframe_regcount, \regcount
665         .set            .Lframe_extra, \extra
666         .set            .Lframe_local_offset, ((\regcount + 3) / 2) * 16
667         stp             x29, x30, [sp, #-.Lframe_local_offset - .Lframe_extra]!
668         mov             x29, sp
669         .endif
670
671         __frame_regs    x19, x20, \op, 1
672         __frame_regs    x21, x22, \op, 3
673         __frame_regs    x23, x24, \op, 5
674         __frame_regs    x25, x26, \op, 7
675         __frame_regs    x27, x28, \op, 9
676
677         .ifc            \op, ld
678         .if             .Lframe_regcount == -1
679         .error          "frame_push/frame_pop may not be nested"
680         .endif
681         ldp             x29, x30, [sp], #.Lframe_local_offset + .Lframe_extra
682         .set            .Lframe_regcount, -1
683         .endif
684         .endm
685
686 /*
687  * Set SCTLR_EL1 to the passed value, and invalidate the local icache
688  * in the process. This is called when setting the MMU on.
689  */
690 .macro set_sctlr_el1, reg
691         msr     sctlr_el1, \reg
692         isb
693         /*
694          * Invalidate the local I-cache so that any instructions fetched
695          * speculatively from the PoC are discarded, since they may have
696          * been dynamically patched at the PoU.
697          */
698         ic      iallu
699         dsb     nsh
700         isb
701 .endm
702
703         /*
704          * Check whether preempt-disabled code should yield as soon as it
705          * is able. This is the case if re-enabling preemption a single
706          * time results in a preempt count of zero, and the TIF_NEED_RESCHED
707          * flag is set. (Note that the latter is stored negated in the
708          * top word of the thread_info::preempt_count field)
709          */
710         .macro          cond_yield, lbl:req, tmp:req
711 #ifdef CONFIG_PREEMPTION
712         get_current_task \tmp
713         ldr             \tmp, [\tmp, #TSK_TI_PREEMPT]
714         sub             \tmp, \tmp, #PREEMPT_DISABLE_OFFSET
715         cbz             \tmp, \lbl
716 #endif
717         .endm
718
719 /*
720  * This macro emits a program property note section identifying
721  * architecture features which require special handling, mainly for
722  * use in assembly files included in the VDSO.
723  */
724
725 #define NT_GNU_PROPERTY_TYPE_0  5
726 #define GNU_PROPERTY_AARCH64_FEATURE_1_AND      0xc0000000
727
728 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI      (1U << 0)
729 #define GNU_PROPERTY_AARCH64_FEATURE_1_PAC      (1U << 1)
730
731 #ifdef CONFIG_ARM64_BTI_KERNEL
732 #define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT          \
733                 ((GNU_PROPERTY_AARCH64_FEATURE_1_BTI |  \
734                   GNU_PROPERTY_AARCH64_FEATURE_1_PAC))
735 #endif
736
737 #ifdef GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT
738 .macro emit_aarch64_feature_1_and, feat=GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT
739         .pushsection .note.gnu.property, "a"
740         .align  3
741         .long   2f - 1f
742         .long   6f - 3f
743         .long   NT_GNU_PROPERTY_TYPE_0
744 1:      .string "GNU"
745 2:
746         .align  3
747 3:      .long   GNU_PROPERTY_AARCH64_FEATURE_1_AND
748         .long   5f - 4f
749 4:
750         /*
751          * This is described with an array of char in the Linux API
752          * spec but the text and all other usage (including binutils,
753          * clang and GCC) treat this as a 32 bit value so no swizzling
754          * is required for big endian.
755          */
756         .long   \feat
757 5:
758         .align  3
759 6:
760         .popsection
761 .endm
762
763 #else
764 .macro emit_aarch64_feature_1_and, feat=0
765 .endm
766
767 #endif /* GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT */
768
769 #endif  /* __ASM_ASSEMBLER_H */