Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pfe / src / SS_PythonTracer.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: SS_PythonTracer.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 __SS_PythonTracer_h__
#define __SS_PythonTracer_h__
#include "SS_Tracer.h"
class SS_PythonTracer : public SS_Tracer
{
public:
SS_PythonTracer()
:
SS_Tracer(),
py_exe_instr(0),
py_reg_value(0),
py_trap(0),
py_mem_access(0),
py_tlb_update(0),
py_end_instr(0)
{}
static void py_hook_exe_instr( SS_Tracer* trc, SS_Vaddr pc, SS_Tte* tte, SS_Instr* i )
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
SS_PythonTracer* py_trc = (SS_PythonTracer*)trc;
PyObject *func, *args, *rslt;
func = (PyObject *)py_trc->py_exe_instr;
args = Py_BuildValue((char*)"Kll",pc,tte,i);
rslt = PyEval_CallObject(func,args);
Py_DECREF(args);
if (rslt)
Py_DECREF(rslt);
PyGILState_Release(gstate);
}
static void py_hook_reg_value( SS_Tracer* trc, SS_Registers::Index index, uint64_t value )
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
SS_PythonTracer* py_trc = (SS_PythonTracer*)trc;
PyObject *func, *args, *rslt;
func = (PyObject *)py_trc->py_reg_value;
args = Py_BuildValue((char*)"iK",index,value);
rslt = PyEval_CallObject(func,args);
Py_DECREF(args);
if (rslt)
Py_DECREF(rslt);
PyGILState_Release(gstate);
}
static void py_hook_trap( SS_Tracer* trc, SS_Trap::Type type, TrapMode mode, SS_Vaddr addr )
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
SS_PythonTracer* py_trc = (SS_PythonTracer*)trc;
PyObject *func, *args, *rslt;
func = (PyObject *)py_trc->py_trap;
args = Py_BuildValue((char*)"iiK",type,mode,addr);
rslt = PyEval_CallObject(func,args);
Py_DECREF(args);
if (rslt)
Py_DECREF(rslt);
PyGILState_Release(gstate);
}
static void py_hook_mem_access( SS_Tracer* trc, MemAccess type, SS_Vaddr va, SS_Tte* tte, uint_t size, uint64_t* data )
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
SS_PythonTracer* py_trc = (SS_PythonTracer*)trc;
PyObject *func, *args, *rslt;
func = (PyObject *)py_trc->py_mem_access;
switch (type)
{
case LD_CODE:
case LD_DATA:
case ST_DATA:
case LD_SWAP:
case ST_SWAP:
case LD_CAS:
case ST_LDST:
case LD_LDST:
switch (size)
{
case 1:
case 2:
case 4:
case 8:
args = Py_BuildValue((char*)"iKli[K]",type,va,tte,size,data[0]);
break;
case 16:
args = Py_BuildValue((char*)"iKli[K,K]",type,va,tte,size,data[0],data[1]);
break;
case 64:
args = Py_BuildValue((char*)"iKli[K,K,K,K,K,K,K,K]",type,va,tte,size,
data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7]);
break;
default:
assert(0);
}
break;
case ST_PART:
case ST_CAS:
args = Py_BuildValue((char*)"iKli[K,K]",type,va,tte,size,data[0],data[1]);
break;
case PREFETCH:
case FLUSH:
args = Py_BuildValue((char*)"iKli[]",type,va,tte,size);
break;
default:
assert(0);
}
rslt = PyEval_CallObject(func,args);
Py_DECREF(args);
if (rslt)
Py_DECREF(rslt);
PyGILState_Release(gstate);
}
static void py_hook_tlb_update( SS_Tracer* trc, bool insert, SS_Tlb* tlb, uint_t index, SS_Tte* tte )
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
SS_PythonTracer* py_trc = (SS_PythonTracer*)trc;
PyObject *func, *args, *rslt;
func = (PyObject *)py_trc->py_tlb_update;
args = Py_BuildValue((char*)"ilil",insert,tlb,index,tte);
rslt = PyEval_CallObject(func,args);
Py_DECREF(args);
if (rslt)
Py_DECREF(rslt);
PyGILState_Release(gstate);
}
static void py_hook_end_instr( SS_Tracer* trc )
{
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
SS_PythonTracer* py_trc = (SS_PythonTracer*)trc;
PyObject *func, *args, *rslt;
func = (PyObject *)py_trc->py_end_instr;
args = Py_BuildValue((char*)"");
rslt = PyEval_CallObject(func,args);
Py_DECREF(args);
if (rslt)
Py_DECREF(rslt);
PyGILState_Release(gstate);
}
void clr_exe_instr()
{
if (py_exe_instr)
Py_DECREF(py_exe_instr);
py_exe_instr = 0;
hook_exe_instr = 0;
}
void set_exe_instr( PyObject* func )
{
Py_INCREF(func);
if (py_exe_instr)
Py_DECREF(py_exe_instr);
py_exe_instr = func;
hook_exe_instr = &py_hook_exe_instr;
}
void clr_reg_value()
{
if (py_reg_value)
Py_DECREF(py_reg_value);
py_reg_value = 0;
hook_reg_value = 0;
}
void set_reg_value( PyObject* func )
{
Py_INCREF(func);
if (py_reg_value)
Py_DECREF(py_reg_value);
py_reg_value = func;
hook_reg_value = &py_hook_reg_value;
}
void clr_trap()
{
if (py_trap)
Py_DECREF(py_trap);
py_trap = 0;
hook_trap = 0;
}
void set_trap( PyObject* func )
{
Py_INCREF(func);
if (py_trap)
Py_DECREF(py_trap);
py_trap = func;
hook_trap = &py_hook_trap;
}
void clr_mem_access()
{
if (py_mem_access)
Py_DECREF(py_mem_access);
py_mem_access = 0;
hook_mem_access = 0;
}
void set_mem_access( PyObject* func )
{
Py_INCREF(func);
if (py_mem_access)
Py_DECREF(py_mem_access);
py_mem_access = func;
hook_mem_access = &py_hook_mem_access;
}
void clr_tlb_update()
{
if (py_tlb_update)
Py_DECREF(py_tlb_update);
py_tlb_update = 0;
hook_tlb_update = 0;
}
void set_tlb_update( PyObject* func )
{
Py_INCREF(func);
if (py_tlb_update)
Py_DECREF(py_tlb_update);
py_tlb_update = func;
hook_tlb_update = &py_hook_tlb_update;
}
void clr_end_instr()
{
if (py_end_instr)
Py_DECREF(py_end_instr);
py_end_instr = 0;
hook_end_instr = 0;
}
void set_end_instr( PyObject* func )
{
Py_INCREF(func);
if (py_end_instr)
Py_DECREF(py_end_instr);
py_end_instr = func;
hook_end_instr = &py_hook_end_instr;
}
private:
PyObject* py_exe_instr;
PyObject* py_reg_value;
PyObject* py_trap;
PyObject* py_mem_access;
PyObject* py_tlb_update;
PyObject* py_end_instr;
};
#endif