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
48 #define FREQ cpu_frequency
49 void set_cpu_frequency(long frequency
);
50 #ifdef CPU_BOOST_LOGGING
51 char * cpu_boost_log_getlog_first(void);
52 char * cpu_boost_log_getlog_next(void);
53 int cpu_boost_log_getcount(void);
54 void cpu_boost_(bool on_off
, char* location
, int line
);
56 void cpu_boost(bool on_off
);
58 void cpu_idle_mode(bool on_off
);
59 int get_cpu_boost_counter(void);
62 #define set_cpu_frequency(frequency)
63 #define cpu_boost(on_off)
64 #define cpu_boost_id(on_off, id)
65 #define cpu_idle_mode(on_off)
66 #define get_cpu_boost_counter()
67 #define get_cpu_boost_tracker()
70 #ifdef CPU_BOOST_LOGGING
71 #define cpu_boost(on_off) cpu_boost_(on_off,__FILE__, __LINE__)
77 #define NULL ((void*)0)
81 #define MIN(a, b) (((a)<(b))?(a):(b))
85 #define MAX(a, b) (((a)>(b))?(a):(b))
88 /* return number of elements in array a */
89 #define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0]))
91 /* return p incremented by specified number of bytes */
92 #define SKIPBYTES(p, count) ((typeof (p))((char *)(p) + (count)))
94 #define P2_M1(p2) ((1 << (p2))-1)
96 /* align up or down to nearest 2^p2 */
97 #define ALIGN_DOWN_P2(n, p2) ((n) & ~P2_M1(p2))
98 #define ALIGN_UP_P2(n, p2) ALIGN_DOWN_P2((n) + P2_M1(p2),p2)
100 /* align up or down to nearest integer multiple of a */
101 #define ALIGN_DOWN(n, a) ((n)/(a)*(a))
102 #define ALIGN_UP(n, a) ALIGN_DOWN((n)+((a)-1),a)
104 /* live endianness conversion */
105 #ifdef ROCKBOX_LITTLE_ENDIAN
106 #define letoh16(x) (x)
107 #define letoh32(x) (x)
108 #define htole16(x) (x)
109 #define htole32(x) (x)
110 #define betoh16(x) swap16(x)
111 #define betoh32(x) swap32(x)
112 #define htobe16(x) swap16(x)
113 #define htobe32(x) swap32(x)
114 #define swap_odd_even_be32(x) (x)
115 #define swap_odd_even_le32(x) swap_odd_even32(x)
117 #define letoh16(x) swap16(x)
118 #define letoh32(x) swap32(x)
119 #define htole16(x) swap16(x)
120 #define htole32(x) swap32(x)
121 #define betoh16(x) (x)
122 #define betoh32(x) (x)
123 #define htobe16(x) (x)
124 #define htobe32(x) (x)
125 #define swap_odd_even_be32(x) swap_odd_even32(x)
126 #define swap_odd_even_le32(x) (x)
129 /* static endianness conversion */
130 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
131 ((unsigned short)(x) << 8)))
133 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
134 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
135 (((unsigned long)(x) & 0xff00ul) << 8) | \
136 ((unsigned long)(x) << 24)))
138 #ifdef ROCKBOX_LITTLE_ENDIAN
139 #define LE_TO_H16(x) (x)
140 #define LE_TO_H32(x) (x)
141 #define H_TO_LE16(x) (x)
142 #define H_TO_LE32(x) (x)
143 #define BE_TO_H16(x) SWAP_16(x)
144 #define BE_TO_H32(x) SWAP_32(x)
145 #define H_TO_BE16(x) SWAP_16(x)
146 #define H_TO_BE32(x) SWAP_32(x)
148 #define LE_TO_H16(x) SWAP_16(x)
149 #define LE_TO_H32(x) SWAP_32(x)
150 #define H_TO_LE16(x) SWAP_16(x)
151 #define H_TO_LE32(x) SWAP_32(x)
152 #define BE_TO_H16(x) (x)
153 #define BE_TO_H32(x) (x)
154 #define H_TO_BE16(x) (x)
155 #define H_TO_BE32(x) (x)
158 /* gcc 3.4 changed the format of the constraints */
159 #if (__GNUC__ >= 3) && (__GNUC_MINOR__ > 3) || (__GNUC__ >= 4)
160 #define I_CONSTRAINT "I08"
162 #define I_CONSTRAINT "I"
165 /* Utilize the user break controller to catch invalid memory accesses. */
166 int system_memory_guard(int newmode
);
169 MEMGUARD_KEEP
= -1, /* don't change the mode; for reading */
170 MEMGUARD_NONE
= 0, /* catch nothing */
171 MEMGUARD_FLASH_WRITES
, /* catch writes to area 02 (flash ROM) */
172 MEMGUARD_ZERO_AREA
, /* catch all accesses to areas 00 and 01 */
177 #include "system-target.h"
178 #else /* SIMULATOR */
180 static inline uint16_t swap16(uint16_t value
)
182 result[15..8] = value[ 7..0];
183 result[ 7..0] = value[15..8];
186 return (value
>> 8) | (value
<< 8);
189 static inline uint32_t swap32(uint32_t value
)
191 result[31..24] = value[ 7.. 0];
192 result[23..16] = value[15.. 8];
193 result[15.. 8] = value[23..16];
194 result[ 7.. 0] = value[31..24];
197 uint32_t hi
= swap16(value
>> 16);
198 uint32_t lo
= swap16(value
& 0xffff);
199 return (lo
<< 16) | hi
;
202 static inline uint32_t swap_odd_even32(uint32_t value
)
205 result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
206 result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
208 uint32_t t
= value
& 0xff00ff00;
209 return (t
>> 8) | ((t
^ value
) << 8);
212 #endif /* !SIMULATOR */
214 /* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */
215 #ifndef DISABLE_INTERRUPTS
216 #define DISABLE_INTERRUPTS HIGHEST_IRQ_LEVEL
219 /* Just define these as empty if not declared */
220 #ifndef HAVE_INVALIDATE_ICACHE
221 #define invalidate_icache()
224 #ifndef HAVE_FLUSH_ICACHE
225 #define flush_icache()
228 #endif /* __SYSTEM_H__ */