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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [except1.cxx] - Blame information for rev 868

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

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        except1.cxx
4
//
5
//        Exception test 1
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):     dsm
43
// Contributors:  dsm, jlarmour
44
// Date:          1999-02-16
45
// Description:   Test basic exception functionality
46
//####DESCRIPTIONEND####
47
 
48
#include <pkgconf/kernel.h>
49
 
50
#include <cyg/infra/testcase.h>
51
 
52
#ifdef CYGPKG_KERNEL_EXCEPTIONS
53
 
54
#include <cyg/kernel/sched.hxx>         // Cyg_Scheduler::start()
55
#include <cyg/kernel/thread.hxx>        // Cyg_Thread
56
#include <cyg/kernel/intr.hxx>          // cyg_VSR
57
 
58
#include <cyg/hal/hal_intr.h>           // exception ranges
59
 
60
#include <cyg/kernel/sched.inl>
61
#include <cyg/kernel/thread.inl>
62
 
63
#define NTHREADS 1
64
#include "testaux.hxx"
65
 
66
#ifndef CYGPKG_HAL_ARM_PID
67
#define EXCEPTION_DATA_ACCESS
68
#endif
69
 
70
static int d0;
71
#ifdef EXCEPTION_DATA_ACCESS
72
static cyg_exception_handler handler0;
73
 
74
static void handler0(CYG_ADDRWORD data, cyg_code number, CYG_ADDRWORD info)
75
{
76
    CYG_TEST_INFO("handler 0 called");
77
 
78
    CYG_TEST_CHECK((CYG_ADDRWORD)123 == data, "handler given wrong data");
79
 
80
    // ignore machine specific stuff
81
    CYG_UNUSED_PARAM(cyg_code, number);
82
    CYG_UNUSED_PARAM(CYG_ADDRWORD, info);
83
 
84
    CYG_TEST_PASS_FINISH("Except 1 OK");
85
}
86
#endif
87
 
88
static void handler1(CYG_ADDRWORD data, cyg_code number, CYG_ADDRWORD info)
89
{
90
    CYG_TEST_INFO("handler 1 called");
91
 
92
    CYG_TEST_CHECK((CYG_ADDRWORD)&d0 == data, "handler given wrong data");
93
 
94
#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
95
    CYG_TEST_CHECK(number == CYGNUM_HAL_EXCEPTION_MAX, "handler given wrong number");
96
#else
97
    CYG_UNUSED_PARAM(cyg_code, number);
98
#endif
99
 
100
    CYG_TEST_CHECK((CYG_ADDRWORD)99 == info, "handler given wrong info");
101
}
102
 
103
#ifdef EXCEPTION_DATA_ACCESS
104
// The following function attempts to cause an exception in various
105
// hacky ways.  It is machine dependent what exception is generated.
106
// It does reads rather than writes hoping not to corrupt anything
107
// important.
108
static int
109
cause_fpe(int num)
110
{
111
    double a;
112
 
113
    a = 1.0/num;                        // Depending on FPU emulation and/or
114
                                        // the FPU architecture, this may
115
                                        // cause an exception.
116
                                        // (float division by zero)
117
 
118
    return ((int)a)/num;                // This may cause an exception if
119
                                        // the architecture supports it.
120
                                        // (integer division by zero).
121
} // cause_fpe()
122
 
123
void cause_exception(void)
124
{
125
    int x;
126
    unsigned int p=0;
127
 
128
    // First try for an address exception (unaligned access exception
129
    // or SEGV/BUS exceptions)
130
    do {
131
        x=*(volatile int *)(p-1);
132
        p+=0x100000;
133
    } while(p != 0);
134
 
135
    // Next try an integer or floating point divide-by-zero exception.
136
    cause_fpe(0);
137
}
138
#endif
139
 
