2 * Debugger register handling
4 * Copyright 1995 Alexandre Julliard
11 /***********************************************************************
16 char *DEBUG_Flags( DWORD flag
, char *buf
)
21 strcpy( buf
, " - 00 - - - " );
22 pt
= buf
+ strlen( buf
);
23 if ( buf
>= pt
-- ) return( buf
);
24 if ( flag
& 0x00000001 ) *pt
= 'C'; /* Carry Falg */
25 if ( buf
>= pt
-- ) return( buf
);
26 if ( flag
& 0x00000002 ) *pt
= '1';
27 if ( buf
>= pt
-- ) return( buf
);
28 if ( flag
& 0x00000004 ) *pt
= 'P'; /* Parity Flag */
29 if ( buf
>= pt
-- ) return( buf
);
30 if ( flag
& 0x00000008 ) *pt
= '-';
31 if ( buf
>= pt
-- ) return( buf
);
32 if ( flag
& 0x00000010 ) *pt
= 'A'; /* Auxiliary Carry Flag */
33 if ( buf
>= pt
-- ) return( buf
);
34 if ( flag
& 0x00000020 ) *pt
= '-';
35 if ( buf
>= pt
-- ) return( buf
);
36 if ( flag
& 0x00000040 ) *pt
= 'Z'; /* Zero Flag */
37 if ( buf
>= pt
-- ) return( buf
);
38 if ( flag
& 0x00000080 ) *pt
= 'S'; /* Sign Flag */
39 if ( buf
>= pt
-- ) return( buf
);
40 if ( flag
& 0x00000100 ) *pt
= 'T'; /* Trap/Trace Flag */
41 if ( buf
>= pt
-- ) return( buf
);
42 if ( flag
& 0x00000200 ) *pt
= 'I'; /* Interupt Enable Flag */
43 if ( buf
>= pt
-- ) return( buf
);
44 if ( flag
& 0x00000400 ) *pt
= 'D'; /* Direction Indicator */
45 if ( buf
>= pt
-- ) return( buf
);
46 if ( flag
& 0x00000800 ) *pt
= 'O'; /* Overflow Flag */
47 if ( buf
>= pt
-- ) return( buf
);
48 if ( flag
& 0x00001000 ) *pt
= '1'; /* I/O Privilage Level */
49 if ( buf
>= pt
-- ) return( buf
);
50 if ( flag
& 0x00002000 ) *pt
= '1'; /* I/O Privilage Level */
51 if ( buf
>= pt
-- ) return( buf
);
52 if ( flag
& 0x00004000 ) *pt
= 'N'; /* Nested Task Flag */
53 if ( buf
>= pt
-- ) return( buf
);
54 if ( flag
& 0x00008000 ) *pt
= '-';
55 if ( buf
>= pt
-- ) return( buf
);
56 if ( flag
& 0x00010000 ) *pt
= 'R'; /* Resume Flag */
57 if ( buf
>= pt
-- ) return( buf
);
58 if ( flag
& 0x00020000 ) *pt
= 'V'; /* Vritual Mode Flag */
59 if ( buf
>= pt
-- ) return( buf
);
60 if ( flag
& 0x00040000 ) *pt
= 'a'; /* Alignment Check Flag */
61 if ( buf
>= pt
-- ) return( buf
);
64 strcpy(buf
, "unknown CPU");
70 /***********************************************************************
73 * Display registers information.
75 void DEBUG_InfoRegisters(void)
77 DEBUG_Printf(DBG_CHN_MESG
,"Register dump:\n");
80 /* First get the segment registers out of the way */
81 DEBUG_Printf( DBG_CHN_MESG
," CS:%04x SS:%04x DS:%04x ES:%04x FS:%04x GS:%04x",
82 (WORD
)DEBUG_context
.SegCs
, (WORD
)DEBUG_context
.SegSs
,
83 (WORD
)DEBUG_context
.SegDs
, (WORD
)DEBUG_context
.SegEs
,
84 (WORD
)DEBUG_context
.SegFs
, (WORD
)DEBUG_context
.SegGs
);
85 if (DEBUG_CurrThread
->dbg_mode
!= MODE_32
)
89 DEBUG_Printf( DBG_CHN_MESG
,"\n IP:%04x SP:%04x BP:%04x FLAGS:%04x(%s)\n",
90 LOWORD(DEBUG_context
.Eip
), LOWORD(DEBUG_context
.Esp
),
91 LOWORD(DEBUG_context
.Ebp
), LOWORD(DEBUG_context
.EFlags
),
92 DEBUG_Flags(LOWORD(DEBUG_context
.EFlags
), flag
));
93 DEBUG_Printf( DBG_CHN_MESG
," AX:%04x BX:%04x CX:%04x DX:%04x SI:%04x DI:%04x\n",
94 LOWORD(DEBUG_context
.Eax
), LOWORD(DEBUG_context
.Ebx
),
95 LOWORD(DEBUG_context
.Ecx
), LOWORD(DEBUG_context
.Edx
),
96 LOWORD(DEBUG_context
.Esi
), LOWORD(DEBUG_context
.Edi
) );
98 else /* 32-bit mode */
102 DEBUG_Printf( DBG_CHN_MESG
, "\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx(%s)\n",
103 DEBUG_context
.Eip
, DEBUG_context
.Esp
,
104 DEBUG_context
.Ebp
, DEBUG_context
.EFlags
,
105 DEBUG_Flags(DEBUG_context
.EFlags
, flag
));
106 DEBUG_Printf( DBG_CHN_MESG
, " EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n",
107 DEBUG_context
.Eax
, DEBUG_context
.Ebx
,
108 DEBUG_context
.Ecx
, DEBUG_context
.Edx
);
109 DEBUG_Printf( DBG_CHN_MESG
, " ESI:%08lx EDI:%08lx\n",
110 DEBUG_context
.Esi
, DEBUG_context
.Edi
);
116 /***********************************************************************
117 * DEBUG_ValidateRegisters
119 * Make sure all registers have a correct value for returning from
120 * the signal handler.
122 BOOL
DEBUG_ValidateRegisters(void)
128 if (DEBUG_context
.EFlags
& V86_FLAG
) return TRUE
;
131 /* Check that a selector is a valid ring-3 LDT selector, or a NULL selector */
132 #define CHECK_SEG(seg,name) \
133 if (((seg) & ~3) && ((((seg) & 7) != 7) || !DEBUG_IsSelector(seg))) { \
134 DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for %s register: %04x\n", \
135 (name), (WORD)(seg) ); \
141 if (DEBUG_context
.SegCs
!= cs
) CHECK_SEG(DEBUG_context
.SegCs
, "CS");
142 if (DEBUG_context
.SegSs
!= ds
) CHECK_SEG(DEBUG_context
.SegSs
, "SS");
143 if (DEBUG_context
.SegDs
!= ds
) CHECK_SEG(DEBUG_context
.SegDs
, "DS");
144 if (DEBUG_context
.SegEs
!= ds
) CHECK_SEG(DEBUG_context
.SegEs
, "ES");
145 if (DEBUG_context
.SegFs
!= ds
) CHECK_SEG(DEBUG_context
.SegFs
, "FS");
146 if (DEBUG_context
.SegGs
!= ds
) CHECK_SEG(DEBUG_context
.SegGs
, "GS");
149 /* Check that CS and SS are not NULL */
151 if (!(DEBUG_context
.SegCs
& ~3))
153 DEBUG_Printf( DBG_CHN_MESG
, "*** Invalid value for CS register: %04x\n",
154 (WORD
)DEBUG_context
.SegCs
);
157 if (!(DEBUG_context
.SegSs
& ~3))
159 DEBUG_Printf( DBG_CHN_MESG
, "*** Invalid value for SS register: %04x\n",
160 (WORD
)DEBUG_context
.SegSs
);
169 /* check if PC is correct */
170 DEBUG_GetCurrentAddress(&addr
);
171 return DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear(&addr
), &ch
, 1);