This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC/PATCH] x86_64 port (attempt 2)


Hans,

A couple of questions/comments.

Is anyone pursuing the gcc patch you mentioned? That patch is pretty old (dated March 2005).

I would have assumed in your patch that you would keep/reuse use some of the i386 assembler routines that you didn't have specific replacements for. For example, you don't have a libm_machine_dir which implements the fast math library routines. You also don't have some other string routines that are implemented in libc/machine/i386. Is there some reason you decided not to do this?

Any requirement for x86_64 libgloss (cygmon)?

I noted a typo in setjmp.h for the __x86_64__ flag (missing a trailing underscore).

-- Jeff J.

Hans Kester wrote:
Here is the revised and now complete port for the x86_64. The
generated and rather big files from aclocal/autoconfig/automake are
not listed as diffs below but can be downloaded from here along with
the other changed files:
http://www.xs4all.nl/~ellips/Newlib/x86_64.tar.bz2

Note that the current GCC does not allow building a x86_64-elf target,
but with this patch you can:
http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01592.html

Regards,

Hans Kester



Index: newlib/ChangeLog
===================================================================
RCS file: /cvs/src/src/newlib/ChangeLog,v
retrieving revision 1.1071
diff -u -r1.1071 ChangeLog
--- newlib/ChangeLog    3 Aug 2007 21:03:40 -0000       1.1071
+++ newlib/ChangeLog    15 Aug 2007 08:53:35 -0000
@@ -1,3 +1,19 @@
+2007-08-10  Hans Kester  <hans.kester@ellips.nl>
+
+       * configure.host: Added support for x86_64.
+       * libc/include/machine/ieeefp.h: Define __IEEE_LITTLE_ENDIAN for x86_64.

+       * libc/include/machine/setjmp.h: Define _JBTYPE and _JBLEN for x86_64.
+       * libc/machine/x86_64/aclocal.m4: Generated.
+       * libc/machine/x86_64/configure.in: New.
+       * libc/machine/x86_64/configure: Generated.
+       * libc/machine/x86_64/Makefile.am: New.
+       * libc/machine/x86_64/Makefile.in: Generated.
+       * libc/machine/x86_64/setjmp.S: New.
+       * libc/machine/x86_64/memcpy.S: New.
+       * libc/machine/x86_64/memset.S: New.
+       * libc/machine/configure.in: Added support for x86_64.
+       * libc/machine/configure: Regenerated.
+
 2007-08-03  Ralf Corsepius  <ralf.corsepius@rtems.org>

* libc/include/tar.h: New.


Index: newlib/configure.host =================================================================== RCS file: /cvs/src/src/newlib/configure.host,v retrieving revision 1.94 diff -u -r1.94 configure.host --- newlib/configure.host 11 May 2007 20:09:00 -0000 1.94 +++ newlib/configure.host 15 Aug 2007 08:54:48 -0000 @@ -156,6 +156,9 @@ ;; esac ;; + x86_64) + machine_dir=x86_64 + ;; ia64*) ;; iq2000)


Index: newlib/libc/include/machine/ieeefp.h =================================================================== RCS file: /cvs/src/src/newlib/libc/include/machine/ieeefp.h,v retrieving revision 1.31 diff -u -r1.31 ieeefp.h --- newlib/libc/include/machine/ieeefp.h 26 Apr 2007 19:23:37 -00001.31 +++ newlib/libc/include/machine/ieeefp.h 15 Aug 2007 08:57:54 -0000 @@ -306,6 +306,10 @@ #define __IEEE_LITTLE_ENDIAN #endif

+#ifdef __x86_64__
+#define __IEEE_LITTLE_ENDIAN
+#endif
+
 #ifndef __IEEE_BIG_ENDIAN
 #ifndef __IEEE_LITTLE_ENDIAN
 #error Endianess not declared!!


Index: newlib/libc/include/machine/setjmp.h =================================================================== RCS file: /cvs/src/src/newlib/libc/include/machine/setjmp.h,v retrieving revision 1.32 diff -u -r1.32 setjmp.h --- newlib/libc/include/machine/setjmp.h 18 Dec 2006 16:48:03 -00001.32 +++ newlib/libc/include/machine/setjmp.h 15 Aug 2007 08:57:54 -0000 @@ -67,6 +67,11 @@ #endif #endif

+#ifdef __x86_64_
+#define _JBTYPE long long
+#define _JBLEN  8
+#endif
+
 #ifdef __i960__
 #define _JBLEN 35
 #endif


