Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / analyzers / rstracer / rstracer.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: rstracer.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef _rstracer_h_9ecb7c16_
#define _rstracer_h_9ecb7c16_
/* rstracer.h */
static const int max_ncpu = 1024;
static const char id[] = "SAM.rstracer";
// the per-cpu-tracer structure
class rst_pct {
public:
int cpuid;
enum state_e {
state_NIL=0, // invalid
state_DELAY, // skipping "delay" insts
state_WAIT_SYNC_START, // skipped delay insts; waiting to sync up with other cpus
state_WAIT_START, // not all cpus have reached sync point. waiting for last one to flag me
state_TRACE_START, // will start trace at the next instr callback
state_TRACING, // actively tracing
state_WAIT_SYNC_STOP, // traced specified # of insts. waiting to sync up with other cpus
state_WAIT_STOP, // not all cpus have reached sync point. waiting for last one to flag me
state_MAX // invalid
};
volatile state_e state;
uint32_t icontext;
uint32_t dcontext;
uint64_t mask_pstate_am;
// we check the pcontext and scontext values at each pavadiff record
// If they have changed, we output a regval record
uint32_t pcontext;
uint32_t scontext;
uint64_t pc_pavadiff;
uint64_t ea_pavadiff;
int64_t ninsts;
int64_t nrecs;
int64_t dinsts; // delay inst count (#insts since trace_on)
char fname[PATH_MAX];
rstf_regvalT regval;
uint8_t hpr; // hpstate.hpriv
uint8_t pr; // pstate.priv
#ifdef USE_RZ3
Rstzip * rz;
#else
FILE * trf;
#endif
uint64_t * memcache;
rstf_memval64T mv64;
rstf_memval128T mv128;
// default constructor
rst_pct() {
state = state_NIL;
}
void init(int arg_cpuid, const char * tmp_tracefilename);
void emit_trace_preamble();
void add_regval(int rstregtype, int rstregid, uint64_t v64);
void flush_regval();
void addrec(rstf_unionT * ru);
void string2rst(const char * str);
int memcache_ref(uint64_t pa); // returns hit(1) or miss(0)
void fini();
}; // struct rst_pct
class rstracer : public VTracer {
public:
rstracer(const char * tmp_modname);
~rstracer();
int process_ui_cmd(int argc, char **tmp_argv);
int attach(VTracer_SAM_intf * sam_intf);
int instr(VCPU_Instruction * ii);
int trap ( VCPU_Trap * ti);
int tlb ( VCPU_TLB * ti);
int async ( VCPU_AsyncData * di);
int sync ( VCPU_Sync * si);
int hwop (VCPU_HwOp * hi);
private:
// the parse_args_*() methods return 0 if success, error code otherwise
int parse_args_v4(int argc, const char * tmp_argv[]);
int parse_args_v5(int argc, const char * tmp_argv[]);
void trace_on(); // initialize a new trace
void print_status();
void trace_off();
const char * modname;
VTracer_SAM_intf * SAM_intf;
int ncpus; // total number of vcpu's
int first_vcpu_id; // id of the first vcpu
int last_vcpu_id; // id of the last vcpu
bool tracing;
int ntraces;
int traces_done;
int64_t initial_delay;
int64_t insts_per_cpu;
int64_t trace_period; // >= insts_per_cpu. the interval between starting points of periodic traces
char tracefilename[PATH_MAX];
int64_t delay; // starts with initial_delay, then equal to (trace_period-insts_per_cpu)
rst_pct * pcs;
// for synchronized start/stop
int sync_count;
mutex_t mu;
}; // class rstracer
#endif // _rstracer_h_9ecb7c16_