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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [fr30/] [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, 2007 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
 
41
#include <pkgconf/hal.h>
42
 
43
#include <cyg/infra/cyg_type.h>
44
#include <cyg/infra/cyg_trac.h>         // tracing macros
45
#include <cyg/infra/cyg_ass.h>          // assertion macros
46
#include <cyg/hal/hal_arch.h>           // HAL header
47
#include <cyg/hal/hal_intr.h>           // VSR/ISR defines
48
#include <cyg/hal/hal_misc.h>
49
 
50
/*------------------------------------------------------------------------*/
51
/* If required, define a variable to store the clock period.              */
52
 
53
#ifdef CYGHWR_HAL_CLOCK_PERIOD_DEFINED
54
 
55
CYG_WORD32 cyg_hal_clock_period;
56
 
57
#endif
58
 
59
 
60
/*****************************************************************************
61
hal_default_exception_handler -- First level C exception handler
62
 
63
     The assembly default VSR  handler calls  this routine  to handle  the
64
exception.  When this routine returns, the  state is restored to the  state
65
pointed to by regs.
66
 
67
     We declare this  routine as  weak so  that other  handlers can  easily
68
become the default exception handler.
69
 
70
INPUT:
71
 
72
     vector: The exception vector number.
73
 
74
     regs: A pointer to the saved state.
75
 
76
OUTPUT:
77
 
78
RETURN VALUE:
79
 
80
     None
81
 
82
*****************************************************************************/
83
 
84
externC void
85
hal_default_exception_handler(CYG_WORD vector, HAL_SavedRegisters *regs)
86
                                                    __attribute__ ((weak));
87
 
88
void hal_default_exception_handler(CYG_WORD vector, HAL_SavedRegisters *regs)
89
{
90
 
91
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
92
    externC void __handle_exception(void);
93
    externC HAL_SavedRegisters * _hal_registers;
94
 
95
    // Set the pointer to the registers of the current exception
96
    // context. At entry the GDB stub will expand the
97
    // HAL_SavedRegisters structure into a (bigger) register array.
98
    _hal_registers = regs;
99
 
100
    __handle_exception();
101
 
102
#elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
103
      defined(CYGPKG_HAL_EXCEPTIONS)
104
 
105
    // We should decode the vector and pass a more appropriate
106
    // value as the second argument. For now we simply pass a
107
    // pointer to the saved registers. We should also divert
108
    // breakpoint and other debug vectors into the debug stubs.
109
 
110
    cyg_hal_deliver_exception(vector, (CYG_ADDRWORD)regs);
111
 
112
#else
113
 
114
    CYG_FAIL("Exception!!!");
115
 
116
#endif
117
 
118
    return;
119
}
120
 
121
//---------------------------------------------------------------------------
122
// Default arch ISR
123
 
124
externC cyg_uint32
125
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
126
{
127
    CYG_FAIL("Spurious Interrupt!!!");
128
    return 0;
129
}
130
 
131
//---------------------------------------------------------------------------
132
// Idle thread action
133
 
134
void
135
hal_idle_thread_action( cyg_uint32 count )
136
{
137
}
138
 
139
//-----------------------------------------------------------------------------
140
// Monitor initialization. This means to init the vsr vector table.
141
// TODO maybe init hal_vsr_table through defining it in assembler code
142
 
143
#ifndef CYGPKG_HAL_FR30_MON_DEFINED
144
void hal_mon_init(void){
145
    int i;
146
    /* 0 - 14 exceptions */
147
    for(i = 0; i < CYGNUM_HAL_VECTOR_INTRFIRST; i++){
148
        hal_vsr_table[i] = (CYG_ADDRESS)__default_exception_vsr;
149
    }
150
    /* 15 - xx interrupts */
151
    for( ; i < CYGNUM_HAL_VECTOR_INTRLAST; i++){
152
        hal_vsr_table[i] = (CYG_ADDRESS)__default_interrupt_vsr;
153
    }
154
    /*  xx+1 - 255 exceptions (fr30 traps) */
155
    for( ; i < CYGNUM_HAL_VSR_MAX; i++){
156
        hal_vsr_table[i] = (CYG_ADDRESS)__default_exception_vsr;
157
    }
158
}
159
#endif
160
 
161
//---------------------------------------------------------------------------
162
// Determine the index of the ls bit of the supplied mask.
163
 
164
cyg_uint32
165
hal_lsbit_index(cyg_uint32 mask)
166
{
167
    cyg_uint32 n = mask;
168
 
169
    static const signed char tab[64] =
170
    { -1, 0, 1, 12, 2, 6, 0, 13, 3, 0, 7, 0, 0, 0, 0, 14, 10,
171
      4, 0, 0, 8, 0, 0, 25, 0, 0, 0, 0, 0, 21, 27 , 15, 31, 11,
172
      5, 0, 0, 0, 0, 0, 9, 0, 0, 24, 0, 0 , 20, 26, 30, 0, 0, 0,
173
      0, 23, 0, 19, 29, 0, 22, 18, 28, 17, 16, 0
174
    };
175
 
176
    n &= ~(n-1UL);
177
    n = (n<<16)-n;
178
    n = (n<<6)+n;
179
    n = (n<<4)+n;
180
 
181
    return tab[n>>26];
182
}
183
 
184
//---------------------------------------------------------------------------
185
// Determine the index of the ms bit of the supplied mask. FIXME: since we
186
// have hardware support for it, use it! (bit search module)
187
 
188
cyg_uint32
189
hal_msbit_index(cyg_uint32 mask)
190
{
191
    cyg_uint32 x = mask;
192
    cyg_uint32 w;
193
 
194
    // Phase 1: make word with all ones from that one to the right.
195
    x |= x >> 16;
196
    x |= x >> 8;
197
    x |= x >> 4;
198
    x |= x >> 2;
199
    x |= x >> 1;
200
 
201
    // Phase 2: calculate number of "1" bits in the word.
202
    w = (x & 0x55555555) + ((x >> 1) & 0x55555555);
203
    w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
204
    w = w + (w >> 4);
205
    w = (w & 0x000F000F) + ((w >> 8) & 0x000F000F);
206
    return (cyg_uint32)((w + (w >> 16)) & 0xFF);
207
 
208
}
209
 
210
/*------------------------------------------------------------------------*/
211
/* C++ support - run initial constructors                                 */
212
 
213
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
214
cyg_bool cyg_hal_stop_constructors;
215
#endif
216
 
217
typedef void (*pfunc) (void);
218
extern pfunc __CTOR_LIST__[];
219
extern pfunc __CTOR_END__[];
220
 
221
void
222
        cyg_hal_invoke_constructors (void)
223
{
224
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
225
    static pfunc *p = &__CTOR_END__[-1];
226
 
227
    cyg_hal_stop_constructors = 0;
228
    for (; p >= __CTOR_LIST__; p--) {
229
        (*p) ();
230
        if (cyg_hal_stop_constructors) {
231
            p--;
232
            break;
233
        }
234
    }
235
#else
236
    pfunc *p;
237
    for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--) {
238
        (*p) ();
239
    }
240
#endif
241
}
242
 
243
//---------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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