Added afm weight "NORMAL".
[wine] / debugger / registers.c
1 /*
2  * Debugger register handling
3  *
4  * Copyright 1995 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include <string.h>
23 #include "debugger.h"
24
25 /***********************************************************************
26  *           DEBUG_Flags
27  *
28  * Return Flag String.
29  */
30 char *DEBUG_Flags( DWORD flag, char *buf )
31 {
32 #ifdef __i386__
33     char *pt;
34
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 );
76     return( buf );
77 #else
78     strcpy(buf, "unknown CPU");
79     return buf;
80 #endif
81 }
82
83
84 /***********************************************************************
85  *           DEBUG_InfoRegisters
86  *
87  * Display registers information.
88  */
89 void DEBUG_InfoRegisters(void)
90 {
91     DEBUG_Printf(DBG_CHN_MESG,"Register dump:\n");
92
93 #ifdef __i386__
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)DEBUG_context.SegCs, (WORD)DEBUG_context.SegSs,
97                   (WORD)DEBUG_context.SegDs, (WORD)DEBUG_context.SegEs,
98                   (WORD)DEBUG_context.SegFs, (WORD)DEBUG_context.SegGs );
99     if (DEBUG_CurrThread->dbg_mode != MODE_32)
100     {
101         char flag[33];
102
103         DEBUG_Printf( DBG_CHN_MESG,"\n IP:%04x SP:%04x BP:%04x FLAGS:%04x(%s)\n",
104                       LOWORD(DEBUG_context.Eip), LOWORD(DEBUG_context.Esp),
105                       LOWORD(DEBUG_context.Ebp), LOWORD(DEBUG_context.EFlags),
106                       DEBUG_Flags(LOWORD(DEBUG_context.EFlags), flag));
107         DEBUG_Printf( DBG_CHN_MESG," AX:%04x BX:%04x CX:%04x DX:%04x SI:%04x DI:%04x\n",
108                       LOWORD(DEBUG_context.Eax), LOWORD(DEBUG_context.Ebx),
109                       LOWORD(DEBUG_context.Ecx), LOWORD(DEBUG_context.Edx),
110                       LOWORD(DEBUG_context.Esi), LOWORD(DEBUG_context.Edi) );
111     }
112     else  /* 32-bit mode */
113     {
114         char flag[33];
115
116         DEBUG_Printf( DBG_CHN_MESG, "\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx(%s)\n",
117                       DEBUG_context.Eip, DEBUG_context.Esp,
118                       DEBUG_context.Ebp, DEBUG_context.EFlags,
119                       DEBUG_Flags(DEBUG_context.EFlags, flag));
120         DEBUG_Printf( DBG_CHN_MESG, " EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n",
121                       DEBUG_context.Eax, DEBUG_context.Ebx,
122                       DEBUG_context.Ecx, DEBUG_context.Edx );
123         DEBUG_Printf( DBG_CHN_MESG, " ESI:%08lx EDI:%08lx\n",
124                       DEBUG_context.Esi, DEBUG_context.Edi );
125     }
126 #endif
127 }
128
129
130 /***********************************************************************
131  *           DEBUG_ValidateRegisters
132  *
133  * Make sure all registers have a correct value for returning from
134  * the signal handler.
135  */
136 BOOL DEBUG_ValidateRegisters(void)
137 {
138    DBG_ADDR     addr;
139    char         ch;
140
141 #ifdef __i386__
142     if (DEBUG_context.EFlags & V86_FLAG) return TRUE;
143
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( DBG_CHN_MESG, "*** Invalid value for %s register: %04x\n", \
149                       (name), (WORD)(seg) ); \
150         return FALSE; \
151     }
152
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
162
163     /* Check that CS and SS are not NULL */
164
165     if (!(DEBUG_context.SegCs & ~3))
166     {
167         DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for CS register: %04x\n",
168                       (WORD)DEBUG_context.SegCs );
169         return FALSE;
170     }
171     if (!(DEBUG_context.SegSs & ~3))
172     {
173         DEBUG_Printf( DBG_CHN_MESG, "*** Invalid value for SS register: %04x\n",
174                       (WORD)DEBUG_context.SegSs );
175         return FALSE;
176     }
177
178 #undef CHECK_SEG
179 #else
180     /* to be written */
181 #endif
182
183     /* check if PC is correct */
184     DEBUG_GetCurrentAddress(&addr);
185     return DEBUG_READ_MEM_VERBOSE((void*)DEBUG_ToLinear(&addr), &ch, 1);
186 }