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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [arch/] [v2_0/] [include/] [hal_intr.h] - Blame information for rev 307

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

Line No. Rev Author Line
1 27 unneback
#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 Red Hat, Inc.
15
// Copyright (C) 2002 Gary Thomas
16
//
17
// eCos is free software; you can redistribute it and/or modify it under
18
// the terms of the GNU General Public License as published by the Free
19
// Software Foundation; either version 2 or (at your option) any later version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
22
// 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 along
27
// with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29
//
30
// As a special exception, if other files instantiate templates or use macros
31
// or inline functions from this file, or you compile this file and link it
32
// with other works to produce a work based on this file, this file does not
33
// by itself cause the resulting work to be covered by the GNU General Public
34
// License. However the source code for this file must still be made available
35
// in accordance with section (3) of the GNU General Public License.
36
//
37
// This exception does not invalidate any other reasons why a work based on
38
// this file might be covered by the GNU General Public License.
39
//
40
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
41
// at http://sources.redhat.com/ecos/ecos-license/
42
// -------------------------------------------
43
//####ECOSGPLCOPYRIGHTEND####
44
//==========================================================================
45
//#####DESCRIPTIONBEGIN####
46
//
47
// Author(s):    nickg
48
// Contributors: nickg, jskov,
49
//               jlarmour
50
// Date:         1999-02-19
51
// Purpose:      Define Interrupt support
52
// Description:  The macros defined here provide the HAL APIs for handling
53
//               interrupts and the clock.
54
//              
55
// Usage:
56
//               #include <cyg/hal/hal_intr.h>
57
//               ...
58
//              
59
//
60
//####DESCRIPTIONEND####
61
//
62
//==========================================================================
63
 
64
#include <pkgconf/hal.h>
65
 
66
#include <cyg/infra/cyg_type.h>         // types
67
 
68
#include <cyg/hal/ppc_regs.h>           // register definitions
69
 
70
#include <cyg/hal/var_intr.h>           // variant extensions
71
 
72
//--------------------------------------------------------------------------
73
// PowerPC exception vectors. These correspond to VSRs and are the values
74
// to use for HAL_VSR_GET/SET
75
 
76
#define CYGNUM_HAL_VECTOR_RESERVED_0        0
77
#define CYGNUM_HAL_VECTOR_RESET             1
78
#define CYGNUM_HAL_VECTOR_MACHINE_CHECK     2
79
#define CYGNUM_HAL_VECTOR_DSI               3
80
#define CYGNUM_HAL_VECTOR_ISI               4
81
#define CYGNUM_HAL_VECTOR_INTERRUPT         5
82
#define CYGNUM_HAL_VECTOR_ALIGNMENT         6
83
#define CYGNUM_HAL_VECTOR_PROGRAM           7
84
#define CYGNUM_HAL_VECTOR_FP_UNAVAILABLE    8
85
#define CYGNUM_HAL_VECTOR_DECREMENTER       9
86
#define CYGNUM_HAL_VECTOR_RESERVED_A        10
87
#define CYGNUM_HAL_VECTOR_RESERVED_B        11
88
#define CYGNUM_HAL_VECTOR_SYSTEM_CALL       12
89
#define CYGNUM_HAL_VECTOR_TRACE             13
90
#define CYGNUM_HAL_VECTOR_FP_ASSIST         14
91
 
92
#define CYGNUM_HAL_VSR_MIN                   CYGNUM_HAL_VECTOR_RESERVED_0
93
#ifndef CYGNUM_HAL_VSR_MAX
94
# define CYGNUM_HAL_VSR_MAX                  CYGNUM_HAL_VECTOR_FP_ASSIST
95
#endif
96
#define CYGNUM_HAL_VSR_COUNT                 ( CYGNUM_HAL_VSR_MAX + 1 )
97
 
98
#ifndef CYG_VECTOR_IS_INTERRUPT
99
# define CYG_VECTOR_IS_INTERRUPT(v)   \
100
     (CYGNUM_HAL_VECTOR_INTERRUPT == (v) \
101
      || CYGNUM_HAL_VECTOR_DECREMENTER == (v))
102
#endif
103
 
