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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [sparclite/] [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_INTR_H
2
#define CYGONCE_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):    nickg, gthomas, hmt
46
// Contributors: nickg, gthomas, hmt,
47
//               jlarmour
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
//
58
//####DESCRIPTIONEND####
59
//
60
//===========================================================================
61
 
62
#include <pkgconf/hal.h>
63
#include <pkgconf/hal_sparclite.h>
64
 
65
#include <cyg/infra/cyg_type.h>
66
 
67
//---------------------------------------------------------------------------
68
// SPARClite exception vectors.
69
//
70
// A note on nomenclature:
71
//
72
// SPARClite has traps: interrupts are traps, and so are exceptions.
73
// There are 255 of them in the hardware: this HAL's trampoline code decodes
74
// them into the 27 listed below as CYGNUM_HAL_VECTOR_xxx.
75
// They are handled uniformly in the trampoline code in the sense that
76
// each vector has a VSR which is called in the same way.
77
// Interrupts (vectors 1-15) have one VSR by default, exceptions (vectors
78
// 16-26) another.
79
// The interrupt VSR sets up a C stack and calls the corresponding ISR with
80
// the required arguments; this ABI is mandated by the kernel.
81
// The exception VSR sets up a C stack and calls the corresponding XSR
82
// (just an entry in the ISR[sic] table) with similar arguments, such that
83
// it (by default) can call the kernel's cyg_hal_deliver_exception().
84
// 
85
// So:
86
// CYGNUM_HAL_VSR_MAX/MIN/COUNT describe the number of VSR entries *and*
87
// the number of ISR (and associated data) entries (including those which
88
// are XSRs, just a special case of ISRs).
89
// CYGNUM_HAL_ISR_MAX/MIN/COUNT describe the number of interrupt sources
90
// and is used for bounds checking in kernel interrupt objects.
91
// CYGNUM_HAL_EXCEPTION_MAX/MIN/COUNT describe vector numbers which have
92
// by default the exception VSR and default XSR installed.
93
 
94
 
95
// These correspond to VSRs and the values are the ones to use for
96
// HAL_VSR_GET/SET
97
 
98
#define CYGNUM_HAL_VECTOR_RESERVED_0       0
99
#define CYGNUM_HAL_VECTOR_INTERRUPT_1      1 // NB: least important
100
#define CYGNUM_HAL_VECTOR_INTERRUPT_2      2 // (lowest priority)
101
#define CYGNUM_HAL_VECTOR_INTERRUPT_3      3
102
#define CYGNUM_HAL_VECTOR_INTERRUPT_4      4
103
#define CYGNUM_HAL_VECTOR_INTERRUPT_5      5
104
#define CYGNUM_HAL_VECTOR_INTERRUPT_6      6
105
#define CYGNUM_HAL_VECTOR_INTERRUPT_7      7
106
#define CYGNUM_HAL_VECTOR_INTERRUPT_8      8
107
#define CYGNUM_HAL_VECTOR_INTERRUPT_9      9
108
#define CYGNUM_HAL_VECTOR_INTERRUPT_10    10
109
#define CYGNUM_HAL_VECTOR_INTERRUPT_11    11
110
#define CYGNUM_HAL_VECTOR_INTERRUPT_12    12
111
#define CYGNUM_HAL_VECTOR_INTERRUPT_13    13
112
#define CYGNUM_HAL_VECTOR_INTERRUPT_14    14 // (highest priority)
113
#define CYGNUM_HAL_VECTOR_INTERRUPT_15    15 // NB: most important (NMI)
114
 
115
#define CYG_VECTOR_IS_INTERRUPT(v)        (15 >= (v))
116
 
117
#define CYGNUM_HAL_VECTOR_USER_TRAP       16 // Ticc instructions
118
#define CYGNUM_HAL_VECTOR_FETCH_ABORT     17 // trap type 1
119
#define CYGNUM_HAL_VECTOR_ILLEGAL_OP      18 // trap type 2
120
#define CYGNUM_HAL_VECTOR_PRIV_OP         19 // tt 3: privileged op
121
#define CYGNUM_HAL_VECTOR_NOFPCP          20 // tt 4,36: FP or coproc
122
#define CYGNUM_HAL_VECTOR_RESERVED_1      21 // (not used)
123
#define CYGNUM_HAL_VECTOR_RESERVED_2      22 // (not used)
124
#define CYGNUM_HAL_VECTOR_UNALIGNED       23 // tt 7: unaligned memory access
125
#define CYGNUM_HAL_VECTOR_TT_EIGHT        24 // tt 8: not defined
126
#define CYGNUM_HAL_VECTOR_DATA_ABORT      25 // tt 9: read/write failed
127
 
128
#define CYGNUM_HAL_VECTOR_OTHERS          26 // any others
129
 
130
#define CYGNUM_HAL_VSR_MIN                 0
131
#define CYGNUM_HAL_VSR_MAX                26
132
#define CYGNUM_HAL_VSR_COUNT              27
133
 
134
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135
 
136
// Interrupt vectors. These are the values used with HAL_INTERRUPT_ATTACH()
137
// et al
138
 
139
#define CYGNUM_HAL_INTERRUPT_RESERVED_0   CYGNUM_HAL_VECTOR_RESERVED_0
140
#define CYGNUM_HAL_INTERRUPT_1            CYGNUM_HAL_VECTOR_INTERRUPT_1
141
#define CYGNUM_HAL_INTERRUPT_2            CYGNUM_HAL_VECTOR_INTERRUPT_2
142
#define CYGNUM_HAL_INTERRUPT_3            CYGNUM_HAL_VECTOR_INTERRUPT_3
143
#define CYGNUM_HAL_INTERRUPT_4            CYGNUM_HAL_VECTOR_INTERRUPT_4
144
#define CYGNUM_HAL_INTERRUPT_5            CYGNUM_HAL_VECTOR_INTERRUPT_5
145
#define CYGNUM_HAL_INTERRUPT_6            CYGNUM_HAL_VECTOR_INTERRUPT_6
146
#define CYGNUM_HAL_INTERRUPT_7            CYGNUM_HAL_VECTOR_INTERRUPT_7
147
#define CYGNUM_HAL_INTERRUPT_8            CYGNUM_HAL_VECTOR_INTERRUPT_8
148
#define CYGNUM_HAL_INTERRUPT_9            CYGNUM_HAL_VECTOR_INTERRUPT_9
149
#define CYGNUM_HAL_INTERRUPT_10           CYGNUM_HAL_VECTOR_INTERRUPT_10
150
#define CYGNUM_HAL_INTERRUPT_11           CYGNUM_HAL_VECTOR_INTERRUPT_11
151
#define CYGNUM_HAL_INTERRUPT_12           CYGNUM_HAL_VECTOR_INTERRUPT_12
152
#define CYGNUM_HAL_INTERRUPT_13           CYGNUM_HAL_VECTOR_INTERRUPT_13
153
#define CYGNUM_HAL_INTERRUPT_14           CYGNUM_HAL_VECTOR_INTERRUPT_14
154
#define CYGNUM_HAL_INTERRUPT_15           CYGNUM_HAL_VECTOR_INTERRUPT_15
155
 
156
#define CYGNUM_HAL_ISR_MIN                 0
157
#define CYGNUM_HAL_ISR_MAX                15
158
#define CYGNUM_HAL_ISR_COUNT              16
159
 
160
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161
 
162
// Exception vectors. These are the values used when passed out to an
163
// external exception handler using cyg_hal_deliver_exception()
164
// They can also be used with HAL_INTERRUPT_ATTACH() et al to install
165
// different XSRs.
166
 
167
#define CYGNUM_HAL_EXCEPTION_TRAP               CYGNUM_HAL_VECTOR_USER_TRAP
168
#define CYGNUM_HAL_EXCEPTION_CODE_ACCESS        CYGNUM_HAL_VECTOR_FETCH_ABORT
169
#define CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION \
170
                                                CYGNUM_HAL_VECTOR_ILLEGAL_OP
171
#define CYGNUM_HAL_EXCEPTION_PRIVILEGED_INSTRUCTION \
172
                                                CYGNUM_HAL_VECTOR_PRIV_OP
173
#define CYGNUM_HAL_EXCEPTION_FPU_NOT_AVAIL      CYGNUM_HAL_VECTOR_NOFPCP
174
#define CYGNUM_HAL_EXCEPTION_RESERVED1          CYGNUM_HAL_VECTOR_RESERVED1
175
#define CYGNUM_HAL_EXCEPTION_RESERVED2          CYGNUM_HAL_VECTOR_RESERVED2
176
#define CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS \
177
                                                CYGNUM_HAL_VECTOR_UNALIGNED
178
#define CYGNUM_HAL_EXCEPTION_TT_EIGHT           CYGNUM_HAL_VECTOR_TT_EIGHT
179
#define CYGNUM_HAL_EXCEPTION_DATA_ACCESS        CYGNUM_HAL_VECTOR_DATA_ABORT
180
#define CYGNUM_HAL_EXCEPTION_OTHERS             CYGNUM_HAL_VECTOR_OTHERS
181
 
182
 
183
#define CYGNUM_HAL_EXCEPTION_MIN          16
184
#define CYGNUM_HAL_EXCEPTION_MAX          (16 + 10)
185
#define CYGNUM_HAL_EXCEPTION_COUNT        (1 + CYGNUM_HAL_EXCEPTION_MAX - \
186
                                           CYGNUM_HAL_EXCEPTION_MIN)
