summaryrefslogtreecommitdiff
path: root/firmware/export/system.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/export/system.h')
-rw-r--r--firmware/export/system.h267
1 files changed, 267 insertions, 0 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h
new file mode 100644
index 0000000000..d5f1b4ba97
--- /dev/null
+++ b/firmware/export/system.h
@@ -0,0 +1,267 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __SYSTEM_H__
21#define __SYSTEM_H__
22
23#include "sh7034.h"
24#include "config.h"
25
26#define FREQ CPU_FREQ
27#define BAUDRATE 9600
28
29#ifndef NULL
30#define NULL ((void*)0)
31#endif
32
33#ifndef MIN
34#define MIN(a, b) (((a)<(b))?(a):(b))
35#endif
36
37#ifndef MAX
38#define MAX(a, b) (((a)>(b))?(a):(b))
39#endif
40
41#ifdef LITTLE_ENDIAN
42#define SWAB16(x) (x)
43#define SWAB32(x) (x)
44#endif
45
46#define nop \
47 asm volatile ("nop")
48
49#define __set_mask_constant(mask,address) \
50 asm \
51 ("or.b\t%0,@(r0,gbr)" \
52 : \
53 : /* %0 */ "I"((char)(mask)), \
54 /* %1 */ "z"(address-GBR))
55
56#define __clear_mask_constant(mask,address) \
57 asm \
58 ("and.b\t%0,@(r0,gbr)" \
59 : \
60 : /* %0 */ "I"((char)~(mask)), \
61 /* %1 */ "z"(address-GBR))
62
63#define __toggle_mask_constant(mask,address) \
64 asm \
65 ("xor.b\t%0,@(r0,gbr)" \
66 : \
67 : /* %0 */ "I"((char)(mask)), \
68 /* %1 */ "z"(address-GBR))
69
70#define __test_mask_constant(mask,address) \
71 ({ \
72 int result; \
73 asm \
74 ("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
75 : "=r"(result) \
76 : "I"((char)(mask)),"z"(address-GBR)); \
77 result; \
78 })
79
80#define __set_bit_constant(bit,address) \
81 asm \
82 ("or.b\t%0,@(r0,gbr)" \
83 : \
84 : /* %0 */ "I"((char)(1<<(bit))), \
85 /* %1 */ "z"(address-GBR))
86
87#define __clear_bit_constant(bit,address) \
88 asm \
89 ("and.b\t%0,@(r0,gbr)" \
90 : \
91 : /* %0 */ "I"((char)~(1<<(bit))), \
92 /* %1 */ "z"(address-GBR))
93
94#define __toggle_bit_constant(bit,address) \
95 asm \
96 ("xor.b\t%0,@(r0,gbr)" \
97 : \
98 : /* %0 */ "I"((char)(1<<(bit))), \
99 /* %1 */ "z"(address-GBR))
100
101#define __test_bit_constant(bit,address) \
102 ({ \
103 int result; \
104 asm \
105 ("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
106 : "=r"(result) \
107 : "I"((char)(1<<(bit))),"z"(address-GBR)); \
108 result; \
109 })
110
111#define __set_mask(mask,address) /* FIXME */
112#define __test_mask(mask,address) 0 /* FIXME */
113#define __clear_mask(mask,address) /* FIXME */
114#define __toggle_mask(mask,address) /* FIXME */
115
116#define __set_bit(bit,address) /* FIXME */
117#define __test_bit(bit,address) 0 /* FIXME */
118#define __clear_bit(bit,address) /* FIXME */
119#define __toggle_bit(bit,address) /* FIXME */
120
121#define set_mask(mask,address) \
122 if (__builtin_constant_p (mask)) \
123 __set_mask_constant (mask,address); \
124 else \
125 __set_mask (mask,address)
126
127#define clear_mask(mask,address) \
128 if (__builtin_constant_p (mask)) \
129 __clear_mask_constant (mask,address); \
130 else \
131 __clear_mask (mask,address)
132
133#define toggle_mask(mask,address) \
134 if (__builtin_constant_p (mask)) \
135 __toggle_mask_constant (mask,address); \
136 else \
137 __toggle_mask (mask,address)
138
139#define test_mask(mask,address) \
140 ( \
141 (__builtin_constant_p (mask)) \
142 ? (int)__test_mask_constant (mask,address) \
143 : (int)__test_mask (mask,address) \
144 )
145
146
147#define set_bit(bit,address) \
148 if (__builtin_constant_p (bit)) \
149 __set_bit_constant (bit,address); \
150 else \
151 __set_bit (bit,address)
152
153#define clear_bit(bit,address) \
154 if (__builtin_constant_p (bit)) \
155 __clear_bit_constant (bit,address); \
156 else \
157 __clear_bit (bit,address)
158
159#define toggle_bit(bit,address) \
160 if (__builtin_constant_p (bit)) \
161 __toggle_bit_constant (bit,address); \
162 else \
163 __toggle_bit (bit,address)
164
165#define test_bit(bit,address) \
166 ( \
167 (__builtin_constant_p (bit)) \
168 ? (int)__test_bit_constant (bit,address) \
169 : (int)__test_bit (bit,address) \
170 )
171
172
173extern char __swap_bit[256];
174
175#define swap_bit(byte) \
176 __swap_bit[byte]
177
178#ifndef SIMULATOR
179
180static inline short SWAB16(short value)
181 /*
182 result[15..8] = value[ 7..0];
183 result[ 7..0] = value[15..8];
184 */
185{
186 short result;
187 asm volatile ("swap.b\t%1,%0" : "=r"(result) : "r"(value));
188 return result;
189}
190
191static inline long SWAW32(long value)
192 /*
193 result[31..16] = value[15.. 0];
194 result[15.. 0] = value[31..16];
195 */
196{
197 long result;
198 asm volatile ("swap.w\t%1,%0" : "=r"(result) : "r"(value));
199 return result;
200}
201
202static inline long SWAB32(long value)
203 /*
204 result[31..24] = value[ 7.. 0];
205 result[23..16] = value[15.. 8];
206 result[15.. 8] = value[23..16];
207 result[ 7.. 0] = value[31..24];
208 */
209{
210 asm volatile ("swap.b\t%0,%0\n"
211 "swap.w\t%0,%0\n"
212 "swap.b\t%0,%0\n" : "+r"(value));
213 return value;
214}
215
216/* Test And Set - UNTESTED */
217static inline int tas (volatile int *pointer)
218 {
219 int result;
220 asm volatile ("tas.b\t@%1;movt\t%0" : "=t"(result) : "r"((char *)pointer) : "memory");
221 return result;
222 }
223
224static inline void sti (void)
225 {
226 asm volatile ("ldc\t%0,sr" : : "r"(0<<4));
227 }
228
229static inline void cli (void)
230 {
231 asm volatile ("ldc\t%0,sr" : : "r"(15<<4));
232 }
233
234/* Compare And Swap */
235static inline int cas (volatile int *pointer,int requested_value,int new_value)
236 {
237 cli();
238 if (*pointer == requested_value)
239 {
240 *pointer = new_value;
241 sti ();
242 return 1;
243 }
244 sti ();
245 return 0;
246 }
247
248static inline int cas2 (volatile int *pointer1,volatile int *pointer2,int requested_value1,int requested_value2,int new_value1,int new_value2)
249 {
250 cli();
251 if (*pointer1 == requested_value1 && *pointer2 == requested_value2)
252 {
253 *pointer1 = new_value1;
254 *pointer2 = new_value2;
255 sti ();
256 return 1;
257 }
258 sti ();
259 return 0;
260 }
261
262#endif
263
264extern void system_reboot (void);
265extern void system_init(void);
266
267#endif