2 * Debugger register handling
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /***********************************************************************
30 static char *DEBUG_Flags( DWORD flag
, char *buf
)
35 strcpy( buf
, " - 00 - - - " );
36 pt
= buf
+ strlen( buf
);
37 if ( buf
>= pt
-- ) return( buf
);
38 if ( flag
& 0x00000001 ) *pt
= 'C'; /* Carry Falg */
39 if ( buf
>= pt
-- ) return( buf
);
40 if ( flag
& 0x00000002 ) *pt
= '1';
41 if ( buf
>= pt
-- ) return( buf
);
42 if ( flag
& 0x00000004 ) *pt
= 'P'; /* Parity Flag */
43 if ( buf
>= pt
-- ) return( buf
);
44 if ( flag
& 0x00000008 ) *pt
= '-';
45 if ( buf
>= pt
-- ) return( buf
);
46 if ( flag
& 0x00000010 ) *pt
= 'A'; /* Auxiliary Carry Flag */
47 if ( buf
>= pt
-- ) return( buf
);
48 if ( flag
& 0x00000020 ) *pt
= '-';
49 if ( buf
>= pt
-- ) return( buf
);
50 if ( flag
& 0x00000040 ) *pt
= 'Z'; /* Zero Flag */
51 if ( buf
>= pt
-- ) return( buf
);
52 if ( flag
& 0x00000080 ) *pt
= 'S'; /* Sign Flag */
53 if ( buf
>= pt
-- ) return( buf
);
54 if ( flag
& 0x00000100 ) *pt
= 'T'; /* Trap/Trace Flag */
55 if ( buf
>= pt
-- ) return( buf
);
56 if ( flag
& 0x00000200 ) *pt
= 'I'; /* Interupt Enable Flag */
57 if ( buf
>= pt
-- ) return( buf
);
58 if ( flag
& 0x00000400 ) *pt
= 'D'; /* Direction Indicator */
59 if ( buf
>= pt
-- ) return( buf
);
60 if ( flag
& 0x00000800 ) *pt
= 'O'; /* Overflow Flag */
61 if ( buf
>= pt
-- ) return( buf
);
62 if ( flag
& 0x00001000 ) *pt
= '1'; /* I/O Privilage Level */
63 if ( buf
>= pt
-- ) return( buf
);
64 if ( flag
& 0x00002000 ) *pt
= '1'; /* I/O Privilage Level */
65 if ( buf
>= pt
-- ) return( buf
);
66 if ( flag
& 0x00004000 ) *pt
= 'N'; /* Nested Task Flag */
67 if ( buf
>= pt
-- ) return( buf
);
68 if ( flag
& 0x00008000 ) *pt
= '-';
69 if ( buf
>= pt
-- ) return( buf
);
70 if ( flag
& 0x00010000 ) *pt
= 'R'; /* Resume Flag */
71 if ( buf
>= pt
-- ) return( buf
);
72 if ( flag
& 0x00020000 ) *pt
= 'V'; /* Vritual Mode Flag */
73 if ( buf
>= pt
-- ) return( buf
);
74 if ( flag
& 0x00040000 ) *pt
= 'a'; /* Alignment Check Flag */
75 if ( buf
>= pt
-- ) return( buf
);
78 strcpy(buf
, "unknown CPU");
84 /***********************************************************************
87 * Display registers information.
89 void DEBUG_InfoRegisters(const CONTEXT
* ctx
)
91 DEBUG_Printf(DBG_CHN_MESG
,"Register dump:\n");
94 /* First get the segment registers out of the way */
95 DEBUG_Printf( DBG_CHN_MESG
," CS:%04x SS:%04x DS:%04x ES:%04x FS:%04x GS:%04x",
96 (WORD
)ctx
->SegCs
, (WORD
)ctx
->SegSs
,
97 (WORD
)ctx
->SegDs
, (WORD
)ctx
->SegEs
,
98 (WORD
)ctx
->SegFs
, (WORD
)ctx
->SegGs
);
99 if (DEBUG_CurrThread
->dbg_mode
!= MODE_32
)
103 DEBUG_Printf( DBG_CHN_MESG
,"\n IP:%04x SP:%04x BP:%04x FLAGS:%04x(%s)\n",
104 LOWORD(ctx
->Eip
), LOWORD(ctx
->Esp
),
105 LOWORD(ctx
->Ebp
), LOWORD(ctx
->EFlags
),
106 DEBUG_Flags(LOWORD(ctx
->EFlags
), flag
));
107 DEBUG_Printf( DBG_CHN_MESG
," AX:%04x BX:%04x CX:%04x DX:%04x SI:%04x DI:%04x\n",
108 LOWORD(ctx
->Eax
), LOWORD(ctx
->Ebx
),
109 LOWORD(ctx
->Ecx
), LOWORD(ctx
->Edx
),
110 LOWORD(ctx
->Esi
), LOWORD(ctx
->Edi
) );
112 else /* 32-bit mode */
116 DEBUG_Printf( DBG_CHN_MESG
, "\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx(%s)\n",
118 ctx
->Ebp
, ctx
->EFlags
,
119 DEBUG_Flags(ctx
->EFlags
, flag
));
120 DEBUG_Printf( DBG_CHN_MESG
, " EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n",
122 ctx
->Ecx
, ctx
->Edx
);
123 DEBUG_Printf( DBG_CHN_MESG
, " ESI:%08lx EDI:%08lx\n",
124 ctx
->Esi
, ctx
->Edi
);
130 /***********************************************************************
131 * DEBUG_ValidateRegisters
133 * Make sure all registers have a correct value for returning from
134 * the signal handler.
136 BOOL
DEBUG_ValidateRegisters(void)
142 if (DEBUG_context
.EFlags
& V86_FLAG
) return TRUE
;
145 /* Check that a selector is a valid ring-3 LDT selector, or a NULL selector */
146 #define CHECK_SEG(seg,name) \
147 if (((seg) & ~3) && ((((seg) & 7) != 7) || !DEBUG_IsSelector(seg))) { \
148 DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for %s register: %04x\n", \
149 (name), (WORD)(seg) ); \
155 if (DEBUG_context
.SegCs
!= cs
) CHECK_SEG(DEBUG_context
.SegCs
, "CS");
156 if (DEBUG_context
.SegSs
!= ds
) CHECK_SEG(DEBUG_context
.SegSs
, "SS");
157 if (DEBUG_context
.SegDs
!= ds
) CHECK_SEG(DEBUG_context
.SegDs
, "DS");
158 if (DEBUG_context
.SegEs
!= ds
) CHECK_SEG(DEBUG_context
.SegEs
, "ES");
159 if (DEBUG_context
.SegFs
!= ds
) CHECK_SEG(DEBUG_context
.SegFs
, "FS");
160 if (DEBUG_context
.SegGs
!= ds
) CHECK_SEG(DEBUG_context
.SegGs
, "GS");
163 /* Check that CS and SS are not NULL */
165 if (!(DEBUG_context
.SegCs
& ~3))
167 DEBUG_Printf( DBG_CHN_MESG
, "*** Invalid value for CS register: %04x\n",
168 (WORD
)DEBUG_context
.SegCs
);
171 if (!(DEBUG_context
.SegSs
& ~3))
173 DEBUG_Printf( DBG_CHN_MESG
, "*** Invalid value for SS register: %04x\n",
174 (WORD
)DEBUG_context
.SegSs
);
183 /* check if PC is correct */
184 DEBUG_GetCurrentAddress(&addr
);
185 return DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear(&addr
), &ch
, 1);