mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-07 12:44:45 +00:00
to include the SSE/SSE2 architectural state. Automagically detect at startup, in vg_startup.S, whether or not this is a SSE-enabled CPU and act accordingly. All subsequent FPU/SSE state transfers between the simulated and real machine are then done either with fsave/frstor (as before) or fxsave/fxrstor (the SSE equivalents). Fragile and fiddly; (1) the SSE state needs to be stored on a 16-byte boundary, and (2) certain bits in the saved MXCSR reg in a state written by fxsave need to be anded out before we can safely restore using fxrstor. It does appear to work. I'd appreciate people trying it out on various CPUs to establish whether the SSE / not-SSE check works right, and/or anything else is broken. Unfortunately makes some programs run significantly slower. I don't know why. Perhaps due to copying around more processor state than there was before (SSE state is 512 bytes, FPU state was only 108). I will look into this. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1574
168 lines
4.8 KiB
ArmAsm
168 lines
4.8 KiB
ArmAsm
|
|
##--------------------------------------------------------------------##
|
|
##--- Support for doing system calls. ---##
|
|
##--- vg_syscall.S ---##
|
|
##--------------------------------------------------------------------##
|
|
|
|
/*
|
|
This file is part of Valgrind, an extensible x86 protected-mode
|
|
emulator for monitoring program execution on x86-Unixes.
|
|
|
|
Copyright (C) 2000-2003 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 "vg_constants.h"
|
|
|
|
|
|
.globl VG_(do_syscall)
|
|
|
|
# NOTE that this routine expects the simulated machines state
|
|
# to be in m_state_static. Therefore it needs to be wrapped by
|
|
# code which copies from baseBlock before the call, into
|
|
# m_state_static, and back afterwards.
|
|
|
|
VG_(do_syscall):
|
|
# Save all the int registers of the real machines state on the
|
|
# simulators stack.
|
|
pushal
|
|
|
|
# and save the real FPU state too
|
|
fwait
|
|
|
|
pushfl
|
|
cmpb $0, VG_(have_ssestate)
|
|
jz qq1nosse
|
|
fxsave VG_(real_sse_state_saved_over_syscall)
|
|
andl $0x0000FFBF, VG_(real_sse_state_saved_over_syscall)+24
|
|
fxrstor VG_(real_sse_state_saved_over_syscall)
|
|
jmp qq1merge
|
|
qq1nosse:
|
|
fnsave VG_(real_sse_state_saved_over_syscall)
|
|
frstor VG_(real_sse_state_saved_over_syscall)
|
|
qq1merge:
|
|
popfl
|
|
|
|
# remember what the simulators stack pointer is
|
|
movl %esp, VG_(esp_saved_over_syscall)
|
|
|
|
# Now copy the simulated machines state into the real one
|
|
# esp still refers to the simulators stack
|
|
pushfl
|
|
cmpb $0, VG_(have_ssestate)
|
|
jz qq2nosse
|
|
andl $0x0000FFBF, VG_(m_state_static)+64+24
|
|
fxrstor VG_(m_state_static)+64
|
|
jmp qq2merge
|
|
qq2nosse:
|
|
frstor VG_(m_state_static)+64
|
|
qq2merge:
|
|
popfl
|
|
|
|
movl VG_(m_state_static)+56, %eax
|
|
pushl %eax
|
|
popfl
|
|
#if 0
|
|
/* don't bother to save/restore seg regs across the kernel iface.
|
|
Once we have our hands on them, our simulation of it is
|
|
completely internal, and the kernel sees nothing.
|
|
What's more, loading new values in to %cs seems
|
|
to be impossible anyway. */
|
|
movw VG_(m_state_static)+0, %cs
|
|
movw VG_(m_state_static)+4, %ss
|
|
movw VG_(m_state_static)+8, %ds
|
|
movw VG_(m_state_static)+12, %es
|
|
movw VG_(m_state_static)+16, %fs
|
|
movw VG_(m_state_static)+20, %gs
|
|
#endif
|
|
movl VG_(m_state_static)+24, %eax
|
|
movl VG_(m_state_static)+28, %ecx
|
|
movl VG_(m_state_static)+32, %edx
|
|
movl VG_(m_state_static)+36, %ebx
|
|
movl VG_(m_state_static)+40, %esp
|
|
movl VG_(m_state_static)+44, %ebp
|
|
movl VG_(m_state_static)+48, %esi
|
|
movl VG_(m_state_static)+52, %edi
|
|
|
|
# esp now refers to the simulatees stack
|
|
# Do the actual system call
|
|
int $0x80
|
|
|
|
# restore stack as soon as possible
|
|
# esp refers to simulatees stack
|
|
movl %esp, VG_(m_state_static)+40
|
|
movl VG_(esp_saved_over_syscall), %esp
|
|
# esp refers to simulators stack
|
|
|
|
# ... and undo everything else.
|
|
# Copy real state back to simulated state.
|
|
#if 0
|
|
movw %cs, VG_(m_state_static)+0
|
|
movw %ss, VG_(m_state_static)+4
|
|
movw %ds, VG_(m_state_static)+8
|
|
movw %es, VG_(m_state_static)+12
|
|
movw %fs, VG_(m_state_static)+16
|
|
movw %gs, VG_(m_state_static)+20
|
|
#endif
|
|
movl %eax, VG_(m_state_static)+24
|
|
movl %ecx, VG_(m_state_static)+28
|
|
movl %edx, VG_(m_state_static)+32
|
|
movl %ebx, VG_(m_state_static)+36
|
|
movl %ebp, VG_(m_state_static)+44
|
|
movl %esi, VG_(m_state_static)+48
|
|
movl %edi, VG_(m_state_static)+52
|
|
pushfl
|
|
popl %eax
|
|
movl %eax, VG_(m_state_static)+56
|
|
fwait
|
|
|
|
pushfl
|
|
cmpb $0, VG_(have_ssestate)
|
|
jz pp2nosse
|
|
fxsave VG_(m_state_static)+64
|
|
andl $0x0000FFBF, VG_(m_state_static)+64+24
|
|
fxrstor VG_(m_state_static)+64
|
|
jmp pp2merge
|
|
pp2nosse:
|
|
fnsave VG_(m_state_static)+64
|
|
frstor VG_(m_state_static)+64
|
|
pp2merge:
|
|
popfl
|
|
|
|
# Restore the state of the simulator
|
|
pushfl
|
|
cmpb $0, VG_(have_ssestate)
|
|
jz pp1nosse
|
|
andl $0x0000FFBF, VG_(real_sse_state_saved_over_syscall)+24
|
|
fxrstor VG_(real_sse_state_saved_over_syscall)
|
|
jmp pp1merge
|
|
pp1nosse:
|
|
frstor VG_(real_sse_state_saved_over_syscall)
|
|
pp1merge:
|
|
popfl
|
|
|
|
popal
|
|
|
|
ret
|
|
|
|
##--------------------------------------------------------------------##
|
|
##--- end vg_syscall.S ---##
|
|
##--------------------------------------------------------------------##
|