updated instrumentation callbacks

This commit is contained in:
Stanislav Shwartsman 2011-03-22 22:18:40 +00:00
parent a626140c35
commit 0a88065722
12 changed files with 132 additions and 84 deletions

View File

@ -403,6 +403,8 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR0Rd(bxInstruction_c *i)
#endif #endif
if (! SetCR0(val_32)) if (! SetCR0(val_32))
exception(BX_GP_EXCEPTION, 0); exception(BX_GP_EXCEPTION, 0);
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_MOV_CR0, val_32);
} }
void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR2Rd(bxInstruction_c *i) void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR2Rd(bxInstruction_c *i)
@ -462,6 +464,8 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR4Rd(bxInstruction_c *i)
#endif #endif
if (! SetCR4(val_32)) if (! SetCR4(val_32))
exception(BX_GP_EXCEPTION, 0); exception(BX_GP_EXCEPTION, 0);
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_MOV_CR4, val_32);
#endif #endif
} }
@ -536,6 +540,8 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR0Rq(bxInstruction_c *i)
#endif #endif
if (! SetCR0(val_64)) if (! SetCR0(val_64))
exception(BX_GP_EXCEPTION, 0); exception(BX_GP_EXCEPTION, 0);
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_MOV_CR0, (Bit32u) val_64);
} }
else { else {
// CR8 // CR8
@ -631,6 +637,8 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_CR4Rq(bxInstruction_c *i)
BX_DEBUG(("MOV_CqRq: write to CR4 of %08x:%08x", GET32H(val_64), GET32L(val_64))); BX_DEBUG(("MOV_CqRq: write to CR4 of %08x:%08x", GET32H(val_64), GET32L(val_64)));
if (! SetCR4(val_64)) if (! SetCR4(val_64))
exception(BX_GP_EXCEPTION, 0); exception(BX_GP_EXCEPTION, 0);
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_MOV_CR4, (Bit32u) val_64);
} }
void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RqCR0(bxInstruction_c *i) void BX_CPP_AttrRegparmN(1) BX_CPU_C::MOV_RqCR0(bxInstruction_c *i)

View File

@ -244,6 +244,8 @@ void BX_CPU_C::enter_system_management_mode(void)
BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]; BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]; BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]; BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_CONTEXT_SWITCH, 0);
} }
#define SMRAM_TRANSLATE(addr) (((0x8000 - (addr)) >> 2) - 1) #define SMRAM_TRANSLATE(addr) (((0x8000 - (addr)) >> 2) - 1)
@ -697,6 +699,8 @@ bx_bool BX_CPU_C::smram_restore_state(const Bit32u *saved_state)
if (SMM_REVISION_ID & SMM_SMBASE_RELOCATION) if (SMM_REVISION_ID & SMM_SMBASE_RELOCATION)
BX_CPU_THIS_PTR smbase = SMRAM_FIELD(saved_state, SMRAM_FIELD_SMBASE_OFFSET); BX_CPU_THIS_PTR smbase = SMRAM_FIELD(saved_state, SMRAM_FIELD_SMBASE_OFFSET);
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_CONTEXT_SWITCH, 0);
return 1; return 1;
} }

View File