=================================================================== RCS file: /cvs/src/src/newlib/libc/machine/configure.in,v retrieving revision 1.7 diff -u -r1.7 configure.in --- newlib/libc/machine/configure.in 24 May 2007 17:33:31 -0000 1.7 +++ newlib/libc/machine/configure.in 15 Aug 2007 08:59:19 -0000 @@ -35,6 +35,7 @@ h8500) AC_CONFIG_SUBDIRS(h8500) ;; hppa) AC_CONFIG_SUBDIRS(hppa) ;; i386) AC_CONFIG_SUBDIRS(i386) ;; + x86_64) AC_CONFIG_SUBDIRS(x86_64) ;; i960) AC_CONFIG_SUBDIRS(i960) ;; iq2000) AC_CONFIG_SUBDIRS(iq2000) ;; m32c) AC_CONFIG_SUBDIRS(m32c) ;;


Index: newlib/libc/machine/x86_64/Makefile.am =================================================================== RCS file: /cvs/src/src/newlib/libc/machine/x86_64/Makefile.am diff -u -N newlib/libc/machine/x86_64/Makefile.am --- /dev/null 2007-08-15 11:13:46.414196600 +0200 +++ newlib/libc/machine/x86_64/Makefile.am 2007-08-14 16:04:30.230005100 +0200 @@ -0,0 +1,16 @@ +## Process this file with automake to generate Makefile.in + +AUTOMAKE_OPTIONS = cygnus + +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) + +AM_CCASFLAGS = $(INCLUDES) + +noinst_LIBRARIES = lib.a + +lib_a_SOURCES = setjmp.S memcpy.S memset.S +lib_a_CCASFLAGS=$(AM_CCASFLAGS) +lib_a_CFLAGS = $(AM_CFLAGS) + +ACLOCAL_AMFLAGS = -I ../../.. -I ../../../.. +CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host



Index: newlib/libc/machine/x86_64/configure.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/x86_64/configure.in
diff -u -N newlib/libc/machine/x86_64/configure.in
--- /dev/null   2007-08-15 11:22:21.919025000 +0200
+++ newlib/libc/machine/x86_64/configure.in     2007-08-15
11:21:10.003598600 +0200
@@ -0,0 +1,14 @@
+dnl This is the newlib/libc/machine/x86_64 configure.in file.
+dnl Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.59)
+AC_INIT([newlib],[NEWLIB_VERSION])
+AC_CONFIG_SRCDIR([Makefile.am])
+
+dnl Can't be done in NEWLIB_CONFIGURE because that confuses automake.
+AC_CONFIG_AUX_DIR(../../../..)
+
+NEWLIB_CONFIGURE(../../..)
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT



Index: newlib/libc/machine/x86_64/setjmp.S
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/x86_64/setjmp.S
diff -u -N newlib/libc/machine/x86_64/setjmp.S
--- /dev/null   2007-08-15 11:23:28.200946400 +0200
+++ newlib/libc/machine/x86_64/setjmp.S 2007-08-14 16:50:18.480450200 +0200
@@ -0,0 +1,53 @@
+/*
+ * ====================================================
+ * Copyright (C) 2007 by Ellips BV. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+ /*
+ **  jmp_buf:
+ **   rbx rbp r12 r13 r14 r15 rsp rip
+ **   0   8   16  24  32  40  48  56
+ */
+
+  #include "x86_64mach.h"
+
+  .global SYM (setjmp)
+  .global SYM (longjmp)
+  SOTYPE_FUNCTION(setjmp)
+  SOTYPE_FUNCTION(longjmp)
+
+SYM (setjmp):
+  movq    rbx,  0 (rdi)
+  movq    rbp,  8 (rdi)
+  movq    r12, 16 (rdi)
+  movq    r13, 24 (rdi)
+  movq    r14, 32 (rdi)
+  movq    r15, 40 (rdi)
+  leaq    8 (rsp), rax
+  movq    rax, 48 (rdi)
+  movq    (rsp), rax
+  movq    rax, 56 (rdi)
+  movq    $0, rax
+  ret
+
+SYM (longjmp):
+  movq    rsi, rax        /* Return value */
+
+  movq     8 (rdi), rbp
+
+  __CLI
+  movq    48 (rdi), rsp
+  pushq   56 (rdi)
+  movq     0 (rdi), rbx
+  movq    16 (rdi), r12
+  movq    24 (rdi), r13
+  movq    32 (rdi), r14
+  movq    40 (rdi), r15
+  __STI
+
+  ret


