1 | /* sh.h |
---|
2 | * |
---|
3 | * This include file contains information pertaining to the Hitachi SH |
---|
4 | * processor. |
---|
5 | * |
---|
6 | * Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and |
---|
7 | * Bernd Becker (becker@faw.uni-ulm.de) |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1997-1998, FAW Ulm, Germany |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE |
---|
14 | * |
---|
15 | * |
---|
16 | * COPYRIGHT (c) 1998. |
---|
17 | * On-Line Applications Research Corporation (OAR). |
---|
18 | * Copyright assigned to U.S. Government, 1994. |
---|
19 | * |
---|
20 | * The license and distribution terms for this file may be |
---|
21 | * found in the file LICENSE in this distribution or at |
---|
22 | * http://www.OARcorp.com/rtems/license.html. |
---|
23 | * |
---|
24 | * $Id$ |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef _sh_h |
---|
28 | #define _sh_h |
---|
29 | |
---|
30 | #ifdef __cplusplus |
---|
31 | extern "C" { |
---|
32 | #endif |
---|
33 | |
---|
34 | /* |
---|
35 | * This file contains the information required to build |
---|
36 | * RTEMS for a particular member of the "SH" family. |
---|
37 | * |
---|
38 | * It does this by setting variables to indicate which implementation |
---|
39 | * dependent features are present in a particular member of the family. |
---|
40 | */ |
---|
41 | |
---|
42 | /* |
---|
43 | * Figure out all CPU Model Feature Flags based upon compiler |
---|
44 | * predefines. |
---|
45 | */ |
---|
46 | |
---|
47 | #if defined(__SH3E__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) |
---|
48 | |
---|
49 | /* |
---|
50 | * Define this if you want to use XD-registers. |
---|
51 | * Then this registers will be saved/restored on context switch. |
---|
52 | * ! They will not be saved/restored on interrupts! |
---|
53 | */ |
---|
54 | #define SH4_USE_X_REGISTERS 0 |
---|
55 | |
---|
56 | #if defined(__LITTLE_ENDIAN__) |
---|
57 | #define SH_HAS_FPU 1 |
---|
58 | #else |
---|
59 | /* FIXME: Context_Control_fp does not support big endian */ |
---|
60 | #warning FPU not supported |
---|
61 | #define SH_HAS_FPU 0 |
---|
62 | #endif |
---|
63 | |
---|
64 | #elif defined(__sh1__) || defined(__sh2__) || defined(__sh3__) |
---|
65 | #define SH_HAS_FPU 0 |
---|
66 | #else |
---|
67 | #warning Cannot detect FPU support, assuming no FPU |
---|
68 | #define SH_HAS_FPU 0 |
---|
69 | #endif |
---|
70 | |
---|
71 | /* this should not be here */ |
---|
72 | #ifndef CPU_MODEL_NAME |
---|
73 | #define CPU_MODEL_NAME "SH-Multilib" |
---|
74 | #endif |
---|
75 | |
---|
76 | /* |
---|
77 | * If the following macro is set to 0 there will be no software irq stack |
---|
78 | */ |
---|
79 | |
---|
80 | #ifndef SH_HAS_SEPARATE_STACKS |
---|
81 | #define SH_HAS_SEPARATE_STACKS 1 |
---|
82 | #endif |
---|
83 | |
---|
84 | /* |
---|
85 | * Define the name of the CPU family. |
---|
86 | */ |
---|
87 | |
---|
88 | #define CPU_NAME "Hitachi SH" |
---|
89 | |
---|
90 | #ifndef ASM |
---|
91 | |
---|
92 | #if defined(__sh1__) || defined(__sh2__) |
---|
93 | |
---|
94 | /* |
---|
95 | * Mask for disabling interrupts |
---|
96 | */ |
---|
97 | #define SH_IRQDIS_VALUE 0xf0 |
---|
98 | |
---|
99 | #define sh_disable_interrupts( _level ) \ |
---|
100 | asm volatile ( \ |
---|
101 | "stc sr,%0\n\t" \ |
---|
102 | "ldc %1,sr\n\t"\ |
---|
103 | : "=&r" (_level ) \ |
---|
104 | : "r" (SH_IRQDIS_VALUE) ); |
---|
105 | |
---|
106 | #define sh_enable_interrupts( _level ) \ |
---|
107 | asm volatile( "ldc %0,sr\n\t" \ |
---|
108 | "nop\n\t" \ |
---|
109 | :: "r" (_level) ); |
---|
110 | |
---|
111 | /* |
---|
112 | * This temporarily restores the interrupt to _level before immediately |
---|
113 | * disabling them again. This is used to divide long RTEMS critical |
---|
114 | * sections into two or more parts. The parameter _level is not |
---|
115 | * modified. |
---|
116 | */ |
---|
117 | |
---|
118 | #define sh_flash_interrupts( _level ) \ |
---|
119 | asm volatile( \ |
---|
120 | "ldc %1,sr\n\t" \ |
---|
121 | "nop\n\t" \ |
---|
122 | "ldc %0,sr\n\t" \ |
---|
123 | "nop\n\t" \ |
---|
124 | : : "r" (SH_IRQDIS_VALUE), "r" (_level) ); |
---|
125 | |
---|
126 | #else |
---|
127 | |
---|
128 | #define SH_IRQDIS_MASK 0xf0 |
---|
129 | |
---|
130 | #define sh_disable_interrupts( _level ) \ |
---|
131 | asm volatile ( \ |
---|
132 | "stc sr,%0\n\t" \ |
---|
133 | "mov %0,r5\n\t" \ |
---|
134 | "or %1,r5\n\t" \ |
---|
135 | "ldc r5,sr\n\t"\ |
---|
136 | : "=&r" (_level ) \ |
---|
137 | : "r" (SH_IRQDIS_MASK) \ |
---|
138 | : "r5" ); |
---|
139 | |
---|
140 | #define sh_enable_interrupts( _level ) \ |
---|
141 | asm volatile( "ldc %0,sr\n\t" \ |
---|
142 | "nop\n\t" \ |
---|
143 | :: "r" (_level) ); |
---|
144 | |
---|
145 | /* |
---|
146 | * This temporarily restores the interrupt to _level before immediately |
---|
147 | * disabling them again. This is used to divide long RTEMS critical |
---|
148 | * sections into two or more parts. The parameter _level is not |
---|
149 | * modified. |
---|
150 | */ |
---|
151 | |
---|
152 | #define sh_flash_interrupts( _level ) \ |
---|
153 | asm volatile( \ |
---|
154 | "stc sr,r5\n\t" \ |
---|
155 | "ldc %1,sr\n\t" \ |
---|
156 | "nop\n\t" \ |
---|
157 | "or %0,r5\n\t" \ |
---|
158 | "ldc r5,sr\n\t" \ |
---|
159 | "nop\n\t" \ |
---|
160 | : : "r" (SH_IRQDIS_MASK), "r" (_level) : "r5"); |
---|
161 | |
---|
162 | #endif |
---|
163 | |
---|
164 | #define sh_get_interrupt_level( _level ) \ |
---|
165 | { \ |
---|
166 | register unsigned32 _tmpsr ; \ |
---|
167 | \ |
---|
168 | asm volatile( "stc sr, %0" : "=r" (_tmpsr) ); \ |
---|
169 | _level = (_tmpsr & 0xf0) >> 4 ; \ |
---|
170 | } |
---|
171 | |
---|
172 | #define sh_set_interrupt_level( _newlevel ) \ |
---|
173 | { \ |
---|
174 | register unsigned32 _tmpsr; \ |
---|
175 | \ |
---|
176 | asm volatile ( "stc sr, %0" : "=r" (_tmpsr) ); \ |
---|
177 | _tmpsr = ( _tmpsr & ~0xf0 ) | ((_newlevel) << 4) ; \ |
---|
178 | asm volatile( "ldc %0,sr" :: "r" (_tmpsr) ); \ |
---|
179 | } |
---|
180 | |
---|
181 | /* |
---|
182 | * The following routine swaps the endian format of an unsigned int. |
---|
183 | * It must be static because it is referenced indirectly. |
---|
184 | */ |
---|
185 | |
---|
186 | static inline unsigned int sh_swap_u32( |
---|
187 | unsigned int value |
---|
188 | ) |
---|
189 | { |
---|
190 | register unsigned int swapped; |
---|
191 | |
---|
192 | asm volatile ( |
---|
193 | "swap.b %1,%0; " |
---|
194 | "swap.w %0,%0; " |
---|
195 | "swap.b %0,%0" |
---|
196 | : "=r" (swapped) |
---|
197 | : "r" (value) ); |
---|
198 | |
---|
199 | return( swapped ); |
---|
200 | } |
---|
201 | |
---|
202 | static inline unsigned int sh_swap_u16( |
---|
203 | unsigned int value |
---|
204 | ) |
---|
205 | { |
---|
206 | register unsigned int swapped ; |
---|
207 | |
---|
208 | asm volatile ( "swap.b %1,%0" : "=r" (swapped) : "r" (value) ); |
---|
209 | |
---|
210 | return( swapped ); |
---|
211 | } |
---|
212 | |
---|
213 | #define CPU_swap_u32( value ) sh_swap_u32( value ) |
---|
214 | #define CPU_swap_u16( value ) sh_swap_u16( value ) |
---|
215 | |
---|
216 | extern unsigned int sh_set_irq_priority( |
---|
217 | unsigned int irq, |
---|
218 | unsigned int prio ); |
---|
219 | |
---|
220 | #endif /* !ASM */ |
---|
221 | |
---|
222 | #ifdef __cplusplus |
---|
223 | } |
---|
224 | #endif |
---|
225 | |
---|
226 | #endif |
---|