187
 
188
//---------------------------------------------------------------------------
189
// (Null) Translation from a wider space of interrupt sources:
190
 
191
#define HAL_TRANSLATE_VECTOR(_vector_,_index_) _index_ = (_vector_)
192
 
193
//---------------------------------------------------------------------------
194
// Routine to execute DSRs using separate interrupt stack
195
 
196
#ifdef  CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
197
 
198
externC void hal_interrupt_stack_call_pending_DSRs(void);
199
#define HAL_INTERRUPT_STACK_CALL_PENDING_DSRS() \
200
    hal_interrupt_stack_call_pending_DSRs()
201
 
202
// these are offered solely for stack usage testing
203
// if they are not defined, then there is no interrupt stack.
204
#define HAL_INTERRUPT_STACK_BASE cyg_interrupt_stack_base
205
#define HAL_INTERRUPT_STACK_TOP  cyg_interrupt_stack
206
// use them to declare these extern however you want:
207
//       extern char HAL_INTERRUPT_STACK_BASE[];
208
//       extern char HAL_INTERRUPT_STACK_TOP[];
209
// is recommended
210
#endif
211
 
212
//---------------------------------------------------------------------------
213
// Static data used by HAL
214
 
215
// VSR table
216
externC volatile CYG_ADDRESS    hal_vsr_table[CYGNUM_HAL_VSR_COUNT];
217
 
