3 * Purpose: Generic Kinetis startup code
\r
11 #pragma section = ".data"
\r
12 #pragma section = ".data_init"
\r
13 #pragma section = ".bss"
\r
14 #pragma section = "CodeRelocate"
\r
15 #pragma section = "CodeRelocateRam"
\r
18 /********************************************************************/
\r
20 common_startup(void)
\r
24 extern char __START_BSS[];
\r
25 extern char __END_BSS[];
\r
26 extern uint32 __DATA_ROM[];
\r
27 extern uint32 __DATA_RAM[];
\r
28 extern char __DATA_END[];
\r
31 /* Declare a counter we'll use in all of the copy loops */
\r
34 /* Declare pointers for various data sections. These pointers
\r
35 * are initialized using values pulled in from the linker file
\r
37 uint8 * data_ram, * data_rom, * data_rom_end;
\r
38 uint8 * bss_start, * bss_end;
\r
41 /* Get the addresses for the .data section (initialized data section) */
\r
43 data_ram = (uint8 *)__DATA_RAM;
\r
44 data_rom = (uint8 *)__DATA_ROM;
\r
45 data_rom_end = (uint8 *)__DATA_END; /* This is actually a RAM address in CodeWarrior */
\r
46 n = data_rom_end - data_ram;
\r
47 #elif (defined(IAR))
\r
48 data_ram = __section_begin(".data");
\r
49 data_rom = __section_begin(".data_init");
\r
50 data_rom_end = __section_end(".data_init");
\r
51 n = data_rom_end - data_rom;
\r
54 /* Copy initialized data from ROM to RAM */
\r
56 *data_ram++ = *data_rom++;
\r
59 /* Get the addresses for the .bss section (zero-initialized data) */
\r
61 bss_start = (uint8 *)__START_BSS;
\r
62 bss_end = (uint8 *)__END_BSS;
\r
63 #elif (defined(IAR))
\r
64 bss_start = __section_begin(".bss");
\r
65 bss_end = __section_end(".bss");
\r
71 /* Clear the zero-initialized data section */
\r
72 n = bss_end - bss_start;
\r
76 /* Get addresses for any code sections that need to be copied from ROM to RAM.
\r
77 * The IAR tools have a predefined keyword that can be used to mark individual
\r
78 * functions for execution from RAM. Add "__ramfunc" before the return type in
\r
79 * the function prototype for any routines you need to execute from RAM instead
\r
80 * of ROM. ex: __ramfunc void foo(void);
\r
83 uint8* code_relocate_ram = __section_begin("CodeRelocateRam");
\r
84 uint8* code_relocate = __section_begin("CodeRelocate");
\r
85 uint8* code_relocate_end = __section_end("CodeRelocate");
\r
87 /* Copy functions from ROM to RAM */
\r
88 n = code_relocate_end - code_relocate;
\r
90 *code_relocate_ram++ = *code_relocate++;
\r
93 /********************************************************************/
\r