1 |
27 |
unneback |
#ifndef CYGONCE_HAL_HAL_INTR_H
|
2 |
|
|
#define CYGONCE_HAL_HAL_INTR_H
|
3 |
|
|
|
4 |
|
|
//==========================================================================
|
5 |
|
|
//
|
6 |
|
|
// hal_intr.h
|
7 |
|
|
//
|
8 |
|
|
// HAL Interrupt and clock support
|
9 |
|
|
//
|
10 |
|
|
//==========================================================================
|
11 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
21 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License along
|
26 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
30 |
|
|
// or inline functions from this file, or you compile this file and link it
|
31 |
|
|
// with other works to produce a work based on this file, this file does not
|
32 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
33 |
|
|
// License. However the source code for this file must still be made available
|
34 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
37 |
|
|
// this file might be covered by the GNU General Public License.
|
38 |
|
|
//
|
39 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
40 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
41 |
|
|
// -------------------------------------------
|
42 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
43 |
|
|
//==========================================================================
|
44 |
|
|
//#####DESCRIPTIONBEGIN####
|
45 |
|
|
//
|
46 |
|
|
// Author(s): proven
|
47 |
|
|
// Contributors: proven, jskov, pjo, nickg
|
48 |
|
|
// Date: 1999-02-20
|
49 |
|
|
// Purpose: Define Interrupt support
|
50 |
|
|
// Description: The macros defined here provide the HAL APIs for handling
|
51 |
|
|
// interrupts and the clock.
|
52 |
|
|
//
|
53 |
|
|
// Usage:
|
54 |
|
|
// #include <cyg/hal/hal_intr.h>
|
55 |
|
|
// ...
|
56 |
|
|
//
|
57 |
|
|
//####DESCRIPTIONEND####
|
58 |
|
|
//
|
59 |
|
|
//==========================================================================
|
60 |
|
|
|
61 |
|
|
#include <pkgconf/hal.h>
|
62 |
|
|
#include <pkgconf/hal_i386.h>
|
63 |
|
|
|
64 |
|
|
#include <cyg/infra/cyg_type.h>
|
65 |
|
|
|
66 |
|
|
#include <cyg/hal/var_intr.h>
|
67 |
|
|
|
68 |
|
|
//--------------------------------------------------------------------------
|
69 |
|
|
// Exception vectors.
|
70 |
|
|
// Standard exception vectors supported by most IA32 CPUs
|
71 |
|
|
|
72 |
|
|
#define CYGNUM_HAL_VECTOR_DIV0 0
|
73 |
|
|
#define CYGNUM_HAL_VECTOR_DEBUG 1
|
74 |
|
|
#define CYGNUM_HAL_VECTOR_NMI 2
|
75 |
|
|
#define CYGNUM_HAL_VECTOR_BREAKPOINT 3
|
76 |
|
|
#define CYGNUM_HAL_VECTOR_OVERFLOW 4
|
77 |
|
|
#define CYGNUM_HAL_VECTOR_BOUND 5
|
78 |
|
|
#define CYGNUM_HAL_VECTOR_OPCODE 6
|
79 |
|
|
#define CYGNUM_HAL_VECTOR_NO_DEVICE 7
|
80 |
|
|
#define CYGNUM_HAL_VECTOR_DOUBLE_FAULT 8
|
81 |
|
|
#define CYGNUM_HAL_VECTOR_INVALID_TSS 10
|
82 |
|
|
#define CYGNUM_HAL_VECTOR_SEGV 11
|
83 |
|
|
#define CYGNUM_HAL_VECTOR_STACK_FAULT 12
|
84 |
|
|
#define CYGNUM_HAL_VECTOR_PROTECTION 13
|
85 |
|
|
#define CYGNUM_HAL_VECTOR_PAGE 14
|
86 |
|
|
#define CYGNUM_HAL_VECTOR_FPE 16
|
87 |
|
|
#define CYGNUM_HAL_VECTOR_ALIGNMENT 17
|
88 |
|
|
|
89 |
|
|
// The default size of the VSR table is 256 entries.
|
90 |
|
|
#ifndef CYGNUM_HAL_VSR_MIN
|
91 |
|
|
#define CYGNUM_HAL_VSR_MIN 0
|
92 |
|
|
#define CYGNUM_HAL_VSR_MAX 255
|
93 |
|
|
#define CYGNUM_HAL_VSR_COUNT 256
|
94 |
|
|
#endif
|
95 |
|
|
|
96 |
|
|
// Common exception vectors.
|
97 |
|
|
#define CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION CYGNUM_HAL_VECTOR_OPCODE
|
98 |
|
|
#define CYGNUM_HAL_EXCEPTION_INTERRUPT CYGNUM_HAL_VECTOR_BREAKPOINT
|
99 |
|
|
#define CYGNUM_HAL_EXCEPTION_CODE_ACCESS CYGNUM_HAL_VECTOR_PROTECTION
|
100 |
|
|
#define CYGNUM_HAL_EXCEPTION_DATA_ACCESS CYGNUM_HAL_VECTOR_PROTECTION
|
101 |
|
|
#define CYGNUM_HAL_EXCEPTION_TRAP CYGNUM_HAL_VECTOR_DEBUG
|
102 |
|
|
#define CYGNUM_HAL_EXCEPTION_FPU CYGNUM_HAL_VECTOR_FPE
|
103 |
|
|
#define CYGNUM_HAL_EXCEPTION_STACK_OVERFLOW CYGNUM_HAL_VECTOR_SEGV
|
104 |
|
|
#define CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO CYGNUM_HAL_VECTOR_DIV0
|
105 |
|
|
#define CYGNUM_HAL_EXCEPTION_OVERFLOW CYGNUM_HAL_VECTOR_OVERFLOW
|
106 |
|
|
|
107 |
|
|
#define CYGNUM_HAL_EXCEPTION_MIN 0
|
108 |
|
|
#define CYGNUM_HAL_EXCEPTION_MAX 31
|
109 |
|
|
#define CYGNUM_HAL_EXCEPTION_COUNT (CYGNUM_HAL_EXCEPTION_MAX - CYGNUM_HAL_EXCEPTION_MIN + 1)
|
110 |
|
|
|
111 |
|
|
// These really are wild guesses on my part...
|
112 |
|
|
#define CYGNUM_HAL_VECTOR_SIGBUS CYGNUM_HAL_EXCEPTION_DATA_ACCESS
|
113 |
|
|
#define CYGNUM_HAL_VECTOR_SIGFPE CYGNUM_HAL_EXCEPTION_FPU
|
114 |
|
|
#define CYGNUM_HAL_VECTOR_SIGSEGV CYGNUM_HAL_VECTOR_SEGV
|
115 |
|
|
|
116 |
|
|
//--------------------------------------------------------------------------
|
117 |
|
|
// Static data used by HAL
|
118 |
|
|
|
119 |
|
|
// ISR tables
|
120 |
|
|
externC volatile CYG_ADDRESS hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
|
121 |
|
|
externC volatile CYG_ADDRWORD hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
|
122 |
|
|
externC volatile CYG_ADDRESS hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
|
123 |
|
|
|
124 |
|
|
// VSR table
|
125 |
|
|
externC volatile CYG_ADDRESS hal_vsr_table[CYGNUM_HAL_VSR_COUNT];
|
126 |
|
|
|
127 |
|
|
//--------------------------------------------------------------------------
|
128 |
|
|
// Interrupt state storage
|
129 |
|
|
|
130 |
|
|
typedef cyg_uint32 CYG_INTERRUPT_STATE;
|
131 |
|
|
|
132 |
|
|
//---------------------------------------------------------------------------
|
133 |
|
|
// Default ISR
|
134 |
|
|
|
135 |
|
|
externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
|
136 |
|
|
|
137 |
|
|
#define HAL_DEFAULT_ISR hal_default_isr
|
138 |
|
|
|
139 |
|
|
//--------------------------------------------------------------------------
|
140 |
|
|
// CPU interrupt enable/disable macros
|
141 |
|
|
|
142 |
|
|
#define HAL_ENABLE_INTERRUPTS() \
|
143 |
|
|
CYG_MACRO_START \
|
144 |
|
|
asm ("sti") ; \
|
145 |
|
|
CYG_MACRO_END
|
146 |
|
|
|
147 |
|
|
#define HAL_DISABLE_INTERRUPTS(_old_) \
|
148 |
|
|
CYG_MACRO_START \
|
149 |
|
|
register int x ; \
|
150 |
|
|
asm volatile ( \
|
151 |
|
|
"pushfl ;" \
|
152 |
|
|
"popl %0 ;" \
|
153 |
|
|
"cli" \
|
154 |
|
|
: "=r" (x) \
|
155 |
|
|
) ; \
|
156 |
|
|
(_old_) = (x & 0x200); \
|
157 |
|
|
CYG_MACRO_END
|
158 |
|
|
|
159 |
|
|
#define HAL_RESTORE_INTERRUPTS(_old_) \
|
160 |
|
|
CYG_MACRO_START \
|
161 |
|
|
register int x = _old_; \
|
162 |
|
|
asm volatile ( "pushfl ;" \
|
163 |
|
|
"popl %%eax ;" \
|
164 |
|
|
"andl $0xFFFFFDFF,%%eax;" \
|
165 |
|
|
"orl %0,%%eax;" \
|
166 |
|
|
"pushl %%eax;" \
|
167 |
|
|
"popfl ;" \
|
168 |
|
|
: /* No outputs */ \
|
169 |
|
|
: "r"(x) \
|
170 |
|
|
: "eax" \
|
171 |
|
|
); \
|
172 |
|
|
CYG_MACRO_END
|
173 |
|
|
|
174 |
|
|
#define HAL_QUERY_INTERRUPTS(_old_) \
|
175 |
|
|
CYG_MACRO_START \
|
176 |
|
|
register int x ; \
|
177 |
|
|
asm volatile ("pushfl ;" \
|
178 |
|
|
"popl %0" \
|
179 |
|
|
: "=r" (x) \
|
180 |
|
|
); \
|
181 |
|
|
(_old_) = (x & 0x200); \
|
182 |
|
|
CYG_MACRO_END
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
//--------------------------------------------------------------------------
|
186 |
|
|
// Routine to execute DSRs using separate interrupt stack
|
187 |
|
|
|
188 |
|
|
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
|
189 |
|
|
externC void hal_interrupt_stack_call_pending_DSRs(void);
|
190 |
|
|
#define HAL_INTERRUPT_STACK_CALL_PENDING_DSRS() \
|
191 |
|
|
hal_interrupt_stack_call_pending_DSRs()
|
192 |
|
|
|
193 |
|
|
// these are offered solely for stack usage testing
|
194 |
|
|
// if they are not defined, then there is no interrupt stack.
|
195 |
|
|
#define HAL_INTERRUPT_STACK_BASE cyg_interrupt_stack_base
|
196 |
|
|
#define HAL_INTERRUPT_STACK_TOP cyg_interrupt_stack
|
197 |
|
|
// use them to declare these extern however you want:
|
198 |
|
|
// extern char HAL_INTERRUPT_STACK_BASE[];
|
199 |
|
|
// extern char HAL_INTERRUPT_STACK_TOP[];
|
200 |
|
|
// is recommended
|
201 |
|
|
#endif
|
202 |
|
|
|
203 |
|
|
//---------------------------------------------------------------------------
|
204 |
|
|
// Interrupt and VSR attachment macros
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
#define HAL_INTERRUPT_IN_USE( _vector_, _state_) \
|
208 |
|
|
CYG_MACRO_START \
|
209 |
|
|
cyg_uint32 _index_; \
|
210 |
|
|
HAL_TRANSLATE_VECTOR ((_vector_), _index_); \
|
211 |
|
|
\
|
212 |
|
|
if (hal_interrupt_handlers[_index_] \
|
213 |
|
|
==(CYG_ADDRESS)HAL_DEFAULT_ISR) \
|
214 |
|
|
(_state_) = 0; \
|
215 |
|
|
else \
|
216 |
|
|
(_state_) = 1; \
|
217 |
|
|
CYG_MACRO_END
|
218 |
|
|
|
219 |
|
|
#ifndef HAL_INTERRUPT_ATTACH
|
220 |
|
|
externC void __default_interrupt_vsr(void);
|
221 |
|
|
#define HAL_INTERRUPT_ATTACH( _vector_, _isr_, _data_, _object_ ) \
|
222 |
|
|
CYG_MACRO_START \
|
223 |
|
|
cyg_uint32 _index_; \
|
224 |
|
|
HAL_TRANSLATE_VECTOR((_vector_), _index_); \
|
225 |
|
|
\
|
226 |
|
|
HAL_VSR_SET( _vector_, &__default_interrupt_vsr , NULL); \
|
227 |
|
|
if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)HAL_DEFAULT_ISR ) \
|
228 |
|
|
{ \
|
229 |
|
|
hal_interrupt_handlers[_index_] = (CYG_ADDRESS)(_isr_); \
|
230 |
|
|
hal_interrupt_data[_index_] = (CYG_ADDRWORD)(_data_); \
|
231 |
|
|
hal_interrupt_objects[_index_] = (CYG_ADDRESS)(_object_); \
|
232 |
|
|
} \
|
233 |
|
|
CYG_MACRO_END
|
234 |
|
|
#endif /* HAL_INTERRUPT_ATTACH */
|
235 |
|
|
|
236 |
|
|
#define HAL_INTERRUPT_DETACH( _vector_, _isr_ ) \
|
237 |
|
|
CYG_MACRO_START \
|
238 |
|
|
cyg_uint32 _index_; \
|
239 |
|
|
HAL_TRANSLATE_VECTOR((_vector_), _index_); \
|
240 |
|
|
\
|
241 |
|
|
if (hal_interrupt_handlers[_index_] \
|
242 |
|
|
== (CYG_ADDRESS)(_isr_)) \
|
243 |
|
|
{ \
|
244 |
|
|
hal_interrupt_handlers[_index_] = \
|
245 |
|
|
(CYG_ADDRESS)HAL_DEFAULT_ISR; \
|
246 |
|
|
hal_interrupt_data[_index_] = 0; \
|
247 |
|
|
hal_interrupt_objects[_index_] = 0; \
|
248 |
|
|
} \
|
249 |
|
|
CYG_MACRO_END
|
250 |
|
|
|
251 |
|
|
#define HAL_VSR_GET( _vector_, _pvsr_ ) \
|
252 |
|
|
*((CYG_ADDRESS *)(_pvsr_)) = hal_vsr_table[(_vector_)];
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
#define HAL_VSR_SET( _vector_, _vsr_, _poldvsr_ ) \
|
256 |
|
|
CYG_MACRO_START \
|
257 |
|
|
if( (_poldvsr_) != NULL ) \
|
258 |
|
|
*(CYG_ADDRESS *)(_poldvsr_) = hal_vsr_table[(_vector_)]; \
|
259 |
|
|
hal_vsr_table[(_vector_)] = (CYG_ADDRESS)(_vsr_); \
|
260 |
|
|
CYG_MACRO_END
|
261 |
|
|
|
262 |
|
|
// This is an ugly name, but what it means is: grab the VSR back to eCos
|
263 |
|
|
// internal handling, or if you like, the default handler. But if
|
264 |
|
|
// cooperating with GDB and CygMon, the default behaviour is to pass most
|
265 |
|
|
// exceptions to CygMon. This macro undoes that so that eCos handles the
|
266 |
|
|
// exception. So use it with care.
|
267 |
|
|
|
268 |
|
|
externC void __default_exception_vsr(void);
|
269 |
|
|
externC void __default_interrupt_vsr(void);
|
270 |
|
|
|
271 |
|
|
#define HAL_VSR_SET_TO_ECOS_HANDLER( _vector_, _poldvsr_ ) \
|
272 |
|
|
CYG_MACRO_START \
|
273 |
|
|
HAL_VSR_SET( _vector_, _vector_ > CYGNUM_HAL_EXCEPTION_MAX \
|
274 |
|
|
? (CYG_ADDRESS)__default_interrupt_vsr \
|
275 |
|
|
: (CYG_ADDRESS)__default_exception_vsr, \
|
276 |
|
|
_poldvsr_ ); \
|
277 |
|
|
CYG_MACRO_END
|
278 |
|
|
|
279 |
|
|
//---------------------------------------------------------------------------
|
280 |
|
|
#endif // ifndef CYGONCE_HAL_HAL_INTR_H
|
281 |
|
|
// End of hal_intr.h
|