OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [bx_debug/] [debug.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: debug.h 11580 2013-01-19 20:45:03Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2013  The Bochs Project
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20
 
21
#ifndef BX_DEBUG_H
22
#define BX_DEBUG_H
23
 
24
// if including from C parser, need basic types etc
25
#include "config.h"
26
#include "osdep.h"
27
 
28
#define BX_DBG_NO_HANDLE 1000
29
 
30
Bit32u crc32(const Bit8u *buf, int len);
31
 
32
#if BX_DEBUGGER
33
 
34
// some strict C declarations needed by the parser/lexer
35
#ifdef __cplusplus
36
extern "C" {
37
#endif
38
 
39
extern Bit32u dbg_cpu;
40
 
41
void dbg_printf (const char *fmt, ...);
42
 
43
typedef enum {
44
  BX_DBG_SREG_ES,
45
  BX_DBG_SREG_CS,
46
  BX_DBG_SREG_SS,
47
  BX_DBG_SREG_DS,
48
  BX_DBG_SREG_FS,
49
  BX_DBG_SREG_GS
50
} SRegs;
51
 
52
#if BX_SUPPORT_X86_64
53
# define BX_DBG_GEN_REGISTERS 16
54
#else
55
# define BX_DBG_GEN_REGISTERS 8
56
#endif
57
 
58
typedef enum {
59
  BX_DBG_REG8H_AH,
60
  BX_DBG_REG8H_CH,
61
  BX_DBG_REG8H_DH,
62
  BX_DBG_REG8H_BH,
63
} Regs8H;
64
 
65
#if BX_SUPPORT_X86_64
66
 
67
typedef enum {
68
  BX_DBG_REG8L_AL,
69
  BX_DBG_REG8L_CL,
70
  BX_DBG_REG8L_DL,
71
  BX_DBG_REG8L_BL,
72
  BX_DBG_REG8L_SPL,
73
  BX_DBG_REG8L_BPL,
74
  BX_DBG_REG8L_SIL,
75
  BX_DBG_REG8L_DIL,
76
  BX_DBG_REG8L_R8,
77
  BX_DBG_REG8L_R9,
78
  BX_DBG_REG8L_R10,
79
  BX_DBG_REG8L_R11,
80
  BX_DBG_REG8L_R12,
81
  BX_DBG_REG8L_R13,
82
  BX_DBG_REG8L_R14,
83
  BX_DBG_REG8L_R15
84
} Regs8L;
85
 
86
typedef enum {
87
  BX_DBG_REG16_AX,
88
  BX_DBG_REG16_CX,
89
  BX_DBG_REG16_DX,
90
  BX_DBG_REG16_BX,
91
  BX_DBG_REG16_SP,
92
  BX_DBG_REG16_BP,
93
  BX_DBG_REG16_SI,
94
  BX_DBG_REG16_DI,
95
  BX_DBG_REG16_R8,
96
  BX_DBG_REG16_R9,
97
  BX_DBG_REG16_R10,
98
  BX_DBG_REG16_R11,
99
  BX_DBG_REG16_R12,
100
  BX_DBG_REG16_R13,
101
  BX_DBG_REG16_R14,
102
  BX_DBG_REG16_R15
103
} Regs16;
104
 
105
typedef enum {
106
  BX_DBG_REG32_EAX,
107
  BX_DBG_REG32_ECX,
108
  BX_DBG_REG32_EDX,
109
  BX_DBG_REG32_EBX,
110
  BX_DBG_REG32_ESP,
111
  BX_DBG_REG32_EBP,
112
  BX_DBG_REG32_ESI,
113
  BX_DBG_REG32_EDI,
114
  BX_DBG_REG32_R8,
115
  BX_DBG_REG32_R9,
116
  BX_DBG_REG32_R10,
117
  BX_DBG_REG32_R11,
118
  BX_DBG_REG32_R12,
119
  BX_DBG_REG32_R13,
120
  BX_DBG_REG32_R14,
121
  BX_DBG_REG32_R15
122
} Regs32;
123
 
124
typedef enum {
125
  BX_DBG_REG64_RAX,
126
  BX_DBG_REG64_RCX,
127
  BX_DBG_REG64_RDX,
128
  BX_DBG_REG64_RBX,
129
  BX_DBG_REG64_RSP,
130
  BX_DBG_REG64_RBP,
131
  BX_DBG_REG64_RSI,
132
  BX_DBG_REG64_RDI,
133
  BX_DBG_REG64_R8,
134
  BX_DBG_REG64_R9,
135
  BX_DBG_REG64_R10,
136
  BX_DBG_REG64_R11,
137
  BX_DBG_REG64_R12,
138
  BX_DBG_REG64_R13,
139
  BX_DBG_REG64_R14,
140
  BX_DBG_REG64_R15
141
} Regs64;
142
 
143
#else
144
 
145
typedef enum {
146
  BX_DBG_REG8L_AL,
147
  BX_DBG_REG8L_CL,
148
  BX_DBG_REG8L_DL,
149
  BX_DBG_REG8L_BL
150
} Regs8L;
151
 
152
typedef enum {
153
  BX_DBG_REG16_AX,
154
  BX_DBG_REG16_CX,
155
  BX_DBG_REG16_DX,
156
  BX_DBG_REG16_BX,
157
  BX_DBG_REG16_SP,
158
  BX_DBG_REG16_BP,
159
  BX_DBG_REG16_SI,
160
  BX_DBG_REG16_DI
161
} Regs16;
162
 
163
typedef enum {
164
  BX_DBG_REG32_EAX,
165
  BX_DBG_REG32_ECX,
166
  BX_DBG_REG32_EDX,
167
  BX_DBG_REG32_EBX,
168
  BX_DBG_REG32_ESP,
169
  BX_DBG_REG32_EBP,
170
  BX_DBG_REG32_ESI,
171
  BX_DBG_REG32_EDI
172
} Regs32;
173
 
174
#endif
175
 
176
typedef enum
177
{
178
  bkRegular,
179
  bkAtIP,
180
  bkStepOver
181
} BreakpointKind;
182
 
183
typedef enum _show_flags {
184
  Flag_call    = 0x1,
185
  Flag_ret     = 0x2,
186
  Flag_softint = 0x4,
187
  Flag_iret    = 0x8,
188
  Flag_intsig  = 0x10,
189
  Flag_mode    = 0x20,
190
} show_flags_t;
191
 
192
// Flex defs
193
extern int bxlex(void);
194
extern char *bxtext;  // Using the pointer option rather than array
195
extern int bxwrap(void);
196
void bx_add_lex_input(char *buf);
197
 
198
// Yacc defs
199
extern int bxparse(void);
200
extern void bxerror(char *s);
201
 
202
// register function for 'info device' command
203
bx_bool bx_dbg_register_debug_info(const char *devname, void *dev);
204
 
205
#define EMPTY_ARG (-1)
206
 
207
bx_bool bx_dbg_read_linear(unsigned which_cpu, bx_address laddr, unsigned len, Bit8u *buf);
208
Bit16u bx_dbg_get_selector_value(unsigned int seg_no);
209
Bit16u bx_dbg_get_ip (void);
210
Bit32u bx_dbg_get_eip(void);
211
bx_address bx_dbg_get_instruction_pointer(void);
212
Bit8u bx_dbg_get_reg8l_value(unsigned reg);
213
Bit8u bx_dbg_get_reg8h_value(unsigned reg);
214
Bit16u bx_dbg_get_reg16_value(unsigned reg);
215
Bit32u bx_dbg_get_reg32_value(unsigned reg);
216
Bit64u bx_dbg_get_reg64_value(unsigned reg);
217
void bx_dbg_set_reg8l_value(unsigned reg, Bit8u value);
218
void bx_dbg_set_reg8h_value(unsigned reg, Bit8u value);
219
void bx_dbg_set_reg16_value(unsigned reg, Bit16u value);
220
void bx_dbg_set_reg32_value(unsigned reg, Bit32u value);
221
void bx_dbg_set_reg64_value(unsigned reg, Bit64u value);
222
void bx_dbg_set_rip_value(bx_address value);
223
void bx_dbg_load_segreg(unsigned reg, unsigned value);
224
bx_address bx_dbg_get_laddr(Bit16u sel, bx_address ofs);
225
void bx_dbg_step_over_command(void);
226
void bx_dbg_trace_command(bx_bool enable);
227
void bx_dbg_trace_reg_command(bx_bool enable);
228
void bx_dbg_trace_mem_command(bx_bool enable);
229
void bx_dbg_ptime_command(void);
230
void bx_dbg_timebp_command(bx_bool absolute, Bit64u time);
231
#define MAX_CONCURRENT_BPS 5
232
extern int timebp_timer;
233
extern Bit64u timebp_queue[MAX_CONCURRENT_BPS];
234
extern int timebp_queue_size;
235
void bx_dbg_modebp_command(void);
236
void bx_dbg_vmexitbp_command(void);
237
void bx_dbg_where_command(void);
238
void bx_dbg_print_string_command(bx_address addr);
239
void bx_dbg_xlate_address(bx_lin_address laddr);
240
void bx_dbg_tlb_lookup(bx_lin_address laddr);
241
void bx_dbg_show_command(const char*);
242
void bx_dbg_print_stack_command(unsigned nwords);
243
void bx_dbg_print_watchpoints(void);
244
void bx_dbg_watchpoint_continue(bx_bool watch_continue);
245
void bx_dbg_watch(int type, bx_phy_address address, Bit32u len);
246
void bx_dbg_unwatch_all(void);
247
void bx_dbg_unwatch(bx_phy_address handle);
248
void bx_dbg_continue_command(void);
249
void bx_dbg_stepN_command(int cpu, Bit32u count);
250
void bx_dbg_set_auto_disassemble(bx_bool enable);
251
void bx_dbg_disassemble_switch_mode(void);
252
void bx_dbg_disassemble_hex_mode_switch(int mode);
253
void bx_dbg_set_disassemble_size(unsigned size);
254
void bx_dbg_del_breakpoint_command(unsigned handle);
255
void bx_dbg_en_dis_breakpoint_command(unsigned handle, bx_bool enable);
256
bx_bool bx_dbg_en_dis_pbreak(unsigned handle, bx_bool enable);
257
bx_bool bx_dbg_en_dis_lbreak(unsigned handle, bx_bool enable);
258
bx_bool bx_dbg_en_dis_vbreak(unsigned handle, bx_bool enable);
259
bx_bool bx_dbg_del_pbreak(unsigned handle);
260
bx_bool bx_dbg_del_lbreak(unsigned handle);
261
bx_bool bx_dbg_del_vbreak(unsigned handle);
262
int bx_dbg_vbreakpoint_command(BreakpointKind bk, Bit32u cs, bx_address eip);
263
int bx_dbg_lbreakpoint_command(BreakpointKind bk, bx_address laddress);
264
int bx_dbg_pbreakpoint_command(BreakpointKind bk, bx_phy_address paddress);
265
void bx_dbg_info_bpoints_command(void);
266
void bx_dbg_quit_command(void);
267
#define BX_INFO_GENERAL_PURPOSE_REGS 0x01 /* bitmasks - choices for bx_dbg_info_registers_command */
268
#define BX_INFO_FPU_REGS 0x02
269
#define BX_INFO_MMX_REGS 0x04
270
#define BX_INFO_SSE_REGS 0x08
271
#define BX_INFO_AVX_REGS 0x10
272
void bx_dbg_info_registers_command(int);
273
void bx_dbg_info_ivt_command(unsigned from, unsigned to);
274
void bx_dbg_info_idt_command(unsigned from, unsigned to);
275
void bx_dbg_info_gdt_command(unsigned from, unsigned to);
276
void bx_dbg_info_ldt_command(unsigned from, unsigned to);
277
void bx_dbg_info_tss_command(void);
278
void bx_dbg_info_debug_regs_command(void);
279
void bx_dbg_info_control_regs_command(void);
280
void bx_dbg_info_segment_regs_command(void);
281
void bx_dbg_info_flags(void);
282
void bx_dbg_info_linux_command(void);
283
void bx_dbg_examine_command(const char *command, const char *format, bx_bool format_passed,
284
                    bx_address addr, bx_bool addr_passed);
285
Bit32u bx_dbg_lin_indirect(bx_address addr);
286
Bit32u bx_dbg_phy_indirect(bx_phy_address addr);
287
void bx_dbg_writemem_command(const char *filename, bx_address laddr, unsigned len);
288
void bx_dbg_setpmem_command(bx_phy_address addr, unsigned len, Bit32u val);
289
void bx_dbg_query_command(const char *);
290
void bx_dbg_take_command(const char *, unsigned n);
291
void bx_dbg_disassemble_current(const char *);
292
void bx_dbg_disassemble_command(const char *, Bit64u from, Bit64u to);
293
void bx_dbg_instrument_command(const char *);
294
void bx_dbg_doit_command(unsigned);
295
void bx_dbg_crc_command(bx_phy_address addr1, bx_phy_address addr2);
296
void bx_dbg_linux_syscall(unsigned which_cpu);
297
void bx_dbg_info_device(const char *, const char *);
298
void bx_dbg_print_help(void);
299
void bx_dbg_calc_command(Bit64u value);
300
void bx_dbg_dump_table(void);
301
 
302
// callbacks from CPU
303
void bx_dbg_exception(unsigned cpu, Bit8u vector, Bit16u error_code);
304
void bx_dbg_interrupt(unsigned cpu, Bit8u vector, Bit16u error_code);
305
void bx_dbg_halt(unsigned cpu);
306
 
307
// memory trace callbacks from CPU, len=1,2,4 or 8
308
void bx_dbg_lin_memory_access(unsigned cpu, bx_address lin, bx_phy_address phy, unsigned len, unsigned pl, unsigned rw, Bit8u *data);
309
void bx_dbg_phy_memory_access(unsigned cpu, bx_phy_address phy, unsigned len, unsigned rw, unsigned attr, Bit8u *data);
310
 
311
// check memory access for watchpoints
312
void bx_dbg_check_memory_watchpoints(unsigned cpu, bx_phy_address phy, unsigned len, unsigned rw);
313
 
314
// commands that work with Bochs param tree
315
void bx_dbg_restore_command(const char *param_name, const char *path);
316
void bx_dbg_show_param_command(const char *param);
317
 
318
int bx_dbg_show_symbolic(void);
319
void bx_dbg_set_symbol_command(const char *symbol, bx_address val);
320
const char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base);
321
const char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs);
322
int bx_dbg_symbol_command(const char* filename, bx_bool global, Bit32u offset);
323
void bx_dbg_info_symbols_command(const char *Symbol);
324
int bx_dbg_lbreakpoint_symbol_command(const char *Symbol);
325
Bit32u bx_dbg_get_symbol_value(const char *Symbol);
326
const char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base);
327
 
