]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/synth/arch/v2_0/src/synth_entry.c
923bb0fb625af6e89f0cfc1ae0b8f4c4fec8447a
[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 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/hal/hal_arch.h>
58 #include <cyg/hal/hal_intr.h>
59 #include <cyg/hal/hal_io.h>
60 #include CYGHWR_MEMORY_LAYOUT_H
61
62 /*------------------------------------------------------------------------*/
63 /* C++ support - run initial constructors                                 */
64
65 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
66 cyg_bool cyg_hal_stop_constructors;
67 #endif
68
69 typedef void (*pfunc) (void);
70 extern pfunc __CTOR_LIST__[];
71 extern pfunc __CTOR_END__[];
72
73 void
74 cyg_hal_invoke_constructors (void)
75 {
76 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
77     static pfunc *p = &__CTOR_END__[-1];
78     
79     cyg_hal_stop_constructors = 0;
80     for (; p >= __CTOR_LIST__; p--) {
81         (*p) ();
82         if (cyg_hal_stop_constructors) {
83             p--;
84             break;
85         }
86     }
87 #else
88     pfunc *p;
89
90     for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
91         (*p) ();
92 #endif
93 }
94
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
100 // startup.
101
102 externC void    cyg_start( void );
103 externC void    synth_hardware_init(void);
104 externC void    synth_hardware_init2(void);
105
106 void _linux_entry( void )
107 {
108     void* new_top = (void*) 0;
109     
110     // "Initialize various cpu status registers, including disabling interrupts."
111     // That is a no-op for the synthetic target, in particular interrupts are
112     // already disabled.
113
114     // "Set up any CPU memory controller to access ROM, RAM, and I/O devices
115     // correctly".
116     //
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");
125         cyg_hal_sys_exit(1);
126     }
127     
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.
131
132     // "Enable the cache". Effectively the synthetic target has no cache,
133     // anything provided by the hardware is not readily accessible.
134
135     // "Set up the stack pointer". The system starts up a program with a
136     // suitable stack.
137
138     // "Initialize any global pointer register". There is no such register.
139
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();
144
145     // This is not a ROM startup, so no need to worry about copying the
146     // .data section.
147
148     // "Zero the .bss section". Linux will have done this for us.
149
150     // "Create a suitable C stack frame". Already done.
151
152     // Invoke the C++ constructors.
153     cyg_hal_invoke_constructors();
154
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();
162     
163     // "Call cyg_start()". OK.
164     cyg_start();
165
166     // "Drop into an infinite loop". Not a good idea for the synthetic
167     // target. Instead, exit.
168     cyg_hal_sys_exit(0);
169 }
170
171 // ----------------------------------------------------------------------------
172 // Stub functions needed for linking with various versions of gcc
173 // configured for Linux rather than i386-elf.
174
175 #if (__GNUC__ < 3)
176 // 2.95.x libgcc.a __pure_virtual() calls __write().
177 int __write(void)
178 {
179     return -1;
180 }
181 #endif
182
183 #if (__GNUC__ >= 3)
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.
195
196 void
197 __cxa_atexit(void (*arg1)(void*), void* arg2, void* arg3)
198 {
199 }
200 void*   __dso_handle = (void*) &__dso_handle;
201
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.
207 int
208 dl_iterate_phdr(void* arg1, void* arg2)
209 {
210     return -1;
211 }
212 #endif
213
214 //-----------------------------------------------------------------------------
215 // End of entry.c