Terminate image data with a '>' [The PSLRM is rather vague about this].
[wine/multimedia.git] / debugger / registers.c
blob4dde821cdcc5239a4834ed46812c258fb88ea4dc
1 /*
2 * Debugger register handling
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include "config.h"
8 #include <string.h>
9 #include "debugger.h"
11 /***********************************************************************
12 * DEBUG_Flags
14 * Return Flag String.
16 char *DEBUG_Flags( DWORD flag, char *buf )
18 #ifdef __i386__
19 char *pt;
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 );
62 return( buf );
63 #else
64 strcpy(buf, "unknown CPU");
65 return buf;
66 #endif
70 /***********************************************************************
71 * DEBUG_InfoRegisters
73 * Display registers information.
75 void DEBUG_InfoRegisters(void)
77 DEBUG_Printf(DBG_CHN_MESG,"Register dump:\n");
79 #ifdef __i386__
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 == 16)
87 char flag[33];
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 */
100 char flag[33];
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 );
112 #endif
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)
124 #ifdef __i386__
125 if (DEBUG_context.EFlags & V86_FLAG) return TRUE;
127 #if 0
128 /* Check that a selector is a valid ring-3 LDT selector, or a NULL selector */
129 #define CHECK_SEG(seg,name) \
130 if (((seg) & ~3) && ((((seg) & 7) != 7) || !DEBUG_IsSelector(seg))) { \
131 DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for %s register: %04x\n", \
132 (name), (WORD)(seg) ); \
133 return FALSE; \
136 cs = __get_cs();
137 ds = __get_ds();
138 if (CS_reg(DEBUG_context) != cs) CHECK_SEG(CS_reg(DEBUG_context), "CS");
139 if (SS_reg(DEBUG_context) != ds) CHECK_SEG(SS_reg(DEBUG_context), "SS");
140 if (DS_reg(DEBUG_context) != ds) CHECK_SEG(DS_reg(DEBUG_context), "DS");
141 if (ES_reg(DEBUG_context) != ds) CHECK_SEG(ES_reg(DEBUG_context), "ES");
142 if (FS_reg(DEBUG_context) != ds) CHECK_SEG(FS_reg(DEBUG_context), "FS");
143 if (GS_reg(DEBUG_context) != ds) CHECK_SEG(GS_reg(DEBUG_context), "GS");
144 #endif
146 /* Check that CS and SS are not NULL */
148 if (!(DEBUG_context.SegCs & ~3))
150 DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for CS register: %04x\n",
151 (WORD)DEBUG_context.SegCs );
152 return FALSE;
154 if (!(DEBUG_context.SegSs & ~3))
156 DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for SS register: %04x\n",
157 (WORD)DEBUG_context.SegSs );
158 return FALSE;
160 return TRUE;
161 #undef CHECK_SEG
162 #else
163 return TRUE;
164 #endif