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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [mn10300/] [am33/] [v2_0/] [src/] [var_misc.c] - Blame information for rev 773

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      var_misc.c
4
//
5
//      HAL CPU variant 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, dmoseley
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
 
56
#include <cyg/infra/cyg_type.h>         // Base types
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/infra/cyg_ass.h>          // assertion macros
59
 
60
#include <cyg/hal/hal_cache.h>
61
 
62
#include <cyg/hal/hal_intr.h>           // HAL_CLOCK_READ
63
#include CYGHWR_MEMORY_LAYOUT_H
64
 
65
/*------------------------------------------------------------------------*/
66
/* Variant specific initialization routine.                               */
67
 
68
void hal_variant_init(void)
69
{
70
    // Let the timer run at a default rate (for delays)
71
    HAL_CLOCK_INITIALIZE(CYGNUM_HAL_RTC_PERIOD);
72
}
73
 
74
/*------------------------------------------------------------------------*/
75
/* Cache functions.                                                       */
76
 
77
#if 0 //!defined(CYG_HAL_MN10300_SIM)
78
void cyg_hal_dcache_store(CYG_ADDRWORD base, int size)
79
{
80
    volatile register CYG_BYTE *way0 = HAL_DCACHE_PURGE_WAY0;
81
    volatile register CYG_BYTE *way1 = HAL_DCACHE_PURGE_WAY1;
82
    volatile register CYG_BYTE *way2 = HAL_DCACHE_PURGE_WAY2;
83
    volatile register CYG_BYTE *way3 = HAL_DCACHE_PURGE_WAY3;
84
    register int i;
85
    register CYG_ADDRWORD state;
86
 
87
    HAL_DCACHE_IS_ENABLED(state);
88
    if (state)
89
        HAL_DCACHE_DISABLE();
90
 
91
    way0 += base & 0x000003f0;
92
    way1 += base & 0x000003f0;
93
    way2 += base & 0x000003f0;
94
    way3 += base & 0x000003f0;
95
    for( i = 0; i < size; i += HAL_DCACHE_LINE_SIZE )
96
    {
97
        *(CYG_ADDRWORD *)way0 = 0;
98
        *(CYG_ADDRWORD *)way1 = 0;
99
        *(CYG_ADDRWORD *)way2 = 0;
100
        *(CYG_ADDRWORD *)way3 = 0;
101
        way0 += HAL_DCACHE_LINE_SIZE;
102
        way1 += HAL_DCACHE_LINE_SIZE;
103
        way2 += HAL_DCACHE_LINE_SIZE;
104
        way3 += HAL_DCACHE_LINE_SIZE;
105
    }
106
    if (state)
107
        HAL_DCACHE_ENABLE();
108
}
109
#endif
110
 
111
/*------------------------------------------------------------------------*/
112
/* Clock functions.                                                       */
113
 
114
cyg_uint32 __hal_period__;
115
 
116
// Delay for some usecs.
117
void
118
hal_delay_us(cyg_int32 delay)
119
{
120
#define _TICKS_PER_USEC (CYGHWR_HAL_MN10300_PROCESSOR_OSC/1000000)
121
    cyg_uint32 now, prev, diff, usecs;
122
 
123
    diff = usecs = 0;
124
    HAL_CLOCK_READ(&prev);
125
 
126
    while (delay > usecs) {
127
        HAL_CLOCK_READ(&now);
128
 
129
        if (now < prev)
130
            diff += (now + (__hal_period__ - prev));
131
        else
132
            diff += (now - prev);
133
 
134
        prev = now;
135
 
136
        if (diff >= _TICKS_PER_USEC) {
137
            usecs += (diff / _TICKS_PER_USEC);
138
            diff %= _TICKS_PER_USEC;
139
        }
140
    }
141
}
142
 
143
 
144
/*------------------------------------------------------------------------*/
145
/* Memory top support                                                     */
146
 
147
#define SDBASE0       ((volatile unsigned *)0xDA000008)
148
#define SDBASE1       ((volatile unsigned *)0xDA00000C)
149
#define SDRAMBUS      ((volatile unsigned *)0xDA000000)
150
 
