]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/coldfire/arch/v2_0/src/hal_startup.c
Initial revision
[karo-tx-redboot.git] / packages / hal / coldfire / arch / v2_0 / src / hal_startup.c
1 //==========================================================================
2 //
3 //      hal_startup.c
4 //
5 //      ColdFire architecture HAL startup code
6 //
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.
13 //
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.
17 //
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
21 // for more details.
22 //
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.
26 //
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.
33 //
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####
40 //
41 // Author(s):     Enrico Piria
42 // Contributors:
43 // Date:          2005-25-06
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
48 //                to work properly.
49 //
50 //####DESCRIPTIONEND####
51 //========================================================================
52
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
59
60 externC void cyg_start(void);
61 externC void hal_ctrlc_isr_init(void);
62
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")));
67
68 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
69
70 externC unsigned char __romram_copy_source[];
71 externC unsigned char __romram_copy_dest[];
72 externC unsigned char __romram_copy_length[];
73
74 #endif
75
76
77 // -------------------------------------------------------------------------
78 // Reset vector routine.
79
80 void hal_reset(void)
81 {
82     // Do any variant-specific reset initialization
83     var_reset();
84
85     // Do any platform-specific reset initialization
86     plf_reset();
87
88     // Initialize the RAM sections that the rest of the C code requires
89     hal_init_ram_sections();
90
91     // All program sections are now in place
92
93     // Make sure that every instruction above this one has been output by
94     // the compiler
95     HAL_REORDER_BARRIER();
96
97     // Now it is safe to use a stack in RAM
98     asm volatile ("lea cyg_interrupt_stack, %sp");
99    
100     // It is now safe to call C functions which may rely on initialized
101     // data
102     hal_vsr_init();
103     hal_isr_init();
104
105     // Initialize variant HAL private data
106     var_init_data();
107
108     // Initialize platform HAL private data
109     plf_init_data();
110
111     // Initialize the virtual vector table
112     hal_if_init();
113
114     // Call C++ constructors
115     cyg_hal_invoke_constructors();
116
117 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
118     initialize_stub();
119 #endif
120
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();
125 #endif
126
127     // Call cyg_start. This routine should not return.
128     cyg_start();
129 }
130
131
132 // -------------------------------------------------------------------------
133 // Initialize the vector table.
134
135 static void hal_vsr_init(void)
136 {
137     unsigned int i;
138     
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))
145
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];
149
150 #elif defined(CYG_HAL_STARTUP_RAM) && defined(CYGSEM_HAL_USE_ROM_MONITOR)
151
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];
156
157     cyg_hal_vsr_table[CYGNUM_HAL_VECTOR_SPURINT] =
158         rom_vsr_table[CYGNUM_HAL_VECTOR_SPURINT];
159
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];
163     
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];
167
168 #endif
169 }
170
171
172 // -------------------------------------------------------------------------
173 // Initialize the ISRs.
174
175 static void hal_isr_init(void)
176 {
177     int i;
178
179     // Initialize all ISR entries to default
180     for (i = 0; i < CYGNUM_HAL_ISR_COUNT; i++)
181     {
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;
185     }
186 }
187
188
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
193 // guarantee this.
194
195 static void hal_init_ram_sections(void)
196 {
197     cyg_uint32 *m;
198
199 #if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
200     {
201         // Initialize the RAM data section from the ROM image of the data
202         // section.
203         cyg_uint32 *p = (cyg_uint32 *) __romram_copy_dest;
204         cyg_uint32 *q = (cyg_uint32 *) __romram_copy_source;
205         cyg_uint32 length = 0;
206
207         while (length < (cyg_uint32) __romram_copy_length)
208         {
209             *p++ = *q++;
210             length += 4;
211         }
212     }       
213 #endif
214
215     // Initialize the bss sections to zero
216     m = (cyg_uint32 *) __bss_start;
217     while (m != (cyg_uint32 *) __bss_end)
218         *m++ = 0x0;
219 }
220
221
222 // -------------------------------------------------------------------------
223 // Call static constructors.
224
225 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
226 cyg_bool cyg_hal_stop_constructors;
227 #endif
228
229 typedef void (*pfunc) (void);
230 extern pfunc __CTOR_LIST__[];
231 extern pfunc __CTOR_END__[];
232
233 static void cyg_hal_invoke_constructors(void)
234 {
235 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
236     static pfunc *p = &__CTOR_END__[-1];
237
238     cyg_hal_stop_constructors = 0;
239     for (; p >= __CTOR_LIST__; p--) {
240         (*p) ();
241         if (cyg_hal_stop_constructors) {
242             p--;
243             break;
244         }
245     }
246 #else
247     pfunc *p;
248
249     for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
250         (*p) ();
251 #endif
252 }