1 ///////////////////////////////////////////////////////////////////////// 2 // $Id: instrument.h 14160 2021-02-21 09:25:33Z vruppert $ 3 ///////////////////////////////////////////////////////////////////////// 4 // 5 // Copyright (c) 2009-2015 Stanislav Shwartsman 6 // Written by Stanislav Shwartsman [sshwarts at sourceforge net] 7 // 8 // This library is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU Lesser General Public 10 // License as published by the Free Software Foundation; either 11 // version 2 of the License, or (at your option) any later version. 12 // 13 // This library is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 // Lesser General Public License for more details. 17 // 18 // You should have received a copy of the GNU Lesser General Public 19 // License along with this library; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 #if BX_INSTRUMENTATION 23 24 class bxInstruction_c; 25 26 // define if you want to store instruction opcode bytes in bxInstruction_c 27 //#define BX_INSTR_STORE_OPCODE_BYTES 28 29 // called from the CPU core 30 31 void bx_instr_initialize(unsigned cpu); 32 void bx_instr_reset(unsigned cpu, unsigned type); 33 34 void bx_instr_interrupt(unsigned cpu, unsigned vector); 35 void bx_instr_exception(unsigned cpu, unsigned vector, unsigned error_code); 36 void bx_instr_hwinterrupt(unsigned cpu, unsigned vector, Bit16u cs, bx_address eip); 37 38 void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i); 39 40 /* initialization/deinitialization of instrumentalization*/ 41 #define BX_INSTR_INIT_ENV() 42 #define BX_INSTR_EXIT_ENV() 43 44 /* simulation init, shutdown, reset */ 45 #define BX_INSTR_INITIALIZE(cpu_id) bx_instr_initialize(cpu_id) 46 #define BX_INSTR_EXIT(cpu_id) 47 #define BX_INSTR_RESET(cpu_id, type) bx_instr_reset(cpu_id, type) 48 #define BX_INSTR_HLT(cpu_id) 49 #define BX_INSTR_MWAIT(cpu_id, addr, len, flags) 50 #define BX_INSTR_NEW_INSTRUCTION(cpu_id) 51 52 /* called from command line debugger */ 53 #define BX_INSTR_DEBUG_PROMPT() 54 #define BX_INSTR_DEBUG_CMD(cmd) 55 56 /* branch resolution */ 57 #define BX_INSTR_CNEAR_BRANCH_TAKEN(cpu_id, branch_eip, new_eip) 58 #define BX_INSTR_CNEAR_BRANCH_NOT_TAKEN(cpu_id, branch_eip) 59 #define BX_INSTR_UCNEAR_BRANCH(cpu_id, what, branch_eip, new_eip) 60 #define BX_INSTR_FAR_BRANCH(cpu_id, what, prev_cs, prev_rip, new_cs, new_eip) 61 62 /* decoding completed */ 63 #define BX_INSTR_OPCODE(cpu_id, i, opcode, len, is32, is64) 64 65 /* exceptional case and interrupt */ 66 #define BX_INSTR_EXCEPTION(cpu_id, vector, error_code) \ 67 bx_instr_exception(cpu_id, vector, error_code) 68 69 #define BX_INSTR_INTERRUPT(cpu_id, vector) bx_instr_interrupt(cpu_id, vector) 70 #define BX_INSTR_HWINTERRUPT(cpu_id, vector, cs, eip) bx_instr_hwinterrupt(cpu_id, vector, cs, eip) 71 72 /* TLB/CACHE control instruction executed */ 73 #define BX_INSTR_CLFLUSH(cpu_id, laddr, paddr) 74 #define BX_INSTR_CACHE_CNTRL(cpu_id, what) 75 #define BX_INSTR_TLB_CNTRL(cpu_id, what, new_cr3) 76 #define BX_INSTR_PREFETCH_HINT(cpu_id, what, seg, offset) 77 78 /* execution */ 79 #define BX_INSTR_BEFORE_EXECUTION(cpu_id, i) bx_instr_before_execution(cpu_id, i) 80 81 #define BX_INSTR_AFTER_EXECUTION(cpu_id, i) 82 #define BX_INSTR_REPEAT_ITERATION(cpu_id, i) 83 84 /* linear memory access */ 85 #define BX_INSTR_LIN_ACCESS(cpu_id, lin, phy, len, memtype, rw) 86 87 /* physical memory access */ 88 #define BX_INSTR_PHY_ACCESS(cpu_id, phy, len, memtype, rw) 89 90 /* feedback from device units */ 91 #define BX_INSTR_INP(addr, len) 92 #define BX_INSTR_INP2(addr, len, val) 93 #define BX_INSTR_OUTP(addr, len, val) 94 95 /* wrmsr callback */ 96 #define BX_INSTR_WRMSR(cpu_id, addr, value) 97 98 /* vmexit callback */ 99 #define BX_INSTR_VMEXIT(cpu_id, reason, qualification) 100 101 #else // BX_INSTRUMENTATION 102 103 /* initialization/deinitialization of instrumentalization */ 104 #define BX_INSTR_INIT_ENV() 105 #define BX_INSTR_EXIT_ENV() 106 107 /* simulation init, shutdown, reset */ 108 #define BX_INSTR_INITIALIZE(cpu_id) 109 #define BX_INSTR_EXIT(cpu_id) 110 #define BX_INSTR_RESET(cpu_id, type) 111 #define BX_INSTR_HLT(cpu_id) 112 #define BX_INSTR_MWAIT(cpu_id, addr, len, flags) 113 #define BX_INSTR_NEW_INSTRUCTION(cpu_id) 114 115 /* called from command line debugger */ 116 #define BX_INSTR_DEBUG_PROMPT() 117 #define BX_INSTR_DEBUG_CMD(cmd) 118 119 /* branch resolution */ 120 #define BX_INSTR_CNEAR_BRANCH_TAKEN(cpu_id, branch_eip, new_eip) 121 #define BX_INSTR_CNEAR_BRANCH_NOT_TAKEN(cpu_id, branch_eip) 122 #define BX_INSTR_UCNEAR_BRANCH(cpu_id, what, branch_eip, new_eip) 123 #define BX_INSTR_FAR_BRANCH(cpu_id, what, prev_cs, prev_rip, new_cs, new_eip) 124 125 /* decoding completed */ 126 #define BX_INSTR_OPCODE(cpu_id, i, opcode, len, is32, is64) 127 128 /* exceptional case and interrupt */ 129 #define BX_INSTR_EXCEPTION(cpu_id, vector, error_code) 130 #define BX_INSTR_INTERRUPT(cpu_id, vector) 131 #define BX_INSTR_HWINTERRUPT(cpu_id, vector, cs, eip) 132 133 /* TLB/CACHE control instruction executed */ 134 #define BX_INSTR_CLFLUSH(cpu_id, laddr, paddr) 135 #define BX_INSTR_CACHE_CNTRL(cpu_id, what) 136 #define BX_INSTR_TLB_CNTRL(cpu_id, what, new_cr3) 137 #define BX_INSTR_PREFETCH_HINT(cpu_id, what, seg, offset) 138 139 /* execution */ 140 #define BX_INSTR_BEFORE_EXECUTION(cpu_id, i) 141 #define BX_INSTR_AFTER_EXECUTION(cpu_id, i) 142 #define BX_INSTR_REPEAT_ITERATION(cpu_id, i) 143 144 /* linear memory access */ 145 #define BX_INSTR_LIN_ACCESS(cpu_id, lin, phy, len, memtype, rw) 146 147 /* physical memory access */ 148 #define BX_INSTR_PHY_ACCESS(cpu_id, phy, len, memtype, rw) 149 150 /* feedback from device units */ 151 #define BX_INSTR_INP(addr, len) 152 #define BX_INSTR_INP2(addr, len, val) 153 #define BX_INSTR_OUTP(addr, len, val) 154 155 /* wrmsr callback */ 156 #define BX_INSTR_WRMSR(cpu_id, addr, value) 157 158 /* vmexit callback */ 159 #define BX_INSTR_VMEXIT(cpu_id, reason, qualification) 160 161 #endif // BX_INSTRUMENTATION 162