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.1 by cebix, 2002-02-04T16:58:13Z vs.
Revision 1.16 by gbeauche, 2003-11-28T22:13:49Z

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines