source: rtems/c/src/exec/score/cpu/mips/cpu.c @ e6dec71c

4.104.114.84.95
Last change on this file since e6dec71c was e6dec71c, checked in by Joel Sherrill <joel.sherrill@…>, on 02/01/02 at 15:00:30

2001-02-01 Greg Menke <gregory.menke@…>

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