assembler.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (C) 2015-2019 ARM Limited.
  3. // Original author: Dave Martin <[email protected]>
  4. #ifndef ASSEMBLER_H
  5. #define ASSEMBLER_H
  6. .macro __for from:req, to:req
  7. .if (\from) == (\to)
  8. _for__body %\from
  9. .else
  10. __for \from, %(\from) + ((\to) - (\from)) / 2
  11. __for %(\from) + ((\to) - (\from)) / 2 + 1, \to
  12. .endif
  13. .endm
  14. .macro _for var:req, from:req, to:req, insn:vararg
  15. .macro _for__body \var:req
  16. .noaltmacro
  17. \insn
  18. .altmacro
  19. .endm
  20. .altmacro
  21. __for \from, \to
  22. .noaltmacro
  23. .purgem _for__body
  24. .endm
  25. .macro function name
  26. .macro endfunction
  27. .type \name, @function
  28. .purgem endfunction
  29. .endm
  30. \name:
  31. .endm
  32. .macro define_accessor name, num, insn
  33. .macro \name\()_entry n
  34. \insn \n, 1
  35. ret
  36. .endm
  37. function \name
  38. adr x2, .L__accessor_tbl\@
  39. add x2, x2, x0, lsl #3
  40. br x2
  41. .L__accessor_tbl\@:
  42. _for x, 0, (\num) - 1, \name\()_entry \x
  43. endfunction
  44. .purgem \name\()_entry
  45. .endm
  46. // Utility macro to print a literal string
  47. // Clobbers x0-x4,x8
  48. .macro puts string
  49. .pushsection .rodata.str1.1, "aMS", 1
  50. .L__puts_literal\@: .string "\string"
  51. .popsection
  52. ldr x0, =.L__puts_literal\@
  53. bl puts
  54. .endm
  55. #endif /* ! ASSEMBLER_H */