pauth_helpers.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2019, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <lib/el3_runtime/cpu_data.h>
  9. .global pauth_init_enable_el1
  10. .global pauth_disable_el1
  11. .global pauth_init_enable_el3
  12. .global pauth_disable_el3
  13. .globl pauth_load_bl31_apiakey
  14. .globl pauth_load_bl1_apiakey_enable
  15. /* -------------------------------------------------------------
  16. * Program APIAKey_EL1 and enable pointer authentication in EL1
  17. * -------------------------------------------------------------
  18. */
  19. func pauth_init_enable_el1
  20. stp x29, x30, [sp, #-16]!
  21. /* Initialize platform key */
  22. bl plat_init_apkey
  23. /* Program instruction key A used by the Trusted Firmware */
  24. msr APIAKeyLo_EL1, x0
  25. msr APIAKeyHi_EL1, x1
  26. /* Enable pointer authentication */
  27. mrs x0, sctlr_el1
  28. orr x0, x0, #SCTLR_EnIA_BIT
  29. #if ENABLE_BTI
  30. /* Enable PAC branch type compatibility */
  31. bic x0, x0, #(SCTLR_BT0_BIT | SCTLR_BT1_BIT)
  32. #endif
  33. msr sctlr_el1, x0
  34. isb
  35. ldp x29, x30, [sp], #16
  36. ret
  37. endfunc pauth_init_enable_el1
  38. /* -------------------------------------------------------------
  39. * Disable pointer authentication in EL1
  40. * -------------------------------------------------------------
  41. */
  42. func pauth_disable_el1
  43. mrs x0, sctlr_el1
  44. bic x0, x0, #SCTLR_EnIA_BIT
  45. msr sctlr_el1, x0
  46. isb
  47. ret
  48. endfunc pauth_disable_el1
  49. /* -------------------------------------------------------------
  50. * Program APIAKey_EL1 and enable pointer authentication in EL3
  51. * -------------------------------------------------------------
  52. */
  53. func pauth_init_enable_el3
  54. stp x29, x30, [sp, #-16]!
  55. /* Initialize platform key */
  56. bl plat_init_apkey
  57. /* Program instruction key A used by the Trusted Firmware */
  58. msr APIAKeyLo_EL1, x0
  59. msr APIAKeyHi_EL1, x1
  60. /* Enable pointer authentication */
  61. mrs x0, sctlr_el3
  62. orr x0, x0, #SCTLR_EnIA_BIT
  63. #if ENABLE_BTI
  64. /* Enable PAC branch type compatibility */
  65. bic x0, x0, #SCTLR_BT_BIT
  66. #endif
  67. msr sctlr_el3, x0
  68. isb
  69. ldp x29, x30, [sp], #16
  70. ret
  71. endfunc pauth_init_enable_el3
  72. /* -------------------------------------------------------------
  73. * Disable pointer authentication in EL3
  74. * -------------------------------------------------------------
  75. */
  76. func pauth_disable_el3
  77. mrs x0, sctlr_el3
  78. bic x0, x0, #SCTLR_EnIA_BIT
  79. msr sctlr_el3, x0
  80. isb
  81. ret
  82. endfunc pauth_disable_el3
  83. /* -------------------------------------------------------------
  84. * The following functions strictly follow the AArch64 PCS
  85. * to use x9-x17 (temporary caller-saved registers) to load
  86. * the APIAKey_EL1 and enable pointer authentication.
  87. * -------------------------------------------------------------
  88. */
  89. func pauth_load_bl31_apiakey
  90. /* tpidr_el3 contains the address of cpu_data structure */
  91. mrs x9, tpidr_el3
  92. /* Load apiakey from cpu_data */
  93. ldp x10, x11, [x9, #CPU_DATA_APIAKEY_OFFSET]
  94. /* Program instruction key A */
  95. msr APIAKeyLo_EL1, x10
  96. msr APIAKeyHi_EL1, x11
  97. isb
  98. ret
  99. endfunc pauth_load_bl31_apiakey
  100. func pauth_load_bl1_apiakey_enable
  101. /* Load instruction key A used by the Trusted Firmware */
  102. adrp x9, bl1_apiakey
  103. add x9, x9, :lo12:bl1_apiakey
  104. ldp x10, x11, [x9]
  105. /* Program instruction key A */
  106. msr APIAKeyLo_EL1, x10
  107. msr APIAKeyHi_EL1, x11
  108. /* Enable pointer authentication */
  109. mrs x9, sctlr_el3
  110. orr x9, x9, #SCTLR_EnIA_BIT
  111. #if ENABLE_BTI
  112. /* Enable PAC branch type compatibility */
  113. bic x9, x9, #SCTLR_BT_BIT
  114. #endif
  115. msr sctlr_el3, x9
  116. isb
  117. ret
  118. endfunc pauth_load_bl1_apiakey_enable