insttracer.hh revision 4776
1/* 2 * Copyright (c) 2001-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Steve Reinhardt 29 * Nathan Binkert 30 */ 31 32#ifndef __INSTRECORD_HH__ 33#define __INSTRECORD_HH__ 34 35#include "base/trace.hh" 36#include "cpu/inst_seq.hh" // for InstSeqNum 37#include "cpu/static_inst.hh" 38#include "sim/host.hh" 39#include "sim/sim_object.hh" 40 41class ThreadContext; 42 43namespace Trace { 44 45class InstRecord 46{ 47 protected: 48 Tick when; 49 50 // The following fields are initialized by the constructor and 51 // thus guaranteed to be valid. 52 ThreadContext *thread; 53 // need to make this ref-counted so it doesn't go away before we 54 // dump the record 55 StaticInstPtr staticInst; 56 Addr PC; 57 bool misspeculating; 58 59 // The remaining fields are only valid for particular instruction 60 // types (e.g, addresses for memory ops) or when particular 61 // options are enabled (e.g., tracing full register contents). 62 // Each data field has an associated valid flag to indicate 63 // whether the data field is valid. 64 Addr addr; 65 bool addr_valid; 66 67 union { 68 uint64_t as_int; 69 double as_double; 70 } data; 71 enum { 72 DataInvalid = 0, 73 DataInt8 = 1, // set to equal number of bytes 74 DataInt16 = 2, 75 DataInt32 = 4, 76 DataInt64 = 8, 77 DataDouble = 3 78 } data_status; 79 80 InstSeqNum fetch_seq; 81 bool fetch_seq_valid; 82 83 InstSeqNum cp_seq; 84 bool cp_seq_valid; 85 86 public: 87 InstRecord(Tick _when, ThreadContext *_thread, 88 const StaticInstPtr &_staticInst, 89 Addr _pc, bool spec) 90 : when(_when), thread(_thread), 91 staticInst(_staticInst), PC(_pc), 92 misspeculating(spec) 93 { 94 data_status = DataInvalid; 95 addr_valid = false; 96 97 fetch_seq_valid = false; 98 cp_seq_valid = false; 99 } 100 101 virtual ~InstRecord() { } 102 103 void setAddr(Addr a) { addr = a; addr_valid = true; } 104 105 void setData(Twin64_t d) { data.as_int = d.a; data_status = DataInt64; } 106 void setData(Twin32_t d) { data.as_int = d.a; data_status = DataInt32; } 107 void setData(uint64_t d) { data.as_int = d; data_status = DataInt64; } 108 void setData(uint32_t d) { data.as_int = d; data_status = DataInt32; } 109 void setData(uint16_t d) { data.as_int = d; data_status = DataInt16; } 110 void setData(uint8_t d) { data.as_int = d; data_status = DataInt8; } 111 112 void setData(int64_t d) { setData((uint64_t)d); } 113 void setData(int32_t d) { setData((uint32_t)d); } 114 void setData(int16_t d) { setData((uint16_t)d); } 115 void setData(int8_t d) { setData((uint8_t)d); } 116 117 void setData(double d) { data.as_double = d; data_status = DataDouble; } 118 119 void setFetchSeq(InstSeqNum seq) 120 { fetch_seq = seq; fetch_seq_valid = true; } 121 122 void setCPSeq(InstSeqNum seq) 123 { cp_seq = seq; cp_seq_valid = true; } 124 125 virtual void dump() = 0; 126}; 127 128class InstTracer : public SimObject 129{ 130 public: 131 InstTracer(const std::string & name) : SimObject(name) 132 {} 133 134 virtual ~InstTracer() 135 {}; 136 137 virtual InstRecord * 138 getInstRecord(Tick when, ThreadContext *tc, 139 const StaticInstPtr staticInst, Addr pc) = 0; 140}; 141 142 143 144}; // namespace Trace 145 146#endif // __INSTRECORD_HH__ 147