assembler.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S
  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. #ifndef __ASM_ASSEMBLER_H
  23. #define __ASM_ASSEMBLER_H
  24. #include <asm/asm-offsets.h>
  25. #include <asm/cpufeature.h>
  26. #include <asm/debug-monitors.h>
  27. #include <asm/page.h>
  28. #include <asm/pgtable-hwdef.h>
  29. #include <asm/ptrace.h>
  30. #include <asm/thread_info.h>
  31. .macro save_and_disable_daif, flags
  32. mrs \flags, daif
  33. msr daifset, #0xf
  34. .endm
  35. .macro disable_daif
  36. msr daifset, #0xf
  37. .endm
  38. .macro enable_daif
  39. msr daifclr, #0xf
  40. .endm
  41. .macro restore_daif, flags:req
  42. msr daif, \flags
  43. .endm
  44. /* Only on aarch64 pstate, PSR_D_BIT is different for aarch32 */
  45. .macro inherit_daif, pstate:req, tmp:req
  46. and \tmp, \pstate, #(PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
  47. msr daif, \tmp
  48. .endm
  49. /* IRQ is the lowest priority flag, unconditionally unmask the rest. */
  50. .macro enable_da_f
  51. msr daifclr, #(8 | 4 | 1)
  52. .endm
  53. /*
  54. * Enable and disable interrupts.
  55. */
  56. .macro disable_irq
  57. msr daifset, #2
  58. .endm
  59. .macro enable_irq
  60. msr daifclr, #2
  61. .endm
  62. .macro save_and_disable_irq, flags
  63. mrs \flags, daif
  64. msr daifset, #2
  65. .endm
  66. .macro restore_irq, flags
  67. msr daif, \flags
  68. .endm
  69. .macro enable_dbg
  70. msr daifclr, #8
  71. .endm
  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. /* call with daif masked */
  81. .macro enable_step_tsk, flgs, tmp
  82. tbz \flgs, #TIF_SINGLESTEP, 9990f
  83. mrs \tmp, mdscr_el1
  84. orr \tmp, \tmp, #DBG_MDSCR_SS
  85. msr mdscr_el1, \tmp
  86. 9990:
  87. .endm
  88. /*
  89. * SMP data memory barrier
  90. */
  91. .macro smp_dmb, opt
  92. dmb \opt
  93. .endm
  94. /*
  95. * RAS Error Synchronization barrier
  96. */
  97. .macro esb
  98. #ifdef CONFIG_ARM64_RAS_EXTN
  99. hint #16
  100. #else
  101. nop
  102. #endif
  103. .endm
  104. /*
  105. * Value prediction barrier
  106. */
  107. .macro csdb
  108. hint #20
  109. .endm
  110. /*
  111. * Sanitise a 64-bit bounded index wrt speculation, returning zero if out
  112. * of bounds.
  113. */
  114. .macro mask_nospec64, idx, limit, tmp
  115. sub \tmp, \idx, \limit
  116. bic \tmp, \tmp, \idx
  117. and \idx, \idx, \tmp, asr #63
  118. csdb
  119. .endm
  120. /*
  121. * NOP sequence
  122. */
  123. .macro nops, num
  124. .rept \num
  125. nop
  126. .endr
  127. .endm
  128. /*
  129. * Emit an entry into the exception table
  130. */
  131. .macro _asm_extable, from, to
  132. .pushsection __ex_table, "a"
  133. .align 3
  134. .long (\from - .), (\to - .)
  135. .popsection
  136. .endm
  137. #define USER(l, x...) \
  138. 9999: x; \
  139. _asm_extable 9999b, l
  140. /*
  141. * Register aliases.
  142. */
  143. lr .req x30 // link register
  144. /*
  145. * Vector entry
  146. */
  147. .macro ventry label
  148. .align 7
  149. b \label
  150. .endm
  151. /*
  152. * Select code when configured for BE.
  153. */
  154. #ifdef CONFIG_CPU_BIG_ENDIAN
  155. #define CPU_BE(code...) code
  156. #else
  157. #define CPU_BE(code...)
  158. #endif
  159. /*
  160. * Select code when configured for LE.
  161. */
  162. #ifdef CONFIG_CPU_BIG_ENDIAN
  163. #define CPU_LE(code...)
  164. #else
  165. #define CPU_LE(code...) code
  166. #endif
  167. /*
  168. * Define a macro that constructs a 64-bit value by concatenating two
  169. * 32-bit registers. Note that on big endian systems the order of the
  170. * registers is swapped.
  171. */
  172. #ifndef CONFIG_CPU_BIG_ENDIAN
  173. .macro regs_to_64, rd, lbits, hbits
  174. #else
  175. .macro regs_to_64, rd, hbits, lbits
  176. #endif
  177. orr \rd, \lbits, \hbits, lsl #32
  178. .endm
  179. /*
  180. * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
  181. * <symbol> is within the range +/- 4 GB of the PC.
  182. */
  183. /*
  184. * @dst: destination register (64 bit wide)
  185. * @sym: name of the symbol
  186. */
  187. .macro adr_l, dst, sym
  188. adrp \dst, \sym
  189. add \dst, \dst, :lo12:\sym
  190. .endm
  191. /*
  192. * @dst: destination register (32 or 64 bit wide)
  193. * @sym: name of the symbol
  194. * @tmp: optional 64-bit scratch register to be used if <dst> is a
  195. * 32-bit wide register, in which case it cannot be used to hold
  196. * the address
  197. */
  198. .macro ldr_l, dst, sym, tmp=
  199. .ifb \tmp
  200. adrp \dst, \sym
  201. ldr \dst, [\dst, :lo12:\sym]
  202. .else
  203. adrp \tmp, \sym
  204. ldr \dst, [\tmp, :lo12:\sym]
  205. .endif
  206. .endm
  207. /*
  208. * @src: source register (32 or 64 bit wide)
  209. * @sym: name of the symbol
  210. * @tmp: mandatory 64-bit scratch register to calculate the address
  211. * while <src> needs to be preserved.
  212. */
  213. .macro str_l, src, sym, tmp
  214. adrp \tmp, \sym
  215. str \src, [\tmp, :lo12:\sym]
  216. .endm
  217. /*
  218. * @dst: Result of per_cpu(sym, smp_processor_id()) (can be SP)
  219. * @sym: The name of the per-cpu variable
  220. * @tmp: scratch register
  221. */
  222. .macro adr_this_cpu, dst, sym, tmp
  223. adrp \tmp, \sym
  224. add \dst, \tmp, #:lo12:\sym
  225. alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
  226. mrs \tmp, tpidr_el1
  227. alternative_else
  228. mrs \tmp, tpidr_el2
  229. alternative_endif
  230. add \dst, \dst, \tmp
  231. .endm
  232. /*
  233. * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id()))
  234. * @sym: The name of the per-cpu variable
  235. * @tmp: scratch register
  236. */
  237. .macro ldr_this_cpu dst, sym, tmp
  238. adr_l \dst, \sym
  239. alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
  240. mrs \tmp, tpidr_el1
  241. alternative_else
  242. mrs \tmp, tpidr_el2
  243. alternative_endif
  244. ldr \dst, [\dst, \tmp]
  245. .endm
  246. /*
  247. * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
  248. */
  249. .macro vma_vm_mm, rd, rn
  250. ldr \rd, [\rn, #VMA_VM_MM]
  251. .endm
  252. /*
  253. * mmid - get context id from mm pointer (mm->context.id)
  254. */
  255. .macro mmid, rd, rn
  256. ldr \rd, [\rn, #MM_CONTEXT_ID]
  257. .endm
  258. /*
  259. * read_ctr - read CTR_EL0. If the system has mismatched
  260. * cache line sizes, provide the system wide safe value
  261. * from arm64_ftr_reg_ctrel0.sys_val
  262. */
  263. .macro read_ctr, reg
  264. alternative_if_not ARM64_MISMATCHED_CACHE_LINE_SIZE
  265. mrs \reg, ctr_el0 // read CTR
  266. nop
  267. alternative_else
  268. ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL
  269. alternative_endif
  270. .endm
  271. /*
  272. * raw_dcache_line_size - get the minimum D-cache line size on this CPU
  273. * from the CTR register.
  274. */
  275. .macro raw_dcache_line_size, reg, tmp
  276. mrs \tmp, ctr_el0 // read CTR
  277. ubfm \tmp, \tmp, #16, #19 // cache line size encoding
  278. mov \reg, #4 // bytes per word
  279. lsl \reg, \reg, \tmp // actual cache line size
  280. .endm
  281. /*
  282. * dcache_line_size - get the safe D-cache line size across all CPUs
  283. */
  284. .macro dcache_line_size, reg, tmp
  285. read_ctr \tmp
  286. ubfm \tmp, \tmp, #16, #19 // cache line size encoding
  287. mov \reg, #4 // bytes per word
  288. lsl \reg, \reg, \tmp // actual cache line size
  289. .endm
  290. /*
  291. * raw_icache_line_size - get the minimum I-cache line size on this CPU
  292. * from the CTR register.
  293. */
  294. .macro raw_icache_line_size, reg, tmp
  295. mrs \tmp, ctr_el0 // read CTR
  296. and \tmp, \tmp, #0xf // cache line size encoding
  297. mov \reg, #4 // bytes per word
  298. lsl \reg, \reg, \tmp // actual cache line size
  299. .endm
  300. /*
  301. * icache_line_size - get the safe I-cache line size across all CPUs
  302. */
  303. .macro icache_line_size, reg, tmp
  304. read_ctr \tmp
  305. and \tmp, \tmp, #0xf // cache line size encoding
  306. mov \reg, #4 // bytes per word
  307. lsl \reg, \reg, \tmp // actual cache line size
  308. .endm
  309. /*
  310. * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map
  311. */
  312. .macro tcr_set_idmap_t0sz, valreg, tmpreg
  313. ldr_l \tmpreg, idmap_t0sz
  314. bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH
  315. .endm
  316. /*
  317. * tcr_compute_pa_size - set TCR.(I)PS to the highest supported
  318. * ID_AA64MMFR0_EL1.PARange value
  319. *
  320. * tcr: register with the TCR_ELx value to be updated
  321. * pos: IPS or PS bitfield position
  322. * tmp{0,1}: temporary registers
  323. */
  324. .macro tcr_compute_pa_size, tcr, pos, tmp0, tmp1
  325. mrs \tmp0, ID_AA64MMFR0_EL1
  326. // Narrow PARange to fit the PS field in TCR_ELx
  327. ubfx \tmp0, \tmp0, #ID_AA64MMFR0_PARANGE_SHIFT, #3
  328. mov \tmp1, #ID_AA64MMFR0_PARANGE_MAX
  329. cmp \tmp0, \tmp1
  330. csel \tmp0, \tmp1, \tmp0, hi
  331. bfi \tcr, \tmp0, \pos, #3
  332. .endm
  333. /*
  334. * Macro to perform a data cache maintenance for the interval
  335. * [kaddr, kaddr + size)
  336. *
  337. * op: operation passed to dc instruction
  338. * domain: domain used in dsb instruciton
  339. * kaddr: starting virtual address of the region
  340. * size: size of the region
  341. * Corrupts: kaddr, size, tmp1, tmp2
  342. */
  343. .macro __dcache_op_workaround_clean_cache, op, kaddr
  344. alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE
  345. dc \op, \kaddr
  346. alternative_else
  347. dc civac, \kaddr
  348. alternative_endif
  349. .endm
  350. .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2
  351. dcache_line_size \tmp1, \tmp2
  352. add \size, \kaddr, \size
  353. sub \tmp2, \tmp1, #1
  354. bic \kaddr, \kaddr, \tmp2
  355. 9998:
  356. .ifc \op, cvau
  357. __dcache_op_workaround_clean_cache \op, \kaddr
  358. .else
  359. .ifc \op, cvac
  360. __dcache_op_workaround_clean_cache \op, \kaddr
  361. .else
  362. .ifc \op, cvap
  363. sys 3, c7, c12, 1, \kaddr // dc cvap
  364. .else
  365. dc \op, \kaddr
  366. .endif
  367. .endif
  368. .endif
  369. add \kaddr, \kaddr, \tmp1
  370. cmp \kaddr, \size
  371. b.lo 9998b
  372. dsb \domain
  373. .endm
  374. /*
  375. * Macro to perform an instruction cache maintenance for the interval
  376. * [start, end)
  377. *
  378. * start, end: virtual addresses describing the region
  379. * label: A label to branch to on user fault.
  380. * Corrupts: tmp1, tmp2
  381. */
  382. .macro invalidate_icache_by_line start, end, tmp1, tmp2, label
  383. icache_line_size \tmp1, \tmp2
  384. sub \tmp2, \tmp1, #1
  385. bic \tmp2, \start, \tmp2
  386. 9997:
  387. USER(\label, ic ivau, \tmp2) // invalidate I line PoU
  388. add \tmp2, \tmp2, \tmp1
  389. cmp \tmp2, \end
  390. b.lo 9997b
  391. dsb ish
  392. isb
  393. .endm
  394. /*
  395. * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present
  396. */
  397. .macro reset_pmuserenr_el0, tmpreg
  398. mrs \tmpreg, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer
  399. sbfx \tmpreg, \tmpreg, #8, #4
  400. cmp \tmpreg, #1 // Skip if no PMU present
  401. b.lt 9000f
  402. msr pmuserenr_el0, xzr // Disable PMU access from EL0
  403. 9000:
  404. .endm
  405. /*
  406. * copy_page - copy src to dest using temp registers t1-t8
  407. */
  408. .macro copy_page dest:req src:req t1:req t2:req t3:req t4:req t5:req t6:req t7:req t8:req
  409. 9998: ldp \t1, \t2, [\src]
  410. ldp \t3, \t4, [\src, #16]
  411. ldp \t5, \t6, [\src, #32]
  412. ldp \t7, \t8, [\src, #48]
  413. add \src, \src, #64
  414. stnp \t1, \t2, [\dest]
  415. stnp \t3, \t4, [\dest, #16]
  416. stnp \t5, \t6, [\dest, #32]
  417. stnp \t7, \t8, [\dest, #48]
  418. add \dest, \dest, #64
  419. tst \src, #(PAGE_SIZE - 1)
  420. b.ne 9998b
  421. .endm
  422. /*
  423. * Annotate a function as position independent, i.e., safe to be called before
  424. * the kernel virtual mapping is activated.
  425. */
  426. #define ENDPIPROC(x) \
  427. .globl __pi_##x; \
  428. .type __pi_##x, %function; \
  429. .set __pi_##x, x; \
  430. .size __pi_##x, . - x; \
  431. ENDPROC(x)
  432. /*
  433. * Annotate a function as being unsuitable for kprobes.
  434. */
  435. #ifdef CONFIG_KPROBES
  436. #define NOKPROBE(x) \
  437. .pushsection "_kprobe_blacklist", "aw"; \
  438. .quad x; \
  439. .popsection;
  440. #else
  441. #define NOKPROBE(x)
  442. #endif
  443. /*
  444. * Emit a 64-bit absolute little endian symbol reference in a way that
  445. * ensures that it will be resolved at build time, even when building a
  446. * PIE binary. This requires cooperation from the linker script, which
  447. * must emit the lo32/hi32 halves individually.
  448. */
  449. .macro le64sym, sym
  450. .long \sym\()_lo32
  451. .long \sym\()_hi32
  452. .endm
  453. /*
  454. * mov_q - move an immediate constant into a 64-bit register using
  455. * between 2 and 4 movz/movk instructions (depending on the
  456. * magnitude and sign of the operand)
  457. */
  458. .macro mov_q, reg, val
  459. .if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff)
  460. movz \reg, :abs_g1_s:\val
  461. .else
  462. .if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff)
  463. movz \reg, :abs_g2_s:\val
  464. .else
  465. movz \reg, :abs_g3:\val
  466. movk \reg, :abs_g2_nc:\val
  467. .endif
  468. movk \reg, :abs_g1_nc:\val
  469. .endif
  470. movk \reg, :abs_g0_nc:\val
  471. .endm
  472. /*
  473. * Return the current thread_info.
  474. */
  475. .macro get_thread_info, rd
  476. mrs \rd, sp_el0
  477. .endm
  478. /*
  479. * Arrange a physical address in a TTBR register, taking care of 52-bit
  480. * addresses.
  481. *
  482. * phys: physical address, preserved
  483. * ttbr: returns the TTBR value
  484. */
  485. .macro phys_to_ttbr, ttbr, phys
  486. #ifdef CONFIG_ARM64_PA_BITS_52
  487. orr \ttbr, \phys, \phys, lsr #46
  488. and \ttbr, \ttbr, #TTBR_BADDR_MASK_52
  489. #else
  490. mov \ttbr, \phys
  491. #endif
  492. .endm
  493. .macro phys_to_pte, pte, phys
  494. #ifdef CONFIG_ARM64_PA_BITS_52
  495. /*
  496. * We assume \phys is 64K aligned and this is guaranteed by only
  497. * supporting this configuration with 64K pages.
  498. */
  499. orr \pte, \phys, \phys, lsr #36
  500. and \pte, \pte, #PTE_ADDR_MASK
  501. #else
  502. mov \pte, \phys
  503. #endif
  504. .endm
  505. .macro pte_to_phys, phys, pte
  506. #ifdef CONFIG_ARM64_PA_BITS_52
  507. ubfiz \phys, \pte, #(48 - 16 - 12), #16
  508. bfxil \phys, \pte, #16, #32
  509. lsl \phys, \phys, #16
  510. #else
  511. and \phys, \pte, #PTE_ADDR_MASK
  512. #endif
  513. .endm
  514. /**
  515. * Errata workaround prior to disable MMU. Insert an ISB immediately prior
  516. * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0.
  517. */
  518. .macro pre_disable_mmu_workaround
  519. #ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041
  520. isb
  521. #endif
  522. .endm
  523. /*
  524. * frame_push - Push @regcount callee saved registers to the stack,
  525. * starting at x19, as well as x29/x30, and set x29 to
  526. * the new value of sp. Add @extra bytes of stack space
  527. * for locals.
  528. */
  529. .macro frame_push, regcount:req, extra
  530. __frame st, \regcount, \extra
  531. .endm
  532. /*
  533. * frame_pop - Pop the callee saved registers from the stack that were
  534. * pushed in the most recent call to frame_push, as well
  535. * as x29/x30 and any extra stack space that may have been
  536. * allocated.
  537. */
  538. .macro frame_pop
  539. __frame ld
  540. .endm
  541. .macro __frame_regs, reg1, reg2, op, num
  542. .if .Lframe_regcount == \num
  543. \op\()r \reg1, [sp, #(\num + 1) * 8]
  544. .elseif .Lframe_regcount > \num
  545. \op\()p \reg1, \reg2, [sp, #(\num + 1) * 8]
  546. .endif
  547. .endm
  548. .macro __frame, op, regcount, extra=0
  549. .ifc \op, st
  550. .if (\regcount) < 0 || (\regcount) > 10
  551. .error "regcount should be in the range [0 ... 10]"
  552. .endif
  553. .if ((\extra) % 16) != 0
  554. .error "extra should be a multiple of 16 bytes"
  555. .endif
  556. .ifdef .Lframe_regcount
  557. .if .Lframe_regcount != -1
  558. .error "frame_push/frame_pop may not be nested"
  559. .endif
  560. .endif
  561. .set .Lframe_regcount, \regcount
  562. .set .Lframe_extra, \extra
  563. .set .Lframe_local_offset, ((\regcount + 3) / 2) * 16
  564. stp x29, x30, [sp, #-.Lframe_local_offset - .Lframe_extra]!
  565. mov x29, sp
  566. .endif
  567. __frame_regs x19, x20, \op, 1
  568. __frame_regs x21, x22, \op, 3
  569. __frame_regs x23, x24, \op, 5
  570. __frame_regs x25, x26, \op, 7
  571. __frame_regs x27, x28, \op, 9
  572. .ifc \op, ld
  573. .if .Lframe_regcount == -1
  574. .error "frame_push/frame_pop may not be nested"
  575. .endif
  576. ldp x29, x30, [sp], #.Lframe_local_offset + .Lframe_extra
  577. .set .Lframe_regcount, -1
  578. .endif
  579. .endm
  580. /*
  581. * Check whether to yield to another runnable task from kernel mode NEON code
  582. * (which runs with preemption disabled).
  583. *
  584. * if_will_cond_yield_neon
  585. * // pre-yield patchup code
  586. * do_cond_yield_neon
  587. * // post-yield patchup code
  588. * endif_yield_neon <label>
  589. *
  590. * where <label> is optional, and marks the point where execution will resume
  591. * after a yield has been performed. If omitted, execution resumes right after
  592. * the endif_yield_neon invocation. Note that the entire sequence, including
  593. * the provided patchup code, will be omitted from the image if CONFIG_PREEMPT
  594. * is not defined.
  595. *
  596. * As a convenience, in the case where no patchup code is required, the above
  597. * sequence may be abbreviated to
  598. *
  599. * cond_yield_neon <label>
  600. *
  601. * Note that the patchup code does not support assembler directives that change
  602. * the output section, any use of such directives is undefined.
  603. *
  604. * The yield itself consists of the following:
  605. * - Check whether the preempt count is exactly 1, in which case disabling
  606. * preemption once will make the task preemptible. If this is not the case,
  607. * yielding is pointless.
  608. * - Check whether TIF_NEED_RESCHED is set, and if so, disable and re-enable
  609. * kernel mode NEON (which will trigger a reschedule), and branch to the
  610. * yield fixup code.
  611. *
  612. * This macro sequence may clobber all CPU state that is not guaranteed by the
  613. * AAPCS to be preserved across an ordinary function call.
  614. */
  615. .macro cond_yield_neon, lbl
  616. if_will_cond_yield_neon
  617. do_cond_yield_neon
  618. endif_yield_neon \lbl
  619. .endm
  620. .macro if_will_cond_yield_neon
  621. #ifdef CONFIG_PREEMPT
  622. get_thread_info x0
  623. ldr w1, [x0, #TSK_TI_PREEMPT]
  624. ldr x0, [x0, #TSK_TI_FLAGS]
  625. cmp w1, #PREEMPT_DISABLE_OFFSET
  626. csel x0, x0, xzr, eq
  627. tbnz x0, #TIF_NEED_RESCHED, .Lyield_\@ // needs rescheduling?
  628. /* fall through to endif_yield_neon */
  629. .subsection 1
  630. .Lyield_\@ :
  631. #else
  632. .section ".discard.cond_yield_neon", "ax"
  633. #endif
  634. .endm
  635. .macro do_cond_yield_neon
  636. bl kernel_neon_end
  637. bl kernel_neon_begin
  638. .endm
  639. .macro endif_yield_neon, lbl
  640. .ifnb \lbl
  641. b \lbl
  642. .else
  643. b .Lyield_out_\@
  644. .endif
  645. .previous
  646. .Lyield_out_\@ :
  647. .endm
  648. #endif /* __ASM_ASSEMBLER_H */