1 //==========================================================================
5 // ColdFire architecture HAL startup code
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2006 eCosCentric Ltd.
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 // -------------------------------------------
37 //####ECOSGPLCOPYRIGHTEND####
38 //==========================================================================
39 //#####DESCRIPTIONBEGIN####
41 // Author(s): Enrico Piria
44 // Purpose: Architecture startup code.
45 // Description: This module contains code that sets up the hardware and the
46 // memory sections. All the code must be contained in the
47 // section called ".boot", in order for the ROMRAM startup
50 //####DESCRIPTIONEND####
51 //========================================================================
53 #include <pkgconf/hal.h>
54 #include <cyg/hal/hal_startup.h>
55 #include CYGHWR_MEMORY_LAYOUT_H
56 #include <cyg/hal/hal_if.h> // hal_if_init
57 #include <cyg/hal/hal_intr.h> // Interrupt definitions
58 #include <cyg/hal/hal_stub.h> // initialize_stub
60 externC void cyg_start(void);
61 externC void hal_ctrlc_isr_init(void);
63 static void hal_vsr_init(void) __attribute__ ((section (".boot")));
64 static void hal_isr_init(void) __attribute__ ((section (".boot")));
65 static void hal_init_ram_sections(void) __attribute__ ((section (".boot")));
66 static void cyg_hal_invoke_constructors(void) __attribute__ ((section (".boot")));
68 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
70 externC unsigned char __romram_copy_source[];
71 externC unsigned char __romram_copy_dest[];
72 externC unsigned char __romram_copy_length[];
77 // -------------------------------------------------------------------------
78 // Reset vector routine.
82 // Do any variant-specific reset initialization
85 // Do any platform-specific reset initialization
88 // Initialize the RAM sections that the rest of the C code requires
89 hal_init_ram_sections();
91 // All program sections are now in place
93 // Make sure that every instruction above this one has been output by
95 HAL_REORDER_BARRIER();
97 // Now it is safe to use a stack in RAM
98 asm volatile ("lea cyg_interrupt_stack, %sp");
100 // It is now safe to call C functions which may rely on initialized
105 // Initialize variant HAL private data
108 // Initialize platform HAL private data
111 // Initialize the virtual vector table
114 // Call C++ constructors
115 cyg_hal_invoke_constructors();
117 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
121 // Init Ctrl-C debug ISR
122 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) \
123 || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
124 hal_ctrlc_isr_init();
127 // Call cyg_start. This routine should not return.
132 // -------------------------------------------------------------------------
133 // Initialize the vector table.
135 static void hal_vsr_init(void)
139 // If we are starting up from ROM, or we are starting in
140 // RAM and NOT using a ROM monitor, initialize the VSR and ISR tables.
141 #if defined(CYG_HAL_STARTUP_ROM) || \
142 defined(CYG_HAL_STARTUP_ROMRAM) || \
143 (defined(CYG_HAL_STARTUP_RAM) && \
144 !defined(CYGSEM_HAL_USE_ROM_MONITOR))
146 // Initialize the HAL's vector table with the ROM vector table
147 for (i = 0; i < CYGNUM_HAL_VSR_COUNT; i++)
148 cyg_hal_vsr_table[i] = rom_vsr_table[i];
150 #elif defined(CYG_HAL_STARTUP_RAM) && defined(CYGSEM_HAL_USE_ROM_MONITOR)
152 // We only take control of the interrupt vectors,
153 // the rest are left to the ROM for now.
154 cyg_hal_vsr_table[CYGNUM_HAL_VECTOR_UNINITINT] =
155 rom_vsr_table[CYGNUM_HAL_VECTOR_UNINITINT];
157 cyg_hal_vsr_table[CYGNUM_HAL_VECTOR_SPURINT] =
158 rom_vsr_table[CYGNUM_HAL_VECTOR_SPURINT];
160 for(i = 0; i < CYGNUM_HAL_NUMAUTOVEC; i++)
161 cyg_hal_vsr_table[CYGNUM_HAL_VECTOR_AUTOVEC1 + i] =
162 rom_vsr_table[CYGNUM_HAL_VECTOR_AUTOVEC1 + i];
164 for(i = 0; i < CYGNUM_HAL_NUMUSERINTR; i++)
165 cyg_hal_vsr_table[CYGNUM_HAL_VECTOR_USERINTRFIRST + i] =
166 rom_vsr_table[CYGNUM_HAL_VECTOR_USERINTRFIRST + i];
172 // -------------------------------------------------------------------------
173 // Initialize the ISRs.
175 static void hal_isr_init(void)
179 // Initialize all ISR entries to default
180 for (i = 0; i < CYGNUM_HAL_ISR_COUNT; i++)
182 cyg_hal_interrupt_handlers[i] = (CYG_ADDRESS) &hal_default_isr;
183 cyg_hal_interrupt_data[i] = (CYG_ADDRWORD) 0;
184 cyg_hal_interrupt_objects[i] = (CYG_ADDRESS) 0;
189 // -------------------------------------------------------------------------
190 // Initialize the RAM sections
191 // For an efficient copy, we suppose that the sections are aligned at a
192 // 4-byte boundary and are a multiple of 4 bytes. Linker scripts should
195 static void hal_init_ram_sections(void)
199 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
201 // Initialize the RAM data section from the ROM image of the data
203 cyg_uint32 *p = (cyg_uint32 *) __romram_copy_dest;
204 cyg_uint32 *q = (cyg_uint32 *) __romram_copy_source;
205 cyg_uint32 length = 0;
207 while (length < (cyg_uint32) __romram_copy_length)
215 // Initialize the bss sections to zero
216 m = (cyg_uint32 *) __bss_start;
217 while (m != (cyg_uint32 *) __bss_end)
222 // -------------------------------------------------------------------------
223 // Call static constructors.
225 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
226 cyg_bool cyg_hal_stop_constructors;
229 typedef void (*pfunc) (void);
230 extern pfunc __CTOR_LIST__[];
231 extern pfunc __CTOR_END__[];
233 static void cyg_hal_invoke_constructors(void)
235 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
236 static pfunc *p = &__CTOR_END__[-1];
238 cyg_hal_stop_constructors = 0;
239 for (; p >= __CTOR_LIST__; p--) {
241 if (cyg_hal_stop_constructors) {
249 for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)