source: rtems/c/src/lib/libcpu/sparc64/shared/score/cpu.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 *  SPARC-v9 Dependent Source
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  This file is based on the SPARC cpu.c file. Modifications are made to
8 *  provide support for the SPARC-v9.
9 *    COPYRIGHT (c) 2010. Gedare Bloom.
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#include <rtems/system.h>
17#include <rtems/asm.h>
18#include <rtems/score/isr.h>
19#include <rtems/rtems/cache.h>
20
21/*
22 *  This initializes the set of opcodes placed in each trap
23 *  table entry.  The routine which installs a handler is responsible
24 *  for filling in the fields for the _handler address and the _vector
25 *  trap type.
26 *
27 *  The constants following this structure are masks for the fields which
28 *  must be filled in when the handler is installed.
29 */
30
31/*  64-bit registers complicate this. Also, in sparc v9,
32 *      each trap level gets its own set of global registers, but
33 *      does not get its own dedicated register window. so we avoid
34 *      using the local registers in the trap handler.
35 */
36const CPU_Trap_table_entry _CPU_Trap_slot_template = {
37  0x89508000,   /* rdpr   %tstate, %g4       */
38  0x05000000,   /* sethi %hh(_handler), %g2  */
39  0x8410a000,   /* or     %g2, %hm(_handler), %g2 */
40  0x8528b020,   /* sllx   %g2, 32, %g2 */
41  0x07000000,   /* sethi  %hi(_handler), %g3 */
42  0x8610c002,   /* or     %g3, %g2, %g3 */
43  0x81c0e000, /* jmp   %g3 + %lo(_handler) */
44  0x84102000  /* mov   _vector, %g2        */
45};
46
47
48/*PAGE
49 *
50 *  _CPU_ISR_Get_level
51 *
52 *  Input Parameters: NONE
53 *
54 *  Output Parameters:
55 *    returns the current interrupt level (PIL field of the PSR)
56 */
57
58uint32_t   _CPU_ISR_Get_level( void )
59{
60  uint32_t   level;
61
62  sparc64_get_interrupt_level( level );
63
64  return level;
65}
66
67/*PAGE
68 *
69 *  _CPU_ISR_install_raw_handler
70 *
71 *  This routine installs the specified handler as a "raw" non-executive
72 *  supported trap handler (a.k.a. interrupt service routine).
73 *
74 *  Input Parameters:
75 *    vector      - trap table entry number plus synchronous
76 *                    vs. asynchronous information
77 *    new_handler - address of the handler to be installed
78 *    old_handler - pointer to an address of the handler previously installed
79 *
80 *  Output Parameters: NONE
81 *    *new_handler - address of the handler previously installed
82 *
83 *  NOTE:
84 *
85 *  On the SPARC v9, there are really only 512 vectors.  However, the executive
86 *  has no easy, fast, reliable way to determine which traps are synchronous
87 *  and which are asynchronous.  By default, traps return to the
88 *  instruction which caused the interrupt.  So if you install a software
89 *  trap handler as an executive interrupt handler (which is desirable since
90 *  RTEMS takes care of window and register issues), then the executive needs
91 *  to know that the return address is to the trap rather than the instruction
92 *  following the trap.
93 *
94 *  So vectors 0 through 511 are treated as regular asynchronous traps which
95 *  provide the "correct" return address.  Vectors 512 through 1023 are assumed
96 *  by the executive to be synchronous and to require that the return be to the
97 *  trapping instruction.
98 *
99 *  If you use this mechanism to install a trap handler which must reexecute
100 *  the instruction which caused the trap, then it should be installed as
101 *  a synchronous trap.  This will avoid the executive changing the return
102 *  address.
103 */
104/*  Verified this is working properly from sparc64_install_isr_entries */
105void _CPU_ISR_install_raw_handler(
106  uint32_t    vector,
107  proc_ptr    new_handler,
108  proc_ptr   *old_handler
109)
110{
111  uint32_t               real_vector;
112  CPU_Trap_table_entry  *tba;
113  CPU_Trap_table_entry  *slot;
114  uint64_t               u64_tba;
115  uint64_t               u64_handler;
116
117  /*
118   *  Get the "real" trap number for this vector ignoring the synchronous
119   *  versus asynchronous indicator included with our vector numbers.
120   */
121
122  real_vector = SPARC_REAL_TRAP_NUMBER( vector );
123
124  /*
125   *  Get the current base address of the trap table and calculate a pointer
126   *  to the slot we are interested in.
127   */
128
129  sparc64_get_tba( u64_tba );
130
131/*  u32_tbr &= 0xfffff000; */
132  u64_tba &= 0xffffffffffff8000;  /* keep only trap base address */
133
134  tba = (CPU_Trap_table_entry *) u64_tba;
135
136  /* use array indexing to fill in lower bits -- require
137   * CPU_Trap_table_entry to be full-sized. */
138  slot = &tba[ real_vector ];
139
140  /*
141   *  Get the address of the old_handler from the trap table.
142   *
143   *  NOTE: The old_handler returned will be bogus if it does not follow
144   *        the RTEMS model.
145   */
146
147  /* shift amount to shift of hi bits (31:10) */
148#define HI_BITS_SHIFT  10
149
150  /* shift amount of hm bits (41:32) */
151#define HM_BITS_SHIFT  32
152
153  /* shift amount of hh bits (63:42) */
154#define HH_BITS_SHIFT  42
155
156  /* We're only interested in bits 0-9 of the immediate field*/
157#define IMM_MASK    0x000003FF
158
159  if ( slot->rdpr_tstate_g4 == _CPU_Trap_slot_template.rdpr_tstate_g4 ) {
160    u64_handler =
161      (((uint64_t)((slot->sethi_of_hh_handler_to_g2 << HI_BITS_SHIFT) |
162      (slot->or_g2_hm_handler_to_g2 & IMM_MASK))) << HM_BITS_SHIFT) |
163      ((slot->sethi_of_handler_to_g3 << HI_BITS_SHIFT) |
164      (slot->jmp_to_low_of_handler_plus_g3 & IMM_MASK));
165    *old_handler = (proc_ptr) u64_handler;
166  } else
167    *old_handler = 0;
168
169  /*
170   *  Copy the template to the slot and then fix it.
171   */
172
173  *slot = _CPU_Trap_slot_template;
174
175  u64_handler = (uint64_t) new_handler;
176
177  /* mask for extracting %hh */
178#define HH_BITS_MASK   0xFFFFFC0000000000
179
180  /* mask for extracting %hm */
181#define HM_BITS_MASK   0x000003FF00000000
182
183  /* mask for extracting %hi */
184#define HI_BITS_MASK   0x00000000FFFFFC00
185
186  /* mask for extracting %lo */
187#define LO_BITS_MASK   0x00000000000003FF
188
189
190  slot->mov_vector_g2 |= vector;
191  slot->sethi_of_hh_handler_to_g2 |=
192    (u64_handler & HH_BITS_MASK) >> HH_BITS_SHIFT;
193  slot->or_g2_hm_handler_to_g2 |=
194    (u64_handler & HM_BITS_MASK) >> HM_BITS_SHIFT;
195  slot->sethi_of_handler_to_g3 |=
196    (u64_handler & HI_BITS_MASK) >> HI_BITS_SHIFT;
197  slot->jmp_to_low_of_handler_plus_g3 |= (u64_handler & LO_BITS_MASK);
198
199  /* need to flush icache after this !!! */
200
201  /* need to flush icache in case old trap handler is in cache */
202  rtems_cache_invalidate_entire_instruction();
203
204}
205
206/*PAGE
207 *
208 *  _CPU_ISR_install_vector
209 *
210 *  This kernel routine installs the RTEMS handler for the
211 *  specified vector.
212 *
213 *  Input parameters:
214 *    vector       - interrupt vector number
215 *    new_handler  - replacement ISR for this vector number
216 *    old_handler  - pointer to former ISR for this vector number
217 *
218 *  Output parameters:
219 *    *old_handler - former ISR for this vector number
220 *
221 */
222
223void _CPU_ISR_install_vector(
224  uint64_t    vector,
225  proc_ptr    new_handler,
226  proc_ptr   *old_handler
227)
228{
229   uint64_t   real_vector;
230   proc_ptr   ignored;
231
232  /*
233   *  Get the "real" trap number for this vector ignoring the synchronous
234   *  versus asynchronous indicator included with our vector numbers.
235   */
236   real_vector = SPARC_REAL_TRAP_NUMBER( vector );
237   /*
238    *  Return the previous ISR handler.
239    */
240
241   *old_handler = _ISR_Vector_table[ vector ];
242
243   /*
244    *  Install the wrapper so this ISR can be invoked properly.
245    */
246
247   _CPU_ISR_install_raw_handler( vector, _ISR_Handler, &ignored );
248
249   /*
250    *  We put the actual user ISR address in '_ISR_vector_table'.  This will
251    *  be used by the _ISR_Handler so the user gets control.
252    */
253
254    _ISR_Vector_table[ real_vector ] = new_handler;
255}
Note: See TracBrowser for help on using the repository browser.