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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [except1.cxx] - Blame information for rev 596

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

Line No. Rev Author Line
1 27 unneback
//=================================================================
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//=================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     dsm
44
// Contributors:  dsm, jlarmour
45
// Date:          1999-02-16
46
// Description:   Test basic exception functionality
47
//####DESCRIPTIONEND####
48
 
49
#include <pkgconf/kernel.h>
50
 
51
#include <cyg/infra/testcase.h>
52
 
53
#ifdef CYGPKG_KERNEL_EXCEPTIONS
54
 
55
#include <cyg/kernel/sched.hxx>         // Cyg_Scheduler::start()
56
#include <cyg/kernel/thread.hxx>        // Cyg_Thread
57
#include <cyg/kernel/intr.hxx>          // cyg_VSR
58
 
59
#include <cyg/hal/hal_intr.h>           // exception ranges
60
 
61
#include <cyg/kernel/sched.inl>
62
#include <cyg/kernel/thread.inl>
63
 
64
#define NTHREADS 1
65
#include "testaux.hxx"
66
 
67
#ifndef CYGPKG_HAL_ARM_PID
68
#define EXCEPTION_DATA_ACCESS
69
#endif
70
 
71
static int d0;
72
#ifdef EXCEPTION_DATA_ACCESS
73
static cyg_exception_handler handler0;
74
 
75
static void handler0(CYG_ADDRWORD data, cyg_code number, CYG_ADDRWORD info)
76
{
77
    CYG_TEST_INFO("handler 0 called");
78
 
79
    CYG_TEST_CHECK((CYG_ADDRWORD)123 == data, "handler given wrong data");
80
 
81
    // ignore machine specific stuff
82
    CYG_UNUSED_PARAM(cyg_code, number);
83
    CYG_UNUSED_PARAM(CYG_ADDRWORD, info);
84
 
85
    CYG_TEST_PASS_FINISH("Except 1 OK");
86
}
87
#endif
88
 
89
static void handler1(CYG_ADDRWORD data, cyg_code number, CYG_ADDRWORD info)
90
{
91
    CYG_TEST_INFO("handler 1 called");
92
 
93
    CYG_TEST_CHECK((CYG_ADDRWORD)&d0 == data, "handler given wrong data");
94
 
95
#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
96
    CYG_TEST_CHECK(number == CYGNUM_HAL_EXCEPTION_MAX, "handler given wrong number");
97
#else
98
    CYG_UNUSED_PARAM(cyg_code, number);
99
#endif
100
 
101
    CYG_TEST_CHECK((CYG_ADDRWORD)99 == info, "handler given wrong info");
102
}
103
 
104
#ifdef EXCEPTION_DATA_ACCESS
105
// The following function attempts to cause an exception in various
106
// hacky ways.  It is machine dependent what exception is generated.
107
// It does reads rather than writes hoping not to corrupt anything
108
// important.
109
static int
110
cause_fpe(int num)
111
{
112
    double a;
113
 
114
    a = 1.0/num;                        // Depending on FPU emulation and/or
115
                                        // the FPU architecture, this may
116
                                        // cause an exception.
117
                                        // (float division by zero)
118
 
119
    return ((int)a)/num;                // This may cause an exception if
120
                                        // the architecture supports it.
121
                                        // (integer division by zero).
122
} // cause_fpe()
123
 
124
void cause_exception(void)
125
{
126
    int x;
127
    unsigned int p=0;
128
 
129
    // First try for an address exception (unaligned access exception
130
    // or SEGV/BUS exceptions)
131
    do {
132
        x=*(volatile int *)(p-1);
133
        p+=0x100000;
134
    } while(p != 0);
135
 
136
    // Next try an integer or floating point divide-by-zero exception.
137
    cause_fpe(0);
138
}
139
#endif
140
 
