This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

PATCH [2/n]: Add x32 sysdep.h file


Hi,

This patch does:

1. Move all VSYSCALL_ADDR_xxx to a single location x86_64/sysdep.h.
2. Remove the `q' suffix from xor/rol instructions in x86_64 PTR_MANGLE
and PTR_DEMANGLE so that they work for both 32bit registers under x32
and 64bit registers under x86_64.
3. Add LP_SIZE, MOVE_LP, ADD_LP, SUB_LP, CMP_LP and ASM_ADDR to support
both 32bit and 64bit long/pointer sizes in assembly codes.
4. Add RXX_LP for registers used as longs and pointers in assembly
codes.
5. Add x32 system call macros to support 32bit error returns in system
calls.  For a few system calls which returns 64bit integer,
SYSCALL_RETURN_INT64 is used to set up properly 64bit error return values.


H.J.
--
2012-03-15  H.J. Lu  <hongjiu.lu@intel.com>

	* sysdeps/unix/sysv/linux/x86_64/sysdep.h
	(VSYSCALL_ADDR_vgettimeofday): New.
	(VSYSCALL_ADDR_vtime): Likewise.
	(VSYSCALL_ADDR_vgetcpu): Likewise.
	(PTR_MANGLE): Remove the `q' suffix from xor/rol instructions.
	(PTR_DEMANGLE): Likewise.

	* sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
	(VSYSCALL_ADDR_vgettimeofday): Removed.
	* sysdeps/unix/sysv/linux/x86_64/init-first.c
	(VSYSCALL_ADDR_vgetcpu): Likewise.
	* sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
	(VSYSCALL_ADDR_vgetcpu): Likewise.
	* sysdeps/unix/sysv/linux/x86_64/time.c (VSYSCALL_ADDR_vtime):
	Likewise.

	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h: New.
	* sysdeps/x86_64/x32/sysdep.h: Likewise.

	* sysdeps/x86_64/sysdep.h (LP_SIZE): New.
	(MOVE_LP): Likewise.
	(ADD_LP): Likewise.
	(SUB_LP): Likewise.
	(CMP_LP): Likewise.
	(ASM_ADDR): Likewise.
	(RAX_LP): New.
	(RBP_LP): Likewise.
	(RBX_LP): Likewise.
	(RCX_LP): Likewise.
	(RDI_LP): Likewise.
	(RSI_LP): Likewise.
	(RSP_LP): Likewise.
	(R8_LP): Likewise.
	(R9_LP): Likewise.
	(R10_LP): Likewise.
	(R10_LP): Likewise.
	(R11_LP): Likewise.
	(R12_LP): Likewise.
	(R13_LP): Likewise.
	(R14_LP): Likewise.
	(R15_LP): Likewise.
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
index e41fddb..57cd072 100644
--- a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
@@ -17,10 +17,6 @@
 
 #include <dl-vdso.h>
 
-
-#define VSYSCALL_ADDR_vgettimeofday	0xffffffffff600000ul
-
-
 #ifdef SHARED
 void *gettimeofday_ifunc (void) __asm__ ("__gettimeofday");
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c
index e8b52ea..719dadc 100644
--- a/sysdeps/unix/sysv/linux/x86_64/init-first.c
+++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c
@@ -44,7 +44,6 @@ _libc_vdso_platform_setup (void)
 
   p = _dl_vdso_vsym ("__vdso_getcpu", &linux26);
   /* If the vDSO is not available we fall back on the old vsyscall.  */
-#define VSYSCALL_ADDR_vgetcpu	0xffffffffff600800
   if (p == NULL)
     p = (void *) VSYSCALL_ADDR_vgetcpu;
   PTR_MANGLE (p);
diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
index 4c3cebe..0e5a7bc 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
+++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
@@ -21,10 +21,6 @@
 #include <bits/errno.h>
 #include <kernel-features.h>
 
