be2433d37e6787b1f602d4d4e587c70869196ae8
[binutils-gdb.git] / gdb / arch-utils.c
1 /* Dynamic architecture support for GDB, the GNU debugger.
2 Copyright 1998-1999, Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program 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
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22
23 #if GDB_MULTI_ARCH
24 #include "gdbcmd.h"
25 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
26 #else
27 /* Just include everything in sight so that the every old definition
28 of macro is visible. */
29 #include "gdb_string.h"
30 #include <ctype.h>
31 #include "symtab.h"
32 #include "frame.h"
33 #include "inferior.h"
34 #include "breakpoint.h"
35 #include "gdb_wait.h"
36 #include "gdbcore.h"
37 #include "gdbcmd.h"
38 #include "target.h"
39 #include "gdbthread.h"
40 #include "annotate.h"
41 #include "symfile.h" /* for overlay functions */
42 #endif
43
44 #include "floatformat.h"
45
46 /* Convenience macro for allocting typesafe memory. */
47
48 #ifndef XMALLOC
49 #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
50 #endif
51
52
53 /* Use the program counter to determine the contents and size
54 of a breakpoint instruction. If no target-dependent macro
55 BREAKPOINT_FROM_PC has been defined to implement this function,
56 assume that the breakpoint doesn't depend on the PC, and
57 use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
58 Return a pointer to a string of bytes that encode a breakpoint
59 instruction, stores the length of the string to *lenptr,
60 and optionally adjust the pc to point to the correct memory location
61 for inserting the breakpoint. */
62
63 unsigned char *
64 legacy_breakpoint_from_pc (CORE_ADDR * pcptr, int *lenptr)
65 {
66 /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
67 breakpoint. On some machines, breakpoints are handled by the
68 target environment and we don't have to worry about them here. */
69 #ifdef BIG_BREAKPOINT
70 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
71 {
72 static unsigned char big_break_insn[] = BIG_BREAKPOINT;
73 *lenptr = sizeof (big_break_insn);
74 return big_break_insn;
75 }
76 #endif
77 #ifdef LITTLE_BREAKPOINT
78 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
79 {
80 static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
81 *lenptr = sizeof (little_break_insn);
82 return little_break_insn;
83 }
84 #endif
85 #ifdef BREAKPOINT
86 {
87 static unsigned char break_insn[] = BREAKPOINT;
88 *lenptr = sizeof (break_insn);
89 return break_insn;
90 }
91 #endif
92 *lenptr = 0;
93 return NULL;
94 }
95
96 int
97 generic_frameless_function_invocation_not (struct frame_info *fi)
98 {
99 return 0;
100 }
101
102 int
103 generic_return_value_on_stack_not (struct type *type)
104 {
105 return 0;
106 }
107
108 char *
109 legacy_register_name (int i)
110 {
111 #ifdef REGISTER_NAMES
112 static char *names[] = REGISTER_NAMES;
113 if (i < 0 || i >= (sizeof (names) / sizeof (*names)))
114 return NULL;
115 else
116 return names[i];
117 #else
118 internal_error ("legacy_register_name: called.");
119 return NULL;
120 #endif
121 }
122
123 #if defined (CALL_DUMMY)
124 LONGEST legacy_call_dummy_words[] = CALL_DUMMY;
125 #else
126 LONGEST legacy_call_dummy_words[1];
127 #endif
128 int legacy_sizeof_call_dummy_words = sizeof (legacy_call_dummy_words);
129
130 void
131 generic_remote_translate_xfer_address (CORE_ADDR gdb_addr, int gdb_len,
132 CORE_ADDR * rem_addr, int *rem_len)
133 {
134 *rem_addr = gdb_addr;
135 *rem_len = gdb_len;
136 }
137
138 int
139 generic_prologue_frameless_p (CORE_ADDR ip)
140 {
141 #ifdef SKIP_PROLOGUE_FRAMELESS_P
142 return ip == SKIP_PROLOGUE_FRAMELESS_P (ip);
143 #else
144 return ip == SKIP_PROLOGUE (ip);
145 #endif
146 }
147
148
149 /* Helper functions for INNER_THAN */
150
151 int
152 core_addr_lessthan (lhs, rhs)
153 CORE_ADDR lhs;
154 CORE_ADDR rhs;
155 {
156 return (lhs < rhs);
157 }
158
159 int
160 core_addr_greaterthan (lhs, rhs)
161 CORE_ADDR lhs;
162 CORE_ADDR rhs;
163 {
164 return (lhs > rhs);
165 }
166
167
168 /* Helper functions for TARGET_{FLOAT,DOUBLE}_FORMAT */
169
170 const struct floatformat *
171 default_float_format (struct gdbarch *gdbarch)
172 {
173 #if GDB_MULTI_ARCH
174 int byte_order = gdbarch_byte_order (gdbarch);
175 #else
176 int byte_order = TARGET_BYTE_ORDER;
177 #endif
178 switch (byte_order)
179 {
180 case BIG_ENDIAN:
181 return &floatformat_ieee_single_big;
182 case LITTLE_ENDIAN:
183 return &floatformat_ieee_single_little;
184 default:
185 internal_error ("default_float_format: bad byte order");
186 }
187 }
188
189
190 const struct floatformat *
191 default_double_format (struct gdbarch *gdbarch)
192 {
193 #if GDB_MULTI_ARCH
194 int byte_order = gdbarch_byte_order (gdbarch);
195 #else
196 int byte_order = TARGET_BYTE_ORDER;
197 #endif
198 switch (byte_order)
199 {
200 case BIG_ENDIAN:
201 return &floatformat_ieee_double_big;
202 case LITTLE_ENDIAN:
203 return &floatformat_ieee_double_little;
204 default:
205 internal_error ("default_double_format: bad byte order");
206 }
207 }
208
209 /* */
210
211 extern initialize_file_ftype __initialize_gdbarch_utils;
212
213 void
214 __initialize_gdbarch_utils (void)
215 {
216 }