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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [hal/] [i386/] [pcmb/] [v2_0/] [src/] [pcmb_misc.c] - Blame information for rev 1254

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//==========================================================================
2
//
3
//      pcmb_misc.c
4
//
5
//      HAL implementation 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, pjo
45
// Date:         1999-01-21
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
#include <pkgconf/hal_i386.h>
56
#include <pkgconf/hal_i386_pcmb.h>
57
 
58
#include <cyg/infra/cyg_type.h>         // Base types
59
#include <cyg/infra/cyg_trac.h>         // tracing macros
60
#include <cyg/infra/cyg_ass.h>          // assertion macros
61
 
62
#include <cyg/hal/hal_intr.h>
63
#include <cyg/hal/hal_io.h>
64
#include <cyg/hal/hal_smp.h>
65
 
66
/*------------------------------------------------------------------------*/
67
// Array which stores the configured priority levels for the configured
68
// interrupts.
69
 
70
volatile CYG_BYTE hal_interrupt_level[CYGNUM_HAL_ISR_COUNT];
71
 
72
/*------------------------------------------------------------------------*/
73
// Static variables
74
 
75
CYG_ADDRWORD cyg_hal_pcmb_memsize_base;
76
CYG_ADDRWORD cyg_hal_pcmb_memsize_extended;
77
 
78
/*------------------------------------------------------------------------*/
79
// Initializer
80
 
81
void hal_pcmb_init(void)
82
{
83
#ifdef CYGPKG_HAL_I386_PCMB_MEMSIZE_HARDCODE
84
    cyg_hal_pcmb_memsize_base = CYGNUM_HAL_I386_PCMB_MEMSIZE_BASE;
85
    cyg_hal_pcmb_memsize_extended = CYGNUM_HAL_I386_PCMB_MEMSIZE_EXTENDED;
86
#endif
87
 
88
#ifdef CYGPKG_HAL_I386_PCMB_MEMSIZE_BIOS
89
    cyg_uint8 lo,hi;
90
 
91
    HAL_READ_CMOS( 0x15, lo );
92
    HAL_READ_CMOS( 0x16, hi );
93
 
94
    cyg_hal_pcmb_memsize_base = ((hi<<8)+lo)*1024;
95
 
96
#ifndef CYG_HAL_STARTUP_ROM
97
    // If we started up under a BIOS, then it will have put
98
    // the discovered extended memory size in CMOS bytes 30/31.
99
    HAL_READ_CMOS( 0x30, lo );
100
    HAL_READ_CMOS( 0x31, hi );
101
#else
102
    // 
103
    HAL_READ_CMOS( 0x17, lo );
104
    HAL_READ_CMOS( 0x18, hi );
105
#endif
106
 
107
    cyg_hal_pcmb_memsize_extended = ((hi<<8)+lo)*1024;
108
#endif
109
 
110
    // Disable NMI - this can be reenabled later, once a proper handler
111
    // is registered and ready to handle events
112
    HAL_WRITE_UINT8(0x70, 0x80);
113
}
114
 
115
/*------------------------------------------------------------------------*/
116
 
117
cyg_uint8 *hal_i386_mem_real_region_top( cyg_uint8 *regionend )
118
{
119
    CYG_ASSERT( cyg_hal_pcmb_memsize_base > 0 , "No base RAM size set!");
120
    CYG_ASSERT( cyg_hal_pcmb_memsize_extended > 0 , "No extended RAM size set!");
121
 
122
    if( (CYG_ADDRESS)regionend <= 0x000A0000 )
123
        regionend = (cyg_uint8 *)cyg_hal_pcmb_memsize_base;
124
    else if( (CYG_ADDRESS)regionend >= 0x00100000 )
125
        regionend = (cyg_uint8 *)cyg_hal_pcmb_memsize_extended+0x00100000;
126
 
127
    return regionend;
128
}
129
 
130
/*------------------------------------------------------------------------*/
131
// Clock initialization and access
132
 
133
#ifdef CYGPKG_HAL_SMP_SUPPORT
134
static HAL_SPINLOCK_TYPE pc_clock_lock;
135
#else
136
#define HAL_SPINLOCK_SPIN( lock )
137
#define HAL_SPINLOCK_CLEAR( lock )
138
#endif
139
 
