Move CPUID functions into their own module, m_cpuid.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3940 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/cachegrind/cg-x86.c b/cachegrind/cg-x86.c
index b7bce81..d0dc588 100644
--- a/cachegrind/cg-x86.c
+++ b/cachegrind/cg-x86.c
@@ -29,6 +29,7 @@
 */
 
 #include "tool.h"
+#include "pub_tool_cpuid.h"
 #include "pub_tool_libcbase.h"
 #include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
diff --git a/configure.in b/configure.in
index 96e698a..d10a795 100644
--- a/configure.in
+++ b/configure.in
@@ -430,9 +430,6 @@
    coregrind/m_scheduler/Makefile 
    coregrind/m_sigframe/Makefile 
    coregrind/m_syswrap/Makefile 
-   coregrind/amd64/Makefile
-   coregrind/arm/Makefile
-   coregrind/x86/Makefile
    addrcheck/Makefile
    addrcheck/tests/Makefile
    addrcheck/docs/Makefile
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index 214c267..a0f87e3 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -14,13 +14,9 @@
 ## When building, we are only interested in the current arch/OS/platform.
 ## But when doing 'make dist', we are interested in every arch/OS/platform.
 ## That's what DIST_SUBDIRS specifies.
-SUBDIRS = \
-	$(VG_ARCH) \
-	$(MODULES) .
+SUBDIRS = $(MODULES) .
 
-DIST_SUBDIRS = \
-	$(VG_ARCH_ALL) \
-	$(MODULES) .
+DIST_SUBDIRS = $(MODULES) .
 
 AM_CPPFLAGS += -DVG_LIBDIR="\"$(valdir)"\" \
 		-DKICKSTART_BASE=@KICKSTART_BASE@
@@ -38,6 +34,7 @@
 	core.h			\
 	coregrind.h		\
 	pub_core_aspacemgr.h	\
+	pub_core_cpuid.h	\
 	pub_core_debuginfo.h	\
 	pub_core_debuglog.h	\
 	pub_core_demangle.h	\
@@ -96,6 +93,7 @@
 valgrind_LDADD=
 
 stage2_SOURCES = \
+	m_cpuid.S \
 	m_debuglog.c \
 	m_errormgr.c \
 	m_execontext.c \
@@ -135,7 +133,6 @@
 	m_aspacemgr/libaspacemgr.a \
 	m_sigframe/libsigframe.a \
 	m_syswrap/libsyswrap.a \
-	${VG_ARCH}/libarch.a \
 	@VEX_DIR@/libvex.a
 
 ## These ones must be linked in with the --whole-archive flag, because they
