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.2 by cebix, 2002-02-21T15:12:12Z vs.
Revision 1.15 by gbeauche, 2003-11-24T21:20:47Z

# Line 59 | Line 59
59   # endif
60   #endif
61  
62 < // Are we using a PPC emulator or the real thing?
63 < #ifdef __powerpc__
64 < #define EMULATED_PPC 0
65 < #else
66 < #define EMULATED_PPC 1
67 < #endif
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   #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 ROM_IS_WRITE_PROTECTED 1
79 + #endif
80 + // Configure PowerPC emulator
81 + #define PPC_CHECK_INTERRUPTS (ASYNC_IRQ ? 0 : 1)
82 + #define PPC_DECODE_CACHE 1
83 + #define PPC_FLIGHT_RECORDER 1
84 + #else
85 + // Mac ROM is write protected
86 + #define ROM_IS_WRITE_PROTECTED 1
87 + #define USE_SCRATCHMEM_SUBTERFUGE 0
88 + #endif
89 +
90   // Data types
91   typedef unsigned char uint8;
92   typedef signed char int8;
# Line 92 | Line 111 | typedef long int32;
111   #if SIZEOF_LONG == 8
112   typedef unsigned long uint64;
113   typedef long int64;
114 + #define VAL64(a) (a ## l)
115 + #define UVAL64(a) (a ## ul)
116   #elif SIZEOF_LONG_LONG == 8
117   typedef unsigned long long uint64;
118   typedef long long int64;
119 + #define VAL64(a) (a ## LL)
120 + #define UVAL64(a) (a ## uLL)
121   #else
122   #error "No 8 byte type, you lose."
123   #endif
124 + #if SIZEOF_VOID_P == 4
125 + typedef uint32 uintptr;
126 + typedef int32 intptr;
127 + #elif SIZEOF_VOID_P == 8
128 + typedef uint64 uintptr;
129 + typedef int64 intptr;
130 + #else
131 + #error "Unsupported size of pointer"
132 + #endif
133 +
134 + /**
135 + *              Helper functions to byteswap data
136 + **/
137 +
138 + #if defined(__GNUC__)
139 + #if defined(__x86_64__)
140 + // Linux/AMD64 currently has no asm optimized bswap_32() in <byteswap.h>
141 + #define opt_bswap_32 do_opt_bswap_32
142 + static inline uint32 do_opt_bswap_32(uint32 x)
143 + {
144 +  uint32 v;
145 +  __asm__ __volatile__ ("bswap %0" : "=r" (v) : "0" (x));
146 +  return v;
147 + }
148 + #endif
149 + #endif
150 +
151 + #ifdef HAVE_BYTESWAP_H
152 + #include <byteswap.h>
153 + #endif
154 +
155 + #ifdef  opt_bswap_16
156 + #undef  bswap_16
157 + #define bswap_16 opt_bswap_16
158 + #endif
159 + #ifndef bswap_16
160 + #define bswap_16 generic_bswap_16
161 + #endif
162 +
163 + static inline uint16 generic_bswap_16(uint16 x)
164 + {
165 +  return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
166 + }
167 +
168 + #ifdef  opt_bswap_32
169 + #undef  bswap_32
170 + #define bswap_32 opt_bswap_32
171 + #endif
172 + #ifndef bswap_32
173 + #define bswap_32 generic_bswap_32
174 + #endif
175 +
176 + static inline uint32 generic_bswap_32(uint32 x)
177 + {
178 +  return (((x & 0xff000000) >> 24) |
179 +                  ((x & 0x00ff0000) >>  8) |
180 +                  ((x & 0x0000ff00) <<  8) |
181 +                  ((x & 0x000000ff) << 24) );
182 + }
183 +
184 + #ifdef  opt_bswap_64
185 + #undef  bswap_64
186 + #define bswap_64 opt_bswap_64
187 + #endif
188 + #ifndef bswap_64
189 + #define bswap_64 generic_bswap_64
190 + #endif
191 +
192 + static inline uint64 generic_bswap_64(uint64 x)
193 + {
194 +  return (((x & UVAL64(0xff00000000000000)) >> 56) |
195 +                  ((x & UVAL64(0x00ff000000000000)) >> 40) |
196 +                  ((x & UVAL64(0x0000ff0000000000)) >> 24) |
197 +                  ((x & UVAL64(0x000000ff00000000)) >>  8) |
198 +                  ((x & UVAL64(0x00000000ff000000)) <<  8) |
199 +                  ((x & UVAL64(0x0000000000ff0000)) << 24) |
200 +                  ((x & UVAL64(0x000000000000ff00)) << 40) |
201 +                  ((x & UVAL64(0x00000000000000ff)) << 56) );
202 + }
203 +
204 + #ifdef WORDS_BIGENDIAN
205 + static inline uint16 tswap16(uint16 x) { return x; }
206 + static inline uint32 tswap32(uint32 x) { return x; }
207 + static inline uint64 tswap64(uint64 x) { return x; }
208 + #else
209 + static inline uint16 tswap16(uint16 x) { return bswap_16(x); }
210 + static inline uint32 tswap32(uint32 x) { return bswap_32(x); }
211 + static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
212 + #endif
213 +
214 + // spin locks
215 + #ifdef __GNUC__
216 +
217 + #ifdef __powerpc__
218 + #define HAVE_TEST_AND_SET 1
219 + static inline int testandset(int *p)
220 + {
221 +        int ret;
222 +        __asm__ __volatile__("0:    lwarx %0,0,%1 ;"
223 +                                                 "      xor. %0,%3,%0;"
224 +                                                 "      bne 1f;"
225 +                                                 "      stwcx. %2,0,%1;"
226 +                                                 "      bne- 0b;"
227 +                                                 "1:    "
228 +                                                 : "=&r" (ret)
229 +                                                 : "r" (p), "r" (1), "r" (0)
230 +                                                 : "cr0", "memory");
231 +        return ret;
232 + }
233 + #endif
234 +
235 + #ifdef __i386__
236 + #define HAVE_TEST_AND_SET 1
237 + static inline int testandset(int *p)
238 + {
239 +        char ret;
240 +        long int readval;
241 +        
242 +        __asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0"
243 +                                                 : "=q" (ret), "=m" (*p), "=a" (readval)
244 +                                                 : "r" (1), "m" (*p), "a" (0)
245 +                                                 : "memory");
246 +        return ret;
247 + }
248 + #endif
249 +
250 + #ifdef __s390__
251 + #define HAVE_TEST_AND_SET 1
252 + static inline int testandset(int *p)
253 + {
254 +        int ret;
255 +
256 +        __asm__ __volatile__("0: cs    %0,%1,0(%2)\n"
257 +                                                 "   jl    0b"
258 +                                                 : "=&d" (ret)
259 +                                                 : "r" (1), "a" (p), "0" (*p)
260 +                                                 : "cc", "memory" );
261 +        return ret;
262 + }
263 + #endif
264 +
265 + #ifdef __alpha__
266 + #define HAVE_TEST_AND_SET 1
267 + static inline int testandset(int *p)
268 + {
269 +        int ret;
270 +        unsigned long one;
271 +
272 +        __asm__ __volatile__("0:        mov 1,%2\n"
273 +                                                 "      ldl_l %0,%1\n"
274 +                                                 "      stl_c %2,%1\n"
275 +                                                 "      beq %2,1f\n"
276 +                                                 ".subsection 2\n"
277 +                                                 "1:    br 0b\n"
278 +                                                 ".previous"
279 +                                                 : "=r" (ret), "=m" (*p), "=r" (one)
280 +                                                 : "m" (*p));
281 +        return ret;
282 + }
283 + #endif
284 +
285 + #ifdef __sparc__
286 + #define HAVE_TEST_AND_SET 1
287 + static inline int testandset(int *p)
288 + {
289 +        int ret;
290 +
291 +        __asm__ __volatile__("ldstub    [%1], %0"
292 +                                                 : "=r" (ret)
293 +                                                 : "r" (p)
294 +                                                 : "memory");
295 +
296 +        return (ret ? 1 : 0);
297 + }
298 + #endif
299 +
300 + #ifdef __arm__
301 + #define HAVE_TEST_AND_SET 1
302 + static inline int testandset(int *p)
303 + {
304 +        register unsigned int ret;
305 +        __asm__ __volatile__("swp %0, %1, [%2]"
306 +                                                 : "=r"(ret)
307 +                                                 : "0"(1), "r"(p));
308 +        
309 +        return ret;
310 + }
311 + #endif
312 +
313 + #endif /* __GNUC__ */
314 +
315 + #if HAVE_TEST_AND_SET
316 + #define HAVE_SPINLOCKS 1
317 + typedef int spinlock_t;
318 +
319 + static const spinlock_t SPIN_LOCK_UNLOCKED = 0;
320 +
321 + static inline void spin_lock(spinlock_t *lock)
322 + {
323 +        while (testandset(lock));
324 + }
325 +
326 + static inline void spin_unlock(spinlock_t *lock)
327 + {
328 +        *lock = 0;
329 + }
330 +
331 + static inline int spin_trylock(spinlock_t *lock)
332 + {
333 +        return !testandset(lock);
334 + }
335 + #endif
336  
337   // Time data type for Time Manager emulation
338   #ifdef HAVE_CLOCK_GETTIME
# Line 127 | Line 362 | typedef struct rgb_color {
362   #define CallMacOS6(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6) call_macos6((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5, (uint32)arg6)
363   #define CallMacOS7(type, tvect, arg1, arg2, arg3, arg4, arg5, arg6, arg7) call_macos7((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5, (uint32)arg6, (uint32)arg7)
364  
365 < extern "C" uint32 call_macos(uint32 tvect);
366 < extern "C" uint32 call_macos1(uint32 tvect, uint32 arg1);
367 < extern "C" uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
368 < extern "C" uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
369 < extern "C" uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
370 < extern "C" uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
371 < extern "C" uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
372 < extern "C" uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
365 > #ifdef __cplusplus
366 > extern "C" {
367 > #endif
368 > extern uint32 call_macos(uint32 tvect);
369 > extern uint32 call_macos1(uint32 tvect, uint32 arg1);
370 > extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
371 > extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
372 > extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
373 > extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
374 > extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
375 > extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
376 > #ifdef __cplusplus
377 > }
378 > #endif
379  
380   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines