LPC4300_Startup.s 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*****************************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. *****************************************************************************
  5. * *
  6. * (c) 2017 SEGGER Microcontroller GmbH & Co. KG *
  7. * *
  8. * Internet: www.segger.com Support: support@segger.com *
  9. * *
  10. *****************************************************************************/
  11. /*****************************************************************************
  12. * Preprocessor Definitions *
  13. * ------------------------ *
  14. * NO_FPU_ENABLE *
  15. * *
  16. * If defined, FPU will not be enabled. *
  17. * *
  18. * NO_STACK_INIT *
  19. * *
  20. * If defined, the stack pointer will not be initialised. *
  21. * *
  22. * NO_SYSTEM_INIT *
  23. * *
  24. * If defined, the SystemInit() function will not be called. By default *
  25. * SystemInit() is called after reset to enable the clocks and memories to *
  26. * be initialised prior to any C startup initialisation. *
  27. * *
  28. * NO_VTOR_CONFIG *
  29. * *
  30. * If defined, the vector table offset register will not be configured. *
  31. * *
  32. * MEMORY_INIT *
  33. * *
  34. * If defined, the MemoryInit() function will be called. By default *
  35. * MemoryInit() is called after SystemInit() to enable an external memory *
  36. * controller. *
  37. * *
  38. * STACK_INIT_VAL *
  39. * *
  40. * If defined, specifies the initial stack pointer value. If undefined, *
  41. * the stack pointer will be initialised to point to the end of the *
  42. * RAM segment. *
  43. * *
  44. * VECTORS_IN_RAM *
  45. * *
  46. * If defined, the exception vectors will be copied from Flash to RAM. *
  47. * *
  48. *****************************************************************************/
  49. .syntax unified
  50. .global Reset_Handler
  51. .extern _vectors
  52. .section .init, "ax"
  53. .thumb_func
  54. .equ VTOR_REG, 0xE000ED08
  55. .equ FPU_CPACR_REG, 0xE000ED88
  56. #ifndef STACK_INIT_VAL
  57. #define STACK_INIT_VAL __RAM_segment_end__
  58. #endif
  59. Reset_Handler:
  60. #ifndef NO_STACK_INIT
  61. /* Initialise main stack */
  62. ldr r0, =STACK_INIT_VAL
  63. ldr r1, =0x7
  64. bics r0, r1
  65. mov sp, r0
  66. #endif
  67. #ifndef NO_SYSTEM_INIT
  68. /* Initialise system */
  69. ldr r0, =SystemInit
  70. blx r0
  71. #endif
  72. #ifdef MEMORY_INIT
  73. ldr r0, =MemoryInit
  74. blx r0
  75. #endif
  76. #ifdef VECTORS_IN_RAM
  77. /* Copy exception vectors into RAM */
  78. ldr r0, =__vectors_start__
  79. ldr r1, =__vectors_end__
  80. ldr r2, =__vectors_ram_start__
  81. 1:
  82. cmp r0, r1
  83. beq 2f
  84. ldr r3, [r0]
  85. str r3, [r2]
  86. adds r0, r0, #4
  87. adds r2, r2, #4
  88. b 1b
  89. 2:
  90. #endif
  91. #ifndef NO_VTOR_CONFIG
  92. /* Configure vector table offset register */
  93. ldr r0, =VTOR_REG
  94. #ifdef VECTORS_IN_RAM
  95. ldr r1, =_vectors_ram
  96. #else
  97. ldr r1, =_vectors
  98. #endif
  99. str r1, [r0]
  100. #endif
  101. #if (defined(__ARM_ARCH_FPV4_SP_D16__) || defined(__ARM_ARCH_FPV5_D16__)) && !defined(NO_FPU_ENABLE)
  102. /* Enable FPU */
  103. ldr r0, =FPU_CPACR_REG
  104. ldr r1, [r0]
  105. orr r1, r1, #(0xF << 20)
  106. str r1, [r0]
  107. dsb
  108. isb
  109. #endif
  110. /* Jump to program start */
  111. b _start