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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [powerpc/] [arch/] [v2_0/] [src/] [hal_misc.c] - Blame information for rev 307

Go to most recent revision | 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
// Copyright (C) 2002 Gary Thomas
13
//
14
// eCos is free software; you can redistribute it and/or modify it under
15
// the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 or (at your option) any later version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19
// 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 along
24
// with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26
//
27
// As a special exception, if other files instantiate templates or use macros
28
// or inline functions from this file, or you compile this file and link it
29
// with other works to produce a work based on this file, this file does not
30
// by itself cause the resulting work to be covered by the GNU General Public
31
// License. However the source code for this file must still be made available
32
// in accordance with section (3) of the GNU General Public License.
33
//
34
// This exception does not invalidate any other reasons why a work based on
35
// this file might be covered by the GNU General Public License.
36
//
37
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38
// at http://sources.redhat.com/ecos/ecos-license/
39
// -------------------------------------------
40
//####ECOSGPLCOPYRIGHTEND####
41
//==========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    nickg, jskov
45
// Contributors: nickg, jskov,
46
//               jlarmour, gthomas
47
// Date:         1999-02-20
48
// Purpose:      HAL miscellaneous functions
49
// Description:  This file contains miscellaneous functions provided by the
50
//               HAL.
51
//
52
//####DESCRIPTIONEND####
53
//
54
//===========================================================================
55
 
56
#include <pkgconf/hal.h>
57
 
58
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
59
#include <cyg/hal/ppc_regs.h>           // SPR definitions
60
 
61
#include <cyg/infra/cyg_type.h>
62
#include <cyg/infra/cyg_trac.h>         // tracing macros
63
#include <cyg/infra/cyg_ass.h>          // assertion macros
64
#include <cyg/infra/diag.h>             // diag_printf
65
 
66
#include <cyg/hal/hal_arch.h>           // HAL header
67
#include <cyg/hal/hal_cache.h>          // HAL cache
68
#if defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
69
    defined(CYGPKG_HAL_EXCEPTIONS)
70
# include <cyg/hal/hal_intr.h>           // HAL interrupts/exceptions
71
#endif
72
#include <cyg/hal/hal_mem.h>            // HAL memory handling
73
 
74
//---------------------------------------------------------------------------
75
// Functions used during initialization.
76
 
77
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
78
cyg_bool cyg_hal_stop_constructors;
79
#endif
80
 
81
typedef void (*pfunc) (void);
82
extern pfunc __CTOR_LIST__[];
83
extern pfunc __CTOR_END__[];
84
 
85
void
86
cyg_hal_invoke_constructors (void)
87
{
88
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
89
    static pfunc *p = &__CTOR_END__[-1];
90
 
91
    cyg_hal_stop_constructors = 0;
92
    for (; p >= __CTOR_LIST__; p--) {
93
        (*p) ();
94
        if (cyg_hal_stop_constructors) {
95
            p--;
96
            break;
97
        }
98
    }
99
#else
100
    pfunc *p;
101
 
102
    for (p = &__CTOR_END__[-1]; p >= __CTOR_LIST__; p--)
103
        (*p) ();
104
#endif
105
}
106
 
107
// Override any __eabi the compiler might generate. We don't want
108
// constructors to be called twice.
109
void __eabi (void) {}
110
 
111
//---------------------------------------------------------------------------
112
// First level C exception handler.
113
 
114
externC void __handle_exception (void);
115
 
116
externC HAL_SavedRegisters *_hal_registers;
117
 
118
externC void* volatile __mem_fault_handler;
119
 
120
void
121
cyg_hal_exception_handler(HAL_SavedRegisters *regs)
122
{
123
#ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
124
 
125
    // If we caught an exception inside the stubs, see if we were expecting it
126
    // and if so jump to the saved address
127
    if (__mem_fault_handler) {
128
        regs->pc = (CYG_ADDRWORD)__mem_fault_handler;
129
        return; // Caught an exception inside stubs        
130
    }
131
 
132
    // Set the pointer to the registers of the current exception
133
    // context. At entry the GDB stub will expand the
134
    // HAL_SavedRegisters structure into a (bigger) register array.
135
    _hal_registers = regs;
136
 
137
    __handle_exception();
138
 
139
#ifdef CYGPKG_HAL_QUICC
140
    {
141
        // This is unpleasant: it appears that if we interrupt the board
142
        // using ^C coming in on the QUICC's SMC1, by planting a breakpoint
143
        // at the interrupt return address, the decrementer interrupt is
144
        // not taken when the bp exception returns AND WORSE no other
145
        // interrupt is possible until the decrementer fires again.  This
146
        // does not apply to simple "incoming character" interrupts; it
147
        // seems it has to be combined with an immediate trap on RTI for
148
        // this to occur.
149
        // 
150
        // The solution is to test for decrementer underflow after the
151
        // (any) exception, and maybe reinitialize the decrementer.  If the
152
        // decrementer interrupt gets taken, that causes decrementer reinit
153
        // too, and no harm is done.
154
 
155
        cyg_uint32 result;
156
        asm volatile(
157
            "mfdec  %0;"
158
            : "=r"(result)
159
            );
160
 
161
        if ( CYGNUM_HAL_RTC_PERIOD < result ) {
162
            // then we missed a tick, but the exception masked it
163
            // reset the decrementer here
164
            asm volatile(
165
                "mtdec  %0;"
166
                : : "r"(CYGNUM_HAL_RTC_PERIOD)
167
                );
168
        }
169
    }
170
#endif
171
 
172
#elif defined(CYGFUN_HAL_COMMON_KERNEL_SUPPORT) && \
173
      defined(CYGPKG_HAL_EXCEPTIONS)
174
    int vector = regs->vector>>8;
175
 
176
    // We should decode the vector and pass a more appropriate
177
    // value as the second argument. For now we simply pass a
178
    // pointer to the saved registers. We should also divert
179
    // breakpoint and other debug vectors into the debug stubs.
180
 
181
    if (vector==CYGNUM_HAL_VECTOR_PROGRAM) {
182
        int srr1;
183
        CYGARC_MFSPR(CYGARC_REG_SRR1, srr1); // get srr1
184
 
185
        switch ((srr1 >> 17) & 0xf) {
186
        case 1:
187
            vector = CYGNUM_HAL_EXCEPTION_TRAP;
188
            break;
189
        case 2:
190
            vector = CYGNUM_HAL_EXCEPTION_PRIVILEGED_INSTRUCTION;
191
            break;
192
        case 4:
193
            vector = CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION;
194
            break;
195
        case 8:
196
            vector = CYGNUM_HAL_EXCEPTION_FPU;
197
            break;
198
        default:
199
            CYG_FAIL("Unknown PROGRAM exception!!");
200
        }
201
    }
202
    cyg_hal_deliver_exception( vector, (CYG_ADDRWORD)regs );
203
 
204
#else
205
 
206
    CYG_FAIL("Exception!!!");
207
 
208
#endif    
209
 
210
    return;
211
}
212
 