diff --git a/coregrind/amd64/Makefile.am b/coregrind/amd64/Makefile.am
deleted file mode 100644
index 8306f65..0000000
--- a/coregrind/amd64/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-include $(top_srcdir)/Makefile.all.am
-include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
-
-noinst_LIBRARIES = libarch.a
-
-libarch_a_SOURCES = \
-	cpuid.S
-
diff --git a/coregrind/amd64/cpuid.S b/coregrind/amd64/cpuid.S
deleted file mode 100644
index 7641f5a..0000000
--- a/coregrind/amd64/cpuid.S
+++ /dev/null
@@ -1,86 +0,0 @@
-
-##--------------------------------------------------------------------##
-##--- Support for determining CPU characteristics.   amd64/cpuid.S ---##
-##--------------------------------------------------------------------##
-
-/*
-  This file is part of Valgrind, a dynamic binary instrumentation
-  framework.
-
-  Copyright (C) 2000-2005 Julian Seward 
-     jseward@acm.org
-
-  This program is free software; you can redistribute it and/or
-  modify it under the terms of the GNU General Public License as
-  published by the Free Software Foundation; either version 2 of the
-  License, or (at your option) any later version.
-
-  This program 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
-  General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-  02111-1307, USA.
-
-  The GNU General Public License is contained in the file COPYING.
-*/
-
-#include "pub_basics_asm.h"
-
-/*
-    Bool VG_(has_cpuid)(void)
- */
-.globl VG_(has_cpuid)
-VG_(has_cpuid):
-        movq    $1, %rax
-        ret
-
-/*
-    int VG_(cpuid)(UInt eax,
-                   UInt *eax_ret, UInt *ebx_ret, UInt *ecx_ret, UInt *edx_ret)
- */
-.globl VG_(cpuid)
-VG_(cpuid):
-        pushq   %rbp
-        movq    %rsp, %rbp
-        pushq   %rbx
-        movl    %edi, %eax
-        movq    %rdx, %rdi
-        movq    %rcx, %r9
-        /*
-           eax_ret now in %rsi
-           ebx_ret now in %rdi
-           ecx_ret now in %r9
-           edx_ret now in %r8
-         */
-        cpuid
-        testq   %rsi, %rsi
-        jz      1f
-        movl    %eax, (%rsi)
-1:
-        testq   %rdi, %rdi
-        jz      2f
-        movl    %ebx, (%rdi)
-2:
-        testq   %r9, %r9
-        jz      3f
-        movl    %ecx, (%r9)
-3:
-        testq   %r8, %r8
-        jz      4f
-        movl    %edx, (%r8)
-4:
-        popq    %rbx
-        movq    %rbp, %rsp
-        popq    %rbp
-        ret
-        
-/* Let the linker know we don't need an executable stack */
-.section .note.GNU-stack,"",@progbits
-
-##--------------------------------------------------------------------##
-##--- end                                    	                   ---##
-##--------------------------------------------------------------------##
diff --git a/coregrind/arm/Makefile.am b/coregrind/arm/Makefile.am
deleted file mode 100644
index da669e9..0000000
--- a/coregrind/arm/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-include $(top_srcdir)/Makefile.all.am
-include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
-
-noinst_LIBRARIES = libarch.a
-
-libarch_a_SOURCES =
-
diff --git a/coregrind/x86/cpuid.S b/coregrind/m_cpuid.S
similarity index 69%
rename from coregrind/x86/cpuid.S
rename to coregrind/m_cpuid.S
index 6fea1b5..c08a151 100644
--- a/coregrind/x86/cpuid.S
+++ b/coregrind/m_cpuid.S
@@ -1,6 +1,6 @@
 
 ##--------------------------------------------------------------------##
-##--- Support for determining CPU characteristics.     x86/cpuid.S ---##
+##--- CPUID interface.                                   m_cpuid.S ---##
 ##--------------------------------------------------------------------##
 
 /*
@@ -34,7 +34,8 @@
     Bool VG_(has_cpuid)(void)
  */
 .globl VG_(has_cpuid)
-VG_(has_cpuid):
+#if defined(VGA_x86)
+    VG_(has_cpuid):
         pushl   %ebp
         movl    %esp, %ebp
         pushl   %ecx
@@ -55,13 +56,19 @@
         movl    %ebp, %esp
         popl    %ebp
         ret
+#elif defined(VGA_amd64)
+    VG_(has_cpuid):
+        movq    $1, %rax
+        ret
+#endif
 
 /*
     void VG_(cpuid)(UInt eax,
-                    UInt *eax_ret, UInt *ebx_ret, UInt *ecx_ret, UInt *edx_ret)
+                    UInt* eax_ret, UInt* ebx_ret, UInt* ecx_ret, UInt* edx_ret)
  */
 .globl VG_(cpuid)
-VG_(cpuid):
+#if defined(VGA_x86)
+    VG_(cpuid):
         pushl   %ebp
         movl    %esp, %ebp
         pushl   %eax
@@ -75,22 +82,22 @@
         testl   %esi, %esi
         jz      1f
         movl    %eax, (%esi)
-1:
+    1:
         movl    16(%ebp), %esi
         testl   %esi, %esi
         jz      2f
         movl    %ebx, (%esi)
-2:
+    2:
         movl    20(%ebp), %esi
         testl   %esi, %esi
         jz      3f
         movl    %ecx, (%esi)
-3:
+    3:
         movl    24(%ebp), %esi
         testl   %esi, %esi
         jz      4f
         movl    %edx, (%esi)
-4:
+    4:
         popl    %esi
         popl    %edx
         popl    %ecx
@@ -99,10 +106,46 @@
         movl    %ebp, %esp
         popl    %ebp
         ret
