mte_helper.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2020 ARM Limited */
  3. #include "mte_def.h"
  4. .arch armv8.5-a+memtag
  5. #define ENTRY(name) \
  6. .globl name ;\
  7. .p2align 2;\
  8. .type name, @function ;\
  9. name:
  10. #define ENDPROC(name) \
  11. .size name, .-name ;
  12. .text
  13. /*
  14. * mte_insert_random_tag: Insert random tag and might be same as the source tag if
  15. * the source pointer has it.
  16. * Input:
  17. * x0 - source pointer with a tag/no-tag
  18. * Return:
  19. * x0 - pointer with random tag
  20. */
  21. ENTRY(mte_insert_random_tag)
  22. irg x0, x0, xzr
  23. ret
  24. ENDPROC(mte_insert_random_tag)
  25. /*
  26. * mte_insert_new_tag: Insert new tag and different from the source tag if
  27. * source pointer has it.
  28. * Input:
  29. * x0 - source pointer with a tag/no-tag
  30. * Return:
  31. * x0 - pointer with random tag
  32. */
  33. ENTRY(mte_insert_new_tag)
  34. gmi x1, x0, xzr
  35. irg x0, x0, x1
  36. ret
  37. ENDPROC(mte_insert_new_tag)
  38. /*
  39. * mte_get_tag_address: Get the tag from given address.
  40. * Input:
  41. * x0 - source pointer
  42. * Return:
  43. * x0 - pointer with appended tag
  44. */
  45. ENTRY(mte_get_tag_address)
  46. ldg x0, [x0]
  47. ret
  48. ENDPROC(mte_get_tag_address)
  49. /*
  50. * mte_set_tag_address_range: Set the tag range from the given address
  51. * Input:
  52. * x0 - source pointer with tag data
  53. * x1 - range
  54. * Return:
  55. * none
  56. */
  57. ENTRY(mte_set_tag_address_range)
  58. cbz x1, 2f
  59. 1:
  60. stg x0, [x0, #0x0]
  61. add x0, x0, #MT_GRANULE_SIZE
  62. sub x1, x1, #MT_GRANULE_SIZE
  63. cbnz x1, 1b
  64. 2:
  65. ret
  66. ENDPROC(mte_set_tag_address_range)
  67. /*
  68. * mt_clear_tag_address_range: Clear the tag range from the given address
  69. * Input:
  70. * x0 - source pointer with tag data
  71. * x1 - range
  72. * Return:
  73. * none
  74. */
  75. ENTRY(mte_clear_tag_address_range)
  76. cbz x1, 2f
  77. 1:
  78. stzg x0, [x0, #0x0]
  79. add x0, x0, #MT_GRANULE_SIZE
  80. sub x1, x1, #MT_GRANULE_SIZE
  81. cbnz x1, 1b
  82. 2:
  83. ret
  84. ENDPROC(mte_clear_tag_address_range)
  85. /*
  86. * mte_enable_pstate_tco: Enable PSTATE.TCO (tag check override) field
  87. * Input:
  88. * none
  89. * Return:
  90. * none
  91. */
  92. ENTRY(mte_enable_pstate_tco)
  93. msr tco, #MT_PSTATE_TCO_EN
  94. ret
  95. ENDPROC(mte_enable_pstate_tco)
  96. /*
  97. * mte_disable_pstate_tco: Disable PSTATE.TCO (tag check override) field
  98. * Input:
  99. * none
  100. * Return:
  101. * none
  102. */
  103. ENTRY(mte_disable_pstate_tco)
  104. msr tco, #MT_PSTATE_TCO_DIS
  105. ret
  106. ENDPROC(mte_disable_pstate_tco)
  107. /*
  108. * mte_get_pstate_tco: Get PSTATE.TCO (tag check override) field
  109. * Input:
  110. * none
  111. * Return:
  112. * x0
  113. */
  114. ENTRY(mte_get_pstate_tco)
  115. mrs x0, tco
  116. ubfx x0, x0, #MT_PSTATE_TCO_SHIFT, #1
  117. ret
  118. ENDPROC(mte_get_pstate_tco)