assembler.h 16 KB

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