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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [frv/] [arch/] [v2_0/] [src/] [hal_misc.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*==========================================================================
2
//
3
//      hal_misc.c
4
//
5
//      HAL miscellaneous functions
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):    nickg, gthomas
44
// Contributors: nickg, gthomas
45
// Date:         1999-02-20
46
// Purpose:      HAL miscellaneous functions
47
// Description:  This file contains miscellaneous functions provided by the
48
//               HAL.
49
//
50
//####DESCRIPTIONEND####
51
//
52
//=========================================================================*/
53
 
54
#include <pkgconf/hal.h>
55
#include <pkgconf/hal_frv.h>
56
#ifdef CYGPKG_KERNEL
57
#include <pkgconf/kernel.h>
58
#endif
59
#ifdef CYGPKG_CYGMON
60
#include <pkgconf/cygmon.h>
61
#endif
62
 
63
#include <cyg/infra/cyg_type.h>
64
#include <cyg/infra/cyg_trac.h>         // tracing macros
65
#include <cyg/infra/cyg_ass.h>          // assertion macros
66
#include <cyg/infra/diag.h>
67
 
68
#include <cyg/hal/hal_arch.h>           // HAL header
69
#include <cyg/hal/hal_intr.h>           // HAL header
70
#include <cyg/hal/hal_cache.h>          // HAL header
71
 
72
/*------------------------------------------------------------------------*/
73
/* First level C exception handler.                                       */
74
 
75
externC void __handle_exception (void);
76
 
77
externC HAL_SavedRegisters *_hal_registers;
78
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
79
// Historical - this datum is defined by the GDB stubs if present
80
externC
81
#endif
82
        void* volatile __mem_fault_handler;
83
 
84
#if 0
85
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
86
/* Force exception handling into the GDB stubs.  This is done by taking over
87
   the exception vectors while executing in the stubs.  This allows for the
88
   debugged program to handle exceptions itself, except while the GDB
89
   processing is underway.  The only vector that can't be handled this way
90
   is the illegal instruction vector which is used for breakpoint/single-step
91
   and must be maintained by the stubs at all times.
92
   Note: the interrupt vectors are _not_ preempted as the stubs probably can't
93
   handle them properly.
94
*/
95
 
96
#define ARM_VECTORS 8
97
extern unsigned long vectors[];  // exception vectors as defined by the stubs
98
 
99
#if !defined(CYGPKG_CYGMON)
100
static unsigned long *hardware_vectors = (unsigned long *)0x20;
101
static unsigned long hold_vectors[ARM_VECTORS];
102
static int exception_level;
103
 
104
static void
105
__take_over_debug_traps(void)
106
{
107
    hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
108
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
109
    hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
110
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
111
}
112
 
113
static void
114
__restore_debug_traps(void)
115
{
116
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
117
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
118
}
119
#endif // !CYGPKG_CYGMON
120
#endif
121
 
122
#endif // if 0
123
 
124
void
125
exception_handler(HAL_SavedRegisters *regs)
126
{
127
    // Special case handler for code which has chosen to take care
128
    // of data exceptions (i.e. code which expects them to happen)
129
    // This is common in discovery code, e.g. checking for a particular
130
    // device which may generate an exception when probing if the
131
    // device is not present
132
    if (__mem_fault_handler &&
133
        regs->vector == CYGNUM_HAL_EXCEPTION_DATA_ACCESS) {
134
        regs->pc = (unsigned long)__mem_fault_handler;
135
        return; // Caught an exception inside stubs        
136
    }
137
 
138
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) && !defined(CYGPKG_CYGMON)
139
//??    if (++exception_level == 1) __take_over_debug_traps();
140
 
141
    _hal_registers = regs;
142
    __handle_exception();
143
 
144
//??    if (--exception_level == 0) __restore_debug_traps();
145
 
146
#elif defined(CYGPKG_KERNEL_EXCEPTIONS)
147
 
148
    // We should decode the vector and pass a more appropriate
149
    // value as the second argument. For now we simply pass a
150
    // pointer to the saved registers. We should also divert
151
    // breakpoint and other debug vectors into the debug stubs.
152
 
153
    cyg_hal_deliver_exception( regs->vector, (CYG_ADDRWORD)regs );
154
 
155
#else
156
 
157
    CYG_FAIL("Exception!!!");
158
 
159
#endif    
160
 
161
    return;
162
}
163
 
164
void hal_spurious_IRQ(HAL_SavedRegisters *regs) CYGBLD_ATTRIB_WEAK;
165
void
166
hal_spurious_IRQ(HAL_SavedRegisters *regs)
167
{
168
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
169
    exception_handler(regs);
170
#else
171
    CYG_FAIL("Spurious interrupt!!");
172
#endif    
173
}
174
 
175
/*------------------------------------------------------------------------*/
176
/* C++ support - run initial constructors                                 */
177
 
178
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
179
cyg_bool cyg_hal_stop_constructors;
180
#endif
181
 
182
typedef void (*pfunc) (void);
183
extern pfunc __CTOR_LIST__[];
184
extern pfunc __CTOR_END__[];
185
 
186
void
187
cyg_hal_invoke_constructors (void)
188
{
189
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
190
    static pfunc *p = &__CTOR_END__[-1];
191
 
192
    cyg_hal_stop_constructors = 0;
193
    for (; p >= __CTOR_LIST__; p--) {
194
        (*p) ();
195
        if (cyg_hal_stop_constructors) {
196
            p--;
197
            break;
198
        }
199
    }
200
#else
201
    pfunc *p;
202
 
203
    for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) {
204
        (*p) ();
205
    }
206
#endif
207
}
208
 
209
/*------------------------------------------------------------------------*/
210
/* Architecture default ISR                                               */
211
 
212
externC cyg_uint32
213
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
214
{
215
    CYG_TRACE1(true, "Interrupt: %d", vector);
216
 
217
    CYG_FAIL("Spurious Interrupt!!!");
218
    return 0;
219
}
220
 
221
/*------------------------------------------------------------------------*/
222
/* Idle thread action                                                     */
223
 
224
void
225
hal_idle_thread_action( cyg_uint32 count )
226
{
227
}
228
 
229
/*-------------------------------------------------------------------------*/
230
/* Misc functions                                                          */
231
 
232
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS__
233
/* This function will generate a breakpoint exception.  It is used at the
234
   beginning of a program to sync up with a debugger and can be used
235
   otherwise as a quick means to stop program execution and "break" into
236
   the debugger. */
237
 
238
void
239
breakpoint(void)
240
{
241
    HAL_BREAKPOINT(_breakinst);
242
}
243
 
244
 
245
/* This function returns the opcode for a 'trap' instruction.  */
246
 
247
unsigned long
248
__break_opcode (void)
249
{
250
    return HAL_BREAKINST;
251
}
252
#endif
253
 
254
int
255
hal_lsbindex(int mask)
256
{
257
    int i;
258
    for (i = 0;  i < 32;  i++) {
259
      if (mask & (1<<i)) return (i);
260
    }
261
    return (-1);
262
}
263
 
264
int
265
hal_msbindex(int mask)
266
{
267
    int i;
268
    for (i = 31;  i >= 0;  i--) {
269
      if (mask & (1<<i)) return (i);
270
    }
271
    return (-1);
272
}
273
 
274
/*------------------------------------------------------------------------*/
275
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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