+#elif defined(VGA_amd64)
+    VG_(cpuid):
+        pushq   %rbp
+        movq    %rsp, %rbp
+        pushq   %rbx
+        movl    %edi, %eax
+        movq    %rdx, %rdi
+        movq    %rcx, %r9
+        /*
+           eax_ret now in %rsi
+           ebx_ret now in %rdi
+           ecx_ret now in %r9
+           edx_ret now in %r8
+         */
+        cpuid
+        testq   %rsi, %rsi
+        jz      1f
+        movl    %eax, (%rsi)
+    1:
+        testq   %rdi, %rdi
+        jz      2f
+        movl    %ebx, (%rdi)
+    2:
+        testq   %r9, %r9
+        jz      3f
+        movl    %ecx, (%r9)
+    3:
+        testq   %r8, %r8
+        jz      4f
+        movl    %edx, (%r8)
+    4:
+        popq    %rbx
+        movq    %rbp, %rsp
+        popq    %rbp
+        ret
+#endif
         
 /* Let the linker know we don't need an executable stack */
 .section .note.GNU-stack,"",@progbits
-
+		
 ##--------------------------------------------------------------------##
-##--- end                                    	                   ---##
+##--- end                                                          ---##
 ##--------------------------------------------------------------------##
diff --git a/coregrind/m_translate.c b/coregrind/m_translate.c
index 0211808..5442fa5 100644
--- a/coregrind/m_translate.c
+++ b/coregrind/m_translate.c
@@ -31,6 +31,7 @@
 
 #include "core.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_cpuid.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
diff --git a/coregrind/pub_core_cpuid.h b/coregrind/pub_core_cpuid.h
new file mode 100644
index 0000000..f825336
--- /dev/null
+++ b/coregrind/pub_core_cpuid.h
@@ -0,0 +1,45 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Interface to CPUID.                         pub_core_cpuid.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program 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
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_CPUID_H
+#define __PUB_CORE_CPUID_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module provides Valgrind's interface to the x86/amd64
+// CPUID instruction.
+//--------------------------------------------------------------------
+
+#include "pub_tool_cpuid.h"
+
+#endif   // __PUB_CORE_CPUID_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/x86/.cvsignore b/coregrind/x86/.cvsignore
deleted file mode 100644
index 1d5e32f..0000000
--- a/coregrind/x86/.cvsignore
+++ /dev/null
@@ -1,5 +0,0 @@
-Makefile.in
-Makefile
-core_arch_asm_offsets.h
-gen_offsets
-stage2.lds
diff --git a/coregrind/x86/Makefile.am b/coregrind/x86/Makefile.am
deleted file mode 100644
index 8306f65..0000000
--- a/coregrind/x86/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-include $(top_srcdir)/Makefile.all.am
-include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
-
-noinst_LIBRARIES = libarch.a
-
-libarch_a_SOURCES = \
-	cpuid.S
-
diff --git a/include/Makefile.am b/include/Makefile.am
index bcd9503..5bf9b1d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,6 +6,7 @@
 	tool.h 				\
 	pub_basics_asm.h 		\
 	pub_tool_aspacemgr.h 		\
+	pub_tool_cpuid.h 		\
 	pub_tool_errormgr.h 		\
 	pub_tool_execontext.h 		\
 	pub_tool_hashtable.h 		\
diff --git a/include/pub_tool_cpuid.h b/include/pub_tool_cpuid.h
new file mode 100644
index 0000000..b37d458
--- /dev/null
+++ b/include/pub_tool_cpuid.h
@@ -0,0 +1,46 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Interface to CPUID.                         pub_tool_cpuid.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program 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
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_CPUID_H
+#define __PUB_TOOL_CPUID_H
+
+#if defined(VGA_x86) || defined(VGA_amd64)
+extern Bool VG_(has_cpuid) ( void );
+
+extern void VG_(cpuid) ( UInt eax,
+                         UInt* eax_ret, UInt* ebx_ret,
+                         UInt* ecx_ret, UInt* edx_ret );
+#endif
+
+#endif   // __PUB_TOOL_CPUID_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/include/tool.h b/include/tool.h
index f78f40d..52a3a1d 100644
--- a/include/tool.h
+++ b/include/tool.h
@@ -68,18 +68,6 @@
                         ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
                           void* d );
 
-/*====================================================================*/
-/*=== Valgrind's version of libc                                   ===*/
-/*====================================================================*/
-
-/* ------------------------------------------------------------------ */
-/* other, randomly useful functions */
-extern Bool VG_(has_cpuid) ( void );
-
-extern void VG_(cpuid) ( UInt eax,
-                         UInt *eax_ret, UInt *ebx_ret,
-                         UInt *ecx_ret, UInt *edx_ret );
-
 #endif   /* __TOOL_H */