104
// The decoded interrupts.
105
// Define decrementer as the first interrupt since it is guaranteed to
106
// be defined on all PowerPCs. External may expand into several interrupts
107
// depending on interrupt controller capabilities.
108
#define CYGNUM_HAL_INTERRUPT_DECREMENTER     0
109
#define CYGNUM_HAL_INTERRUPT_EXTERNAL        1
110
 
111
#define CYGNUM_HAL_ISR_MIN                   CYGNUM_HAL_INTERRUPT_DECREMENTER
112
#ifndef CYGNUM_HAL_ISR_MAX
113
# define CYGNUM_HAL_ISR_MAX                  CYGNUM_HAL_INTERRUPT_EXTERNAL
114
#endif
115
#define CYGNUM_HAL_ISR_COUNT                 ( CYGNUM_HAL_ISR_MAX + 1 )
116
 
117
#ifndef CYGHWR_HAL_EXCEPTION_VECTORS_DEFINED
118
// Exception vectors. These are the values used when passed out to an
119
// external exception handler using cyg_hal_deliver_exception()
120
 
121
#define CYGNUM_HAL_EXCEPTION_RESERVED_0      CYGNUM_HAL_VECTOR_RESERVED_0
122
#define CYGNUM_HAL_EXCEPTION_MACHINE_CHECK   CYGNUM_HAL_VECTOR_MACHINE_CHECK
123
#define CYGNUM_HAL_EXCEPTION_DATA_ACCESS     CYGNUM_HAL_VECTOR_DSI
124
#define CYGNUM_HAL_EXCEPTION_CODE_ACCESS     CYGNUM_HAL_VECTOR_ISI
125
#define CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS  \
126
           CYGNUM_HAL_VECTOR_ALIGNMENT
127
#define CYGNUM_HAL_EXCEPTION_FPU_NOT_AVAIL   CYGNUM_HAL_VECTOR_FP_UNAVAILABLE
128
#define CYGNUM_HAL_EXCEPTION_RESERVED_A      CYGNUM_HAL_VECTOR_RESERVED_A
129
#define CYGNUM_HAL_EXCEPTION_RESERVED_B      CYGNUM_HAL_VECTOR_RESERVED_B
130
#define CYGNUM_HAL_EXCEPTION_SYSTEM_CALL     CYGNUM_HAL_VECTOR_SYSTEM_CALL
131
#define CYGNUM_HAL_EXCEPTION_TRACE           CYGNUM_HAL_VECTOR_TRACE
132
#define CYGNUM_HAL_EXCEPTION_FP_ASSIST       CYGNUM_HAL_VECTOR_FP_ASSIST
133
 
134
#define CYGNUM_HAL_EXCEPTION_MIN             CYGNUM_HAL_EXCEPTION_RESERVED_0
135
#ifndef CYGNUM_HAL_EXCEPTION_MAX
136
#define CYGNUM_HAL_EXCEPTION_MAX             CYGNUM_HAL_VSR_MAX
137
#endif
138
 
139
#define CYGHWR_HAL_EXCEPTION_VECTORS_DEFINED
140
 
141
#endif // CYGHWR_HAL_EXCEPTION_VECTORS_DEFINED
142
 
143
// FIXME: This is still rather ugly. Should probably be made variant
144
//        specific using a decode_hal_exception macro or somesuch.
145
// decoded exception vectors
146
#define CYGNUM_HAL_EXCEPTION_TRAP                     (-1)
147
#define CYGNUM_HAL_EXCEPTION_PRIVILEGED_INSTRUCTION   (-2)
148
#define CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION      (-3)
149
#define CYGNUM_HAL_EXCEPTION_FPU                      (-4)
150
 
151
#undef  CYGNUM_HAL_EXCEPTION_MIN
152
#define CYGNUM_HAL_EXCEPTION_MIN             CYGNUM_HAL_EXCEPTION_FPU
153
 
154
 
155
#define CYGNUM_HAL_EXCEPTION_COUNT           \
156
                 ( CYGNUM_HAL_EXCEPTION_MAX - CYGNUM_HAL_EXCEPTION_MIN + 1 )
157
 
158
//--------------------------------------------------------------------------
159
// Static data used by HAL
160
 
