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 ****************************************************************************/
27 extern void system_reboot (void);
28 extern void system_init(void);
30 extern long cpu_frequency
;
38 bool detect_flashed_romimage(void);
39 bool detect_flashed_ramimage(void);
40 bool detect_original_firmware(void);
42 #if defined(HAVE_ADJUSTABLE_CPU_FREQ) \
43 && defined(ROCKBOX_HAS_LOGF) && (NUM_CORES == 1)
44 #define CPU_BOOST_LOGGING
47 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
49 extern struct spinlock boostctrl_spin
;
51 void cpu_boost_init(void);
52 #define FREQ cpu_frequency
53 void set_cpu_frequency(long frequency
);
54 #ifdef CPU_BOOST_LOGGING
55 char * cpu_boost_log_getlog_first(void);
56 char * cpu_boost_log_getlog_next(void);
57 int cpu_boost_log_getcount(void);
58 void cpu_boost_(bool on_off
, char* location
, int line
);
60 void cpu_boost(bool on_off
);
62 void cpu_idle_mode(bool on_off
);
63 int get_cpu_boost_counter(void);
66 #define set_cpu_frequency(frequency)
67 #define cpu_boost(on_off)
68 #define cpu_boost_id(on_off, id)
69 #define cpu_idle_mode(on_off)
70 #define get_cpu_boost_counter()
71 #define get_cpu_boost_tracker()
74 #ifdef CPU_BOOST_LOGGING
75 #define cpu_boost(on_off) cpu_boost_(on_off,__FILE__, __LINE__)
81 #define NULL ((void*)0)
85 #define MIN(a, b) (((a)<(b))?(a):(b))
89 #define MAX(a, b) (((a)>(b))?(a):(b))
92 /* return number of elements in array a */
93 #define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0]))
95 /* return p incremented by specified number of bytes */
96 #define SKIPBYTES(p, count) ((typeof (p))((char *)(p) + (count)))
98 #define P2_M1(p2) ((1 << (p2))-1)
100 /* align up or down to nearest 2^p2 */
101 #define ALIGN_DOWN_P2(n, p2) ((n) & ~P2_M1(p2))
102 #define ALIGN_UP_P2(n, p2) ALIGN_DOWN_P2((n) + P2_M1(p2),p2)
104 /* align up or down to nearest integer multiple of a */
105 #define ALIGN_DOWN(n, a) ((n)/(a)*(a))
106 #define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a)
108 /* live endianness conversion */
109 #ifdef ROCKBOX_LITTLE_ENDIAN
110 #define letoh16(x) (x)
111 #define letoh32(x) (x)
112 #define htole16(x) (x)
113 #define htole32(x) (x)
114 #define betoh16(x) swap16(x)
115 #define betoh32(x) swap32(x)
116 #define htobe16(x) swap16(x)
117 #define htobe32(x) swap32(x)
118 #define swap_odd_even_be32(x) (x)
119 #define swap_odd_even_le32(x) swap_odd_even32(x)
121 #define letoh16(x) swap16(x)
122 #define letoh32(x) swap32(x)
123 #define htole16(x) swap16(x)
124 #define htole32(x) swap32(x)
125 #define betoh16(x) (x)
126 #define betoh32(x) (x)
127 #define htobe16(x) (x)
128 #define htobe32(x) (x)
129 #define swap_odd_even_be32(x) swap_odd_even32(x)
130 #define swap_odd_even_le32(x) (x)
133 /* static endianness conversion */
134 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
135 ((unsigned short)(x) << 8)))
137 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
138 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
139 (((unsigned long)(x) & 0xff00ul) << 8) | \
140 ((unsigned long)(x) << 24)))
142 #ifdef ROCKBOX_LITTLE_ENDIAN
143 #define LE_TO_H16(x) (x)
144 #define LE_TO_H32(x) (x)
145 #define H_TO_LE16(x) (x)
146 #define H_TO_LE32(x) (x)
147 #define BE_TO_H16(x) SWAP_16(x)
148 #define BE_TO_H32(x) SWAP_32(x)
149 #define H_TO_BE16(x) SWAP_16(x)
150 #define H_TO_BE32(x) SWAP_32(x)
152 #define LE_TO_H16(x) SWAP_16(x)
153 #define LE_TO_H32(x) SWAP_32(x)
154 #define H_TO_LE16(x) SWAP_16(x)
155 #define H_TO_LE32(x) SWAP_32(x)
156 #define BE_TO_H16(x) (x)
157 #define BE_TO_H32(x) (x)
158 #define H_TO_BE16(x) (x)
159 #define H_TO_BE32(x) (x)
162 /* gcc 3.4 changed the format of the constraints */
163 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ > 3) || (__GNUC__ >= 4)
164 #define I_CONSTRAINT "I08"
166 #define I_CONSTRAINT "I"
169 /* Utilize the user break controller to catch invalid memory accesses. */
170 int system_memory_guard(int newmode
);
173 MEMGUARD_KEEP
= -1, /* don't change the mode; for reading */
174 MEMGUARD_NONE
= 0, /* catch nothing */
175 MEMGUARD_FLASH_WRITES
, /* catch writes to area 02 (flash ROM) */
176 MEMGUARD_ZERO_AREA
, /* catch all accesses to areas 00 and 01 */
181 #include "system-target.h"
182 #else /* SIMULATOR */
184 static inline uint16_t swap16(uint16_t value
)
186 result[15..8] = value[ 7..0];
187 result[ 7..0] = value[15..8];
190 return (value
>> 8) | (value
<< 8);
193 static inline uint32_t swap32(uint32_t value
)
195 result[31..24] = value[ 7.. 0];
196 result[23..16] = value[15.. 8];
197 result[15.. 8] = value[23..16];
198 result[ 7.. 0] = value[31..24];
201 uint32_t hi
= swap16(value
>> 16);
202 uint32_t lo
= swap16(value
& 0xffff);
203 return (lo
<< 16) | hi
;
206 static inline uint32_t swap_odd_even32(uint32_t value
)
209 result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
210 result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
212 uint32_t t
= value
& 0xff00ff00;
213 return (t
>> 8) | ((t
^ value
) << 8);
216 #endif /* !SIMULATOR */
218 /* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */
219 #ifndef DISABLE_INTERRUPTS
220 #define DISABLE_INTERRUPTS HIGHEST_IRQ_LEVEL
223 /* Just define these as empty if not declared */
224 #ifndef HAVE_INVALIDATE_ICACHE
225 #define invalidate_icache()
228 #ifndef HAVE_FLUSH_ICACHE
229 #define flush_icache()
232 #ifdef PROC_NEEDS_CACHEALIGN
233 /* Cache alignment attributes and sizes are enabled */
235 /* 2^CACHEALIGN_BITS = the byte size */
236 #define CACHEALIGN_SIZE (1u << CACHEALIGN_BITS)
238 #define CACHEALIGN_ATTR __attribute__((aligned(CACHEALIGN_SIZE)))
239 /* Aligns x up to a CACHEALIGN_SIZE boundary */
240 #define CACHEALIGN_UP(x) \
241 ((typeof (x))ALIGN_UP_P2((uintptr_t)(x), CACHEALIGN_BITS))
242 /* Aligns x down to a CACHEALIGN_SIZE boundary */
243 #define CACHEALIGN_DOWN(x) \
244 ((typeof (x))ALIGN_DOWN_P2((uintptr_t)(x), CACHEALIGN_BITS))
245 /* Aligns at least to the greater of size x or CACHEALIGN_SIZE */
246 #define CACHEALIGN_AT_LEAST_ATTR(x) \
247 __attribute__((aligned(CACHEALIGN_UP(x))))
248 /* Aligns a buffer pointer and size to proper boundaries */
249 #define CACHEALIGN_BUFFER(start, size) \
250 ({ align_buffer(PUN_PTR(void **, (start)), (size), CACHEALIGN_SIZE); })
252 #else /* ndef PROC_NEEDS_CACHEALIGN */
254 /* Cache alignment attributes and sizes are not enabled */
255 #define CACHEALIGN_ATTR
256 #define CACHEALIGN_AT_LEAST_ATTR(x) \
257 __attribute__((aligned(x)))
258 #define CACHEALIGN_UP(x) (x)
259 #define CACHEALIGN_DOWN(x) (x)
260 /* Make no adjustments */
261 #define CACHEALIGN_BUFFER(start, size) \
262 ({ (void)(start); (size); })
264 #endif /* PROC_NEEDS_CACHEALIGN */
266 /* Double-cast to avoid 'dereferencing type-punned pointer will
267 * break strict aliasing rules' B.S. */
268 #define PUN_PTR(type, p) ((type)(intptr_t)(p))
270 #endif /* __SYSTEM_H__ */