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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [kexcept1.c] - Blame information for rev 851

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

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

powered by: WebSVN 2.1.0

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