161
// ISR tables
162
externC volatile CYG_ADDRESS    hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
163
externC volatile CYG_ADDRWORD   hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
164
externC volatile CYG_ADDRESS    hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
165
// VSR table
166
externC volatile CYG_ADDRESS    hal_vsr_table[CYGNUM_HAL_VSR_COUNT];
167
 
168
//--------------------------------------------------------------------------
169
// Default ISRs
170
// The #define is used to test whether this routine exists, and to allow
171
// us to call it.
172
 
173
externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data);
174
externC cyg_uint32 hal_default_decrementer_isr(CYG_ADDRWORD vector,
175
                                               CYG_ADDRWORD data);
176
 
177
#define HAL_DEFAULT_ISR hal_default_isr
178
 
179
//--------------------------------------------------------------------------
180
// Interrupt state storage
181
 
182
typedef cyg_uint32 CYG_INTERRUPT_STATE;
183
 
184
//--------------------------------------------------------------------------
185
// Interrupt control macros
186
 
187
#define HAL_DISABLE_INTERRUPTS(_old_)                   \
188
    CYG_MACRO_START                                     \
189
    cyg_uint32 tmp1, tmp2;                              \
190
    asm volatile (                                      \
191
        "mfmsr  %0;"                                    \
192
        "mr     %2,%0;"                                 \
193
        "li     %1,0;"                                  \
194
        "rlwimi %2,%1,0,16,16;"                         \
195
        "mtmsr  %2;"                                    \
196
        : "=r"(_old_), "=r" (tmp1), "=r" (tmp2));       \
197
    CYG_MACRO_END
198
 
199
#define HAL_ENABLE_INTERRUPTS()         \
200
    CYG_MACRO_START                     \
201
    cyg_uint32 tmp1, tmp2;              \
202
    asm volatile (                      \
203
        "mfmsr  %0;"                    \
204
        "ori    %1,%1,0x8000;"          \
205
        "rlwimi %0,%1,0,16,16;"         \
206
        "mtmsr  %0;"                    \
207
        : "=r" (tmp1), "=r" (tmp2));    \
208
    CYG_MACRO_END
209
 
210
#define HAL_RESTORE_INTERRUPTS(_old_)   \
211
    CYG_MACRO_START                     \
212
    cyg_uint32 tmp;                     \
213
    asm volatile (                      \
214
        "mfmsr  %0;"                    \
215
        "rlwimi %0,%1,0,16,16;"         \
216
        "mtmsr  %0;"                    \
217
        : "=&r" (tmp)                   \
218
        : "r" (_old_));                 \
219
    CYG_MACRO_END
220
 
221
#define HAL_QUERY_INTERRUPTS(_old_)     \
222
    CYG_MACRO_START                     \
223
    cyg_uint32 tmp;                     \
224
    asm volatile (                      \
225
        "mfmsr  %0;"                    \
226
        "lis    %1,0;"                  \
227
        "ori    %1,%1,0x8000;"          \
228
        "and    %0,%0,%1;"              \
229
        : "=&r"(_old_), "=r" (tmp));     \
230
    CYG_MACRO_END
231
 
232
//--------------------------------------------------------------------------
233
// Vector translation.
234
 
235
#ifndef HAL_TRANSLATE_VECTOR
236
// Basic PowerPC configuration only has two vectors; decrementer and
237
// external. Isr tables/chaining use same vector decoder.
238
#define HAL_TRANSLATE_VECTOR(_vector_,_index_) \
239
    (_index_) = (_vector_)
240
#endif
241
 
242
//--------------------------------------------------------------------------
243
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
244
 
245
externC void hal_interrupt_stack_call_pending_DSRs(void);
246
#define HAL_INTERRUPT_STACK_CALL_PENDING_DSRS() \
247
    hal_interrupt_stack_call_pending_DSRs()
248
 
249
// these are offered solely for stack usage testing
250
// if they are not defined, then there is no interrupt stack.
251
#define HAL_INTERRUPT_STACK_BASE cyg_interrupt_stack_base
252
#define HAL_INTERRUPT_STACK_TOP  cyg_interrupt_stack
253
// use them to declare these extern however you want:
254
//       extern char HAL_INTERRUPT_STACK_BASE[];
255
//       extern char HAL_INTERRUPT_STACK_TOP[];
256
// is recommended
257
#endif
258
 
