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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [src/] [common/] [except.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      common/except.cxx
4
//
5
//      Exception handling implementation
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: nickg, jlarmour
44
// Date:         1999-02-16
45
// Purpose:      Exception handling implementation
46
// Description:  This file contains the code that registers and delivers
47
//               exceptions.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#include <pkgconf/kernel.h>
54
 
55
#include <cyg/kernel/ktypes.h>         // base kernel types
56
#include <cyg/infra/cyg_trac.h>        // tracing macros
57
#include <cyg/infra/cyg_ass.h>         // assertion macros
58
#include <cyg/kernel/instrmnt.h>       // instrumentation
59
 
60
#include <cyg/kernel/except.hxx>       // our header
61
 
62
#include <cyg/hal/hal_arch.h>          // architecture definitions
63
#include <cyg/hal/hal_intr.h>          // vector definitions
64
 
65
#include <cyg/kernel/thread.hxx>       // thread interface
66
 
67
#include <cyg/kernel/thread.inl>       // thread inlines
68
 
69
#ifdef CYGPKG_KERNEL_EXCEPTIONS
70
 
71
// -------------------------------------------------------------------------
72
// Null exception handler. This is used to capture exceptions that are
73
// not caught by user supplied handlers.
74
 
75
void
76
cyg_null_exception_handler(
77
    CYG_ADDRWORD        data,                   // user supplied data
78
    cyg_code            exception_number,       // exception being raised
79
    CYG_ADDRWORD        exception_info          // any exception specific info
80
    )
81
{
82
    CYG_REPORT_FUNCTION();
83
    CYG_REPORT_FUNCARG3("data=%08x, exception=%d, info=%08x", data,
84
                        exception_number, exception_info);
85
    CYG_TRACE1( 1, "Uncaught exception: %d", exception_number);
86
    CYG_REPORT_RETURN();
87
}
88
 
89
// -------------------------------------------------------------------------
90
// Exception Controller constructor.
91
 
92
Cyg_Exception_Control::Cyg_Exception_Control()
93
{
94
    CYG_REPORT_FUNCTION();
95
#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
96
 
97
    for( int i = 0; i < CYGNUM_HAL_EXCEPTION_COUNT ; i++ )
98
        exception_handler[i] = cyg_null_exception_handler,
99
            exception_data[i] = 0;
100
#else
101
 
102
    exception_handler = cyg_null_exception_handler;
103
    exception_data = 0;
104
 
105
#endif
106
    CYG_REPORT_RETURN();
107
}
108
 
109
// -------------------------------------------------------------------------
110
// Exception registation. Stores the handler function and data to be used
111
// for handling the given exception number. Where exceptions are not decoded
112
// only a single handler may be registered for all exceptions. This function
113
// also returns the old values of the exception handler and data to allow
114
// chaining to be implemented.
115
 
116
void
117
Cyg_Exception_Control::register_exception(
118
    cyg_code                exception_number,       // exception number
119
    cyg_exception_handler   handler,                // handler function
120
    CYG_ADDRWORD            data,                   // data argument
121
    cyg_exception_handler   **old_handler,          // handler function
122
    CYG_ADDRWORD            *old_data               // data argument
123
    )
124
{
125
    CYG_REPORT_FUNCTION();
126
    CYG_REPORT_FUNCARG5("exception=%d, handler func=%08x, data=%08x, "
127
                        "space for old handler=%08x,space for old data=%08x",
128
                        exception_number, handler, data, old_handler,
129
                        old_data);
130
 
131
    CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX,
132
                "Out of range exception number");
133
    CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN,
134
                "Out of range exception number");
135
 
136
 
137
    // Should we complain if there is already a registered
138
    // handler, or should we just replace is silently?
139
 
140
#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
141
 
142
    if( old_handler != NULL )
143
        *old_handler = exception_handler[exception_number -
144
                                        CYGNUM_HAL_EXCEPTION_MIN];
145
    if( old_data != NULL )
146
        *old_data = exception_data[exception_number -
147
                                  CYGNUM_HAL_EXCEPTION_MIN];
