Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / platform / system-selection.h
blobbbd527aa2466f7dccbfa8c4b6d5b204050b050c8
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 1993-2006
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __avmplus_system_selection__
41 #define __avmplus_system_selection__
43 // Standard operating system, CPU, word size, and endianness selection
44 // for tier-one AVM platforms. This file defines all the AVMSYSTEM_
45 // names. It would normally be included into a feature definition file.
47 // operating system
49 #ifdef UNIX
50 #define AVMSYSTEM_UNIX 1
51 #else
52 #define AVMSYSTEM_UNIX 0
53 #endif
54 #ifdef _MAC
55 #define AVMSYSTEM_MAC 1
56 #else
57 #define AVMSYSTEM_MAC 0
58 #endif
59 #ifdef WIN32
60 #define AVMSYSTEM_WIN32 1
61 #else
62 #define AVMSYSTEM_WIN32 0
63 #endif
64 #ifdef __SYMBIAN32__ // defined by Symbian S60 tool chain
65 #define AVMSYSTEM_SYMBIAN 1
66 #else
67 #define AVMSYSTEM_SYMBIAN 0
68 #endif
70 #ifdef WEBOS
71 #define AVMSYSTEM_WEBOS 1
72 #else
73 #define AVMSYSTEM_WEBOS 0
74 #endif
76 // cpu, word size
78 #undef SIXTYFOURBIT
80 #if AVMSYSTEM_MAC || AVMSYSTEM_UNIX
82 #if defined(__i386__) || defined(__i386)
83 #define AVMSYSTEM_IA32 1
84 #else
85 #define AVMSYSTEM_IA32 0
86 #endif
88 #if defined(__x86_64__)
89 #define AVMSYSTEM_AMD64 1
90 #define SIXTYFOURBIT
91 #else
92 #define AVMSYSTEM_AMD64 0
93 #endif
95 #if defined(__ppc__) || defined(__powerpc__) || (__ppc64__) || (__powerpc64__)
96 #define AVMSYSTEM_PPC 1
97 #if (__ppc64__) || (__powerpc64__)
98 #define SIXTYFOURBIT
99 #endif
100 #else
101 #define AVMSYSTEM_PPC 0
102 #endif
104 #if defined(__arm__) || defined(__ARM__)
105 #define AVMSYSTEM_ARM 1
106 #else
107 #define AVMSYSTEM_ARM 0
108 #endif
110 #if defined(__sparc__) || defined(__sparc)
111 #define AVMSYSTEM_SPARC 1
112 #else
113 #define AVMSYSTEM_SPARC 0
114 #endif
116 #if defined(__mips__) || defined(__MIPS__)
117 #define AVMSYSTEM_MIPS 1
118 #else
119 #define AVMSYSTEM_MIPS 0
120 #endif
122 #if defined(__SH4__)
123 #define AVMSYSTEM_SH4 1
124 #else
125 #define AVMSYSTEM_SH4 0
126 #endif
128 #endif // mac || unix
130 #if AVMSYSTEM_WIN32
132 #ifdef _M_X64
133 #define AVMSYSTEM_AMD64 1
134 #define SIXTYFOURBIT
135 #else
136 #define AVMSYSTEM_AMD64 0
137 #endif
139 #if defined(_ARM_)
140 #define AVMSYSTEM_ARM 1
141 #else
142 #define AVMSYSTEM_ARM 0
143 #endif
145 #if !AVMSYSTEM_AMD64 && !AVMSYSTEM_ARM
146 #define AVMSYSTEM_IA32 1
147 #else
148 #define AVMSYSTEM_IA32 0
149 #endif
151 #define AVMSYSTEM_PPC 0
152 #define AVMSYSTEM_SPARC 0
153 #define AVMSYSTEM_SH4 0
154 #define AVMSYSTEM_MIPS 0
156 #endif // win32
158 #if AVMSYSTEM_SYMBIAN
160 #define AVMSYSTEM_PPC 0
161 #define AVMSYSTEM_AMD64 0
162 #define AVMSYSTEM_SPARC 0
163 #define AVMSYSTEM_MIPS 0
164 #define AVMSYSTEM_SH4 0
166 #if defined(__ARMCC__)
167 #define AVMSYSTEM_ARM 1
168 #else
169 #define AVMSYSTEM_ARM 0
170 #endif
172 #if !AVMSYSTEM_ARM
173 #define AVMSYSTEM_IA32 1
174 #else
175 #define AVMSYSTEM_IA32 0
176 #endif
178 #ifdef __WINSCW__
179 #define AVMTWEAK_EPOC_EMULATOR 1
180 #endif
182 #endif // symbian
184 #ifdef SIXTYFOURBIT
185 #define AVMSYSTEM_32BIT 0
186 #define AVMSYSTEM_64BIT 1
187 #else
188 #define AVMSYSTEM_32BIT 1
189 #define AVMSYSTEM_64BIT 0
190 #endif
192 #undef SIXTYFOURBIT
194 // endianness
196 #if AVMSYSTEM_IA32 || AVMSYSTEM_AMD64
197 #define AVMSYSTEM_LITTLE_ENDIAN 1
198 #define AVMSYSTEM_BIG_ENDIAN 0
199 #elif AVMSYSTEM_ARM
200 #if defined _MSC_VER
201 #define AVMSYSTEM_LITTLE_ENDIAN 1
202 #define AVMSYSTEM_BIG_ENDIAN 0
203 #elif defined __GNUC__
204 #if AVMSYSTEM_MAC && AVMSYSTEM_ARM
205 #include <machine/endian.h>
206 #define __BYTE_ORDER BYTE_ORDER
207 #else
208 #include <endian.h>
209 #endif
210 #if __BYTE_ORDER == LITTLE_ENDIAN
211 #define AVMSYSTEM_LITTLE_ENDIAN 1
212 #define AVMSYSTEM_BIG_ENDIAN 0
213 #if __FLOAT_WORD_ORDER == BIG_ENDIAN
214 #define AVMSYSTEM_DOUBLE_MSW_FIRST 1
215 #endif
216 #else
217 #define AVMSYSTEM_LITTLE_ENDIAN 0
218 #define AVMSYSTEM_BIG_ENDIAN 1
219 #endif
220 #elif defined __ARMCC__
221 #define AVMSYSTEM_LITTLE_ENDIAN 1
222 #define AVMSYSTEM_BIG_ENDIAN 0
223 #endif
224 #elif AVMSYSTEM_PPC || AVMSYSTEM_SPARC
225 #define AVMSYSTEM_LITTLE_ENDIAN 0
226 #define AVMSYSTEM_BIG_ENDIAN 1
227 #elif AVMSYSTEM_MIPS || AVMSYSTEM_SH4
228 #if defined __GNUC__
229 #include <endian.h>
230 #if __BYTE_ORDER == LITTLE_ENDIAN
231 #define AVMSYSTEM_LITTLE_ENDIAN 1
232 #define AVMSYSTEM_BIG_ENDIAN 0
233 #else
234 #define AVMSYSTEM_LITTLE_ENDIAN 0
235 #define AVMSYSTEM_BIG_ENDIAN 1
236 #endif
237 #endif
238 #else
239 #error "Error in test to determine endianness"
240 #endif
242 // unaligned access
244 // currently used only by the AVMSYSTEM_ARM case, but we include
245 // it on all platforms to ensure consistent build system failures
246 #include "../nanojit/njcpudetect.h"
248 #if AVMSYSTEM_IA32 || AVMSYSTEM_AMD64
249 #define AVMSYSTEM_UNALIGNED_INT_ACCESS 1
250 #define AVMSYSTEM_UNALIGNED_FP_ACCESS 1
251 #elif AVMSYSTEM_ARM
252 #if AVMSYSTEM_WEBOS
253 // At the time of this writing (Feb 2010), Palm's webOS deliberately enables software interrupts
254 // for all unaligned accesses, apparently in the name of promoting "clean code", making unaligned
255 // accesses vastly slower than aligned (reportedly on the order of 1000x). Unless they change this
256 // policy (or give us a way to change it selectively) we will consider all webOS builds not to
257 // support unaligned access, regardless of the processor variant.
258 #define AVMSYSTEM_UNALIGNED_INT_ACCESS 0
259 #else
261 // ARM is a little complicated:
263 // ARMv5 (e.g. ARM926): No support for unaligned accesses.
264 // ARMv6 (e.g. ARM1176): Optional support that must be enabled by the OS.
265 // ARMv7 (e.g. Cortex-A8): Unaligned access support cannot be disabled; you always have it.
267 #if NJ_COMPILER_ARM_ARCH >= 7
268 #define AVMSYSTEM_UNALIGNED_INT_ACCESS 1
269 #else
270 #define AVMSYSTEM_UNALIGNED_INT_ACCESS 0
271 #endif
272 #endif
273 // VFP rules are different from int rules on ARM
274 #define AVMSYSTEM_UNALIGNED_FP_ACCESS 0
275 #elif AVMSYSTEM_PPC || AVMSYSTEM_SPARC || AVMSYSTEM_MIPS || AVMSYSTEM_SH4
276 #define AVMSYSTEM_UNALIGNED_INT_ACCESS 0
277 #define AVMSYSTEM_UNALIGNED_FP_ACCESS 0
278 #else
279 #error "Error in test to determine endianness"
280 #endif
282 #ifndef AVMSYSTEM_DOUBLE_MSW_FIRST
283 #define AVMSYSTEM_DOUBLE_MSW_FIRST 0
284 #endif
286 #endif