sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | ##--------------------------------------------------------------------## |
| 3 | ##--- Support for doing system calls. ---## |
| 4 | ##--- vg_syscall.S ---## |
| 5 | ##--------------------------------------------------------------------## |
| 6 | |
| 7 | /* |
| 8 | This file is part of Valgrind, an x86 protected-mode emulator |
| 9 | designed for debugging and profiling binaries on x86-Unixes. |
| 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 12 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file LICENSE. |
| 30 | */ |
| 31 | |
| 32 | #include "vg_constants.h" |
| 33 | |
| 34 | |
| 35 | .globl VG_(do_syscall) |
| 36 | |
| 37 | # NOTE that this routine expects the simulated machines state |
| 38 | # to be in m_state_static. Therefore it needs to be wrapped by |
| 39 | # code which copies from baseBlock before the call, into |
| 40 | # m_state_static, and back afterwards. |
| 41 | |
| 42 | VG_(do_syscall): |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 43 | # Save all the int registers of the real machines state on the |
| 44 | # simulators stack. |
| 45 | pushal |
| 46 | |
| 47 | # and save the real FPU state too |
| 48 | fwait |
| 49 | fnsave VG_(real_fpu_state_saved_over_syscall_d1) |
| 50 | frstor VG_(real_fpu_state_saved_over_syscall_d1) |
| 51 | |
| 52 | # remember what the simulators stack pointer is |
| 53 | movl %esp, VG_(esp_saved_over_syscall_d1) |
| 54 | |
| 55 | # Now copy the simulated machines state into the real one |
| 56 | # esp still refers to the simulators stack |
| 57 | frstor VG_(m_state_static)+40 |
| 58 | movl VG_(m_state_static)+32, %eax |
| 59 | pushl %eax |
| 60 | popfl |
| 61 | movl VG_(m_state_static)+0, %eax |
| 62 | movl VG_(m_state_static)+4, %ecx |
| 63 | movl VG_(m_state_static)+8, %edx |
| 64 | movl VG_(m_state_static)+12, %ebx |
| 65 | movl VG_(m_state_static)+16, %esp |
| 66 | movl VG_(m_state_static)+20, %ebp |
| 67 | movl VG_(m_state_static)+24, %esi |
| 68 | movl VG_(m_state_static)+28, %edi |
| 69 | |
| 70 | # esp now refers to the simulatees stack |
| 71 | # Do the actual system call |
| 72 | int $0x80 |
| 73 | |
| 74 | # restore stack as soon as possible |
| 75 | # esp refers to simulatees stack |
| 76 | movl %esp, VG_(m_state_static)+16 |
| 77 | movl VG_(esp_saved_over_syscall_d1), %esp |
| 78 | # esp refers to simulators stack |
| 79 | |
| 80 | # ... and undo everything else. |
| 81 | # Copy real state back to simulated state. |
| 82 | movl %eax, VG_(m_state_static)+0 |
| 83 | movl %ecx, VG_(m_state_static)+4 |
| 84 | movl %edx, VG_(m_state_static)+8 |
| 85 | movl %ebx, VG_(m_state_static)+12 |
| 86 | movl %ebp, VG_(m_state_static)+20 |
| 87 | movl %esi, VG_(m_state_static)+24 |
| 88 | movl %edi, VG_(m_state_static)+28 |
| 89 | pushfl |
| 90 | popl %eax |
| 91 | movl %eax, VG_(m_state_static)+32 |
| 92 | fwait |
| 93 | fnsave VG_(m_state_static)+40 |
| 94 | frstor VG_(m_state_static)+40 |
| 95 | |
| 96 | # Restore the state of the simulator |
| 97 | frstor VG_(real_fpu_state_saved_over_syscall_d1) |
| 98 | popal |
| 99 | |
| 100 | ret |
| 101 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 102 | ##--------------------------------------------------------------------## |
| 103 | ##--- end vg_syscall.S ---## |
| 104 | ##--------------------------------------------------------------------## |