151
#if CYGINT_HAL_MN10300_MEM_REAL_REGION_TOP
152
externC cyg_uint8 *
153
hal_mn10300_mem_real_region_top( cyg_uint8 *regionend )
154
{
155
    unsigned dram_size, dram_base;
156
 
157
    // Figure out actual DRAM size from memory controller config.
158
    dram_size = 0x400000 << ((*SDRAMBUS >> 16) & 0x3);
159
    if (*SDBASE1 & 1)
160
        dram_size *= 2;
161
    dram_base = (*SDBASE0 & ((*SDBASE0 & 0xfff0) << 16));
162
 
163
    CYG_ASSERT( dram_size >= 8<<20, "Less than 8MB SDRAM reported!" );
164
    CYG_ASSERT( dram_size <=  256<<20, "More than 256MB SDRAM reported!" );
165
 
166
    // is it the "normal" end of the DRAM region? If so, it should be
167
    // replaced by the real size
168
    if ( regionend ==
169
         ((cyg_uint8 *)CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE) ) {
170
        regionend = (cyg_uint8 *)dram_base + dram_size;
171
    }
172
    return regionend;
173
}
174
#endif
175
 
176
 
177
#ifdef CYGPKG_CYGMON
178
/*------------------------------------------------------------------------*/
179
/* GDB Register functions.                                                */
180
#include <cyg/hal/var_arch.h>
181
#include <cyg/hal/hal_stub.h>
182
 
183
#if CYGHWR_HAL_MN10300_AM33_REVISION == 2
184
int fpu_regs_read = 0;
185
#endif
186
 
187
int msp_read = 0;
188
 
189
extern int *_registers_valid;
190
 
