ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
(Generate patch)

Comparing SheepShaver/src/Unix/sysdeps.h (file contents):
Revision 1.4 by gbeauche, 2003-05-22T22:12:05Z vs.
Revision 1.7 by gbeauche, 2003-09-29T15:46:07Z

# Line 59 | Line 59
59   # endif
60   #endif
61  
62 + // Define for external components
63 + #define SHEEPSHAVER 1
64 +
65   // Mac and host address space are the same
66   #define REAL_ADDRESSING 1
67  
68 < // Are we using a PPC emulator or the real thing?
69 < #ifdef __powerpc__
70 < #define EMULATED_PPC 0
68 > #define POWERPC_ROM 1
69 >
70 > #if EMULATED_PPC
71 > // Handle interrupts asynchronously?
72 > #define ASYNC_IRQ 0
73 > // Mac ROM is write protected when banked memory is used
74 > #if REAL_ADDRESSING || DIRECT_ADDRESSING
75 > # define ROM_IS_WRITE_PROTECTED 0
76 > # define USE_SCRATCHMEM_SUBTERFUGE 1
77   #else
78 < #define EMULATED_PPC 1
78 > # define ROM_IS_WRITE_PROTECTED 1
79 > #endif
80 > #else
81 > // Mac ROM is write protected
82 > #define ROM_IS_WRITE_PROTECTED 1
83 > #define USE_SCRATCHMEM_SUBTERFUGE 0
84   #endif
71
72 #define POWERPC_ROM 1
85  
86   // Data types
87   typedef unsigned char uint8;
# Line 115 | Line 127 | typedef int64 intptr;
127   #error "Unsupported size of pointer"
128   #endif
129  
130 + // Helper functions to byteswap data
131 + #ifdef HAVE_BYTESWAP_H
132 + #include <byteswap.h>
133 + #endif
134 +
135 + #ifndef bswap_16
136 + #define bswap_16 generic_bswap_16
137 + #endif
138 +
139 + static inline uint16 generic_bswap_16(uint16 x)
140 + {
141 +  return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
142 + }
143 +
144 + #ifndef bswap_32
145 + #define bswap_32 generic_bswap_32
146 + #endif
147 +
148 + static inline uint32 generic_bswap_32(uint32 x)
149 + {
150 +  return (((x & 0xff000000) >> 24) |
151 +                  ((x & 0x00ff0000) >>  8) |
152 +                  ((x & 0x0000ff00) <<  8) |
153 +                  ((x & 0x000000ff) << 24) );
154 + }
155 +
156 + #ifndef bswap_64
157 + #define bswap_64 generic_bswap_64
158 + #endif
159 +
160 + static inline uint64 generic_bswap_64(uint64 x)
161 + {
162 +  return (((x & UVAL64(0xff00000000000000)) >> 56) |
163 +                  ((x & UVAL64(0x00ff000000000000)) >> 40) |
164 +                  ((x & UVAL64(0x0000ff0000000000)) >> 24) |
165 +                  ((x & UVAL64(0x000000ff00000000)) >>  8) |
166 +                  ((x & UVAL64(0x00000000ff000000)) <<  8) |
167 +                  ((x & UVAL64(0x0000000000ff0000)) << 24) |
168 +                  ((x & UVAL64(0x000000000000ff00)) << 40) |
169 +                  ((x & UVAL64(0x00000000000000ff)) << 56) );
170 + }
171 +
172 + #ifdef WORDS_BIGENDIAN
173 + static inline uint16 tswap16(uint16 x) { return x; }
174 + static inline uint32 tswap32(uint32 x) { return x; }
175 + static inline uint64 tswap64(uint64 x) { return x; }
176 + #else
177 + static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
178 + static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
179 + static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
180 + #endif
181 +
182 + // spin locks
183 + #ifdef __GNUC__
184 +
185 + #ifdef __powerpc__
186 + #define HAVE_TEST_AND_SET 1
187 + static inline int testandset(int *p)
188 + {
189 +        int ret;
190 +        __asm__ __volatile__("0:    lwarx %0,0,%1 ;"
191 +                                                 "      xor. %0,%3,%0;"
192 +                                                 "      bne 1f;"
193 +                                                 "      stwcx. %2,0,%1;"
194 +                                                 "      bne- 0b;"
195 +                                                 "1:    "
196 +                                                 : "=&r" (ret)
197 +                                                 : "r" (p), "r" (1), "r" (0)
198 +                                                 : "cr0", "memory");
199 +        return ret;
200 + }
201 + #endif
202 +
203 + #ifdef __i386__
204 + #define HAVE_TEST_AND_SET 1
205 + static inline int testandset(int *p)
206 + {
207 +        char ret;
208 +        long int readval;
209 +        
210 +        __asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0"
211 +                                                 : "=q" (ret), "=m" (*p), "=a" (readval)
212 +                                                 : "r" (1), "m" (*p), "a" (0)
213 +                                                 : "memory");
214 +        return ret;
215 + }
216 + #endif
217 +
218 + #ifdef __s390__
219 + #define HAVE_TEST_AND_SET 1
220 + static inline int testandset(int *p)
221 + {
222 +        int ret;
223 +
224 +        __asm__ __volatile__("0: cs    %0,%1,0(%2)\n"
225 +                                                 "   jl    0b"
226 +                                                 : "=&d" (ret)
227 +                                                 : "r" (1), "a" (p), "0" (*p)
228 +                                                 : "cc", "memory" );
229 +        return ret;
230 + }
231 + #endif
232 +
233 + #ifdef __alpha__
234 + #define HAVE_TEST_AND_SET 1
235 + static inline int testandset(int *p)
236 + {
237 +        int ret;
238 +        unsigned long one;
239 +
240 +        __asm__ __volatile__("0:        mov 1,%2\n"
241 +                                                 "      ldl_l %0,%1\n"
242 +                                                 "      stl_c %2,%1\n"
243 +                                                 "      beq %2,1f\n"
244 +                                                 ".subsection 2\n"
245 +                                                 "1:    br 0b\n"
246 +                                                 ".previous"
247 +                                                 : "=r" (ret), "=m" (*p), "=r" (one)
248 +                                                 : "m" (*p));
249 +        return ret;
250 + }
251 + #endif
252 +
253 + #ifdef __sparc__
254 + #define HAVE_TEST_AND_SET 1
255 + static inline int testandset(int *p)
256 + {
257 +        int ret;
258 +
259 +        __asm__ __volatile__("ldstub    [%1], %0"
260 +                                                 : "=r" (ret)
261 +                                                 : "r" (p)
262 +                                                 : "memory");
263 +
264 +        return (ret ? 1 : 0);
265 + }
266 + #endif
267 +
268 + #ifdef __arm__
269 + #define HAVE_TEST_AND_SET 1
270 + static inline int testandset(int *p)
271 + {
272 +        register unsigned int ret;
273 +        __asm__ __volatile__("swp %0, %1, [%2]"
274 +                                                 : "=r"(ret)
275 +                                                 : "0"(1), "r"(p));
276 +        
277 +        return ret;
278 + }
279 + #endif
280 +
281 + #endif /* __GNUC__ */
282 +
283 + #if HAVE_TEST_AND_SET
284 + #define HAVE_SPINLOCKS 1
285 + typedef int spinlock_t;
286 +
287 + const spinlock_t SPIN_LOCK_UNLOCKED = 0;
288 +
289 + static inline void spin_lock(spinlock_t *lock)
290 + {
291 +        while (testandset(lock));
292 + }
293 +
294 + static inline void spin_unlock(spinlock_t *lock)
295 + {
296 +        *lock = 0;
297 + }
298 +
299 + static inline int spin_trylock(spinlock_t *lock)
300 + {
301 +        return !testandset(lock);
302 + }
303 + #endif
304 +
305   // Time data type for Time Manager emulation
306   #ifdef HAVE_CLOCK_GETTIME
307   typedef struct timespec tm_time_t;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines