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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [compat/] [posix/] [current/] [tests/] [signal2.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        signal2.cxx
4
//
5
//        POSIX signal test 2
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:  jlarmour
44
// Date:          2000-04-10
45
// Description:   Tests POSIX signal functionality.
46
//
47
//####DESCRIPTIONEND####
48
//==========================================================================
49
 
50
#include <pkgconf/isoinfra.h>
51
#include <cyg/hal/hal_intr.h>   // For exception codes
52
 
53
#include <sys/types.h>
54
#include <pthread.h>
55
#include <signal.h>
56
#include <semaphore.h>
57
 
58
#include <setjmp.h>
59
 
60
#include <cyg/infra/testcase.h>
61
 
62
#if CYGINT_ISO_SETJMP == 0
63
# define NA_MSG "Requires setjmp/longjmp implementation"
64
#elif !defined(CYGPKG_POSIX_SIGNALS)
65
# define NA_MSG "POSIX signals not enabled"
66
#endif
67
 
68
#ifdef NA_MSG
69
void
70
cyg_start(void)
71
{
72
    CYG_TEST_INIT();
73
    CYG_TEST_NA( NA_MSG );
74
}
75
#else
76
 
77
//--------------------------------------------------------------------------
78
// Local variables
79
 
80
static jmp_buf jbuf;
81
 
82
//--------------------------------------------------------------------------
83
 
84
// PowerPC is a special case as it has the alignment exception, but it
85
// doesn't trigger for this function unless in little-endian mode (although
86
// the exception exists for other instructions not used by this function so
87
// CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS will still be defined
88
 
89
#if defined(CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS) && !(defined(CYGPKG_HAL_POWERPC) && (CYG_BYTEORDER==CYG_MSBFIRST))
90
 
91
static void
92
cause_unaligned_access(void)
93
{
94
    volatile int x;
95
    volatile CYG_ADDRESS p=(CYG_ADDRESS) &jbuf;
96
 
97
    x = *(volatile int *)(p+1);
98
 
99
} // cause_unaligned_access()
100
 
101
#endif
102
 
103
//--------------------------------------------------------------------------
104
 
105
#ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS
106
 
107
static void
108
cause_illegal_access(void)
109
{
110
#ifdef CYGPKG_HAL_I386
111
 
112
    // In the x86 architecture, although we have the DATA_ACCESS
113
    // exception available, it is not possible to provoke it using the
114
    // normal code of this test. This is because the normal segments we
115
    // have installed in the segment registers cover all of memory. Instead we
116
    // set GS to a descriptor that does not cover 0xF0000000-0xFFFFFFFF and
117
    // poke at that.
118
 
119
    __asm__ ( "movw     $0x20,%%ax\n"
120
              "movw     %%ax,%%gs\n"
121
              "movl     %%gs:0xF0000000,%%eax\n"
122
              :
123
              :
124
              : "eax"
125
            );
126
 
127
#else    
128
    volatile int x CYGBLD_ATTRIB_UNUSED;
129
    volatile CYG_ADDRESS p=(CYG_ADDRESS) &jbuf;
130
 
131
    do
132
    {
133
        x = *(volatile int *)(p);
134
        p += (CYG_ADDRESS)0x100000;
135
    } while( p != (CYG_ADDRESS)&jbuf );
136
 
137
#endif    
138
} // cause_illegal_access()
139
 
140
#endif
141
 
142
//--------------------------------------------------------------------------
143
 
144
#ifdef CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO
145
 
146
// num must always be 0 - do it this way in case the optimizer tries to
147
// get smart
148
 
149
static int
150
cause_fpe(int num)
151
{
152
    double a;
153
 
154
    a = 1.0/num;                        // Depending on FPU emulation and/or
155
                                        // the FPU architecture, this may
156
                                        // cause an exception.
157
                                        // (float division by zero)
158
 
159
    return ((int)a)/num;                // This may cause an exception if
160
                                        // the architecture supports it.
161
                                        // (integer division by zero).
162
} // cause_fpe()
163
 
164
#endif
165
 
166
//--------------------------------------------------------------------------
167
// Signal handler functions
168
 
169
static void sigsegv( int signo )
170
{
171
    CYG_TEST_INFO( "sigsegv() handler called" );
172
    CYG_TEST_CHECK( signo == SIGSEGV, "Signal not SIGSEGV");
173
 
174
    longjmp( jbuf, 1 );
175
}
176
 
177
static void sigbus( int signo )
178
{
179
    CYG_TEST_INFO( "sigbus() handler called" );
180
    CYG_TEST_CHECK( signo == SIGBUS, "Signal not SIGBUS");
181
 
182
    longjmp( jbuf, 1 );
183
}
184
 
185
static void sigfpe( int signo )
186
{
187
    CYG_TEST_INFO( "sigfpe() handler called" );
188
    CYG_TEST_CHECK( signo == SIGFPE, "Signal not SIGFPE");
189
 
190
    longjmp( jbuf, 1 );
191
}
192
 
193
 
194
//--------------------------------------------------------------------------
195
 
196
int main(int argc, char **argv)
197
{
198
    int ret;
199
    sigset_t mask;
200
    struct sigaction sa;
201
 
202
    CYG_TEST_INIT();
203
 
204
    // Make a full signal set
205
    sigfillset( &mask );
206
 
207
 
208
    // Install signal handlers
209
 
210
    sa.sa_mask = mask;
211
    sa.sa_flags = 0;
212
 
213
    sa.sa_handler = sigsegv;
214
    ret = sigaction( SIGSEGV, &sa, NULL );
215
    CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
216
 
217
    sa.sa_handler = sigbus;
218
    ret = sigaction( SIGBUS, &sa, NULL );
219
    CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
220
 
221
    sa.sa_handler = sigfpe;
222
    ret = sigaction( SIGFPE, &sa, NULL );
223
    CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
224
 
225
    // now make an empty signal set
226
    sigemptyset( &mask );
227
 
228
// Now reset the various exception handlers to eCos handlers so that we
229
// have control; this is the target side equivalent of the CYG_TEST_GDBCMD
230
// lines above:
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_FPU_DIV_BY_ZERO
246
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO, NULL );
247
#endif
248
#endif
249
 
250
    // PowerPC is a special case as it has the alignment exception, but it
251
    // doesn't trigger for this function unless in little-endian mode (although
252
    // the exception exists for other instructions not used by this function so
253
    // CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS will still be defined
254
 
255
#if defined(CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS) && !(defined(CYGPKG_HAL_POWERPC) && (CYG_BYTEORDER==CYG_MSBFIRST))
256
 
257
    CYG_TEST_INFO("Test 1 - provoke unaligned access");
258
 
259
    if( setjmp( jbuf ) == 0 )
260
    {
261
        pthread_sigmask( SIG_SETMASK, &mask, NULL );
262
        cause_unaligned_access();
263
        CYG_TEST_FAIL("Didn't cause exception");
264
    }
265
 
266
#else
267
 
268
    CYG_TEST_INFO("Test 1 - provoke unaligned access - not supported");
269
 
270
#endif    
271
 
272
#ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS
273
 
274
    CYG_TEST_INFO("Test 2 - provoke illegal access");
275
 
276
    if( setjmp( jbuf ) == 0 )
277
    {
278
        pthread_sigmask( SIG_SETMASK, &mask, NULL );
279
        cause_illegal_access();
280
        CYG_TEST_FAIL("Didn't cause exception");
281
    }
282
 
283
#else
284
 
285
    CYG_TEST_INFO("Test 1 - provoke illegal access - not supported");
286
 
287
#endif    
288
 
289
#ifdef CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO
290
 
291
    CYG_TEST_INFO("Test 3 - provoke FP error");
292
 
293
    if( setjmp( jbuf ) == 0 )
294
    {
295
        pthread_sigmask( SIG_SETMASK, &mask, NULL );
296
        cause_fpe(0);
297
        CYG_TEST_FAIL("Didn't cause exception");
298
    }
299
 
300
#else
301
 
302
    CYG_TEST_INFO("Test 3 - provoke FP error - not supported");
303
 
304
#endif    
305
 
306
    CYG_TEST_PASS_FINISH( "signal2" );
307
}
308
 
309
#endif // ifndef NA_MSG
310
 
311
//--------------------------------------------------------------------------
312
// end of signal1.c

powered by: WebSVN 2.1.0

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