1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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
16 * The Original Code is Mozilla Communicator client code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
25 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 * Generate CPU-specific bit-size and similar #defines.
51 /************************************************************************/
54 #define NS_NEVER_INLINE __attribute__((noinline))
56 #define NS_NEVER_INLINE
60 static int StackGrowthDirection(int *dummy1addr
);
61 #pragma no_inline(StackGrowthDirection)
64 static int NS_NEVER_INLINE
StackGrowthDirection(int *dummy1addr
)
68 return (&dummy2
< dummy1addr
) ? -1 : 1;
71 int main(int argc
, char **argv
)
75 printf("#ifndef js_cpucfg___\n");
76 printf("#define js_cpucfg___\n\n");
78 printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
81 #if defined(__APPLE__)
83 * Darwin NSPR uses the same MDCPUCFG (_darwin.cfg) for multiple
84 * processors, and determines which processor to configure for based
85 * on compiler predefined macros. We do the same thing here.
87 printf("#ifdef __LITTLE_ENDIAN__\n");
88 printf("#define IS_LITTLE_ENDIAN 1\n");
89 printf("#undef IS_BIG_ENDIAN\n");
91 printf("#undef IS_LITTLE_ENDIAN\n");
92 printf("#define IS_BIG_ENDIAN 1\n");
94 #elif defined(IS_LITTLE_ENDIAN)
95 printf("#define IS_LITTLE_ENDIAN 1\n");
96 printf("#undef IS_BIG_ENDIAN\n\n");
97 #elif defined(IS_BIG_ENDIAN)
98 printf("#undef IS_LITTLE_ENDIAN\n");
99 printf("#define IS_BIG_ENDIAN 1\n\n");
101 #error "Endianess not defined."
107 * We don't handle PDP-endian or similar orders: if a short is big-endian,
108 * so must int and long be big-endian for us to generate the IS_BIG_ENDIAN
109 * #define and the IS_LITTLE_ENDIAN #undef.
112 int big_endian
= 0, little_endian
= 0, ntests
= 0;
114 if (sizeof(short) == 2) {
115 /* force |volatile| here to get rid of any compiler optimisations
116 * (var in register etc.) which may be appiled to |auto| vars -
117 * even those in |union|s...
118 * (|static| is used to get the same functionality for compilers
119 * which do not honor |volatile|...).
121 volatile static union {
127 big_endian
+= (u
.c
[0] == 0x01 && u
.c
[1] == 0x02);
128 little_endian
+= (u
.c
[0] == 0x02 && u
.c
[1] == 0x01);
132 if (sizeof(int) == 4) {
133 /* force |volatile| here ... */
134 volatile static union {
140 big_endian
+= (u
.c
[0] == 0x01 && u
.c
[1] == 0x02 &&
141 u
.c
[2] == 0x03 && u
.c
[3] == 0x04);
142 little_endian
+= (u
.c
[0] == 0x04 && u
.c
[1] == 0x03 &&
143 u
.c
[2] == 0x02 && u
.c
[3] == 0x01);
147 if (sizeof(long) == 8) {
148 /* force |volatile| here ... */
149 volatile static union {
155 * Write this as portably as possible: avoid 0x0102030405060708L
159 u
.i
<<= 16, u
.i
<<= 16;
161 big_endian
+= (u
.c
[0] == 0x01 && u
.c
[1] == 0x02 &&
162 u
.c
[2] == 0x03 && u
.c
[3] == 0x04 &&
163 u
.c
[4] == 0x05 && u
.c
[5] == 0x06 &&
164 u
.c
[6] == 0x07 && u
.c
[7] == 0x08);
165 little_endian
+= (u
.c
[0] == 0x08 && u
.c
[1] == 0x07 &&
166 u
.c
[2] == 0x06 && u
.c
[3] == 0x05 &&
167 u
.c
[4] == 0x04 && u
.c
[5] == 0x03 &&
168 u
.c
[6] == 0x02 && u
.c
[7] == 0x01);
172 if (big_endian
&& big_endian
== ntests
) {
173 printf("#undef IS_LITTLE_ENDIAN\n");
174 printf("#define IS_BIG_ENDIAN 1\n\n");
175 } else if (little_endian
&& little_endian
== ntests
) {
176 printf("#define IS_LITTLE_ENDIAN 1\n");
177 printf("#undef IS_BIG_ENDIAN\n\n");
179 fprintf(stderr
, "%s: unknown byte order"
180 "(big_endian=%d, little_endian=%d, ntests=%d)!\n",
181 argv
[0], big_endian
, little_endian
, ntests
);
186 #endif /* CROSS_COMPILE */
188 printf("#define JS_STACK_GROWTH_DIRECTION (%d)\n", StackGrowthDirection(&dummy1
));
190 printf("#endif /* js_cpucfg___ */\n");