1 // include file for the Win32 Enhanced GUI debugger frontend
2 // User Customizable initial settings:
5 TRUE
, // in 64bit mode, show 32bit versions of registers also (EAX, ...)
6 FALSE
, // show segment registers (CS, ...)
7 FALSE
, // show GDTR, IDTR, LDTR, Task Reg
8 FALSE
, // show control register (CR0, ...)
9 FALSE
, // show FPU (STi) / MMX registers
10 FALSE
, // show XMM registers
11 FALSE
, // show the Debug Registers (DR0, ...)
12 FALSE
// Test Registers not yet supported in bochs (2.3.7)
15 bx_bool ShowIOWindows
= TRUE
; // Display the top-row Step/Continue pushbuttons
16 bx_bool ShowButtons
= TRUE
; // Display the top-row Step/Continue pushbuttons
17 bx_bool SeeRegColors
= TRUE
; // Display registers with background color "groups"
18 bx_bool ignoreNxtT
= TRUE
; // Do not show "Next at t=" output lines
19 bx_bool ignSSDisasm
= TRUE
; // Do not show extra disassembly line at each break
20 int UprCase
= 1; // 1 = convert all Asm, Register names, Register values to uppercase
21 int DumpInAsciiMode
= 3; // bit 1 = show ASCII in dumps, bit 2 = show hex, value=0 is illegal
23 bx_bool isLittleEndian
= TRUE
;
24 int DefaultAsmLines
= 250; // default # of asm lines disassembled and "cached"
25 int bottommargin
= 6; // ASM autoscroller tries to leave this many lines below
26 int topmargin
= 3; // autoscroller tries to leave this many lines above
27 // Note: topmargin must be less than bottommargin
29 // How to use DockOrder: the Register list is window 1, ASM is window 2, MemDump is window 3
30 // Create the hex value with the digits in the order you want the windows to be.
31 // 0x312 would have MemDump on the left, Register in the middle, ASM on the right
32 short DockOrder
= 0x123; // set the default List "docking" (Reg, ASM, Dump)
34 COLORREF ColorList
[16] = { // background "register type" colors indexed by RegColor value
35 RGB(255,255,255), // white
36 RGB(200,255,255), // blue (aqua)
37 RGB(230,230,230), // gray
38 RGB(248,255,200), // yellow
39 RGB(216,216,255), // purple
40 RGB(200,255,200), // green
41 RGB(255,230,200), // orange
42 RGB(255,255,255), // user definable
53 #define STATUS_WIN_OVERLAP 4 // # of "extra" pixels at the top of a Status window
54 #define STACK_ENTRIES 50 // # of words/dwords/qwords to display in stack window
55 // Note: STACK_ENTRIES must be <= 512
57 // END of User Customizable settings
60 #include "iodev/iodev.h"
61 #include "wenhdbg_res.h" // MenuIDs
64 #ifndef LVS_EX_DOUBLEBUFFER
66 // these two defines may not exist in some compilers
67 #define LVS_EX_DOUBLEBUFFER 0
68 #define LVIF_GROUPID 0
71 #define MAX_ASM 2048 // max entries in ASM window
73 // The wordsize popup is the 13th entry in the Opt menu -- COUNTING SEPARATORS
74 // Index = (entry number - 1) -- if the Opt menu is modified, then update this value
75 // -- or else the checkmarks won't work
76 #define WS_POPUP_IDX 12
79 // Handles to Windows and global stuff
80 HWND hY
; // complete parent window
81 HWND hL
[3]; // 0=registers, 1=Asm, 2=MemDump
82 HWND hE_I
; // command input window
83 HWND hS_S
; // "status" window at bottom
84 HWND hE_O
; // debugger text output
85 HWND hT
; // param_tree window
86 HWND hBTN
[5]; // button row
87 HWND hCPUt
[BX_MAX_SMP_THREADS_SUPPORTED
]; // "tabs" for the individual CPUs
88 HFONT CustomFont
= NULL
;
89 HMENU hOptMenu
; // "Options" popup menu (needed to set check marks)
90 HMENU hViewMenu
; // "View" popup menu (needed to gray entries)
91 HMENU hCmdMenu
; // "Command" popup menu (needed to gray entries)
92 // one "defualtProc" for each edit window (Input and Output)
94 WNDPROC wBtn
; // all the buttons have the same Proc
96 WNDPROC wListView
; // all the lists use the same Proc
98 //HANDLE hTCevent[BX_MAX_SMP_THREADS_SUPPORTED]; // Start/Sleep Control for cpu_loop threads
100 // get a "class" to access the disassebler
101 // Note; any instance has access to all the member functions -- that is enough!
102 // -- i.e. No further initialization necessary.
103 static disassembler bx_disassemble
;
104 // for refreshing the bochs VGA window:
105 BOCHSAPI
extern bx_devices_c bx_devices
;
107 // Note: all these BSS global variables are initialized to 0 automatically
108 Bit64u SelectedDataAddress
= 0;
109 Bit64u CurrentAsmLA
= 0; // = EIP/RIP -- for highlighting in ASM window
110 Bit64u BottomAsmLA
; // beginning and end addrs on ASM window
113 Bit32u PrevStepNSize
= 50; // cpu_loop control variables
114 //Bit32u RequestedLoops; // number of cpu_loops the user is asking for
115 //bx_bool DoBreak; // stop a local subthreaded cpu_loop
116 Bit64u PrevPtime
= 9; // any number other than 0
117 Bit64u NewPtime
; // used to test whether sim has "updated"
118 unsigned int TotCPUs
; // # of CPUs in a multi-CPU simulation
119 unsigned int CurrentCPU
; // cpu that is being displayed
122 // window resizing/docking stuff
126 LVHITTESTINFO lvht
; // calculate and remember which list item was clicked
127 int OneCharWide
; // average width of a char in current font
128 int Sizing
= 0; // current "resizing/docking mode"
129 int Resize_HiX
; // horizontal limits of the current resize operation
131 unsigned short BarScrx
[2]; // position of central listview's left and right borders in SCREEN coordinates
132 unsigned short BarClix
[2]; // in client coordinates
133 unsigned int ListWidthPix
[3] = {5,7,8}; // set initial proportions of Reg, Asm, Dump windows
134 unsigned int LstTop
= 0;
136 int SizeList
; // pre-docking list #
137 bx_bool DumpHasFocus
= FALSE
;
138 Bit32s xClick
= -1; // halfway through a mouseclick flag + location
139 Bit32s yClick
; // values are in Listview coordinates
140 Bit32u CurTimeStamp
; // last mousedown time
141 short nDock
[36] = { // lookup table for alternate DockOrders
142 0x231, 0x312, 0x231, 0x213, 0x132, 0x132,
143 0x213, 0x321, 0x123, 0x123, 0x321, 0x312,
144 0x213, 0x213, 0x123, 0x312, 0x321, 0x312,
145 0x132, 0x123, 0x132, 0x321, 0x231, 0x231,
146 0x312, 0x312, 0x231, 0x213, 0x132, 0x213,
147 0x132, 0x123, 0x321, 0x321, 0x123, 0x231
150 // base window "styles" for the 3 listviews.
152 LVS_REPORT
| WS_CHILD
,
153 LVS_SHOWSELALWAYS
| LVS_REPORT
| WS_CHILD
,
154 LVS_SHOWSELALWAYS
| LVS_REPORT
| WS_CHILD
| WS_VISIBLE
157 bx_bool AtBreak
= FALSE
; // Status indicators
158 bx_bool PrevAtBreak
= FALSE
;
159 bx_bool CpuModeChange
= TRUE
;
160 bx_bool StatusChange
= TRUE
;
162 bx_bool In64Mode
= FALSE
; // CPU modes
163 bx_bool In32Mode
= FALSE
;
164 unsigned CpuMode
= 0;
165 Bit32u InPaging
= 0; // Storage for the top bit of CR0, unmodified
167 bx_bool doOneTimeInit
= TRUE
; // Internal flags
168 bx_bool ResizeColmns
; // address/value column autosize flag
169 bx_bool dbgOn
= FALSE
; // the bochs internal debugger needs some time to get started
170 bx_bool FWflag
= FALSE
; // friendly warning has been shown to user once already
171 int StackSized
; // autosize flag for stack window
173 char *PrevStack
; // buffer for testing changes in stack values
174 Bit64u PStackLA
= 0; // to calculate alignment between prev and current stack
175 bx_bool StackEntChg
[STACK_ENTRIES
]; // flag for "change detected" on each stack line
176 bx_bool StkInvOnce
= FALSE
; // sometimes need to specially invalidate the stack window
179 #define VIEW_MEMDUMP 0
182 #define VIEW_PAGING 3
186 bx_bool DumpInitted
= FALSE
; // has the MemDump window ever been filled with data?
188 int PrevDAD
; // saves "previous DumpAlign value" (forces column autosize)
190 Bit64u DumpStart
= 0; // current emulated address (lin or phys) of DataDump
191 bx_bool doDumpRefresh
;
192 int DViewMode
= VIEW_MEMDUMP
;
193 bx_bool DumpMode
= 1; // 0 physical, 1 linear
194 char* DC0txt
[2] = {"P.Address","L.Address"}; // DumpMode definitions in text
196 // make some global 512b temp char buffers -- they are needed to test against overflows anyway
197 char *tmpcb
, *tmpcd
; // space is allocated in bigbuf
198 char *tmpce
, *tmpcf
; // exclusively for use in subthreads
199 char *AsciiHex
; // Unsigned char to printable hex xlat table
201 #define outbufSIZE 30720
202 char bigbuf
[outbufSIZE
]; // 30K preallocated storage for all char buffers (see DoAllInit)
203 char *DbgAppendPtr
= bigbuf
;
204 char *OutWindow
; // buffer for the Output window
205 #define OutWinSIZE 10240
206 int OutWinCnt
= OutWinSIZE
; // available size of OutWindow buffer
207 int PO_Tdelay
= 0; // delay before displaying partial output lines
209 int AsmLineCount
= 1; // # of disassembled asm lines loaded
211 int ListLineRatio
; // number of vertical pixels in a ListView Item
212 int ListVerticalPix
; // number of vertical pixels in each List
213 Bit64u AsmLA
[MAX_ASM
]; // linear address of each disassembled ASM line
216 int CommandHistoryIdx
= 0;
217 char *CmdHistory
[64]; // 64 command History storage (fixed 80b each)
218 int CmdHInsert
= 0; // index of next history entry to store
220 // register storage -- names and values
238 #define EFL_Rnum 17 // it makes the most sense if EFLAGS is between RXX and EXX
239 #define EAX_Rnum 18 // because it "belongs with" both sets of GP registers
261 #define EFER_Rnum 40 // currently used to mark the last entry in rV[]
292 // #define TR0_Rnum 71 -- put Test Registers in here when they are supported
293 #define TOT_REG_NUM 72
294 // extra "register numbers" for registers that have more than one part
321 #define EXTRA_REGS 28
323 char * EflBName
[16] = {
324 "cf", "pf", "af", "zf", "sf", "tf", "if", "df", "of", "nt", "rf", "vm", "ac", "vif", "vip", "id"
326 int EflBNameLen
[16] = {
327 2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,2
329 int EflBitVal
[16] = {
330 1, 4, 0x10, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x4000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000
333 // only pay special attention to registers up to EFER
334 char* RegLCName
[EFER_Rnum
+ 1] = {
335 "rax","rbx","rcx","rdx","rsi","rdi","rbp","rsp","rip",
336 "r8","r9","r10","r11","r12","r13","r14","r15",
337 "eflags","eax","ebx","ecx","edx","esi","edi","ebp","esp","eip",
338 "cs","ds","es","ss","fs","gs",
339 "gdtr","idtr","ldtr","tr","cr0","cr3","cr4","efer"
341 char* RDispName
[EFER_Rnum
+ 1];
342 bx_param_num_c
*RegObject
[BX_MAX_SMP_THREADS_SUPPORTED
][TOT_REG_NUM
+ EXTRA_REGS
];
343 Bit64u rV
[EFER_Rnum
+ 1]; // current values of registers
344 Bit64u PV
[EFER_Rnum
+ 1]; // previous values of registers
345 Bit32s GDT_Len
; // "limits" (= bytesize-1) for GDT and IDT
347 Bit8u RegColor
[TOT_REG_NUM
]; // specifies foreground and background color of registers
348 // Text color is red if the upper bit is set. Background is set according to ColorList.
349 int RitemToRnum
[TOT_REG_NUM
]; // mapping from Reg List Item# to register number
351 // lviG is a generic ListViewItem with GroupID -- reused many times
352 LV_ITEM lviG
= {LVIF_TEXT
| LVIF_GROUPID
,0,0,0,0,(LPSTR
)0,0,0,0};
354 TVINSERTSTRUCT tvis
; // tree-view generic item
356 Bit64u ladrmin
= 0; // bochs linear addressing access variables
360 #define BTN_BASE 1024
361 #define MULTICPU_BTN_BASE 1030
363 CMD_CONT
, CMD_STEP1
, CMD_STEPN
, CMD_BREAK
, CMD_RFRSH
, CMD_BRKALL
365 char* BTxt
[6] = {"Continue [c]","Step [s]","Step N [s ###]","Break [^C]","Refresh","Break All"};
366 char* GDTt2
[8] = {"16-bit code","64-bit code","32-bit code","16-bit data","64-bit data","32-bit data","Illegal","Unused"};
367 char* GDTsT
[] = { "","Available 16bit TSS","LDT","Busy 16bit TSS","16bit Call Gate",
368 "Task Gate","16bit Interrupt Gate","16bit Trap Gate","Reserved",
369 "Available 32bit TSS","Reserved","Busy 32bit TSS","32bit Call Gate",
370 "Reserved","32bit Interrupt Gate","32bit Trap Gate"
372 // Register hex display formats -- index by UprCase
373 char* Fmt64b
[2] = { "%016I64x", "%016I64X" };
374 char* Fmt32b
[2] = { "%08x", "%08X" };
375 char* Fmt16b
[2] = { "%04x", "%04X" };
376 char* xDT64Fmt
[2] = { "%016I64x (%4x)", "%016I64X (%4X)" };
377 char* xDT32Fmt
[2] = { "%08x (%4x)", "%08X (%4X)" };
379 // do the linear breakpoint list as 2 arrays, rather than a structure -- much easier to search!
380 bx_address BrkLAddr
[BX_DBG_MAX_LIN_BPOINTS
];
381 unsigned int BrkIdx
[BX_DBG_MAX_LIN_BPOINTS
];