/* * unaligned-rt.c * * Runtime code for unaligned access counting Tool. * * The routines LoadReference and StoreReference are called * at each memory access by code inserted into the executable * at instrumentation time. ProgramAfter is called before the * program exits, so that counters can be written out. * * */ #include #include #include #include #include "util.h" #define DllExport __declspec( dllexport ) #define DllImport __declspec( dllimport ) DllExport void ProgramAfter(); DllExport void LoadReference(unsigned long address, int len, unsigned long pc); DllExport void StoreReference(unsigned long address, int len, unsigned long pc); int loads = 0; int stores = 0; int unaligned_loads = 0; int unaligned_stores = 0; FILE * f; void ProgramAfter() { char *fname; /* call our etchOutputName() utility routine to create an * output file name. */ fname = etchOutputName("unaligned"); f = fopen(fname,"w"); assert(f); /* dump the final counter information into the output file. */ fprintf(f,"Category,Number\n"); fprintf(f,"loads,%d\n", loads); fprintf(f,"stores,%d\n", stores); fprintf(f,"unaligned loads,%d\n", unaligned_loads); fprintf(f,"unaligned_stores,%d\n", unaligned_stores); fclose(f); } void LoadReference(unsigned long address, int len, unsigned long pc) { /* count the number of loads and the number of unaligned loads */ loads++; if (address % len) unaligned_loads++; } void StoreReference(unsigned long address, int len, unsigned long pc) { /* count the number of stores and the number of unaligned stores */ stores++; if (address % len) unaligned_stores++; }