Index: newlib/libc/machine/x86_64/memcpy.S =================================================================== RCS file: /cvs/src/src/newlib/libc/machine/x86_64/memcpy.S diff -u -N newlib/libc/machine/x86_64/memcpy.S --- /dev/null 2007-08-15 11:25:56.230053800 +0200 +++ newlib/libc/machine/x86_64/memcpy.S 2007-08-14 15:37:53.662509100 +0200 @@ -0,0 +1,113 @@ +/* + * ==================================================== + * Copyright (C) 2007 by Ellips BV. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + + #include "x86_64mach.h" + + .global SYM (memcpy) + SOTYPE_FUNCTION(memcpy) + +SYM (memcpy): + movq rdi, rax /* Store destination in return value */ + cmpq $16, rdx + jb byte_copy + + movq rdi, r8 /* Align destination on quad word boundary */

+  andq    $7, r8
+  jz      quadword_aligned
+  movq    $8, rcx
+  subq    r8, rcx
+  subq    rcx, rdx
+  rep     movsb
+
+quadword_aligned:
+  cmpq    $256, rdx
+  jb      quadword_copy
+
+  movq    rax, -8  (rsp)
+  movq    r12, -16 (rsp)
+  movq    r13, -24 (rsp)
+  movq    r14, -32 (rsp)
+
+  movq    rdx, rcx                /* Copy 128 bytes at a time with minimum cach
e polution */
+  shrq    $7, rcx
+
+  .p2align 4
+loop:
+  prefetchnta   768 (rsi)
+  prefetchnta   832 (rsi)
+
+  movq       (rsi), rax
+  movq     8 (rsi), r8
+  movq    16 (rsi), r9
+  movq    24 (rsi), r10
+  movq    32 (rsi), r11
+  movq    40 (rsi), r12
+  movq    48 (rsi), r13
+  movq    56 (rsi), r14
+
+  movntiq rax,    (rdi)
+  movntiq r8 ,  8 (rdi)
+  movntiq r9 , 16 (rdi)
+  movntiq r10, 24 (rdi)
+  movntiq r11, 32 (rdi)
+  movntiq r12, 40 (rdi)
+  movntiq r13, 48 (rdi)
+  movntiq r14, 56 (rdi)
+
+  movq     64 (rsi), rax
+  movq     72 (rsi), r8
+  movq     80 (rsi), r9
+  movq     88 (rsi), r10
+  movq     96 (rsi), r11
+  movq    104 (rsi), r12
+  movq    112 (rsi), r13
+  movq    120 (rsi), r14
+
+  movntiq rax,  64 (rdi)
+  movntiq r8 ,  72 (rdi)
+  movntiq r9 ,  80 (rdi)
+  movntiq r10,  88 (rdi)
+  movntiq r11,  96 (rdi)
+  movntiq r12, 104 (rdi)
+  movntiq r13, 112 (rdi)
+  movntiq r14, 120 (rdi)
+
+  leaq    128 (rsi), rsi
+  leaq    128 (rdi), rdi
+
+  dec     rcx
+  jnz     loop
+
+  sfence
+  movq    rdx, rcx
+  andq    $127, rcx
+  rep     movsb
+  movq    -8  (rsp), rax
+  movq    -16 (rsp), r12
+  movq    -24 (rsp), r13
+  movq    -32 (rsp), r14
+  ret
+
+
+byte_copy:
+  movq    rdx, rcx
+  rep     movsb
+  ret
+
+
+quadword_copy:
+  movq    rdx, rcx
+  shrq    $3, rcx
+  .p2align 4
+  rep     movsq
+  movq    rdx, rcx
+  andq    $7, rcx
+  rep     movsb                   /* Copy the remaining bytes */
+  ret


Index: newlib/libc/machine/x86_64/memset.S =================================================================== RCS file: /cvs/src/src/newlib/libc/machine/x86_64/memset.S diff -u -N newlib/libc/machine/x86_64/memset.S --- /dev/null 2007-08-15 11:27:28.060279800 +0200 +++ newlib/libc/machine/x86_64/memset.S 2007-08-14 16:11:09.325121100 +0200 @@ -0,0 +1,88 @@ +/* + * ==================================================== + * Copyright (C) 2007 by Ellips BV. All rights reserved. + * + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + + #include "x86_64mach.h" + + .global SYM (memset) + SOTYPE_FUNCTION(memset) + +SYM (memset): + movq rdi, r9 /* Save return value */ + movq rsi, rax + movq rdx, rcx + cmpq $16, rdx + jb byte_set + + movq rdi, r8 /* Align on quad word boundary */ + andq $7, r8 + jz quadword_aligned + movq $8, rcx + subq r8, rcx + subq rcx, rdx + rep stosb + movq rdx, rcx + +quadword_aligned: + movabs $0x0101010101010101, r8 + movzbl sil, eax + imul r8, rax + cmpq $256, rdx + jb quadword_set + + shrq $7, rcx /* Store 128 bytes at a time with minimum cac he polution */ + + .p2align 4 +loop: + movntiq rax, (rdi) + movntiq rax, 8 (rdi) + movntiq rax, 16 (rdi) + movntiq rax, 24 (rdi) + movntiq rax, 32 (rdi) + movntiq rax, 40 (rdi) + movntiq rax, 48 (rdi) + movntiq rax, 56 (rdi) + movntiq rax, 64 (rdi) + movntiq rax, 72 (rdi) + movntiq rax, 80 (rdi) + movntiq rax, 88 (rdi) + movntiq rax, 96 (rdi) + movntiq rax, 104 (rdi) + movntiq rax, 112 (rdi) + movntiq rax, 120 (rdi) + + leaq 128 (rdi), rdi + + dec rcx + jnz loop + + sfence + movq rdx, rcx + andq $127, rcx + rep stosb + movq r9, rax + ret + + +byte_set: + rep stosb + movq r9, rax + ret + + +quadword_set: + shrq $3, rcx + .p2align 4 + rep stosq + movq rdx, rcx + andq $7, rcx + rep stosb /* Store the remaining bytes */ + movq r9, rax + ret +


