/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S3*4* Copyright (C) 1996-2000 Russell King5* Copyright (C) 2012 ARM Ltd.6*/7#ifndef __ASSEMBLY__8#error "Only include this from assembly code"9#endif1011#ifndef __ASM_ASSEMBLER_H12#define __ASM_ASSEMBLER_H1314#include <linux/export.h>1516#include <asm/alternative.h>17#include <asm/asm-bug.h>18#include <asm/asm-extable.h>19#include <asm/asm-offsets.h>20#include <asm/cpufeature.h>21#include <asm/cputype.h>22#include <asm/debug-monitors.h>23#include <asm/page.h>24#include <asm/pgtable-hwdef.h>25#include <asm/ptrace.h>26#include <asm/thread_info.h>2728/*29* Provide a wxN alias for each wN register so what we can paste a xN30* reference after a 'w' to obtain the 32-bit version.31*/32.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,3033wx\n .req w\n34.endr3536.macro disable_daif37msr daifset, #0xf38.endm3940/*41* Save/restore interrupts.42*/43.macro save_and_disable_daif, flags44mrs \flags, daif45msr daifset, #0xf46.endm4748.macro save_and_disable_irq, flags49mrs \flags, daif50msr daifset, #351.endm5253.macro restore_irq, flags54msr daif, \flags55.endm5657.macro disable_step_tsk, flgs, tmp58tbz \flgs, #TIF_SINGLESTEP, 9990f59mrs \tmp, mdscr_el160bic \tmp, \tmp, #MDSCR_EL1_SS61msr mdscr_el1, \tmp62isb // Take effect before a subsequent clear of DAIF.D639990:64.endm6566/* call with daif masked */67.macro enable_step_tsk, flgs, tmp68tbz \flgs, #TIF_SINGLESTEP, 9990f69mrs \tmp, mdscr_el170orr \tmp, \tmp, #MDSCR_EL1_SS71msr mdscr_el1, \tmp729990:73.endm7475/*76* RAS Error Synchronization barrier77*/78.macro esb79#ifdef CONFIG_ARM64_RAS_EXTN80hint #1681#else82nop83#endif84.endm8586/*87* Value prediction barrier88*/89.macro csdb90hint #2091.endm9293/*94* Clear Branch History instruction95*/96.macro clearbhb97hint #2298.endm99100/*101* Speculation barrier102*/103.macro sb104alternative_if_not ARM64_HAS_SB105dsb nsh106isb107alternative_else108SB_BARRIER_INSN109nop110alternative_endif111.endm112113/*114* NOP sequence115*/116.macro nops, num117.rept \num118nop119.endr120.endm121122/*123* Register aliases.124*/125lr .req x30 // link register126127/*128* Vector entry129*/130.macro ventry label131.align 7132b \label133.endm134135/*136* Select code when configured for BE.137*/138#ifdef CONFIG_CPU_BIG_ENDIAN139#define CPU_BE(code...) code140#else141#define CPU_BE(code...)142#endif143144/*145* Select code when configured for LE.146*/147#ifdef CONFIG_CPU_BIG_ENDIAN148#define CPU_LE(code...)149#else150#define CPU_LE(code...) code151#endif152153/*154* Define a macro that constructs a 64-bit value by concatenating two155* 32-bit registers. Note that on big endian systems the order of the156* registers is swapped.157*/158#ifndef CONFIG_CPU_BIG_ENDIAN159.macro regs_to_64, rd, lbits, hbits160#else161.macro regs_to_64, rd, hbits, lbits162#endif163orr \rd, \lbits, \hbits, lsl #32164.endm165166/*167* Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where168* <symbol> is within the range +/- 4 GB of the PC.169*/170/*171* @dst: destination register (64 bit wide)172* @sym: name of the symbol173*/174.macro adr_l, dst, sym175adrp \dst, \sym176add \dst, \dst, :lo12:\sym177.endm178179/*180* @dst: destination register (32 or 64 bit wide)181* @sym: name of the symbol182* @tmp: optional 64-bit scratch register to be used if <dst> is a183* 32-bit wide register, in which case it cannot be used to hold184* the address185*/186.macro ldr_l, dst, sym, tmp=187.ifb \tmp188adrp \dst, \sym189ldr \dst, [\dst, :lo12:\sym]190.else191adrp \tmp, \sym192ldr \dst, [\tmp, :lo12:\sym]193.endif194.endm195196/*197* @src: source register (32 or 64 bit wide)198* @sym: name of the symbol199* @tmp: mandatory 64-bit scratch register to calculate the address200* while <src> needs to be preserved.201*/202.macro str_l, src, sym, tmp203adrp \tmp, \sym204str \src, [\tmp, :lo12:\sym]205.endm206207/*208* @dst: destination register209*/210#if defined(__KVM_NVHE_HYPERVISOR__) || defined(__KVM_VHE_HYPERVISOR__)211.macro get_this_cpu_offset, dst212mrs \dst, tpidr_el2213.endm214#else215.macro get_this_cpu_offset, dst216alternative_if_not ARM64_HAS_VIRT_HOST_EXTN217mrs \dst, tpidr_el1218alternative_else219mrs \dst, tpidr_el2220alternative_endif221.endm222223.macro set_this_cpu_offset, src224alternative_if_not ARM64_HAS_VIRT_HOST_EXTN225msr tpidr_el1, \src226alternative_else227msr tpidr_el2, \src228alternative_endif229.endm230#endif231232/*233* @dst: Result of per_cpu(sym, smp_processor_id()) (can be SP)234* @sym: The name of the per-cpu variable235* @tmp: scratch register236*/237.macro adr_this_cpu, dst, sym, tmp238adrp \tmp, \sym239add \dst, \tmp, #:lo12:\sym240get_this_cpu_offset \tmp241add \dst, \dst, \tmp242.endm243244/*245* @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id()))246* @sym: The name of the per-cpu variable247* @tmp: scratch register248*/249.macro ldr_this_cpu dst, sym, tmp250adr_l \dst, \sym251get_this_cpu_offset \tmp252ldr \dst, [\dst, \tmp]253.endm254255/*256* read_ctr - read CTR_EL0. If the system has mismatched register fields,257* provide the system wide safe value from arm64_ftr_reg_ctrel0.sys_val258*/259.macro read_ctr, reg260#ifndef __KVM_NVHE_HYPERVISOR__261alternative_if_not ARM64_MISMATCHED_CACHE_TYPE262mrs \reg, ctr_el0 // read CTR263nop264alternative_else265ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL266alternative_endif267#else268alternative_if_not ARM64_KVM_PROTECTED_MODE269ASM_BUG()270alternative_else_nop_endif271alternative_cb ARM64_ALWAYS_SYSTEM, kvm_compute_final_ctr_el0272movz \reg, #0273movk \reg, #0, lsl #16274movk \reg, #0, lsl #32275movk \reg, #0, lsl #48276alternative_cb_end277#endif278.endm279280281/*282* raw_dcache_line_size - get the minimum D-cache line size on this CPU283* from the CTR register.284*/285.macro raw_dcache_line_size, reg, tmp286mrs \tmp, ctr_el0 // read CTR287ubfm \tmp, \tmp, #16, #19 // cache line size encoding288mov \reg, #4 // bytes per word289lsl \reg, \reg, \tmp // actual cache line size290.endm291292/*293* dcache_line_size - get the safe D-cache line size across all CPUs294*/295.macro dcache_line_size, reg, tmp296read_ctr \tmp297ubfm \tmp, \tmp, #16, #19 // cache line size encoding298mov \reg, #4 // bytes per word299lsl \reg, \reg, \tmp // actual cache line size300.endm301302/*303* raw_icache_line_size - get the minimum I-cache line size on this CPU304* from the CTR register.305*/306.macro raw_icache_line_size, reg, tmp307mrs \tmp, ctr_el0 // read CTR308and \tmp, \tmp, #0xf // cache line size encoding309mov \reg, #4 // bytes per word310lsl \reg, \reg, \tmp // actual cache line size311.endm312313/*314* icache_line_size - get the safe I-cache line size across all CPUs315*/316.macro icache_line_size, reg, tmp317read_ctr \tmp318and \tmp, \tmp, #0xf // cache line size encoding319mov \reg, #4 // bytes per word320lsl \reg, \reg, \tmp // actual cache line size321.endm322323/*324* tcr_set_t0sz - update TCR.T0SZ so that we can load the ID map325*/326.macro tcr_set_t0sz, valreg, t0sz327bfi \valreg, \t0sz, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH328.endm329330/*331* tcr_set_t1sz - update TCR.T1SZ332*/333.macro tcr_set_t1sz, valreg, t1sz334bfi \valreg, \t1sz, #TCR_T1SZ_OFFSET, #TCR_TxSZ_WIDTH335.endm336337/*338* tcr_compute_pa_size - set TCR.(I)PS to the highest supported339* ID_AA64MMFR0_EL1.PARange value340*341* tcr: register with the TCR_ELx value to be updated342* pos: IPS or PS bitfield position343* tmp{0,1}: temporary registers344*/345.macro tcr_compute_pa_size, tcr, pos, tmp0, tmp1346mrs \tmp0, ID_AA64MMFR0_EL1347// Narrow PARange to fit the PS field in TCR_ELx348ubfx \tmp0, \tmp0, #ID_AA64MMFR0_EL1_PARANGE_SHIFT, #3349mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_MAX350#ifdef CONFIG_ARM64_LPA2351alternative_if_not ARM64_HAS_VA52352mov \tmp1, #ID_AA64MMFR0_EL1_PARANGE_48353alternative_else_nop_endif354#endif355cmp \tmp0, \tmp1356csel \tmp0, \tmp1, \tmp0, hi357bfi \tcr, \tmp0, \pos, #3358.endm359360.macro __dcache_op_workaround_clean_cache, op, addr361alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE362dc \op, \addr363alternative_else364dc civac, \addr365alternative_endif366.endm367368/*369* Macro to perform a data cache maintenance for the interval370* [start, end) with dcache line size explicitly provided.371*372* op: operation passed to dc instruction373* domain: domain used in dsb instruciton374* start: starting virtual address of the region375* end: end virtual address of the region376* linesz: dcache line size377* fixup: optional label to branch to on user fault378* Corrupts: start, end, tmp379*/380.macro dcache_by_myline_op op, domain, start, end, linesz, tmp, fixup381sub \tmp, \linesz, #1382bic \start, \start, \tmp383.Ldcache_op\@:384.ifc \op, cvau385__dcache_op_workaround_clean_cache \op, \start386.else387.ifc \op, cvac388__dcache_op_workaround_clean_cache \op, \start389.else390.ifc \op, cvap391sys 3, c7, c12, 1, \start // dc cvap392.else393.ifc \op, cvadp394sys 3, c7, c13, 1, \start // dc cvadp395.else396dc \op, \start397.endif398.endif399.endif400.endif401add \start, \start, \linesz402cmp \start, \end403b.lo .Ldcache_op\@404dsb \domain405406_cond_uaccess_extable .Ldcache_op\@, \fixup407.endm408409/*410* Macro to perform a data cache maintenance for the interval411* [start, end)412*413* op: operation passed to dc instruction414* domain: domain used in dsb instruciton415* start: starting virtual address of the region416* end: end virtual address of the region417* fixup: optional label to branch to on user fault418* Corrupts: start, end, tmp1, tmp2419*/420.macro dcache_by_line_op op, domain, start, end, tmp1, tmp2, fixup421dcache_line_size \tmp1, \tmp2422dcache_by_myline_op \op, \domain, \start, \end, \tmp1, \tmp2, \fixup423.endm424425/*426* Macro to perform an instruction cache maintenance for the interval427* [start, end)428*429* start, end: virtual addresses describing the region430* fixup: optional label to branch to on user fault431* Corrupts: tmp1, tmp2432*/433.macro invalidate_icache_by_line start, end, tmp1, tmp2, fixup434icache_line_size \tmp1, \tmp2435sub \tmp2, \tmp1, #1436bic \tmp2, \start, \tmp2437.Licache_op\@:438ic ivau, \tmp2 // invalidate I line PoU439add \tmp2, \tmp2, \tmp1440cmp \tmp2, \end441b.lo .Licache_op\@442dsb ish443isb444445_cond_uaccess_extable .Licache_op\@, \fixup446.endm447448/*449* load_ttbr1 - install @pgtbl as a TTBR1 page table450* pgtbl preserved451* tmp1/tmp2 clobbered, either may overlap with pgtbl452*/453.macro load_ttbr1, pgtbl, tmp1, tmp2454phys_to_ttbr \tmp1, \pgtbl455offset_ttbr1 \tmp1, \tmp2456msr ttbr1_el1, \tmp1457isb458.endm459460/*461* To prevent the possibility of old and new partial table walks being visible462* in the tlb, switch the ttbr to a zero page when we invalidate the old463* records. D4.7.1 'General TLB maintenance requirements' in ARM DDI 0487A.i464* Even switching to our copied tables will cause a changed output address at465* each stage of the walk.466*/467.macro break_before_make_ttbr_switch zero_page, page_table, tmp, tmp2468phys_to_ttbr \tmp, \zero_page469msr ttbr1_el1, \tmp470isb471tlbi vmalle1472dsb nsh473load_ttbr1 \page_table, \tmp, \tmp2474.endm475476/*477* reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present478*/479.macro reset_pmuserenr_el0, tmpreg480mrs \tmpreg, id_aa64dfr0_el1481ubfx \tmpreg, \tmpreg, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4482cmp \tmpreg, #ID_AA64DFR0_EL1_PMUVer_NI483ccmp \tmpreg, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF, #4, ne484b.eq 9000f // Skip if no PMU present or IMP_DEF485msr pmuserenr_el0, xzr // Disable PMU access from EL04869000:487.endm488489/*490* reset_amuserenr_el0 - reset AMUSERENR_EL0 if AMUv1 present491*/492.macro reset_amuserenr_el0, tmpreg493mrs \tmpreg, id_aa64pfr0_el1 // Check ID_AA64PFR0_EL1494ubfx \tmpreg, \tmpreg, #ID_AA64PFR0_EL1_AMU_SHIFT, #4495cbz \tmpreg, .Lskip_\@ // Skip if no AMU present496msr_s SYS_AMUSERENR_EL0, xzr // Disable AMU access from EL0497.Lskip_\@:498.endm499/*500* copy_page - copy src to dest using temp registers t1-t8501*/502.macro copy_page dest:req src:req t1:req t2:req t3:req t4:req t5:req t6:req t7:req t8:req5039998: ldp \t1, \t2, [\src]504ldp \t3, \t4, [\src, #16]505ldp \t5, \t6, [\src, #32]506ldp \t7, \t8, [\src, #48]507add \src, \src, #64508stnp \t1, \t2, [\dest]509stnp \t3, \t4, [\dest, #16]510stnp \t5, \t6, [\dest, #32]511stnp \t7, \t8, [\dest, #48]512add \dest, \dest, #64513tst \src, #(PAGE_SIZE - 1)514b.ne 9998b515.endm516517/*518* Annotate a function as being unsuitable for kprobes.519*/520#ifdef CONFIG_KPROBES521#define NOKPROBE(x) \522.pushsection "_kprobe_blacklist", "aw"; \523.quad x; \524.popsection;525#else526#define NOKPROBE(x)527#endif528529#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)530#define EXPORT_SYMBOL_NOKASAN(name)531#else532#define EXPORT_SYMBOL_NOKASAN(name) EXPORT_SYMBOL(name)533#endif534535/*536* Emit a 64-bit absolute little endian symbol reference in a way that537* ensures that it will be resolved at build time, even when building a538* PIE binary. This requires cooperation from the linker script, which539* must emit the lo32/hi32 halves individually.540*/541.macro le64sym, sym542.long \sym\()_lo32543.long \sym\()_hi32544.endm545546/*547* mov_q - move an immediate constant into a 64-bit register using548* between 2 and 4 movz/movk instructions (depending on the549* magnitude and sign of the operand)550*/551.macro mov_q, reg, val552.if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff)553movz \reg, :abs_g1_s:\val554.else555.if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff)556movz \reg, :abs_g2_s:\val557.else558movz \reg, :abs_g3:\val559movk \reg, :abs_g2_nc:\val560.endif561movk \reg, :abs_g1_nc:\val562.endif563movk \reg, :abs_g0_nc:\val564.endm565566/*567* Return the current task_struct.568*/569.macro get_current_task, rd570mrs \rd, sp_el0571.endm572573/*574* If the kernel is built for 52-bit virtual addressing but the hardware only575* supports 48 bits, we cannot program the pgdir address into TTBR1 directly,576* but we have to add an offset so that the TTBR1 address corresponds with the577* pgdir entry that covers the lowest 48-bit addressable VA.578*579* Note that this trick is only used for LVA/64k pages - LPA2/4k pages uses an580* additional paging level, and on LPA2/16k pages, we would end up with a root581* level table with only 2 entries, which is suboptimal in terms of TLB582* utilization, so there we fall back to 47 bits of translation if LPA2 is not583* supported.584*585* orr is used as it can cover the immediate value (and is idempotent).586* ttbr: Value of ttbr to set, modified.587*/588.macro offset_ttbr1, ttbr, tmp589#if defined(CONFIG_ARM64_VA_BITS_52) && !defined(CONFIG_ARM64_LPA2)590mrs \tmp, tcr_el1591and \tmp, \tmp, #TCR_T1SZ_MASK592cmp \tmp, #TCR_T1SZ(VA_BITS_MIN)593orr \tmp, \ttbr, #TTBR1_BADDR_4852_OFFSET594csel \ttbr, \tmp, \ttbr, eq595#endif596.endm597598/*599* Arrange a physical address in a TTBR register, taking care of 52-bit600* addresses.601*602* phys: physical address, preserved603* ttbr: returns the TTBR value604*/605.macro phys_to_ttbr, ttbr, phys606#ifdef CONFIG_ARM64_PA_BITS_52607orr \ttbr, \phys, \phys, lsr #46608and \ttbr, \ttbr, #TTBR_BADDR_MASK_52609#else610mov \ttbr, \phys611#endif612.endm613614.macro phys_to_pte, pte, phys615#ifdef CONFIG_ARM64_PA_BITS_52616orr \pte, \phys, \phys, lsr #PTE_ADDR_HIGH_SHIFT617and \pte, \pte, #PHYS_TO_PTE_ADDR_MASK618#else619mov \pte, \phys620#endif621.endm622623/*624* tcr_clear_errata_bits - Clear TCR bits that trigger an errata on this CPU.625*/626.macro tcr_clear_errata_bits, tcr, tmp1, tmp2627#ifdef CONFIG_FUJITSU_ERRATUM_010001628mrs \tmp1, midr_el1629630mov_q \tmp2, MIDR_FUJITSU_ERRATUM_010001_MASK631and \tmp1, \tmp1, \tmp2632mov_q \tmp2, MIDR_FUJITSU_ERRATUM_010001633cmp \tmp1, \tmp2634b.ne 10f635636mov_q \tmp2, TCR_CLEAR_FUJITSU_ERRATUM_010001637bic \tcr, \tcr, \tmp263810:639#endif /* CONFIG_FUJITSU_ERRATUM_010001 */640.endm641642/**643* Errata workaround prior to disable MMU. Insert an ISB immediately prior644* to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0.645*/646.macro pre_disable_mmu_workaround647#ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041648isb649#endif650.endm651652/*653* frame_push - Push @regcount callee saved registers to the stack,654* starting at x19, as well as x29/x30, and set x29 to655* the new value of sp. Add @extra bytes of stack space656* for locals.657*/658.macro frame_push, regcount:req, extra659__frame st, \regcount, \extra660.endm661662/*663* frame_pop - Pop the callee saved registers from the stack that were664* pushed in the most recent call to frame_push, as well665* as x29/x30 and any extra stack space that may have been666* allocated.667*/668.macro frame_pop669__frame ld670.endm671672.macro __frame_regs, reg1, reg2, op, num673.if .Lframe_regcount == \num674\op\()r \reg1, [sp, #(\num + 1) * 8]675.elseif .Lframe_regcount > \num676\op\()p \reg1, \reg2, [sp, #(\num + 1) * 8]677.endif678.endm679680.macro __frame, op, regcount, extra=0681.ifc \op, st682.if (\regcount) < 0 || (\regcount) > 10683.error "regcount should be in the range [0 ... 10]"684.endif685.if ((\extra) % 16) != 0686.error "extra should be a multiple of 16 bytes"687.endif688.ifdef .Lframe_regcount689.if .Lframe_regcount != -1690.error "frame_push/frame_pop may not be nested"691.endif692.endif693.set .Lframe_regcount, \regcount694.set .Lframe_extra, \extra695.set .Lframe_local_offset, ((\regcount + 3) / 2) * 16696stp x29, x30, [sp, #-.Lframe_local_offset - .Lframe_extra]!697mov x29, sp698.endif699700__frame_regs x19, x20, \op, 1701__frame_regs x21, x22, \op, 3702__frame_regs x23, x24, \op, 5703__frame_regs x25, x26, \op, 7704__frame_regs x27, x28, \op, 9705706.ifc \op, ld707.if .Lframe_regcount == -1708.error "frame_push/frame_pop may not be nested"709.endif710ldp x29, x30, [sp], #.Lframe_local_offset + .Lframe_extra711.set .Lframe_regcount, -1712.endif713.endm714715/*716* Set SCTLR_ELx to the @reg value, and invalidate the local icache717* in the process. This is called when setting the MMU on.718*/719.macro set_sctlr, sreg, reg720msr \sreg, \reg721isb722/*723* Invalidate the local I-cache so that any instructions fetched724* speculatively from the PoC are discarded, since they may have725* been dynamically patched at the PoU.726*/727ic iallu728dsb nsh729isb730.endm731732.macro set_sctlr_el1, reg733set_sctlr sctlr_el1, \reg734.endm735736.macro set_sctlr_el2, reg737set_sctlr sctlr_el2, \reg738.endm739740/*741* Check whether asm code should yield as soon as it is able. This is742* the case if we are currently running in task context, and the743* TIF_NEED_RESCHED flag is set. (Note that the TIF_NEED_RESCHED flag744* is stored negated in the top word of the thread_info::preempt_count745* field)746*/747.macro cond_yield, lbl:req, tmp:req, tmp2748#ifdef CONFIG_PREEMPT_VOLUNTARY749get_current_task \tmp750ldr \tmp, [\tmp, #TSK_TI_PREEMPT]751/*752* If we are serving a softirq, there is no point in yielding: the753* softirq will not be preempted no matter what we do, so we should754* run to completion as quickly as we can. The preempt_count field will755* have BIT(SOFTIRQ_SHIFT) set in this case, so the zero check will756* catch this case too.757*/758cbz \tmp, \lbl759#endif760.endm761762/*763* Branch Target Identifier (BTI)764*/765.macro bti, targets766.equ .L__bti_targets_c, 34767.equ .L__bti_targets_j, 36768.equ .L__bti_targets_jc,38769hint #.L__bti_targets_\targets770.endm771772/*773* This macro emits a program property note section identifying774* architecture features which require special handling, mainly for775* use in assembly files included in the VDSO.776*/777778#define NT_GNU_PROPERTY_TYPE_0 5779#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000780781#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)782#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)783784#ifdef CONFIG_ARM64_BTI_KERNEL785#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \786((GNU_PROPERTY_AARCH64_FEATURE_1_BTI | \787GNU_PROPERTY_AARCH64_FEATURE_1_PAC))788#endif789790#ifdef GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT791.macro emit_aarch64_feature_1_and, feat=GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT792.pushsection .note.gnu.property, "a"793.align 3794.long 2f - 1f795.long 6f - 3f796.long NT_GNU_PROPERTY_TYPE_07971: .string "GNU"7982:799.align 38003: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND801.long 5f - 4f8024:803/*804* This is described with an array of char in the Linux API805* spec but the text and all other usage (including binutils,806* clang and GCC) treat this as a 32 bit value so no swizzling807* is required for big endian.808*/809.long \feat8105:811.align 38126:813.popsection814.endm815816#else817.macro emit_aarch64_feature_1_and, feat=0818.endm819820#endif /* GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT */821822.macro __mitigate_spectre_bhb_loop tmp823#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY824alternative_cb ARM64_ALWAYS_SYSTEM, spectre_bhb_patch_loop_iter825mov \tmp, #32 // Patched to correct the immediate826alternative_cb_end827.Lspectre_bhb_loop\@:828b . + 4829subs \tmp, \tmp, #1830b.ne .Lspectre_bhb_loop\@831sb832#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */833.endm834835.macro mitigate_spectre_bhb_loop tmp836#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY837alternative_cb ARM64_ALWAYS_SYSTEM, spectre_bhb_patch_loop_mitigation_enable838b .L_spectre_bhb_loop_done\@ // Patched to NOP839alternative_cb_end840__mitigate_spectre_bhb_loop \tmp841.L_spectre_bhb_loop_done\@:842#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */843.endm844845/* Save/restores x0-x3 to the stack */846.macro __mitigate_spectre_bhb_fw847#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY848stp x0, x1, [sp, #-16]!849stp x2, x3, [sp, #-16]!850mov w0, #ARM_SMCCC_ARCH_WORKAROUND_3851alternative_cb ARM64_ALWAYS_SYSTEM, smccc_patch_fw_mitigation_conduit852nop // Patched to SMC/HVC #0853alternative_cb_end854ldp x2, x3, [sp], #16855ldp x0, x1, [sp], #16856#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */857.endm858859.macro mitigate_spectre_bhb_clear_insn860#ifdef CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY861alternative_cb ARM64_ALWAYS_SYSTEM, spectre_bhb_patch_clearbhb862/* Patched to NOP when not supported */863clearbhb864isb865alternative_cb_end866#endif /* CONFIG_MITIGATE_SPECTRE_BRANCH_HISTORY */867.endm868#endif /* __ASM_ASSEMBLER_H */869870871