191
void am33_get_gdb_extra_registers(CYG_ADDRWORD *registers, HAL_SavedRegisters *regs)
192
{
193
  register CYG_ADDRWORD epsw;
194
  asm volatile ("  mov epsw, %0 " : "=r" (epsw) : );
195
 
196
  registers[15] = regs->e0;
197
  registers[16] = regs->e1;
198
  registers[17] = regs->e2;
199
  registers[18] = regs->e3;
200
  registers[19] = regs->e4;
201
  registers[20] = regs->e5;
202
  registers[21] = regs->e6;
203
  registers[22] = regs->e7;
204
 
205
  registers[26] = regs->mcrh;
206
  registers[27] = regs->mcrl;
207
  registers[28] = regs->mcvf;
208
 
209
  registers[14] = regs->mdrq;
210
 
211
  {
212
    register CYG_ADDRWORD ssp, usp, msp;
213
    asm volatile (" mov usp,  %0 " : "=a" (usp) : );
214
    asm volatile (" mov ssp,  %0 " : "=a" (ssp) : );
215
    if ((epsw & HAL_ARCH_AM33_PSW_ML) == HAL_ARCH_AM33_PSW_ML)
216
      {
217
        // We are running in Monitor mode.  Go ahead and read the MSP.
218
        asm volatile (" mov msp, %0 " : "=a" (msp) : );
219
        msp_read = 1;
220
      } else {
221
        msp = 0;
222
        msp_read = 0;
223
      }
224
 
225
    // Now we need to determine which sp was in effect when we hit this exception,
226
    // since we want the register image to reflect the state at the time of the
227
    // exception.
228
    if ((regs->psw & HAL_ARCH_AM33_PSW_ML) == HAL_ARCH_AM33_PSW_ML)
229
      {
230
        msp = regs->sp;
231
      }
232
    else if ((regs->psw & HAL_ARCH_AM33_PSW_nSL) == 0)
233
      {
234
        ssp = regs->sp;
235
      }
236
    else
237
      {
238
        usp = regs->sp;
239
      }
240
 
241
    registers[23] = ssp;
242
    registers[24] = msp;
243
    registers[25] = usp;
244
  }
245
 
246
#if CYGHWR_HAL_MN10300_AM33_REVISION == 2
247
  if ((regs->psw & HAL_ARCH_AM33_PSW_FE) == HAL_ARCH_AM33_PSW_FE)
248
    {
249
      // The FPU is enabled.  Go ahead and read the registers
250
      asm volatile (" fmov fpcr, %0  " : "=d" (registers[29]) : );
251
      asm volatile (" fmov fs0,  %0  " : "=m" (registers[32]) : );
252
      asm volatile (" fmov fs1,  %0  " : "=m" (registers[33]) : );
253
      asm volatile (" fmov fs2,  %0  " : "=m" (registers[34]) : );
254
      asm volatile (" fmov fs3,  %0  " : "=m" (registers[35]) : );
255
      asm volatile (" fmov fs4,  %0  " : "=m" (registers[36]) : );
256
      asm volatile (" fmov fs5,  %0  " : "=m" (registers[37]) : );
257
      asm volatile (" fmov fs6,  %0  " : "=m" (registers[38]) : );
258
      asm volatile (" fmov fs7,  %0  " : "=m" (registers[39]) : );
259
      asm volatile (" fmov fs8,  %0  " : "=m" (registers[40]) : );
260
      asm volatile (" fmov fs9,  %0  " : "=m" (registers[41]) : );
261
      asm volatile (" fmov fs10, %0  " : "=m" (registers[42]) : );
262
      asm volatile (" fmov fs11, %0  " : "=m" (registers[43]) : );
263
      asm volatile (" fmov fs12, %0  " : "=m" (registers[44]) : );
264
      asm volatile (" fmov fs13, %0  " : "=m" (registers[45]) : );
265
      asm volatile (" fmov fs14, %0  " : "=m" (registers[46]) : );
266
      asm volatile (" fmov fs15, %0  " : "=m" (registers[47]) : );
267
      asm volatile (" fmov fs16, %0  " : "=m" (registers[48]) : );
268
      asm volatile (" fmov fs17, %0  " : "=m" (registers[49]) : );
269
      asm volatile (" fmov fs18, %0  " : "=m" (registers[50]) : );
270
      asm volatile (" fmov fs19, %0  " : "=m" (registers[51]) : );
271
      asm volatile (" fmov fs20, %0  " : "=m" (registers[52]) : );
272
      asm volatile (" fmov fs21, %0  " : "=m" (registers[53]) : );
273
      asm volatile (" fmov fs22, %0  " : "=m" (registers[54]) : );
274
      asm volatile (" fmov fs23, %0  " : "=m" (registers[55]) : );
275
      asm volatile (" fmov fs24, %0  " : "=m" (registers[56]) : );
276
      asm volatile (" fmov fs25, %0  " : "=m" (registers[57]) : );
277
      asm volatile (" fmov fs26, %0  " : "=m" (registers[58]) : );
278
      asm volatile (" fmov fs27, %0  " : "=m" (registers[59]) : );
279
      asm volatile (" fmov fs28, %0  " : "=m" (registers[60]) : );
280
      asm volatile (" fmov fs29, %0  " : "=m" (registers[61]) : );
281
      asm volatile (" fmov fs30, %0  " : "=m" (registers[62]) : );
282
      asm volatile (" fmov fs31, %0  " : "=m" (registers[63]) : );
283
      fpu_regs_read = 1;
284
    } else {
285
      fpu_regs_read = 0;
286
    }
287
#endif
288
 
289
#ifdef CYGHWR_REGISTER_VALIDITY_CHECKING
290
  {
291
    int i;
292
 
293
    // Initially set all registers to valid
294
    for (i = 0; i < NUMREGS; i++)
295
      _registers_valid[i] = 1;
296
 
297
    if (msp_read == 0)
298
      _registers_valid[MSP] = 0;
299
 
300
    if (fpu_regs_read == 0)
301
      {
302
        for (i = FP_START; i <= FP_END; i++)
303
          _registers_valid[i] = 0;
304
      }
305
  }
306
#endif
307
}
308
 
