source: rtems/cpukit/score/cpu/sparc/cpu.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/*
2 *  SPARC Dependent Source
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <rtems/system.h>
17#include <rtems/score/isr.h>
18#include <rtems/rtems/cache.h>
19
20/*
21 *  This initializes the set of opcodes placed in each trap
22 *  table entry.  The routine which installs a handler is responsible
23 *  for filling in the fields for the _handler address and the _vector
24 *  trap type.
25 *
26 *  The constants following this structure are masks for the fields which
27 *  must be filled in when the handler is installed.
28 */
29
30const CPU_Trap_table_entry _CPU_Trap_slot_template = {
31  0xa1480000,      /* mov   %psr, %l0           */
32  0x29000000,      /* sethi %hi(_handler), %l4  */
33  0x81c52000,      /* jmp   %l4 + %lo(_handler) */
34  0xa6102000       /* mov   _vector, %l3        */
35};
36
37/*
38 *  _CPU_Initialize
39 *
40 *  This routine performs processor dependent initialization.
41 *
42 *  INPUT PARAMETERS: NONE
43 *
44 *  Output Parameters: NONE
45 *
46 *  NOTE: There is no need to save the pointer to the thread dispatch routine.
47 *        The SPARC's assembly code can reference it directly with no problems.
48 */
49
50void _CPU_Initialize(void)
51{
52#if (SPARC_HAS_FPU == 1)
53  Context_Control_fp *pointer;
54
55  /*
56   *  This seems to be the most appropriate way to obtain an initial
57   *  FP context on the SPARC.  The NULL fp context is copied it to
58   *  the task's FP context during Context_Initialize.
59   */
60
61  pointer = &_CPU_Null_fp_context;
62  _CPU_Context_save_fp( &pointer );
63#endif
64
65  /*
66   *  Since no tasks have been created yet and no interrupts have occurred,
67   *  there is no way that the currently executing thread can have an
68   *  _ISR_Dispatch stack frame on its stack.
69   */
70  _CPU_ISR_Dispatch_disable = 0;
71}
72
73/*
74 *  _CPU_ISR_Get_level
75 *
76 *  Input Parameters: NONE
77 *
78 *  Output Parameters:
79 *    returns the current interrupt level (PIL field of the PSR)
80 */
81
82uint32_t   _CPU_ISR_Get_level( void )
83{
84  uint32_t   level;
85
86  sparc_get_interrupt_level( level );
87
88  return level;
89}
90
91/*
92 *  _CPU_ISR_install_raw_handler
93 *
94 *  This routine installs the specified handler as a "raw" non-executive
95 *  supported trap handler (a.k.a. interrupt service routine).
96 *
97 *  Input Parameters:
98 *    vector      - trap table entry number plus synchronous
99 *                    vs. asynchronous information
100 *    new_handler - address of the handler to be installed
101 *    old_handler - pointer to an address of the handler previously installed
102 *
103 *  Output Parameters: NONE
104 *    *new_handler - address of the handler previously installed
105 *
106 *  NOTE:
107 *
108 *  On the SPARC, there are really only 256 vectors.  However, the executive
109 *  has no easy, fast, reliable way to determine which traps are synchronous
110 *  and which are asynchronous.  By default, synchronous traps return to the
111 *  instruction which caused the interrupt.  So if you install a software
112 *  trap handler as an executive interrupt handler (which is desirable since
113 *  RTEMS takes care of window and register issues), then the executive needs
114 *  to know that the return address is to the trap rather than the instruction
115 *  following the trap.
116 *
117 *  So vectors 0 through 255 are treated as regular asynchronous traps which
118 *  provide the "correct" return address.  Vectors 256 through 512 are assumed
119 *  by the executive to be synchronous and to require that the return address
120 *  be fudged.
121 *
122 *  If you use this mechanism to install a trap handler which must reexecute
123 *  the instruction which caused the trap, then it should be installed as
124 *  an asynchronous trap.  This will avoid the executive changing the return
125 *  address.
126 */
127
128void _CPU_ISR_install_raw_handler(
129  uint32_t    vector,
130  proc_ptr    new_handler,
131  proc_ptr   *old_handler
132)
133{
134  uint32_t               real_vector;
135  CPU_Trap_table_entry  *tbr;
136  CPU_Trap_table_entry  *slot;
137  uint32_t               u32_tbr;
138  uint32_t               u32_handler;
139
140  /*
141   *  Get the "real" trap number for this vector ignoring the synchronous
142   *  versus asynchronous indicator included with our vector numbers.
143   */
144
145  real_vector = SPARC_REAL_TRAP_NUMBER( vector );
146
147  /*
148   *  Get the current base address of the trap table and calculate a pointer
149   *  to the slot we are interested in.
150   */
151
152  sparc_get_tbr( u32_tbr );
153
154  u32_tbr &= 0xfffff000;
155
156  tbr = (CPU_Trap_table_entry *) u32_tbr;
157
158  slot = &tbr[ real_vector ];
159
160  /*
161   *  Get the address of the old_handler from the trap table.
162   *
163   *  NOTE: The old_handler returned will be bogus if it does not follow
164   *        the RTEMS model.
165   */
166
167#define HIGH_BITS_MASK   0xFFFFFC00
168#define HIGH_BITS_SHIFT  10
169#define LOW_BITS_MASK    0x000003FF
170
171  if ( slot->mov_psr_l0 == _CPU_Trap_slot_template.mov_psr_l0 ) {
172    u32_handler =
173      (slot->sethi_of_handler_to_l4 << HIGH_BITS_SHIFT) |
174      (slot->jmp_to_low_of_handler_plus_l4 & LOW_BITS_MASK);
175    *old_handler = (proc_ptr) u32_handler;
176  } else
177    *old_handler = 0;
178
179  /*
180   *  Copy the template to the slot and then fix it.
181   */
182
183  *slot = _CPU_Trap_slot_template;
184
185  u32_handler = (uint32_t) new_handler;
186
187  slot->mov_vector_l3 |= vector;
188  slot->sethi_of_handler_to_l4 |=
189    (u32_handler & HIGH_BITS_MASK) >> HIGH_BITS_SHIFT;
190  slot->jmp_to_low_of_handler_plus_l4 |= (u32_handler & LOW_BITS_MASK);
191
192  /* need to flush icache after this !!! */
193
194  rtems_cache_invalidate_entire_instruction();
195
196}
197
198/*
199 *  _CPU_ISR_install_vector
200 *
201 *  This kernel routine installs the RTEMS handler for the
202 *  specified vector.
203 *
204 *  Input parameters:
205 *    vector       - interrupt vector number
206 *    new_handler  - replacement ISR for this vector number
207 *    old_handler  - pointer to former ISR for this vector number
208 *
209 *  Output parameters:
210 *    *old_handler - former ISR for this vector number
211 *
212 */
213
214void _CPU_ISR_install_vector(
215  uint32_t    vector,
216  proc_ptr    new_handler,
217  proc_ptr   *old_handler
218)
219{
220   uint32_t   real_vector;
221   proc_ptr   ignored;
222
223  /*
224   *  Get the "real" trap number for this vector ignoring the synchronous
225   *  versus asynchronous indicator included with our vector numbers.
226   */
227
228   real_vector = SPARC_REAL_TRAP_NUMBER( vector );
229
230   /*
231    *  Return the previous ISR handler.
232    */
233
234   *old_handler = _ISR_Vector_table[ real_vector ];
235
236   /*
237    *  Install the wrapper so this ISR can be invoked properly.
238    */
239
240   _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
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[ real_vector ] = new_handler;
248}
249
250/*
251 *  _CPU_Context_Initialize
252 *
253 *  This kernel routine initializes the basic non-FP context area associated
254 *  with each thread.
255 *
256 *  Input parameters:
257 *    the_context  - pointer to the context area
258 *    stack_base   - address of memory for the SPARC
259 *    size         - size in bytes of the stack area
260 *    new_level    - interrupt level for this context area
261 *    entry_point  - the starting execution point for this this context
262 *    is_fp        - TRUE if this context is associated with an FP thread
263 *
264 *  Output parameters: NONE
265 */
266
267void _CPU_Context_Initialize(
268  Context_Control  *the_context,
269  uint32_t         *stack_base,
270  uint32_t          size,
271  uint32_t          new_level,
272  void             *entry_point,
273  bool              is_fp
274)
275{
276    uint32_t     stack_high;  /* highest "stack aligned" address */
277    uint32_t     tmp_psr;
278
279    /*
280     *  On CPUs with stacks which grow down (i.e. SPARC), we build the stack
281     *  based on the stack_high address.
282     */
283
284    stack_high = ((uint32_t)(stack_base) + size);
285    stack_high &= ~(CPU_STACK_ALIGNMENT - 1);
286
287    /*
288     *  See the README in this directory for a diagram of the stack.
289     */
290
291    the_context->o7    = ((uint32_t) entry_point) - 8;
292    the_context->o6_sp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE;
293    the_context->i6_fp = 0;
294
295    /*
296     *  Build the PSR for the task.  Most everything can be 0 and the
297     *  CWP is corrected during the context switch.
298     *
299     *  The EF bit determines if the floating point unit is available.
300     *  The FPU is ONLY enabled if the context is associated with an FP task
301     *  and this SPARC model has an FPU.
302     */
303
304    sparc_get_psr( tmp_psr );
305    tmp_psr &= ~SPARC_PSR_PIL_MASK;
306    tmp_psr |= (new_level << 8) & SPARC_PSR_PIL_MASK;
307    tmp_psr &= ~SPARC_PSR_EF_MASK;      /* disabled by default */
308
309#if (SPARC_HAS_FPU == 1)
310    /*
311     *  If this bit is not set, then a task gets a fault when it accesses
312     *  a floating point register.  This is a nice way to detect floating
313     *  point tasks which are not currently declared as such.
314     */
315
316    if ( is_fp )
317      tmp_psr |= SPARC_PSR_EF_MASK;
318#endif
319    the_context->psr = tmp_psr;
320
321  /*
322   *  Since THIS thread is being created, there is no way that THIS
323   *  thread can have an _ISR_Dispatch stack frame on its stack.
324   */
325    the_context->isr_dispatch_disable = 0;
326}
Note: See TracBrowser for help on using the repository browser.