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.1.1 by cebix, 2002-02-04T16:58:13Z vs.
Revision 1.6 by gbeauche, 2003-09-29T08:27:56Z

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines