S32 SDK
startup.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
55 #include "startup.h"
56 #include "device_registers.h"
57 #include <stdint.h>
58 
59 #if (defined(__ICCARM__))
60  #pragma section = ".data"
61  #pragma section = ".data_init"
62  #pragma section = ".bss"
63 #endif
64 
65 /*******************************************************************************
66  * Code
67  ******************************************************************************/
68 
69 /*FUNCTION**********************************************************************
70  *
71  * Function Name : init_data_bss
72  * Description : Make necessary initializations for RAM.
73  * - Copy the vector table from ROM to RAM.
74  * - Copy initialized data from ROM to RAM.
75  * - Copy code that should reside in RAM from ROM
76  * - Clear the zero-initialized data section.
77  *
78  * Tool Chains:
79  * __GNUC__ : GNU Compiler Collection
80  * __ghs__ : Green Hills ARM Compiler
81  * __ICCARM__ : IAR ARM Compiler
82  * __CSMC__ : Cosmic C Cross Compiler
83  * __DCC__ : Wind River Diab Compiler
84  *
85  * Implements : init_data_bss_Activity
86  *END**************************************************************************/
87 void init_data_bss(void)
88 {
89  uint32_t n;
90  /* Declare pointers for various data sections. These pointers
91  * are initialized using values pulled in from the linker file */
92  uint8_t * data_ram;
93  uint8_t * code_ram;
94  uint8_t * bss_start;
95  const uint8_t * data_rom, * data_rom_end;
96  const uint8_t * code_rom, * code_rom_end;
97  const uint8_t * bss_end;
98 
99  /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
100  extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
101  extern uint32_t __VECTOR_TABLE[];
102  extern uint32_t __VECTOR_RAM[];
103 
104  /* Get section information from linker files */
105 #if defined(__ICCARM__)
106  /* Data */
107  data_ram = __section_begin(".data");
108  data_rom = __section_begin(".data_init");
109  data_rom_end = __section_end(".data_init");
110 
111  /* CODE RAM */
112  #pragma section = "__CODE_ROM"
113  #pragma section = "__CODE_RAM"
114  code_ram = __section_begin("__CODE_RAM");
115  code_rom = __section_begin("__CODE_ROM");
116  code_rom_end = __section_end("__CODE_ROM");
117 
118  /* BSS */
119  bss_start = __section_begin(".bss");
120  bss_end = __section_end(".bss");
121 #else
122  extern uint32_t __DATA_ROM[];
123  extern uint32_t __DATA_RAM[];
124  extern uint32_t __DATA_END[];
125 
126  extern uint32_t __CODE_RAM[];
127  extern uint32_t __CODE_ROM[];
128  extern uint32_t __CODE_END[];
129 
130  extern uint32_t __BSS_START[];
131  extern uint32_t __BSS_END[];
132 
133  /* Data */
134  data_ram = (uint8_t *)__DATA_RAM;
135  data_rom = (uint8_t *)__DATA_ROM;
136  data_rom_end = (uint8_t *)__DATA_END;
137  /* CODE RAM */
138  code_ram = (uint8_t *)__CODE_RAM;
139  code_rom = (uint8_t *)__CODE_ROM;
140  code_rom_end = (uint8_t *)__CODE_END;
141  /* BSS */
142  bss_start = (uint8_t *)__BSS_START;
143  bss_end = (uint8_t *)__BSS_END;
144 #endif
145 
146  /* Check if VECTOR_TABLE copy is needed */
147  if (__VECTOR_RAM != __VECTOR_TABLE)
148  {
149  /* Copy the vector table from ROM to RAM */
150  for (n = 0; n < (((uint32_t)__RAM_VECTOR_TABLE_SIZE)/sizeof(uint32_t)); n++)
151  {
152  __VECTOR_RAM[n] = __VECTOR_TABLE[n];
153  }
154  /* Point the VTOR to the position of vector table */
155  S32_SCB->VTOR = (uint32_t)__VECTOR_RAM;
156  }
157  else
158  {
159  /* Point the VTOR to the position of vector table */
160  S32_SCB->VTOR = (uint32_t)__VECTOR_TABLE;
161  }
162 
163  /* Copy initialized data from ROM to RAM */
164  while (data_rom_end != data_rom)
165  {
166  *data_ram = *data_rom;
167  data_ram++;
168  data_rom++;
169  }
170 
171  /* Copy functions from ROM to RAM */
172  while (code_rom_end != code_rom)
173  {
174  *code_ram = *code_rom;
175  code_ram++;
176  code_rom++;
177  }
178 
179  /* Clear the zero-initialized data section */
180  while(bss_end != bss_start)
181  {
182  *bss_start = 0;
183  bss_start++;
184  }
185 }
186 
187 /*******************************************************************************
188  * EOF
189  ******************************************************************************/
190 
uint32_t __VECTOR_RAM[((uint32_t)(FEATURE_INTERRUPT_IRQ_MAX))+16U+1U]
Declaration of vector table. FEATURE_INTERRUPT_IRQ_MAX is the highest interrupt request number...
void init_data_bss(void)
Make necessary initializations for RAM.
Definition: startup.c:87
#define S32_SCB
Definition: S32K144.h:9795