OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [i386/] [arch/] [current/] [include/] [hal_intr.h] - Blame information for rev 838

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.