-/* For the calculation see asm/vsyscall.h.  */
-#define VSYSCALL_ADDR_vgetcpu	0xffffffffff600800
-
-
 ENTRY (sched_getcpu)
 	/* Align stack and create local variable for result.  */
 	sub	$0x8, %rsp
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index c9c4dbd..dc9c5fe 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -189,6 +189,11 @@
 # define DOARGS_5 DOARGS_4
 # define DOARGS_6 DOARGS_5
 
+/* For the calculation see asm/vsyscall.h.  */
+# define VSYSCALL_ADDR_vgettimeofday	0xffffffffff600000
+# define VSYSCALL_ADDR_vtime		0xffffffffff600400
+# define VSYSCALL_ADDR_vgetcpu		0xffffffffff600800
+
 #else	/* !__ASSEMBLER__ */
 /* Define a macro which expands inline into the wrapper code for a system
    call.  */
@@ -334,6 +339,11 @@
   LOAD_REGS_5
 # define ASM_ARGS_6	ASM_ARGS_5, "r" (_a6)
 
+/* For the calculation see asm/vsyscall.h.  */
+# define VSYSCALL_ADDR_vgettimeofday	0xffffffffff600000ul
+# define VSYSCALL_ADDR_vgetcpu		0xffffffffff600800ul
+# define VSYSCALL_ADDR_vtime		0xffffffffff600400ul
+
 #endif	/* __ASSEMBLER__ */
 
 
@@ -342,33 +352,33 @@
 /* We cannot use the thread descriptor because in ld.so we use setjmp
    earlier than the descriptor is initialized.  */
 # ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg)	xorq __pointer_chk_guard_local(%rip), reg;    \
-				rolq $17, reg
-#  define PTR_DEMANGLE(reg)	rorq $17, reg;				      \
-				xorq __pointer_chk_guard_local(%rip), reg
+#  define PTR_MANGLE(reg)	xor __pointer_chk_guard_local(%rip), reg;    \
+				rol $17, reg
+#  define PTR_DEMANGLE(reg)	ror $17, reg;				      \
+				xor __pointer_chk_guard_local(%rip), reg
 # else
-#  define PTR_MANGLE(reg)	asm ("xorq __pointer_chk_guard_local(%%rip), %0\n" \
-				     "rolq $17, %0"			      \
+#  define PTR_MANGLE(reg)	asm ("xor __pointer_chk_guard_local(%%rip), %0\n" \
+				     "rol $17, %0"			      \
 				     : "=r" (reg) : "0" (reg))
-#  define PTR_DEMANGLE(reg)	asm ("rorq $17, %0\n"			      \
-				     "xorq __pointer_chk_guard_local(%%rip), %0" \
+#  define PTR_DEMANGLE(reg)	asm ("ror $17, %0\n"			      \
+				     "xor __pointer_chk_guard_local(%%rip), %0" \
 				     : "=r" (reg) : "0" (reg))
 # endif
 #else
 # ifdef __ASSEMBLER__
-#  define PTR_MANGLE(reg)	xorq %fs:POINTER_GUARD, reg;		      \
-				rolq $17, reg
-#  define PTR_DEMANGLE(reg)	rorq $17, reg;				      \
-				xorq %fs:POINTER_GUARD, reg
+#  define PTR_MANGLE(reg)	xor %fs:POINTER_GUARD, reg;		      \
+				rol $17, reg
+#  define PTR_DEMANGLE(reg)	ror $17, reg;				      \
+				xor %fs:POINTER_GUARD, reg
 # else
-#  define PTR_MANGLE(var)	asm ("xorq %%fs:%c2, %0\n"		      \
-				     "rolq $17, %0"			      \
+#  define PTR_MANGLE(var)	asm ("xor %%fs:%c2, %0\n"		      \
+				     "rol $17, %0"			      \
 				     : "=r" (var)			      \
 				     : "0" (var),			      \
 				       "i" (offsetof (tcbhead_t,	      \
 						      pointer_guard)))
