|
From: Nicholas N. <nj...@ca...> - 2004-07-23 11:00:09
|
Hi,
Either VG_(helper_CPUID) is broken, or I'm not clever enough to understand
it... it looks like this:
.global VG_(helper_CPUID)
VG_(helper_CPUID):
push %ebp
movl %esp,%ebp
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
pushl %esi
pushl %edi
pushf
lea 2*4(%ebp),%eax /* &edx */
pushl %eax
addl $4,%eax /* &ecx */
pushl %eax
addl $4,%eax /* &ebx */
pushl %eax
addl $4,%eax /* &eax */
pushl %eax
pushl (%eax) /* eax */
call VG_(helperc_CPUID)
addl $20,%esp
The relevant part of the baseBlock is initialised like this:
static void init_baseBlock ( Addr client_eip, Addr esp_at_startup )
{
/* WORD offsets in this column */
/* 0 */ VGOFF_(m_eax) = alloc_BaB_1_set(0);
/* 1 */ VGOFF_(m_ecx) = alloc_BaB_1_set(0);
/* 2 */ VGOFF_(m_edx) = alloc_BaB_1_set(0);
/* 3 */ VGOFF_(m_ebx) = alloc_BaB_1_set(0);
/* 4 */ VGOFF_(m_esp) = alloc_BaB_1_set(esp_at_startup);
/* 5 */ VGOFF_(m_ebp) = alloc_BaB_1_set(0);
/* 6 */ VGOFF_(m_esi) = alloc_BaB_1_set(0);
/* 7 */ VGOFF_(m_edi) = alloc_BaB_1_set(0);
/* 8 */ VGOFF_(m_eflags) = alloc_BaB_1_set(0)
So, AFAICT, VG_(helper_CPUID) starts by pushing &EDX (ie. baseBlock+8 --
from the "lea 2*4(%ebp)"), then &EBX, then &ESP, then &EBP. Not &EDX,
&ECX, &EBX, &EAX as it claims.
But it seems to be working, eg. in Cachegrind, so I must be
misunderstanding. Can anyone explain?
Thanks.
N
|
|
From: Tom H. <th...@cy...> - 2004-07-23 11:32:21
|
In message <Pin...@he...>
Nicholas Nethercote <nj...@ca...> wrote:
> Either VG_(helper_CPUID) is broken, or I'm not clever enough to
> understand it... it looks like this:
>
> .global VG_(helper_CPUID)
> VG_(helper_CPUID):
> push %ebp
> movl %esp,%ebp
> pushl %eax
> pushl %ebx
> pushl %ecx
> pushl %edx
> pushl %esi
> pushl %edi
> pushf
Note this bit, and what it does to ebp...
> lea 2*4(%ebp),%eax /* &edx */
> pushl %eax
> addl $4,%eax /* &ecx */
> pushl %eax
> addl $4,%eax /* &ebx */
> pushl %eax
> addl $4,%eax /* &eax */
> pushl %eax
> pushl (%eax) /* eax */
>
> call VG_(helperc_CPUID)
> addl $20,%esp
>
> The relevant part of the baseBlock is initialised like this:
[ snipped ]
> So, AFAICT, VG_(helper_CPUID) starts by pushing &EDX (ie. baseBlock+8 --
> from the "lea 2*4(%ebp)"), then &EBX, then &ESP, then &EBP. Not &EDX,
> &ECX, &EBX, &EAX as it claims.
But EBP is pointing at the stack by then, not the base block, so the
call to VG_(helperc_CPUID) winds up updating the stacked registers
which are then popped again.
> But it seems to be working, eg. in Cachegrind, so I must be
> misunderstanding. Can anyone explain?
The cache detection in cachgrind doesn't go through the helper anyway
as it isn't emulated - that just call VG_(cpuid) directly.
The helper is only used when CPUID is encountered in the target
program.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|
|
From: Nicholas N. <nj...@ca...> - 2004-07-23 11:46:55
|
On Fri, 23 Jul 2004, Tom Hughes wrote: >> .global VG_(helper_CPUID) >> VG_(helper_CPUID): >> push %ebp >> movl %esp,%ebp >> ... >> lea 2*4(%ebp),%eax /* &edx */ > > But EBP is pointing at the stack by then, not the base block, so the > call to VG_(helperc_CPUID) winds up updating the stacked registers > which are then popped again. I am stupid. Thanks, Tom. N |