Index: newlib/libc/machine/x86_64/x86_64mach.h =================================================================== RCS file: /cvs/src/src/newlib/libc/machine/x86_64/x86_64mach.h diff -u -N newlib/libc/machine/x86_64/x86_64mach.h --- /dev/null 2007-08-15 11:40:31.116537800 +0200 +++ newlib/libc/machine/x86_64/x86_64mach.h 2007-08-14 16:10:54.362561100 +0200 @@ -0,0 +1,113 @@ +/* + ** This file is distributed WITHOUT ANY WARRANTY; without even the implied + ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifndef __USER_LABEL_PREFIX__ +#define __USER_LABEL_PREFIX__ _ +#endif + +#define __REG_PREFIX__ % + +/* ANSI concatenation macros. */ + +#define CONCAT1(a, b) CONCAT2(a, b) +#define CONCAT2(a, b) a##b + +/* Use the right prefix for global labels. */ + +#define SYM(x) CONCAT1(__USER_LABEL_PREFIX__, x) + +/* Use the right prefix for registers. */ + +#define REG(x) CONCAT1(__REG_PREFIX__, x) + +#define rax REG(rax) +#define rbx REG(rbx) +#define rcx REG(rcx) +#define rdx REG(rdx) +#define rsi REG(rsi) +#define rdi REG(rdi) +#define rbp REG(rbp) +#define rsp REG(rsp) + +#define r8 REG(r8) +#define r9 REG(r9) +#define r10 REG(r10) +#define r11 REG(r11) +#define r12 REG(r12) +#define r13 REG(r13) +#define r14 REG(r14) +#define r15 REG(r15) + +#define eax REG(eax) +#define ebx REG(ebx) +#define ecx REG(ecx) +#define edx REG(edx) +#define esi REG(esi) +#define edi REG(edi) +#define ebp REG(ebp) +#define esp REG(esp) + +#define st0 REG(st) +#define st1 REG(st(1)) +#define st2 REG(st(2)) +#define st3 REG(st(3)) +#define st4 REG(st(4)) +#define st5 REG(st(5)) +#define st6 REG(st(6)) +#define st7 REG(st(7)) + +#define ax REG(ax) +#define bx REG(bx) +#define cx REG(cx) +#define dx REG(dx) + +#define ah REG(ah) +#define bh REG(bh) +#define ch REG(ch) +#define dh REG(dh) + +#define al REG(al) +#define bl REG(bl) +#define cl REG(cl) +#define dl REG(dl) + +#define sil REG(sil) + +#define mm1 REG(mm1) +#define mm2 REG(mm2) +#define mm3 REG(mm3) +#define mm4 REG(mm4) +#define mm5 REG(mm5) +#define mm6 REG(mm6) +#define mm7 REG(mm7) + +#define xmm0 REG(xmm0) +#define xmm1 REG(xmm1) +#define xmm2 REG(xmm2) +#define xmm3 REG(xmm3) +#define xmm4 REG(xmm4) +#define xmm5 REG(xmm5) +#define xmm6 REG(xmm6) +#define xmm7 REG(xmm7) + +#define cr0 REG(cr0) +#define cr1 REG(cr1) +#define cr2 REG(cr2) +#define cr3 REG(cr3) +#define cr4 REG(cr4) + +#ifdef _I386MACH_NEED_SOTYPE_FUNCTION +#define SOTYPE_FUNCTION(sym) .type SYM(sym),@function +#else +#define SOTYPE_FUNCTION(sym) +#endif + +#ifdef _I386MACH_ALLOW_HW_INTERRUPTS +#define __CLI +#define __STI +#else +#define __CLI cli +#define __STI sti +#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]