]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/synth/arch/v2_0/src/synth_entry.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / hal / synth / arch / v2_0 / src / synth_entry.c
1 //==========================================================================
2 //
3 //      synth_entry.c
4 //
5 //      Entry code for Linux synthetic target.
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2002, 2005 Bart Veer
12 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
43 //
44 // Author(s):   proven
45 // Contributors:proven, jskov, bartv
46 // Date:        1999-01-06
47 // Purpose:     Entry point for Linux synthetic target.
48 //
49 //####DESCRIPTIONEND####
50 //
51 //=========================================================================
52
53 #include <pkgconf/system.h>
54 #include <pkgconf/hal.h>
55 #include <cyg/infra/cyg_type.h>
56 #include <cyg/infra/cyg_ass.h>
57 #include <cyg/infra/diag.h>
58 #include <cyg/hal/hal_arch.h>
59 #include <cyg/hal/hal_intr.h>
60 #include <cyg/hal/hal_io.h>
61 #include CYGHWR_MEMORY_LAYOUT_H
62
63 /*------------------------------------------------------------------------*/
64 /* C++ support - run initial constructors                                 */
65
66 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
67 cyg_bool cyg_hal_stop_constructors;
68 #endif
69
70 typedef void (*pfunc) (void);
71 extern pfunc __CTOR_LIST__[];
72 extern pfunc __CTOR_END__[];
73
74 void
75 cyg_hal_invoke_constructors (void)
76 {
77 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
78     static pfunc *p = &__CTOR_END__[-1];
79     
80     cyg_hal_stop_constructors = 0;
81     for (; p >= __CTOR_LIST__; p--) {
82         (*p) ();
83         if (cyg_hal_stop_constructors) {
84             p--;
85             break;
86         }
87     }
88 #else
89     pfunc *p;
90
91     for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
92         (*p) ();
93 #endif
94 }
95
96 // ----------------------------------------------------------------------------
97 // The low-level entry point is platform-specific, typically in the
98 // assember file vectors.S. However that entry point simply jumps
99 // directly here, with no further processing or stack manipulation.
100 // The HAL specification defines clearly what should happen during
101 // startup.
102
103 externC void    cyg_start( void );
104 externC void    synth_hardware_init(void);
105 externC void    synth_hardware_init2(void);
106
107 void _linux_entry( void )
108 {
109     // "Initialize various cpu status registers, including disabling interrupts."
110     // That is a no-op for the synthetic target, in particular interrupts are
111     // already disabled.
112
113     // "Set up any CPU memory controller to access ROM, RAM, and I/O
114     // devices correctly". The ROM and RAM are set up via the linker
115     // script and taken care of automatically during loading. There
116     // are no memory-mapped devices. Arguably the auxiliary should be
117     // started up here, but instead that is left to platform
118     // initialization.
119
120     // "Enable the cache". Effectively the synthetic target has no cache,
121     // anything provided by the hardware is not readily accessible.
122
123     // "Set up the stack pointer". The system starts up a program with a
124     // suitable stack.
125
126     // "Initialize any global pointer register". There is no such register.
127
128     // Perform platform-specific initialization. Actually, all Linux
129     // platforms can share this. It involves setting up signal handlers,
130     // starting the I/O auxiliary, and so on.
131     synth_hardware_init();
132
133     // This is not a ROM startup, so no need to worry about copying the
134     // .data section.
135
136     // "Zero the .bss section". Linux will have done this for us.
137
138     // "Create a suitable C stack frame". Already done.
139
140     // Invoke the C++ constructors.
141     cyg_hal_invoke_constructors();
142
143     // Once the C++ constructors have been invoked, a second stage
144     // of hardware initialization is desirable. At this point all
145     // eCos device drivers should have been initialized so the
146     // I/O auxiliary will have loaded the appropriate support
147     // scripts, and the auxiliary can now map the window(s) on to
148     // the display and generally operate normally.
149     synth_hardware_init2();
150     
151     // "Call cyg_start()". OK.
152     cyg_start();
153
154     // "Drop into an infinite loop". Not a good idea for the synthetic
155     // target. Instead, exit.
156     cyg_hal_sys_exit(0);
157 }
158
159 // ----------------------------------------------------------------------------
160 // Stub functions needed for linking with various versions of gcc
161 // configured for Linux rather than i386-elf.
162
163 #if (__GNUC__ < 3)
164 // 2.95.x libgcc.a __pure_virtual() calls __write().
165 int __write(void)
166 {
167     return -1;
168 }
169 #endif
170
171 #if (__GNUC__ >= 3)
172 // Versions of gcc/g++ after 3.0 (approx.), when configured for Linux
173 // native development (specifically, --with-__cxa_enable), have
174 // additional dependencies related to the destructors for static
175 // objects. When compiling C++ code with static objects the compiler
176 // inserts a call to __cxa_atexit() with __dso_handle as one of the
177 // arguments. __cxa_atexit() would normally be provided by glibc, and
178 // __dso_handle is part of crtstuff.c. Synthetic target applications
179 // are linked rather differently, so either a differently-configured
180 // compiler is needed or dummy versions of these symbols should be
181 // provided. If these symbols are not actually used then providing
182 // them is still harmless, linker garbage collection will remove them.
183
184 void
185 __cxa_atexit(void (*arg1)(void*), void* arg2, void* arg3)
186 {
187 }
188 void*   __dso_handle = (void*) &__dso_handle;
189
190 // gcc 3.2.2 (approx). The libsupc++ version of the new operator pulls
191 // in exception handling code, even when using the nothrow version and
192 // building with -fno-exceptions. libgcc_eh.a provides the necessary
193 // functions, but requires a dl_iterate_phdr() function. That is related
194 // to handling dynamically loaded code so is not applicable to eCos.
195 int
196 dl_iterate_phdr(void* arg1, void* arg2)
197 {
198     return -1;
199 }
200 #endif
201
202 #if (__GNUC__ >= 4)
203 // First noticed with gcc 4.1.1. There is now code to detect stack
204 // smashing.
205 void __attribute__ ((noreturn))
206 __stack_chk_fail_local(void)
207 {
208     CYG_FAIL("Stack smashing detected, aborting");
209     diag_printf("Application error: stack smashing detected.\n");
210     cyg_hal_sys_exit(1);
211     for (;;);
212 }
213 // Another symbol which indicates a similar problem occurred.
214 void __stack_chk_fail(void)
215 {
216   __stack_chk_fail_local();
217 }
218 #endif
219
220 //-----------------------------------------------------------------------------
221 // End of entry.c