From: Steve Munroe <sjmunroe@us.ibm.com>
To: libc-hacker@sources.redhat.com
Cc: Paul Mackerras <paulus@samba.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH] PPC enable Alitvec hardware, part 1
Date: Sat, 10 Jan 2004 20:31:00 -0000 [thread overview]
Message-ID: <40006121.9070903@us.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 524 bytes --]
The attached patch provides base enabling for PowerPC Altivec (AKA VMX)
and for versioning effected functions. 2.6.0 kernels provide a
PPC_FEATURE_HAS_ALTIVEC status in the AT_HWCAP. We need to capture this
status as a static flag (__has_altivec) so functions enabled for altivec
can run safely on PowerPC hardware without the Altivec feature.
And now for the fun part. I think this requires a new glibc version
because GLIBC_2.3.3 symbols are already defined for these
(get/setcontext) functions in shipped distros.
[-- Attachment #2: ppcvmx-base-20040104.txt --]
[-- Type: text/plain, Size: 11895 bytes --]
2004-01-09 Steven Munroe <sjmunroe@us.ibm.com>
* elf/elf.h: Define PPC_FEATURE_* masks for Aux Vector AT_HWCAP.
* include/libc-symbols.h [HAVE_ASM_GLOBAL_DOT_NAME]
(_symbol_version): Use C_SYMBOL_DOT_NAME to create '.'ed symbols.
(_default_symbol_version): Use C_SYMBOL_DOT_NAME to create '.'ed
symbols.
* sysdeps/powerpc/Versions: Add __has_altivec symbol for GLIBC_2.3.4.
* sysdeps/powerpc/elf/libc-start.c [!SHARED]: Add extern for
__has_altivec.
(libc_start_main)[!SHARED]: Initialize __has_altivec from dl_hwcap.
* sysdeps/powerpc/longjmp.c: New file.
* sysdeps/powerpc/sysdep.h: Define v# symbols for vector registers.
* sysdeps/unix/sysv/linux/kernel-features.h
(__ASSUME_ALTIVEC_SIGCONTEXT): Define for PPC and 2.6.0 kernels.
* sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c (DL_PLATFORM_INIT):
Initialize __has_altivec from dl_hwcap.
* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
[!__ASSUME_ALTIVEC_SIGCONTEXT]: Insure altivec state is defined in
sigcontext for old kernels.
diff -urN libc23-cvstip-20040102/elf/elf.h libc23/elf/elf.h
--- libc23-cvstip-20040102/elf/elf.h 2003-12-29 12:50:21.000000000 -0600
+++ libc23/elf/elf.h 2004-01-07 14:25:55.000000000 -0600
@@ -1854,6 +1854,17 @@
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
flag */
+/* from linux/asm/cputable.h. */
+#define PPC_FEATURE_32 0x80000000
+#define PPC_FEATURE_64 0x40000000
+#define PPC_FEATURE_601_INSTR 0x20000000
+#define PPC_FEATURE_HAS_ALTIVEC 0x10000000
+#define PPC_FEATURE_HAS_FPU 0x08000000
+#define PPC_FEATURE_HAS_MMU 0x04000000
+#define PPC_FEATURE_HAS_4xxMAC 0x02000000
+#define PPC_FEATURE_UNIFIED_CACHE 0x01000000
+
+
/* PowerPC relocations defined by the ABIs */
#define R_PPC_NONE 0
diff -urN libc23-cvstip-20040102/include/libc-symbols.h libc23/include/libc-symbols.h
--- libc23-cvstip-20040102/include/libc-symbols.h 2003-07-22 14:24:48.000000000 -0500
+++ libc23/include/libc-symbols.h 2004-01-07 14:25:55.000000000 -0600
@@ -420,10 +420,10 @@
# ifdef HAVE_ASM_GLOBAL_DOT_NAME
# define _symbol_version(real, name, version) \
.symver real, name##@##version ASM_LINE_SEP \
- .symver .##real, .##name##@##version
+ .symver C_SYMBOL_DOT_NAME(real), C_SYMBOL_DOT_NAME(name##@##version)
# define _default_symbol_version(real, name, version) \
.symver real, name##@##@##version ASM_LINE_SEP \
- .symver .##real, .##name##@##@##version
+ .symver C_SYMBOL_DOT_NAME(real), C_SYMBOL_DOT_NAME(name##@##@##version)
# else
# define _symbol_version(real, name, version) \
.symver real, name##@##version
diff -urN libc23-cvstip-20040102/sysdeps/powerpc/Versions libc23/sysdeps/powerpc/Versions
--- libc23-cvstip-20040102/sysdeps/powerpc/Versions 2002-09-05 04:54:59.000000000 -0500
+++ libc23/sysdeps/powerpc/Versions 2004-01-10 11:29:00.000000000 -0600
@@ -4,3 +4,9 @@
__fe_dfl_env; __fe_enabled_env; __fe_nonieee_env; __fe_nomask_env;
}
}
+
+ld {
+ GLIBC_2.3.4 {
+ __has_altivec;
+ }
+}
diff -urN libc23-cvstip-20040102/sysdeps/powerpc/elf/libc-start.c libc23/sysdeps/powerpc/elf/libc-start.c
--- libc23-cvstip-20040102/sysdeps/powerpc/elf/libc-start.c 2003-03-15 17:09:18.000000000 -0600
+++ libc23/sysdeps/powerpc/elf/libc-start.c 2004-01-07 14:25:55.000000000 -0600
@@ -25,6 +25,10 @@
extern int __cache_line_size;
weak_extern (__cache_line_size)
+#ifndef SHARED
+extern int __has_altivec;
+#endif
+
/* Scan the Aux Vector for the "Data Cache Block Size" entry. If found
verify that the static extern __cache_line_size is defined by checking
for not NULL. If it is defined then assign the cache block size
@@ -104,7 +108,9 @@
/* Initialize the __cache_line_size variable from the aux vector. */
__aux_init_cache (auxvec);
-
+#ifndef SHARED
+ __has_altivec=((GL(dl_hwcap) & PPC_FEATURE_HAS_ALTIVEC) ? 1:0);
+#endif
return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
stinfo->init, stinfo->fini, rtld_fini,
stack_on_entry);
diff -urN libc23-cvstip-20040102/sysdeps/powerpc/longjmp.c libc23/sysdeps/powerpc/longjmp.c
--- libc23-cvstip-20040102/sysdeps/powerpc/longjmp.c Wed Dec 31 18:00:00 1969
+++ libc23/sysdeps/powerpc/longjmp.c Sat Jan 10 11:29:58 2004
@@ -0,0 +1,56 @@
+/* Copyright (C) 1991,92,94,95,97,98,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+/*
+ Versioned copy of sysdeps/generic/longjmp.c modified for altivec support.
+ */
+#include <shlib-compat.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <signal.h>
+
+#if defined(NOT_IN_libc) || !defined(SHARED)
+/* We don't want this variable both in ld.so & libc.so as
+ we would then have duplicate variable linker confusion. */
+int vec__has_altivec=0;
+default_symbol_version (vec__has_altivec,__has_altivec,GLIBC_2.3.4);
+#endif
+
+/* Set the signal mask to the one specified in ENV, and jump
+ to the position specified in ENV, causing the setjmp
+ call there to return VAL, or 1 if VAL is 0. */
+void
+__libc_siglongjmp (sigjmp_buf env, int val)
+{
+ /* Perform any cleanups needed by the frames being unwound. */
+ _longjmp_unwind (env, val);
+
+ if (env[0].__mask_was_saved)
+ /* Restore the saved signal mask. */
+ (void) __sigprocmask (SIG_SETMASK, &env[0].__saved_mask,
+ (sigset_t *) NULL);
+
+ /* Call the machine-dependent function to restore machine state. */
+ __longjmp (env[0].__jmpbuf, val ?: 1);
+}
+
+strong_alias (__libc_siglongjmp, __libc_longjmp)
+libc_hidden_def (__libc_longjmp)
+weak_alias (__libc_siglongjmp, _longjmp)
+weak_alias (__libc_siglongjmp, longjmp)
+weak_alias (__libc_siglongjmp, siglongjmp)
+
diff -urN libc23-cvstip-20040102/sysdeps/powerpc/sysdep.h libc23/sysdeps/powerpc/sysdep.h
--- libc23-cvstip-20040102/sysdeps/powerpc/sysdep.h 2002-09-20 18:44:55.000000000 -0500
+++ libc23/sysdeps/powerpc/sysdep.h 2004-01-07 14:25:55.000000000 -0600
@@ -100,6 +100,42 @@
#define cr6 6
#define cr7 7
+/* Vector registers. */
+#define v0 0
+#define v1 1
+#define v2 2
+#define v3 3
+#define v4 4
+#define v5 5
+#define v6 6
+#define v7 7
+#define v8 8
+#define v9 9
+#define v10 10
+#define v11 11
+#define v12 12
+#define v13 13
+#define v14 14
+#define v15 15
+#define v16 16
+#define v17 17
+#define v18 18
+#define v19 19
+#define v20 20
+#define v21 21
+#define v22 22
+#define v23 23
+#define v24 24
+#define v25 25
+#define v26 26
+#define v27 27
+#define v28 28
+#define v29 29
+#define v30 30
+#define v31 31
+
+#define VRSAVE 256
+
#ifdef __ELF__
diff -urN libc23-cvstip-20040102/sysdeps/unix/sysv/linux/kernel-features.h libc23/sysdeps/unix/sysv/linux/kernel-features.h
--- libc23-cvstip-20040102/sysdeps/unix/sysv/linux/kernel-features.h 2003-12-11 22:31:39.000000000 -0600
+++ libc23/sysdeps/unix/sysv/linux/kernel-features.h 2004-01-09 19:38:30.000000000 -0600
@@ -247,6 +247,15 @@
# define __ASSUME_NEW_RT_SIGRETURN_SYSCALL 1
#endif
+/* Starting with 2.6.0 PowerPC adds signal/swapcontext support for Vector
+ SIMD (AKA Altivec, VMX) instructions and register state. This changes
+ the overall size of the sigcontext and adds the swapcontext syscall.
+ This requires versioning of the setjmp/longjmp and get/make/set/swapcontext
+ functions */
+#if __LINUX_KERNEL_VERSION >= (132608) && defined __powerpc__
+# define __ASSUME_ALTIVEC_SIGCONTEXT 1
+#endif
+
/* On x86, the set_thread_area syscall was introduced in 2.5.29, but its
semantics was changed in 2.5.30, and again after 2.5.31. */
#if __LINUX_KERNEL_VERSION >= 132384 && defined __i386__
diff -urN libc23-cvstip-20040102/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c libc23/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c
--- libc23-cvstip-20040102/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c 2003-03-15 18:40:44.000000000 -0600
+++ libc23/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.c 2004-01-07 14:25:55.000000000 -0600
@@ -69,4 +69,8 @@
} while (0)
#endif
+int __has_altivec=0;
+#define DL_PLATFORM_INIT \
+__has_altivec=((GL(dl_hwcap) & PPC_FEATURE_HAS_ALTIVEC) ? 1:0);
+
#include <sysdeps/unix/sysv/linux/dl-sysdep.c>
diff -urN libc23-cvstip-20040102/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h libc23/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
--- libc23-cvstip-20040102/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h 2003-12-17 17:11:15.000000000 -0600
+++ libc23/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h 2004-01-10 12:34:56.000000000 -0600
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -29,7 +29,7 @@
#if __WORDSIZE == 32
/* Number of general registers. */
-#define NGREG 48
+# define NGREG 48
/* Container for all general registers. */
typedef unsigned long gregset_t[NGREG];
@@ -62,8 +62,53 @@
#else
-/* For 64-bit, a machine context is exactly a sigcontext. */
+# ifdef __ASSUME_ALTIVEC_SIGCONTEXT
+/* For 64-bit kernels with Altivec support, a machine context is exactly
+ a sigcontext. */
typedef struct sigcontext mcontext_t;
+# else
+/* We have old kernel headers. So we need to allocate space for the
+ Altivec state here so programs will run correctly when they do run
+ a new kernel. */
+
+#include <asm/types.h>
+
+typedef __vector128 elf_vrreg_t;
+
+struct vmx_sigcontext {
+ unsigned long _unused[4];
+ int signal;
+ int _pad0;
+ unsigned long handler;
+ unsigned long oldmask;
+ struct pt_regs *regs;
+ elf_gregset_t gp_regs;
+ elf_fpregset_t fp_regs;
+/*
+ * To maintain compatibility with current implementations the sigcontext is
+ * extended by appending a pointer (v_regs) to a quadword type (elf_vrreg_t)
+ * followed by an unstructured (vmx_reserve) field of 69 doublewords. This
+ * allows the array of vector registers to be quadword aligned independent of
+ * the alignment of the containing sigcontext or ucontext. It is the
+ * responsibility of the code setting the sigcontext to set this pointer to
+ * either NULL (if this processor does not support the VMX feature) or the
+ * address of the first quadword within the allocated (vmx_reserve) area.
+ *
+ * The pointer (v_regs) of vector type (elf_vrreg_t) is type compatible with
+ * an array of 34 quadword entries (elf_vrregset_t). The entries with
+ * indexes 0-31 contain the corresponding vector registers. The entry with
+ * index 32 contains the vscr as the last word (offset 12) within the
+ * quadword. This allows the vscr to be stored as either a quadword (since
+ * it must be copied via a vector register to/from storage) or as a word.
+ * The entry with index 33 contains the vrsave as the first word (offset 0)
+ * within the quadword.
+ */
+ elf_vrreg_t *v_regs;
+ long vmx_reserve[69];
+};
+
+typedef struct vmx_sigcontext mcontext_t;
+# endif
#endif
next reply other threads:[~2004-01-10 20:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-10 20:31 Steve Munroe [this message]
2004-01-10 21:11 ` Roland McGrath
2004-01-11 17:32 ` Andreas Jaeger
2004-01-11 16:41 Steve Munroe
2004-01-11 18:21 ` Ulrich Drepper
2004-01-11 18:45 Steve Munroe
2004-01-11 18:52 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40006121.9070903@us.ibm.com \
--to=sjmunroe@us.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=libc-hacker@sources.redhat.com \
--cc=paulus@samba.org \
--cc=sjmunroe@vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).