hdarwin

MSP430_boot.c

Jul 21st, 2014
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.76 KB | None | 0 0
  1. /*****************************************************************************/
  2. /* BOOT.C   v4.3.2 - Initialize the MSP430 C runtime environment             */
  3. /*                                                                           */
  4. /* Copyright (c) 2003-2014 Texas Instruments Incorporated                    */
  5. /* http://www.ti.com/                                                        */
  6. /*                                                                           */
  7. /*  Redistribution and  use in source  and binary forms, with  or without    */
  8. /*  modification,  are permitted provided  that the  following conditions    */
  9. /*  are met:                                                                 */
  10. /*                                                                           */
  11. /*     Redistributions  of source  code must  retain the  above copyright    */
  12. /*     notice, this list of conditions and the following disclaimer.         */
  13. /*                                                                           */
  14. /*     Redistributions in binary form  must reproduce the above copyright    */
  15. /*     notice, this  list of conditions  and the following  disclaimer in    */
  16. /*     the  documentation  and/or   other  materials  provided  with  the    */
  17. /*     distribution.                                                         */
  18. /*                                                                           */
  19. /*     Neither the  name of Texas Instruments Incorporated  nor the names    */
  20. /*     of its  contributors may  be used to  endorse or  promote products    */
  21. /*     derived  from   this  software  without   specific  prior  written    */
  22. /*     permission.                                                           */
  23. /*                                                                           */
  24. /*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS    */
  25. /*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT    */
  26. /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    */
  27. /*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT    */
  28. /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
  29. /*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT    */
  30. /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    */
  31. /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY    */
  32. /*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT    */
  33. /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE    */
  34. /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
  35. /*                                                                           */
  36. /*****************************************************************************/
  37. #include <stdlib.h>
  38. #include <_lock.h>
  39.  
  40. extern int _args_main();
  41. extern int main(int argc);
  42. extern void exit(int status);
  43. extern void _auto_init();
  44. extern void __interrupt _c_int00();
  45. extern void __interrupt _c_int00_noargs();
  46. extern void __interrupt _c_int00_noinit();
  47. extern void __interrupt _c_int00_noexit();
  48. extern void __interrupt _c_int00_noinit_noexit();
  49. extern void __interrupt _c_int00_mpu_init();
  50. extern void __interrupt _c_int00_noargs_mpu_init();
  51. extern void __interrupt _c_int00_noinit_mpu_init();
  52. extern void __interrupt _c_int00_noexit_mpu_init();
  53. extern void __interrupt _c_int00_noinit_noexit_mpu_init();
  54. extern int  _system_pre_init(void);
  55. extern void __mpu_init(void);
  56.  
  57. void              (*__TI_cleanup_ptr)(void);
  58. void _DATA_ACCESS (*__TI_dtors_ptr)(int);
  59.  
  60. /*---------------------------------------------------------------------------*/
  61. /* Allocate the memory for the system stack.  This section will be sized     */
  62. /* by the linker.                                                            */
  63. /*---------------------------------------------------------------------------*/
  64. __asm("\t.global __STACK_END");
  65. #pragma DATA_SECTION (_stack, ".stack");
  66. #if defined(__LARGE_DATA_MODEL__)
  67. long _stack;
  68. #else
  69. int _stack;
  70. #endif
  71.  
  72. /*---------------------------------------------------------------------------*/
  73. /*  Initialize reset vector to point at _c_int00                             */
  74. /*  _c_int00 must always be located in low-memory on MSP430X devices.        */
  75. /*---------------------------------------------------------------------------*/
  76. #if defined(__LARGE_CODE_MODEL__)
  77. _Pragma("CODE_SECTION(_c_int00, \".text:_isr\")")
  78. _Pragma("CODE_SECTION(_c_int00_noargs, \".text:_isr\")")
  79. _Pragma("CODE_SECTION(_c_int00_noinit, \".text:_isr\")")
  80. _Pragma("CODE_SECTION(_c_int00_noexit, \".text:_isr\")")
  81. _Pragma("CODE_SECTION(_c_int00_noinit_noexit, \".text:_isr\")")
  82. _Pragma("CODE_SECTION(_c_int00_mpu_init, \".text:_isr\")")
  83. _Pragma("CODE_SECTION(_c_int00_noargs_mpu_init, \".text:_isr\")")
  84. _Pragma("CODE_SECTION(_c_int00_noinit_mpu_init, \".text:_isr\")")
  85. _Pragma("CODE_SECTION(_c_int00_noexit_mpu_init, \".text:_isr\")")
  86. _Pragma("CODE_SECTION(_c_int00_noinit_noexit_mpu_init, \".text:_isr\")")
  87. #endif
  88.  
  89. __asm("\t.global _reset_vector");
  90. __asm("\t.sect   \".reset\"");
  91. __asm("\t.align  2");
  92. __asm("_reset_vector:\n\t.field _c_int00, 16");
  93.  
  94. /*---------------------------------------------------------------------------*/
  95. /* Macro to initialize stack pointer.  Stack grows towards lower memory.     */
  96. /*---------------------------------------------------------------------------*/
  97. #if defined(__LARGE_DATA_MODEL__)
  98. #define STACK_INIT() __asm("\t   MOVX.A\t   #__STACK_END,SP")
  99. #else
  100. #define STACK_INIT() __asm("\t   MOV.W\t    #__STACK_END,SP")
  101. #endif
  102.  
  103. /*---------------------------------------------------------------------------*/
  104. /* Macros to initialize required global variables.                           */
  105. /*---------------------------------------------------------------------------*/
  106. #if defined(__TI_EABI__)
  107. #define INIT_EXIT_PTRS() do { } while(0)
  108. #define INIT_LOCKS()     do { } while(0)
  109. #else
  110. #define INIT_EXIT_PTRS() do { __TI_cleanup_ptr = NULL; __TI_dtors_ptr = NULL; } while(0)
  111. #define INIT_LOCKS()     do { _lock = _nop; _unlock = _nop; } while(0)
  112. #endif
  113.  
  114. /*****************************************************************************/
  115. /* C_INT00() - C ENVIRONMENT ENTRY POINT                                     */
  116. /*****************************************************************************/
  117. #pragma CLINK(_c_int00)
  118. extern void __interrupt _c_int00()
  119. {
  120.    STACK_INIT();
  121.    
  122.    INIT_EXIT_PTRS();
  123.    INIT_LOCKS();
  124.  
  125.    /*------------------------------------------------------------------------*/
  126.    /* Allow for any application-specific low level initialization prior to   */
  127.    /* initializing the C/C++ environment (global variable initialization,    */
  128.    /* constructers).  If _system_pre_init() returns 0, then bypass C/C++     */
  129.    /* initialization.  NOTE: BYPASSING THE CALL TO THE C/C++ INITIALIZATION  */
  130.    /* ROUTINE MAY RESULT IN PROGRAM FAILURE.                                 */
  131.    /*------------------------------------------------------------------------*/
  132.    if(_system_pre_init() != 0)  _auto_init();
  133.  
  134.    /*------------------------------------------------------------------------*/
  135.    /* Handle any argc/argv arguments if supported by an MSP430 loader.       */
  136.    /*------------------------------------------------------------------------*/
  137.    _args_main();
  138.  
  139.    exit(1);
  140. }
  141.  
  142.  
  143. /*****************************************************************************/
  144. /* C_INT00_NOARGS() - Specialized version of _c_int00 that does not handle   */
  145. /*                    arguments passed to main.                              */
  146. /*****************************************************************************/
  147. #pragma CLINK(_c_int00_noargs)
  148. extern void __interrupt _c_int00_noargs()
  149. {
  150.    STACK_INIT();
  151.    INIT_EXIT_PTRS();
  152.    INIT_LOCKS();
  153.    if(_system_pre_init() != 0) _auto_init();
  154.    main(0);
  155.    exit(1);
  156. }
  157.  
  158. /*****************************************************************************/
  159. /* C_INT00_NOINIT() - Specialized version of _c_int00 that does not perform  */
  160. /*                    auto initialization.                                   */
  161. /*****************************************************************************/
  162. #pragma CLINK(_c_int00_noinit)
  163. extern void __interrupt _c_int00_noinit()
  164. {
  165.    STACK_INIT();
  166.    INIT_EXIT_PTRS();
  167.    INIT_LOCKS();
  168.    _system_pre_init();
  169.    _args_main();
  170.    exit(1);
  171. }
  172.  
  173. /*****************************************************************************/
  174. /* C_INT00_NOEXIT() - Specialized version of _c_int00 that directly calls    */
  175. /*                    abort and skips cleanup in exit.                       */
  176. /*****************************************************************************/
  177. #pragma CLINK(_c_int00_noexit)
  178. extern void __interrupt _c_int00_noexit()
  179. {
  180.    STACK_INIT();
  181.    INIT_LOCKS();
  182.    if(_system_pre_init() != 0) _auto_init();
  183.    main(0);
  184.    abort();
  185. }
  186.  
  187. /*****************************************************************************/
  188. /* C_INT00_NOINIT_NOEXIT() - Specialized version of _c_int00 that does not   */
  189. /*                           perform auto initialization and calls abort     */
  190. /*                           directly.                                       */
  191. /*****************************************************************************/
  192. #pragma CLINK(_c_int00_noinit_noexit)
  193. extern void __interrupt _c_int00_noinit_noexit()
  194. {
  195.    STACK_INIT();
  196.    INIT_LOCKS();
  197.    _system_pre_init();
  198.    main(0);
  199.    abort();
  200. }
  201.  
  202. /*****************************************************************************/
  203. /* C_INT00_MPU_INIT() - Specialized version of _c_int00 that initializes the */
  204. /*                      FRAM memory protection unit.                         */
  205. /*****************************************************************************/
  206. #pragma CLINK(_c_int00_mpu_init)
  207. extern void __interrupt _c_int00_mpu_init()
  208. {
  209.    __mpu_init();
  210.    STACK_INIT();
  211.    INIT_EXIT_PTRS();
  212.    INIT_LOCKS();
  213.    if(_system_pre_init() != 0)  _auto_init();
  214.    _args_main();
  215.    exit(1);
  216. }
  217.  
  218. /*****************************************************************************/
  219. /* C_INT00_NOARGS_MPU_INIT() - Specialized version of _c_int00 that          */
  220. /*                             initializes the FRAM memory protection unit   */
  221. /*                             and does not handle arguments passed to main. */
  222. /*****************************************************************************/
  223. #pragma CLINK(_c_int00_noargs_mpu_init)
  224. extern void __interrupt _c_int00_noargs_mpu_init()
  225. {
  226.    __mpu_init();
  227.    STACK_INIT();
  228.    INIT_EXIT_PTRS();
  229.    INIT_LOCKS();
  230.    if(_system_pre_init() != 0) _auto_init();
  231.    main(0);
  232.    exit(1);
  233. }
  234.  
  235. /*****************************************************************************/
  236. /* C_INT00_NOINIT_MPU_INIT() - Specialized version of _c_int00 that          */
  237. /*                             initializes the FRAM memory protection unit   */
  238. /*                             and does not perform auto initialization.     */
  239. /*****************************************************************************/
  240. #pragma CLINK(_c_int00_noinit_mpu_init)
  241. extern void __interrupt _c_int00_noinit_mpu_init()
  242. {
  243.    __mpu_init();
  244.    STACK_INIT();
  245.    INIT_EXIT_PTRS();
  246.    INIT_LOCKS();
  247.    _system_pre_init();
  248.    _args_main();
  249.    exit(1);
  250. }
  251.  
  252. /*****************************************************************************/
  253. /* C_INT00_NOEXIT_MPU_INIT() - Specialized version of _c_int00 that          */
  254. /*                             initializes the FRAM memory protection unit   */
  255. /*                             and directly calls abort and skips cleanup in */
  256. /*                             exit.                                         */
  257. /*****************************************************************************/
  258. #pragma CLINK(_c_int00_noexit_mpu_init)
  259. extern void __interrupt _c_int00_noexit_mpu_init()
  260. {
  261.    __mpu_init();
  262.    STACK_INIT();
  263.    INIT_LOCKS();
  264.    if(_system_pre_init() != 0) _auto_init();
  265.    main(0);
  266.    abort();
  267. }
  268.  
  269. /*****************************************************************************/
  270. /* C_INT00_NOINIT_NOEXIT_MPU_INIT() - Specialized version of _c_int00 that   */
  271. /*                                    initializes the FRAM memory protection */
  272. /*                                    unit and does not perform auto         */
  273. /*                                    initialization and calls abort         */
  274. /*                                    directly.                              */
  275. /*****************************************************************************/
  276. #pragma CLINK(_c_int00_noinit_noexit_mpu_init)
  277. extern void __interrupt _c_int00_noinit_noexit_mpu_init()
  278. {
  279.    __mpu_init();
  280.    STACK_INIT();
  281.    INIT_LOCKS();
  282.    _system_pre_init();
  283.    main(0);
  284.    abort();
  285. }
Advertisement
Add Comment
Please, Sign In to add comment