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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [arch/] [current/] [src/] [hal_misc.c] - Blame information for rev 838

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

Line No. Rev Author Line
1 786 skrzyp
/*==========================================================================
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, 2008 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, gthomas
43
// Contributors: nickg, gthomas
44
// Date:         1999-02-20
45
// Purpose:      HAL miscellaneous functions
46
// Description:  This file contains miscellaneous functions provided by the
47
//               HAL.
48
//
49
//####DESCRIPTIONEND####
50
//
51
//=========================================================================*/
52
 
53
#include <pkgconf/hal.h>
54
#include <pkgconf/hal_arm.h>
55
#ifdef CYGPKG_KERNEL
56
#include <pkgconf/kernel.h>
57
#endif
58
#ifdef CYGPKG_CYGMON
59
#include <pkgconf/cygmon.h>
60
#endif
61
 
62
#include <cyg/infra/diag.h>
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
/*------------------------------------------------------------------------*/
71
/* First level C exception handler.                                       */
72
 
73
externC void __handle_exception (void);
74
 
75
externC HAL_SavedRegisters *_hal_registers;
76
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
77
externC void* volatile __mem_fault_handler;
78
#endif
79
 
80
 
81
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
82
/* Force exception handling into the GDB stubs.  This is done by taking over
83
   the exception vectors while executing in the stubs.  This allows for the
84
   debugged program to handle exceptions itself, except while the GDB
85
   processing is underway.  The only vector that can't be handled this way
86
   is the illegal instruction vector which is used for breakpoint/single-step
87
   and must be maintained by the stubs at all times.
88
   Note: the interrupt vectors are _not_ preempted as the stubs probably can't
89
   handle them properly.
90
*/
91
 
92
#define ARM_VECTORS 8
93
extern unsigned long vectors[];  // exception vectors as defined by the stubs
94
 
95
#if !defined(CYGPKG_CYGMON)
96
static unsigned long *hardware_vectors = (unsigned long *)0x20;
97
static unsigned long hold_vectors[ARM_VECTORS];
98
static int exception_level;
99
 
100
static void
101
__take_over_debug_traps(void)
102
{
103
    hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
104
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
105
    hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
106
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
107
}
108
 
109
static void
110
__restore_debug_traps(void)
111
{
112
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_PREFETCH];
113
    hardware_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA] = hold_vectors[CYGNUM_HAL_VECTOR_ABORT_DATA];
114
}
115
#endif // !CYGPKG_CYGMON
116
#endif
117
 
118
void
119
exception_handler(HAL_SavedRegisters *regs)
120
{
121
    // Special case handler for code which has chosen to take care
122
    // of data exceptions (i.e. code which expects them to happen)
123
    // This is common in discovery code, e.g. checking for a particular
124
    // device which may generate an exception when probing if the
125
    // device is not present
126
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
127
    if (__mem_fault_handler &&
128
        regs->vector == CYGNUM_HAL_EXCEPTION_DATA_ACCESS) {
129
        regs->pc = (unsigned long)__mem_fault_handler;
130
        return; // Caught an exception inside stubs        
131
    }
132
#endif
133
 
134
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) && !defined(CYGPKG_CYGMON)
135
    if (++exception_level == 1) __take_over_debug_traps();
136
 
137
    _hal_registers = regs;
138
    __handle_exception();
139
 
140
    if (--exception_level == 0) __restore_debug_traps();
141
 
142
#elif defined(CYGPKG_KERNEL_EXCEPTIONS)
143
 
144
    // We should decode the vector and pass a more appropriate
145
    // value as the second argument. For now we simply pass a
146
    // pointer to the saved registers. We should also divert
147
    // breakpoint and other debug vectors into the debug stubs.
148
 
149
    cyg_hal_deliver_exception( regs->vector, (CYG_ADDRWORD)regs );
150
 
151
#else
152
 
153
    CYG_FAIL("Exception!!!");
154
 
155
#endif    
156
 
157
    return;
158
}
159
 
160
void hal_spurious_IRQ(HAL_SavedRegisters *regs) CYGBLD_ATTRIB_WEAK;
161
void
162
hal_spurious_IRQ(HAL_SavedRegisters *regs)
163
{
164
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
165
    exception_handler(regs);
166
#else
167
    CYG_FAIL("Spurious interrupt!!");
168
#endif    
169
}
170
 
171
/*------------------------------------------------------------------------*/
172
/* C++ support - run initial constructors                                 */
173
 
174
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
175
cyg_bool cyg_hal_stop_constructors;
176
#endif
177
 
178
typedef void (*pfunc) (void);
179
 
180
// EABI uses different symbols, and constructors are in opposite order.
181
#ifdef CYGBLD_HAL_ARM_EABI
182
extern pfunc __init_array_start__[];
183
extern pfunc __init_array_end__[];
184
#define CONSTRUCTORS_START  (__init_array_start__[0])
185
#define CONSTRUCTORS_END    (__init_array_end__)
186
#define NEXT_CONSTRUCTOR(c) ((c)++)
187
#else
188
extern pfunc __CTOR_LIST__[];
189
extern pfunc __CTOR_END__[];
190
#define CONSTRUCTORS_START  (__CTOR_END__[-1])
191
#define CONSTRUCTORS_END    (&__CTOR_LIST__[-1])
192
#define NEXT_CONSTRUCTOR(c) ((c)--)
193
#endif
194
 
