1 |
786 |
skrzyp |
//===========================================================================
|
2 |
|
|
//
|
3 |
|
|
// hal_misc.c
|
4 |
|
|
//
|
5 |
|
|
// HAL miscellaneous functions
|
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 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): nickg
|
43 |
|
|
// Contributors: proven, pjo
|
44 |
|
|
// Date: 1999-02-20
|
45 |
|
|
// Purpose: HAL miscellaneous functions
|
46 |
|
|
// Description: This file contains miscellaneous functions provided by the
|
47 |
|
|
// HAL.
|
48 |
|
|
//
|
49 |
|
|
//####DESCRIPTIONEND####
|
50 |
|
|
//
|
51 |
|
|
//===========================================================================
|
52 |
|
|
|
53 |
|
|
#include <pkgconf/system.h>
|
54 |
|
|
#include <pkgconf/hal.h>
|
55 |
|
|
|
56 |
|
|
#include <cyg/infra/cyg_type.h>
|
57 |
|
|
#include <cyg/infra/cyg_ass.h>
|
58 |
|
|
#include <cyg/infra/diag.h> // diag_printf
|
59 |
|
|
|
60 |
|
|
#include <cyg/hal/hal_arch.h>
|
61 |
|
|
#include <cyg/hal/hal_intr.h>
|
62 |
|
|
|
63 |
|
|
#include <cyg/hal/hal_if.h>
|
64 |
|
|
|
65 |
|
|
//---------------------------------------------------------------------------
|
66 |
|
|
|
67 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
68 |
|
|
cyg_bool cyg_hal_stop_constructors;
|
69 |
|
|
#endif
|
70 |
|
|
|
71 |
|
|
typedef void (*pfunc) (void);
|
72 |
|
|
extern pfunc __CTOR_LIST__[];
|
73 |
|
|
extern pfunc __CTOR_END__[];
|
74 |
|
|
|
75 |
|
|
void
|
76 |
|
|
cyg_hal_invoke_constructors (void)
|
77 |
|
|
{
|
78 |
|
|
|
79 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
80 |
|
|
static pfunc *p = &__CTOR_END__[-1];
|
81 |
|
|
cyg_hal_stop_constructors = 0;
|
82 |
|
|
for (; p >= __CTOR_LIST__; p--) {
|
83 |
|
|
(*p) ();
|
84 |
|
|
if (cyg_hal_stop_constructors) {
|
85 |
|
|
p--;
|
86 |
|
|
break;
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
#else
|
90 |
|
|
pfunc *p;
|
91 |
|
|
|
92 |
|
|
for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
|
93 |
|
|
(*p) ();
|
94 |
|
|
#endif
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
//---------------------------------------------------------------------------
|
98 |
|
|
// First level C exception handler.
|
99 |
|
|
|
100 |
|
|
externC void __handle_exception (void);
|
101 |
|
|
externC HAL_SavedRegisters *_hal_registers;
|
102 |
|
|
|
103 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
|
104 |
|
|
externC void* volatile __mem_fault_handler;
|
105 |
|
|
#endif
|
106 |
|
|
|
107 |
|
|
void
|
108 |
|
|
cyg_hal_exception_handler(HAL_SavedRegisters *regs)
|
109 |
|
|
{
|
110 |
|
|
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
|
111 |
|
|
|
112 |
|
|
// If we caught an exception inside the stubs, see if we were expecting it
|
113 |
|
|
// and if so jump to the saved address
|
114 |
|
|
if (__mem_fault_handler) {
|
115 |
|
|
regs->pc = (CYG_ADDRWORD)__mem_fault_handler;
|
116 |
|
|
return; // Caught an exception inside stubs
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
_hal_registers = regs;
|
120 |
|
|
__handle_exception();
|
121 |
|
|
|
122 |
|
|
#elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && defined(CYGPKG_HAL_EXCEPTIONS)
|
123 |
|
|
// We should decode the vector and pass a more appropriate
|
124 |
|
|
// value as the second argument. For now we simply pass a
|
125 |
|
|
// pointer to the saved registers. We should also divert
|
126 |
|
|
// breakpoint and other debug vectors into the debug stubs.
|
127 |
|
|
|
128 |
|
|
cyg_hal_deliver_exception( regs->vector>>8, (CYG_ADDRWORD)regs );
|
129 |
|
|
|
130 |
|
|
#else
|
131 |
|
|
CYG_FAIL("Exception!!!");
|
132 |
|
|
#endif
|
133 |
|
|
return;
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
/*------------------------------------------------------------------------*/
|
137 |
|
|
/* default architecture ISR */
|
138 |
|
|
/* The real default ISR is in hal/common/.../src/hal_misc.c */
|
139 |
|
|
|
140 |
|
|
externC cyg_uint32 hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
|
141 |
|
|
{
|
142 |
|
|
// For some reason I seem to be geting spurious interrupts on
|
143 |
|
|
// interrupt 0x27(39). This is the parallel port. This is masked
|
144 |
|
|
// in the PIC so the exact reason for these is a mystery. They do
|
145 |
|
|
// appear to be real interrupts since they always appear just
|
146 |
|
|
// after a clear of the interrupt flag, and the stack shows a
|
147 |
|
|
// proper interrupt context being pushed by the hardware. This may
|
148 |
|
|
// be some feature of the Celeron CPU I am using.
|
149 |
|
|
|
150 |
|
|
if( vector == 0x27 )
|
151 |
|
|
return 2;
|
152 |
|
|
|
153 |
|
|
diag_printf("hal_arch_default_isr: %d (data: %d)\n", vector,data);
|
154 |
|
|
CYG_FAIL("Spurious Interrupt!!!");
|
155 |
|
|
|
156 |
|
|
return 0;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
//---------------------------------------------------------------------------
|
160 |
|
|
// Profiling support. The timer has to be implemented by the platform
|
161 |
|
|
// HAL, but mcount() is generic for all x86 processors. There are three
|
162 |
|
|
// complications: the generic profile code assumes that __profile_mcount()
|
163 |
|
|
// is called with interrupts disabled; on an SMP system there may be
|
164 |
|
|
// concurrent calls to mcount(); and if eCos itself is built with
|
165 |
|
|
// -pg then there may be recursive calls to mcount() which we have
|
166 |
|
|
// to guard against.
|
167 |
|
|
//
|
168 |
|
|
// With i386-elf-gcc the call is to _mcount(), not mcount(), and there
|
169 |
|
|
// is already a return address in %edx. For now the latter is ignored.
|
170 |
|
|
// It would be useful in assembler code, but because we have to worry
|
171 |
|
|
// about interrupts and spinlocks a implementation is rather easier.
|
172 |
|
|
|
173 |
|
|
#ifdef CYGPKG_PROFILE_GPROF
|
174 |
|
|
#include <cyg/profile/profile.h>
|
175 |
|
|
|
176 |
|
|
# ifdef CYGPKG_HAL_SMP_SUPPORT
|
177 |
|
|
static HAL_SMP_CPU_TYPE mcount_cpu = HAL_SMP_CPU_NONE;
|
178 |
|
|
static HAL_SPINLOCK_TYPE mcount_lock = HAL_SPINLOCK_INIT_CLEAR;
|
179 |
|
|
|
180 |
|
|
void
|
181 |
|
|
_mcount(void)
|
182 |
|
|
{
|
183 |
|
|
int ints_enabled;
|
184 |
|
|
HAL_SMP_CPU_TYPE this_cpu;
|
185 |
|
|
|
186 |
|
|
HAL_DISABLE_INTERRUPTS(ints_enabled);
|
187 |
|
|
|
188 |
|
|
// This cpu is now not going to run any other code. So, did it
|
189 |
|
|
// already own the spinlock?
|
190 |
|
|
this_cpu = HAL_SMP_CPU_THIS();
|
191 |
|
|
if (mcount_cpu != this_cpu) {
|
192 |
|
|
// Nope, so this cannot be a nested call to mcount()
|
193 |
|
|
HAL_SPINLOCK_SPIN(mcount_lock);
|
194 |
|
|
// And no other cpu is executing inside mcount() either
|
195 |
|
|
mcount_cpu = this_cpu;
|
196 |
|
|
// A possibly-recursive call is now safe.
|
197 |
|
|
__profile_mcount((CYG_ADDRWORD)__builtin_return_address(1),
|
198 |
|
|
(CYG_ADDRWORD)__builtin_return_address(0));
|
199 |
|
|
// All done.
|
200 |
|
|
mcount_cpu = HAL_SMP_CPU_NONE;
|
201 |
|
|
HAL_SPINLOCK_CLEAR(mcount_lock);
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
HAL_RESTORE_INTERRUPTS(ints_enabled);
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
# else // ! SMP
|
208 |
|
|
|
209 |
|
|
static int mcount_nested;
|
210 |
|
|
|
211 |
|
|
void
|
212 |
|
|
_mcount(void)
|
213 |
|
|
{
|
214 |
|
|
int ints_enabled;
|
215 |
|
|
HAL_DISABLE_INTERRUPTS(ints_enabled);
|
216 |
|
|
if (! mcount_nested) {
|
217 |
|
|
mcount_nested = 1;
|
218 |
|
|
__profile_mcount((CYG_ADDRWORD)__builtin_return_address(1),
|
219 |
|
|
(CYG_ADDRWORD)__builtin_return_address(0));
|
220 |
|
|
mcount_nested = 0;
|
221 |
|
|
}
|
222 |
|
|
HAL_RESTORE_INTERRUPTS(ints_enabled);
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
# endif // SMP
|
226 |
|
|
|
227 |
|
|
// The main VSR will update hal_saved_interrupt_state if profiling is
|
228 |
|
|
// enabled, on the assumption that the platform-specific
|
229 |
|
|
// hal_enable_profile_timer() will somehow make use of timer
|
230 |
|
|
// interrupts. The generic HAL will only provide that if GDB break
|
231 |
|
|
// support is enabled.
|
232 |
|
|
# if !( defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) || defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT))
|
233 |
|
|
struct HAL_SavedRegisters *hal_saved_interrupt_state;
|
234 |
|
|
# endif
|
235 |
|
|
|
236 |
|
|
#endif // CYGPKG_PROFILE_GPROF
|
237 |
|
|
|
238 |
|
|
//---------------------------------------------------------------------------
|
239 |
|
|
// End of hal_misc.c
|