218
// ISR + XSR tables - so VSR count.
219
externC volatile CYG_ADDRESS    hal_interrupt_handlers[CYGNUM_HAL_VSR_COUNT];
220
externC volatile CYG_ADDRWORD   hal_interrupt_data[CYGNUM_HAL_VSR_COUNT];
221
externC volatile CYG_ADDRESS    hal_interrupt_objects[CYGNUM_HAL_VSR_COUNT];
222
// (interrupt_objects only used in the interrupt case _but_ the interrupt
223
//  attach &co macros write it, so keep it full-sized)
224
 
225
//---------------------------------------------------------------------------
226
// Default ISRs for exception/interrupt handing.
227
 
228
// note that these have the same ABI apart from the extra SP parameter
229
// for exceptions.
230
 
231
externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
232
// return code from ISR is passed to interrupt_end() in the kernel.
233
 
234
externC void cyg_hal_exception_handler(CYG_ADDRWORD vector,
235
                                       CYG_ADDRWORD data,
236
                                       CYG_ADDRWORD stackpointer);
237
 
238
//---------------------------------------------------------------------------
239
// Default VSRs for exception/interrupt handing.
240
 
241
// note that these do not have a C ABI as such; they are *vector* service
242
// routines and are written in assembler.
243
 
244
externC void hal_default_exception_vsr( void );
245
externC void hal_default_interrupt_vsr( void );
246
 