195
void
196
cyg_hal_invoke_constructors (void)
197
{
198
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
199
    static pfunc *p = &CONSTRUCTORS_START;
200
 
201
    cyg_hal_stop_constructors = 0;
202
    for (; p != CONSTRUCTORS_END; NEXT_CONSTRUCTOR(p)) {
203
        (*p)();
204
        if (cyg_hal_stop_constructors) {
205
            NEXT_CONSTRUCTOR(p);
206
            break;
207
        }
208
    }
209
#else
210
    pfunc *p;
211
 
212
    for (p = &CONSTRUCTORS_START; p != CONSTRUCTORS_END; NEXT_CONSTRUCTOR(p))
213
        (*p)();
214
#endif
215
}
216
 
217
/*------------------------------------------------------------------------*/
218
/* Architecture default ISR                                               */
219
 
220
externC cyg_uint32
221
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
222
{
223
    CYG_TRACE1(true, "Interrupt: %d", vector);
224
 
225
    CYG_FAIL("Spurious Interrupt!!!");
226
    return 0;
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
#ifdef  CYGHWR_HAL_ARM_DUMP_EXCEPTIONS
275
void
276
dump_frame(unsigned char *frame)
277
{
278
    HAL_SavedRegisters *rp = (HAL_SavedRegisters *)frame;
279
    int i;
280
    diag_dump_buf(frame, 128);
281
    diag_printf("Registers:\n");
282
    for (i = 0;  i <= 10;  i++) {
283
        if ((i == 0) || (i == 6)) diag_printf("R%d: ", i);
284
        diag_printf("%08X ", rp->d[i]);
285
        if ((i == 5) || (i == 10)) diag_printf("\n");
286
    }
287
    diag_printf("FP: %08X, SP: %08X, LR: %08X, PC: %08X, PSR: %08X\n",
288
                rp->fp, rp->sp, rp->lr, rp->pc, rp->cpsr);
289
}
290
#endif
291
 
292
#if 0
293
void
294
show_frame_in(HAL_SavedRegisters *frame)
295
{
296
    int old;
297
    HAL_DISABLE_INTERRUPTS(old);
298
    diag_printf("[IN] IRQ Frame:\n");
299
    dump_frame((unsigned char *)frame);
300
    HAL_RESTORE_INTERRUPTS(old);
301
}
302
 
303
void
304
show_frame_out(HAL_SavedRegisters *frame)
305
{
306
    int old;
307
    HAL_DISABLE_INTERRUPTS(old);
308
    diag_printf("[OUT] IRQ Frame:\n");
309
    dump_frame((unsigned char *)frame);
310
    HAL_RESTORE_INTERRUPTS(old);
311
}
312
#endif
313
 
314
#ifdef  CYGHWR_HAL_ARM_DUMP_EXCEPTIONS
315
// Debug routines
316
void cyg_hal_report_undefined_instruction(HAL_SavedRegisters *frame)
317
{
318
    int old;
319
    HAL_DISABLE_INTERRUPTS(old);
320
    diag_printf("[UNDEFINED INSTRUCTION] Frame:\n");
321
    dump_frame((unsigned char *)frame);
322
    HAL_RESTORE_INTERRUPTS(old);
323
}
324
 
325
void cyg_hal_report_software_interrupt(HAL_SavedRegisters *frame)
326
{
327
    int old;
328
    HAL_DISABLE_INTERRUPTS(old);
329
    diag_printf("[SOFTWARE INTERRUPT] Frame:\n");
330
    dump_frame((unsigned char *)frame);
331
    HAL_RESTORE_INTERRUPTS(old);
332
}
333
 
334
void cyg_hal_report_abort_prefetch(HAL_SavedRegisters *frame)
335
{
336
    int old;
337
    HAL_DISABLE_INTERRUPTS(old);
338
    diag_printf("[ABORT PREFETCH] Frame:\n");
339
    dump_frame((unsigned char *)frame);
340
    HAL_RESTORE_INTERRUPTS(old);
341
}
342
 
343
void cyg_hal_report_abort_data(HAL_SavedRegisters *frame)
344
{
345
    int old;
346
    HAL_DISABLE_INTERRUPTS(old);
347
    diag_printf("[ABORT DATA] Frame:\n");
348
    dump_frame((unsigned char *)frame);
349
    HAL_RESTORE_INTERRUPTS(old);
350
}
351
 
352
void cyg_hal_report_exception_handler_returned(HAL_SavedRegisters *frame)
353
{
354
    int old;
355
    HAL_DISABLE_INTERRUPTS(old);
356
    diag_printf("Exception handler returned!\n");
357
    dump_frame((unsigned char *)frame);
358
    HAL_RESTORE_INTERRUPTS(old);
359
}
360
#endif
361
 
362
/*------------------------------------------------------------------------*/
363
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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