328
#ifdef __cplusplus
329
}
330
#endif
331
 
332
// the rest for C++
333
#ifdef __cplusplus
334
 
335
typedef enum {
336
  STOP_NO_REASON = 0,
337
  STOP_TIME_BREAK_POINT,
338
  STOP_READ_WATCH_POINT,
339
  STOP_WRITE_WATCH_POINT,
340
  STOP_MAGIC_BREAK_POINT,
341
  STOP_MODE_BREAK_POINT,
342
  STOP_VMEXIT_BREAK_POINT,
343
  STOP_CPU_HALTED,
344
} stop_reason_t;
345
 
346
typedef enum {
347
  BREAK_POINT_MAGIC, BREAK_POINT_READ, BREAK_POINT_WRITE, BREAK_POINT_TIME
348
} break_point_t;
349
 
350
#define BX_DBG_PENDING_DMA 1
351
#define BX_DBG_PENDING_IRQ 2
352
 
353
void bx_debug_break(void);
354
 
355
void bx_dbg_exit(int code);
356
#if BX_DBG_EXTENSIONS
357
    int bx_dbg_extensions(char *command);
358
#else
359
#define bx_dbg_extensions(command) 0
360
#endif
361
 
362
//
363
// code for guards...
364
//
365
 
366
#define BX_DBG_GUARD_IADDR_VIR     0x0001
367
#define BX_DBG_GUARD_IADDR_LIN     0x0002
368
#define BX_DBG_GUARD_IADDR_PHY     0x0004
369
#define BX_DBG_GUARD_IADDR_ALL (BX_DBG_GUARD_IADDR_VIR | \
370
                                BX_DBG_GUARD_IADDR_LIN | \
371
                                BX_DBG_GUARD_IADDR_PHY)
372
 
373
#define BX_DBG_GUARD_ICOUNT        0x0010
374
 
375
typedef struct {
376
  unsigned guard_for;
377
 
378
  // instruction address breakpoints
379
  struct {
380
#if (BX_DBG_MAX_VIR_BPOINTS > 0)
381
    unsigned num_virtual;
382
    struct {
383
      Bit32u cs;  // only use 16 bits
384
      bx_address eip;
385
      unsigned bpoint_id;
386
      bx_bool enabled;
387
    } vir[BX_DBG_MAX_VIR_BPOINTS];
388
#endif
389
 
390
#if (BX_DBG_MAX_LIN_BPOINTS > 0)
391
    unsigned num_linear;
392
    struct {
393
      bx_address addr;
394
      unsigned bpoint_id;
395
      bx_bool enabled;
396
    } lin[BX_DBG_MAX_LIN_BPOINTS];
397
#endif
398
 
399
#if (BX_DBG_MAX_PHY_BPOINTS > 0)
400
    unsigned num_physical;
401
    struct {
402
      bx_phy_address addr;
403
      unsigned bpoint_id;
404
      bx_bool enabled;
405
    } phy[BX_DBG_MAX_PHY_BPOINTS];
406
#endif
407
  } iaddr;
408
 
409
  // user typed Ctrl-C, requesting simulator stop at next convinient spot
410
  volatile bx_bool interrupt_requested;
411
 
412
  // booleans to control whether simulator should report events
413
  // to debug controller
414
  struct {
415
    bx_bool irq;
416
    bx_bool a20;
417
    bx_bool io;
418
    bx_bool dma;
419
  } report;
420
 
421
  struct {
422
    bx_bool irq;  // should process IRQs asynchronously
423
    bx_bool dma;  // should process DMAs asynchronously
424
  } async;
425
 
426
#define BX_DBG_ASYNC_PENDING_A20   0x01
427
#define BX_DBG_ASYNC_PENDING_RESET 0x02
428
#define BX_DBG_ASYNC_PENDING_NMI   0x04
429
 
430
  // Asynchronous changes which are pending.  These are Q'd by
431
  // the debugger, as the master simulator is notified of a pending
432
  // async change.  At the simulator's next point, where it checks for
433
  // such events, it notifies the debugger with acknowlegement.  This
434
  // field contains a logically or'd list of all events which should
435
  // be checked, and ack'd.
436
  struct {
437
    unsigned which; // logical OR of above constants
438
    bx_bool a20;
439
    bx_bool reset;
440
    bx_bool nmi;
441
  } async_changes_pending;
442
} bx_guard_t;
443
 