@ -1588,6 +1588,8 @@ Bit32u BX_CPU_C::VMenterLoadCheckGuestState(Bit64u *qualification)
handleAvxModeChange(); handleAvxModeChange();
#endif #endif
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_CONTEXT_SWITCH, 0);
return VMXERR_NO_ERROR; return VMXERR_NO_ERROR;
} }
@ -2035,6 +2037,8 @@ void BX_CPU_C::VMexitLoadHostState(void)
#if BX_SUPPORT_AVX #if BX_SUPPORT_AVX
handleAvxModeChange(); handleAvxModeChange();
#endif #endif
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_CONTEXT_SWITCH, 0);
} }
void BX_CPU_C::VMexit(bxInstruction_c *i, Bit32u reason, Bit64u qualification) void BX_CPU_C::VMexit(bxInstruction_c *i, Bit32u reason, Bit64u qualification)
@ -2834,6 +2838,8 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::INVEPT(bxInstruction_c *i)
return; return;
} }
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_INVEPT, 0);
VMsucceed(); VMsucceed();
#else #else
BX_INFO(("INVEPT: required VMXx2 support, use --enable-vmx=2 option")); BX_INFO(("INVEPT: required VMXx2 support, use --enable-vmx=2 option"));
@ -2911,6 +2917,8 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::INVVPID(bxInstruction_c *i)
return; return;
} }
BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_INVVPID, 0);
VMsucceed(); VMsucceed();
#else #else
BX_INFO(("INVVPID: required VMXx2 support, use --enable-vmx=2 option")); BX_INFO(("INVVPID: required VMXx2 support, use --enable-vmx=2 option"));

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.cc,v 1.30 2009-10-14 20:45:29 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2006-2009 Stanislav Shwartsman // Copyright (c) 2006-2009 Stanislav Shwartsman

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.h,v 1.36 2009-10-14 20:45:29 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2006-2009 Stanislav Shwartsman // Copyright (c) 2006-2009 Stanislav Shwartsman
@ -21,30 +21,35 @@
// possible types passed to BX_INSTR_TLB_CNTRL() // possible types passed to BX_INSTR_TLB_CNTRL()
#define BX_INSTR_MOV_CR3 10 #define BX_INSTR_MOV_CR0 10
#define BX_INSTR_INVLPG 11 #define BX_INSTR_MOV_CR3 11
#define BX_INSTR_TASKSWITCH 12 #define BX_INSTR_MOV_CR4 12
#define BX_INSTR_TASK_SWITCH 13
#define BX_INSTR_CONTEXT_SWITCH 14
#define BX_INSTR_INVLPG 15
#define BX_INSTR_INVEPT 15
#define BX_INSTR_INVVPID 16
// possible types passed to BX_INSTR_CACHE_CNTRL() // possible types passed to BX_INSTR_CACHE_CNTRL()
#define BX_INSTR_INVD 20 #define BX_INSTR_INVD 20
#define BX_INSTR_WBINVD 21 #define BX_INSTR_WBINVD 21
// possible types passed to BX_INSTR_FAR_BRANCH() // possible types passed to BX_INSTR_FAR_BRANCH()
#define BX_INSTR_IS_CALL 10 #define BX_INSTR_IS_CALL 10
#define BX_INSTR_IS_RET 11 #define BX_INSTR_IS_RET 11
#define BX_INSTR_IS_IRET 12 #define BX_INSTR_IS_IRET 12
#define BX_INSTR_IS_JMP 13 #define BX_INSTR_IS_JMP 13
#define BX_INSTR_IS_INT 14 #define BX_INSTR_IS_INT 14
#define BX_INSTR_IS_SYSCALL 15 #define BX_INSTR_IS_SYSCALL 15
#define BX_INSTR_IS_SYSRET 16 #define BX_INSTR_IS_SYSRET 16
#define BX_INSTR_IS_SYSENTER 17 #define BX_INSTR_IS_SYSENTER 17
#define BX_INSTR_IS_SYSEXIT 18 #define BX_INSTR_IS_SYSEXIT 18
// possible types passed to BX_INSTR_PREFETCH_HINT() // possible types passed to BX_INSTR_PREFETCH_HINT()
#define BX_INSTR_PREFETCH_NTA 0 #define BX_INSTR_PREFETCH_NTA 0
#define BX_INSTR_PREFETCH_T0 1 #define BX_INSTR_PREFETCH_T0 1
#define BX_INSTR_PREFETCH_T1 2 #define BX_INSTR_PREFETCH_T1 2
#define BX_INSTR_PREFETCH_T2 3 #define BX_INSTR_PREFETCH_T2 3
#if BX_INSTRUMENTATION #if BX_INSTRUMENTATION

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.cc,v 1.25 2009-10-14 20:45:29 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2006-2009 Stanislav Shwartsman // Copyright (c) 2006-2009 Stanislav Shwartsman

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.h,v 1.35 2009-10-14 20:45:29 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2006-2009 Stanislav Shwartsman // Copyright (c) 2006-2009 Stanislav Shwartsman
@ -21,30 +21,35 @@
// possible types passed to BX_INSTR_TLB_CNTRL() // possible types passed to BX_INSTR_TLB_CNTRL()
#define BX_INSTR_MOV_CR3 10 #define BX_INSTR_MOV_CR0 10
#define BX_INSTR_INVLPG 11 #define BX_INSTR_MOV_CR3 11
#define BX_INSTR_TASKSWITCH 12 #define BX_INSTR_MOV_CR4 12
#define BX_INSTR_TASK_SWITCH 13
#define BX_INSTR_CONTEXT_SWITCH 14
#define BX_INSTR_INVLPG 15
#define BX_INSTR_INVEPT 15
#define BX_INSTR_INVVPID 16
// possible types passed to BX_INSTR_CACHE_CNTRL() // possible types passed to BX_INSTR_CACHE_CNTRL()
#define BX_INSTR_INVD 20 #define BX_INSTR_INVD 20
#define BX_INSTR_WBINVD 21 #define BX_INSTR_WBINVD 21
// possible types passed to BX_INSTR_FAR_BRANCH() // possible types passed to BX_INSTR_FAR_BRANCH()
#define BX_INSTR_IS_CALL 10 #define BX_INSTR_IS_CALL 10
#define BX_INSTR_IS_RET 11 #define BX_INSTR_IS_RET 11
#define BX_INSTR_IS_IRET 12 #define BX_INSTR_IS_IRET 12
#define BX_INSTR_IS_JMP 13 #define BX_INSTR_IS_JMP 13
#define BX_INSTR_IS_INT 14 #define BX_INSTR_IS_INT 14
#define BX_INSTR_IS_SYSCALL 15 #define BX_INSTR_IS_SYSCALL 15
#define BX_INSTR_IS_SYSRET 16 #define BX_INSTR_IS_SYSRET 16
#define BX_INSTR_IS_SYSENTER 17 #define BX_INSTR_IS_SYSENTER 17
#define BX_INSTR_IS_SYSEXIT 18 #define BX_INSTR_IS_SYSEXIT 18
// possible types passed to BX_INSTR_PREFETCH_HINT() // possible types passed to BX_INSTR_PREFETCH_HINT()
#define BX_INSTR_PREFETCH_NTA 0 #define BX_INSTR_PREFETCH_NTA 0
#define BX_INSTR_PREFETCH_T0 1 #define BX_INSTR_PREFETCH_T0 1
#define BX_INSTR_PREFETCH_T1 2 #define BX_INSTR_PREFETCH_T1 2
#define BX_INSTR_PREFETCH_T2 3 #define BX_INSTR_PREFETCH_T2 3
#if BX_INSTRUMENTATION #if BX_INSTRUMENTATION

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.cc,v 1.4 2010-01-09 15:11:32 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2009 Stanislav Shwartsman // Copyright (c) 2009 Stanislav Shwartsman

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.h,v 1.2 2010-01-09 15:11:32 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2009 Stanislav Shwartsman // Copyright (c) 2009 Stanislav Shwartsman
@ -21,30 +21,35 @@
// possible types passed to BX_INSTR_TLB_CNTRL() // possible types passed to BX_INSTR_TLB_CNTRL()
#define BX_INSTR_MOV_CR3 10 #define BX_INSTR_MOV_CR0 10
#define BX_INSTR_INVLPG 11 #define BX_INSTR_MOV_CR3 11
#define BX_INSTR_TASKSWITCH 12 #define BX_INSTR_MOV_CR4 12
#define BX_INSTR_TASK_SWITCH 13
#define BX_INSTR_CONTEXT_SWITCH 14
#define BX_INSTR_INVLPG 15
#define BX_INSTR_INVEPT 15
#define BX_INSTR_INVVPID 16
// possible types passed to BX_INSTR_CACHE_CNTRL() // possible types passed to BX_INSTR_CACHE_CNTRL()
#define BX_INSTR_INVD 20 #define BX_INSTR_INVD 20
#define BX_INSTR_WBINVD 21 #define BX_INSTR_WBINVD 21
// possible types passed to BX_INSTR_FAR_BRANCH() // possible types passed to BX_INSTR_FAR_BRANCH()
#define BX_INSTR_IS_CALL 10 #define BX_INSTR_IS_CALL 10
#define BX_INSTR_IS_RET 11 #define BX_INSTR_IS_RET 11
#define BX_INSTR_IS_IRET 12 #define BX_INSTR_IS_IRET 12
#define BX_INSTR_IS_JMP 13 #define BX_INSTR_IS_JMP 13
#define BX_INSTR_IS_INT 14 #define BX_INSTR_IS_INT 14
#define BX_INSTR_IS_SYSCALL 15 #define BX_INSTR_IS_SYSCALL 15
#define BX_INSTR_IS_SYSRET 16 #define BX_INSTR_IS_SYSRET 16
#define BX_INSTR_IS_SYSENTER 17 #define BX_INSTR_IS_SYSENTER 17
#define BX_INSTR_IS_SYSEXIT 18 #define BX_INSTR_IS_SYSEXIT 18
// possible types passed to BX_INSTR_PREFETCH_HINT() // possible types passed to BX_INSTR_PREFETCH_HINT()
#define BX_INSTR_PREFETCH_NTA 0 #define BX_INSTR_PREFETCH_NTA 0
#define BX_INSTR_PREFETCH_T0 1 #define BX_INSTR_PREFETCH_T0 1
#define BX_INSTR_PREFETCH_T1 2 #define BX_INSTR_PREFETCH_T1 2
#define BX_INSTR_PREFETCH_T2 3 #define BX_INSTR_PREFETCH_T2 3
#if BX_INSTRUMENTATION #if BX_INSTRUMENTATION

