source: rtems/cpukit/score/cpu/sparc/rtems/score/sparc.h @ 6a1b9e4

5
Last change on this file since 6a1b9e4 was 6a1b9e4, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/16 at 09:13:27

sparc: Optimize _ISR_Handler()

Use _Thread_Do_dispatch() instead of _Thread_Dispatch(). Restore the
PSR[EF] state of the interrupted context via new system call
syscall_irqdis_fp in case floating-point support is enabled.

  • Property mode set to 100644
File size: 11.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Information Required to Build RTEMS for a Particular Member
5 * of the SPARC Family
6 *
7 * This file contains the information required to build
8 * RTEMS for a particular member of the SPARC family.  It does
9 * this by setting variables to indicate which implementation
10 * dependent features are present in a particular member
11 * of the family.
12 */
13
14/*
15 *  COPYRIGHT (c) 1989-2011.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 *  The license and distribution terms for this file may be
19 *  found in the file LICENSE in this distribution or at
20 *  http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _RTEMS_SCORE_SPARC_H
24#define _RTEMS_SCORE_SPARC_H
25
26#include <rtems/score/types.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/*
33 *
34 *  Currently recognized feature flags:
35 *
36 *    + SPARC_HAS_FPU
37 *        0 - no HW FPU
38 *        1 - has HW FPU (assumed to be compatible w/90C602)
39 *
40 *    + SPARC_HAS_BITSCAN
41 *        0 - does not have scan instructions
42 *        1 - has scan instruction  (not currently implemented)
43 *
44 *    + SPARC_NUMBER_OF_REGISTER_WINDOWS
45 *        8 is the most common number supported by SPARC implementations.
46 *        SPARC_PSR_CWP_MASK is derived from this value.
47 */
48
49/**
50 * Some higher end SPARCs have a bitscan instructions. It would
51 * be nice to take advantage of them.  Right now, there is no
52 * port to a CPU model with this feature and no (untested) code
53 * that is based on this feature flag.
54 */
55#define SPARC_HAS_BITSCAN                0
56
57/**
58 * This should be OK until a port to a higher end SPARC processor
59 * is made that has more than 8 register windows.  If this cannot
60 * be determined based on multilib settings (v7/v8/v9), then the
61 * cpu_asm.S code that depends on this will have to move to libcpu.
62 */
63#define SPARC_NUMBER_OF_REGISTER_WINDOWS 8
64
65/**
66 * This macro indicates whether this multilib variation has hardware
67 * floating point or not.  We use the gcc cpp predefine _SOFT_FLOAT
68 * to determine that.
69 */
70#if defined(_SOFT_FLOAT)
71  #define SPARC_HAS_FPU 0
72#else
73  #define SPARC_HAS_FPU 1
74#endif
75
76/**
77 * This macro contains a string describing the multilib variant being
78 * build.
79 */
80#if SPARC_HAS_FPU
81  #define CPU_MODEL_NAME "w/FPU"
82#else
83  #define CPU_MODEL_NAME "w/soft-float"
84#endif
85
86/**
87 * Define the name of the CPU family.
88 */
89#define CPU_NAME "SPARC"
90
91/*
92 *  Miscellaneous constants
93 */
94
95/**
96 * PSR masks and starting bit positions
97 *
98 * NOTE: Reserved bits are ignored.
99 */
100#if (SPARC_NUMBER_OF_REGISTER_WINDOWS == 8)
101  #define SPARC_PSR_CWP_MASK               0x07   /* bits  0 -  4 */
102#elif (SPARC_NUMBER_OF_REGISTER_WINDOWS == 16)
103  #define SPARC_PSR_CWP_MASK               0x0F   /* bits  0 -  4 */
104#elif (SPARC_NUMBER_OF_REGISTER_WINDOWS == 32)
105  #define SPARC_PSR_CWP_MASK               0x1F   /* bits  0 -  4 */
106#else
107  #error "Unsupported number of register windows for this cpu"
108#endif
109
110/** This constant is a mask for the ET bits in the PSR. */
111#define SPARC_PSR_ET_MASK   0x00000020   /* bit   5 */
112/** This constant is a mask for the PS bits in the PSR. */
113#define SPARC_PSR_PS_MASK   0x00000040   /* bit   6 */
114/** This constant is a mask for the S bits in the PSR. */
115#define SPARC_PSR_S_MASK    0x00000080   /* bit   7 */
116/** This constant is a mask for the PIL bits in the PSR. */
117#define SPARC_PSR_PIL_MASK  0x00000F00   /* bits  8 - 11 */
118/** This constant is a mask for the EF bits in the PSR. */
119#define SPARC_PSR_EF_MASK   0x00001000   /* bit  12 */
120/** This constant is a mask for the EC bits in the PSR. */
121#define SPARC_PSR_EC_MASK   0x00002000   /* bit  13 */
122/** This constant is a mask for the ICC bits in the PSR. */
123#define SPARC_PSR_ICC_MASK  0x00F00000   /* bits 20 - 23 */
124/** This constant is a mask for the VER bits in the PSR. */
125#define SPARC_PSR_VER_MASK  0x0F000000   /* bits 24 - 27 */
126/** This constant is a mask for the IMPL bits in the PSR. */
127#define SPARC_PSR_IMPL_MASK 0xF0000000   /* bits 28 - 31 */
128
129/** This constant is the starting bit position of the CWP in the PSR. */
130#define SPARC_PSR_CWP_BIT_POSITION   0   /* bits  0 -  4 */
131/** This constant is the starting bit position of the ET in the PSR. */
132#define SPARC_PSR_ET_BIT_POSITION    5   /* bit   5 */
133/** This constant is the starting bit position of the PS in the PSR. */
134#define SPARC_PSR_PS_BIT_POSITION    6   /* bit   6 */
135/** This constant is the starting bit position of the S in the PSR. */
136#define SPARC_PSR_S_BIT_POSITION     7   /* bit   7 */
137/** This constant is the starting bit position of the PIL in the PSR. */
138#define SPARC_PSR_PIL_BIT_POSITION   8   /* bits  8 - 11 */
139/** This constant is the starting bit position of the EF in the PSR. */
140#define SPARC_PSR_EF_BIT_POSITION   12   /* bit  12 */
141/** This constant is the starting bit position of the EC in the PSR. */
142#define SPARC_PSR_EC_BIT_POSITION   13   /* bit  13 */
143/** This constant is the starting bit position of the ICC in the PSR. */
144#define SPARC_PSR_ICC_BIT_POSITION  20   /* bits 20 - 23 */
145/** This constant is the starting bit position of the VER in the PSR. */
146#define SPARC_PSR_VER_BIT_POSITION  24   /* bits 24 - 27 */
147/** This constant is the starting bit position of the IMPL in the PSR. */
148#define SPARC_PSR_IMPL_BIT_POSITION 28   /* bits 28 - 31 */
149
150#define LEON3_ASR17_PROCESSOR_INDEX_SHIFT 28
151
152/* SPARC Software Trap number definitions */
153#define SPARC_SWTRAP_SYSCALL 0
154#define SPARC_SWTRAP_IRQDIS 9
155#define SPARC_SWTRAP_IRQEN 10
156#if SPARC_HAS_FPU == 1
157#define SPARC_SWTRAP_IRQDIS_FP 11
158#endif
159
160#ifndef ASM
161
162/**
163 * This macro is a standard nop instruction.
164 */
165#define nop() \
166  do { \
167    __asm__ volatile ( "nop" ); \
168  } while ( 0 )
169
170/**
171 * @brief Macro to obtain the PSR.
172 *
173 * This macro returns the current contents of the PSR register in @a _psr.
174 */
175#if defined(RTEMS_PARAVIRT)
176
177uint32_t _SPARC_Get_PSR( void );
178
179#define sparc_get_psr( _psr ) \
180  (_psr) = _SPARC_Get_PSR()
181
182#else /* RTEMS_PARAVIRT */
183
184#define sparc_get_psr( _psr ) \
185  do { \
186     (_psr) = 0; \
187     __asm__ volatile( "rd %%psr, %0" :  "=r" (_psr) : "0" (_psr) ); \
188  } while ( 0 )
189
190#endif /* RTEMS_PARAVIRT */
191
192/**
193 * @brief Macro to set the PSR.
194 *
195 * This macro sets the PSR register to the value in @a _psr.
196 */
197#if defined(RTEMS_PARAVIRT)
198
199void _SPARC_Set_PSR( uint32_t new_psr );
200
201#define sparc_set_psr( _psr ) \
202  _SPARC_Set_PSR( _psr )
203
204#else /* RTEMS_PARAVIRT */
205
206#define sparc_set_psr( _psr ) \
207  do { \
208    __asm__ volatile ( "mov  %0, %%psr " : "=r" ((_psr)) : "0" ((_psr)) ); \
209    nop(); \
210    nop(); \
211    nop(); \
212  } while ( 0 )
213
214#endif /* RTEMS_PARAVIRT */
215
216/**
217 * @brief Macro to obtain the TBR.
218 *
219 * This macro returns the current contents of the TBR register in @a _tbr.
220 */
221#if defined(RTEMS_PARAVIRT)
222
223uint32_t _SPARC_Get_TBR( void );
224
225#define sparc_get_tbr( _tbr ) \
226  (_tbr) = _SPARC_Get_TBR()
227
228#else /* RTEMS_PARAVIRT */
229
230#define sparc_get_tbr( _tbr ) \
231  do { \
232     (_tbr) = 0; /* to avoid unitialized warnings */ \
233     __asm__ volatile( "rd %%tbr, %0" :  "=r" (_tbr) : "0" (_tbr) ); \
234  } while ( 0 )
235
236#endif /* RTEMS_PARAVIRT */
237
238/**
239 * @brief Macro to set the TBR.
240 *
241 * This macro sets the TBR register to the value in @a _tbr.
242 */
243#if defined(RTEMS_PARAVIRT)
244
245void _SPARC_Set_TBR( uint32_t new_tbr );
246
247#define sparc_set_tbr( _tbr ) \
248  _SPARC_Set_TBR((_tbr))
249
250#else /* RTEMS_PARAVIRT */
251
252#define sparc_set_tbr( _tbr ) \
253  do { \
254     __asm__ volatile( "wr %0, 0, %%tbr" :  "=r" (_tbr) : "0" (_tbr) ); \
255  } while ( 0 )
256
257#endif /* RTEMS_PARAVIRT */
258
259/**
260 * @brief Macro to obtain the WIM.
261 *
262 * This macro returns the current contents of the WIM field in @a _wim.
263 */
264#define sparc_get_wim( _wim ) \
265  do { \
266    __asm__ volatile( "rd %%wim, %0" :  "=r" (_wim) : "0" (_wim) ); \
267  } while ( 0 )
268
269/**
270 * @brief Macro to set the WIM.
271 *
272 * This macro sets the WIM field to the value in @a _wim.
273 */
274#define sparc_set_wim( _wim ) \
275  do { \
276    __asm__ volatile( "wr %0, %%wim" :  "=r" (_wim) : "0" (_wim) ); \
277    nop(); \
278    nop(); \
279    nop(); \
280  } while ( 0 )
281
282/**
283 * @brief Macro to obtain the Y register.
284 *
285 * This macro returns the current contents of the Y register in @a _y.
286 */
287#define sparc_get_y( _y ) \
288  do { \
289    __asm__ volatile( "rd %%y, %0" :  "=r" (_y) : "0" (_y) ); \
290  } while ( 0 )
291
292/**
293 * @brief Macro to set the Y register.
294 *
295 * This macro sets the Y register to the value in @a _y.
296 */
297#define sparc_set_y( _y ) \
298  do { \
299    __asm__ volatile( "wr %0, %%y" :  "=r" (_y) : "0" (_y) ); \
300  } while ( 0 )
301
302/**
303 * @brief SPARC disable processor interrupts.
304 *
305 * This method is invoked to disable all maskable interrupts.
306 *
307 * @return This method returns the entire PSR contents.
308 */
309static inline uint32_t sparc_disable_interrupts(void)
310{
311  register uint32_t psr __asm__("g1"); /* return value of trap handler */
312  __asm__ volatile ( "ta %1\n\t" : "=r" (psr) : "i" (SPARC_SWTRAP_IRQDIS));
313  return psr;
314}
315
316/**
317 * @brief SPARC enable processor interrupts.
318 *
319 * This method is invoked to enable all maskable interrupts.
320 *
321 * @param[in] psr is the PSR returned by @ref sparc_disable_interrupts.
322 */
323static inline void sparc_enable_interrupts(uint32_t psr)
324{
325  register uint32_t _psr __asm__("g1") = psr; /* input to trap handler */
326
327  /*
328   * The trap instruction has a higher trap priority than the interrupts
329   * according to "The SPARC Architecture Manual: Version 8", Table 7-1
330   * "Exception and Interrupt Request Priority and tt Values".  Add a nop to
331   * prevent a trap instruction right after the interrupt enable trap.
332   */
333  __asm__ volatile ( "ta %0\nnop\n" :: "i" (SPARC_SWTRAP_IRQEN), "r" (_psr));
334}
335
336/**
337 * @brief SPARC exit through system call 1
338 *
339 * This method is invoked to go into system error halt. The optional
340 * arguments can be given to hypervisor, hardware debugger, simulator or
341 * similar.
342 *
343 * System error mode is entered when taking a trap when traps have been
344 * disabled. What happens when error mode is entered depends on the motherboard.
345 * In a typical development systems the CPU relingish control to the debugger,
346 * simulator, hypervisor or similar. The following steps are taken:
347 *
348 * 1. Going into system error mode by Software Trap 0
349 * 2. %g1=1 (syscall 1 - Exit)
350 * 3. %g2=Primary exit code
351 * 4. %g3=Secondary exit code. Dependends on %g2 exit type.
352 *
353 * This function never returns.
354 *
355 * @param[in] exitcode1 Primary exit code stored in CPU g2 register after exit
356 * @param[in] exitcode2 Primary exit code stored in CPU g3 register after exit
357 */
358void sparc_syscall_exit(uint32_t exitcode1, uint32_t exitcode2)
359  RTEMS_NO_RETURN;
360
361/**
362 * @brief SPARC flash processor interrupts.
363 *
364 * This method is invoked to temporarily enable all maskable interrupts.
365 *
366 * @param[in] _psr is the PSR returned by @ref sparc_disable_interrupts.
367 */
368#define sparc_flash_interrupts( _psr ) \
369  do { \
370    sparc_enable_interrupts( (_psr) ); \
371    _psr = sparc_disable_interrupts(); \
372  } while ( 0 )
373
374/**
375 * @brief SPARC obtain interrupt level.
376 *
377 * This method is invoked to obtain the current interrupt disable level.
378 *
379 * @param[in] _level is the PSR returned by @ref sparc_disable_interrupts.
380 */
381#define sparc_get_interrupt_level( _level ) \
382  do { \
383    register uint32_t   _psr_level = 0; \
384    \
385    sparc_get_psr( _psr_level ); \
386    (_level) = \
387      (_psr_level & SPARC_PSR_PIL_MASK) >> SPARC_PSR_PIL_BIT_POSITION; \
388  } while ( 0 )
389
390static inline uint32_t _LEON3_Get_current_processor( void )
391{
392  uint32_t asr17;
393
394  __asm__ volatile (
395    "rd %%asr17, %0"
396    : "=&r" (asr17)
397  );
398
399  return asr17 >> LEON3_ASR17_PROCESSOR_INDEX_SHIFT;
400}
401
402#endif
403
404#ifdef __cplusplus
405}
406#endif
407
408#endif /* _RTEMS_SCORE_SPARC_H */
Note: See TracBrowser for help on using the repository browser.