1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
26 #ifdef ARCHOS_RECORDER
27 # define FREQ 11059200
29 # define FREQ 12000000 /* cycle time ~83.3ns */
34 #define NULL ((void*)0)
38 #define MIN(a, b) (((a)<(b))?(a):(b))
42 #define MAX(a, b) (((a)>(b))?(a):(b))
53 #define __set_mask_constant(mask,address) \
55 ("or.b\t%0,@(r0,gbr)" \
57 : /* %0 */ "I"((char)(mask)), \
58 /* %1 */ "z"(address-GBR))
60 #define __clear_mask_constant(mask,address) \
62 ("and.b\t%0,@(r0,gbr)" \
64 : /* %0 */ "I"((char)~(mask)), \
65 /* %1 */ "z"(address-GBR))
67 #define __toggle_mask_constant(mask,address) \
69 ("xor.b\t%0,@(r0,gbr)" \
71 : /* %0 */ "I"((char)(mask)), \
72 /* %1 */ "z"(address-GBR))
74 #define __test_mask_constant(mask,address) \
78 ("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
80 : "I"((char)(mask)),"z"(address-GBR)); \
84 #define __set_bit_constant(bit,address) \
86 ("or.b\t%0,@(r0,gbr)" \
88 : /* %0 */ "I"((char)(1<<(bit))), \
89 /* %1 */ "z"(address-GBR))
91 #define __clear_bit_constant(bit,address) \
93 ("and.b\t%0,@(r0,gbr)" \
95 : /* %0 */ "I"((char)~(1<<(bit))), \
96 /* %1 */ "z"(address-GBR))
98 #define __toggle_bit_constant(bit,address) \
100 ("xor.b\t%0,@(r0,gbr)" \
102 : /* %0 */ "I"((char)(1<<(bit))), \
103 /* %1 */ "z"(address-GBR))
105 #define __test_bit_constant(bit,address) \
109 ("tst.b\t%1,@(r0,gbr)\n\tmovt\t%0" \
111 : "I"((char)(1<<(bit))),"z"(address-GBR)); \
115 #define __set_mask(mask,address) /* FIXME */
116 #define __test_mask(mask,address) 0 /* FIXME */
117 #define __clear_mask(mask,address) /* FIXME */
118 #define __toggle_mask(mask,address) /* FIXME */
120 #define __set_bit(bit,address) /* FIXME */
121 #define __test_bit(bit,address) 0 /* FIXME */
122 #define __clear_bit(bit,address) /* FIXME */
123 #define __toggle_bit(bit,address) /* FIXME */
125 #define set_mask(mask,address) \
126 if (__builtin_constant_p (mask)) \
127 __set_mask_constant (mask,address); \
129 __set_mask (mask,address)
131 #define clear_mask(mask,address) \
132 if (__builtin_constant_p (mask)) \
133 __clear_mask_constant (mask,address); \
135 __clear_mask (mask,address)
137 #define toggle_mask(mask,address) \
138 if (__builtin_constant_p (mask)) \
139 __toggle_mask_constant (mask,address); \
141 __toggle_mask (mask,address)
143 #define test_mask(mask,address) \
145 (__builtin_constant_p (mask)) \
146 ? (int)__test_mask_constant (mask,address) \
147 : (int)__test_mask (mask,address) \
151 #define set_bit(bit,address) \
152 if (__builtin_constant_p (bit)) \
153 __set_bit_constant (bit,address); \
155 __set_bit (bit,address)
157 #define clear_bit(bit,address) \
158 if (__builtin_constant_p (bit)) \
159 __clear_bit_constant (bit,address); \
161 __clear_bit (bit,address)
163 #define toggle_bit(bit,address) \
164 if (__builtin_constant_p (bit)) \
165 __toggle_bit_constant (bit,address); \
167 __toggle_bit (bit,address)
169 #define test_bit(bit,address) \
171 (__builtin_constant_p (bit)) \
172 ? (int)__test_bit_constant (bit,address) \
173 : (int)__test_bit (bit,address) \
177 extern char __swap_bit
[256];
179 #define swap_bit(byte) \
184 static inline short SWAB16(short value
)
186 result[15..8] = value[ 7..0];
187 result[ 7..0] = value[15..8];
191 asm volatile ("swap.b\t%1,%0" : "=r"(result
) : "r"(value
));
195 static inline long SWAW32(long value
)
197 result[31..16] = value[15.. 0];
198 result[15.. 0] = value[31..16];
202 asm volatile ("swap.w\t%1,%0" : "=r"(result
) : "r"(value
));
206 static inline long SWAB32(long value
)
208 result[31..24] = value[ 7.. 0];
209 result[23..16] = value[15.. 8];
210 result[15.. 8] = value[23..16];
211 result[ 7.. 0] = value[31..24];
214 asm volatile ("swap.b\t%0,%0\n"
216 "swap.b\t%0,%0\n" : "+r"(value
));
220 /* Test And Set - UNTESTED */
221 static inline int tas (volatile int *pointer
)
224 asm volatile ("tas.b\t@%1;movt\t%0" : "=t"(result
) : "r"((char *)pointer
) : "memory");
228 static inline void sti (void)
230 asm volatile ("ldc\t%0,sr" : : "r"(0<<4));
233 static inline void cli (void)
235 asm volatile ("ldc\t%0,sr" : : "r"(15<<4));
238 /* Compare And Swap */
239 static inline int cas (volatile int *pointer
,int requested_value
,int new_value
)
242 if (*pointer
== requested_value
)
244 *pointer
= new_value
;
252 static inline int cas2 (volatile int *pointer1
,volatile int *pointer2
,int requested_value1
,int requested_value2
,int new_value1
,int new_value2
)
255 if (*pointer1
== requested_value1
&& *pointer2
== requested_value2
)
257 *pointer1
= new_value1
;
258 *pointer2
= new_value2
;
268 extern void system_reboot (void);
269 extern void system_init(void);