ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/sysdeps.h
Revision: 1.5
Committed: 2003-09-07T14:19:25Z (21 years, 2 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.4: +68 -6 lines
Log Message:
Add byteswap routines

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * sysdeps.h - System dependent definitions for Linux
3     *
4     * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #ifndef SYSDEPS_H
22     #define SYSDEPS_H
23    
24     #ifndef __STDC__
25     #error "Your compiler is not ANSI. Get a real one."
26     #endif
27    
28     #include "config.h"
29     #include "user_strings_unix.h"
30    
31     #ifndef STDC_HEADERS
32     #error "You don't have ANSI C header files."
33     #endif
34    
35     #ifdef HAVE_UNISTD_H
36     # include <sys/types.h>
37     # include <unistd.h>
38     #endif
39    
40     #include <netinet/in.h>
41     #include <assert.h>
42     #include <stdio.h>
43     #include <stdlib.h>
44     #include <string.h>
45     #include <signal.h>
46    
47     #ifdef HAVE_FCNTL_H
48     # include <fcntl.h>
49     #endif
50    
51     #ifdef TIME_WITH_SYS_TIME
52     # include <sys/time.h>
53     # include <time.h>
54     #else
55     # ifdef HAVE_SYS_TIME_H
56     # include <sys/time.h>
57     # else
58     # include <time.h>
59     # endif
60     #endif
61    
62 gbeauche 1.5 // Define for external components
63     #define SHEEPSHAVER 1
64    
65 gbeauche 1.4 // Mac and host address space are the same
66     #define REAL_ADDRESSING 1
67    
68 gbeauche 1.5 #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 cebix 1.1 #else
76 gbeauche 1.5 # 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 cebix 1.1 #endif
83    
84     // Data types
85     typedef unsigned char uint8;
86     typedef signed char int8;
87     #if SIZEOF_SHORT == 2
88     typedef unsigned short uint16;
89     typedef short int16;
90     #elif SIZEOF_INT == 2
91     typedef unsigned int uint16;
92     typedef int int16;
93     #else
94     #error "No 2 byte type, you lose."
95     #endif
96     #if SIZEOF_INT == 4
97     typedef unsigned int uint32;
98     typedef int int32;
99     #elif SIZEOF_LONG == 4
100     typedef unsigned long uint32;
101     typedef long int32;
102     #else
103     #error "No 4 byte type, you lose."
104     #endif
105     #if SIZEOF_LONG == 8
106     typedef unsigned long uint64;
107     typedef long int64;
108 gbeauche 1.3 #define VAL64(a) (a ## l)
109     #define UVAL64(a) (a ## ul)
110 cebix 1.1 #elif SIZEOF_LONG_LONG == 8
111     typedef unsigned long long uint64;
112     typedef long long int64;
113 gbeauche 1.3 #define VAL64(a) (a ## LL)
114     #define UVAL64(a) (a ## uLL)
115 cebix 1.1 #else
116     #error "No 8 byte type, you lose."
117     #endif
118 gbeauche 1.3 #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 gbeauche 1.5 #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 gbeauche 1.3 #endif
179 cebix 1.1
180     // Time data type for Time Manager emulation
181     #ifdef HAVE_CLOCK_GETTIME
182     typedef struct timespec tm_time_t;
183     #else
184     typedef struct timeval tm_time_t;
185     #endif
186    
187 cebix 1.2 // Setup pthread attributes
188     extern void Set_pthread_attr(pthread_attr_t *attr, int priority);
189    
190 cebix 1.1 // Various definitions
191     typedef struct rgb_color {
192     uint8 red;
193     uint8 green;
194     uint8 blue;
195     uint8 alpha;
196     } rgb_color;
197    
198     // Macro for calling MacOS routines
199     #define CallMacOS(type, tvect) call_macos((uint32)tvect)
200     #define CallMacOS1(type, tvect, arg1) call_macos1((uint32)tvect, (uint32)arg1)
201     #define CallMacOS2(type, tvect, arg1, arg2) call_macos2((uint32)tvect, (uint32)arg1, (uint32)arg2)
202     #define CallMacOS3(type, tvect, arg1, arg2, arg3) call_macos3((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3)
203     #define CallMacOS4(type, tvect, arg1, arg2, arg3, arg4) call_macos4((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4)
204     #define CallMacOS5(type, tvect, arg1, arg2, arg3, arg4, arg5) call_macos5((uint32)tvect, (uint32)arg1, (uint32)arg2, (uint32)arg3, (uint32)arg4, (uint32)arg5)
205     #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)
206     #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)
207    
208 gbeauche 1.3 #ifdef __cplusplus
209     extern "C" {
210     #endif
211     extern uint32 call_macos(uint32 tvect);
212     extern uint32 call_macos1(uint32 tvect, uint32 arg1);
213     extern uint32 call_macos2(uint32 tvect, uint32 arg1, uint32 arg2);
214     extern uint32 call_macos3(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3);
215     extern uint32 call_macos4(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4);
216     extern uint32 call_macos5(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5);
217     extern uint32 call_macos6(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6);
218     extern uint32 call_macos7(uint32 tvect, uint32 arg1, uint32 arg2, uint32 arg3, uint32 arg4, uint32 arg5, uint32 arg6, uint32 arg7);
219     #ifdef __cplusplus
220     }
221     #endif
222 cebix 1.1
223     #endif