asm_macros.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of ARM nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without specific
  16. * prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. .macro func_prologue
  31. stp x29, x30, [sp, #-0x10]!
  32. mov x29,sp
  33. .endm
  34. .macro func_epilogue
  35. ldp x29, x30, [sp], #0x10
  36. .endm
  37. .macro dcache_line_size reg, tmp
  38. mrs \tmp, ctr_el0
  39. ubfx \tmp, \tmp, #16, #4
  40. mov \reg, #4
  41. lsl \reg, \reg, \tmp
  42. .endm
  43. .macro icache_line_size reg, tmp
  44. mrs \tmp, ctr_el0
  45. and \tmp, \tmp, #0xf
  46. mov \reg, #4
  47. lsl \reg, \reg, \tmp
  48. .endm
  49. .macro smc_check label
  50. bl read_esr
  51. ubfx x0, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
  52. cmp x0, #EC_AARCH64_SMC
  53. b.ne $label
  54. .endm
  55. .macro setup_dcsw_op_args start_level, end_level, clidr, shift, fw, ls
  56. mrs \clidr, clidr_el1
  57. mov \start_level, xzr
  58. ubfx \end_level, \clidr, \shift, \fw
  59. lsl \end_level, \end_level, \ls
  60. .endm
  61. /*
  62. * This macro verifies that the a given vector doesn't exceed the
  63. * architectural limit of 32 instructions. This is meant to be placed
  64. * immedately after the last instruction in the vector. It takes the
  65. * vector entry as the parameter
  66. */
  67. .macro check_vector_size since
  68. .if (. - \since) > (32 * 4)
  69. .error "Vector exceeds 32 instructions"
  70. .endif
  71. .endm
  72. /*
  73. * This macro is used to create a function label and place the
  74. * code into a separate text section based on the function name
  75. * to enable elimination of unused code during linking
  76. */
  77. .macro func _name
  78. .section .text.\_name, "ax"
  79. .type \_name, %function
  80. \_name:
  81. .endm
  82. /*
  83. * This macro declares an array of 1 or more stacks, properly
  84. * aligned and in the requested section
  85. */
  86. #define STACK_ALIGN 6
  87. .macro declare_stack _name, _section, _size, _count
  88. .if ((\_size & ((1 << STACK_ALIGN) - 1)) <> 0)
  89. .error "Stack size not correctly aligned"
  90. .endif
  91. .section \_section, "aw", %nobits
  92. .align STACK_ALIGN
  93. \_name:
  94. .space ((\_count) * (\_size)), 0
  95. .endm
  96. /*
  97. * This macro calculates the base address of an MP stack using the
  98. * platform_get_core_pos() index, the name of the stack storage and
  99. * the size of each stack
  100. * In: X0 = MPIDR of CPU whose stack is wanted
  101. * Out: X0 = physical address of stack base
  102. * Clobber: X30, X1, X2
  103. */
  104. .macro get_mp_stack _name, _size
  105. bl platform_get_core_pos
  106. ldr x2, =(\_name + \_size)
  107. mov x1, #\_size
  108. madd x0, x0, x1, x2
  109. .endm
  110. /*
  111. * This macro calculates the base address of a UP stack using the
  112. * name of the stack storage and the size of the stack
  113. * Out: X0 = physical address of stack base
  114. */
  115. .macro get_up_stack _name, _size
  116. ldr x0, =(\_name + \_size)
  117. .endm