njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1 | /*--------------------------------------------------------------------*/ |
| 2 | /*--- Higher-level UCode sequence builders ---*/ |
| 3 | /*--- vg_instrument.c ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, an x86 protected-mode emulator |
| 8 | designed for debugging and profiling binaries on x86-Unixes. |
| 9 | |
| 10 | Copyright (C) 2000-2002 Nicholas Nethercote |
| 11 | njn25@cam.ac.uk |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | // SSS: should this file should eventually not be in core, but included in |
| 32 | // skins that use it?? Reduces size of core, but increases size of every |
| 33 | // skin that uses it... |
| 34 | |
| 35 | /* We only import vg_skin.h here, because this file only provides functions |
| 36 | for doing things that could be done directly by the skin -- it's just to |
| 37 | make skins' lives easier, rather than let them do something they |
| 38 | couldn't otherwise do. */ |
| 39 | #include "vg_skin.h" |
| 40 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 41 | #define uInstr0 VG_(new_UInstr0) |
| 42 | #define uInstr1 VG_(new_UInstr1) |
| 43 | #define uInstr2 VG_(new_UInstr2) |
| 44 | #define uLiteral VG_(set_lit_field) |
| 45 | #define uCCall VG_(set_ccall_fields) |
| 46 | #define newTemp VG_(get_new_temp) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 47 | |
| 48 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 49 | void VG_(call_helper_0_0)(UCodeBlock* cb, Addr f) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 50 | { |
| 51 | uInstr0(cb, CCALL, 0); |
| 52 | uCCall(cb, f, 0, 0, 0); |
| 53 | } |
| 54 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 55 | void VG_(call_helper_1_0)(UCodeBlock* cb, Addr f, UInt arg1, UInt regparms_n) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 56 | { |
| 57 | UInt t1 = newTemp(cb); |
| 58 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame^] | 59 | sk_assert(regparms_n <= 1); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 60 | uInstr2(cb, MOV, 4, Literal, 0, TempReg, t1); |
| 61 | uLiteral(cb, arg1); |
| 62 | uInstr1(cb, CCALL, 0, TempReg, t1); |
| 63 | uCCall(cb, f, 1, regparms_n, 0); |
| 64 | } |
| 65 | |
njn | 4ba5a79 | 2002-09-30 10:23:54 +0000 | [diff] [blame] | 66 | void VG_(call_helper_2_0)(UCodeBlock* cb, Addr f, UInt arg1, UInt arg2, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 67 | UInt regparms_n) |
| 68 | { |
| 69 | UInt t1 = newTemp(cb); |
| 70 | UInt t2 = newTemp(cb); |
| 71 | |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame^] | 72 | sk_assert(regparms_n <= 2); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 73 | uInstr2(cb, MOV, 4, Literal, 0, TempReg, t1); |
| 74 | uLiteral(cb, arg1); |
| 75 | uInstr2(cb, MOV, 4, Literal, 0, TempReg, t2); |
| 76 | uLiteral(cb, arg2); |
| 77 | uInstr2(cb, CCALL, 0, TempReg, t1, TempReg, t2); |
| 78 | uCCall(cb, f, 2, regparms_n, 0); |
| 79 | } |
| 80 | |
| 81 | void VG_(set_global_var)(UCodeBlock* cb, Addr globvar_ptr, UInt val) |
| 82 | { |
| 83 | Int t_gv = newTemp(cb); |
| 84 | Int t_val = newTemp(cb); |
| 85 | |
| 86 | uInstr2(cb, MOV, 4, Literal, 0, TempReg, t_val); |
| 87 | uLiteral(cb, val); |
| 88 | uInstr2(cb, MOV, 4, Literal, 0, TempReg, t_gv); |
| 89 | uLiteral(cb, globvar_ptr); |
| 90 | uInstr2(cb, STORE, 4, TempReg, t_val, TempReg, t_gv); |
| 91 | } |
| 92 | |
| 93 | /*--------------------------------------------------------------------*/ |
| 94 | /*--- end vg_instrument.c ---*/ |
| 95 | /*--------------------------------------------------------------------*/ |
| 96 | |