1 //==========================================================================
5 // Entry code for Linux synthetic target.
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.
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.
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####
45 // Contributors:proven, jskov, bartv
47 // Purpose: Entry point for Linux synthetic target.
49 //####DESCRIPTIONEND####
51 //=========================================================================
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
63 /*------------------------------------------------------------------------*/
64 /* C++ support - run initial constructors */
66 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
67 cyg_bool cyg_hal_stop_constructors;
70 typedef void (*pfunc) (void);
71 extern pfunc __CTOR_LIST__[];
72 extern pfunc __CTOR_END__[];
75 cyg_hal_invoke_constructors (void)
77 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
78 static pfunc *p = &__CTOR_END__[-1];
80 cyg_hal_stop_constructors = 0;
81 for (; p >= __CTOR_LIST__; p--) {
83 if (cyg_hal_stop_constructors) {
91 for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
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
103 externC void cyg_start( void );
104 externC void synth_hardware_init(void);
105 externC void synth_hardware_init2(void);
107 void _linux_entry( void )
109 // "Initialize various cpu status registers, including disabling interrupts."
110 // That is a no-op for the synthetic target, in particular interrupts are
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
120 // "Enable the cache". Effectively the synthetic target has no cache,
121 // anything provided by the hardware is not readily accessible.
123 // "Set up the stack pointer". The system starts up a program with a
126 // "Initialize any global pointer register". There is no such register.
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();
133 // This is not a ROM startup, so no need to worry about copying the
136 // "Zero the .bss section". Linux will have done this for us.
138 // "Create a suitable C stack frame". Already done.
140 // Invoke the C++ constructors.
141 cyg_hal_invoke_constructors();
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();
151 // "Call cyg_start()". OK.
154 // "Drop into an infinite loop". Not a good idea for the synthetic
155 // target. Instead, exit.
159 // ----------------------------------------------------------------------------
160 // Stub functions needed for linking with various versions of gcc
161 // configured for Linux rather than i386-elf.
164 // 2.95.x libgcc.a __pure_virtual() calls __write().
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.
185 __cxa_atexit(void (*arg1)(void*), void* arg2, void* arg3)
188 void* __dso_handle = (void*) &__dso_handle;
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.
196 dl_iterate_phdr(void* arg1, void* arg2)
203 // First noticed with gcc 4.1.1. There is now code to detect stack
205 void __attribute__ ((noreturn))
206 __stack_chk_fail_local(void)
208 CYG_FAIL("Stack smashing detected, aborting");
209 diag_printf("Application error: stack smashing detected.\n");
213 // Another symbol which indicates a similar problem occurred.
214 void __stack_chk_fail(void)
216 __stack_chk_fail_local();
220 //-----------------------------------------------------------------------------