/* * unaligned-inst.cxx * * Instrumentation code for simple unaligned access counter tool. * * The InstrumentInstruction procedure is invoked by Etch before and * after each instruction is discovered. It calls Etch routines * InsertCallLoadRefs and InsertCallStoreRefs, which cause calls * to be made to tool runtime routines (LoadReference and StoreReference) * when a memory load or store is executed. * */ #define _ETCHLIB_IMPORTER_ #include "etch-inst.h" /* * make the callbacks visible to the etch engine. */ extern "C" { DllExport void InstrumentInstruction(WhenType when, InstPtr inst, int procNum); DllExport void InstrumentProgram(WhenType when); } void InstrumentInstruction(WhenType when, InstPtr inst, int procNum) { int argc; Address_t pc; void * array[3]; ArgType argt[3]; if (when == Before) { argc = 3; pc = InstGetPC(inst); /* set up the arguments for the calls to LoadReference and * StoreReference. */ array[0] = 0; argt[0] = ArgEffAddr; array[1] = 0; argt[1] = ArgEffAddrLen; array[2] = (void*)pc; argt[2] = ArgImmed; /* insert calls to LoadReference and StoreReference. Note * that these routines will only be called on instructions * that actually make memory references. */ InsertCallLoadRefs("LoadReference",argc,array,argt); InsertCallStoreRefs("StoreReference",argc,array,argt); } } void InstrumentProgram(WhenType when) { /* call the ProgramAfter routine with no arguments, once the * program completes. */ if (when == After) { InsertCall("ProgramAfter", 0, 0, 0); } }