309
void am33_set_gdb_extra_registers(CYG_ADDRWORD *registers, HAL_SavedRegisters *regs)
310
{
311
  regs->e0 = registers[15];
312
  regs->e1 = registers[16];
313
  regs->e2 = registers[17];
314
  regs->e3 = registers[18];
315
  regs->e4 = registers[19];
316
  regs->e5 = registers[20];
317
  regs->e6 = registers[21];
318
  regs->e7 = registers[22];
319
 
320
  regs->mcrh = registers[26];
321
  regs->mcrl = registers[27];
322
  regs->mcvf = registers[28];
323
 
324
  regs->mdrq = registers[14];
325
 
326
  {
327
    register CYG_ADDRWORD ssp, usp, msp;
328
    ssp = registers[23];
329
    msp = registers[24];
330
    usp = registers[25];
331
    if ((registers[11] & HAL_ARCH_AM33_PSW_ML) == HAL_ARCH_AM33_PSW_ML)
332
      {
333
        // We were running in monitor mode.
334
        // Go ahead and manually restore ssp and usp.
335
        // msp will be restored by the rti.
336
        asm volatile (" mov %0, usp " : : "a" (usp));
337
        asm volatile (" mov %0, ssp " : : "a" (ssp));
338
      }
339
    else if ((registers[11] & HAL_ARCH_AM33_PSW_nSL) == 0)
340
      {
341
        // We were running in system mode.
342
        // Go ahead and manually restore msp and usp.
343
        // ssp will be restored by the rti.
344
        asm volatile (" mov %0, usp " : : "a" (usp));
345
        if (msp_read)
346
          {
347
          asm volatile (" mov %0, msp " : : "a" (msp));
348
          }
349
      }
350
    else
351
      {
352
        // We were running in user mode.
353
        // Go ahead and manually restore msp and ssp.
354
        // usp will be restored by the rti.
355
        asm volatile (" mov %0, ssp " : : "a" (ssp));
356
        if (msp_read)
357
          {
358
          asm volatile (" mov %0, msp " : : "a" (msp));
359
          }
360
      }
361
  }
362
 
363
#if CYGHWR_HAL_MN10300_AM33_REVISION == 2
364
  if (fpu_regs_read)
365
    {
366
      // The FPU registers have been read and the FPU is enabled.
367
      // Go ahead and write the registers
368
      asm volatile (" fmov %0, fpcr  " : : "d" (registers[29]) );
369
      asm volatile (" fmov %0, fs0   " : : "m" (registers[32]) );
370
      asm volatile (" fmov %0, fs1   " : : "m" (registers[33]) );
371
      asm volatile (" fmov %0, fs2   " : : "m" (registers[34]) );
372
      asm volatile (" fmov %0, fs3   " : : "m" (registers[35]) );
373
      asm volatile (" fmov %0, fs4   " : : "m" (registers[36]) );
374
      asm volatile (" fmov %0, fs5   " : : "m" (registers[37]) );
375
      asm volatile (" fmov %0, fs6   " : : "m" (registers[38]) );
376
      asm volatile (" fmov %0, fs7   " : : "m" (registers[39]) );
377
      asm volatile (" fmov %0, fs8   " : : "m" (registers[40]) );
378
      asm volatile (" fmov %0, fs9   " : : "m" (registers[41]) );
379
      asm volatile (" fmov %0, fs10  " : : "m" (registers[42]) );
380
      asm volatile (" fmov %0, fs11  " : : "m" (registers[43]) );
381
      asm volatile (" fmov %0, fs12  " : : "m" (registers[44]) );
382
      asm volatile (" fmov %0, fs13  " : : "m" (registers[45]) );
383
      asm volatile (" fmov %0, fs14  " : : "m" (registers[46]) );
384
      asm volatile (" fmov %0, fs15  " : : "m" (registers[47]) );
385
      asm volatile (" fmov %0, fs16  " : : "m" (registers[48]) );
386
      asm volatile (" fmov %0, fs17  " : : "m" (registers[49]) );
387
      asm volatile (" fmov %0, fs18  " : : "m" (registers[50]) );
388
      asm volatile (" fmov %0, fs19  " : : "m" (registers[51]) );
389
      asm volatile (" fmov %0, fs20  " : : "m" (registers[52]) );
390
      asm volatile (" fmov %0, fs21  " : : "m" (registers[53]) );
391
      asm volatile (" fmov %0, fs22  " : : "m" (registers[54]) );
392
      asm volatile (" fmov %0, fs23  " : : "m" (registers[55]) );
393
      asm volatile (" fmov %0, fs24  " : : "m" (registers[56]) );
394
      asm volatile (" fmov %0, fs25  " : : "m" (registers[57]) );
395
      asm volatile (" fmov %0, fs26  " : : "m" (registers[58]) );
396
      asm volatile (" fmov %0, fs27  " : : "m" (registers[59]) );
397
      asm volatile (" fmov %0, fs28  " : : "m" (registers[60]) );
398
      asm volatile (" fmov %0, fs29  " : : "m" (registers[61]) );
399
      asm volatile (" fmov %0, fs30  " : : "m" (registers[62]) );
400
      asm volatile (" fmov %0, fs31  " : : "m" (registers[63]) );
401
    }
402
#endif
403
}
404
#endif // CYGPKG_CYGMON
405
 
406
/*------------------------------------------------------------------------*/
407
/* End of var_misc.c                                                      */

powered by: WebSVN 2.1.0

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