140
static void entry0( CYG_ADDRWORD data )
141
{
142
#ifdef EXCEPTION_DATA_ACCESS
143
    cyg_code n;
144
#endif
145
    cyg_exception_handler *old_handler, *old_handler1;
146
    CYG_ADDRWORD old_data, old_data1;
147
    Cyg_Thread *p=Cyg_Thread::self();
148
 
149
    CYG_UNUSED_PARAM(CYG_ADDRESS, data);
150
 
151
    p->register_exception(
152
        CYGNUM_HAL_EXCEPTION_MAX,
153
        &handler1,
154
        (CYG_ADDRWORD)&d0,
155
        &old_handler,
156
        &old_data);
157
 
158
    p->register_exception(
159
        CYGNUM_HAL_EXCEPTION_MAX,
160
        &handler1,
161
        (CYG_ADDRWORD)&d0,
162
        &old_handler1,
163
        &old_data1);
164
 
165
    CYG_TEST_CHECK(old_handler1 == &handler1,
166
        "register exception: old_handler not the one previously registered");
167
    CYG_TEST_CHECK(old_data1 == (CYG_ADDRWORD)&d0,
168
        "register exception: old_data not those previously registered");
169
 
170
    p->deliver_exception(CYGNUM_HAL_EXCEPTION_MAX, (CYG_ADDRWORD)99);
171
 
172
    CYG_TEST_INFO("handler 1 returned");
173
 
174
    p->deregister_exception(CYGNUM_HAL_EXCEPTION_MAX);
175
    p->deregister_exception(CYGNUM_HAL_EXCEPTION_MAX);
176
 
177
#ifdef EXCEPTION_DATA_ACCESS
178
 
179
#if 0
180
#elif defined(CYGPKG_HAL_POWERPC_SIM)
181
    // The exception generated by the SIM is not recognized by GDB.
182
    // PR 19945 workaround.
183
    CYG_TEST_NA("Not applicable to PowerPC SIM");
184
#endif
185
 
186
    for(n = CYGNUM_HAL_EXCEPTION_MIN; n <= CYGNUM_HAL_EXCEPTION_MAX; n++) {
187
        p->register_exception(
188
            n,
189
            handler0,
190
            (CYG_ADDRWORD)123,
191
            &old_handler1,
192
            &old_data1);
193
    }
194
 
195
    CYG_TEST_PASS("Attempting to provoke exception");
196
 
197
    cause_exception();
198
 
199
    CYG_TEST_FAIL_FINISH("Couldn't cause exception");
200
#else // EXCEPTION_DATA_ACCESS
201
    CYG_TEST_NA("Platform does not support data exceptions");
202
#endif
203
 
204
}
205
 
206
#ifdef CYG_HAL_MIPS_TX39_JMR3904
207
 
208
externC cyg_VSR __default_exception_vsr;
209
cyg_VSR *old_vsr;
210
 
211
#endif
212
 
213
void except0_main( void )
214
{
215
    // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT()
216
    CYG_TEST_GDBCMD("handle SIGBUS nostop");
217
    CYG_TEST_GDBCMD("handle SIGSEGV nostop");
218
    CYG_TEST_GDBCMD("handle SIGFPE nostop");
219
 
220
    CYG_TEST_INIT();
221
 
222
#ifdef HAL_VSR_SET_TO_ECOS_HANDLER
223
    // Reclaim the VSR off CygMon possibly
224
#ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS
225
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_ACCESS, NULL );
226
#endif
227
#ifdef CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS
228
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS, NULL );
229
#endif
230
#ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS
231
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL );
232
#endif
233
#ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION
234
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL );
235
#endif
236
#ifdef CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO
237
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO, NULL );
238
#endif
239
#ifdef CYGNUM_HAL_EXCEPTION_FPU
240
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU, NULL );
241
#endif
242
#ifdef CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO
243
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO, NULL );
244
#endif
245
#endif
246
 
247
    new_thread(entry0, 0);
248
 
249
    Cyg_Scheduler::start();
250
 
251
    CYG_TEST_FAIL_FINISH("Not reached");
252
}
253
externC void
254
cyg_start( void )
255
{
256
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
257
    cyg_hal_invoke_constructors();
258
#endif
259
    except0_main();
260
}
261
#else // def CYGPKG_KERNEL_EXCEPTIONS
262
externC void
263
cyg_start( void )
264
{
265
    CYG_TEST_INIT();
266
    CYG_TEST_NA("Exceptions disabled");
267
}
268
#endif // def CYGPKG_KERNEL_EXCEPTIONS
269
 
270
// EOF except1.cxx

powered by: WebSVN 2.1.0

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