startup_ARMCA7.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /******************************************************************************
  2. * @file startup_ARMCA7.c
  3. * @brief CMSIS Device System Source File for Arm Cortex-A7 Device Series
  4. * @version V1.00
  5. * @date 10. January 2018
  6. *
  7. * @note
  8. *
  9. ******************************************************************************/
  10. /*
  11. * Copyright (c) 2009-2018 Arm Limited. All rights reserved.
  12. *
  13. * SPDX-License-Identifier: Apache-2.0
  14. *
  15. * Licensed under the Apache License, Version 2.0 (the License); you may
  16. * not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing, software
  22. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  23. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the License for the specific language governing permissions and
  25. * limitations under the License.
  26. */
  27. #include <ARMCA7.h>
  28. /*----------------------------------------------------------------------------
  29. Definitions
  30. *----------------------------------------------------------------------------*/
  31. #define USR_MODE 0x10 // User mode
  32. #define FIQ_MODE 0x11 // Fast Interrupt Request mode
  33. #define IRQ_MODE 0x12 // Interrupt Request mode
  34. #define SVC_MODE 0x13 // Supervisor mode
  35. #define ABT_MODE 0x17 // Abort mode
  36. #define UND_MODE 0x1B // Undefined Instruction mode
  37. #define SYS_MODE 0x1F // System mode
  38. /*----------------------------------------------------------------------------
  39. Internal References
  40. *----------------------------------------------------------------------------*/
  41. void Vectors (void) __attribute__ ((section("RESET")));
  42. void Reset_Handler (void);
  43. /*----------------------------------------------------------------------------
  44. Exception / Interrupt Handler
  45. *----------------------------------------------------------------------------*/
  46. void Undef_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  47. void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  48. void PAbt_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  49. void DAbt_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  50. void IRQ_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  51. void FIQ_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
  52. /*----------------------------------------------------------------------------
  53. Exception / Interrupt Vector Table
  54. *----------------------------------------------------------------------------*/
  55. __ASM void Vectors(void) {
  56. PRESERVE8
  57. IMPORT Undef_Handler
  58. IMPORT SVC_Handler
  59. IMPORT PAbt_Handler
  60. IMPORT DAbt_Handler
  61. IMPORT IRQ_Handler
  62. IMPORT FIQ_Handler
  63. LDR PC, =Reset_Handler
  64. LDR PC, =Undef_Handler
  65. LDR PC, =SVC_Handler
  66. LDR PC, =PAbt_Handler
  67. LDR PC, =DAbt_Handler
  68. NOP
  69. LDR PC, =IRQ_Handler
  70. LDR PC, =FIQ_Handler
  71. }
  72. /*----------------------------------------------------------------------------
  73. Reset Handler called on controller reset
  74. *----------------------------------------------------------------------------*/
  75. __ASM void Reset_Handler(void) {
  76. PRESERVE8
  77. // Mask interrupts
  78. CPSID if
  79. // Put any cores other than 0 to sleep
  80. MRC p15, 0, R0, c0, c0, 5 // Read MPIDR
  81. ANDS R0, R0, #3
  82. goToSleep
  83. WFINE
  84. BNE goToSleep
  85. // Reset SCTLR Settings
  86. MRC p15, 0, R0, c1, c0, 0 // Read CP15 System Control register
  87. BIC R0, R0, #(0x1 << 12) // Clear I bit 12 to disable I Cache
  88. BIC R0, R0, #(0x1 << 2) // Clear C bit 2 to disable D Cache
  89. BIC R0, R0, #0x1 // Clear M bit 0 to disable MMU
  90. BIC R0, R0, #(0x1 << 11) // Clear Z bit 11 to disable branch prediction
  91. BIC R0, R0, #(0x1 << 13) // Clear V bit 13 to disable hivecs
  92. MCR p15, 0, R0, c1, c0, 0 // Write value back to CP15 System Control register
  93. ISB
  94. // Configure ACTLR
  95. MRC p15, 0, r0, c1, c0, 1 // Read CP15 Auxiliary Control Register
  96. ORR r0, r0, #(1 << 1) // Enable L2 prefetch hint (UNK/WI since r4p1)
  97. MCR p15, 0, r0, c1, c0, 1 // Write CP15 Auxiliary Control Register
  98. // Set Vector Base Address Register (VBAR) to point to this application's vector table
  99. LDR R0, =Vectors
  100. MCR p15, 0, R0, c12, c0, 0
  101. // Setup Stack for each exceptional mode
  102. IMPORT |Image$$FIQ_STACK$$ZI$$Limit|
  103. IMPORT |Image$$IRQ_STACK$$ZI$$Limit|
  104. IMPORT |Image$$SVC_STACK$$ZI$$Limit|
  105. IMPORT |Image$$ABT_STACK$$ZI$$Limit|
  106. IMPORT |Image$$UND_STACK$$ZI$$Limit|
  107. IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
  108. CPS #0x11
  109. LDR SP, =|Image$$FIQ_STACK$$ZI$$Limit|
  110. CPS #0x12
  111. LDR SP, =|Image$$IRQ_STACK$$ZI$$Limit|
  112. CPS #0x13
  113. LDR SP, =|Image$$SVC_STACK$$ZI$$Limit|
  114. CPS #0x17
  115. LDR SP, =|Image$$ABT_STACK$$ZI$$Limit|
  116. CPS #0x1B
  117. LDR SP, =|Image$$UND_STACK$$ZI$$Limit|
  118. CPS #0x1F
  119. LDR SP, =|Image$$ARM_LIB_STACK$$ZI$$Limit|
  120. // Call SystemInit
  121. IMPORT SystemInit
  122. BL SystemInit
  123. // Unmask interrupts
  124. CPSIE if
  125. // Call __main
  126. IMPORT __main
  127. BL __main
  128. }
  129. /*----------------------------------------------------------------------------
  130. Default Handler for Exceptions / Interrupts
  131. *----------------------------------------------------------------------------*/
  132. void Default_Handler(void) {
  133. while(1);
  134. }