Moved a number of 16-bit functions to file16.c.
[wine.git] / programs / winedbg / registers.c
blob0bbeb78cabadef410c3f0c9e52d5ef96e8a7211c
1 /*
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
21 #include "config.h"
22 #include <string.h>
23 #include "debugger.h"
25 /***********************************************************************
26 * DEBUG_Flags
28 * Return Flag String.
30 static char *DEBUG_Flags( DWORD flag, char *buf )
32 #ifdef __i386__
33 char *pt;
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 Privilege Level */
63 if ( buf >= pt-- ) return( buf );
64 if ( flag & 0x00002000 ) *pt = '1'; /* I/O Privilege 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 );
76 return( buf );
77 #else
78 strcpy(buf, "unknown CPU");
79 return buf;
80 #endif
84 /***********************************************************************
85 * DEBUG_InfoRegisters
87 * Display registers information.
89 void DEBUG_InfoRegisters(const CONTEXT* ctx)
91 DEBUG_Printf("Register dump:\n");
93 #ifdef __i386__
94 /* First get the segment registers out of the way */
95 DEBUG_Printf(" 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)
101 char flag[33];
103 DEBUG_Printf("\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(" 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 */
114 char flag[33];
116 DEBUG_Printf("\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx(%s)\n",
117 ctx->Eip, ctx->Esp,
118 ctx->Ebp, ctx->EFlags,
119 DEBUG_Flags(ctx->EFlags, flag));
120 DEBUG_Printf(" EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n",
121 ctx->Eax, ctx->Ebx,
122 ctx->Ecx, ctx->Edx );
123 DEBUG_Printf(" ESI:%08lx EDI:%08lx\n",
124 ctx->Esi, ctx->Edi );
126 #endif
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)
138 DBG_ADDR addr;
139 char ch;
141 #ifdef __i386__
142 if (DEBUG_context.EFlags & V86_FLAG) return TRUE;
144 #if 0
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("*** Invalid value for %s register: %04x\n", \
149 (name), (WORD)(seg) ); \
150 return FALSE; \
153 cs = __get_cs();
154 ds = __get_ds();
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");
161 #endif
163 /* Check that CS and SS are not NULL */
165 if (!(DEBUG_context.SegCs & ~3))
167 DEBUG_Printf("*** Invalid value for CS register: %04x\n",
168 (WORD)DEBUG_context.SegCs );
169 return FALSE;
171 if (!(DEBUG_context.SegSs & ~3))
173 DEBUG_Printf("*** Invalid value for SS register: %04x\n",
174 (WORD)DEBUG_context.SegSs );
175 return FALSE;
178 #undef CHECK_SEG
179 #else
180 /* to be written */
181 #endif
183 /* check if PC is correct */
184 DEBUG_GetCurrentAddress(&addr);
185 return DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear(&addr), &ch, 1);