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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [h8300/] [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
44
// Contributors: nickg, jlarmour
45
// Date:         1999-02-18
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
 
56
#include <cyg/infra/cyg_type.h>
57
#include <cyg/infra/cyg_trac.h>
58
 
59
#include <cyg/hal/hal_arch.h>
60
 
61
#include <cyg/hal/hal_intr.h>
62
 
63
#if 0
64
void trace( CYG_ADDRWORD tag, CYG_ADDRWORD a1, CYG_ADDRWORD a2)
65
{
66
    CYG_ADDRWORD **pp = (CYG_ADDRWORD **)0x48100000;
67
    CYG_ADDRWORD *ix = (CYG_ADDRWORD *)0x4810000C;
68
    CYG_ADDRWORD *p = *pp;
69
    *p++ = tag;
70
    *ix = *ix + 1;
71
    *p++ = *ix;
72
    *p++ = a1;
73
    *p++ = a2;
74
    *pp = p;
75
}
76
#endif
77
 
78
/*------------------------------------------------------------------------*/
79
 
80
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
81
cyg_bool cyg_hal_stop_constructors;
82
#endif
83
 
84
void
85
cyg_hal_invoke_constructors(void)
86
{
87
    typedef void (*pfunc) (void);
88
    extern pfunc __CTOR_LIST__[];
89
    extern pfunc __CTOR_END__[];
90
 
91
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
92
    static pfunc *p = &__CTOR_END__[-1];
93
 
94
    cyg_hal_stop_constructors = 0;
95
    for (; p >= __CTOR_LIST__; p--) {
96
        (*p) ();
97
        if (cyg_hal_stop_constructors) {
98
            p--;
99
            break;
100
        }
101
    }
102
#else
103
    pfunc *p;
104
 
105
    for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
106
        (*p) ();
107
#endif
108
 
109
} // cyg_hal_invoke_constructors()
110
 
111
/*------------------------------------------------------------------------*/
112
// Default ISR
113
externC cyg_uint32
114
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
115
{
116
    return 0;
117
}
118
 
119
//--------------------------------------------------------------------------
120
/* Determine the index of the ls bit of the supplied mask.                */
121
 
122
cyg_uint32
123
hal_lsbit_index(cyg_uint32 mask)
124
{
125
    cyg_uint32 n = mask;
126
 
127
    static const signed char tab[64] =
128
    { -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10,
129
      4, 0, 0, 8, 0, 0, 25, 0, 0, 0, 0, 0, 21, 27 , 15, 31, 11,
130
      5, 0, 0, 0, 0, 0, 9, 0, 0, 24, 0, 0 , 20, 26, 30, 0, 0, 0,
131
      0, 23, 0, 19, 29, 0, 22, 18, 28, 17, 16, 0
132
    };
133
 
134
    n &= ~(n-1UL);
135
    n = (n<<16)-n;
136
    n = (n<<6)+n;
137
    n = (n<<4)+n;
138
 
139
    return tab[n>>26];
140
}
141
 
142
/*------------------------------------------------------------------------*/
143
/* Determine the index of the ms bit of the supplied mask.                */
144
 
145
cyg_uint32
146
hal_msbit_index(cyg_uint32 mask)
147
{
148
    cyg_uint32 x = mask;
149
    cyg_uint32 w;
150
 
151
    /* Phase 1: make word with all ones from that one to the right */
152
    x |= x >> 16;
153
    x |= x >> 8;
154
    x |= x >> 4;
155
    x |= x >> 2;
156
    x |= x >> 1;
157
 
158
    /* Phase 2: calculate number of "1" bits in the word        */
159
    w = (x & 0x55555555) + ((x >> 1) & 0x55555555);
160
    w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
161
    w = w + (w >> 4);
162
    w = (w & 0x000F000F) + ((w >> 8) & 0x000F000F);
163
    return (cyg_uint32)((w + (w >> 16)) & 0xFF);
164
 
165
}
166
 
167
/*------------------------------------------------------------------------*/
168
/* First level C exception handler.                                       */
169
 
170
externC void __handle_exception (void);
171
 
172
externC HAL_SavedRegisters *_hal_registers;
173
 
174
void
175
cyg_hal_exception_handler(HAL_SavedRegisters *regs,CYG_WORD vector)
176
{
177
 
178
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
179
 
180
    // Set the pointer to the registers of the current exception
181
    // context. At entry the GDB stub will expand the
182
    // HAL_SavedRegisters structure into a (bigger) register array.
183
    _hal_registers = regs;
184
 
185
    __handle_exception();
186
 
187
#endif
188
#if defined(CYGPKG_HAL_EXCEPTIONS)
189
 
190
    // We should decode the vector and pass a more appropriate
191
    // value as the second argument. For now we simply pass a
192
    // pointer to the saved registers. We should also divert
193
    // breakpoint and other debug vectors into the debug stubs.
194
 
195
    cyg_hal_deliver_exception( vector, (CYG_ADDRWORD)regs );
196
 
197
#endif
198
 
199
    return;
200
}
201
 
202
/*------------------------------------------------------------------------*/
203
/* default ISR                                                            */
204
 
205
#ifndef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
206
externC cyg_uint32 hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
207
{
208
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) && \
209
    defined(CYGHWR_HAL_GDB_PORT_VECTOR) &&         \
210
    defined(HAL_CTRLC_ISR)
211
 
212
#ifndef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN    
213
    if( vector == CYGHWR_HAL_GDB_PORT_VECTOR )
214
#endif        
215
    {
216
        cyg_uint32 result = HAL_CTRLC_ISR( vector, data );
217
        if( result != 0 ) return result;
218
    }
219
 
220
#endif
221
 
222
    CYG_TRACE1(true, "Interrupt: %d", vector);
223
    CYG_FAIL("Spurious Interrupt!!!");
224
    return 0;
225
}
226
#endif
227
 
228
/*------------------------------------------------------------------------*/
229
/* Idle thread activity.                                                  */
230
 
231
externC void hal_idle_thread_action(cyg_uint32 loop_count)
232
{
233
}
234
 
235
/*------------------------------------------------------------------------*/
236
/* End of hal_misc.c                                                      */

powered by: WebSVN 2.1.0

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