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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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