From 2108c8932f4247a5330308c342e82f125c44fb39 Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Fri, 30 Aug 2013 17:03:37 +0200 Subject: [PATCH] util: disassembler register/address mapping fix For def/use pruning, the linear address mapping of the x86 sub-registers (e.g., AX represents the lower 16 bits of EAX) must overlap. If it doesn't, e.g., AX and EAX are considered separate registers by def/use pruning, resulting in a failure to correlate an EAX def with a subsequent AX use. The only user of this mapping up to now, RegisterImporter, forced all register widths to 8 bits, thereby fortunately canceling out this problem. Nevertheless it makes no sense to continue encoding a constant width in these virtual addresses. Existing trace, fspgroup, fsppilot and result tables may be converted to the new encoding by using this query: UPDATE SET data_address = ((data_address >> 4) & ~0xf) | data_address & 0xf; Change-Id: I7a942b78c34f6140803a86af639eeedef3550f34 --- .../llvmdisassembler/LLVMtoFailTranslator.hpp | 21 ++++++++++++------- tools/import-trace/RegisterImporter.cc | 5 ++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/core/util/llvmdisassembler/LLVMtoFailTranslator.hpp b/src/core/util/llvmdisassembler/LLVMtoFailTranslator.hpp index 4e9444c2..5849e12c 100644 --- a/src/core/util/llvmdisassembler/LLVMtoFailTranslator.hpp +++ b/src/core/util/llvmdisassembler/LLVMtoFailTranslator.hpp @@ -13,6 +13,12 @@ namespace fail { */ class LLVMtoFailTranslator { public: + /** + * Maps registers to/from linear addresses usable for def/use-pruning + * purposes and storage in the database. Takes care that the linear + * addresses of x86 subregisters (e.g., AX represents the lower 16 bits of + * EAX) overlap with their siblings. + */ struct reginfo_t { int id; regwidth_t width; @@ -20,18 +26,17 @@ public: byte_t offset; int toDataAddress() const { - // .. 5 4 | 7 6 5 4 | 3 2 1 0 - // | | - return (id << 8) | ((width/8) << 4) | (offset / 8); + // .. 5 4 | 3 2 1 0 + // | + return (id << 4) | (offset / 8); } + // does not recreate width or mask static reginfo_t fromDataAddress(int addr) { - int id = addr >> 8; - regwidth_t width = ((addr >> 4) & 0xf) * 8; - byte_t offset = (addr & 0xf) * 8; - return reginfo_t(id, width, offset); + int id = addr >> 4; + byte_t offset = (addr & 0xf) * 8; + return reginfo_t(id, 0, offset); } - reginfo_t(int id=-1, regwidth_t width = 32, byte_t offs = 0) : id(id), width(width), mask((regwidth_t)((((long long)1 << width) - 1) << offs)), offset(offs) {}; }; diff --git a/tools/import-trace/RegisterImporter.cc b/tools/import-trace/RegisterImporter.cc index 6b44969e..5564a184 100644 --- a/tools/import-trace/RegisterImporter.cc +++ b/tools/import-trace/RegisterImporter.cc @@ -33,9 +33,8 @@ bool RegisterImporter::addRegisterTrace(simtime_t curtime, instruction_count_t i const Trace_Event &ev, const LLVMtoFailTranslator::reginfo_t &info, char access_type) { - LLVMtoFailTranslator::reginfo_t one_byte_window = info; - one_byte_window.width = 8; - address_t from = one_byte_window.toDataAddress(), to = one_byte_window.toDataAddress() + (info.width) / 8; + address_t from = info.toDataAddress(); + address_t to = from + info.width / 8; // Iterate over all accessed bytes for (address_t data_address = from; data_address < to; ++data_address) {