RTEMS 6.1-rc5
Loading...
Searching...
No Matches
sparc.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
18/*
19 * COPYRIGHT (c) 1989-2011.
20 * On-Line Applications Research Corporation (OAR).
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
35 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
42 */
43
44#ifndef _RTEMS_SCORE_SPARC_H
45#define _RTEMS_SCORE_SPARC_H
46
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/*
54 *
55 * Currently recognized feature flags:
56 *
57 * + SPARC_HAS_FPU
58 * 0 - no HW FPU
59 * 1 - has HW FPU (assumed to be compatible w/90C602)
60 *
61 * + SPARC_HAS_BITSCAN
62 * 0 - does not have scan instructions
63 * 1 - has scan instruction (not currently implemented)
64 *
65 * + SPARC_NUMBER_OF_REGISTER_WINDOWS
66 * 8 is the most common number supported by SPARC implementations.
67 * SPARC_PSR_CWP_MASK is derived from this value.
68 */
69
76#define SPARC_HAS_BITSCAN 0
77
84#define SPARC_NUMBER_OF_REGISTER_WINDOWS 8
85
90#if defined(__FIX_LEON3FT_B2BST)
91 #define SPARC_LEON3FT_B2BST_NOP nop
92#else
93 #define SPARC_LEON3FT_B2BST_NOP
94#endif
95
101#if defined(_SOFT_FLOAT)
102 #define SPARC_HAS_FPU 0
103#else
104 #define SPARC_HAS_FPU 1
105#endif
106
111#if SPARC_HAS_FPU
112 #define CPU_MODEL_NAME "w/FPU"
113#else
114 #define CPU_MODEL_NAME "w/soft-float"
115#endif
116
120#define CPU_NAME "SPARC"
121
122/*
123 * Miscellaneous constants
124 */
125
131#if (SPARC_NUMBER_OF_REGISTER_WINDOWS == 8)
132 #define SPARC_PSR_CWP_MASK 0x07 /* bits 0 - 4 */
133#elif (SPARC_NUMBER_OF_REGISTER_WINDOWS == 16)
134 #define SPARC_PSR_CWP_MASK 0x0F /* bits 0 - 4 */
135#elif (SPARC_NUMBER_OF_REGISTER_WINDOWS == 32)
136 #define SPARC_PSR_CWP_MASK 0x1F /* bits 0 - 4 */
137#else
138 #error "Unsupported number of register windows for this cpu"
139#endif
140
142#define SPARC_PSR_ET_MASK 0x00000020 /* bit 5 */
144#define SPARC_PSR_PS_MASK 0x00000040 /* bit 6 */
146#define SPARC_PSR_S_MASK 0x00000080 /* bit 7 */
148#define SPARC_PSR_PIL_MASK 0x00000F00 /* bits 8 - 11 */
150#define SPARC_PSR_EF_MASK 0x00001000 /* bit 12 */
152#define SPARC_PSR_EC_MASK 0x00002000 /* bit 13 */
154#define SPARC_PSR_ICC_MASK 0x00F00000 /* bits 20 - 23 */
156#define SPARC_PSR_VER_MASK 0x0F000000 /* bits 24 - 27 */
158#define SPARC_PSR_IMPL_MASK 0xF0000000 /* bits 28 - 31 */
159
161#define SPARC_PSR_CWP_BIT_POSITION 0 /* bits 0 - 4 */
163#define SPARC_PSR_ET_BIT_POSITION 5 /* bit 5 */
165#define SPARC_PSR_PS_BIT_POSITION 6 /* bit 6 */
167#define SPARC_PSR_S_BIT_POSITION 7 /* bit 7 */
169#define SPARC_PSR_PIL_BIT_POSITION 8 /* bits 8 - 11 */
171#define SPARC_PSR_EF_BIT_POSITION 12 /* bit 12 */
173#define SPARC_PSR_EC_BIT_POSITION 13 /* bit 13 */
175#define SPARC_PSR_ICC_BIT_POSITION 20 /* bits 20 - 23 */
177#define SPARC_PSR_VER_BIT_POSITION 24 /* bits 24 - 27 */
179#define SPARC_PSR_IMPL_BIT_POSITION 28 /* bits 28 - 31 */
180
181#define LEON3_ASR17_PROCESSOR_INDEX_SHIFT 28
182
183/* SPARC Software Trap number definitions */
184#define SPARC_SWTRAP_SYSCALL 0
185#define SPARC_SWTRAP_IRQDIS 9
186#define SPARC_SWTRAP_IRQEN 10
187#if SPARC_HAS_FPU == 1
188#define SPARC_SWTRAP_IRQDIS_FP 11
189#endif
190
195#define SPARC_SYNCHRONOUS_TRAP_BIT_MASK 0x100
196
206#define SPARC_ASYNCHRONOUS_TRAP( _vector ) ( _vector )
207
217#define SPARC_SYNCHRONOUS_TRAP( _vector ) ( ( _vector ) + 256 )
218
228#define SPARC_REAL_TRAP_NUMBER( _trap ) ( ( _trap ) % 256 )
229
243#define SPARC_IS_INTERRUPT_TRAP( _trap ) \
244 ( SPARC_REAL_TRAP_NUMBER( _trap ) >= 0x11 && \
245 SPARC_REAL_TRAP_NUMBER( _trap ) <= 0x1f )
246
261#define SPARC_INTERRUPT_TRAP_TO_SOURCE( _trap ) \
262 ( SPARC_REAL_TRAP_NUMBER( _trap ) - 0x10 )
263
273#define SPARC_INTERRUPT_SOURCE_TO_TRAP( _source ) \
274 ( SPARC_ASYNCHRONOUS_TRAP( _source ) + 0x10 )
275
276#ifndef ASM
277
281#define nop() \
282 do { \
283 __asm__ volatile ( "nop" ); \
284 } while ( 0 )
285
291#if defined(RTEMS_PARAVIRT)
292
293uint32_t _SPARC_Get_PSR( void );
294
295#define sparc_get_psr( _psr ) \
296 (_psr) = _SPARC_Get_PSR()
297
298#else /* RTEMS_PARAVIRT */
299
300#define sparc_get_psr( _psr ) \
301 do { \
302 (_psr) = 0; \
303 __asm__ volatile( "rd %%psr, %0" : "=r" (_psr) : "0" (_psr) ); \
304 } while ( 0 )
305
306#endif /* RTEMS_PARAVIRT */
307
313#if defined(RTEMS_PARAVIRT)
314
315void _SPARC_Set_PSR( uint32_t new_psr );
316
317#define sparc_set_psr( _psr ) \
318 _SPARC_Set_PSR( _psr )
319
320#else /* RTEMS_PARAVIRT */
321
322#define sparc_set_psr( _psr ) \
323 do { \
324 __asm__ volatile ( "mov %0, %%psr " : "=r" ((_psr)) : "0" ((_psr)) ); \
325 nop(); \
326 nop(); \
327 nop(); \
328 } while ( 0 )
329
330#endif /* RTEMS_PARAVIRT */
331
337#if defined(RTEMS_PARAVIRT)
338
339uint32_t _SPARC_Get_TBR( void );
340
341#define sparc_get_tbr( _tbr ) \
342 (_tbr) = _SPARC_Get_TBR()
343
344#else /* RTEMS_PARAVIRT */
345
346#define sparc_get_tbr( _tbr ) \
347 do { \
348 (_tbr) = 0; /* to avoid unitialized warnings */ \
349 __asm__ volatile( "rd %%tbr, %0" : "=r" (_tbr) : "0" (_tbr) ); \
350 } while ( 0 )
351
352#endif /* RTEMS_PARAVIRT */
353
359#if defined(RTEMS_PARAVIRT)
360
361void _SPARC_Set_TBR( uint32_t new_tbr );
362
363#define sparc_set_tbr( _tbr ) \
364 _SPARC_Set_TBR((_tbr))
365
366#else /* RTEMS_PARAVIRT */
367
368#define sparc_set_tbr( _tbr ) \
369 do { \
370 __asm__ volatile( "wr %0, 0, %%tbr" : "=r" (_tbr) : "0" (_tbr) ); \
371 } while ( 0 )
372
373#endif /* RTEMS_PARAVIRT */
374
380#define sparc_get_wim( _wim ) \
381 do { \
382 __asm__ volatile( "rd %%wim, %0" : "=r" (_wim) : "0" (_wim) ); \
383 } while ( 0 )
384
390#define sparc_set_wim( _wim ) \
391 do { \
392 __asm__ volatile( "wr %0, %%wim" : "=r" (_wim) : "0" (_wim) ); \
393 nop(); \
394 nop(); \
395 nop(); \
396 } while ( 0 )
397
403#define sparc_get_y( _y ) \
404 do { \
405 __asm__ volatile( "rd %%y, %0" : "=r" (_y) : "0" (_y) ); \
406 } while ( 0 )
407
413#define sparc_set_y( _y ) \
414 do { \
415 __asm__ volatile( "wr %0, %%y" : "=r" (_y) : "0" (_y) ); \
416 } while ( 0 )
417
425static inline uint32_t sparc_disable_interrupts(void)
426{
427 register uint32_t psr __asm__("g1"); /* return value of trap handler */
428#ifdef __FIX_LEON3FT_TN0018
429 __asm__ volatile ( "ta %1\n\tnop\n\t" : "=r" (psr) : "i" (SPARC_SWTRAP_IRQDIS));
430#else
431 __asm__ volatile ( "ta %1\n\t" : "=r" (psr) : "i" (SPARC_SWTRAP_IRQDIS));
432#endif
433 return psr;
434}
435
443static inline void sparc_enable_interrupts(uint32_t psr)
444{
445 register uint32_t _psr __asm__("g1") = psr; /* input to trap handler */
446
447 /*
448 * The trap instruction has a higher trap priority than the interrupts
449 * according to "The SPARC Architecture Manual: Version 8", Table 7-1
450 * "Exception and Interrupt Request Priority and tt Values". Add a nop to
451 * prevent a trap instruction right after the interrupt enable trap.
452 */
453 __asm__ volatile ( "ta %0\nnop\n" :: "i" (SPARC_SWTRAP_IRQEN), "r" (_psr));
454}
455
479 uint32_t exitcode1,
480 uint32_t exitcode2
481);
482
490#define sparc_flash_interrupts( _psr ) \
491 do { \
492 sparc_enable_interrupts( (_psr) ); \
493 _psr = sparc_disable_interrupts(); \
494 } while ( 0 )
495
503#define sparc_get_interrupt_level( _level ) \
504 do { \
505 uint32_t _psr_level = 0; \
506 \
507 sparc_get_psr( _psr_level ); \
508 (_level) = \
509 (_psr_level & SPARC_PSR_PIL_MASK) >> SPARC_PSR_PIL_BIT_POSITION; \
510 } while ( 0 )
511
512static inline uint32_t _LEON3_Get_current_processor( void )
513{
514 uint32_t asr17;
515
516 __asm__ volatile (
517 "rd %%asr17, %0"
518 : "=&r" (asr17)
519 );
520
521 return asr17 >> LEON3_ASR17_PROCESSOR_INDEX_SHIFT;
522}
523
524#endif /* ASM */
525
526#ifdef __cplusplus
527}
528#endif
529
530#endif /* _RTEMS_SCORE_SPARC_H */
This header file provides basic definitions used by the API and the implementation.
#define RTEMS_NO_RETURN
Tells the compiler in a function declaration that this function does not return.
Definition: basedefs.h:386
RTEMS_NO_RETURN void sparc_syscall_exit(uint32_t exitcode1, uint32_t exitcode2)
SPARC exit through system call 1.