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