247
//---------------------------------------------------------------------------
248
// Interrupt state storage
249
 
250
typedef cyg_uint32 CYG_INTERRUPT_STATE;
251
 
252
//---------------------------------------------------------------------------
253
// Interrupt control macros
254
 
255
// THIS ONE IS NOT A STANDARD HAL ENTRY (HAL_DISABLE_TRAPS)
256
// (so should be unused externally)
257
#define HAL_DISABLE_TRAPS(_old_)                \
258
    asm volatile (                              \
259
        "rd     %%psr, %0;"                     \
260
        "andn   %0, 0x20, %%l7;"                \
261
        "wr     %%l7, %%psr;"                   \
262
        "nop; nop; nop"                         \
263
        : "=r"(_old_)                           \
264
        :                                       \
265
        : "l7"                                  \
266
        );
267
 
268
// THIS ONE IS NOT A STANDARD HAL ENTRY (HAL_QUERY_TRAPS)
269
// (so should be unused externally)
270
#define HAL_QUERY_TRAPS(_old_)                  \
271
    asm volatile (                              \
272
        "rd     %%psr, %%l7;"                   \
273
        "and    %%l7, 0x020, %0"                \
274
        : "=r"(_old_)                           \
275
        :                                       \
276
        : "l7"                                  \
277
        );
278
 
279
#define HAL_DISABLE_INTERRUPTS(_old_)           \
280
    asm volatile (                              \
281
        "rd     %%psr, %0;"                     \
282
        "or     %0, 0xf00, %%l7;"               \
283
        "wr     %%l7, %%psr;"                   \
284
        "nop; nop; nop"                         \
285
        : "=r"(_old_)                           \
286
        :                                       \
287
        : "l7"                                  \
288
        );
289
 
290
#define HAL_ENABLE_INTERRUPTS()                 \
291
    asm volatile (                              \
292
        "rd     %%psr, %%l7;"                   \
293
        "andn   %%l7, 0xf00, %%l7;"             \
294
        "or     %%l7, 0x020, %%l7;"             \
295
        "wr     %%l7, %%psr;"                   \
296
        "nop; nop; nop"                         \
297
        :                                       \
298
        :                                       \
299
        : "l7"                                  \
300
        );
301
 
302
#define HAL_RESTORE_INTERRUPTS(_old_)           \
303
    asm volatile (                              \
304
        "rd     %%psr, %%l7;"                   \
305
        "andn   %%l7, 0xf20, %%l7;"             \
306
        "and    %0 , 0xf20, %%l6;"              \
307
        "wr     %%l6, %%l7, %%psr;"             \
308
        "nop; nop; nop"                         \
309
        :                                       \
310
        : "r"(_old_)                            \
311
        : "l6","l7"                             \
312
        );
313
 
314
#define HAL_QUERY_INTERRUPTS(_old_)             \
315
    asm volatile (                              \
316
        "rd     %%psr, %%l7;"                   \
317
        "and    %%l7, 0xf00, %%l7;"             \
318
        "xor    %%l7, 0xf00, %0"                \
319
        : "=r"(_old_)                           \
320
        :                                       \
321
        : "l7"                                  \
322
        );
323
 
324
 
325
//---------------------------------------------------------------------------
326
// Interrupt and VSR attachment macros
327
 
328
#define HAL_INTERRUPT_IN_USE( _vector_, _state_)                             \
329
    CYG_MACRO_START                                                          \
330
    cyg_uint32 _index_;                                                      \
331
    HAL_TRANSLATE_VECTOR ((_vector_), _index_);                              \
332
                                                                             \
