boot.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SAMA5D2/boot.S
  15. * @brief SAMA5D2 boot-related code managing the trusted zone.
  16. *
  17. * @addtogroup SAMA5D2_BOOT
  18. * @{
  19. */
  20. #if !defined(__DOXYGEN__)
  21. .set SCR_NS, 0x01
  22. .set SCR_IRQ, 0x02
  23. .set SCR_FIQ, 0x04
  24. .set SCR_EA, 0x08
  25. .set SCR_FW, 0x10
  26. .set SCR_AW, 0x20
  27. .set AIC_REDIR_KEY, 0x5B6C0E26 << 1
  28. .set SFR_SN1, 0xF8030050
  29. .set SFR_AICREDIR, 0xF8030054
  30. .set SFR_L2CC_HRAMC, 0xF8030058
  31. .set L2CC_CR, 0x00A00100
  32. .set SCR_RESET_VAL, (SCR_EA|SCR_IRQ)
  33. .section .boot
  34. .code 32
  35. .balign 4
  36. /*
  37. * Boot initialization code
  38. */
  39. .global Boot_Handler
  40. Boot_Handler:
  41. /*
  42. * Set VBAR to system vectors table
  43. * Set MVBAR to monitor vectors table
  44. */
  45. ldr r0, =_start
  46. mcr p15, 0, r0, c12, c0, 0
  47. ldr r0, =_monitor_vectors
  48. mcr p15, 0, r0, c12, c0, 1
  49. /*
  50. * Do not redirect secure interrupts to AIC
  51. */
  52. ldr r0, =AIC_REDIR_KEY
  53. ldr r1, =SFR_SN1
  54. ldr r1, [r1]
  55. eor r0, r0, r1
  56. bic r0, r0, #0x1
  57. ldr r1, =SFR_AICREDIR
  58. str r0, [r1]
  59. #if defined(ARM_RESET_SYS_CTRL)
  60. /*
  61. * Reset SCTLR Settings
  62. */
  63. mrc p15, 0, r0, c1, c0, 0 // Read CP15 System Control register
  64. bic r0, r0, #(0x1 << 12) // Clear I bit 12 to disable I Cache
  65. bic r0, r0, #(0x1 << 2) // Clear C bit 2 to disable D Cache
  66. bic r0, r0, #0x1 // Clear M bit 0 to disable MMU
  67. bic r0, r0, #(0x1 << 11) // Clear Z bit 11 to disable branch prediction
  68. bic r0, r0, #(0x1 << 13) // Clear V bit 13 to disable hivecs
  69. mcr p15, 0, r0, c1, c0, 0 // Write value back to CP15 System Control register
  70. isb
  71. /*
  72. * Turn off L2Cache
  73. */
  74. bic r0, r0, #0x1
  75. ldr r1, =L2CC_CR
  76. str r0, [r1]
  77. /*
  78. * Configure the L2 cache to be used as an internal SRAM
  79. */
  80. bic r0, r0, #0x1
  81. ldr r1, =SFR_L2CC_HRAMC
  82. str r0, [r1]
  83. #endif
  84. /*
  85. * Enabling Cycle counter
  86. */
  87. mrc p15, 0, r0, c9, c12, 0 // read PMCR register
  88. orr r0, r0, #(0x1) // set E bit 0 to enable counter
  89. mcr p15, 0, r0, c9, c12, 0 // write r0
  90. mrc p15, 0, r0, c9, c12, 1 // read PMCNTENSET register
  91. orr r0, r0, #(0x1 << 31) // set bit 31 to enable counter
  92. mcr p15, 0, r0, c9, c12, 1 // write r0
  93. /*
  94. * Configure the intial catching of the interrupts
  95. */
  96. ldr r0, =SCR_RESET_VAL // IRQ and external ABT to monitor in secure mode
  97. mcr p15, 0, r0, c1, c1, 0
  98. b Reset_Handler
  99. #endif /* !defined(__DOXYGEN__) */
  100. /** @} */