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 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/hal/hal_arch.h>
58 #include <cyg/hal/hal_intr.h>
59 #include <cyg/hal/hal_io.h>
60 #include CYGHWR_MEMORY_LAYOUT_H
62 /*------------------------------------------------------------------------*/
63 /* C++ support - run initial constructors */
65 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
66 cyg_bool cyg_hal_stop_constructors;
69 typedef void (*pfunc) (void);
70 extern pfunc __CTOR_LIST__[];
71 extern pfunc __CTOR_END__[];
74 cyg_hal_invoke_constructors (void)
76 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
77 static pfunc *p = &__CTOR_END__[-1];
79 cyg_hal_stop_constructors = 0;
80 for (; p >= __CTOR_LIST__; p--) {
82 if (cyg_hal_stop_constructors) {
90 for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
95 // ----------------------------------------------------------------------------
96 // The low-level entry point is platform-specific, typically in the
97 // assember file vectors.S. However that entry point simply jumps
98 // directly here, with no further processing or stack manipulation.
99 // The HAL specification defines clearly what should happen during
102 externC void cyg_start( void );
103 externC void synth_hardware_init(void);
104 externC void synth_hardware_init2(void);
106 void _linux_entry( void )
108 void* new_top = (void*) 0;
110 // "Initialize various cpu status registers, including disabling interrupts."
111 // That is a no-op for the synthetic target, in particular interrupts are
114 // "Set up any CPU memory controller to access ROM, RAM, and I/O devices
117 // This involves using the brk() system call to allocate the RAM used
118 // for the heaps. There are no variables mapped there so the system
119 // will not have done this for us. Note that the implementation of
120 // brk() (mm/mmap.c) differs from the documentation - the return
121 // value is the new brk value, not an error code.
122 new_top = (void*) (CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE);
123 if (new_top != cyg_hal_sys_brk(new_top)) {
124 CYG_FAIL("Failed to initialize memory");
128 // Again a no-op for the synthetic target. All memory is readily
129 // accessible. Arguably the auxiliary should be started up here, but
130 // instead that is left to platform initialization.
132 // "Enable the cache". Effectively the synthetic target has no cache,
133 // anything provided by the hardware is not readily accessible.
135 // "Set up the stack pointer". The system starts up a program with a
138 // "Initialize any global pointer register". There is no such register.
140 // Perform platform-specific initialization. Actually, all Linux
141 // platforms can share this. It involves setting up signal handlers,
142 // starting the I/O auxiliary, and so on.
143 synth_hardware_init();
145 // This is not a ROM startup, so no need to worry about copying the
148 // "Zero the .bss section". Linux will have done this for us.
150 // "Create a suitable C stack frame". Already done.
152 // Invoke the C++ constructors.
153 cyg_hal_invoke_constructors();
155 // Once the C++ constructors have been invoked, a second stage
156 // of hardware initialization is desirable. At this point all
157 // eCos device drivers should have been initialized so the
158 // I/O auxiliary will have loaded the appropriate support
159 // scripts, and the auxiliary can now map the window(s) on to
160 // the display and generally operate normally.
161 synth_hardware_init2();
163 // "Call cyg_start()". OK.
166 // "Drop into an infinite loop". Not a good idea for the synthetic
167 // target. Instead, exit.
171 // ----------------------------------------------------------------------------
172 // Stub functions needed for linking with various versions of gcc
173 // configured for Linux rather than i386-elf.
176 // 2.95.x libgcc.a __pure_virtual() calls __write().
184 // Versions of gcc/g++ after 3.0 (approx.), when configured for Linux
185 // native development (specifically, --with-__cxa_enable), have
186 // additional dependencies related to the destructors for static
187 // objects. When compiling C++ code with static objects the compiler
188 // inserts a call to __cxa_atexit() with __dso_handle as one of the
189 // arguments. __cxa_atexit() would normally be provided by glibc, and
190 // __dso_handle is part of crtstuff.c. Synthetic target applications
191 // are linked rather differently, so either a differently-configured
192 // compiler is needed or dummy versions of these symbols should be
193 // provided. If these symbols are not actually used then providing
194 // them is still harmless, linker garbage collection will remove them.
197 __cxa_atexit(void (*arg1)(void*), void* arg2, void* arg3)
200 void* __dso_handle = (void*) &__dso_handle;
202 // gcc 3.2.2 (approx). The libsupc++ version of the new operator pulls
203 // in exception handling code, even when using the nothrow version and
204 // building with -fno-exceptions. libgcc_eh.a provides the necessary
205 // functions, but requires a dl_iterate_phdr() function. That is related
206 // to handling dynamically loaded code so is not applicable to eCos.
208 dl_iterate_phdr(void* arg1, void* arg2)
214 //-----------------------------------------------------------------------------