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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [v85x/] [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, jlarmour
45
// Date:         2001-03-21
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_v85x.h>
56
#ifdef CYGPKG_KERNEL
57
#include <pkgconf/kernel.h>
58
#endif
59
 
60
#include <cyg/infra/cyg_type.h>
61
#include <cyg/infra/cyg_trac.h>         // tracing macros
62
#include <cyg/infra/cyg_ass.h>          // assertion macros
63
#include <cyg/infra/diag.h>
64
 
65
#include <cyg/hal/hal_arch.h>           // HAL header
66
#include <cyg/hal/hal_intr.h>           // HAL header
67
 
68
/*------------------------------------------------------------------------*/
69
/* First level C exception handler.                                       */
70
 
71
externC void __handle_exception (void);
72
 
73
externC HAL_SavedRegisters *_hal_registers;
74
externC void* volatile __mem_fault_handler;
75
 
76
void
77
exception_handler(HAL_SavedRegisters *regs)
78
{
79
#if defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS)
80
//    diag_printf("Exception! Frame: %x\n", regs);
81
//    show_regs(regs);
82
    static int gdb_active;
83
    if (gdb_active == 0) {
84
        gdb_active = 1;
85
        _hal_registers = regs;
86
        __handle_exception();
87
        gdb_active = 0;
88
    }
89
 
90
#elif defined(CYGPKG_KERNEL_EXCEPTIONS)
91
 
92
    // We should decode the vector and pass a more appropriate
93
    // value as the second argument. For now we simply pass a
94
    // pointer to the saved registers. We should also divert
95
    // breakpoint and other debug vectors into the debug stubs.
96
 
97
    cyg_hal_deliver_exception( regs->vector, (CYG_ADDRWORD)regs );
98
 
99
#else
100
 
101
    CYG_FAIL("Exception!!!");
102
 
103
#endif    
104
 
105
    return;
106
}
107
 
108
/*------------------------------------------------------------------------*/
109
/* C++ support - run initial constructors                                 */
110
 
111
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
112
cyg_bool cyg_hal_stop_constructors;
113
#endif
114
 
115
typedef void (*pfunc) (void);
116
extern pfunc __CTOR_LIST__[];
117
extern pfunc __CTOR_END__[];
118
 
119
void
120
cyg_hal_invoke_constructors (void)
121
{
122
 
123
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
124
    static pfunc *p = &__CTOR_END__[-1];
125
 
126
    cyg_hal_stop_constructors = 0;
127
    for (; p >= __CTOR_LIST__; p--) {
128
        (*p) ();
129
        if (cyg_hal_stop_constructors) {
130
            p--;
131
            break;
132
        }
133
    }
134
#else
135
    pfunc *p;
136
 
137
    for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) {
138
        (*p) ();
139
    }
140
#endif
141
}
142
 
143
/*------------------------------------------------------------------------*/
144
/* default ISR                                                            */
145
 
146
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
147
externC cyg_uint32
148
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
149
{
150
    CYG_TRACE1(true, "Interrupt: %d", vector);
151
 
152
    diag_printf("Spurious Interrupt!!! - vector: %d, data: %x\n", vector,
153
                data);
154
    CYG_FAIL("Spurious Interrupt!!!");
155
    return 0;
156
}
157
#else
158
externC cyg_uint32
159
hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
160
{
161
    CYG_TRACE1(true, "Interrupt: %d", vector);
162
 
163
#ifndef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
164
#ifdef CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
165
#ifdef CYGDBG_HAL_CTRLC_ISR
166
    // then see if it is an incoming character interrupt and break
167
    // into the stub ROM if the char is a ^C.
168
    if ( CYGDBG_HAL_CTRLC_ISR( vector, data ) )
169
        return 1; // interrupt handled
170
#endif
171
#endif
172
#endif
173
 
174
    diag_printf("Spurious Interrupt!!! - vector: %d, data: %x\n", vector,
175
                data);
176
    CYG_FAIL("Spurious Interrupt!!!");
177
    return 0;
178
}
179
#endif
180
 
181
/*------------------------------------------------------------------------*/
182
/* Idle thread action                                                     */
183
 
184
void
185
hal_idle_thread_action( cyg_uint32 count )
186
{
187
    // power saving instruction
188
    asm("halt");
189
}
190
 
191
/*-------------------------------------------------------------------------*/
192
/* Misc functions                                                          */
193
 
194
cyg_uint32
195
hal_lsbit_index(cyg_uint32 mask)
196
{
197
    int i;
198
    for (i = 0;  i < 32;  i++) {
199
      if (mask & (1<<i)) return ((cyg_uint32)i);
200
    }
201
    return ((cyg_uint32)-1);
202
}
203
 
204
cyg_uint32
205
hal_msbit_index(cyg_uint32 mask)
206
{
207
    int i;
208
    for (i = 31;  i >= 0;  i--) {
209
      if (mask & (1<<i)) return ((cyg_uint32)i);
210
    }
211
    return ((cyg_uint32)-1);
212
}
213
 
214
void
215
show_regs(HAL_SavedRegisters *regs)
216
{
217
    int i;
218
    diag_printf("Regs\n");
219
    for (i = 0;  i < 32;  i++) {
220
        if ((i % 8) == 0) {
221
            diag_printf("R%2d: ", i);
222
        }
223
        diag_printf("0x%08x ", regs->d[i]);
224
        if ((i % 8) == 7) {
225
            diag_printf("\n");
226
        }
227
    }
228
    diag_printf("PC = %x, PSW = %x\n", regs->pc, regs->psw);
229
}
230
 
231
/*------------------------------------------------------------------------*/
232
// EOF hal_misc.c

powered by: WebSVN 2.1.0

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