Advertisement
Mike057

startup.c

Jun 8th, 2025
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.05 KB | None | 0 0
  1. /*
  2.  * Copyright 2013 - 2014, Freescale Semiconductor, Inc.
  3.  * Copyright 2016-2021, 2023 NXP
  4.  *                                                                                                                                                                                                                                                    
  5.  * SPDX-License-Identifier: BSD-3-Clause
  6.  */
  7.  
  8. /**
  9.  * @page misra_violations MISRA-C:2012 violations
  10.  *
  11.  * @section [global]
  12.  * Violates MISRA 2012 Advisory Rule 8.9, An object should be defined at block
  13.  * scope if its identifier only appears in a single function.
  14.  * All variables with this problem are defined in the linker files.
  15.  *
  16.  * @section [global]
  17.  * Violates MISRA 2012 Advisory Rule 8.11, When an array with external linkage
  18.  * is declared, its size should be explicitly specified.
  19.  * The size of the arrays can not be explicitly determined.
  20.  *
  21.  * @section [global]
  22.  * Violates MISRA 2012 Advisory Rule 11.4, A conversion should not be performed
  23.  * between a pointer to object and an integer type.
  24.  * The cast is required to initialize a pointer with an unsigned int define,
  25.  * representing an address.
  26.  *
  27.  * @section [global]
  28.  * Violates MISRA 2012 Required Rule 11.6, A cast shall not be performed
  29.  * between pointer to void and an arithmetic type.
  30.  * The cast is required to initialize a pointer with an unsigned int define,
  31.  * representing an address.
  32.  *
  33.  * @section [global]
  34.  * Violates MISRA 2012 Required Rule 2.1, A project shall not contain unreachable
  35.  * code.
  36.  * The condition compares two address defined in linker files that can be different.
  37.  *
  38.  * @section [global]
  39.  * Violates MISRA 2012 Advisory Rule 8.7, External could be made static.
  40.  * Function is defined for usage by application code.
  41.  *
  42.  * @section [global]
  43.  * Violates MISRA 2012 Mandatory Rule 17.3, Symbol 'MFSPR' undeclared, assumed
  44.  * to return int.
  45.  * This is an e200 Power Architecture Assembly instruction used to retrieve
  46.  * the core number.
  47.  *
  48.  */
  49.  
  50. #include "startup.h"
  51. #include <stdint.h>
  52.  
  53.  
  54. /*******************************************************************************
  55.  * Static Variables
  56.  ******************************************************************************/
  57. static volatile uint32_t * const s_vectors[NUMBER_OF_CORES] = FEATURE_INTERRUPT_INT_VECTORS;
  58.  
  59. /*******************************************************************************
  60.  * Code
  61.  ******************************************************************************/
  62.  
  63. /*FUNCTION**********************************************************************
  64.  *
  65.  * Function Name : init_data_bss
  66.  * Description   : Make necessary initializations for RAM.
  67.  * - Copy the vector table from ROM to RAM.
  68.  * - Copy initialized data from ROM to RAM.
  69.  * - Copy code that should reside in RAM from ROM
  70.  * - Clear the zero-initialized data section.
  71.  *
  72.  * Tool Chains:
  73.  *   __GNUC__           : GNU Compiler Collection
  74.  *   __ghs__            : Green Hills ARM Compiler
  75.  *   __ICCARM__         : IAR ARM Compiler
  76.  *   __DCC__            : Wind River Diab Compiler
  77.  *   __ARMCC_VERSION    : ARMC Compiler
  78.  *
  79.  * Implements    : init_data_bss_Activity
  80.  *END**************************************************************************/
  81. void init_data_bss(void)
  82. {
  83.     uint32_t n;
  84.     uint8_t coreId;
  85. /* For ARMC we are using the library method of initializing DATA, Custom Section and
  86.  * Code RAM sections so the below variables are not needed */
  87. #if !defined(__ARMCC_VERSION)
  88.     /* Declare pointers for various data sections. These pointers
  89.      * are initialized using values pulled in from the linker file */
  90.     uint8_t * data_ram;
  91.     uint8_t * code_ram;
  92.     uint8_t * bss_start;
  93.     uint8_t * custom_ram;
  94.     const uint8_t * data_rom, * data_rom_end;
  95.     const uint8_t * code_rom, * code_rom_end;
  96.     const uint8_t * bss_end;
  97.     const uint8_t * custom_rom, * custom_rom_end;
  98. #endif
  99.     /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
  100.  
  101. #if defined(__ARMCC_VERSION)
  102.     extern uint32_t __RAM_VECTOR_TABLE_SIZE;
  103.     extern uint32_t __VECTOR_ROM;
  104.     extern uint32_t __VECTOR_RAM;
  105. #else
  106.     extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
  107.     extern uint32_t __VECTOR_TABLE[];
  108.     extern uint32_t __VECTOR_RAM[];
  109. #endif
  110.     /* Get section information from linker files */
  111. #if defined(__ICCARM__)
  112.     /* Data */
  113.     data_ram        = __section_begin(".data");
  114.     data_rom        = __section_begin(".data_init");
  115.     data_rom_end    = __section_end(".data_init");
  116.  
  117.     /* CODE RAM */
  118.     #pragma section = "__CODE_ROM"
  119.     #pragma section = "__CODE_RAM"
  120.     code_ram        = __section_begin("__CODE_RAM");
  121.     code_rom        = __section_begin("__CODE_ROM");
  122.     code_rom_end    = __section_end("__CODE_ROM");
  123.  
  124.     /* BSS */
  125.     bss_start       = __section_begin(".bss");
  126.     bss_end         = __section_end(".bss");
  127.  
  128.     custom_ram      = __section_begin(".customSection");
  129.     custom_rom      = __section_begin(".customSection_init");
  130.     custom_rom_end  = __section_end(".customSection_init");
  131.  
  132. #elif defined (__ARMCC_VERSION)
  133.     /* VECTOR TABLE*/
  134.     uint8_t * vector_table_size = (uint8_t *)__RAM_VECTOR_TABLE_SIZE;
  135.     uint32_t * vector_rom    = (uint32_t *)__VECTOR_ROM;
  136.     uint32_t * vector_ram    = (uint32_t *)__VECTOR_RAM;
  137. #else
  138.     extern uint32_t __DATA_ROM[];
  139.     extern uint32_t __DATA_RAM[];
  140.     extern uint32_t __DATA_END[];
  141.  
  142.     extern uint32_t __CODE_RAM[];
  143.     extern uint32_t __CODE_ROM[];
  144.     extern uint32_t __CODE_END[];
  145.  
  146.     extern uint32_t __BSS_START[];
  147.     extern uint32_t __BSS_END[];
  148.  
  149.     extern uint32_t __CUSTOM_ROM[];
  150.     extern uint32_t __CUSTOM_END[];
  151.  
  152.     /* Data */
  153.     data_ram        = (uint8_t *)__DATA_RAM;
  154.     data_rom        = (uint8_t *)__DATA_ROM;
  155.     data_rom_end    = (uint8_t *)__DATA_END;
  156.     /* CODE RAM */
  157.     code_ram        = (uint8_t *)__CODE_RAM;
  158.     code_rom        = (uint8_t *)__CODE_ROM;
  159.     code_rom_end    = (uint8_t *)__CODE_END;
  160.     /* BSS */
  161.     bss_start       = (uint8_t *)__BSS_START;
  162.     bss_end         = (uint8_t *)__BSS_END;
  163.  
  164.     /* Custom section */
  165.     custom_ram      = CUSTOMSECTION_SECTION_START;
  166.     custom_rom      = (uint8_t *)__CUSTOM_ROM;
  167.     custom_rom_end  = (uint8_t *)__CUSTOM_END;
  168.  
  169. #endif
  170.  
  171. #if !defined(__ARMCC_VERSION)
  172.     /* Copy initialized data from ROM to RAM */
  173.     while (data_rom_end != data_rom)
  174.     {
  175.         *data_ram = *data_rom;
  176.         data_ram++;
  177.         data_rom++;
  178.     }
  179.  
  180.     /* Copy functions from ROM to RAM */
  181.     while (code_rom_end != code_rom)
  182.     {
  183.         *code_ram = *code_rom;
  184.         code_ram++;
  185.         code_rom++;
  186.     }
  187.  
  188.     /* Clear the zero-initialized data section */
  189.     while(bss_end != bss_start)
  190.     {
  191.         *bss_start = 0;
  192.         bss_start++;
  193.     }
  194.  
  195.     /* Copy customsection rom to ram */
  196.     while(custom_rom_end != custom_rom)
  197.     {
  198.         *custom_ram = *custom_rom;
  199.         custom_rom++;
  200.         custom_ram++;
  201.     }
  202. #endif
  203.     coreId = (uint8_t)GET_CORE_ID();
  204. #if defined (__ARMCC_VERSION)
  205.         /* Copy the vector table from ROM to RAM */
  206.                 /* Workaround */
  207.         for (n = 0; n < (((uint32_t)(vector_table_size))/sizeof(uint32_t)); n++)
  208.         {
  209.             vector_ram[n] = vector_rom[n];
  210.         }
  211.         /* Point the VTOR to the position of vector table */
  212.          *s_vectors[coreId] = (uint32_t) __VECTOR_RAM;
  213. #else
  214.     /* Check if VECTOR_TABLE copy is needed */
  215.     if (__VECTOR_RAM != __VECTOR_TABLE)
  216.     {
  217.         /* Copy the vector table from ROM to RAM */
  218.         for (n = 0; n < (((uint32_t)__RAM_VECTOR_TABLE_SIZE)/sizeof(uint32_t)); n++)
  219.         {
  220.             __VECTOR_RAM[n] = __VECTOR_TABLE[n];
  221.         }
  222.         /* Point the VTOR to the position of vector table */
  223.         *s_vectors[coreId] = (uint32_t)__VECTOR_RAM;
  224.     }
  225.     else
  226.     {
  227.         /* Point the VTOR to the position of vector table */
  228.         *s_vectors[coreId] = (uint32_t)__VECTOR_TABLE;
  229.     }
  230. #endif
  231.  
  232. }
  233.  
  234. /*******************************************************************************
  235.  * EOF
  236.  ******************************************************************************/
  237.  
  238.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement