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

Subversion Repositories openrisc_me

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

Go to most recent revision | 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_arm.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
 
67
#include <cyg/hal/hal_arch.h>           // HAL header
68
#include <cyg/hal/hal_intr.h>           // HAL header
69
 
70
externC void diag_printf(const char *fmt, ...);
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
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
85
/* Force exception handling into the GDB stubs.  This is done by taking over
86
   the exception vectors while executing in the stubs.  This allows for the
87
   debugged program to handle exceptions itself, except while the GDB
88
   processing is underway.  The only vector that can't be handled this way
89
   is the illegal instruction vector which is used for breakpoint/single-step
90
   and must be maintained by the stubs at all times.
91
   Note: the interrupt vectors are _not_ preempted as the stubs probably can't
92
   handle them properly.
93
*/
94
 
95
#define ARM_VECTORS 8
96
extern unsigned long vectors[];  // exception vectors as defined by the stubs
97
 
98
#if !defined(CYGPKG_CYGMON)
99
static unsigned long *hardware_vectors = (unsigned long *)0x20;
100
static unsigned long hold_vectors[ARM_VECTORS];
101
static int exception_level;
102
 
103
static void
104
__take_over_debug_traps(void)
105
{
106
    hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
107
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
108
    hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
109
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
110
}
111
 
112
static void
113
__restore_debug_traps(void)
114
{
115
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
116
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
117
}
118
#endif // !CYGPKG_CYGMON
119
#endif
120
 
121
void
122
exception_handler(HAL_SavedRegisters *regs)
123
{
124
    // Special case handler for code which has chosen to take care
125
    // of data exceptions (i.e. code which expects them to happen)
126
    // This is common in discovery code, e.g. checking for a particular
127
    // device which may generate an exception when probing if the
128
    // device is not present
129
    if (__mem_fault_handler &&
130
        regs->vector == CYGNUM_HAL_EXCEPTION_DATA_ACCESS) {
131
        regs->pc = (unsigned long)__mem_fault_handler;
132
        return; // Caught an exception inside stubs        
133
    }
134
 
135
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) && !defined(CYGPKG_CYGMON)
136
    if (++exception_level == 1) __take_over_debug_traps();
137
 
138
    _hal_registers = regs;
139
    __handle_exception();
140
 
141
    if (--exception_level == 0) __restore_debug_traps();
142
 
143
#elif defined(CYGPKG_KERNEL_EXCEPTIONS)
144
 
145
    // We should decode the vector and pass a more appropriate
146
    // value as the second argument. For now we simply pass a
147
    // pointer to the saved registers. We should also divert
148
    // breakpoint and other debug vectors into the debug stubs.
149
 
150
    cyg_hal_deliver_exception( regs->vector, (CYG_ADDRWORD)regs );
151
 
152
#else
153
 
154
    CYG_FAIL("Exception!!!");
155
 
156
#endif    
157
 
158
    return;
159
}
160
 
161
void hal_spurious_IRQ(HAL_SavedRegisters *regs) CYGBLD_ATTRIB_WEAK;
162
void
163
hal_spurious_IRQ(HAL_SavedRegisters *regs)
164
{
165
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
166
    exception_handler(regs);
167
#else
168
    CYG_FAIL("Spurious interrupt!!");
169
#endif    
170
}
171
 
172
/*------------------------------------------------------------------------*/
173
/* C++ support - run initial constructors                                 */
174
 
175
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
176
cyg_bool cyg_hal_stop_constructors;
177
#endif
178
 
179
typedef void (*pfunc) (void);
180
extern pfunc __CTOR_LIST__[];
181
extern pfunc __CTOR_END__[];
182
 
183
void
184
cyg_hal_invoke_constructors (void)
185
{
186
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
187
    static pfunc *p = &__CTOR_END__[-1];
188
 
189
    cyg_hal_stop_constructors = 0;
190
    for (; p >= __CTOR_LIST__; p--) {
191
        (*p) ();
192
        if (cyg_hal_stop_constructors) {
193
            p--;
194
            break;
195
        }
196
    }
197
#else
198
    pfunc *p;
199
 
200
    for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
201
        (*p) ();
202
#endif
203
}
204
 
205
/*------------------------------------------------------------------------*/
206
/* Architecture default ISR                                               */
207
 
208
externC cyg_uint32
209
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
210
{
211
    CYG_TRACE1(true, "Interrupt: %d", vector);
212
 
213
    CYG_FAIL("Spurious Interrupt!!!");
214
    return 0;
215
}
216
 
217
/*------------------------------------------------------------------------*/
218
/* Idle thread action                                                     */
219
 
220
void
221
hal_idle_thread_action( cyg_uint32 count )
222
{
223
}
224
 
225
/*-------------------------------------------------------------------------*/
226
/* Misc functions                                                          */
227
 