148
    exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = handler;
149
    exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = data;
150
 
151
#else
152
 
153
    if( old_handler != NULL )
154
        *old_handler = exception_handler;
155
    if( old_data != NULL )
156
        *old_data = exception_data;
157
    exception_handler = handler;
158
    exception_data = data;
159
 
160
#endif
161
    CYG_REPORT_RETURN();
162
}
163
 
164
// -------------------------------------------------------------------------
165
// Exception deregistation. Revert the handler for the exception number
166
// to the default.
167
 
168
void
169
Cyg_Exception_Control::deregister_exception(
170
    cyg_code                exception_number        // exception number
171
    )
172
{
173
    CYG_REPORT_FUNCTION();
174
    CYG_REPORT_FUNCARG1("exception number=%d", exception_number);
175
 
176
    CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX,
177
                "Out of range exception number");
178
    CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN,
179
                "Out of range exception number");
180
 
181
#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
182
 
183
    exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN] =
184
        cyg_null_exception_handler;
185
    exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN] = 0;
186
 
187
#else
188
 
189
    exception_handler = cyg_null_exception_handler;
190
    exception_data = 0;
191
 
192
#endif
193
 
194
    CYG_REPORT_RETURN();
195
}
196
 
197
// -------------------------------------------------------------------------
198
// Exception delivery. Call the appropriate exception handler.
199
 
200
void
201
Cyg_Exception_Control::deliver_exception(
202
    cyg_code            exception_number,       // exception being raised
203
    CYG_ADDRWORD        exception_info          // exception specific info
204
    )
205
{
206
    CYG_REPORT_FUNCTION();
207
    CYG_REPORT_FUNCARG2("exception number=%d, exception info=%08x",
208
                        exception_number, exception_info);
209
 
210
    cyg_exception_handler *handler = NULL;
211
    CYG_ADDRWORD data = 0;
212
 
213
    CYG_ASSERT( exception_number <= CYGNUM_HAL_EXCEPTION_MAX,
214
                "Out of range exception number");
215
    CYG_ASSERT( exception_number >= CYGNUM_HAL_EXCEPTION_MIN,
216
                "Out of range exception number");
217
 
218
#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
219
 
220
    handler = exception_handler[exception_number - CYGNUM_HAL_EXCEPTION_MIN];
221
    data = exception_data[exception_number - CYGNUM_HAL_EXCEPTION_MIN];
222
 
223
#else
224
 
225
    handler = exception_handler;
226
    data = exception_data;
227
 
228
#endif
229
 
230
    // The handler will always be a callable function: either the user's
231
    // registered function or the null handler. So it is always safe to
232
    // just go ahead and call it.
233
 
234
    handler( data, exception_number, exception_info );
235
 
236
    CYG_REPORT_RETURN();
237
}
238
 
239
// -------------------------------------------------------------------------
240
// Exception delivery function called from the HAL as a result of a
241
// hardware exception being raised.
242
 
243
externC void
244
cyg_hal_deliver_exception( CYG_WORD code, CYG_ADDRWORD data )
245
{
246
    CYG_REPORT_FUNCTION();
247
    Cyg_Thread::self()->deliver_exception( (cyg_code)code, data );
248
    CYG_REPORT_RETURN();
249
}
250
 
251
// -------------------------------------------------------------------------
252
// Where exceptions are global, there is a single static instance of the
253
// exception control object. Define it here.
254
 
255
#ifdef CYGSEM_KERNEL_EXCEPTIONS_GLOBAL
256
 
257
Cyg_Exception_Control Cyg_Thread::exception_control
258
                                              CYG_INIT_PRIORITY(INTERRUPTS);
259
 
260
#endif
261
 
262
// -------------------------------------------------------------------------
263
 
264
#endif // ifdef CYGPKG_KERNEL_EXCEPTIONS
265
 
266
// -------------------------------------------------------------------------
267
// EOF common/except.cxx

powered by: WebSVN 2.1.0

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