View File

@ -128,7 +128,7 @@ interrupt.
The callback is called each time the CLFLUSH instruction is executed. The callback is called each time the CLFLUSH instruction is executed.
void bx_instr_tlb_cntrl(unsigned cpu, unsigned what, bx_phy_address new_cr3); void bx_instr_tlb_cntrl(unsigned cpu, unsigned what, bx_phy_address new_cr_value);
void bx_instr_cache_cntrl(unsigned cpu, unsigned what); void bx_instr_cache_cntrl(unsigned cpu, unsigned what);
The callback is called each time, when Bochs simulator executes a cache/tlb The callback is called each time, when Bochs simulator executes a cache/tlb
@ -136,9 +136,17 @@ control instruction.
Possible instruction types, passed through bx_instr_tlb_cntrl: Possible instruction types, passed through bx_instr_tlb_cntrl:
#define BX_INSTR_MOV_CR3 10 #define BX_INSTR_MOV_CR0 10
#define BX_INSTR_INVLPG 11 #define BX_INSTR_MOV_CR3 11
#define BX_INSTR_TASKSWITCH 12 #define BX_INSTR_MOV_CR4 12
#define BX_INSTR_TASK_SWITCH 13
#define BX_INSTR_CONTEXT_SWITCH 14 /* VMM and SMM enter/exit */
#define BX_INSTR_INVLPG 15
#define BX_INSTR_INVEPT 15
#define BX_INSTR_INVVPID 16
The new_cr_value is provided for first for instruction types only and will be
undefined for all others.
Possible instruction types, passed through bx_instr_cache_cntrl: Possible instruction types, passed through bx_instr_cache_cntrl:

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.cc,v 1.34 2009-10-14 20:45:29 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2006-2009 Stanislav Shwartsman // Copyright (c) 2006-2009 Stanislav Shwartsman

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: instrument.h,v 1.44 2010-02-06 09:59:52 sshwarts Exp $ // $Id$
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2006-2009 Stanislav Shwartsman // Copyright (c) 2006-2009 Stanislav Shwartsman
@ -21,30 +21,35 @@
// possible types passed to BX_INSTR_TLB_CNTRL() // possible types passed to BX_INSTR_TLB_CNTRL()
#define BX_INSTR_MOV_CR3 10 #define BX_INSTR_MOV_CR0 10
#define BX_INSTR_INVLPG 11 #define BX_INSTR_MOV_CR3 11
#define BX_INSTR_TASKSWITCH 12 #define BX_INSTR_MOV_CR4 12
#define BX_INSTR_TASK_SWITCH 13
#define BX_INSTR_CONTEXT_SWITCH 14
#define BX_INSTR_INVLPG 15
#define BX_INSTR_INVEPT 15
#define BX_INSTR_INVVPID 16
// possible types passed to BX_INSTR_CACHE_CNTRL() // possible types passed to BX_INSTR_CACHE_CNTRL()
#define BX_INSTR_INVD 20 #define BX_INSTR_INVD 20
#define BX_INSTR_WBINVD 21 #define BX_INSTR_WBINVD 21
// possible types passed to BX_INSTR_FAR_BRANCH() // possible types passed to BX_INSTR_FAR_BRANCH()
#define BX_INSTR_IS_CALL 10 #define BX_INSTR_IS_CALL 10
#define BX_INSTR_IS_RET 11 #define BX_INSTR_IS_RET 11
#define BX_INSTR_IS_IRET 12 #define BX_INSTR_IS_IRET 12
#define BX_INSTR_IS_JMP 13 #define BX_INSTR_IS_JMP 13
#define BX_INSTR_IS_INT 14 #define BX_INSTR_IS_INT 14
#define BX_INSTR_IS_SYSCALL 15 #define BX_INSTR_IS_SYSCALL 15
#define BX_INSTR_IS_SYSRET 16 #define BX_INSTR_IS_SYSRET 16
#define BX_INSTR_IS_SYSENTER 17 #define BX_INSTR_IS_SYSENTER 17
#define BX_INSTR_IS_SYSEXIT 18 #define BX_INSTR_IS_SYSEXIT 18
// possible types passed to BX_INSTR_PREFETCH_HINT() // possible types passed to BX_INSTR_PREFETCH_HINT()
#define BX_INSTR_PREFETCH_NTA 0 #define BX_INSTR_PREFETCH_NTA 0
#define BX_INSTR_PREFETCH_T0 1 #define BX_INSTR_PREFETCH_T0 1
#define BX_INSTR_PREFETCH_T1 2 #define BX_INSTR_PREFETCH_T1 2
#define BX_INSTR_PREFETCH_T2 3 #define BX_INSTR_PREFETCH_T2 3
#if BX_INSTRUMENTATION #if BX_INSTRUMENTATION