259
//--------------------------------------------------------------------------
260
// Interrupt and VSR attachment macros
261
 
262
#define HAL_INTERRUPT_IN_USE( _vector_, _state_)                             \
263
    CYG_MACRO_START                                                          \
264
    cyg_uint32 _index_;                                                      \
265
    HAL_TRANSLATE_VECTOR ((_vector_), _index_);                              \
266
                                                                             \
267
    if((hal_interrupt_handlers[_index_]                                      \
268
            == (CYG_ADDRESS)hal_default_decrementer_isr)                     \
269
       || (hal_interrupt_handlers[_index_] == (CYG_ADDRESS)hal_default_isr)) \
270
        (_state_) = 0;                                                       \
271
    else                                                                     \
272
        (_state_) = 1;                                                       \
273
    CYG_MACRO_END
274
 
275
#define HAL_INTERRUPT_ATTACH( _vector_, _isr_, _data_, _object_ )            \
276
    CYG_MACRO_START                                                          \
277
    cyg_uint32 _index_;                                                      \
278
    HAL_TRANSLATE_VECTOR ((_vector_), _index_);                              \
279
                                                                             \
280
    if((hal_interrupt_handlers[_index_]                                      \
281
            == (CYG_ADDRESS)hal_default_decrementer_isr)                     \
282
       || (hal_interrupt_handlers[_index_] == (CYG_ADDRESS)hal_default_isr)) \
283
    {                                                                        \
284
        hal_interrupt_handlers[_index_] = (CYG_ADDRESS)_isr_;                \
285
        hal_interrupt_data[_index_] = (CYG_ADDRWORD) _data_;                 \
286
        hal_interrupt_objects[_index_] = (CYG_ADDRESS)_object_;              \
287
    }                                                                        \
288
    CYG_MACRO_END
289
 
290
#define HAL_INTERRUPT_DETACH( _vector_, _isr_ )                             \
291
    CYG_MACRO_START                                                         \
292
    cyg_uint32 _index_;                                                     \
293
    HAL_TRANSLATE_VECTOR ((_vector_), _index_);                             \
294
                                                                            \
295
    if( hal_interrupt_handlers[_index_] == (CYG_ADDRESS)_isr_ )             \
296
    {                                                                       \
297
        if (CYGNUM_HAL_INTERRUPT_DECREMENTER == (_vector_))                 \
298
            hal_interrupt_handlers[_index_] =                               \
299
                (CYG_ADDRESS)hal_default_decrementer_isr;                   \
300
        else                                                                \
301
            hal_interrupt_handlers[_index_] = (CYG_ADDRESS)hal_default_isr; \
302
        hal_interrupt_data[_index_] = 0;                                    \
303
        hal_interrupt_objects[_index_] = 0;                                 \
304
    }                                                                       \
305
    CYG_MACRO_END
306
 
307
#define HAL_VSR_GET( _vector_, _pvsr_ )                                 \
308
    *(CYG_ADDRESS *)(_pvsr_) = hal_vsr_table[_vector_];
309
 
310
 
311
#define HAL_VSR_SET( _vector_, _vsr_, _poldvsr_ )               \
312
    CYG_MACRO_START                                             \
313
    if( _poldvsr_ != NULL )                                     \
314
        *(CYG_ADDRESS *)_poldvsr_ = hal_vsr_table[_vector_];    \
315
    hal_vsr_table[_vector_] = (CYG_ADDRESS)_vsr_;               \
316
    CYG_MACRO_END
317
 
318
// This is an ugly name, but what it means is: grab the VSR back to eCos
319
// internal handling, or if you like, the default handler.  But if
320
// cooperating with GDB and CygMon, the default behaviour is to pass most
321
// exceptions to CygMon.  This macro undoes that so that eCos handles the
322
// exception.  So use it with care.
323
externC void cyg_hal_default_interrupt_vsr( void );
324
externC void cyg_hal_default_exception_vsr( void );
325
#define HAL_VSR_SET_TO_ECOS_HANDLER( _vector_, _poldvsr_ )                    \
326
    CYG_MACRO_START                                                           \
327
    if( (void*)_poldvsr_ != (void*)NULL )                                     \
328
        *(CYG_ADDRESS *)_poldvsr_ = hal_vsr_table[_vector_];                  \