141
static void entry0( CYG_ADDRWORD data )
142
{
143
#ifdef EXCEPTION_DATA_ACCESS
144
    cyg_code n;
145
#endif
146
    cyg_exception_handler *old_handler, *old_handler1;
147
    CYG_ADDRWORD old_data, old_data1;
148
    Cyg_Thread *p=Cyg_Thread::self();
149
 
150
    CYG_UNUSED_PARAM(CYG_ADDRESS, data);
151
 
152
    p->register_exception(
153
        CYGNUM_HAL_EXCEPTION_MAX,
154
        &handler1,
155
        (CYG_ADDRWORD)&d0,
156
        &old_handler,
157
        &old_data);
158
 
159
    p->register_exception(
160
        CYGNUM_HAL_EXCEPTION_MAX,
161
        &handler1,
162
        (CYG_ADDRWORD)&d0,
163
        &old_handler1,
164
        &old_data1);
165
 
166
    CYG_TEST_CHECK(old_handler1 == &handler1,
167
        "register exception: old_handler not the one previously registered");
168
    CYG_TEST_CHECK(old_data1 == (CYG_ADDRWORD)&d0,
169
        "register exception: old_data not those previously registered");
170
 
171
    p->deliver_exception(CYGNUM_HAL_EXCEPTION_MAX, (CYG_ADDRWORD)99);
172
 
173
    CYG_TEST_INFO("handler 1 returned");
174
 
175
    p->deregister_exception(CYGNUM_HAL_EXCEPTION_MAX);
176
    p->deregister_exception(CYGNUM_HAL_EXCEPTION_MAX);
177
 
178
#ifdef EXCEPTION_DATA_ACCESS
179
 
180
#if 0
181
#elif defined(CYGPKG_HAL_POWERPC_SIM)
182
    // The exception generated by the SIM is not recognized by GDB.
183
    // PR 19945 workaround.
184
    CYG_TEST_NA("Not applicable to PowerPC SIM");
185
#endif
186
 
187
    for(n = CYGNUM_HAL_EXCEPTION_MIN; n <= CYGNUM_HAL_EXCEPTION_MAX; n++) {
188
        p->register_exception(
189
            n,
190
            handler0,
191
            (CYG_ADDRWORD)123,
192
            &old_handler1,
193
            &old_data1);
194
    }
195
 
196
    CYG_TEST_PASS("Attempting to provoke exception");
197
 
198
    cause_exception();
199
 
200
    CYG_TEST_FAIL_FINISH("Couldn't cause exception");
201
#else // EXCEPTION_DATA_ACCESS
202
    CYG_TEST_NA("Platform does not support data exceptions");
203
#endif
204
 
205
}
206
 
207
#ifdef CYG_HAL_MIPS_TX39_JMR3904
208
 
209
externC cyg_VSR __default_exception_vsr;
210
cyg_VSR *old_vsr;
211
 
212
#endif
213
 
214
void except0_main( void )
215
{
216
    // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT()
217
    CYG_TEST_GDBCMD("handle SIGBUS nostop");
218
    CYG_TEST_GDBCMD("handle SIGSEGV nostop");
219
    CYG_TEST_GDBCMD("handle SIGFPE nostop");
220
 
221
    CYG_TEST_INIT();
222
 
223
#ifdef HAL_VSR_SET_TO_ECOS_HANDLER
224
    // Reclaim the VSR off CygMon possibly
225
#ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS
226
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_ACCESS, NULL );
227
#endif
228
#ifdef CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS
229
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS, NULL );
230
#endif
231
#ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS
232
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL );
233
#endif
234
#ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION
235
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL );
236
#endif
237
#ifdef CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO
238
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO, NULL );
239
#endif
240
#ifdef CYGNUM_HAL_EXCEPTION_FPU
241
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU, NULL );
242
#endif
243
#ifdef CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO
244
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO, NULL );
245
#endif
246
#endif
247
 
248
    new_thread(entry0, 0);
249
 
250
    Cyg_Scheduler::start();
251
 
252
    CYG_TEST_FAIL_FINISH("Not reached");
253
}
254
externC void
255
cyg_start( void )
256
{
257
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
258
    cyg_hal_invoke_constructors();
259
#endif
260
    except0_main();
261
}
262
#else // def CYGPKG_KERNEL_EXCEPTIONS
263
externC void
264
cyg_start( void )
265
{
266
    CYG_TEST_INIT();
267
    CYG_TEST_NA("Exceptions disabled");
268
}
269
#endif // def CYGPKG_KERNEL_EXCEPTIONS
270
 
271
// EOF except1.cxx

powered by: WebSVN 2.1.0

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