-#  define PTR_DEMANGLE(var)	asm ("rorq $17, %0\n"			      \
-				     "xorq %%fs:%c2, %0"		      \
+#  define PTR_DEMANGLE(var)	asm ("ror $17, %0\n"			      \
+				     "xor %%fs:%c2, %0"		      \
 				     : "=r" (var)			      \
 				     : "0" (var),			      \
 				       "i" (offsetof (tcbhead_t,	      \
diff --git a/sysdeps/unix/sysv/linux/x86_64/time.c b/sysdeps/unix/sysv/linux/x86_64/time.c
index 0e05ddd..54c8e29 100644
--- a/sysdeps/unix/sysv/linux/x86_64/time.c
+++ b/sysdeps/unix/sysv/linux/x86_64/time.c
@@ -18,8 +18,6 @@
 #ifdef SHARED
 #include <dl-vdso.h>
 
-#define VSYSCALL_ADDR_vtime	0xffffffffff600400
-
 void *time_ifunc (void) __asm__ ("time");
 
 void *
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
new file mode 100644
index 0000000..15b67b4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
@@ -0,0 +1,60 @@
+/* Copyright (C) 2011 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.  */
+
+#ifndef _LINUX_X32_SYSDEP_H
+#define _LINUX_X32_SYSDEP_H 1
+
+/* There is some commonality.  */
+#include <sysdeps/unix/sysv/linux/x86_64/sysdep.h>
+#include <sysdeps/x86_64/x32/sysdep.h>
+
+#ifdef __ASSEMBLER__
+
+# ifdef SYSCALL_RETURN_INT64
+#  define SYSCALL_SET_ERROR_RETURN orq $-1, %rax
+# else
+#  define SYSCALL_SET_ERROR_RETURN orl $-1, %eax
+# endif
+
+# ifndef PIC
+/* Nothing here.  */
+# elif RTLD_PRIVATE_ERRNO
+#  undef SYSCALL_ERROR_HANDLER
+#  define SYSCALL_ERROR_HANDLER			\
+0:						\
+  lea rtld_errno(%rip), %ecx;			\
+  xorl %edx, %edx;				\
+  subl %eax, %edx;				\
+  movl %edx, (%rcx);				\
+  SYSCALL_SET_ERROR_RETURN;			\
+  jmp L(pseudo_end);
+# else
+#  undef SYSCALL_ERROR_HANDLER
+#  define SYSCALL_ERROR_HANDLER			\
+0:						\
+  movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx;\
+  xorl %edx, %edx;				\
+  subl %eax, %edx;				\
+  movl %edx, %fs:(%rcx);			\
+  SYSCALL_SET_ERROR_RETURN;			\
+  jmp L(pseudo_end);
+# endif	/* PIC */
+
+#endif	/* __ASSEMBLER__ */
+
+#endif /* linux/x86_64/x32/sysdep.h */
diff --git a/sysdeps/x86_64/sysdep.h b/sysdeps/x86_64/sysdep.h
index e455c60..466abff 100644
--- a/sysdeps/x86_64/sysdep.h
+++ b/sysdeps/x86_64/sysdep.h
@@ -95,4 +95,66 @@ lose:									      \
 
 #define atom_text_section .section ".text.atom", "ax"
 
+/* Long and pointer size in bytes.  */
+#define LP_SIZE	8
+
+/* Instruction to move long and pointer.  */
+#define MOVE_LP movq
+
+/* Instruction to add long and pointer.  */
+#define ADD_LP addq
+
+/* Instruction to substract long and pointer.  */
+#define SUB_LP subq
+
+/* Instruction to compare against long and pointer.  */
+#define CMP_LP cmpq
+
+/* Assembler address directive. */
+#define ASM_ADDR .quad
+
+/* Registers to hold long and pointer.  */
+#define RAX_LP	rax
+#define RBP_LP	rbp
+#define RBX_LP	rbx
+#define RCX_LP	rcx
+#define RDI_LP	rdi
+#define RDX_LP	rdx
+#define RSI_LP	rsi
+#define RSP_LP	rsp
+#define R8_LP	r8
+#define R9_LP	r9
+#define R10_LP	r10
+#define R11_LP	r11
+#define R12_LP	r12
+#define R13_LP	r13
+#define R14_LP	r14
+#define R15_LP	r15
+
+#else	/* __ASSEMBLER__ */
+
+/* Long and pointer size in bytes.  */
+#define LP_SIZE "8"
+
+/* Assembler address directive. */
+#define ASM_ADDR ".quad"
+
+/* Registers to hold long and pointer.  */
+#define RAX_LP	"rax"
+#define RBP_LP	"rbp"
+#define RBX_LP	"rbx"
+#define RCX_LP	"rcx"
+#define RDI_LP	"rdi"
+#define RDX_LP	"rdx"
+#define RSI_LP	"rsi"
+#define RSP_LP	"rsp"
+#define R8_LP	"r8"
+#define R9_LP	"r9"
+#define R10_LP	"r10"
+#define R11_LP	"r11"
+#define R12_LP	"r12"
+#define R13_LP	"r13"
+#define R14_LP	"r14"
+#define R15_LP	"r15"
+
 #endif	/* __ASSEMBLER__ */
diff --git a/sysdeps/x86_64/x32/sysdep.h b/sysdeps/x86_64/x32/sysdep.h
new file mode 100644
index 0000000..0bb21f8
--- /dev/null
+++ b/sysdeps/x86_64/x32/sysdep.h
@@ -0,0 +1,98 @@
+/* Assembler macros for x32.
+   Copyright (C) 2011 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.  */
+
+#undef ASM_ADDR
+#undef LP_SIZE
+
+#undef RAX_LP
+#undef RBP_LP
+#undef RBX_LP
+#undef RCX_LP
+#undef RDI_LP
+#undef RDX_LP
+#undef RSP_LP
+#undef RSI_LP
+#undef R8_LP
+#undef R9_LP
+#undef R10_LP
+#undef R11_LP
+#undef R12_LP
+#undef R13_LP
+#undef R14_LP
+#undef R15_LP
+
+#ifdef	__ASSEMBLER__
+
+# define LP_SIZE 4
+
+# undef MOVE_LP
+# define MOVE_LP movl
+
+# undef ADD_LP
+# define ADD_LP addl
+
+# undef SUB_LP
+# define SUB_LP subl
+
+# undef CMP_LP
+# define CMP_LP cmpl
+
+# define ASM_ADDR .long
+
+# define RAX_LP	eax
+# define RBP_LP	ebp
+# define RBX_LP	ebx
+# define RCX_LP	ecx
+# define RDI_LP	edi
+# define RDX_LP	edx
+# define RSI_LP	esi
+# define RSP_LP	esp
+# define R8_LP	r8d
+# define R9_LP	r9d
+# define R10_LP	r10d
+# define R11_LP	r11d
+# define R12_LP	r12d
+# define R13_LP	r13d
+# define R14_LP	r14d
+# define R15_LP	r15d
+
+#else	/* __ASSEMBLER__ */
+
+# define LP_SIZE "4"
+
+# define ASM_ADDR ".long"
+
+# define RAX_LP	"eax"
+# define RBP_LP	"ebp"
+# define RBX_LP	"ebx"
+# define RCX_LP	"ecx"
+# define RDI_LP	"edi"
+# define RDX_LP	"edx"
+# define RSI_LP	"esi"
+# define RSP_LP	"esp"
+# define R8_LP	"r8d"
+# define R9_LP	"r9d"
+# define R10_LP	"r10d"
+# define R11_LP	"r11d"
+# define R12_LP	"r12d"
+# define R13_LP	"r13d"
+# define R14_LP	"r14d"
+# define R15_LP	"r15d"
+
+#endif	/* __ASSEMBLER__ */
-- 
1.7.6.5


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