From f4871f2c728d8ac745d531d4e552123872f5aa5a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 18 Jun 2005 18:31:26 +0000 Subject: [PATCH] Move CPUID functions into their own module, m_cpuid. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3940 --- cachegrind/cg-x86.c | 1 + configure.in | 3 - coregrind/Makefile.am | 11 ++-- coregrind/amd64/Makefile.am | 8 --- coregrind/amd64/cpuid.S | 86 ---------------------------- coregrind/arm/Makefile.am | 7 --- coregrind/{x86/cpuid.S => m_cpuid.S} | 63 ++++++++++++++++---- coregrind/m_translate.c | 1 + coregrind/pub_core_cpuid.h | 45 +++++++++++++++ coregrind/x86/.cvsignore | 5 -- coregrind/x86/Makefile.am | 8 --- include/Makefile.am | 1 + include/pub_tool_cpuid.h | 46 +++++++++++++++ include/tool.h | 12 ---- 14 files changed, 151 insertions(+), 146 deletions(-) delete mode 100644 coregrind/amd64/Makefile.am delete mode 100644 coregrind/amd64/cpuid.S delete mode 100644 coregrind/arm/Makefile.am rename coregrind/{x86/cpuid.S => m_cpuid.S} (69%) create mode 100644 coregrind/pub_core_cpuid.h delete mode 100644 coregrind/x86/.cvsignore delete mode 100644 coregrind/x86/Makefile.am create mode 100644 include/pub_tool_cpuid.h diff --git a/cachegrind/cg-x86.c b/cachegrind/cg-x86.c index b7bce81e4..d0dc58856 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 96e698ad0..d10a795b4 100644 --- a/configure.in +++ b/configure.in @@ -430,9 +430,6 @@ AC_OUTPUT( 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 214c26712..a0f87e3d9 100644 --- a/coregrind/Makefile.am +++ b/coregrind/Makefile.am @@ -14,13 +14,9 @@ MODULES = \ ## 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 @@ noinst_HEADERS = \ 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_LDFLAGS=-static -g valgrind_LDADD= stage2_SOURCES = \ + m_cpuid.S \ m_debuglog.c \ m_errormgr.c \ m_execontext.c \ @@ -135,7 +133,6 @@ stage2_extra= \ 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 8306f657e..000000000 --- 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 7641f5a71..000000000 --- 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 da669e952..000000000 --- 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 6fea1b519..c08a15150 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 @@ VG_(has_cpuid): 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 @@ VG_(cpuid): 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 @@ VG_(cpuid): 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 0211808ea..5442fa56b 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 000000000..f82533678 --- /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 1d5e32f51..000000000 --- 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 8306f657e..000000000 --- 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 bcd950300..5bf9b1d48 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -6,6 +6,7 @@ incinc_HEADERS = \ 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 000000000..b37d458f3 --- /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 f78f40da1..52a3a1df1 100644 --- a/include/tool.h +++ b/include/tool.h @@ -68,18 +68,6 @@ extern ThreadId VG_(first_matching_thread_stack) ( 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 */