2 * defines common to all virtual CPUs
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library 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. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* all CPU memory access use these macros */
24 static inline int ldub(void *ptr)
26 return *(uint8_t *)ptr;
29 static inline int ldsb(void *ptr)
31 return *(int8_t *)ptr;
34 static inline void stb(void *ptr, int v)
39 /* NOTE: on arm, putting 2 in /proc/sys/debug/alignment so that the
40 kernel handles unaligned load/stores may give better results, but
41 it is a system wide setting : bad */
42 #if defined(WORDS_BIGENDIAN) || defined(__arm__)
44 /* conservative code for little endian unaligned accesses */
45 static inline int lduw(void *ptr)
49 __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr));
53 return p[0] | (p[1] << 8);
57 static inline int ldsw(void *ptr)
61 __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr));
65 return (int16_t)(p[0] | (p[1] << 8));
69 static inline int ldl(void *ptr)
73 __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr));
77 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
81 static inline uint64_t ldq(void *ptr)
87 return v1 | ((uint64_t)v2 << 32);
90 static inline void stw(void *ptr, int v)
93 __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*(uint16_t *)ptr) : "r" (v), "r" (ptr));
101 static inline void stl(void *ptr, int v)
104 __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*(uint32_t *)ptr) : "r" (v), "r" (ptr));
114 static inline void stq(void *ptr, uint64_t v)
123 static inline float ldfl(void *ptr)
133 static inline void stfl(void *ptr, float v)
144 #if defined(__arm__) && !defined(WORDS_BIGENDIAN)
146 /* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
147 static inline double ldfq(void *ptr)
154 u.tab[0] = ldl(ptr + 4);
158 static inline void stfq(void *ptr, double v)
166 stl(ptr + 4, u.tab[0]);
170 static inline double ldfq(void *ptr)
180 static inline void stfq(void *ptr, double v)
193 static inline int lduw(void *ptr)
195 return *(uint16_t *)ptr;
198 static inline int ldsw(void *ptr)
200 return *(int16_t *)ptr;
203 static inline int ldl(void *ptr)
205 return *(uint32_t *)ptr;
208 static inline uint64_t ldq(void *ptr)
210 return *(uint64_t *)ptr;
213 static inline void stw(void *ptr, int v)
215 *(uint16_t *)ptr = v;
218 static inline void stl(void *ptr, int v)
220 *(uint32_t *)ptr = v;
223 static inline void stq(void *ptr, uint64_t v)
225 *(uint64_t *)ptr = v;
230 static inline float ldfl(void *ptr)
232 return *(float *)ptr;
235 static inline double ldfq(void *ptr)
237 return *(double *)ptr;
240 static inline void stfl(void *ptr, float v)
245 static inline void stfq(void *ptr, double v)
251 /* page related stuff */
253 #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
254 #define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
255 #define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
257 extern unsigned long real_host_page_size;
258 extern unsigned long host_page_bits;
259 extern unsigned long host_page_size;
260 extern unsigned long host_page_mask;
262 #define HOST_PAGE_ALIGN(addr) (((addr) + host_page_size - 1) & host_page_mask)
264 /* same as PROT_xxx */
265 #define PAGE_READ 0x0001
266 #define PAGE_WRITE 0x0002
267 #define PAGE_EXEC 0x0004
268 #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
269 #define PAGE_VALID 0x0008
270 /* original state of the write flag (used when tracking self-modifying
272 #define PAGE_WRITE_ORG 0x0010
274 void page_dump(FILE *f);
275 int page_get_flags(unsigned long address);
276 void page_set_flags(unsigned long start, unsigned long end, int flags);
277 void page_unprotect_range(uint8_t *data, unsigned long data_size);
279 #define SINGLE_CPU_DEFINES
280 #ifdef SINGLE_CPU_DEFINES
282 #if defined(TARGET_I386)
284 #define CPUState CPUX86State
285 #define cpu_init cpu_x86_init
286 #define cpu_exec cpu_x86_exec
287 #define cpu_gen_code cpu_x86_gen_code
288 #define cpu_interrupt cpu_x86_interrupt
289 #define cpu_signal_handler cpu_x86_signal_handler
291 #elif defined(TARGET_ARM)
293 #define CPUState CPUARMState
294 #define cpu_init cpu_arm_init
295 #define cpu_exec cpu_arm_exec
296 #define cpu_gen_code cpu_arm_gen_code
297 #define cpu_interrupt cpu_arm_interrupt
298 #define cpu_signal_handler cpu_arm_signal_handler
302 #error unsupported target CPU
306 #endif /* SINGLE_CPU_DEFINES */
308 #define DEFAULT_GDBSTUB_PORT 1234
310 void cpu_abort(CPUState *env, const char *fmt, ...);
311 extern CPUState *cpu_single_env;
313 #define CPU_INTERRUPT_EXIT 0x01 /* wants exit from main loop */
314 #define CPU_INTERRUPT_HARD 0x02 /* hardware interrupt pending */
315 void cpu_interrupt(CPUState *s, int mask);
317 int cpu_breakpoint_insert(CPUState *env, uint32_t pc);
318 int cpu_breakpoint_remove(CPUState *env, uint32_t pc);
319 void cpu_single_step(CPUState *env, int enabled);
323 typedef void CPUWriteMemoryFunc(uint32_t addr, uint32_t value);
324 typedef uint32_t CPUReadMemoryFunc(uint32_t addr);
326 void cpu_register_physical_memory(unsigned long start_addr, unsigned long size,
328 int cpu_register_io_memory(int io_index,
329 CPUReadMemoryFunc **mem_read,
330 CPUWriteMemoryFunc **mem_write);
333 extern int gdbstub_fd;
334 CPUState *cpu_gdbstub_get_env(void *opaque);
335 int cpu_gdbstub(void *opaque, int (*main_loop)(void *opaque), int port);
337 #endif /* CPU_ALL_H */