bl2_entrypoint.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <common/bl_common.h>
  9. .globl bl2_entrypoint
  10. func bl2_entrypoint
  11. /*---------------------------------------------
  12. * Save arguments x0 - x3 from BL1 for future
  13. * use.
  14. * ---------------------------------------------
  15. */
  16. mov x20, x0
  17. mov x21, x1
  18. mov x22, x2
  19. mov x23, x3
  20. /* ---------------------------------------------
  21. * Set the exception vector to something sane.
  22. * ---------------------------------------------
  23. */
  24. adr x0, early_exceptions
  25. msr vbar_el1, x0
  26. isb
  27. /* ---------------------------------------------
  28. * Enable the SError interrupt now that the
  29. * exception vectors have been setup.
  30. * ---------------------------------------------
  31. */
  32. msr daifclr, #DAIF_ABT_BIT
  33. /* ---------------------------------------------
  34. * Enable the instruction cache, stack pointer
  35. * and data access alignment checks and disable
  36. * speculative loads.
  37. * ---------------------------------------------
  38. */
  39. mov x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
  40. mrs x0, sctlr_el1
  41. orr x0, x0, x1
  42. bic x0, x0, #SCTLR_DSSBS_BIT
  43. msr sctlr_el1, x0
  44. isb
  45. /* ---------------------------------------------
  46. * Invalidate the RW memory used by the BL2
  47. * image. This includes the data and NOBITS
  48. * sections. This is done to safeguard against
  49. * possible corruption of this memory by dirty
  50. * cache lines in a system cache as a result of
  51. * use by an earlier boot loader stage.
  52. * ---------------------------------------------
  53. */
  54. adr x0, __RW_START__
  55. adr x1, __RW_END__
  56. sub x1, x1, x0
  57. bl inv_dcache_range
  58. /* ---------------------------------------------
  59. * Zero out NOBITS sections. There are 2 of them:
  60. * - the .bss section;
  61. * - the coherent memory section.
  62. * ---------------------------------------------
  63. */
  64. adrp x0, __BSS_START__
  65. add x0, x0, :lo12:__BSS_START__
  66. adrp x1, __BSS_END__
  67. add x1, x1, :lo12:__BSS_END__
  68. sub x1, x1, x0
  69. bl zeromem
  70. #if USE_COHERENT_MEM
  71. adrp x0, __COHERENT_RAM_START__
  72. add x0, x0, :lo12:__COHERENT_RAM_START__
  73. adrp x1, __COHERENT_RAM_END_UNALIGNED__
  74. add x1, x1, :lo12:__COHERENT_RAM_END_UNALIGNED__
  75. sub x1, x1, x0
  76. bl zeromem
  77. #endif
  78. /* --------------------------------------------
  79. * Allocate a stack whose memory will be marked
  80. * as Normal-IS-WBWA when the MMU is enabled.
  81. * There is no risk of reading stale stack
  82. * memory after enabling the MMU as only the
  83. * primary cpu is running at the moment.
  84. * --------------------------------------------
  85. */
  86. bl plat_set_my_stack
  87. /* ---------------------------------------------
  88. * Initialize the stack protector canary before
  89. * any C code is called.
  90. * ---------------------------------------------
  91. */
  92. #if STACK_PROTECTOR_ENABLED
  93. bl update_stack_protector_canary
  94. #endif
  95. /* ---------------------------------------------
  96. * Perform BL2 setup
  97. * ---------------------------------------------
  98. */
  99. mov x0, x20
  100. mov x1, x21
  101. mov x2, x22
  102. mov x3, x23
  103. bl bl2_setup
  104. #if ENABLE_PAUTH
  105. /* ---------------------------------------------
  106. * Program APIAKey_EL1
  107. * and enable pointer authentication.
  108. * ---------------------------------------------
  109. */
  110. bl pauth_init_enable_el1
  111. #endif /* ENABLE_PAUTH */
  112. /* ---------------------------------------------
  113. * Jump to main function.
  114. * ---------------------------------------------
  115. */
  116. bl bl2_main
  117. /* ---------------------------------------------
  118. * Should never reach this point.
  119. * ---------------------------------------------
  120. */
  121. no_ret plat_panic_handler
  122. endfunc bl2_entrypoint