228
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
229
/* This function will generate a breakpoint exception.  It is used at the
230
   beginning of a program to sync up with a debugger and can be used
231
   otherwise as a quick means to stop program execution and "break" into
232
   the debugger. */
233
 
234
void
235
breakpoint(void)
236
{
237
    HAL_BREAKPOINT(_breakinst);
238
}
239
 
240
 
241
/* This function returns the opcode for a 'trap' instruction.  */
242
 
243
unsigned long
244
__break_opcode (void)
245
{
246
    return HAL_BREAKINST;
247
}
248
#endif
249
 
250
int
251
hal_lsbindex(int mask)
252
{
253
    int i;
254
    for (i = 0;  i < 32;  i++) {
255
      if (mask & (1<<i)) return (i);
256
    }
257
    return (-1);
258
}
259
 
260
int
261
hal_msbindex(int mask)
262
{
263
    int i;
264
    for (i = 31;  i >= 0;  i--) {
265
      if (mask & (1<<i)) return (i);
266
    }
267
    return (-1);
268
}
269
 
270
#ifdef  CYGHWR_HAL_ARM_DUMP_EXCEPTIONS
271
void
272
dump_frame(unsigned char *frame)
273
{
274
    HAL_SavedRegisters *rp = (HAL_SavedRegisters *)frame;
275
    int i;
276
    diag_dump_buf(frame, 128);
277
    diag_printf("Registers:\n");
278
    for (i = 0;  i <= 10;  i++) {
279
        if ((i == 0) || (i == 6)) diag_printf("R%d: ", i);
280
        diag_printf("%08X ", rp->d[i]);
281
        if ((i == 5) || (i == 10)) diag_printf("\n");
282
    }
283
    diag_printf("FP: %08X, SP: %08X, LR: %08X, PC: %08X, PSR: %08X\n",
284
                rp->fp, rp->sp, rp->lr, rp->pc, rp->cpsr);
285
}
286
#endif
287
 
288
#if 0
289
void
290
show_frame_in(HAL_SavedRegisters *frame)
291
{
292
    int old;
293
    HAL_DISABLE_INTERRUPTS(old);
294
    diag_printf("[IN] IRQ Frame:\n");
295
    dump_frame((unsigned char *)frame);
296
    HAL_RESTORE_INTERRUPTS(old);
297
}
298
 
299
void
300
show_frame_out(HAL_SavedRegisters *frame)
301
{
302
    int old;
303
    HAL_DISABLE_INTERRUPTS(old);
304
    diag_printf("[OUT] IRQ Frame:\n");
305
    dump_frame((unsigned char *)frame);
306
    HAL_RESTORE_INTERRUPTS(old);
307
}
308
#endif
309
 
310
#ifdef  CYGHWR_HAL_ARM_DUMP_EXCEPTIONS
311
// Debug routines
312
void cyg_hal_report_undefined_instruction(HAL_SavedRegisters *frame)
313
{
314
    int old;
315
    HAL_DISABLE_INTERRUPTS(old);
316
    diag_printf("[UNDEFINED INSTRUCTION] Frame:\n");
317
    dump_frame((unsigned char *)frame);
318
    HAL_RESTORE_INTERRUPTS(old);
319
}
320
 
321
void cyg_hal_report_software_interrupt(HAL_SavedRegisters *frame)
322
{
323
    int old;
324
    HAL_DISABLE_INTERRUPTS(old);
325
    diag_printf("[SOFTWARE INTERRUPT] Frame:\n");
326
    dump_frame((unsigned char *)frame);
327
    HAL_RESTORE_INTERRUPTS(old);
328
}
329
 
330
void cyg_hal_report_abort_prefetch(HAL_SavedRegisters *frame)
331
{
332
    int old;
333
    HAL_DISABLE_INTERRUPTS(old);
334
    diag_printf("[ABORT PREFETCH] Frame:\n");
335
    dump_frame((unsigned char *)frame);
336
    HAL_RESTORE_INTERRUPTS(old);
337
}
338
 
339
void cyg_hal_report_abort_data(HAL_SavedRegisters *frame)
340
{
341
    int old;
342
    HAL_DISABLE_INTERRUPTS(old);
343
    diag_printf("[ABORT DATA] Frame:\n");
344
    dump_frame((unsigned char *)frame);
345
    HAL_RESTORE_INTERRUPTS(old);
346
}
347
 
348
void cyg_hal_report_exception_handler_returned(HAL_SavedRegisters *frame)
349
{
350
    int old;
351
    HAL_DISABLE_INTERRUPTS(old);
352
    diag_printf("Exception handler returned!\n");
353
    dump_frame((unsigned char *)frame);
354
    HAL_RESTORE_INTERRUPTS(old);
355
}
356
#endif
357
 
358
/*------------------------------------------------------------------------*/
359
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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