213
//---------------------------------------------------------------------------
214
// Default ISRs
215
 
216
#ifndef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
217
externC cyg_uint32
218
hal_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
219
{
220
    diag_printf("Interrupt: %d\n", vector);
221
 
222
    CYG_FAIL("Spurious Interrupt!!!");
223
    return 0;
224
}
225
#else
226
externC cyg_uint32
227
hal_arch_default_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
228
{
229
    return 0;
230
}
231
#endif
232
 
233
// The decrementer default ISR has to do nothing. The reason is that
234
// decrementer interrupts cannot be disabled - if a kernel configuration
235
// does not use the RTC, but does use external interrupts, the decrementer
236
// underflow could cause a CYG_FAIL (as above) even though the user did
237
// not expect any decrementer interrupts to happen.
238
externC cyg_uint32
239
hal_default_decrementer_isr(CYG_ADDRWORD vector, CYG_ADDRWORD data)
240
{
241
    return 0;
242
}
243
 
244
//---------------------------------------------------------------------------
245
// Idle thread action
246
 
247
externC bool hal_variant_idle_thread_action(cyg_uint32);
248
 
249
void
250
hal_idle_thread_action( cyg_uint32 count )
251
{
252
    // Execute variant idle thread action, while allowing it to control
253
    // whether to run any of the architecture action code.
254
    if (!hal_variant_idle_thread_action(count))
255
        return;
256
 
257
#if 0
258
    do {
259
        register cyg_uint32 dec;
260
 
261
        asm volatile(
262
            "mfdec  %0;"
263
            : "=r"(dec)
264
            );
265
        diag_printf( "Decrementer %08x\n", dec);
266
    } while (0);
267
#endif
268
}
269
 
270
//---------------------------------------------------------------------------
271
// Use MMU resources to map memory regions.  
272
// This relies that the platform HAL providing an
273
//          externC cyg_memdesc_t cyg_hal_mem_map[];
274
// as detailed in hal_cache.h, and the variant HAL providing the
275
// MMU mapping/clear functions.
276
externC void
277
hal_MMU_init (void)
278
{
279
    int id = 0;
280
    int i  = 0;
281
 
282
    cyg_hal_clear_MMU ();
283
 
284
    while (cyg_hal_mem_map[i].size) {
285
        id = cyg_hal_map_memory (id,
286
                                 cyg_hal_mem_map[i].virtual_addr,
287
                                 cyg_hal_mem_map[i].physical_addr,
288
                                 cyg_hal_mem_map[i].size,
289
                                 cyg_hal_mem_map[i].flags);
290
        i++;
291
    }
292
}
293
 
294
//---------------------------------------------------------------------------
295
// Initial cache enabling
296
// Specific behavior for each platform configured via plf_cache.h
297
 
298
externC void
299
hal_enable_caches(void)
300
{
301
#ifndef CYG_HAL_STARTUP_RAM
302
    // Invalidate caches
303
    HAL_DCACHE_INVALIDATE_ALL();
304
    HAL_ICACHE_INVALIDATE_ALL();
305
#endif
306
 
307
#ifdef CYGSEM_HAL_ENABLE_ICACHE_ON_STARTUP
308
#ifdef HAL_ICACHE_UNLOCK_ALL
309
    HAL_ICACHE_UNLOCK_ALL();
310
#endif
311
    HAL_ICACHE_ENABLE();
312
#endif
313
 
314
#ifdef CYGSEM_HAL_ENABLE_DCACHE_ON_STARTUP
315
#ifdef HAL_DCACHE_UNLOCK_ALL
316
    HAL_DCACHE_UNLOCK_ALL();
317
#endif
318
    HAL_DCACHE_ENABLE();
319
#ifdef HAL_DCACHE_WRITE_MODE
320
#ifdef CYGSEM_HAL_DCACHE_STARTUP_MODE_COPYBACK
321
    HAL_DCACHE_WRITE_MODE(HAL_DCACHE_WRITEBACK_MODE);
322
#else
323
    HAL_DCACHE_WRITE_MODE(HAL_DCACHE_WRITETHRU_MODE);
324
#endif
325
#endif
326
#endif
327
}
328
 
329
//---------------------------------------------------------------------------
330
//A jump via a null pointer causes the CPU to end up here.
331
externC void
332
hal_null_call(void)
333
{
334
 
335
    CYG_FAIL("Call via NULL-pointer!");
336
    for(;;);
337
}
338
 
339
//---------------------------------------------------------------------------
340
// 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.