1 /*
2 * UAE - The Un*x Amiga Emulator - CPU core
3 *
4 * Big endian memory access functions.
5 *
6 * Copyright 1996 Bernd Schmidt
7 *
8 * Adaptation to Hatari by Thomas Huth, Eero Tamminen
9 *
10 * This file is distributed under the GNU General Public License, version 2
11 * or at your option any later version. Read the file gpl.txt for details.
12 */
13
14 #ifndef UAE_MACCESS_H
15 #define UAE_MACCESS_H
16
17
18 /* Can the actual CPU access unaligned memory? */
19 #ifndef CPU_CAN_ACCESS_UNALIGNED
20 # if defined(__i386__) || defined(__x86_64__) || defined(__mc68020__) || \
21 defined(powerpc) || defined(__ppc__) || defined(__ppc64__)
22 # define CPU_CAN_ACCESS_UNALIGNED 1
23 # else
24 # define CPU_CAN_ACCESS_UNALIGNED 0
25 # endif
26 #endif
27
28 #define ALIGN_POINTER_TO32(p) ((~(unsigned long)(p)) & 3)
29
30 /* If the CPU can access unaligned memory, use these accelerated functions: */
31 #if CPU_CAN_ACCESS_UNALIGNED
32
33 #include <SDL_endian.h>
34
35
do_get_mem_long(void * a)36 static inline uae_u32 do_get_mem_long(void *a)
37 {
38 return SDL_SwapBE32(*(uae_u32 *)a);
39 }
40
do_get_mem_word(void * a)41 static inline uae_u16 do_get_mem_word(void *a)
42 {
43 return SDL_SwapBE16(*(uae_u16 *)a);
44 }
45
46
do_put_mem_long(void * a,uae_u32 v)47 static inline void do_put_mem_long(void *a, uae_u32 v)
48 {
49 *(uae_u32 *)a = SDL_SwapBE32(v);
50 }
51
do_put_mem_word(void * a,uae_u16 v)52 static inline void do_put_mem_word(void *a, uae_u16 v)
53 {
54 *(uae_u16 *)a = SDL_SwapBE16(v);
55 }
56
57
58 #else /* Cpu can not access unaligned memory: */
59
60
do_get_mem_long(void * a)61 static inline uae_u32 do_get_mem_long(void *a)
62 {
63 uae_u8 *b = (uae_u8 *)a;
64
65 return ((uae_u32)b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
66 }
67
do_get_mem_word(void * a)68 static inline uae_u16 do_get_mem_word(void *a)
69 {
70 uae_u8 *b = (uae_u8 *)a;
71
72 return (b[0] << 8) | b[1];
73 }
74
do_put_mem_long(void * a,uae_u32 v)75 static inline void do_put_mem_long(void *a, uae_u32 v)
76 {
77 uae_u8 *b = (uae_u8 *)a;
78
79 b[0] = v >> 24;
80 b[1] = v >> 16;
81 b[2] = v >> 8;
82 b[3] = v;
83 }
84
do_put_mem_word(void * a,uae_u16 v)85 static inline void do_put_mem_word(void *a, uae_u16 v)
86 {
87 uae_u8 *b = (uae_u8 *)a;
88
89 b[0] = v >> 8;
90 b[1] = v;
91 }
92
93
94 #endif /* CPU_CAN_ACCESS_UNALIGNED */
95
96
97 /* These are same for all architectures: */
98
do_get_mem_byte(uae_u8 * a)99 static inline uae_u8 do_get_mem_byte(uae_u8 *a)
100 {
101 return *a;
102 }
103
do_put_mem_byte(uae_u8 * a,uae_u8 v)104 static inline void do_put_mem_byte(uae_u8 *a, uae_u8 v)
105 {
106 *a = v;
107 }
108
109
110 #define call_mem_get_func(func, addr) ((*func)(addr))
111 #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
112
113
114 #endif /* UAE_MACCESS_H */
115