3 To use instrumentation features in bochs, you must compile in support for it.
4 You should build a custom instrumentation library in a separate directory in
5 the "instrument/" directory. To tell configure which instrumentation library
6 you want to use, use the "--enable-instrumentation" option. The default
7 library consists of a set of stubs, and the following are equivalent:
9 ./configure [...] --enable-instrumentation
10 ./configure [...] --enable-instrumentation="instrument/stubs"
12 You could make a separate directory with your custom library, for example
13 "instrument/myinstrument", copy the contents of the "instrument/stubs"
14 directory to it, then customize it. Use:
16 ./configure [...] --enable-instrumentation="instrument/myinstrument"
18 -----------------------------------------------------------------------------
19 BOCHS instrumentation callbacks
22 void bx_instr_init_env();
24 The callback is called when Bochs is initialized, before of reading .bochsrc.
25 It can be used for registration of parameters in siminterface. Then
26 when bx_instr_init() is called it can access configuration parameters defined
28 by bx_instr_init_env(), so instrumentalization module can use additional
32 void bx_instr_exit_env();
34 The callback is called each time Bochs exits.
37 void bx_instr_initialize(unsigned cpu);
39 The callback is called each time, when Bochs initializes the CPU object. It
40 can be used for initialization of user's data, dynamic memory allocation and
44 void bx_instr_exit(unsigned cpu);
46 The callback is called each time, when Bochs destructs the CPU object. It can
47 be used for destruction of user's data, allocated by bx_instr_init callback.
50 void bx_instr_reset(unsigned cpu, unsigned type);
52 The callback is called each time, when Bochs resets the CPU object. It would
53 be executed once at the start of simulation and each time that user presses
54 RESET BUTTON on the simulator's control panel.
57 void bx_instr_hlt(unsigned cpu);
59 The callback is called each time, when Bochs' emulated CPU enters HALT or
63 void bx_instr_mwait(unsigned cpu, bx_phy_address addr, unsigned len, Bit32u flags);
65 The callback is called each time, when Bochs' emulated CPU enters to the MWAIT
66 state. The callback receives monitored memory range and MWAIT flags as a
70 void bx_instr_new_instruction(unsigned cpu);
72 The callback is called each time, when Bochs completes (commits) already
73 finished instruction and starts a new one.
76 void bx_instr_cnear_branch_taken(unsigned cpu, bx_address new_eip);
78 The callback is called each time, when currently executed instruction is a
79 conditional near branch and it is taken.
82 void bx_instr_cnear_branch_not_taken(unsigned cpu);
84 The callback is called each time, when currently executed instruction is a
85 conditional near branch and it is not taken.
88 void bx_instr_ucnear_branch(unsigned cpu, unsigned what, bx_address new_eip);
90 The callback is called each time, when currently executed instruction is an
91 unconditional near branch (always taken).
94 void bx_instr_far_branch(unsigned cpu, unsigned what, Bit16u new_cs, bx_address new_eip);
96 The callback is called each time, when currently executed instruction is an
97 unconditional far branch (always taken).
100 void bx_instr_opcode(unsigned cpu, const Bit8u *opcode, unsigned len, bx_bool is32, bx_bool is64);
102 The callback is called each time, when Bochs starts to decode a new
103 instruction. Through this callback function Bochs could provide an opcode of
104 the instruction, opcode length and an execution mode (16/32/64).
106 Currently the callback is not supported when trace-cache optimization feature
110 void bx_instr_interrupt(unsigned cpu, unsigned vector);
112 The callback is called each time, when Bochs simulator executes an interrupt
113 (software interrupt, hardware interrupt or an exception).
116 void bx_instr_exception(unsigned cpu, unsigned vector);
118 The callback is called each time, when Bochs simulator executes an exception.
121 void bx_instr_hwinterrupt(unsigned cpu, unsigned vector, Bit16u cs, bx_address eip);
123 The callback is called each time, when Bochs simulator executes a hardware
127 void bx_instr_clflush(unsigned cpu, bx_address laddr, bx_phy_address paddr);
129 The callback is called each time the CLFLUSH instruction is executed.
132 void bx_instr_tlb_cntrl(unsigned cpu, unsigned what, bx_phy_address new_cr3);
133 void bx_instr_cache_cntrl(unsigned cpu, unsigned what);
135 The callback is called each time, when Bochs simulator executes a cache/tlb
138 Possible instruction types, passed through bx_instr_tlb_cntrl:
140 #define BX_INSTR_MOV_CR3 10
141 #define BX_INSTR_INVLPG 11
142 #define BX_INSTR_TASKSWITCH 12
144 Possible instruction types, passed through bx_instr_cache_cntrl:
146 #define BX_INSTR_INVD 20
147 #define BX_INSTR_WBINVD 21
150 void bx_instr_prefetch_hint(unsigned cpu, unsigned what, unsigned seg, bx_address offset);
152 The callback is called each time, when Bochs simulator executes a PREFETCH
155 Possible PREFETCH types:
157 #define BX_INSTR_PREFETCH_NTA 00
158 #define BX_INSTR_PREFETCH_T0 01
159 #define BX_INSTR_PREFETCH_T1 02
160 #define BX_INSTR_PREFETCH_T2 03
162 The seg/offset arguments indicate the address of the requested prefetch.
165 void bx_instr_wrmsr(unsigned cpu, unsigned msr, Bit64u value);
167 This callback is called each time when WRMSR instruction is executed.
168 MSR number and written value passed as parameters to the callback function.
171 void bx_instr_repeat_iteration(unsigned cpu, bxInstruction_c *i);
173 The callback is called each time, when Bochs simulator starts a new repeat
177 void bx_instr_before_execution(unsigned cpu, bxInstruction_c *i);
179 The callback is called each time, when Bochs simulator starts a new
180 instruction execution. In case of repeat instruction the callback will
181 be called only once before the first iteration will be started.
184 void bx_instr_after_execution(unsigned cpu, bxInstruction_c *i);
186 The callback is called each time, when Bochs simulator finishes any
187 instruction execution. In case of repeat instruction the callback will
188 be called only once after all repeat iterations.
191 void bx_instr_lin_access(unsigned cpu, bx_address lin, bx_address phy, unsigned len, unsigned rw);
193 The callback is called each time, when Bochs simulator executes a linear
194 memory access. Note that no page split accesses will be generated because
195 Bochs splits page split accesses to two different memory accesses during its
196 execution flow. The callback also will not be generated in case of direct
197 physical memory access like in SMM, VMM or SVM modes.
199 Possible access types are: BX_READ, BX_WRITE and BX_RW.
201 Currently the callback is not supported when repeat-speedups optimization is
205 void bx_instr_mem_data_access(unsigned cpu, unsigned seg, bx_address offset, unsigned len, unsigned rw);
207 The callback is called each time, when Bochs simulator executes segment based
208 linear memory access. In contrast to previous callback it will be called even
209 if memory access fails because of any reason (for example segment protection
210 failure or page fault).
212 The callback will not be called for system memory accesses like sys desriptor
213 tables reads/writes or new stack pushes during far call or exception.
216 void bx_instr_phy_read(unsigned cpu, bx_address addr, unsigned len);
217 void bx_instr_phy_write(unsigned cpu, bx_address addr, unsigned len);
219 These callback functions are the feedback from external memory system.
222 void bx_instr_inp(Bit16u addr, unsigned len);
223 void bx_instr_outp(Bit16u addr, unsigned len);
224 void bx_instr_inp2(Bit16u addr, unsigned len, unsigned val);
225 void bx_instr_outp2(Bit16u addr, unsigned len, unsigned val);
227 These callback functions are a feedback from various system devices.
229 -----------------------------------------------------------------------------
232 1. BX_INSTR_LIN_ACCESS doesn't work when repeat-speedups feature is enabled.
234 2. BX_INSTR_MEM_DATA doesn't work when repeat-speedups feature is enabled.
236 3. BX_INSTR_OPCODE doesn't work with trace cache optimization enabled
240 1. BX_INSTR_CNEAR_BRANCH_NOT_TAKEN callback should have an additional
241 'not taken' new_EIP parameter.
243 2. BX_INSTR_SMI, BX_INSTR_NMI, BX_INSTR_SIPI and other external events
248 While using Bochs as a reference model for simulations, the simulator needs
249 information about what loads/stores are taking place with each instruction.
250 Presumably, that is what the BX_INSTR_MEM_DATA() instrumentation macros
251 cover (which is the place where our simulator hooks up).
253 The RETnear_xxx() functions call access_linear() directly, rather than call
254 read_virtual_xxx() functions. This is a problem for code making use of the
255 BX_INSTR_MEM_DATA() hook because it does not get called for these
256 instructions. Should this be changed along with some other instructions