329
    hal_vsr_table[_vector_] = ( CYG_VECTOR_IS_INTERRUPT( _vector_ )           \
330
                               ? (CYG_ADDRESS)cyg_hal_default_interrupt_vsr   \
331
                              : (CYG_ADDRESS)cyg_hal_default_exception_vsr ); \
332
    CYG_MACRO_END
333
 
334
 
335
#ifndef CYGHWR_HAL_INTERRUPT_CONTROLLER_ACCESS_DEFINED
336
 
337
#define HAL_INTERRUPT_MASK( _vector_ )
338
 
339
#define HAL_INTERRUPT_UNMASK( _vector_ )
340
 
341
#define HAL_INTERRUPT_ACKNOWLEDGE( _vector_ )
342
 
343
#define HAL_INTERRUPT_CONFIGURE( _vector_, _level_, _up_ )
344
 
345
#define HAL_INTERRUPT_SET_LEVEL( _vector_, _level_ )
346
 
347
#endif
348
 
349
//--------------------------------------------------------------------------
350
// Clock control
351
 
352
#ifndef CYGHWR_HAL_CLOCK_DEFINED
353
// Note: variant or platform allowed to override these definitions
354
 
355
#define HAL_CLOCK_INITIALIZE( _period_ )        \
356
    CYG_MACRO_START                             \
357
    asm volatile (                              \
358
        "mtdec %0;"                             \
359
        :                                       \
360
        : "r"(_period_)                         \
361
        );                                      \
362
    CYG_MACRO_END
363
 
364
#define HAL_CLOCK_RESET( _vector_, _period_ )   \
365
    CYG_MACRO_START                             \
366
    cyg_uint32 tmp;                             \
367
    asm volatile (                              \
368
        "mfdec  %0;"                            \
369
        "add.   %0,%0,%1;"                      \
370
        "bgt    1f;"                            \
371
        "mr     %0,%1;"                         \
372
        "1: mtdec %0;"                          \
373
        : "=&r" (tmp)                           \
374
        : "r"(_period_)                         \
375
        : "cc"                                  \
376
        );                                      \
377
    CYG_MACRO_END
378
 
379
#define HAL_CLOCK_READ( _pvalue_ )                              \
380
    CYG_MACRO_START                                             \
381
    register cyg_uint32 result;                                 \
382
    asm volatile(                                               \
383
        "mfdec  %0;"                                            \
384
        : "=r"(result)                                          \
385
        );                                                      \
386
    *(_pvalue_) = CYGNUM_KERNEL_COUNTERS_RTC_PERIOD-result;     \
387
    CYG_MACRO_END
388
 
389
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY
390
#define HAL_CLOCK_LATENCY( _pvalue_ )                           \
391
    CYG_MACRO_START                                             \
392
    register cyg_int32 result;                                  \
393
    asm volatile(                                               \
394
        "mfdec  %0;"                                            \
395
        : "=r"(result)                                          \
396
        );                                                      \
397
    /* Pending DEC interrupts cannot be discarded. If dec is */ \
398
    /* positive it''s because a DEC interrupt occured while  */ \
399
    /* eCos was getting ready to run. Just return 0 in that  */ \
400
    /* case.                                                 */ \
401
    if (result > 0)                                             \
402
        result = 0;                                             \
403
    *(_pvalue_) = -result;                                      \
404
    CYG_MACRO_END
405
#endif
406
 
407
#ifndef HAL_DELAY_US
408
extern void hal_delay_us(int);
409
#define HAL_DELAY_US(n) hal_delay_us(n)
410
#endif
411
 
412
// The vector used by the Real time clock
413
#ifndef CYGNUM_HAL_INTERRUPT_RTC
414
#define CYGNUM_HAL_INTERRUPT_RTC             CYGNUM_HAL_INTERRUPT_DECREMENTER
415
#endif // CYGNUM_HAL_INTERRUPT_RTC
416
 
417
#endif // CYGHWR_HAL_CLOCK_DEFINED
418
 
419
//--------------------------------------------------------------------------
420
// Variant functions
421
externC void hal_variant_IRQ_init(void);
422
 
423
//--------------------------------------------------------------------------
424
#endif // ifndef CYGONCE_HAL_INTR_H
425
// 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.