Debian Codegraph @

docs-html/bxdebugger.html

raw symbols SCIP
1 <HTML>
2
3 <BODY TEXT="#000000" BGCOLOR="#ececec" LINK="#3333cc" VLINK="#666666">
4
5 <CENTER><H1><I>Welcome to the Bochs x86 PC Emulation Software Home Page!</I></H1></CENTER>
6
7 <HR>
8 <HR>
9 <H3>Debugger Functions:</H3>
10
11 <P><B>void bx_dbg_exit(int code)</B>
12 <P>When there is a situation in the simulator, where you need to terminate
13 due to an unrecoverable error (panic), call <I>bx_dbg_exit()</I>. Among
14 other things, this function will call the <I>at_exit</I> callback function
15 in each simulator, and ultimately call the system exit() function.
16
17 <P><B>Bit8u bx_dbg_IAC(void)</B>
18 <P>The simulator's CPU code should call this function when it is acknowledging an
19 interrupt from the PIC via the INTR line. The interrupt vector number from the PIC
20 is returned.
21
22 <P><B>Bit32u bx_dbg_inp(Bit16u addr, unsigned len)</B>
23 <P>To read data from an IO device, the simulator should call this function.
24 Pass in the IO address <I>addr</I>, and the size of the IO operation <I>len</I>.
25
26 <P><B>void bx_dbg_outp(Bit16u addr, Bit32u value, unsigned len)</B>
27 <P>To write data to an IO device, the simulator should call this function.
28 Pass in the IO address <I>addr</I>, and the size of the IO operation <I>len</I>.
29
30 <P><B>Bit8u bx_dbg_ucmem_read(Bit32u addr)</B>
31 <BR><B>void bx_dbg_ucmem_write(Bit32u addr, Bit8u value)</B>
32 <P>For memory read/write accesses which fall in the range of 0xA0000 to 0xBFFFF,
33 the accesses should not be to directed to the simulator's memory, since
34 these are UnCacheable MEMory addresses. The VGA adapter maps it's memory to this
35 range. Instead, call these functions to perform reads/writes to memory
36 accesses in this range. For <I>bx_dbg_ucmem_read()</I>, pass the physical address
37 <I>addr</I>, and the value of the read is returned. For <I>bx_dbg_ucmem_write()</I>,
38 pass the physical address <I>addr</I> and value <I>value</I> of the write.
39
40 <P><B>void bx_dbg_async_pin_ack(unsigned what, bool val)</B>
41 <P>In order for the master and slave simulators to accept changes in pins
42 such as the A20 line, at the same point, the debugger provides a mechanism
43 for pending the pin change, until it is acknowledged by the master simulator.
44 The place where the change is ack'd, is recorded by the debugger. This
45 information is used to run the slave simulator, forcing it to accept the
46 changes at the same locale as did the master.
47
48 <P>Initially, the IO devices call a function <I>bx_dbg_async_pin_request()</I>,
49 not listed here, to record the pin change as pending. The pending status
50 is recorded along with the guard information in <I>bx_guard.async_changes_pending.which</I>.
51 This field contains a binary OR'd set of pending pin changes. Currently
52 only A20 is supported, which is represented by the macro BX_DBG_ASYNC_PENDING_A20.
53
54 <P>At a time prudent to your CPU simulator, check to see if there are
55 any pending changes, that the CPU should acknowledge. If so, acknowledge
56 them by calling <I>bx_dbg_async_pin_ack()</I>. The pending value of
57 the A20 enable is stored in <I>bx_guard.async_changes_pending.a20</I>.
58 Here is some sample code which performs this task, that you can insert
59 into the appropriate place in your CPU simulator.
60
61 <PRE>
62 if (bx_guard.async_changes_pending.which) {
63 if (bx_guard.async_changes_pending.which & BX_DBG_ASYNC_PENDING_A20)
64 bx_dbg_async_pin_ack(BX_DBG_ASYNC_PENDING_A20,
65 bx_guard.async_changes_pending.a20);
66 // ...other checks here when they are supported
67 }
68 </PRE>
69
70 The <I>bx_dbg_async_pin_ack()</I> function will in turn, invoke
71 the <I>set_A20()</I> callback function in the master simulator, so you
72 don't have to deal with updating local A20 state in your simulator here,
73 as long as you handle it in <I>set_A20()</I>. Keep in mind, the slave
74 simulator will never see the code inside this sample code if-construct,
75 since changes are forced in the slave by the debugger at points where the master
76 simulator acknowledged them, not as a direct effect of the IO devices.
77
78 <HR>
79 <HR>
80 <H3>Guards:</H3>
81
82 Guards are a mechanism by which the debugger requests each simulator
83 to stop execution and return control back to the debugger. The debugger
84 runs each simulator for a particular number of instructions, or until
85 certain events occur. Guards are set by the debugger, and it is up
86 to each simulator to examine them upon and during execution of the <I>execute()</I>
87 callback, and return control back to the debugger when the guard criteria
88 are met.
89
90 <P>Guard information set by the debugger is stored in global structure
91 <I>bx_guard</I> of type <I>bx_guard_t</I>. For reference, it's declaration
92 is shown here, followed by an explanation of the purpose of each field.
93 Information about the guard encountered by the simulator, and which
94 caused control to return to the debugger is stored in the global structure
95 <I>bx_guard_found[]</I> of type <I>bx_guard_found_t</I>. This is actually
96 an array of structures, where <I>bx_guard_found[0]</I> is the first simulator
97 with ID 0, and <I>bx_guard_found[1]</I> is the second simulator with
98 ID 1. This structure is also declared below, and the text explains
99 the information which should be returned in this structure based on
100 the guard encountered.
101
102 <PRE>
103 typedef struct {
104 unsigned long guard_for;
105
106 // instruction address breakpoints
107 struct {
108 #if BX_DBG_SUPPORT_VIR_BPOINT
109 unsigned num_virtual;
110 struct {
111 Bit32u cs; // only use 16 bits
112 Bit32u eip;
113 unsigned bpoint_id;
114 } vir[BX_DBG_MAX_VIR_BPOINTS];
115 #endif
116
117 #if BX_DBG_SUPPORT_LIN_BPOINT
118 unsigned num_linear;
119 struct {
120 Bit32u addr;
121 unsigned bpoint_id;
122 } lin[BX_DBG_MAX_LIN_BPOINTS];
123 #endif
124
125 #if BX_DBG_SUPPORT_PHY_BPOINT
126 unsigned num_physical;
127 struct {
128 Bit32u addr;
129 unsigned bpoint_id;
130 } phy[BX_DBG_MAX_PHY_BPOINTS];
131 #endif
132 } iaddr;
133
134 bx_dbg_icount_t icount; // stop after completing this many instructions
135
136 // user typed Ctrl-C, requesting simulator stop at next convient spot
137 volatile bool interrupt_requested;
138
139 // booleans to control whether simulator should report events
140 // to debug controller
141 struct {
142 bool irq;
143 bool a20;
144 bool io;
145 bool ucmem;
146 bool dma;
147 } report;
148
149 struct {
150 bool irq; // should process IRQs asynchronously
151 bool dma; // should process DMAs asynchronously
152 } async;
153
154 #define BX_DBG_ASYNC_PENDING_A20 0x01
155 #define BX_DBG_ASYNC_PENDING_RESET 0x02
156 #define BX_DBG_ASYNC_PENDING_NMI 0x04
157
158 // Asynchronous changes which are pending. These are Q'd by
159 // the debugger, as the master simulator is notified of a pending
160 // async change. At the simulator's next point, where it checks for
161 // such events, it notifies the debugger with acknowlegement. This
162 // field contains a logically or'd list of all events which should
163 // be checked, and ack'd.
164 struct {
165 unsigned which; // logical OR of above constants
166 bool a20;
167 bool reset;
168 bool nmi;
169 } async_changes_pending;
170 } bx_guard_t;
171
172 typedef struct {
173 unsigned long guard_found;
174 unsigned iaddr_index;
175 bx_dbg_icount_t icount; // number of completed instructions
176 Bit32u cs; // cs:eip and linear addr of instruction at guard point
177 Bit32u eip;
178 Bit32u laddr;
179 bool is_32bit_code; // CS seg size at guard point
180 bool ctrl_c; // simulator stopped due to Ctrl-C request
181 } bx_guard_found_t;
182
183 extern bx_guard_t bx_guard;
184 extern bx_guard_found_t bx_guard_found[];
185 </PRE>
186
187 <HR>
188 <H3>bx_guard_found[]:</H3>
189 It is the task of each simulator to update the <I>bx_guard_found</I>
190 structure.
191 There are some fields which are specific to the type of guard in
192 question, and you should update those when a particular guard is
193 encountered. Those fields are explained in more detail in the section
194 relating to the specific guard. There are some fields which are
195 updated for every case, no matter what the guard is. Below is a list
196 and explanation of the usage of each field.
197
198 <P><B>unsigned long guard_found;</B> this should be filled in with the
199 particular guard encountered, for example if an instruction count
200 guard is hit, set this to BX_DBG_GUARD_ICOUNT.
201
202 <P><B>unsigned iaddr_index;</B>
203 This field is updated, whenever a virtual/linear/physical instruction
204 address guard is hit. It is the array index into the bx_guard.iaddr.vir[],
205 bx_guard.iaddr.lin[], or bx_guard.iaddr.phy[] arrays, whichever is appropriate.
206
207 <P><B>bx_dbg_icount_t icount;</B>
208 This contains the number of instructions which have been completely
209 executed, when the guard was encountered.
210
211 <P><B>Bit32u cs;</B>
212 <BR><B>Bit32u eip;</B>
213 <BR><B>Bit32u laddr;</B>
214 <BR><B>bool is_32bit_code;</B>
215 These all relate to the same instruction address. From the debugger's
216 point of view, instruction addresses can be only at the beginning of
217 the instruction. Once an instruction is completed, use the address
218 of the next instruction.
219 Set <I>cs</I> and <I>eip</I> to the instruction's address (CS:EIP).
220 Set <I>laddr</I> to the instruction's corresponding linear address.
221 Set <I>is_32bit_code</I> to the size (0=16bit, 1=32bit) of the code
222 segment when the guard is encountered. This is used for disassembly.
223
224 <P><B>bool ctrl_c;</B>
225 To allow the user to interrupt a simulator from the debug prompt, the
226 debugger traps Ctrl-C interrupts, and sets <I>bx_guard.interrupt_requested</I>.
227 Your simulator can optionally look for this, provided that the
228 BX_DBG_GUARD_CTRL_C bit is set in <I>bx_guard.guard_for</I> structure.
229 If you chose to do so, you may look for this occurrance whenever is
230 convenient. Set <I>ctrl_c</I> to 1 to signify this guard has occurred.
231 Here' some sample code to demonstrate this:
232 <PRE>
233 // convenient point to see if user typed Ctrl-C
234 if (bx_guard.interrupt_requested && (bx_guard.guard_for & BX_DBG_GUARD_CTRL_C)) {
235 bx_guard_found[BX_SIM_ID].guard_found = BX_DBG_GUARD_CTRL_C;
236 return; // some mechanism to return control here
237 }
238 </PRE>
239
240 <HR>
241 <H3>bx_guard:</H3>
242 <P><B>unsigned long guard_for;</B>
243 <P>This is a binary OR'd list of guards the debugger is requesting each
244 simulator to stop on. Only if the corresponding bit is set in this field,
245 should the simulator examine the rest of the criteria for that guard.
246 Currently, each simulator must be capable of recognizing the following
247 guards, and returning to the debugger when they occur:
248 <UL>
249 <LI>BX_DBG_GUARD_ICOUNT: Instruction count.
250 <LI>BX_DBG_GUARD_CTRL_C: User requested interrupt via Ctrl-C
251 <LI>BX_DBG_GUARD_IADDR_VIR: Stop on this virtual instruction address
252 <LI>BX_DBG_GUARD_IADDR_LIN: Stop on this linear instruction address
253 <LI>BX_DBG_GUARD_IADDR_PHY: Stop on this physical instruction address
254 </UL>
255
256 <P><B>struct { .. } iaddr;</B>
257 <P>This structure holds the guard information for instruction address
258 guards (breakpoints). Depending upon your selections, after editing
259 <I>config.h</I> in the main directory (generated by running ./configure),
260 certain types of instruction address guards are supported. Which ones,
261 are determined by the BX_DBG_SUPPORT_VIR_BPOINT, BX_DBG_SUPPORT_LIN_BPOINT,
262 and BX_DBG_SUPPORT_PHY_BPOINT macros.
263
264 <P>If the <I>guard_for</I> field contains a set bit represented by
265 BX_DBG_GUARD_IADDR_VIR, then the <I>iaddr.num_virtual</I> field holds
266 the number of virtual instruction address guards to examine and compare
267 to the current address. For each, you must examine the CS:EIP values
268 stored in <I>iaddr.vir[n]</I>, in the <I>cs</I> and <I>eip</I> subfields.
269 If there is a match, record this in the guard found structure, and
270 return control to the debugger:
271 <PRE>
272 bx_guard_found[ID].guard_found = BX_DBG_GUARD_IADDR_VIR;
273 bx_guard_found[ID].iaddr_index = n; // array index in bx_guard.iaddr.vir[]
274 bx_guard_found[ID].icount = .. // number of completed instructions
275 bx_guard_found[ID].cs = .. // CS selector value
276 bx_guard_found[ID].eip = .. // EIP value
277 bx_guard_found[ID].laddr = .. // linear address of CS:EIP
278 bx_guard_found[ID].is_32bit_code = .. // 0=16bit code, 1=32bit code
279 // return control here
280 </PRE>
281
282 <P>If the <I>guard_for</I> field contains a set bit represented by
283 BX_DBG_GUARD_IADDR_LIN, then the <I>iaddr.num_linear</I> field holds
284 the number of linear instruction address guards to examine and compare
285 to the current address. For each, you must examine the linear address values
286 stored in <I>iaddr.lin[n]</I>, in the <I>addr</I> subfield.
287 If there is a match, record this in the guard found structure, and
288 return control to the debugger:
289 <PRE>
290 bx_guard_found[ID].guard_found = BX_DBG_GUARD_IADDR_LIN;
291 bx_guard_found[ID].iaddr_index = n; // array index in bx_guard.iaddr.lin[]
292 bx_guard_found[ID].icount = .. // number of completed instructions
293 bx_guard_found[ID].cs = .. // CS selector value
294 bx_guard_found[ID].eip = .. // EIP value
295 bx_guard_found[ID].laddr = .. // linear address of CS:EIP
296 bx_guard_found[ID].is_32bit_code = .. // 0=16bit code, 1=32bit code
297 // return control here
298 </PRE>
299
300 <P>If the <I>guard_for</I> field contains a set bit represented by
301 BX_DBG_GUARD_IADDR_PHY, then the <I>iaddr.num_physical</I> field holds
302 the number of physical instruction address guards to examine and compare
303 to the current address. For each, you must examine the physical address values
304 stored in <I>iaddr.phy[n]</I>, in the <I>addr</I> subfield.
305 If there is a match, record this in the guard found structure, and
306 return control to the debugger:
307 <PRE>
308 bx_guard_found[ID].guard_found = BX_DBG_GUARD_IADDR_PHY;
309 bx_guard_found[ID].iaddr_index = n; // array index in bx_guard.iaddr.phy[]
310 bx_guard_found[ID].icount = .. // number of completed instructions
311 bx_guard_found[ID].cs = .. // CS selector value
312 bx_guard_found[ID].eip = .. // EIP value
313 bx_guard_found[ID].laddr = .. // linear address of CS:EIP
314 bx_guard_found[ID].is_32bit_code = .. // 0=16bit code, 1=32bit code
315 // return control here
316 </PRE>
317
318
319 <P><B>volatile bool interrupt_requested;</B>
320 <P>If the debugger has turned on the guard for a user interrupt, and
321 the user has indeed requested one (Ctrl-C), the debugger will set
322 this field to 1. The simulator should record this in the guard found
323 information, and return control back to the debugger. Look above at the
324 explanation for the <I>bx_guard.interrupt_requested</I> field for some sample code
325 on how to do this.
326
327 <P><B>struct { .. } async;</B>
328 <P><B>struct { .. } async_changes_pending;</B>
329
330 <HR SIZE=5 NOSHADE>
331 <P>
332
333 </BODY>
334 </HTML>