Ticket #1141: x86_64-buildtools-haikutrunk.patch

File x86_64-buildtools-haikutrunk.patch, 13.3 KB (added by nmentley, 12 years ago)

added a few header files in haiku/headers/posix/arch that'll allow for an x86_64 haiku target to be compiled. Also edited ./configure to support x86_64 arch when running build-cross-tools-gcc4. fenv.h is src/lib/msun/amd64/fenv.h from freebsd 8.0 file version: 1.6.10.1.2.1 2009/10/25 01:10:29

Line 
1Index: build/jam/BuildSetup
2===================================================================
3--- build/jam/BuildSetup (revision 36735)
4+++ build/jam/BuildSetup (working copy)
5@@ -187,6 +187,7 @@
6 # analyze the gcc machine spec to determine HAIKU_CPU
7 switch $(HAIKU_GCC_MACHINE) {
8 case i?86-* : HAIKU_CPU = x86 ;
9+ case x86_64-* : HAIKU_CPU = x86_64 ;
10 case powerpc-* : HAIKU_CPU = ppc ;
11 case m68k-* : HAIKU_CPU = m68k ;
12 case mipsel-* : HAIKU_CPU = mipsel ;
13@@ -243,6 +244,19 @@
14 Exit "HAIKU_YASM not set. Please re-run configure." ;
15 }
16 }
17+ case x86_64 :
18+ {
19+ HAIKU_DEFINES += __x86_64__ ;
20+ HAIKU_BOOT_PLATFORM = bios_ia32 ;
21+ HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB
22+ # offset in floppy image (>= sizeof(haiku_loader))
23+ HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 300 ; # in kB
24+
25+ # yasm is required for target arch x86_64
26+ if ! $(HAIKU_YASM) {
27+ Exit "HAIKU_YASM not set. Please re-run configure." ;
28+ }
29+ }
30 case m68k :
31 {
32 HAIKU_DEFINES += __M68K__ ;
33@@ -341,6 +355,20 @@
34 # available with gcc 2, but the header will take care of that.
35 HAIKU_DEFINES += B_USE_BUILTIN_ATOMIC_FUNCTIONS ;
36 }
37+ case x86_64 :
38+ {
39+ # Enable use of the gcc built-in atomic functions instead of atomic_*().
40+ # The former are inlined and have thus less overhead. They are not
41+ # available with gcc 2, but the header will take care of that.
42+ HAIKU_DEFINES += B_USE_BUILTIN_ATOMIC_FUNCTIONS ;
43+
44+ # Enables additional atomic functions that aren't supported on x86
45+ HAIKU_DEFINES += B_USE_EXTRA_BUILTIN_ATOMIC_FUNCTIONS ;
46+ }
47 }
48
49 # If the environment variable HAIKU_INCLUDE_PATENTED_CODE is defined, we
50Index: configure
51===================================================================
52--- configure (revision 36735)
53+++ configure (working copy)
54@@ -38,7 +38,7 @@
55 resulting Haiku installation built with gcc 4
56 will not be binary compatible with BeOS R5.
57 <arch> specifies the target architecture, either
58- "x86", "ppc", "m68k", "arm" or "mipsel".
59+ "x86", "x86_64", "ppc", "m68k", "arm" or "mipsel".
60 --cross-tools-prefix <prefix>
61 Assume cross compilation. <prefix> should be a
62 path to the directory where the cross
63@@ -381,6 +381,7 @@
64 buildCrossToolsScript="${buildCrossToolsScript}_gcc4"
65 case "$2" in
66 x86) HAIKU_GCC_MACHINE=i586-pc-haiku;;
67+ x86_64) HAIKU_GCC_MACHINE=x86_64-pc-haiku; targetArch=x86_64;;
68 ppc) HAIKU_GCC_MACHINE=powerpc-apple-haiku; targetArch=ppc;;
69 m68k) HAIKU_GCC_MACHINE=m68k-unknown-haiku; targetArch=m86k;;
70 arm) HAIKU_GCC_MACHINE=arm-unknown-haiku; targetArch=arm;;
71Index: headers/build/config_build/HaikuConfig.h
72===================================================================
73--- headers/build/config_build/HaikuConfig.h (revision 36735)
74+++ headers/build/config_build/HaikuConfig.h (working copy)
75@@ -14,14 +14,12 @@
76 __HAIKU_BIG_ENDIAN - defined to 1 on big endian architectures
77 */
78 #ifdef __INTEL__
79-# ifdef HAIKU_HOST_PLATFORM_64_BIT
80-# define __HAIKU_ARCH x86_64
81-# define __HAIKU_ARCH_X86_64 1
82-# define __HAIKU_ARCH_64_BIT 1
83-# else
84-# define __HAIKU_ARCH x86
85-# define __HAIKU_ARCH_X86 1
86-# endif
87+# define __HAIKU_ARCH x86
88+# define __HAIKU_ARCH_X86 1
89+#elif __x86_64__
90+# define __HAIKU_ARCH x86_64
91+# define __HAIKU_ARCH_X86_64 1
92+# define __HAIKU_ARCH_64_BIT 1
93 #elif __POWERPC__
94 # define __HAIKU_ARCH ppc
95 # define __HAIKU_ARCH_PPC 1
96Index: headers/os/support/SupportDefs.h
97===================================================================
98--- headers/os/support/SupportDefs.h (revision 36735)
99+++ headers/os/support/SupportDefs.h (working copy)
100@@ -225,4 +225,22 @@
101 #endif // B_USE_BUILTIN_ATOMIC_FUNCTIONS && __GNUC__ >= 4
102
103
104+/* Use the additional built-in atomic functions, if requested and available. */
105+
106+#if defined(B_USE_EXTRA_BUILTIN_ATOMIC_FUNCTIONS) && __GNUC__ >= 4
107+
108+#define atomic_sub(valuePointer, subValue) \
109+ __sync_fetch_and_sub (valuePointer, subValue)
110+#define atomic_xor(valuePointer, xorValue) \
111+ __sync_fetch_and_xor (valuePointer, xorValue)
112+#define atomic_nand(valuePointer, nandValue) \
113+ __sync_fetch_and_nand (valuePointer, nandValue)
114+/* TODO: Atomic set code currently locks. not all platforms have full support for
115+ * locks. The __sync_lock_test_and_set function won't the same on all platforms.
116+ *#define atomic_set(valuePointer, newValue) \
117+ * __sync_lock_test_and_set (valuePointer, newValue)
118+ */
119+
120+#endif // B_USE_EXTRA_BUILTIN_ATOMIC_FUNCTIONS && __GNUC__ >= 4
121+
122 #endif /* _SUPPORT_DEFS_H */
123Index: headers/posix/fenv.h
124===================================================================
125--- headers/posix/fenv.h (revision 36735)
126+++ headers/posix/fenv.h (working copy)
127@@ -3,6 +3,8 @@
128
129 #if defined(_X86_)
130 # include <arch/x86/fenv.h>
131+#elif defined(_x86_64_)
132+# include <arch/x86_64/fenv.h>
133 #elif defined(__ARM__)
134 # include <arch/arm/fenv.h>
135 #elif defined(__POWERPC__)
136Index: headers/posix/arch/x86_64/signal.h
137===================================================================
138--- headers/posix/arch/x86_64/signal.h (revision 0)
139+++ headers/posix/arch/x86_64/signal.h (revision 0)
140@@ -0,0 +1,45 @@
141+/*
142+ * Copyright 2002-2007, Haiku, Inc. All Rights Reserved.
143+ * Distributed under the terms of the MIT License.
144+ */
145+#ifndef _ARCH_SIGNAL_H_
146+#define _ARCH_SIGNAL_H_
147+
148+/*
149+ * Architecture-specific structure passed to signal handlers
150+ */
151+
152+#if __x86_64__
153+
154+struct vregs {
155+ unsigned long rax; /* gp regs */
156+ unsigned long rdx;
157+ unsigned long rcx;
158+ unsigned long rbx;
159+ unsigned long rsi;
160+ unsigned long rdi;
161+ unsigned long rbp;
162+ unsigned long rsp;
163+
164+ unsigned long r8; /* egp regs */
165+ unsigned long r9;
166+ unsigned long r10;
167+ unsigned long r11;
168+ unsigned long r12;
169+ unsigned long r13;
170+ unsigned long r14;
171+ unsigned long r15;
172+
173+ unsigned long rip;
174+
175+/*TODO: add
176+* Floatpoint
177+* MMX
178+* SSE
179+*/
180+
181+};
182+
183+#endif /* __x86_64__ */
184+
185+#endif /* _ARCH_SIGNAL_H_ */
186Index: headers/posix/arch/x86_64/fenv.h
187===================================================================
188--- headers/posix/arch/x86_64/fenv.h (revision 0)
189+++ headers/posix/arch/x86_64/fenv.h (revision 0)
190@@ -0,0 +1,214 @@
191+/*-
192+ * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
193+ * All rights reserved.
194+ *
195+ * Redistribution and use in source and binary forms, with or without
196+ * modification, are permitted provided that the following conditions
197+ * are met:
198+ * 1. Redistributions of source code must retain the above copyright
199+ * notice, this list of conditions and the following disclaimer.
200+ * 2. Redistributions in binary form must reproduce the above copyright
201+ * notice, this list of conditions and the following disclaimer in the
202+ * documentation and/or other materials provided with the distribution.
203+ *
204+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
205+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
207+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
208+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
213+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
214+ * SUCH DAMAGE.
215+ *
216+ * $FreeBSD$
217+ */
218+
219+#ifndef _FENV_H_
220+#define _FENV_H_
221+
222+#include <sys/cdefs.h>
223+#include <sys/_types.h>
224+
225+typedef struct {
226+ struct {
227+ __uint32_t __control;
228+ __uint32_t __status;
229+ __uint32_t __tag;
230+ char __other[16];
231+ } __x87;
232+ __uint32_t __mxcsr;
233+} fenv_t;
234+
235+typedef __uint16_t fexcept_t;
236+
237+/* Exception flags */
238+#define FE_INVALID 0x01
239+#define FE_DENORMAL 0x02
240+#define FE_DIVBYZERO 0x04
241+#define FE_OVERFLOW 0x08
242+#define FE_UNDERFLOW 0x10
243+#define FE_INEXACT 0x20
244+#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \
245+ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
246+
247+/* Rounding modes */
248+#define FE_TONEAREST 0x0000
249+#define FE_DOWNWARD 0x0400
250+#define FE_UPWARD 0x0800
251+#define FE_TOWARDZERO 0x0c00
252+#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
253+ FE_UPWARD | FE_TOWARDZERO)
254+
255+/*
256+ * As compared to the x87 control word, the SSE unit's control word
257+ * has the rounding control bits offset by 3 and the exception mask
258+ * bits offset by 7.
259+ */
260+#define _SSE_ROUND_SHIFT 3
261+#define _SSE_EMASK_SHIFT 7
262+
263+__BEGIN_DECLS
264+
265+/* Default floating-point environment */
266+extern const fenv_t __fe_dfl_env;
267+#define FE_DFL_ENV (&__fe_dfl_env)
268+
269+#define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw))
270+#define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env))
271+#define __fldenvx(__env) __asm __volatile("fldenv %0" : : "m" (__env) \
272+ : "st", "st(1)", "st(2)", "st(3)", "st(4)", \
273+ "st(5)", "st(6)", "st(7)")
274+#define __fnclex() __asm __volatile("fnclex")
275+#define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env)))
276+#define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw)))
277+#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw)))
278+#define __fwait() __asm __volatile("fwait")
279+#define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr))
280+#define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr)))
281+
282+static __inline int
283+feclearexcept(int __excepts)
284+{
285+ fenv_t __env;
286+
287+ if (__excepts == FE_ALL_EXCEPT) {
288+ __fnclex();
289+ } else {
290+ __fnstenv(&__env.__x87);
291+ __env.__x87.__status &= ~__excepts;
292+ __fldenv(__env.__x87);
293+ }
294+ __stmxcsr(&__env.__mxcsr);
295+ __env.__mxcsr &= ~__excepts;
296+ __ldmxcsr(__env.__mxcsr);
297+ return (0);
298+}
299+
300+static __inline int
301+fegetexceptflag(fexcept_t *__flagp, int __excepts)
302+{
303+ int __mxcsr, __status;
304+
305+ __stmxcsr(&__mxcsr);
306+ __fnstsw(&__status);
307+ *__flagp = (__mxcsr | __status) & __excepts;
308+ return (0);
309+}
310+
311+int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
312+int feraiseexcept(int __excepts);
313+
314+static __inline int
315+fetestexcept(int __excepts)
316+{
317+ int __mxcsr, __status;
318+
319+ __stmxcsr(&__mxcsr);
320+ __fnstsw(&__status);
321+ return ((__status | __mxcsr) & __excepts);
322+}
323+
324+static __inline int
325+fegetround(void)
326+{
327+ int __control;
328+
329+ /*
330+ * We assume that the x87 and the SSE unit agree on the
331+ * rounding mode. Reading the control word on the x87 turns
332+ * out to be about 5 times faster than reading it on the SSE
333+ * unit on an Opteron 244.
334+ */
335+ __fnstcw(&__control);
336+ return (__control & _ROUND_MASK);
337+}
338+
339+static __inline int
340+fesetround(int __round)
341+{
342+ int __mxcsr, __control;
343+
344+ if (__round & ~_ROUND_MASK)
345+ return (-1);
346+
347+ __fnstcw(&__control);
348+ __control &= ~_ROUND_MASK;
349+ __control |= __round;
350+ __fldcw(__control);
351+
352+ __stmxcsr(&__mxcsr);
353+ __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT);
354+ __mxcsr |= __round << _SSE_ROUND_SHIFT;
355+ __ldmxcsr(__mxcsr);
356+
357+ return (0);
358+}
359+
360+int fegetenv(fenv_t *__envp);
361+int feholdexcept(fenv_t *__envp);
362+
363+static __inline int
364+fesetenv(const fenv_t *__envp)
365+{
366+
367+ /*
368+ * XXX Using fldenvx() instead of fldenv() tells the compiler that this
369+ * instruction clobbers the i387 register stack. This happens because
370+ * we restore the tag word from the saved environment. Normally, this
371+ * would happen anyway and we wouldn't care, because the ABI allows
372+ * function calls to clobber the i387 regs. However, fesetenv() is
373+ * inlined, so we need to be more careful.
374+ */
375+ __fldenvx(__envp->__x87);
376+ __ldmxcsr(__envp->__mxcsr);
377+ return (0);
378+}
379+
380+int feupdateenv(const fenv_t *__envp);
381+
382+#if __BSD_VISIBLE
383+
384+int feenableexcept(int __mask);
385+int fedisableexcept(int __mask);
386+
387+static __inline int
388+fegetexcept(void)
389+{
390+ int __control;
391+
392+ /*
393+ * We assume that the masks for the x87 and the SSE unit are
394+ * the same.
395+ */
396+ __fnstcw(&__control);
397+ return (~__control & FE_ALL_EXCEPT);
398+}
399+
400+#endif /* __BSD_VISIBLE */
401+
402+__END_DECLS
403+
404+#endif /* !_FENV_H_ */
405Index: headers/posix/arch/x86_64/arch_setjmp.h
406===================================================================
407--- headers/posix/arch/x86_64/arch_setjmp.h (revision 0)
408+++ headers/posix/arch/x86_64/arch_setjmp.h (revision 0)
409@@ -0,0 +1,11 @@
410+/*
411+ * Copyright 2005, Haiku, Inc.
412+ * Distributed under the terms of the MIT License.
413+ */
414+#ifndef _ARCH_SETJMP_H_
415+#define _ARCH_SETJMP_H_
416+
417+/* TODO: A jmp_buf size of 12 might not be large enough. Increase to a large size if needed. */
418+typedef int __jmp_buf[12];
419+
420+#endif /* _ARCH_SETJMP_H_ */
421Index: headers/config/HaikuConfig.h
422===================================================================
423--- headers/config/HaikuConfig.h (revision 36735)
424+++ headers/config/HaikuConfig.h (working copy)
425@@ -14,14 +14,12 @@
426 __HAIKU_BIG_ENDIAN - defined to 1 on big endian architectures
427 */
428 #ifdef __INTEL__
429-# ifdef __x86_64__
430-# define __HAIKU_ARCH x86_64
431-# define __HAIKU_ARCH_X86_64 1
432-# define __HAIKU_ARCH_64_BIT 1
433-# else
434-# define __HAIKU_ARCH x86
435-# define __HAIKU_ARCH_X86 1
436-# endif
437+# define __HAIKU_ARCH x86
438+# define __HAIKU_ARCH_X86 1
439+#elif __x86_64__
440+# define __HAIKU_ARCH x86_64
441+# define __HAIKU_ARCH_X86_64 1
442+# define __HAIKU_ARCH_64_BIT 1
443 #elif __POWERPC__
444 # define __HAIKU_ARCH ppc
445 # define __HAIKU_ARCH_PPC 1