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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [i386/] [pc/] [current/] [src/] [plf_misc.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      plf_misc.c
4
//
5
//      HAL platform 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
43
// Contributors: nickg, jlarmour, pjo
44
// Date:         1999-01-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
 
55
#include <cyg/infra/cyg_type.h>         // Base types
56
#include <cyg/infra/cyg_trac.h>         // tracing macros
57
#include <cyg/infra/cyg_ass.h>          // assertion macros
58
 
59
#include <cyg/hal/hal_arch.h>           // architectural definitions
60
 
61
#include <cyg/hal/hal_intr.h>           // Interrupt handling
62
 
63
#include <cyg/hal/hal_cache.h>          // Cache handling
64
 
65
#include <cyg/hal/plf_misc.h>
66
 
67
#include <cyg/hal/hal_io.h>
68
 
69
#ifdef  CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
70
#include <cyg/hal/hal_if.h>
71
#endif
72
 
73
#ifdef CYGPKG_KERNEL
74
#include <pkgconf/kernel.h>
75
#include <cyg/kernel/ktypes.h>
76
#include <cyg/kernel/kapi.h>
77
#endif /* CYGPKG_KERNEL */
78
 
79
/*------------------------------------------------------------------------*/
80
 
81
extern void patch_dbg_syscalls(void * vector);
82
 
83
extern void hal_pcmb_init(void);
84
 
85
#ifdef CYGPKG_HAL_SMP_SUPPORT
86
__externC void cyg_hal_smp_init(void);
87
#endif
88
 
89
CYG_ADDRWORD cyg_hal_pc_memsize_base;
90
CYG_ADDRWORD cyg_hal_pc_memsize_extended;
91
 
92
//----------------------------------------------------------------------------
93
// ISR tables
94
 
95
volatile CYG_ADDRESS    hal_interrupt_handlers[CYGNUM_HAL_ISR_COUNT];
96
volatile CYG_ADDRWORD   hal_interrupt_data[CYGNUM_HAL_ISR_COUNT];
97
volatile CYG_ADDRESS    hal_interrupt_objects[CYGNUM_HAL_ISR_COUNT];
98
 
99
//-----------------------------------------------------------------------------
100
// IDT interrupt gate initialization
101
 
102
externC void cyg_hal_pc_set_idt_entry(CYG_ADDRESS routine,short *idtEntry)
103
{
104
 
105
   idtEntry[0]=routine & 0xFFFF;
106
   idtEntry[1]=8;
107
   idtEntry[2]=0x8E00;
108
   idtEntry[3]=routine >> 16;
109
}
110
 
111
/*------------------------------------------------------------------------*/
112
 
113
void hal_platform_init(void)
114
{
115
    int vector;
116
 
117
    HAL_ICACHE_INVALIDATE_ALL();
118
    HAL_ICACHE_ENABLE();
119
    HAL_DCACHE_INVALIDATE_ALL();
120
    HAL_DCACHE_ENABLE();
121
 
122
#ifdef CYGPKG_HAL_I386_PC_MEMSIZE_HARDCODE
123
    cyg_hal_pc_memsize_base = CYGNUM_HAL_I386_PC_MEMSIZE_BASE;
124
    cyg_hal_pc_memsize_extended = CYGNUM_HAL_I386_PC_MEMSIZE_EXTENDED;
125
#endif
126
 
127
#ifdef CYGPKG_HAL_I386_PC_MEMSIZE_BIOS
128
    cyg_uint8 lo,hi;
129
 
130
    HAL_READ_CMOS( 0x15, lo );
131
    HAL_READ_CMOS( 0x16, hi );
132
 
133
    cyg_hal_pc_memsize_base = ((hi<<8)+lo)*1024;
134
 
135
#ifndef CYG_HAL_STARTUP_ROM
136
    // If we started up under a BIOS, then it will have put
137
    // the discovered extended memory size in CMOS bytes 30/31.
138
    HAL_READ_CMOS( 0x30, lo );
139
    HAL_READ_CMOS( 0x31, hi );
140
#else
141
    // 
142
    HAL_READ_CMOS( 0x17, lo );
143
    HAL_READ_CMOS( 0x18, hi );
144
#endif
145
 
146
    cyg_hal_pc_memsize_extended = ((hi<<8)+lo)*1024;
147
#endif
148
 
149
    // Call motherboard init function
150
    hal_pcmb_init();
151
 
152
    // ISR table setup: plant the default ISR in all interrupt handlers
153
    // and the default interrupt VSR in the equivalent VSR table slots.
154
    for (vector = CYGNUM_HAL_ISR_MIN; vector <= CYGNUM_HAL_ISR_MAX; vector++)
155
    {
156
        cyg_uint32 index;
157
        HAL_TRANSLATE_VECTOR( vector, index );
158
        hal_interrupt_handlers[index] = (CYG_ADDRESS) HAL_DEFAULT_ISR;
159
        HAL_VSR_SET( vector, &__default_interrupt_vsr, NULL );
160
    }
161
 
162
#if !defined(CYG_HAL_STARTUP_RAM)
163
    for (vector = CYGNUM_HAL_EXCEPTION_MIN;
164
         vector <= CYGNUM_HAL_EXCEPTION_MAX;
165
         vector++)
166
    {
167
#if defined(CYGHWR_HAL_I386_FPU_SWITCH_LAZY)
168
        // If we are doing lazy FPU switching, the FPU switch VSR has
169
        // already been installed, so avoid overwriting it.
170
        if( vector != CYGNUM_HAL_VECTOR_NO_DEVICE )
171
#endif
172
        {
173
            HAL_VSR_SET( vector, &__default_exception_vsr, NULL );
174
        }
175
    }
176
#endif
177
 
178
#ifdef CYGPKG_REDBOOT
179
 
180
    // Start the timer device running if we are in a RedBoot
181
    // configuration. 
182
 
183
    HAL_CLOCK_INITIALIZE( CYGNUM_HAL_RTC_PERIOD );
184
 
185
#endif    
186
 
187
    hal_if_init();
188
 
189
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT) || \
190
    defined(CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT)
191
    {
192
        void hal_ctrlc_isr_init(void);
193
        hal_ctrlc_isr_init();
194
    }
195
 
196
#endif
197
 
198
#ifdef CYGPKG_HAL_SMP_SUPPORT
199
 
200
    cyg_hal_smp_init();
201
 
202
#endif
203
 
204
}
205
 
