instrumentation fixes + new example
This commit is contained in:
parent
074d2e6a95
commit
868e716411
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: fetchdecode.h,v 1.90 2009-10-24 11:17:51 sshwarts Exp $
|
||||
// $Id: fetchdecode.h,v 1.91 2009-11-04 15:48:27 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2009 Stanislav Shwartsman
|
||||
@ -64,13 +64,6 @@ struct bxIAOpcodeTable {
|
||||
BxExecutePtr_tR execute2;
|
||||
};
|
||||
|
||||
enum {
|
||||
#define bx_define_opcode(a, b, c) a,
|
||||
#include "ia_opcodes.h"
|
||||
BX_IA_LAST
|
||||
};
|
||||
#undef bx_define_opcode
|
||||
|
||||
//
|
||||
// Common FetchDecode Opcode Tables
|
||||
//
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: instr.h,v 1.22 2009-10-31 20:02:44 sshwarts Exp $
|
||||
// $Id: instr.h,v 1.23 2009-11-04 15:48:28 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2008-2009 Stanislav Shwartsman
|
||||
@ -22,9 +22,11 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BX_INSTR_H
|
||||
# define BX_INSTR_H 1
|
||||
#define BX_INSTR_H
|
||||
|
||||
#define BX_INSTRUMENT_IA_OPCODE 0
|
||||
#ifndef BX_INSTRUMENT_IA_OPCODE
|
||||
#define BX_INSTRUMENT_IA_OPCODE 0
|
||||
#endif
|
||||
|
||||
class bxInstruction_c;
|
||||
|
||||
@ -290,4 +292,11 @@ public:
|
||||
extern const char* BxOpcodeNamesTable[];
|
||||
#endif
|
||||
|
||||
enum {
|
||||
#define bx_define_opcode(a, b, c) a,
|
||||
#include "ia_opcodes.h"
|
||||
BX_IA_LAST
|
||||
};
|
||||
#undef bx_define_opcode
|
||||
|
||||
#endif
|
||||
|
78
bochs/instrument/example2/Makefile.in
Executable file
78
bochs/instrument/example2/Makefile.in
Executable file
@ -0,0 +1,78 @@
|
||||
# Copyright (C) 2001 MandrakeSoft S.A.
|
||||
#
|
||||
# MandrakeSoft S.A.
|
||||
# 43, rue d'Aboukir
|
||||
# 75002 Paris - France
|
||||
# http://www.linux-mandrake.com/
|
||||
# http://www.mandrakesoft.com/
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
|
||||
@SUFFIX_LINE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
SHELL = /bin/sh
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
|
||||
# ===========================================================
|
||||
# end of configurable options
|
||||
# ===========================================================
|
||||
|
||||
|
||||
BX_OBJS = \
|
||||
instrument.o
|
||||
|
||||
BX_INCLUDES =
|
||||
|
||||
BX_INCDIRS = -I../.. -I$(srcdir)/../.. -I. -I$(srcdir)/.
|
||||
|
||||
.@CPP_SUFFIX@.o:
|
||||
$(CXX) -c $(CXXFLAGS) $(BX_INCDIRS) @CXXFP@$< @OFP@$@
|
||||
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $(BX_INCDIRS) @CFP@$< @OFP@$@
|
||||
|
||||
|
||||
|
||||
libinstrument.a: $(BX_OBJS)
|
||||
@RMCOMMAND@ libinstrument.a
|
||||
@MAKELIB@ $(BX_OBJS)
|
||||
$(RANLIB) libinstrument.a
|
||||
|
||||
$(BX_OBJS): $(BX_INCLUDES)
|
||||
|
||||
|
||||
clean:
|
||||
@RMCOMMAND@ *.o
|
||||
@RMCOMMAND@ *.a
|
||||
|
||||
dist-clean: clean
|
||||
@RMCOMMAND@ Makefile
|
94
bochs/instrument/example2/instrument.cc
Executable file
94
bochs/instrument/example2/instrument.cc
Executable file
@ -0,0 +1,94 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: instrument.cc,v 1.1 2009-11-04 15:48:28 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2009 Stanislav Shwartsman
|
||||
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "bochs.h"
|
||||
#include "cpu/cpu.h"
|
||||
|
||||
struct {
|
||||
bx_bool active;
|
||||
Bit32u ia_cnt[BX_IA_LAST];
|
||||
Bit32u total_cnt;
|
||||
Bit32u interrupts;
|
||||
Bit32u exceptions;
|
||||
} ia_stats[BX_SMP_PROCESSORS];
|
||||
|
||||
static logfunctions *instrument_log = new logfunctions ();
|
||||
#define LOG_THIS instrument_log->
|
||||
|
||||
void bx_instr_initialize(unsigned cpu)
|
||||
{
|
||||
assert(cpu < BX_SMP_PROCESSORS);
|
||||
|
||||
ia_stats[cpu].active = 1;
|
||||
|
||||
fprintf(stderr, "Initialize cpu %d instrumentation module\n", cpu);
|
||||
}
|
||||
|
||||
void bx_instr_reset(unsigned cpu, unsigned type)
|
||||
{
|
||||
ia_stats[cpu].total_cnt = 0;
|
||||
|
||||
for(int n=0; n < BX_IA_LAST; n++)
|
||||
ia_stats[cpu].ia_cnt[n] = 0;
|
||||
|
||||
ia_stats[cpu].interrupts = ia_stats[cpu].exceptions = 0;
|
||||
}
|
||||
|
||||
void bx_instr_interrupt(unsigned cpu, unsigned vector)
|
||||
{
|
||||
if(ia_stats[cpu].active) ia_stats[cpu].interrupts++;
|
||||
}
|
||||
|
||||
void bx_instr_exception(unsigned cpu, unsigned vector, unsigned error_code)
|
||||
{
|
||||
if(ia_stats[cpu].active) ia_stats[cpu].exceptions++;
|
||||
}
|
||||
|
||||
void bx_instr_hwinterrupt(unsigned cpu, unsigned vector, Bit16u cs, bx_address eip)
|
||||
{
|
||||
if(ia_stats[cpu].active) ia_stats[cpu].interrupts++;
|
||||
}
|
||||
|
||||
#define IA_CNT_DUMP_THRESHOLD 100000000 /* 100M */
|
||||
|
||||
void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i)
|
||||
{
|
||||
if(ia_stats[cpu].active) {
|
||||
ia_stats[cpu].ia_cnt[i->ia_opcode]++;
|
||||
ia_stats[cpu].total_cnt++;
|
||||
|
||||
if (ia_stats[cpu].total_cnt > IA_CNT_DUMP_THRESHOLD) {
|
||||
printf("Dump IA stats for CPU %d\n", cpu);
|
||||
printf("----------------------------------------------------------\n");
|
||||
printf("Interrupts: %d, Exceptions: %d\n", ia_stats[cpu].interrupts, ia_stats[cpu].exceptions);
|
||||
for (int n=0;n < BX_IA_LAST; n++) {
|
||||
if (ia_stats[cpu].ia_cnt[n] > 0) {
|
||||
printf("%s: %f%%\n", BxOpcodeNamesTable[n], ia_stats[cpu].ia_cnt[n] * 100.0 / ia_stats[cpu].total_cnt);
|
||||
ia_stats[cpu].ia_cnt[n] = 0;
|
||||
}
|
||||
}
|
||||
ia_stats[cpu].total_cnt = 0;
|
||||
}
|
||||
}
|
||||
}
|
189
bochs/instrument/example2/instrument.h
Executable file
189
bochs/instrument/example2/instrument.h
Executable file
@ -0,0 +1,189 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: instrument.h,v 1.1 2009-11-04 15:48:28 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2009 Stanislav Shwartsman
|
||||
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
// possible types passed to BX_INSTR_TLB_CNTRL()
|
||||
#define BX_INSTR_MOV_CR3 10
|
||||
#define BX_INSTR_INVLPG 11
|
||||
#define BX_INSTR_TASKSWITCH 12
|
||||
|
||||
// possible types passed to BX_INSTR_CACHE_CNTRL()
|
||||
#define BX_INSTR_INVD 20
|
||||
#define BX_INSTR_WBINVD 21
|
||||
|
||||
// possible types passed to BX_INSTR_FAR_BRANCH()
|
||||
#define BX_INSTR_IS_CALL 10
|
||||
#define BX_INSTR_IS_RET 11
|
||||
#define BX_INSTR_IS_IRET 12
|
||||
#define BX_INSTR_IS_JMP 13
|
||||
#define BX_INSTR_IS_INT 14
|
||||
#define BX_INSTR_IS_SYSCALL 15
|
||||
#define BX_INSTR_IS_SYSRET 16
|
||||
#define BX_INSTR_IS_SYSENTER 17
|
||||
#define BX_INSTR_IS_SYSEXIT 18
|
||||
|
||||
// possible types passed to BX_INSTR_PREFETCH_HINT()
|
||||
#define BX_INSTR_PREFETCH_NTA 0
|
||||
#define BX_INSTR_PREFETCH_T0 1
|
||||
#define BX_INSTR_PREFETCH_T1 2
|
||||
#define BX_INSTR_PREFETCH_T2 3
|
||||
|
||||
#define BX_INSTRUMENT_IA_OPCODE 1
|
||||
|
||||
#if BX_INSTRUMENTATION
|
||||
|
||||
class bxInstruction_c;
|
||||
|
||||
// called from the CPU core
|
||||
|
||||
void bx_instr_initialize(unsigned cpu);
|
||||
void bx_instr_reset(unsigned cpu, unsigned type);
|
||||
|
||||
void bx_instr_interrupt(unsigned cpu, unsigned vector);
|
||||
void bx_instr_exception(unsigned cpu, unsigned vector, unsigned error_code);
|
||||
void bx_instr_hwinterrupt(unsigned cpu, unsigned vector, Bit16u cs, bx_address eip);
|
||||
|
||||
void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i);
|
||||
|
||||
/* initialization/deinitialization of instrumentalization*/
|
||||
#define BX_INSTR_INIT_ENV()
|
||||
#define BX_INSTR_EXIT_ENV()
|
||||
|
||||
/* simulation init, shutdown, reset */
|
||||
#define BX_INSTR_INITIALIZE(cpu_id) bx_instr_initialize(cpu_id)
|
||||
#define BX_INSTR_EXIT(cpu_id)
|
||||
#define BX_INSTR_RESET(cpu_id, type) bx_instr_reset(cpu_id, type)
|
||||
#define BX_INSTR_HLT(cpu_id)
|
||||
#define BX_INSTR_MWAIT(cpu_id, addr, len, flags)
|
||||
#define BX_INSTR_NEW_INSTRUCTION(cpu_id)
|
||||
|
||||
/* called from command line debugger */
|
||||
#define BX_INSTR_DEBUG_PROMPT()
|
||||
#define BX_INSTR_DEBUG_CMD(cmd)
|
||||
|
||||
/* branch resoultion */
|
||||
#define BX_INSTR_CNEAR_BRANCH_TAKEN(cpu_id, new_eip)
|
||||
#define BX_INSTR_CNEAR_BRANCH_NOT_TAKEN(cpu_id)
|
||||
#define BX_INSTR_UCNEAR_BRANCH(cpu_id, what, new_eip)
|
||||
#define BX_INSTR_FAR_BRANCH(cpu_id, what, new_cs, new_eip)
|
||||
|
||||
/* decoding completed */
|
||||
#define BX_INSTR_OPCODE(cpu_id, opcode, len, is32, is64)
|
||||
|
||||
/* exceptional case and interrupt */
|
||||
#define BX_INSTR_EXCEPTION(cpu_id, vector, error_code) \
|
||||
bx_instr_exception(cpu_id, vector, error_code)
|
||||
|
||||
#define BX_INSTR_INTERRUPT(cpu_id, vector) bx_instr_interrupt(cpu_id, vector)
|
||||
#define BX_INSTR_HWINTERRUPT(cpu_id, vector, cs, eip) bx_instr_hwinterrupt(cpu_id, vector, cs, eip)
|
||||
|
||||
/* TLB/CACHE control instruction executed */
|
||||
#define BX_INSTR_CLFLUSH(cpu_id, laddr, paddr)
|
||||
#define BX_INSTR_CACHE_CNTRL(cpu_id, what)
|
||||
#define BX_INSTR_TLB_CNTRL(cpu_id, what, new_cr3)
|
||||
#define BX_INSTR_PREFETCH_HINT(cpu_id, what, seg, offset)
|
||||
|
||||
/* execution */
|
||||
#define BX_INSTR_BEFORE_EXECUTION(cpu_id, i) bx_instr_before_execution(cpu_id, i)
|
||||
|
||||
#define BX_INSTR_AFTER_EXECUTION(cpu_id, i)
|
||||
#define BX_INSTR_REPEAT_ITERATION(cpu_id, i)
|
||||
|
||||
/* memory access */
|
||||
#define BX_INSTR_LIN_ACCESS(cpu_id, lin, phy, len, rw)
|
||||
|
||||
/* memory access */
|
||||
#define BX_INSTR_MEM_DATA_ACCESS(cpu_id, seg, offset, len, rw)
|
||||
|
||||
/* called from memory object */
|
||||
#define BX_INSTR_PHY_WRITE(cpu_id, addr, len)
|
||||
#define BX_INSTR_PHY_READ(cpu_id, addr, len)
|
||||
|
||||
/* feedback from device units */
|
||||
#define BX_INSTR_INP(addr, len)
|
||||
#define BX_INSTR_INP2(addr, len, val)
|
||||
#define BX_INSTR_OUTP(addr, len, val)
|
||||
|
||||
/* wrmsr callback */
|
||||
#define BX_INSTR_WRMSR(cpu_id, addr, value)
|
||||
|
||||
#else // BX_INSTRUMENTATION
|
||||
|
||||
/* initialization/deinitialization of instrumentalization */
|
||||
#define BX_INSTR_INIT_ENV()
|
||||
#define BX_INSTR_EXIT_ENV()
|
||||
|
||||
/* simulation init, shutdown, reset */
|
||||
#define BX_INSTR_INITIALIZE(cpu_id)
|
||||
#define BX_INSTR_EXIT(cpu_id)
|
||||
#define BX_INSTR_RESET(cpu_id, type)
|
||||
#define BX_INSTR_HLT(cpu_id)
|
||||
#define BX_INSTR_MWAIT(cpu_id, addr, len, flags)
|
||||
#define BX_INSTR_NEW_INSTRUCTION(cpu_id)
|
||||
|
||||
/* called from command line debugger */
|
||||
#define BX_INSTR_DEBUG_PROMPT()
|
||||
#define BX_INSTR_DEBUG_CMD(cmd)
|
||||
|
||||
/* branch resoultion */
|
||||
#define BX_INSTR_CNEAR_BRANCH_TAKEN(cpu_id, new_eip)
|
||||
#define BX_INSTR_CNEAR_BRANCH_NOT_TAKEN(cpu_id)
|
||||
#define BX_INSTR_UCNEAR_BRANCH(cpu_id, what, new_eip)
|
||||
#define BX_INSTR_FAR_BRANCH(cpu_id, what, new_cs, new_eip)
|
||||
|
||||
/* decoding completed */
|
||||
#define BX_INSTR_OPCODE(cpu_id, opcode, len, is32, is64)
|
||||
|
||||
/* exceptional case and interrupt */
|
||||
#define BX_INSTR_EXCEPTION(cpu_id, vector, error_code)
|
||||
#define BX_INSTR_INTERRUPT(cpu_id, vector)
|
||||
#define BX_INSTR_HWINTERRUPT(cpu_id, vector, cs, eip)
|
||||
|
||||
/* TLB/CACHE control instruction executed */
|
||||
#define BX_INSTR_CLFLUSH(cpu_id, laddr, paddr)
|
||||
#define BX_INSTR_CACHE_CNTRL(cpu_id, what)
|
||||
#define BX_INSTR_TLB_CNTRL(cpu_id, what, new_cr3)
|
||||
#define BX_INSTR_PREFETCH_HINT(cpu_id, what, seg, offset)
|
||||
|
||||
/* execution */
|
||||
#define BX_INSTR_BEFORE_EXECUTION(cpu_id, i)
|
||||
#define BX_INSTR_AFTER_EXECUTION(cpu_id, i)
|
||||
#define BX_INSTR_REPEAT_ITERATION(cpu_id, i)
|
||||
|
||||
/* memory access */
|
||||
#define BX_INSTR_LIN_ACCESS(cpu_id, lin, phy, len, rw)
|
||||
|
||||
/* memory access */
|
||||
#define BX_INSTR_MEM_DATA_ACCESS(cpu_id, seg, offset, len, rw)
|
||||
|
||||
/* called from memory object */
|
||||
#define BX_INSTR_PHY_WRITE(cpu_id, addr, len)
|
||||
#define BX_INSTR_PHY_READ(cpu_id, addr, len)
|
||||
|
||||
/* feedback from device units */
|
||||
#define BX_INSTR_INP(addr, len)
|
||||
#define BX_INSTR_INP2(addr, len, val)
|
||||
#define BX_INSTR_OUTP(addr, len, val)
|
||||
|
||||
/* wrmsr callback */
|
||||
#define BX_INSTR_WRMSR(cpu_id, addr, value)
|
||||
|
||||
#endif // BX_INSTRUMENTATION
|
Loading…
Reference in New Issue
Block a user