source: rtems/cpukit/score/cpu/mips/cpu.c @ 25571ae

4.104.114.84.95
Last change on this file since 25571ae was 25571ae, checked in by Greg Menke <gregory.menke@…>, on 06/10/06 at 10:42:07

Added mips==32 to fix build problems on those targets caused by the B.Robinson patch

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 *  Mips CPU Dependent Source
3 *
4 *  2002:       Greg Menke (gregory.menke@gsfc.nasa.gov)
5 *      Overhauled interrupt level and interrupt enable/disable code
6 *      to more exactly support MIPS.  Our mods were for MIPS1 processors
7 *      MIPS3 ports are affected, though apps written to the old behavior
8 *      should still work OK.
9 *
10 *  Conversion to MIPS port by Alan Cudmore <alanc@linuxstart.com> and
11 *           Joel Sherrill <joel@OARcorp.com>.
12 *
13 *    These changes made the code conditional on standard cpp predefines,
14 *    merged the mips1 and mips3 code sequences as much as possible,
15 *    and moved some of the assembly code to C.  Alan did much of the
16 *    initial analysis and rework.  Joel took over from there and
17 *    wrote the JMR3904 BSP so this could be tested.  Joel also
18 *    added the new interrupt vectoring support in libcpu and
19 *    tried to better support the various interrupt controllers.
20 *
21 *  Original MIP64ORION port by Craig Lebakken <craigl@transition.com>
22 *           COPYRIGHT (c) 1996 by Transition Networks Inc.
23 *
24 *         To anyone who acknowledges that this file is provided "AS IS"
25 *         without any express or implied warranty:
26 *             permission to use, copy, modify, and distribute this file
27 *             for any purpose is hereby granted without fee, provided that
28 *             the above copyright notice and this notice appears in all
29 *             copies, and that the name of Transition Networks not be used in
30 *             advertising or publicity pertaining to distribution of the
31 *             software without specific, written prior permission.
32 *             Transition Networks makes no representations about the
33 *             suitability of this software for any purpose.
34 *
35 *  COPYRIGHT (c) 1989-2001.
36 *  On-Line Applications Research Corporation (OAR).
37 *
38 *  The license and distribution terms for this file may be
39 *  found in the file LICENSE in this distribution or at
40 *  http://www.rtems.com/license/LICENSE.
41 *
42 *  $Id$
43 */
44
45#include <rtems/system.h>
46#include <rtems/score/isr.h>
47#include <rtems/score/wkspace.h>
48
49
50
51
52/*
53** Exception stack frame pointer used in cpu_asm to pass the exception stack frame
54** address to the context switch code.
55*/
56#if (__mips == 1) || (__mips == 32)
57typedef uint32_t ESF_PTR_TYPE;
58#elif (__mips == 3)
59typedef uint64_t ESF_PTR_TYPE;
60#else
61#error "unknown MIPS ISA"
62#endif
63
64ESF_PTR_TYPE __exceptionStackFrame = 0;
65
66
67
68
69/*  _CPU_Initialize
70 *
71 *  This routine performs processor dependent initialization.
72 *
73 *  INPUT PARAMETERS:
74 *    cpu_table       - CPU table to initialize
75 *    thread_dispatch - address of disptaching routine
76 */
77
78
79void _CPU_Initialize(
80  rtems_cpu_table  *cpu_table,
81  void      (*thread_dispatch)      /* ignored on this CPU */
82)
83{
84  /*
85   *  If there is not an easy way to initialize the FP context
86   *  during Context_Initialize, then it is usually easier to
87   *  save an "uninitialized" FP context here and copy it to
88   *  the task's during Context_Initialize.
89   */
90
91#if CPU_HARDWARE_FP
92  /* FP context initialization support goes here */
93  _CPU_Null_fp_context.fpcs = 0x1000000;        /* Set FS flag in floating point coprocessor
94                                                   control register to prevent underflow and
95                                                   inexact exceptions */
96#endif
97  _CPU_Table = *cpu_table;
98}
99
100/*PAGE
101 *
102 *  _CPU_ISR_Get_level
103 *
104 *  This routine returns the current interrupt level.
105 */
106
107uint32_t   _CPU_ISR_Get_level( void )
108{
109  unsigned int sr;
110
111  mips_get_sr(sr);
112
113  /* printf("current sr=%08X, ",sr); */
114
115#if (__mips == 3) || (__mips == 32)
116/* IE bit and shift down hardware ints into bits 1 thru 6 */
117  sr = (sr & SR_IE) | ((sr & mips_interrupt_mask()) >> 9);
118
119#elif __mips == 1
120/* IEC bit and shift down hardware ints into bits 1 thru 6 */
121  sr = (sr & SR_IEC) | ((sr & mips_interrupt_mask()) >> 9);
122
123#else
124#error "CPU ISR level: unknown MIPS level for SR handling"
125#endif
126  return sr;
127}
128
129
130void _CPU_ISR_Set_level( uint32_t   new_level )
131{
132  unsigned int sr, srbits;
133
134  /*
135  ** mask off the int level bits only so we can
136  ** preserve software int settings and FP enable
137  ** for this thread.  Note we don't force software ints
138  ** enabled when changing level, they were turned on
139  ** when this task was created, but may have been turned
140  ** off since, so we'll just leave them alone.
141  */
142
143  new_level &= 0xff;
144
145  mips_get_sr(sr);
146
147#if (__mips == 3) || (__mips == 32)
148  mips_set_sr( (sr & ~SR_IE) );                 /* first disable ie bit (recommended) */
149
150   srbits = sr & ~(0xfc00 | SR_IE);
151
152   sr = srbits | ((new_level==0)? (mips_interrupt_mask() | SR_IE): \
153                 (((new_level<<9) & mips_interrupt_mask()) | \
154                   ((new_level & 1)?SR_IE:0)));
155/*
156  if ( (new_level & SR_EXL) == (sr & SR_EXL) )
157    return;
158
159  if ( (new_level & SR_EXL) == 0 ) {
160    sr &= ~SR_EXL;                    * clear the EXL bit *
161    mips_set_sr(sr);
162  } else {
163
164    sr |= SR_EXL|SR_IE;              * enable exception level *
165    mips_set_sr(sr);                 * first disable ie bit (recommended) *
166  }
167*/
168 
169#elif __mips == 1
170  mips_set_sr( (sr & ~SR_IEC) );
171  srbits = sr & ~(0xfc00 | SR_IEC);
172  sr = srbits | ((new_level==0)?0xfc01:( ((new_level<<9) & 0xfc00) | \
173                                         (new_level & SR_IEC)));
174#else
175#error "CPU ISR level: unknown MIPS level for SR handling"
176#endif
177  mips_set_sr( sr );
178}
179
180
181
182/*PAGE
183 *
184 *  _CPU_ISR_install_raw_handler
185 *
186 *  Input parameters:
187 *    vector      - interrupt vector number
188 *    old_handler - former ISR for this vector number
189 *    new_handler - replacement ISR for this vector number
190 *
191 *  Output parameters:  NONE
192 *
193 */
194 
195void _CPU_ISR_install_raw_handler(
196  uint32_t    vector,
197  proc_ptr    new_handler,
198  proc_ptr   *old_handler
199)
200{
201  /*
202   *  This is where we install the interrupt handler into the "raw" interrupt
203   *  table used by the CPU to dispatch interrupt handlers.
204   *
205   *  Because all interrupts are vectored through the same exception handler
206   *  this is not necessary on thi sport.
207   */
208}
209
210/*PAGE
211 *
212 *  _CPU_ISR_install_vector
213 *
214 *  This kernel routine installs the RTEMS handler for the
215 *  specified vector.
216 *
217 *  Input parameters:
218 *    vector      - interrupt vector number
219 *    old_handler - former ISR for this vector number
220 *    new_handler - replacement ISR for this vector number
221 *
222 *  Output parameters:  NONE
223 *
224 */
225
226void _CPU_ISR_install_vector(
227  uint32_t    vector,
228  proc_ptr    new_handler,
229  proc_ptr   *old_handler
230)
231{
232   *old_handler = _ISR_Vector_table[ vector ];
233
234   /*
235    *  If the interrupt vector table is a table of pointer to isr entry
236    *  points, then we need to install the appropriate RTEMS interrupt
237    *  handler for this vector number.
238    */
239
240   _CPU_ISR_install_raw_handler( vector, _ISR_Handler, old_handler );
241
242   /*
243    *  We put the actual user ISR address in '_ISR_vector_table'.  This will
244    *  be used by the _ISR_Handler so the user gets control.
245    */
246
247    _ISR_Vector_table[ vector ] = new_handler;
248}
249
250/*PAGE
251 *
252 *  _CPU_Install_interrupt_stack
253 */
254
255void _CPU_Install_interrupt_stack( void )
256{
257/* we don't support this yet */
258}
259
260/*PAGE
261 *
262 *  _CPU_Internal_threads_Idle_thread_body
263 *
264 *  NOTES:
265 *
266 *  1. This is the same as the regular CPU independent algorithm.
267 *
268 *  2. If you implement this using a "halt", "idle", or "shutdown"
269 *     instruction, then don't forget to put it in an infinite loop.
270 *
271 *  3. Be warned. Some processors with onboard DMA have been known
272 *     to stop the DMA if the CPU were put in IDLE mode.  This might
273 *     also be a problem with other on-chip peripherals.  So use this
274 *     hook with caution.
275 */
276
277void _CPU_Thread_Idle_body( void )
278{
279#if (__mips == 3) || (__mips == 32)
280   for( ; ; )
281     asm volatile("wait"); /* use wait to enter low power mode */
282#elif __mips == 1
283   for( ; ; )
284     ;
285#else
286#error "IDLE: __mips not set to 1 or 3"
287#endif
288}
Note: See TracBrowser for help on using the repository browser.