206
cyg_uint8 *hal_i386_mem_real_region_top( cyg_uint8 *regionend )
207
{
208
    CYG_ASSERT( cyg_hal_pc_memsize_base > 0 , "No base RAM size set!");
209
    CYG_ASSERT( cyg_hal_pc_memsize_extended > 0 , "No extended RAM size set!");
210
 
211
    if( (CYG_ADDRESS)regionend <= 0x000A0000 )
212
        regionend = (cyg_uint8 *)cyg_hal_pc_memsize_base;
213
    else if( (CYG_ADDRESS)regionend >= 0x00100000 )
214
        regionend = (cyg_uint8 *)cyg_hal_pc_memsize_extended+0x00100000;
215
 
216
    return regionend;
217
}
218
 
219
/*------------------------------------------------------------------------*/
220
 
221
void hal_pc_reset(void)
222
{
223
    /* Use Intel's IDT triple-fault trick. */
224
    asm("movl $badIdt, %eax\n"
225
        "lidt (%eax)\n"
226
        "int $3\n"
227
        "hlt\n"
228
 
229
        ".align 4\n"
230
 
231
        "badIdt:\n"
232
        ".word          0\n"
233
        ".long          0\n"
234
        ) ;
235
}
236
 
237
/*------------------------------------------------------------------------*/
238
 
239
void
240
hal_delay_us(int us)
241
{
242
    while( us > 0 )
243
    {
244
        cyg_uint32 us1 = us;
245
        cyg_int32 ticks;
246
        cyg_uint32 cval1, cval2;
247
 
248
        // Wait in bursts of 1s to avoid overflow problems with the
249
        // multiply by 1000 below.
250
 
251
        if( us1 > 1000000 )
252
            us1 = 1000000;
253
 
254
        us -= us1;
255
 
256
        // The PC clock ticks at 838ns per tick. So we convert the us
257
        // value we were given to clock ticks and wait for that many
258
        // to pass.
259
 
260
        ticks = (us1 * 1000UL) / 838UL;
261
 
262
        HAL_CLOCK_READ( &cval1 );
263
 
264
        // We just loop, waiting for clock ticks to happen,
265
        // and subtracting them from ticks when they do.
266
 
267
        while( ticks > 0 )
268
        {
269
            cyg_int32 diff;
270
            HAL_CLOCK_READ( &cval2 );
271
 
272
            diff = cval2 - cval1;
273
 
274
            // Cope with counter wrap-around.
275
            if( diff < 0 )
276
                diff += CYGNUM_HAL_RTC_PERIOD;
277
 
278
            ticks -= diff;
279
            cval1 = cval2;
280
 
281
        }
282
    }
283
}
284
 
285
 
286
/*------------------------------------------------------------------------*/
287
/* End of plf_misc.c                                                      */

powered by: WebSVN 2.1.0

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