444
// working information for each simulator to update when a guard
445
// is reached (found)
446
typedef struct bx_guard_found_t {
447
  unsigned guard_found;
448
  Bit64u icount_max; // stop after completing this many instructions
449
  unsigned iaddr_index;
450
  Bit32u cs; // cs:eip and linear addr of instruction at guard point
451
  bx_address eip;
452
  bx_address laddr;
453
  // 00 - 16 bit, 01 - 32 bit, 10 - 64-bit, 11 - illegal
454
  unsigned code_32_64; // CS seg size at guard point
455
} bx_guard_found_t;
456
 
457
struct bx_watchpoint {
458
  bx_phy_address addr;
459
  Bit32u len;
460
};
461
 
462
extern unsigned num_write_watchpoints;
463
extern unsigned num_read_watchpoints;
464
extern bx_watchpoint write_watchpoint[BX_DBG_MAX_WATCHPONTS];
465
extern bx_watchpoint read_watchpoint[BX_DBG_MAX_WATCHPONTS];
466
extern bx_guard_t bx_guard;
467
 
468
#define IS_CODE_32(code_32_64) ((code_32_64 & 1) != 0)
469
#define IS_CODE_64(code_32_64) ((code_32_64 & 2) != 0)
470
 
471
void bx_dbg_init_infile(void);
472
int  bx_dbg_set_rcfile(const char *rcfile);
473
int  bx_dbg_main(void);
474
void bx_dbg_user_input_loop(void);
475
void bx_dbg_interpret_line(char *cmd);
476
 
477
typedef struct {
478
  Bit16u sel;
479
  Bit32u des_l, des_h, valid;
480
#if BX_SUPPORT_X86_64
481
  Bit32u dword3;
482
#endif
483
} bx_dbg_sreg_t;
484
 
485
typedef struct {
486
  bx_address base;
487
  Bit16u limit;
488
} bx_dbg_global_sreg_t;
489
 
490
void bx_dbg_dma_report(bx_phy_address addr, unsigned len, unsigned what, Bit32u val);
491
void bx_dbg_iac_report(unsigned vector, unsigned irq);
492
void bx_dbg_a20_report(unsigned val);
493
void bx_dbg_io_report(Bit32u port, unsigned size, unsigned op, Bit32u val);
494
void bx_dbg_disassemble_current(int which_cpu, int print_time);
495
 
496
#endif // #ifdef __cplusplus
497
 
498
#endif // #if BX_DEBUGGER
499
 
500
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.