140
void hal_pc_clock_initialize(cyg_uint32 period)
141
{
142
    /* Select mode 2: rate generator.  Then we'll load LSB, and finally MSB. */
143
    HAL_WRITE_UINT8( PC_PIT_CONTROL, 0x34 );
144
    HAL_WRITE_UINT8( PC_PIT_CLOCK_0, period & 0xFF );
145
    HAL_WRITE_UINT8( PC_PIT_CLOCK_0, period >> 8 );
146
 
147
    HAL_SPINLOCK_CLEAR( pc_clock_lock );
148
}
149
 
150
 
151
void hal_pc_clock_read(cyg_uint32 * count)
152
{
153
    cyg_uint8 lo = 0,hi = 0;
154
    cyg_uint32 curr = 0;
155
    CYG_INTERRUPT_STATE interruptState ;
156
 
157
    /* Hold off on interrupts for a bit. */
158
    HAL_DISABLE_INTERRUPTS(interruptState) ;
159
 
160
    HAL_SPINLOCK_SPIN( pc_clock_lock );
161
 
162
    /* Latch counter 0. */
163
    HAL_WRITE_UINT8(PC_PIT_CONTROL, 0x00);
164
 
165
    /* Now get the value. */
166
    HAL_READ_UINT8( PC_PIT_CLOCK_0, lo );
167
    HAL_READ_UINT8( PC_PIT_CLOCK_0, hi );
168
 
169
    curr = (hi<<8) | lo;
170
 
171
    HAL_SPINLOCK_CLEAR( pc_clock_lock );
172
 
173
    /* (Maybe) restore interrupts. */
174
    HAL_RESTORE_INTERRUPTS(interruptState) ;
175
 
176
    *count = CYGNUM_HAL_RTC_PERIOD - curr ;
177
}
178
 
179
/*------------------------------------------------------------------------*/
180
 
181
void hal_idle_thread_action(cyg_uint32 loop_count)
182
{
183
#if 1 //ndef CYGPKG_HAL_SMP_SUPPORT
184
    asm("hlt") ;
185
 
186
#else    
187
 
188
    CYG_WORD32 val;
189
    CYG_WORD32 cpu = 0;
190
#ifdef CYGPKG_HAL_SMP_SUPPORT    
191
    cpu = HAL_SMP_CPU_THIS();
192
 
193
    {
194
        __externC HAL_SPINLOCK_TYPE cyg_hal_ioapic_lock;
195
 
196
        HAL_SPINLOCK_SPIN( cyg_hal_ioapic_lock );
197
        HAL_IOAPIC_READ( HAL_IOAPIC_REG_REDTBL+4, val );
198
        PC_WRITE_SCREEN_32( PC_SCREEN_LINE(15)+10, val );
199
 
200
        HAL_IOAPIC_READ( HAL_IOAPIC_REG_REDTBL+5, val );
201
        PC_WRITE_SCREEN_32( PC_SCREEN_LINE(15), val );
202
 
203
        HAL_SPINLOCK_CLEAR( cyg_hal_ioapic_lock );
204
 
205
    }
206
#endif
207
 
208
    hal_pc_clock_read( &val);
209
    PC_WRITE_SCREEN_32( PC_SCREEN_LINE(15)+20, val );
210
 
211
 
212
#ifdef CYGPKG_HAL_SMP_SUPPORT    
213
 
214
    PC_WRITE_SCREEN_8( PC_SCREEN_LINE(16+cpu), cpu);
215
 
216
    HAL_APIC_READ( HAL_APIC_IRR, val );
217
    PC_WRITE_SCREEN_32( PC_SCREEN_LINE(16+cpu)+10, val );
218
    HAL_APIC_READ( HAL_APIC_IRR+1, val );
219
    PC_WRITE_SCREEN_32( PC_SCREEN_LINE(16+cpu)+20, val );
220
    HAL_APIC_READ( HAL_APIC_IRR+2, val );
221
    PC_WRITE_SCREEN_32( PC_SCREEN_LINE(16+cpu)+30, val );
222
#endif
223
 
224
    HAL_QUERY_INTERRUPTS( val );
225
    PC_WRITE_SCREEN_32( PC_SCREEN_LINE(16+cpu)+50, val );
226
    PC_WRITE_SCREEN_32( PC_SCREEN_LINE(16+cpu)+60, loop_count );
227
 
228
#endif
229
}
230
 
231
/*------------------------------------------------------------------------*/
232
/* End of pcmb_misc.c                                                      */

powered by: WebSVN 2.1.0

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