333
    if( (CYG_ADDRESS)hal_default_isr  == hal_interrupt_handlers[_vector_] || \
334
        (CYG_ADDRESS)cyg_hal_exception_handler ==                            \
335
        hal_interrupt_handlers[_vector_] ) {                                 \
336
        (_state_) = 0;                                                       \
337
    } else {                                                                 \
338
        (_state_) = 1;                                                       \
339
    }                                                                        \
340
    CYG_MACRO_END
341
 
342
#define HAL_INTERRUPT_ATTACH( _vector_, _isr_, _data_, _object_ )           \
343
    CYG_MACRO_START                                                         \
344
    if( (CYG_ADDRESS)hal_default_isr  == hal_interrupt_handlers[_vector_] ||\
345
        (CYG_ADDRESS)cyg_hal_exception_handler ==                           \
346
        hal_interrupt_handlers[_vector_] )                                  \
347
    {                                                                       \
348
        hal_interrupt_handlers[_vector_] = (CYG_ADDRESS)_isr_;              \
349
        hal_interrupt_data[_vector_] = (CYG_ADDRWORD) _data_;               \
350
        hal_interrupt_objects[_vector_] = (CYG_ADDRESS)_object_;            \
351
    }                                                                       \
352
CYG_MACRO_END
353
 
354
#define HAL_INTERRUPT_DETACH( _vector_, _isr_ ) CYG_MACRO_START             \
355
    if( hal_interrupt_handlers[_vector_] == (CYG_ADDRESS)_isr_ )            \
356
    {                                                                       \
357
        hal_interrupt_handlers[_vector_] =                                  \
358
           (CYG_VECTOR_IS_INTERRUPT( _vector_ )                             \
359
              ? (CYG_ADDRESS)hal_default_isr                                \
360
              : (CYG_ADDRESS)cyg_hal_exception_handler);                    \
361
        hal_interrupt_data[_vector_] = 0;                                   \
362
        hal_interrupt_objects[_vector_] = 0;                                \
363
    }                                                                       \
364
CYG_MACRO_END
365
 
366
#define HAL_VSR_GET( _vector_, _pvsr_ )                                     \
367
    *(CYG_ADDRESS *)(_pvsr_) = hal_vsr_table[_vector_];
368
 
369
 
370
#define HAL_VSR_SET( _vector_, _vsr_, _poldvsr_ ) CYG_MACRO_START           \
371
    if( _poldvsr_ != NULL )                                                 \
372
        *(CYG_ADDRESS *)_poldvsr_ = hal_vsr_table[_vector_];                \
373
    hal_vsr_table[_vector_] = (CYG_ADDRESS)_vsr_;                           \
374
CYG_MACRO_END
375
 
376
// This is an ugly name, but what it means is: grab the VSR back to eCos
377
// internal handling, or if you like, the default handler.  But if
378
// cooperating with GDB and CygMon, the default behaviour is to pass most
379
// exceptions to CygMon.  This macro undoes that so that eCos handles the
380
// exception.  So use it with care.
381
 
382
#define HAL_VSR_SET_TO_ECOS_HANDLER( _vector_, _poldvsr_ ) CYG_MACRO_START  \
383
    if( _poldvsr_ != NULL )                                                 \
384
        *(CYG_ADDRESS *)_poldvsr_ = hal_vsr_table[_vector_];                \
385
    hal_vsr_table[_vector_] = ( CYG_VECTOR_IS_INTERRUPT( _vector_ )         \
386
                              ? (CYG_ADDRESS)hal_default_interrupt_vsr      \
387
                              : (CYG_ADDRESS)hal_default_exception_vsr );   \
388
CYG_MACRO_END
389
 
390
 
391
 
392
//---------------------------------------------------------------------------
393
 
394
// Which PIC (if any) is available is dependent on the board.
395
// This sets up that stuff:
396
 
397
#include <cyg/hal/hal_xpic.h>
398
 
399
// Ditto the clock(s)
400
// This defines all the clock macros the kernel requires:
401
 
402
#include <cyg/hal/hal_clock.h>
403
 
404
//---------------------------------------------------------------------------
405
#endif // ifndef CYGONCE_HAL_INTR_H
406
// 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.