daily update
[deliverable/binutils-gdb.git] / gdb / gdbarch.sh
CommitLineData
66b43ecb 1#!/bin/sh -u
104c1213
JM
2
3# Architecture commands for GDB, the GNU debugger.
79d45cd4
AC
4#
5# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
6# Foundation, Inc.
7#
104c1213
JM
8#
9# This file is part of GDB.
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
d8864532
AC
25# Make certain that the script is running in an internationalized
26# environment.
27LANG=c ; export LANG
1bd316f0 28LC_ALL=c ; export LC_ALL
d8864532
AC
29
30
59233f88
AC
31compare_new ()
32{
33 file=$1
66b43ecb 34 if test ! -r ${file}
59233f88
AC
35 then
36 echo "${file} missing? cp new-${file} ${file}" 1>&2
50248794 37 elif diff -u ${file} new-${file}
59233f88
AC
38 then
39 echo "${file} unchanged" 1>&2
40 else
41 echo "${file} has changed? cp new-${file} ${file}" 1>&2
42 fi
43}
44
45
46# Format of the input table
57010b1c 47read="class macro returntype function formal actual attrib staticdefault predefault postdefault invalid_p fmt print print_p description"
c0e8c252
AC
48
49do_read ()
50{
34620563
AC
51 comment=""
52 class=""
53 while read line
54 do
55 if test "${line}" = ""
56 then
57 continue
58 elif test "${line}" = "#" -a "${comment}" = ""
f0d4cc9e 59 then
34620563
AC
60 continue
61 elif expr "${line}" : "#" > /dev/null
f0d4cc9e 62 then
34620563
AC
63 comment="${comment}
64${line}"
f0d4cc9e 65 else
3d9a5942
AC
66
67 # The semantics of IFS varies between different SH's. Some
68 # treat ``::' as three fields while some treat it as just too.
69 # Work around this by eliminating ``::'' ....
70 line="`echo "${line}" | sed -e 's/::/: :/g' -e 's/::/: :/g'`"
71
72 OFS="${IFS}" ; IFS="[:]"
34620563
AC
73 eval read ${read} <<EOF
74${line}
75EOF
76 IFS="${OFS}"
77
3d9a5942
AC
78 # .... and then going back through each field and strip out those
79 # that ended up with just that space character.
80 for r in ${read}
81 do
82 if eval test \"\${${r}}\" = \"\ \"
83 then
84 eval ${r}=""
85 fi
86 done
87
a72293e2
AC
88 case "${class}" in
89 m ) staticdefault="${predefault}" ;;
90 M ) staticdefault="0" ;;
91 * ) test "${staticdefault}" || staticdefault=0 ;;
92 esac
06b25f14
AC
93
94 # come up with a format, use a few guesses for variables
95 case ":${class}:${fmt}:${print}:" in
96 :[vV]::: )
97 if [ "${returntype}" = int ]
98 then
99 fmt="%d"
100 print="${macro}"
101 elif [ "${returntype}" = long ]
102 then
103 fmt="%ld"
104 print="${macro}"
105 fi
106 ;;
107 esac
34620563
AC
108 test "${fmt}" || fmt="%ld"
109 test "${print}" || print="(long) ${macro}"
06b25f14 110
ae45cd16
AC
111 case "${class}" in
112 F | V | M )
113 case "${invalid_p}" in
34620563 114 "" )
f7968451 115 if test -n "${predefault}"
34620563
AC
116 then
117 #invalid_p="gdbarch->${function} == ${predefault}"
ae45cd16 118 predicate="gdbarch->${function} != ${predefault}"
f7968451
AC
119 elif class_is_variable_p
120 then
121 predicate="gdbarch->${function} != 0"
122 elif class_is_function_p
123 then
124 predicate="gdbarch->${function} != NULL"
34620563
AC
125 fi
126 ;;
ae45cd16 127 * )
1e9f55d0 128 echo "Predicate function ${function} with invalid_p." 1>&2
ae45cd16
AC
129 kill $$
130 exit 1
131 ;;
132 esac
34620563
AC
133 esac
134
135 # PREDEFAULT is a valid fallback definition of MEMBER when
136 # multi-arch is not enabled. This ensures that the
137 # default value, when multi-arch is the same as the
138 # default value when not multi-arch. POSTDEFAULT is
139 # always a valid definition of MEMBER as this again
140 # ensures consistency.
141
72e74a21 142 if [ -n "${postdefault}" ]
34620563
AC
143 then
144 fallbackdefault="${postdefault}"
72e74a21 145 elif [ -n "${predefault}" ]
34620563
AC
146 then
147 fallbackdefault="${predefault}"
148 else
73d3c16e 149 fallbackdefault="0"
34620563
AC
150 fi
151
152 #NOT YET: See gdbarch.log for basic verification of
153 # database
154
155 break
f0d4cc9e 156 fi
34620563 157 done
72e74a21 158 if [ -n "${class}" ]
34620563
AC
159 then
160 true
c0e8c252
AC
161 else
162 false
163 fi
164}
165
104c1213 166
f0d4cc9e
AC
167fallback_default_p ()
168{
72e74a21
JB
169 [ -n "${postdefault}" -a "x${invalid_p}" != "x0" ] \
170 || [ -n "${predefault}" -a "x${invalid_p}" = "x0" ]
f0d4cc9e
AC
171}
172
173class_is_variable_p ()
174{
4a5c6a1d
AC
175 case "${class}" in
176 *v* | *V* ) true ;;
177 * ) false ;;
178 esac
f0d4cc9e
AC
179}
180
181class_is_function_p ()
182{
4a5c6a1d
AC
183 case "${class}" in
184 *f* | *F* | *m* | *M* ) true ;;
185 * ) false ;;
186 esac
187}
188
189class_is_multiarch_p ()
190{
191 case "${class}" in
192 *m* | *M* ) true ;;
193 * ) false ;;
194 esac
f0d4cc9e
AC
195}
196
197class_is_predicate_p ()
198{
4a5c6a1d
AC
199 case "${class}" in
200 *F* | *V* | *M* ) true ;;
201 * ) false ;;
202 esac
f0d4cc9e
AC
203}
204
205class_is_info_p ()
206{
4a5c6a1d
AC
207 case "${class}" in
208 *i* ) true ;;
209 * ) false ;;
210 esac
f0d4cc9e
AC
211}
212
213
cff3e48b
JM
214# dump out/verify the doco
215for field in ${read}
216do
217 case ${field} in
218
219 class ) : ;;
c4093a6a 220
c0e8c252
AC
221 # # -> line disable
222 # f -> function
223 # hiding a function
2ada493a
AC
224 # F -> function + predicate
225 # hiding a function + predicate to test function validity
c0e8c252
AC
226 # v -> variable
227 # hiding a variable
2ada493a
AC
228 # V -> variable + predicate
229 # hiding a variable + predicate to test variables validity
c0e8c252
AC
230 # i -> set from info
231 # hiding something from the ``struct info'' object
4a5c6a1d
AC
232 # m -> multi-arch function
233 # hiding a multi-arch function (parameterised with the architecture)
234 # M -> multi-arch function + predicate
235 # hiding a multi-arch function + predicate to test function validity
cff3e48b 236
cff3e48b
JM
237 macro ) : ;;
238
c0e8c252 239 # The name of the MACRO that this method is to be accessed by.
cff3e48b
JM
240
241 returntype ) : ;;
242
c0e8c252 243 # For functions, the return type; for variables, the data type
cff3e48b
JM
244
245 function ) : ;;
246
c0e8c252
AC
247 # For functions, the member function name; for variables, the
248 # variable name. Member function names are always prefixed with
249 # ``gdbarch_'' for name-space purity.
cff3e48b
JM
250
251 formal ) : ;;
252
c0e8c252
AC
253 # The formal argument list. It is assumed that the formal
254 # argument list includes the actual name of each list element.
255 # A function with no arguments shall have ``void'' as the
256 # formal argument list.
cff3e48b
JM
257
258 actual ) : ;;
259
c0e8c252
AC
260 # The list of actual arguments. The arguments specified shall
261 # match the FORMAL list given above. Functions with out
262 # arguments leave this blank.
cff3e48b
JM
263
264 attrib ) : ;;
265
c0e8c252
AC
266 # Any GCC attributes that should be attached to the function
267 # declaration. At present this field is unused.
cff3e48b 268
0b8f9e4d 269 staticdefault ) : ;;
c0e8c252
AC
270
271 # To help with the GDB startup a static gdbarch object is
0b8f9e4d
AC
272 # created. STATICDEFAULT is the value to insert into that
273 # static gdbarch object. Since this a static object only
274 # simple expressions can be used.
cff3e48b 275
0b8f9e4d 276 # If STATICDEFAULT is empty, zero is used.
c0e8c252 277
0b8f9e4d 278 predefault ) : ;;
cff3e48b 279
10312cc4
AC
280 # An initial value to assign to MEMBER of the freshly
281 # malloc()ed gdbarch object. After initialization, the
282 # freshly malloc()ed object is passed to the target
283 # architecture code for further updates.
cff3e48b 284
0b8f9e4d
AC
285 # If PREDEFAULT is empty, zero is used.
286
10312cc4
AC
287 # A non-empty PREDEFAULT, an empty POSTDEFAULT and a zero
288 # INVALID_P are specified, PREDEFAULT will be used as the
289 # default for the non- multi-arch target.
290
291 # A zero PREDEFAULT function will force the fallback to call
292 # internal_error().
f0d4cc9e
AC
293
294 # Variable declarations can refer to ``gdbarch'' which will
295 # contain the current architecture. Care should be taken.
0b8f9e4d
AC
296
297 postdefault ) : ;;
298
299 # A value to assign to MEMBER of the new gdbarch object should
10312cc4
AC
300 # the target architecture code fail to change the PREDEFAULT
301 # value.
0b8f9e4d
AC
302
303 # If POSTDEFAULT is empty, no post update is performed.
304
305 # If both INVALID_P and POSTDEFAULT are non-empty then
306 # INVALID_P will be used to determine if MEMBER should be
307 # changed to POSTDEFAULT.
308
10312cc4
AC
309 # If a non-empty POSTDEFAULT and a zero INVALID_P are
310 # specified, POSTDEFAULT will be used as the default for the
311 # non- multi-arch target (regardless of the value of
312 # PREDEFAULT).
313
f0d4cc9e
AC
314 # You cannot specify both a zero INVALID_P and a POSTDEFAULT.
315
db446970
AC
316 # Variable declarations can refer to ``current_gdbarch'' which
317 # will contain the current architecture. Care should be
318 # taken.
cff3e48b 319
c4093a6a 320 invalid_p ) : ;;
cff3e48b 321
0b8f9e4d 322 # A predicate equation that validates MEMBER. Non-zero is
c0e8c252 323 # returned if the code creating the new architecture failed to
0b8f9e4d
AC
324 # initialize MEMBER or the initialized the member is invalid.
325 # If POSTDEFAULT is non-empty then MEMBER will be updated to
326 # that value. If POSTDEFAULT is empty then internal_error()
327 # is called.
328
329 # If INVALID_P is empty, a check that MEMBER is no longer
330 # equal to PREDEFAULT is used.
331
f0d4cc9e
AC
332 # The expression ``0'' disables the INVALID_P check making
333 # PREDEFAULT a legitimate value.
0b8f9e4d
AC
334
335 # See also PREDEFAULT and POSTDEFAULT.
cff3e48b
JM
336
337 fmt ) : ;;
338
c0e8c252
AC
339 # printf style format string that can be used to print out the
340 # MEMBER. Sometimes "%s" is useful. For functions, this is
341 # ignored and the function address is printed.
342
0b8f9e4d 343 # If FMT is empty, ``%ld'' is used.
cff3e48b
JM
344
345 print ) : ;;
346
c0e8c252
AC
347 # An optional equation that casts MEMBER to a value suitable
348 # for formatting by FMT.
349
0b8f9e4d 350 # If PRINT is empty, ``(long)'' is used.
cff3e48b
JM
351
352 print_p ) : ;;
353
c0e8c252
AC
354 # An optional indicator for any predicte to wrap around the
355 # print member code.
356
4b9b3959 357 # () -> Call a custom function to do the dump.
c0e8c252
AC
358 # exp -> Wrap print up in ``if (${print_p}) ...
359 # ``'' -> No predicate
cff3e48b 360
0b8f9e4d
AC
361 # If PRINT_P is empty, ``1'' is always used.
362
cff3e48b
JM
363 description ) : ;;
364
0b8f9e4d 365 # Currently unused.
cff3e48b 366
50248794
AC
367 *)
368 echo "Bad field ${field}"
369 exit 1;;
cff3e48b
JM
370 esac
371done
372
cff3e48b 373
104c1213
JM
374function_list ()
375{
cff3e48b 376 # See below (DOCO) for description of each field
34620563 377 cat <<EOF
57010b1c 378i:TARGET_ARCHITECTURE:const struct bfd_arch_info *:bfd_arch_info::::&bfd_default_arch_struct::::%s:TARGET_ARCHITECTURE->printable_name:TARGET_ARCHITECTURE != NULL
104c1213 379#
57010b1c 380i:TARGET_BYTE_ORDER:int:byte_order::::BFD_ENDIAN_BIG
4be87837 381#
57010b1c 382i:TARGET_OSABI:enum gdb_osabi:osabi::::GDB_OSABI_UNKNOWN
66b43ecb
AC
383# Number of bits in a char or unsigned char for the target machine.
384# Just like CHAR_BIT in <limits.h> but describes the target machine.
57010b1c 385# v:TARGET_CHAR_BIT:int:char_bit::::8 * sizeof (char):8::0:
66b43ecb
AC
386#
387# Number of bits in a short or unsigned short for the target machine.
57010b1c 388v:TARGET_SHORT_BIT:int:short_bit::::8 * sizeof (short):2*TARGET_CHAR_BIT::0
66b43ecb 389# Number of bits in an int or unsigned int for the target machine.
57010b1c 390v:TARGET_INT_BIT:int:int_bit::::8 * sizeof (int):4*TARGET_CHAR_BIT::0
66b43ecb 391# Number of bits in a long or unsigned long for the target machine.
57010b1c 392v:TARGET_LONG_BIT:int:long_bit::::8 * sizeof (long):4*TARGET_CHAR_BIT::0
66b43ecb
AC
393# Number of bits in a long long or unsigned long long for the target
394# machine.
57010b1c 395v:TARGET_LONG_LONG_BIT:int:long_long_bit::::8 * sizeof (LONGEST):2*TARGET_LONG_BIT::0
66b43ecb 396# Number of bits in a float for the target machine.
57010b1c 397v:TARGET_FLOAT_BIT:int:float_bit::::8 * sizeof (float):4*TARGET_CHAR_BIT::0
66b43ecb 398# Number of bits in a double for the target machine.
57010b1c 399v:TARGET_DOUBLE_BIT:int:double_bit::::8 * sizeof (double):8*TARGET_CHAR_BIT::0
66b43ecb 400# Number of bits in a long double for the target machine.
57010b1c 401v:TARGET_LONG_DOUBLE_BIT:int:long_double_bit::::8 * sizeof (long double):8*TARGET_CHAR_BIT::0
52204a0b
DT
402# For most targets, a pointer on the target and its representation as an
403# address in GDB have the same size and "look the same". For such a
404# target, you need only set TARGET_PTR_BIT / ptr_bit and TARGET_ADDR_BIT
405# / addr_bit will be set from it.
406#
407# If TARGET_PTR_BIT and TARGET_ADDR_BIT are different, you'll probably
408# also need to set POINTER_TO_ADDRESS and ADDRESS_TO_POINTER as well.
409#
410# ptr_bit is the size of a pointer on the target
57010b1c 411v:TARGET_PTR_BIT:int:ptr_bit::::8 * sizeof (void*):TARGET_INT_BIT::0
52204a0b 412# addr_bit is the size of a target address as represented in gdb
57010b1c 413v:TARGET_ADDR_BIT:int:addr_bit::::8 * sizeof (void*):0:TARGET_PTR_BIT:
66b43ecb 414# Number of bits in a BFD_VMA for the target object file format.
57010b1c 415v:TARGET_BFD_VMA_BIT:int:bfd_vma_bit::::8 * sizeof (void*):TARGET_ARCHITECTURE->bits_per_address::0
104c1213 416#
4e409299 417# One if \`char' acts like \`signed char', zero if \`unsigned char'.
57010b1c 418v:TARGET_CHAR_SIGNED:int:char_signed::::1:-1:1::::
4e409299 419#
57010b1c
AC
420F:TARGET_READ_PC:CORE_ADDR:read_pc:ptid_t ptid:ptid
421f:TARGET_WRITE_PC:void:write_pc:CORE_ADDR val, ptid_t ptid:val, ptid::0:generic_target_write_pc::0
a9e5fdc2 422# UNWIND_SP is a direct replacement for TARGET_READ_SP.
57010b1c 423F:TARGET_READ_SP:CORE_ADDR:read_sp:void
39d4ef09
AC
424# Function for getting target's idea of a frame pointer. FIXME: GDB's
425# whole scheme for dealing with "frames" and "frame pointers" needs a
426# serious shakedown.
57010b1c 427f:TARGET_VIRTUAL_FRAME_POINTER:void:virtual_frame_pointer:CORE_ADDR pc, int *frame_regnum, LONGEST *frame_offset:pc, frame_regnum, frame_offset::0:legacy_virtual_frame_pointer::0
66b43ecb 428#
57010b1c
AC
429M::void:pseudo_register_read:struct regcache *regcache, int cookednum, void *buf:regcache, cookednum, buf
430M::void:pseudo_register_write:struct regcache *regcache, int cookednum, const void *buf:regcache, cookednum, buf
61a0eb5b 431#
57010b1c 432v:NUM_REGS:int:num_regs::::0:-1
0aba1244
EZ
433# This macro gives the number of pseudo-registers that live in the
434# register namespace but do not get fetched or stored on the target.
3d9a5942
AC
435# These pseudo-registers may be aliases for other registers,
436# combinations of other registers, or they may be computed by GDB.
57010b1c 437v:NUM_PSEUDO_REGS:int:num_pseudo_regs::::0:0::0:::
c2169756
AC
438
439# GDB's standard (or well known) register numbers. These can map onto
440# a real register or a pseudo (computed) register or not be defined at
1200cd6e 441# all (-1).
a9e5fdc2 442# SP_REGNUM will hopefully be replaced by UNWIND_SP.
57010b1c
AC
443v:SP_REGNUM:int:sp_regnum::::-1:-1::0
444v:PC_REGNUM:int:pc_regnum::::-1:-1::0
445v:PS_REGNUM:int:ps_regnum::::-1:-1::0
446v:FP0_REGNUM:int:fp0_regnum::::0:-1::0
88c72b7d 447# Convert stab register number (from \`r\' declaration) to a gdb REGNUM.
57010b1c 448f:STAB_REG_TO_REGNUM:int:stab_reg_to_regnum:int stab_regnr:stab_regnr:::no_op_reg_to_regnum::0
88c72b7d 449# Provide a default mapping from a ecoff register number to a gdb REGNUM.
57010b1c 450f:ECOFF_REG_TO_REGNUM:int:ecoff_reg_to_regnum:int ecoff_regnr:ecoff_regnr:::no_op_reg_to_regnum::0
88c72b7d 451# Provide a default mapping from a DWARF register number to a gdb REGNUM.
57010b1c 452f:DWARF_REG_TO_REGNUM:int:dwarf_reg_to_regnum:int dwarf_regnr:dwarf_regnr:::no_op_reg_to_regnum::0
88c72b7d 453# Convert from an sdb register number to an internal gdb register number.
57010b1c
AC
454f:SDB_REG_TO_REGNUM:int:sdb_reg_to_regnum:int sdb_regnr:sdb_regnr:::no_op_reg_to_regnum::0
455f:DWARF2_REG_TO_REGNUM:int:dwarf2_reg_to_regnum:int dwarf2_regnr:dwarf2_regnr:::no_op_reg_to_regnum::0
456f:REGISTER_NAME:const char *:register_name:int regnr:regnr
9c04cab7 457
2e092625 458# REGISTER_TYPE is a direct replacement for DEPRECATED_REGISTER_VIRTUAL_TYPE.
57010b1c 459M:REGISTER_TYPE:struct type *:register_type:int reg_nr:reg_nr
2e092625 460# REGISTER_TYPE is a direct replacement for DEPRECATED_REGISTER_VIRTUAL_TYPE.
57010b1c 461F:DEPRECATED_REGISTER_VIRTUAL_TYPE:struct type *:deprecated_register_virtual_type:int reg_nr:reg_nr
9c04cab7
AC
462# DEPRECATED_REGISTER_BYTES can be deleted. The value is computed
463# from REGISTER_TYPE.
57010b1c 464v:DEPRECATED_REGISTER_BYTES:int:deprecated_register_bytes
f3be58bc
AC
465# If the value returned by DEPRECATED_REGISTER_BYTE agrees with the
466# register offsets computed using just REGISTER_TYPE, this can be
467# deleted. See: maint print registers. NOTE: cagney/2002-05-02: This
468# function with predicate has a valid (callable) initial value. As a
469# consequence, even when the predicate is false, the corresponding
470# function works. This simplifies the migration process - old code,
471# calling DEPRECATED_REGISTER_BYTE, doesn't need to be modified.
57010b1c 472F:DEPRECATED_REGISTER_BYTE:int:deprecated_register_byte:int reg_nr:reg_nr::generic_register_byte:generic_register_byte
f3be58bc
AC
473# If all registers have identical raw and virtual sizes and those
474# sizes agree with the value computed from REGISTER_TYPE,
475# DEPRECATED_REGISTER_RAW_SIZE can be deleted. See: maint print
476# registers.
57010b1c 477F:DEPRECATED_REGISTER_RAW_SIZE:int:deprecated_register_raw_size:int reg_nr:reg_nr::generic_register_size:generic_register_size
f3be58bc
AC
478# If all registers have identical raw and virtual sizes and those
479# sizes agree with the value computed from REGISTER_TYPE,
480# DEPRECATED_REGISTER_VIRTUAL_SIZE can be deleted. See: maint print
481# registers.
57010b1c 482F:DEPRECATED_REGISTER_VIRTUAL_SIZE:int:deprecated_register_virtual_size:int reg_nr:reg_nr::generic_register_size:generic_register_size
9c04cab7 483
f3be58bc 484# See gdbint.texinfo, and PUSH_DUMMY_CALL.
57010b1c 485M:UNWIND_DUMMY_ID:struct frame_id:unwind_dummy_id:struct frame_info *info:info
f3be58bc
AC
486# Implement UNWIND_DUMMY_ID and PUSH_DUMMY_CALL, then delete
487# SAVE_DUMMY_FRAME_TOS.
57010b1c 488F:DEPRECATED_SAVE_DUMMY_FRAME_TOS:void:deprecated_save_dummy_frame_tos:CORE_ADDR sp:sp
f3be58bc
AC
489# Implement UNWIND_DUMMY_ID and PUSH_DUMMY_CALL, then delete
490# DEPRECATED_FP_REGNUM.
57010b1c 491v:DEPRECATED_FP_REGNUM:int:deprecated_fp_regnum::::-1:-1::0
f3be58bc
AC
492# Implement UNWIND_DUMMY_ID and PUSH_DUMMY_CALL, then delete
493# DEPRECATED_TARGET_READ_FP.
57010b1c 494F:DEPRECATED_TARGET_READ_FP:CORE_ADDR:deprecated_target_read_fp:void
f3be58bc 495
b8de8283
AC
496# See gdbint.texinfo. See infcall.c. New, all singing all dancing,
497# replacement for DEPRECATED_PUSH_ARGUMENTS.
57010b1c 498M:PUSH_DUMMY_CALL:CORE_ADDR:push_dummy_call:struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr:function, regcache, bp_addr, nargs, args, sp, struct_return, struct_addr
b8de8283 499# PUSH_DUMMY_CALL is a direct replacement for DEPRECATED_PUSH_ARGUMENTS.
57010b1c 500F:DEPRECATED_PUSH_ARGUMENTS:CORE_ADDR:deprecated_push_arguments:int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr:nargs, args, sp, struct_return, struct_addr
b8de8283
AC
501# Implement PUSH_RETURN_ADDRESS, and then merge in
502# DEPRECATED_PUSH_RETURN_ADDRESS.
57010b1c 503F:DEPRECATED_PUSH_RETURN_ADDRESS:CORE_ADDR:deprecated_push_return_address:CORE_ADDR pc, CORE_ADDR sp:pc, sp
b8de8283 504# Implement PUSH_DUMMY_CALL, then merge in DEPRECATED_DUMMY_WRITE_SP.
57010b1c 505F:DEPRECATED_DUMMY_WRITE_SP:void:deprecated_dummy_write_sp:CORE_ADDR val:val
b8de8283 506# DEPRECATED_REGISTER_SIZE can be deleted.
57010b1c
AC
507v:DEPRECATED_REGISTER_SIZE:int:deprecated_register_size
508v:CALL_DUMMY_LOCATION:int:call_dummy_location:::::AT_ENTRY_POINT::0
509M:PUSH_DUMMY_CODE:CORE_ADDR:push_dummy_code:CORE_ADDR sp, CORE_ADDR funaddr, int using_gcc, struct value **args, int nargs, struct type *value_type, CORE_ADDR *real_pc, CORE_ADDR *bp_addr:sp, funaddr, using_gcc, args, nargs, value_type, real_pc, bp_addr
510
511F:DEPRECATED_DO_REGISTERS_INFO:void:deprecated_do_registers_info:int reg_nr, int fpregs:reg_nr, fpregs
512m:PRINT_REGISTERS_INFO:void:print_registers_info:struct ui_file *file, struct frame_info *frame, int regnum, int all:file, frame, regnum, all:::default_print_registers_info::0
513M:PRINT_FLOAT_INFO:void:print_float_info:struct ui_file *file, struct frame_info *frame, const char *args:file, frame, args
514M:PRINT_VECTOR_INFO:void:print_vector_info:struct ui_file *file, struct frame_info *frame, const char *args:file, frame, args
7c7651b2
AC
515# MAP a GDB RAW register number onto a simulator register number. See
516# also include/...-sim.h.
57010b1c
AC
517f:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::legacy_register_sim_regno::0
518F:REGISTER_BYTES_OK:int:register_bytes_ok:long nr_bytes:nr_bytes
519f:CANNOT_FETCH_REGISTER:int:cannot_fetch_register:int regnum:regnum:::cannot_register_not::0
520f:CANNOT_STORE_REGISTER:int:cannot_store_register:int regnum:regnum:::cannot_register_not::0
9df628e0 521# setjmp/longjmp support.
57010b1c
AC
522F:GET_LONGJMP_TARGET:int:get_longjmp_target:CORE_ADDR *pc:pc
523F:DEPRECATED_INIT_FRAME_PC:CORE_ADDR:deprecated_init_frame_pc:int fromleaf, struct frame_info *prev:fromleaf, prev
104c1213 524#
57010b1c
AC
525v:BELIEVE_PCC_PROMOTION:int:believe_pcc_promotion:::::::
526F:DEPRECATED_GET_SAVED_REGISTER:void:deprecated_get_saved_register:char *raw_buffer, int *optimized, CORE_ADDR *addrp, struct frame_info *frame, int regnum, enum lval_type *lval:raw_buffer, optimized, addrp, frame, regnum, lval
104c1213 527#
57010b1c
AC
528f:CONVERT_REGISTER_P:int:convert_register_p:int regnum, struct type *type:regnum, type::0:generic_convert_register_p::0
529f:REGISTER_TO_VALUE:void:register_to_value:struct frame_info *frame, int regnum, struct type *type, void *buf:frame, regnum, type, buf::0
530f:VALUE_TO_REGISTER:void:value_to_register:struct frame_info *frame, int regnum, struct type *type, const void *buf:frame, regnum, type, buf::0
104c1213 531#
57010b1c
AC
532f:POINTER_TO_ADDRESS:CORE_ADDR:pointer_to_address:struct type *type, const void *buf:type, buf:::unsigned_pointer_to_address::0
533f:ADDRESS_TO_POINTER:void:address_to_pointer:struct type *type, void *buf, CORE_ADDR addr:type, buf, addr:::unsigned_address_to_pointer::0
534F:INTEGER_TO_ADDRESS:CORE_ADDR:integer_to_address:struct type *type, void *buf:type, buf
4478b372 535#
57010b1c 536F:DEPRECATED_POP_FRAME:void:deprecated_pop_frame:void:-
4183d812 537# NOTE: cagney/2003-03-24: Replaced by PUSH_ARGUMENTS.
57010b1c 538F:DEPRECATED_STORE_STRUCT_RETURN:void:deprecated_store_struct_return:CORE_ADDR addr, CORE_ADDR sp:addr, sp
92ad9cd9
AC
539
540# It has been suggested that this, well actually its predecessor,
541# should take the type/value of the function to be called and not the
542# return type. This is left as an exercise for the reader.
543
750eb019
AC
544# NOTE: cagney/2004-06-13: The function stack.c:return_command uses
545# the predicate with default hack to avoid calling STORE_RETURN_VALUE
546# (via legacy_return_value), when a small struct is involved.
547
66d659b1 548M::enum return_value_convention:return_value:struct type *valtype, struct regcache *regcache, void *readbuf, const void *writebuf:valtype, regcache, readbuf, writebuf:::legacy_return_value
92ad9cd9 549
b5622e8d
AC
550# The deprecated methods EXTRACT_RETURN_VALUE, STORE_RETURN_VALUE,
551# DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS and
552# DEPRECATED_USE_STRUCT_CONVENTION have all been folded into
553# RETURN_VALUE.
92ad9cd9 554
57010b1c
AC
555f:EXTRACT_RETURN_VALUE:void:extract_return_value:struct type *type, struct regcache *regcache, void *valbuf:type, regcache, valbuf:::legacy_extract_return_value::0
556f:STORE_RETURN_VALUE:void:store_return_value:struct type *type, struct regcache *regcache, const void *valbuf:type, regcache, valbuf:::legacy_store_return_value::0
557f:DEPRECATED_EXTRACT_RETURN_VALUE:void:deprecated_extract_return_value:struct type *type, char *regbuf, char *valbuf:type, regbuf, valbuf
558f:DEPRECATED_STORE_RETURN_VALUE:void:deprecated_store_return_value:struct type *type, char *valbuf:type, valbuf
b5622e8d 559f:DEPRECATED_USE_STRUCT_CONVENTION:int:deprecated_use_struct_convention:int gcc_p, struct type *value_type:gcc_p, value_type:::generic_use_struct_convention::0
92ad9cd9 560
74055713
AC
561# As of 2004-01-17 only the 32-bit SPARC ABI has been identified as an
562# ABI suitable for the implementation of a robust extract
563# struct-convention return-value address method (the sparc saves the
564# address in the callers frame). All the other cases so far examined,
565# the DEPRECATED_EXTRACT_STRUCT_VALUE implementation has been
566# erreneous - the code was incorrectly assuming that the return-value
567# address, stored in a register, was preserved across the entire
568# function call.
569
570# For the moment retain DEPRECATED_EXTRACT_STRUCT_VALUE as a marker of
571# the ABIs that are still to be analyzed - perhaps this should simply
572# be deleted. The commented out extract_returned_value_address method
573# is provided as a starting point for the 32-bit SPARC. It, or
574# something like it, along with changes to both infcmd.c and stack.c
575# will be needed for that case to work. NB: It is passed the callers
576# frame since it is only after the callee has returned that this
577# function is used.
578
57010b1c
AC
579#M::CORE_ADDR:extract_returned_value_address:struct frame_info *caller_frame:caller_frame
580F:DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS:CORE_ADDR:deprecated_extract_struct_value_address:struct regcache *regcache:regcache
74055713 581
57010b1c
AC
582F:DEPRECATED_FRAME_INIT_SAVED_REGS:void:deprecated_frame_init_saved_regs:struct frame_info *frame:frame
583F:DEPRECATED_INIT_EXTRA_FRAME_INFO:void:deprecated_init_extra_frame_info:int fromleaf, struct frame_info *frame:fromleaf, frame
104c1213 584#
57010b1c
AC
585f:SKIP_PROLOGUE:CORE_ADDR:skip_prologue:CORE_ADDR ip:ip::0:0
586f:INNER_THAN:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs::0:0
587f:BREAKPOINT_FROM_PC:const unsigned char *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr:::0:
588M:ADJUST_BREAKPOINT_ADDRESS:CORE_ADDR:adjust_breakpoint_address:CORE_ADDR bpaddr:bpaddr
589f:MEMORY_INSERT_BREAKPOINT:int:memory_insert_breakpoint:CORE_ADDR addr, char *contents_cache:addr, contents_cache::0:default_memory_insert_breakpoint::0
590f:MEMORY_REMOVE_BREAKPOINT:int:memory_remove_breakpoint:CORE_ADDR addr, char *contents_cache:addr, contents_cache::0:default_memory_remove_breakpoint::0
591v:DECR_PC_AFTER_BREAK:CORE_ADDR:decr_pc_after_break::::0:::0
782263ab
AC
592
593# A function can be addressed by either it's "pointer" (possibly a
594# descriptor address) or "entry point" (first executable instruction).
595# The method "convert_from_func_ptr_addr" converting the former to the
596# latter. DEPRECATED_FUNCTION_START_OFFSET is being used to implement
597# a simplified subset of that functionality - the function's address
598# corresponds to the "function pointer" and the function's start
599# corresponds to the "function entry point" - and hence is redundant.
600
601v:DEPRECATED_FUNCTION_START_OFFSET:CORE_ADDR:deprecated_function_start_offset::::0:::0
602
57010b1c 603m:REMOTE_TRANSLATE_XFER_ADDRESS:void:remote_translate_xfer_address:struct regcache *regcache, CORE_ADDR gdb_addr, int gdb_len, CORE_ADDR *rem_addr, int *rem_len:regcache, gdb_addr, gdb_len, rem_addr, rem_len:::generic_remote_translate_xfer_address::0
104c1213 604#
57010b1c 605v:FRAME_ARGS_SKIP:CORE_ADDR:frame_args_skip::::0:::0
19772a2c
AC
606# DEPRECATED_FRAMELESS_FUNCTION_INVOCATION is not needed. The new
607# frame code works regardless of the type of frame - frameless,
608# stackless, or normal.
57010b1c
AC
609F:DEPRECATED_FRAMELESS_FUNCTION_INVOCATION:int:deprecated_frameless_function_invocation:struct frame_info *fi:fi
610F:DEPRECATED_FRAME_CHAIN:CORE_ADDR:deprecated_frame_chain:struct frame_info *frame:frame
611F:DEPRECATED_FRAME_CHAIN_VALID:int:deprecated_frame_chain_valid:CORE_ADDR chain, struct frame_info *thisframe:chain, thisframe
8bedc050
AC
612# DEPRECATED_FRAME_SAVED_PC has been replaced by UNWIND_PC. Please
613# note, per UNWIND_PC's doco, that while the two have similar
614# interfaces they have very different underlying implementations.
57010b1c
AC
615F:DEPRECATED_FRAME_SAVED_PC:CORE_ADDR:deprecated_frame_saved_pc:struct frame_info *fi:fi
616M:UNWIND_PC:CORE_ADDR:unwind_pc:struct frame_info *next_frame:next_frame
617M:UNWIND_SP:CORE_ADDR:unwind_sp:struct frame_info *next_frame:next_frame
42efa47a
AC
618# DEPRECATED_FRAME_ARGS_ADDRESS as been replaced by the per-frame
619# frame-base. Enable frame-base before frame-unwind.
57010b1c 620F:DEPRECATED_FRAME_ARGS_ADDRESS:CORE_ADDR:deprecated_frame_args_address:struct frame_info *fi:fi::get_frame_base:get_frame_base
42efa47a
AC
621# DEPRECATED_FRAME_LOCALS_ADDRESS as been replaced by the per-frame
622# frame-base. Enable frame-base before frame-unwind.
57010b1c
AC
623F:DEPRECATED_FRAME_LOCALS_ADDRESS:CORE_ADDR:deprecated_frame_locals_address:struct frame_info *fi:fi::get_frame_base:get_frame_base
624F:DEPRECATED_SAVED_PC_AFTER_CALL:CORE_ADDR:deprecated_saved_pc_after_call:struct frame_info *frame:frame
625F:FRAME_NUM_ARGS:int:frame_num_args:struct frame_info *frame:frame
104c1213 626#
f27dd7fd
AC
627# DEPRECATED_STACK_ALIGN has been replaced by an initial aligning call
628# to frame_align and the requirement that methods such as
629# push_dummy_call and frame_red_zone_size maintain correct stack/frame
630# alignment.
57010b1c
AC
631F:DEPRECATED_STACK_ALIGN:CORE_ADDR:deprecated_stack_align:CORE_ADDR sp:sp
632M::CORE_ADDR:frame_align:CORE_ADDR address:address
192cb3d4
MK
633# DEPRECATED_REG_STRUCT_HAS_ADDR has been replaced by
634# stabs_argument_has_addr.
57010b1c
AC
635F:DEPRECATED_REG_STRUCT_HAS_ADDR:int:deprecated_reg_struct_has_addr:int gcc_p, struct type *type:gcc_p, type
636m::int:stabs_argument_has_addr:struct type *type:type:::default_stabs_argument_has_addr::0
637v:FRAME_RED_ZONE_SIZE:int:frame_red_zone_size
f0d4cc9e 638#
57010b1c
AC
639v:TARGET_FLOAT_FORMAT:const struct floatformat *:float_format::::::default_float_format (current_gdbarch)::%s:(TARGET_FLOAT_FORMAT)->name
640v:TARGET_DOUBLE_FORMAT:const struct floatformat *:double_format::::::default_double_format (current_gdbarch)::%s:(TARGET_DOUBLE_FORMAT)->name
641v:TARGET_LONG_DOUBLE_FORMAT:const struct floatformat *:long_double_format::::::default_double_format (current_gdbarch)::%s:(TARGET_LONG_DOUBLE_FORMAT)->name
642m::CORE_ADDR:convert_from_func_ptr_addr:CORE_ADDR addr, struct target_ops *targ:addr, targ:::convert_from_func_ptr_addr_identity::0
875e1767
AC
643# On some machines there are bits in addresses which are not really
644# part of the address, but are used by the kernel, the hardware, etc.
645# for special purposes. ADDR_BITS_REMOVE takes out any such bits so
646# we get a "real" address such as one would find in a symbol table.
647# This is used only for addresses of instructions, and even then I'm
648# not sure it's used in all contexts. It exists to deal with there
649# being a few stray bits in the PC which would mislead us, not as some
650# sort of generic thing to handle alignment or segmentation (it's
651# possible it should be in TARGET_READ_PC instead).
57010b1c 652f:ADDR_BITS_REMOVE:CORE_ADDR:addr_bits_remove:CORE_ADDR addr:addr:::core_addr_identity::0
f6214256 653# It is not at all clear why SMASH_TEXT_ADDRESS is not folded into
181c1381 654# ADDR_BITS_REMOVE.
57010b1c 655f:SMASH_TEXT_ADDRESS:CORE_ADDR:smash_text_address:CORE_ADDR addr:addr:::core_addr_identity::0
64c4637f
AC
656# FIXME/cagney/2001-01-18: This should be split in two. A target method that indicates if
657# the target needs software single step. An ISA method to implement it.
658#
659# FIXME/cagney/2001-01-18: This should be replaced with something that inserts breakpoints
660# using the breakpoint system instead of blatting memory directly (as with rs6000).
661#
662# FIXME/cagney/2001-01-18: The logic is backwards. It should be asking if the target can
663# single step. If not, then implement single step using breakpoints.
57010b1c 664F:SOFTWARE_SINGLE_STEP:void:software_single_step:enum target_signal sig, int insert_breakpoints_p:sig, insert_breakpoints_p
f6c40618
AC
665# FIXME: cagney/2003-08-28: Need to find a better way of selecting the
666# disassembler. Perhaphs objdump can handle it?
57010b1c
AC
667f:TARGET_PRINT_INSN:int:print_insn:bfd_vma vma, struct disassemble_info *info:vma, info:::0:
668f:SKIP_TRAMPOLINE_CODE:CORE_ADDR:skip_trampoline_code:CORE_ADDR pc:pc:::generic_skip_trampoline_code::0
d50355b6
MS
669
670
dea0c52f
MK
671# If IN_SOLIB_DYNSYM_RESOLVE_CODE returns true, and SKIP_SOLIB_RESOLVER
672# evaluates non-zero, this is the address where the debugger will place
673# a step-resume breakpoint to get us past the dynamic linker.
57010b1c 674m:SKIP_SOLIB_RESOLVER:CORE_ADDR:skip_solib_resolver:CORE_ADDR pc:pc:::generic_skip_solib_resolver::0
68e9cc94
CV
675# For SVR4 shared libraries, each call goes through a small piece of
676# trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
d50355b6 677# to nonzero if we are currently stopped in one of these.
57010b1c 678f:IN_SOLIB_CALL_TRAMPOLINE:int:in_solib_call_trampoline:CORE_ADDR pc, char *name:pc, name:::generic_in_solib_call_trampoline::0
d50355b6
MS
679
680# Some systems also have trampoline code for returning from shared libs.
57010b1c 681f:IN_SOLIB_RETURN_TRAMPOLINE:int:in_solib_return_trampoline:CORE_ADDR pc, char *name:pc, name:::generic_in_solib_return_trampoline::0
d50355b6 682
c12260ac
CV
683# A target might have problems with watchpoints as soon as the stack
684# frame of the current function has been destroyed. This mostly happens
685# as the first action in a funtion's epilogue. in_function_epilogue_p()
686# is defined to return a non-zero value if either the given addr is one
687# instruction after the stack destroying instruction up to the trailing
688# return instruction or if we can figure out that the stack frame has
689# already been invalidated regardless of the value of addr. Targets
690# which don't suffer from that problem could just let this functionality
691# untouched.
57010b1c 692m::int:in_function_epilogue_p:CORE_ADDR addr:addr::0:generic_in_function_epilogue_p::0
552c04a7
TT
693# Given a vector of command-line arguments, return a newly allocated
694# string which, when passed to the create_inferior function, will be
695# parsed (on Unix systems, by the shell) to yield the same vector.
696# This function should call error() if the argument vector is not
697# representable for this target or if this target does not support
698# command-line arguments.
699# ARGC is the number of elements in the vector.
700# ARGV is an array of strings, one per argument.
57010b1c
AC
701m:CONSTRUCT_INFERIOR_ARGUMENTS:char *:construct_inferior_arguments:int argc, char **argv:argc, argv:::construct_inferior_arguments::0
702f:ELF_MAKE_MSYMBOL_SPECIAL:void:elf_make_msymbol_special:asymbol *sym, struct minimal_symbol *msym:sym, msym:::default_elf_make_msymbol_special::0
703f:COFF_MAKE_MSYMBOL_SPECIAL:void:coff_make_msymbol_special:int val, struct minimal_symbol *msym:val, msym:::default_coff_make_msymbol_special::0
704v:NAME_OF_MALLOC:const char *:name_of_malloc::::"malloc":"malloc"::0:%s:NAME_OF_MALLOC
705v:CANNOT_STEP_BREAKPOINT:int:cannot_step_breakpoint::::0:0::0
706v:HAVE_NONSTEPPABLE_WATCHPOINT:int:have_nonsteppable_watchpoint::::0:0::0
707F:ADDRESS_CLASS_TYPE_FLAGS:int:address_class_type_flags:int byte_size, int dwarf2_addr_class:byte_size, dwarf2_addr_class
708M:ADDRESS_CLASS_TYPE_FLAGS_TO_NAME:const char *:address_class_type_flags_to_name:int type_flags:type_flags
709M:ADDRESS_CLASS_NAME_TO_TYPE_FLAGS:int:address_class_name_to_type_flags:const char *name, int *type_flags_ptr:name, type_flags_ptr
b59ff9d5 710# Is a register in a group
57010b1c 711m::int:register_reggroup_p:int regnum, struct reggroup *reggroup:regnum, reggroup:::default_register_reggroup_p::0
f6214256 712# Fetch the pointer to the ith function argument.
57010b1c 713F:FETCH_POINTER_ARGUMENT:CORE_ADDR:fetch_pointer_argument:struct frame_info *frame, int argi, struct type *type:frame, argi, type
6ce6d90f
MK
714
715# Return the appropriate register set for a core file section with
716# name SECT_NAME and size SECT_SIZE.
57010b1c 717M::const struct regset *:regset_from_core_section:const char *sect_name, size_t sect_size:sect_name, sect_size
104c1213 718EOF
104c1213
JM
719}
720
0b8f9e4d
AC
721#
722# The .log file
723#
724exec > new-gdbarch.log
34620563 725function_list | while do_read
0b8f9e4d
AC
726do
727 cat <<EOF
66d659b1 728${class} ${returntype} ${function} ($formal)${attrib}
104c1213 729EOF
3d9a5942
AC
730 for r in ${read}
731 do
732 eval echo \"\ \ \ \ ${r}=\${${r}}\"
733 done
f0d4cc9e 734 if class_is_predicate_p && fallback_default_p
0b8f9e4d 735 then
66d659b1 736 echo "Error: predicate function ${function} can not have a non- multi-arch default" 1>&2
0b8f9e4d
AC
737 kill $$
738 exit 1
739 fi
72e74a21 740 if [ "x${invalid_p}" = "x0" -a -n "${postdefault}" ]
f0d4cc9e
AC
741 then
742 echo "Error: postdefault is useless when invalid_p=0" 1>&2
743 kill $$
744 exit 1
745 fi
a72293e2
AC
746 if class_is_multiarch_p
747 then
748 if class_is_predicate_p ; then :
749 elif test "x${predefault}" = "x"
750 then
751 echo "Error: pure multi-arch function must have a predefault" 1>&2
752 kill $$
753 exit 1
754 fi
755 fi
3d9a5942 756 echo ""
0b8f9e4d
AC
757done
758
759exec 1>&2
760compare_new gdbarch.log
761
104c1213
JM
762
763copyright ()
764{
765cat <<EOF
59233f88
AC
766/* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
767
104c1213 768/* Dynamic architecture support for GDB, the GNU debugger.
79d45cd4
AC
769
770 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
771 Software Foundation, Inc.
104c1213
JM
772
773 This file is part of GDB.
774
775 This program is free software; you can redistribute it and/or modify
776 it under the terms of the GNU General Public License as published by
777 the Free Software Foundation; either version 2 of the License, or
778 (at your option) any later version.
779
780 This program is distributed in the hope that it will be useful,
781 but WITHOUT ANY WARRANTY; without even the implied warranty of
782 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
783 GNU General Public License for more details.
784
785 You should have received a copy of the GNU General Public License
786 along with this program; if not, write to the Free Software
787 Foundation, Inc., 59 Temple Place - Suite 330,
788 Boston, MA 02111-1307, USA. */
789
104c1213
JM
790/* This file was created with the aid of \`\`gdbarch.sh''.
791
52204a0b 792 The Bourne shell script \`\`gdbarch.sh'' creates the files
104c1213
JM
793 \`\`new-gdbarch.c'' and \`\`new-gdbarch.h and then compares them
794 against the existing \`\`gdbarch.[hc]''. Any differences found
795 being reported.
796
797 If editing this file, please also run gdbarch.sh and merge any
52204a0b 798 changes into that script. Conversely, when making sweeping changes
104c1213
JM
799 to this file, modifying gdbarch.sh and using its output may prove
800 easier. */
801
802EOF
803}
804
805#
806# The .h file
807#
808
809exec > new-gdbarch.h
810copyright
811cat <<EOF
812#ifndef GDBARCH_H
813#define GDBARCH_H
814
da3331ec
AC
815struct floatformat;
816struct ui_file;
104c1213
JM
817struct frame_info;
818struct value;
b6af0555 819struct objfile;
a2cf933a 820struct minimal_symbol;
049ee0e4 821struct regcache;
b59ff9d5 822struct reggroup;
6ce6d90f 823struct regset;
a89aa300 824struct disassemble_info;
e2d0e7eb 825struct target_ops;
030f20e1 826struct obstack;
104c1213 827
104c1213
JM
828extern struct gdbarch *current_gdbarch;
829
104c1213
JM
830/* If any of the following are defined, the target wasn't correctly
831 converted. */
832
83905903
AC
833#if (GDB_MULTI_ARCH >= GDB_MULTI_ARCH_PURE) && defined (GDB_TM_FILE)
834#error "GDB_TM_FILE: Pure multi-arch targets do not have a tm.h file."
835#endif
104c1213
JM
836EOF
837
838# function typedef's
3d9a5942
AC
839printf "\n"
840printf "\n"
841printf "/* The following are pre-initialized by GDBARCH. */\n"
34620563 842function_list | while do_read
104c1213 843do
2ada493a
AC
844 if class_is_info_p
845 then
3d9a5942
AC
846 printf "\n"
847 printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
848 printf "/* set_gdbarch_${function}() - not applicable - pre-initialized. */\n"
57010b1c 849 printf "#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (${macro})\n"
83905903
AC
850 printf "#error \"Non multi-arch definition of ${macro}\"\n"
851 printf "#endif\n"
c25083af 852 printf "#if !defined (${macro})\n"
3d9a5942
AC
853 printf "#define ${macro} (gdbarch_${function} (current_gdbarch))\n"
854 printf "#endif\n"
2ada493a 855 fi
104c1213
JM
856done
857
858# function typedef's
3d9a5942
AC
859printf "\n"
860printf "\n"
861printf "/* The following are initialized by the target dependent code. */\n"
34620563 862function_list | while do_read
104c1213 863do
72e74a21 864 if [ -n "${comment}" ]
34620563
AC
865 then
866 echo "${comment}" | sed \
867 -e '2 s,#,/*,' \
868 -e '3,$ s,#, ,' \
869 -e '$ s,$, */,'
870 fi
b77be6cf 871 if class_is_multiarch_p
2ada493a 872 then
b77be6cf
AC
873 if class_is_predicate_p
874 then
875 printf "\n"
876 printf "extern int gdbarch_${function}_p (struct gdbarch *gdbarch);\n"
877 fi
878 else
879 if class_is_predicate_p
880 then
881 printf "\n"
882 printf "#if defined (${macro})\n"
883 printf "/* Legacy for systems yet to multi-arch ${macro} */\n"
884 #printf "#if (GDB_MULTI_ARCH <= GDB_MULTI_ARCH_PARTIAL) && defined (${macro})\n"
eee30e78 885 printf "#if !defined (${macro}_P)\n"
b77be6cf
AC
886 printf "#define ${macro}_P() (1)\n"
887 printf "#endif\n"
eee30e78 888 printf "#endif\n"
b77be6cf 889 printf "\n"
b77be6cf 890 printf "extern int gdbarch_${function}_p (struct gdbarch *gdbarch);\n"
57010b1c 891 printf "#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (${macro}_P)\n"
83905903
AC
892 printf "#error \"Non multi-arch definition of ${macro}\"\n"
893 printf "#endif\n"
bceabdd8 894 printf "#if !defined (${macro}_P)\n"
b77be6cf
AC
895 printf "#define ${macro}_P() (gdbarch_${function}_p (current_gdbarch))\n"
896 printf "#endif\n"
897 fi
4a5c6a1d 898 fi
2ada493a
AC
899 if class_is_variable_p
900 then
3d9a5942
AC
901 printf "\n"
902 printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
903 printf "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, ${returntype} ${function});\n"
57010b1c 904 printf "#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (${macro})\n"
83905903
AC
905 printf "#error \"Non multi-arch definition of ${macro}\"\n"
906 printf "#endif\n"
c25083af
AC
907 printf "#if !defined (${macro})\n"
908 printf "#define ${macro} (gdbarch_${function} (current_gdbarch))\n"
909 printf "#endif\n"
2ada493a
AC
910 fi
911 if class_is_function_p
912 then
3d9a5942 913 printf "\n"
72e74a21 914 if [ "x${formal}" = "xvoid" ] && class_is_multiarch_p
4a5c6a1d
AC
915 then
916 printf "typedef ${returntype} (gdbarch_${function}_ftype) (struct gdbarch *gdbarch);\n"
917 elif class_is_multiarch_p
918 then
919 printf "typedef ${returntype} (gdbarch_${function}_ftype) (struct gdbarch *gdbarch, ${formal});\n"
920 else
921 printf "typedef ${returntype} (gdbarch_${function}_ftype) (${formal});\n"
922 fi
72e74a21 923 if [ "x${formal}" = "xvoid" ]
104c1213 924 then
3d9a5942 925 printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
104c1213 926 else
3d9a5942 927 printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch, ${formal});\n"
104c1213 928 fi
3d9a5942 929 printf "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, gdbarch_${function}_ftype *${function});\n"
b77be6cf
AC
930 if class_is_multiarch_p ; then :
931 else
57010b1c 932 printf "#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (${macro})\n"
83905903
AC
933 printf "#error \"Non multi-arch definition of ${macro}\"\n"
934 printf "#endif\n"
c25083af
AC
935 if [ "x${actual}" = "x" ]
936 then
937 d="#define ${macro}() (gdbarch_${function} (current_gdbarch))"
938 elif [ "x${actual}" = "x-" ]
939 then
940 d="#define ${macro} (gdbarch_${function} (current_gdbarch))"
941 else
942 d="#define ${macro}(${actual}) (gdbarch_${function} (current_gdbarch, ${actual}))"
943 fi
944 printf "#if !defined (${macro})\n"
72e74a21 945 if [ "x${actual}" = "x" ]
4a5c6a1d
AC
946 then
947 printf "#define ${macro}() (gdbarch_${function} (current_gdbarch))\n"
72e74a21 948 elif [ "x${actual}" = "x-" ]
4a5c6a1d
AC
949 then
950 printf "#define ${macro} (gdbarch_${function} (current_gdbarch))\n"
951 else
952 printf "#define ${macro}(${actual}) (gdbarch_${function} (current_gdbarch, ${actual}))\n"
953 fi
954 printf "#endif\n"
104c1213 955 fi
2ada493a 956 fi
104c1213
JM
957done
958
959# close it off
960cat <<EOF
961
962extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
963
964
965/* Mechanism for co-ordinating the selection of a specific
966 architecture.
967
968 GDB targets (*-tdep.c) can register an interest in a specific
969 architecture. Other GDB components can register a need to maintain
970 per-architecture data.
971
972 The mechanisms below ensures that there is only a loose connection
973 between the set-architecture command and the various GDB
0fa6923a 974 components. Each component can independently register their need
104c1213
JM
975 to maintain architecture specific data with gdbarch.
976
977 Pragmatics:
978
979 Previously, a single TARGET_ARCHITECTURE_HOOK was provided. It
980 didn't scale.
981
982 The more traditional mega-struct containing architecture specific
983 data for all the various GDB components was also considered. Since
0fa6923a 984 GDB is built from a variable number of (fairly independent)
104c1213
JM
985 components it was determined that the global aproach was not
986 applicable. */
987
988
989/* Register a new architectural family with GDB.
990
991 Register support for the specified ARCHITECTURE with GDB. When
992 gdbarch determines that the specified architecture has been
993 selected, the corresponding INIT function is called.
994
995 --
996
997 The INIT function takes two parameters: INFO which contains the
998 information available to gdbarch about the (possibly new)
999 architecture; ARCHES which is a list of the previously created
1000 \`\`struct gdbarch'' for this architecture.
1001
0f79675b
AC
1002 The INFO parameter is, as far as possible, be pre-initialized with
1003 information obtained from INFO.ABFD or the previously selected
1004 architecture.
1005
1006 The ARCHES parameter is a linked list (sorted most recently used)
1007 of all the previously created architures for this architecture
1008 family. The (possibly NULL) ARCHES->gdbarch can used to access
1009 values from the previously selected architecture for this
1010 architecture family. The global \`\`current_gdbarch'' shall not be
1011 used.
104c1213
JM
1012
1013 The INIT function shall return any of: NULL - indicating that it
ec3d358c 1014 doesn't recognize the selected architecture; an existing \`\`struct
104c1213
JM
1015 gdbarch'' from the ARCHES list - indicating that the new
1016 architecture is just a synonym for an earlier architecture (see
1017 gdbarch_list_lookup_by_info()); a newly created \`\`struct gdbarch''
4b9b3959
AC
1018 - that describes the selected architecture (see gdbarch_alloc()).
1019
1020 The DUMP_TDEP function shall print out all target specific values.
1021 Care should be taken to ensure that the function works in both the
1022 multi-arch and non- multi-arch cases. */
104c1213
JM
1023
1024struct gdbarch_list
1025{
1026 struct gdbarch *gdbarch;
1027 struct gdbarch_list *next;
1028};
1029
1030struct gdbarch_info
1031{
104c1213
JM
1032 /* Use default: NULL (ZERO). */
1033 const struct bfd_arch_info *bfd_arch_info;
1034
428721aa 1035 /* Use default: BFD_ENDIAN_UNKNOWN (NB: is not ZERO). */
104c1213
JM
1036 int byte_order;
1037
1038 /* Use default: NULL (ZERO). */
1039 bfd *abfd;
1040
1041 /* Use default: NULL (ZERO). */
1042 struct gdbarch_tdep_info *tdep_info;
4be87837
DJ
1043
1044 /* Use default: GDB_OSABI_UNINITIALIZED (-1). */
1045 enum gdb_osabi osabi;
104c1213
JM
1046};
1047
1048typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
4b9b3959 1049typedef void (gdbarch_dump_tdep_ftype) (struct gdbarch *gdbarch, struct ui_file *file);
104c1213 1050
4b9b3959 1051/* DEPRECATED - use gdbarch_register() */
104c1213
JM
1052extern void register_gdbarch_init (enum bfd_architecture architecture, gdbarch_init_ftype *);
1053
4b9b3959
AC
1054extern void gdbarch_register (enum bfd_architecture architecture,
1055 gdbarch_init_ftype *,
1056 gdbarch_dump_tdep_ftype *);
1057
104c1213 1058
b4a20239
AC
1059/* Return a freshly allocated, NULL terminated, array of the valid
1060 architecture names. Since architectures are registered during the
1061 _initialize phase this function only returns useful information
1062 once initialization has been completed. */
1063
1064extern const char **gdbarch_printable_names (void);
1065
1066
104c1213
JM
1067/* Helper function. Search the list of ARCHES for a GDBARCH that
1068 matches the information provided by INFO. */
1069
1070extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *arches, const struct gdbarch_info *info);
1071
1072
1073/* Helper function. Create a preliminary \`\`struct gdbarch''. Perform
1074 basic initialization using values obtained from the INFO andTDEP
1075 parameters. set_gdbarch_*() functions are called to complete the
1076 initialization of the object. */
1077
1078extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep *tdep);
1079
1080
4b9b3959
AC
1081/* Helper function. Free a partially-constructed \`\`struct gdbarch''.
1082 It is assumed that the caller freeds the \`\`struct
1083 gdbarch_tdep''. */
1084
058f20d5
JB
1085extern void gdbarch_free (struct gdbarch *);
1086
1087
aebd7893
AC
1088/* Helper function. Allocate memory from the \`\`struct gdbarch''
1089 obstack. The memory is freed when the corresponding architecture
1090 is also freed. */
1091
1092extern void *gdbarch_obstack_zalloc (struct gdbarch *gdbarch, long size);
1093#define GDBARCH_OBSTACK_CALLOC(GDBARCH, NR, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), (NR) * sizeof (TYPE)))
1094#define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE) ((TYPE *) gdbarch_obstack_zalloc ((GDBARCH), sizeof (TYPE)))
1095
1096
b732d07d 1097/* Helper function. Force an update of the current architecture.
104c1213 1098
b732d07d
AC
1099 The actual architecture selected is determined by INFO, \`\`(gdb) set
1100 architecture'' et.al., the existing architecture and BFD's default
1101 architecture. INFO should be initialized to zero and then selected
1102 fields should be updated.
104c1213 1103
16f33e29
AC
1104 Returns non-zero if the update succeeds */
1105
1106extern int gdbarch_update_p (struct gdbarch_info info);
104c1213
JM
1107
1108
ebdba546
AC
1109/* Helper function. Find an architecture matching info.
1110
1111 INFO should be initialized using gdbarch_info_init, relevant fields
1112 set, and then finished using gdbarch_info_fill.
1113
1114 Returns the corresponding architecture, or NULL if no matching
1115 architecture was found. "current_gdbarch" is not updated. */
1116
1117extern struct gdbarch *gdbarch_find_by_info (struct gdbarch_info info);
1118
1119
1120/* Helper function. Set the global "current_gdbarch" to "gdbarch".
1121
1122 FIXME: kettenis/20031124: Of the functions that follow, only
1123 gdbarch_from_bfd is supposed to survive. The others will
1124 dissappear since in the future GDB will (hopefully) be truly
1125 multi-arch. However, for now we're still stuck with the concept of
1126 a single active architecture. */
1127
1128extern void deprecated_current_gdbarch_select_hack (struct gdbarch *gdbarch);
1129
104c1213
JM
1130
1131/* Register per-architecture data-pointer.
1132
1133 Reserve space for a per-architecture data-pointer. An identifier
1134 for the reserved data-pointer is returned. That identifer should
95160752 1135 be saved in a local static variable.
104c1213 1136
fcc1c85c
AC
1137 Memory for the per-architecture data shall be allocated using
1138 gdbarch_obstack_zalloc. That memory will be deleted when the
1139 corresponding architecture object is deleted.
104c1213 1140
95160752
AC
1141 When a previously created architecture is re-selected, the
1142 per-architecture data-pointer for that previous architecture is
76860b5f 1143 restored. INIT() is not re-called.
104c1213
JM
1144
1145 Multiple registrarants for any architecture are allowed (and
1146 strongly encouraged). */
1147
95160752 1148struct gdbarch_data;
104c1213 1149
030f20e1
AC
1150typedef void *(gdbarch_data_pre_init_ftype) (struct obstack *obstack);
1151extern struct gdbarch_data *gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *init);
1152typedef void *(gdbarch_data_post_init_ftype) (struct gdbarch *gdbarch);
1153extern struct gdbarch_data *gdbarch_data_register_post_init (gdbarch_data_post_init_ftype *init);
1154extern void deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
1155 struct gdbarch_data *data,
1156 void *pointer);
104c1213 1157
451fbdda 1158extern void *gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *);
104c1213
JM
1159
1160
a8cf2722 1161
104c1213
JM
1162/* Register per-architecture memory region.
1163
1164 Provide a memory-region swap mechanism. Per-architecture memory
1165 region are created. These memory regions are swapped whenever the
1166 architecture is changed. For a new architecture, the memory region
1167 is initialized with zero (0) and the INIT function is called.
1168
1169 Memory regions are swapped / initialized in the order that they are
1170 registered. NULL DATA and/or INIT values can be specified.
1171
030f20e1 1172 New code should use gdbarch_data_register_*(). */
104c1213
JM
1173
1174typedef void (gdbarch_swap_ftype) (void);
046a4708
AC
1175extern void deprecated_register_gdbarch_swap (void *data, unsigned long size, gdbarch_swap_ftype *init);
1176#define DEPRECATED_REGISTER_GDBARCH_SWAP(VAR) deprecated_register_gdbarch_swap (&(VAR), sizeof ((VAR)), NULL)
104c1213
JM
1177
1178
1179
0fa6923a 1180/* Set the dynamic target-system-dependent parameters (architecture,
104c1213
JM
1181 byte-order, ...) using information found in the BFD */
1182
1183extern void set_gdbarch_from_file (bfd *);
1184
1185
e514a9d6
JM
1186/* Initialize the current architecture to the "first" one we find on
1187 our list. */
1188
1189extern void initialize_current_architecture (void);
1190
104c1213
JM
1191/* gdbarch trace variable */
1192extern int gdbarch_debug;
1193
4b9b3959 1194extern void gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file);
104c1213
JM
1195
1196#endif
1197EOF
1198exec 1>&2
1199#../move-if-change new-gdbarch.h gdbarch.h
59233f88 1200compare_new gdbarch.h
104c1213
JM
1201
1202
1203#
1204# C file
1205#
1206
1207exec > new-gdbarch.c
1208copyright
1209cat <<EOF
1210
1211#include "defs.h"
7355ddba 1212#include "arch-utils.h"
104c1213 1213
104c1213
JM
1214#include "gdbcmd.h"
1215#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
104c1213
JM
1216#include "symcat.h"
1217
f0d4cc9e 1218#include "floatformat.h"
104c1213 1219
95160752 1220#include "gdb_assert.h"
b66d6d2e 1221#include "gdb_string.h"
67c2c32c 1222#include "gdb-events.h"
b59ff9d5 1223#include "reggroups.h"
4be87837 1224#include "osabi.h"
aebd7893 1225#include "gdb_obstack.h"
95160752 1226
104c1213
JM
1227/* Static function declarations */
1228
b3cc3077 1229static void alloc_gdbarch_data (struct gdbarch *);
104c1213 1230
104c1213
JM
1231/* Non-zero if we want to trace architecture code. */
1232
1233#ifndef GDBARCH_DEBUG
1234#define GDBARCH_DEBUG 0
1235#endif
1236int gdbarch_debug = GDBARCH_DEBUG;
1237
1238EOF
1239
1240# gdbarch open the gdbarch object
3d9a5942
AC
1241printf "\n"
1242printf "/* Maintain the struct gdbarch object */\n"
1243printf "\n"
1244printf "struct gdbarch\n"
1245printf "{\n"
76860b5f
AC
1246printf " /* Has this architecture been fully initialized? */\n"
1247printf " int initialized_p;\n"
aebd7893
AC
1248printf "\n"
1249printf " /* An obstack bound to the lifetime of the architecture. */\n"
1250printf " struct obstack *obstack;\n"
1251printf "\n"
3d9a5942 1252printf " /* basic architectural information */\n"
34620563 1253function_list | while do_read
104c1213 1254do
2ada493a
AC
1255 if class_is_info_p
1256 then
3d9a5942 1257 printf " ${returntype} ${function};\n"
2ada493a 1258 fi
104c1213 1259done
3d9a5942
AC
1260printf "\n"
1261printf " /* target specific vector. */\n"
1262printf " struct gdbarch_tdep *tdep;\n"
1263printf " gdbarch_dump_tdep_ftype *dump_tdep;\n"
1264printf "\n"
1265printf " /* per-architecture data-pointers */\n"
95160752 1266printf " unsigned nr_data;\n"
3d9a5942
AC
1267printf " void **data;\n"
1268printf "\n"
1269printf " /* per-architecture swap-regions */\n"
1270printf " struct gdbarch_swap *swap;\n"
1271printf "\n"
104c1213
JM
1272cat <<EOF
1273 /* Multi-arch values.
1274
1275 When extending this structure you must:
1276
1277 Add the field below.
1278
1279 Declare set/get functions and define the corresponding
1280 macro in gdbarch.h.
1281
1282 gdbarch_alloc(): If zero/NULL is not a suitable default,
1283 initialize the new field.
1284
1285 verify_gdbarch(): Confirm that the target updated the field
1286 correctly.
1287
7e73cedf 1288 gdbarch_dump(): Add a fprintf_unfiltered call so that the new
104c1213
JM
1289 field is dumped out
1290
c0e8c252 1291 \`\`startup_gdbarch()'': Append an initial value to the static
104c1213
JM
1292 variable (base values on the host's c-type system).
1293
1294 get_gdbarch(): Implement the set/get functions (probably using
1295 the macro's as shortcuts).
1296
1297 */
1298
1299EOF
34620563 1300function_list | while do_read
104c1213 1301do
2ada493a
AC
1302 if class_is_variable_p
1303 then
3d9a5942 1304 printf " ${returntype} ${function};\n"
2ada493a
AC
1305 elif class_is_function_p
1306 then
3d9a5942 1307 printf " gdbarch_${function}_ftype *${function}${attrib};\n"
2ada493a 1308 fi
104c1213 1309done
3d9a5942 1310printf "};\n"
104c1213
JM
1311
1312# A pre-initialized vector
3d9a5942
AC
1313printf "\n"
1314printf "\n"
104c1213
JM
1315cat <<EOF
1316/* The default architecture uses host values (for want of a better
1317 choice). */
1318EOF
3d9a5942
AC
1319printf "\n"
1320printf "extern const struct bfd_arch_info bfd_default_arch_struct;\n"
1321printf "\n"
1322printf "struct gdbarch startup_gdbarch =\n"
1323printf "{\n"
76860b5f 1324printf " 1, /* Always initialized. */\n"
aebd7893 1325printf " NULL, /* The obstack. */\n"
3d9a5942 1326printf " /* basic architecture information */\n"
4b9b3959 1327function_list | while do_read
104c1213 1328do
2ada493a
AC
1329 if class_is_info_p
1330 then
ec5cbaec 1331 printf " ${staticdefault}, /* ${function} */\n"
2ada493a 1332 fi
104c1213
JM
1333done
1334cat <<EOF
4b9b3959
AC
1335 /* target specific vector and its dump routine */
1336 NULL, NULL,
104c1213
JM
1337 /*per-architecture data-pointers and swap regions */
1338 0, NULL, NULL,
1339 /* Multi-arch values */
1340EOF
34620563 1341function_list | while do_read
104c1213 1342do
2ada493a
AC
1343 if class_is_function_p || class_is_variable_p
1344 then
ec5cbaec 1345 printf " ${staticdefault}, /* ${function} */\n"
2ada493a 1346 fi
104c1213
JM
1347done
1348cat <<EOF
c0e8c252 1349 /* startup_gdbarch() */
104c1213 1350};
4b9b3959 1351
c0e8c252 1352struct gdbarch *current_gdbarch = &startup_gdbarch;
104c1213
JM
1353EOF
1354
1355# Create a new gdbarch struct
104c1213 1356cat <<EOF
7de2341d 1357
66b43ecb 1358/* Create a new \`\`struct gdbarch'' based on information provided by
104c1213
JM
1359 \`\`struct gdbarch_info''. */
1360EOF
3d9a5942 1361printf "\n"
104c1213
JM
1362cat <<EOF
1363struct gdbarch *
1364gdbarch_alloc (const struct gdbarch_info *info,
1365 struct gdbarch_tdep *tdep)
1366{
85de9627
AC
1367 /* NOTE: The new architecture variable is named \`\`current_gdbarch''
1368 so that macros such as TARGET_DOUBLE_BIT, when expanded, refer to
1369 the current local architecture and not the previous global
1370 architecture. This ensures that the new architectures initial
1371 values are not influenced by the previous architecture. Once
1372 everything is parameterised with gdbarch, this will go away. */
aebd7893
AC
1373 struct gdbarch *current_gdbarch;
1374
1375 /* Create an obstack for allocating all the per-architecture memory,
1376 then use that to allocate the architecture vector. */
1377 struct obstack *obstack = XMALLOC (struct obstack);
1378 obstack_init (obstack);
1379 current_gdbarch = obstack_alloc (obstack, sizeof (*current_gdbarch));
85de9627 1380 memset (current_gdbarch, 0, sizeof (*current_gdbarch));
aebd7893 1381 current_gdbarch->obstack = obstack;
85de9627
AC
1382
1383 alloc_gdbarch_data (current_gdbarch);
1384
1385 current_gdbarch->tdep = tdep;
104c1213 1386EOF
3d9a5942 1387printf "\n"
34620563 1388function_list | while do_read
104c1213 1389do
2ada493a
AC
1390 if class_is_info_p
1391 then
85de9627 1392 printf " current_gdbarch->${function} = info->${function};\n"
2ada493a 1393 fi
104c1213 1394done
3d9a5942
AC
1395printf "\n"
1396printf " /* Force the explicit initialization of these. */\n"
34620563 1397function_list | while do_read
104c1213 1398do
2ada493a
AC
1399 if class_is_function_p || class_is_variable_p
1400 then
72e74a21 1401 if [ -n "${predefault}" -a "x${predefault}" != "x0" ]
104c1213 1402 then
85de9627 1403 printf " current_gdbarch->${function} = ${predefault};\n"
104c1213 1404 fi
2ada493a 1405 fi
104c1213
JM
1406done
1407cat <<EOF
1408 /* gdbarch_alloc() */
1409
85de9627 1410 return current_gdbarch;
104c1213
JM
1411}
1412EOF
1413
058f20d5 1414# Free a gdbarch struct.
3d9a5942
AC
1415printf "\n"
1416printf "\n"
058f20d5 1417cat <<EOF
aebd7893
AC
1418/* Allocate extra space using the per-architecture obstack. */
1419
1420void *
1421gdbarch_obstack_zalloc (struct gdbarch *arch, long size)
1422{
1423 void *data = obstack_alloc (arch->obstack, size);
1424 memset (data, 0, size);
1425 return data;
1426}
1427
1428
058f20d5
JB
1429/* Free a gdbarch struct. This should never happen in normal
1430 operation --- once you've created a gdbarch, you keep it around.
1431 However, if an architecture's init function encounters an error
1432 building the structure, it may need to clean up a partially
1433 constructed gdbarch. */
4b9b3959 1434
058f20d5
JB
1435void
1436gdbarch_free (struct gdbarch *arch)
1437{
aebd7893 1438 struct obstack *obstack;
95160752 1439 gdb_assert (arch != NULL);
aebd7893
AC
1440 gdb_assert (!arch->initialized_p);
1441 obstack = arch->obstack;
1442 obstack_free (obstack, 0); /* Includes the ARCH. */
1443 xfree (obstack);
058f20d5
JB
1444}
1445EOF
1446
104c1213 1447# verify a new architecture
104c1213 1448cat <<EOF
db446970
AC
1449
1450
1451/* Ensure that all values in a GDBARCH are reasonable. */
1452
1453/* NOTE/WARNING: The parameter is called \`\`current_gdbarch'' so that it
1454 just happens to match the global variable \`\`current_gdbarch''. That
1455 way macros refering to that variable get the local and not the global
1456 version - ulgh. Once everything is parameterised with gdbarch, this
1457 will go away. */
1458
104c1213 1459static void
db446970 1460verify_gdbarch (struct gdbarch *current_gdbarch)
104c1213 1461{
f16a1923
AC
1462 struct ui_file *log;
1463 struct cleanup *cleanups;
1464 long dummy;
1465 char *buf;
f16a1923
AC
1466 log = mem_fileopen ();
1467 cleanups = make_cleanup_ui_file_delete (log);
104c1213 1468 /* fundamental */
db446970 1469 if (current_gdbarch->byte_order == BFD_ENDIAN_UNKNOWN)
f16a1923 1470 fprintf_unfiltered (log, "\n\tbyte-order");
db446970 1471 if (current_gdbarch->bfd_arch_info == NULL)
f16a1923 1472 fprintf_unfiltered (log, "\n\tbfd_arch_info");
104c1213
JM
1473 /* Check those that need to be defined for the given multi-arch level. */
1474EOF
34620563 1475function_list | while do_read
104c1213 1476do
2ada493a
AC
1477 if class_is_function_p || class_is_variable_p
1478 then
72e74a21 1479 if [ "x${invalid_p}" = "x0" ]
c0e8c252 1480 then
3d9a5942 1481 printf " /* Skip verify of ${function}, invalid_p == 0 */\n"
2ada493a
AC
1482 elif class_is_predicate_p
1483 then
3d9a5942 1484 printf " /* Skip verify of ${function}, has predicate */\n"
f0d4cc9e 1485 # FIXME: See do_read for potential simplification
72e74a21 1486 elif [ -n "${invalid_p}" -a -n "${postdefault}" ]
f0d4cc9e 1487 then
3d9a5942 1488 printf " if (${invalid_p})\n"
db446970 1489 printf " current_gdbarch->${function} = ${postdefault};\n"
72e74a21 1490 elif [ -n "${predefault}" -a -n "${postdefault}" ]
f0d4cc9e 1491 then
db446970
AC
1492 printf " if (current_gdbarch->${function} == ${predefault})\n"
1493 printf " current_gdbarch->${function} = ${postdefault};\n"
72e74a21 1494 elif [ -n "${postdefault}" ]
f0d4cc9e 1495 then
db446970
AC
1496 printf " if (current_gdbarch->${function} == 0)\n"
1497 printf " current_gdbarch->${function} = ${postdefault};\n"
72e74a21 1498 elif [ -n "${invalid_p}" ]
104c1213 1499 then
57010b1c 1500 printf " if ((GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL)\n"
3d9a5942 1501 printf " && (${invalid_p}))\n"
f16a1923 1502 printf " fprintf_unfiltered (log, \"\\\\n\\\\t${function}\");\n"
72e74a21 1503 elif [ -n "${predefault}" ]
104c1213 1504 then
57010b1c 1505 printf " if ((GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL)\n"
db446970 1506 printf " && (current_gdbarch->${function} == ${predefault}))\n"
f16a1923 1507 printf " fprintf_unfiltered (log, \"\\\\n\\\\t${function}\");\n"
104c1213 1508 fi
2ada493a 1509 fi
104c1213
JM
1510done
1511cat <<EOF
f16a1923
AC
1512 buf = ui_file_xstrdup (log, &dummy);
1513 make_cleanup (xfree, buf);
1514 if (strlen (buf) > 0)
1515 internal_error (__FILE__, __LINE__,
1516 "verify_gdbarch: the following are invalid ...%s",
1517 buf);
1518 do_cleanups (cleanups);
104c1213
JM
1519}
1520EOF
1521
1522# dump the structure
3d9a5942
AC
1523printf "\n"
1524printf "\n"
104c1213 1525cat <<EOF
4b9b3959
AC
1526/* Print out the details of the current architecture. */
1527
1528/* NOTE/WARNING: The parameter is called \`\`current_gdbarch'' so that it
1529 just happens to match the global variable \`\`current_gdbarch''. That
1530 way macros refering to that variable get the local and not the global
1531 version - ulgh. Once everything is parameterised with gdbarch, this
1532 will go away. */
1533
104c1213 1534void
db446970 1535gdbarch_dump (struct gdbarch *current_gdbarch, struct ui_file *file)
104c1213 1536{
4b9b3959
AC
1537 fprintf_unfiltered (file,
1538 "gdbarch_dump: GDB_MULTI_ARCH = %d\\n",
1539 GDB_MULTI_ARCH);
104c1213 1540EOF
57010b1c 1541function_list | sort -t: -k 2 | while do_read
104c1213 1542do
1e9f55d0
AC
1543 # First the predicate
1544 if class_is_predicate_p
1545 then
1546 if class_is_multiarch_p
1547 then
7996bcec
AC
1548 printf " fprintf_unfiltered (file,\n"
1549 printf " \"gdbarch_dump: gdbarch_${function}_p() = %%d\\\\n\",\n"
1550 printf " gdbarch_${function}_p (current_gdbarch));\n"
1e9f55d0
AC
1551 else
1552 printf "#ifdef ${macro}_P\n"
1553 printf " fprintf_unfiltered (file,\n"
1554 printf " \"gdbarch_dump: %%s # %%s\\\\n\",\n"
1555 printf " \"${macro}_P()\",\n"
1556 printf " XSTRING (${macro}_P ()));\n"
1557 printf " fprintf_unfiltered (file,\n"
1558 printf " \"gdbarch_dump: ${macro}_P() = %%d\\\\n\",\n"
1559 printf " ${macro}_P ());\n"
1560 printf "#endif\n"
1561 fi
1562 fi
4a5c6a1d 1563 # multiarch functions don't have macros.
08e45a40
AC
1564 if class_is_multiarch_p
1565 then
7996bcec
AC
1566 printf " fprintf_unfiltered (file,\n"
1567 printf " \"gdbarch_dump: ${function} = 0x%%08lx\\\\n\",\n"
1568 printf " (long) current_gdbarch->${function});\n"
08e45a40
AC
1569 continue
1570 fi
06b25f14 1571 # Print the macro definition.
08e45a40 1572 printf "#ifdef ${macro}\n"
2ada493a
AC
1573 if class_is_function_p
1574 then
3d9a5942
AC
1575 printf " fprintf_unfiltered (file,\n"
1576 printf " \"gdbarch_dump: %%s # %%s\\\\n\",\n"
1577 printf " \"${macro}(${actual})\",\n"
1578 printf " XSTRING (${macro} (${actual})));\n"
2ada493a 1579 else
3d9a5942
AC
1580 printf " fprintf_unfiltered (file,\n"
1581 printf " \"gdbarch_dump: ${macro} # %%s\\\\n\",\n"
1582 printf " XSTRING (${macro}));\n"
4b9b3959 1583 fi
72e74a21 1584 if [ "x${print_p}" = "x()" ]
4b9b3959 1585 then
4a5c6a1d 1586 printf " gdbarch_dump_${function} (current_gdbarch);\n"
72e74a21 1587 elif [ "x${print_p}" = "x0" ]
4b9b3959 1588 then
4a5c6a1d 1589 printf " /* skip print of ${macro}, print_p == 0. */\n"
72e74a21 1590 elif [ -n "${print_p}" ]
4b9b3959 1591 then
4a5c6a1d 1592 printf " if (${print_p})\n"
3d9a5942
AC
1593 printf " fprintf_unfiltered (file,\n"
1594 printf " \"gdbarch_dump: ${macro} = %s\\\\n\",\n" "${fmt}"
1595 printf " ${print});\n"
4b9b3959
AC
1596 elif class_is_function_p
1597 then
7996bcec
AC
1598 printf " fprintf_unfiltered (file,\n"
1599 printf " \"gdbarch_dump: ${macro} = <0x%%08lx>\\\\n\",\n"
1600 printf " (long) current_gdbarch->${function}\n"
1601 printf " /*${macro} ()*/);\n"
4b9b3959 1602 else
3d9a5942
AC
1603 printf " fprintf_unfiltered (file,\n"
1604 printf " \"gdbarch_dump: ${macro} = %s\\\\n\",\n" "${fmt}"
1605 printf " ${print});\n"
2ada493a 1606 fi
3d9a5942 1607 printf "#endif\n"
104c1213 1608done
381323f4 1609cat <<EOF
4b9b3959
AC
1610 if (current_gdbarch->dump_tdep != NULL)
1611 current_gdbarch->dump_tdep (current_gdbarch, file);
381323f4
AC
1612}
1613EOF
104c1213
JM
1614
1615
1616# GET/SET
3d9a5942 1617printf "\n"
104c1213
JM
1618cat <<EOF
1619struct gdbarch_tdep *
1620gdbarch_tdep (struct gdbarch *gdbarch)
1621{
1622 if (gdbarch_debug >= 2)
3d9a5942 1623 fprintf_unfiltered (gdb_stdlog, "gdbarch_tdep called\\n");
104c1213
JM
1624 return gdbarch->tdep;
1625}
1626EOF
3d9a5942 1627printf "\n"
34620563 1628function_list | while do_read
104c1213 1629do
2ada493a
AC
1630 if class_is_predicate_p
1631 then
3d9a5942
AC
1632 printf "\n"
1633 printf "int\n"
1634 printf "gdbarch_${function}_p (struct gdbarch *gdbarch)\n"
1635 printf "{\n"
8de9bdc4 1636 printf " gdb_assert (gdbarch != NULL);\n"
f7968451 1637 printf " return ${predicate};\n"
3d9a5942 1638 printf "}\n"
2ada493a
AC
1639 fi
1640 if class_is_function_p
1641 then
3d9a5942
AC
1642 printf "\n"
1643 printf "${returntype}\n"
72e74a21 1644 if [ "x${formal}" = "xvoid" ]
104c1213 1645 then
3d9a5942 1646 printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
104c1213 1647 else
3d9a5942 1648 printf "gdbarch_${function} (struct gdbarch *gdbarch, ${formal})\n"
104c1213 1649 fi
3d9a5942 1650 printf "{\n"
8de9bdc4 1651 printf " gdb_assert (gdbarch != NULL);\n"
956ac328 1652 printf " gdb_assert (gdbarch->${function} != NULL);\n"
f7968451 1653 if class_is_predicate_p && test -n "${predefault}"
ae45cd16
AC
1654 then
1655 # Allow a call to a function with a predicate.
956ac328 1656 printf " /* Do not check predicate: ${predicate}, allow call. */\n"
ae45cd16 1657 fi
3d9a5942
AC
1658 printf " if (gdbarch_debug >= 2)\n"
1659 printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\\\\n\");\n"
72e74a21 1660 if [ "x${actual}" = "x-" -o "x${actual}" = "x" ]
4a5c6a1d
AC
1661 then
1662 if class_is_multiarch_p
1663 then
1664 params="gdbarch"
1665 else
1666 params=""
1667 fi
1668 else
1669 if class_is_multiarch_p
1670 then
1671 params="gdbarch, ${actual}"
1672 else
1673 params="${actual}"
1674 fi
1675 fi
72e74a21 1676 if [ "x${returntype}" = "xvoid" ]
104c1213 1677 then
4a5c6a1d 1678 printf " gdbarch->${function} (${params});\n"
104c1213 1679 else
4a5c6a1d 1680 printf " return gdbarch->${function} (${params});\n"
104c1213 1681 fi
3d9a5942
AC
1682 printf "}\n"
1683 printf "\n"
1684 printf "void\n"
1685 printf "set_gdbarch_${function} (struct gdbarch *gdbarch,\n"
1686 printf " `echo ${function} | sed -e 's/./ /g'` gdbarch_${function}_ftype ${function})\n"
1687 printf "{\n"
1688 printf " gdbarch->${function} = ${function};\n"
1689 printf "}\n"
2ada493a
AC
1690 elif class_is_variable_p
1691 then
3d9a5942
AC
1692 printf "\n"
1693 printf "${returntype}\n"
1694 printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
1695 printf "{\n"
8de9bdc4 1696 printf " gdb_assert (gdbarch != NULL);\n"
72e74a21 1697 if [ "x${invalid_p}" = "x0" ]
c0e8c252 1698 then
3d9a5942 1699 printf " /* Skip verify of ${function}, invalid_p == 0 */\n"
72e74a21 1700 elif [ -n "${invalid_p}" ]
104c1213 1701 then
956ac328
AC
1702 printf " /* Check variable is valid. */\n"
1703 printf " gdb_assert (!(${invalid_p}));\n"
72e74a21 1704 elif [ -n "${predefault}" ]
104c1213 1705 then
956ac328
AC
1706 printf " /* Check variable changed from pre-default. */\n"
1707 printf " gdb_assert (gdbarch->${function} != ${predefault});\n"
104c1213 1708 fi
3d9a5942
AC
1709 printf " if (gdbarch_debug >= 2)\n"
1710 printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\\\\n\");\n"
1711 printf " return gdbarch->${function};\n"
1712 printf "}\n"
1713 printf "\n"
1714 printf "void\n"
1715 printf "set_gdbarch_${function} (struct gdbarch *gdbarch,\n"
1716 printf " `echo ${function} | sed -e 's/./ /g'` ${returntype} ${function})\n"
1717 printf "{\n"
1718 printf " gdbarch->${function} = ${function};\n"
1719 printf "}\n"
2ada493a
AC
1720 elif class_is_info_p
1721 then
3d9a5942
AC
1722 printf "\n"
1723 printf "${returntype}\n"
1724 printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
1725 printf "{\n"
8de9bdc4 1726 printf " gdb_assert (gdbarch != NULL);\n"
3d9a5942
AC
1727 printf " if (gdbarch_debug >= 2)\n"
1728 printf " fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\\\\n\");\n"
1729 printf " return gdbarch->${function};\n"
1730 printf "}\n"
2ada493a 1731 fi
104c1213
JM
1732done
1733
1734# All the trailing guff
1735cat <<EOF
1736
1737
f44c642f 1738/* Keep a registry of per-architecture data-pointers required by GDB
104c1213
JM
1739 modules. */
1740
1741struct gdbarch_data
1742{
95160752 1743 unsigned index;
76860b5f 1744 int init_p;
030f20e1
AC
1745 gdbarch_data_pre_init_ftype *pre_init;
1746 gdbarch_data_post_init_ftype *post_init;
104c1213
JM
1747};
1748
1749struct gdbarch_data_registration
1750{
104c1213
JM
1751 struct gdbarch_data *data;
1752 struct gdbarch_data_registration *next;
1753};
1754
f44c642f 1755struct gdbarch_data_registry
104c1213 1756{
95160752 1757 unsigned nr;
104c1213
JM
1758 struct gdbarch_data_registration *registrations;
1759};
1760
f44c642f 1761struct gdbarch_data_registry gdbarch_data_registry =
104c1213
JM
1762{
1763 0, NULL,
1764};
1765
030f20e1
AC
1766static struct gdbarch_data *
1767gdbarch_data_register (gdbarch_data_pre_init_ftype *pre_init,
1768 gdbarch_data_post_init_ftype *post_init)
104c1213
JM
1769{
1770 struct gdbarch_data_registration **curr;
76860b5f 1771 /* Append the new registraration. */
f44c642f 1772 for (curr = &gdbarch_data_registry.registrations;
104c1213
JM
1773 (*curr) != NULL;
1774 curr = &(*curr)->next);
1775 (*curr) = XMALLOC (struct gdbarch_data_registration);
1776 (*curr)->next = NULL;
104c1213 1777 (*curr)->data = XMALLOC (struct gdbarch_data);
f44c642f 1778 (*curr)->data->index = gdbarch_data_registry.nr++;
030f20e1
AC
1779 (*curr)->data->pre_init = pre_init;
1780 (*curr)->data->post_init = post_init;
76860b5f 1781 (*curr)->data->init_p = 1;
104c1213
JM
1782 return (*curr)->data;
1783}
1784
030f20e1
AC
1785struct gdbarch_data *
1786gdbarch_data_register_pre_init (gdbarch_data_pre_init_ftype *pre_init)
1787{
1788 return gdbarch_data_register (pre_init, NULL);
1789}
1790
1791struct gdbarch_data *
1792gdbarch_data_register_post_init (gdbarch_data_post_init_ftype *post_init)
1793{
1794 return gdbarch_data_register (NULL, post_init);
1795}
104c1213 1796
b3cc3077 1797/* Create/delete the gdbarch data vector. */
95160752
AC
1798
1799static void
b3cc3077 1800alloc_gdbarch_data (struct gdbarch *gdbarch)
95160752 1801{
b3cc3077
JB
1802 gdb_assert (gdbarch->data == NULL);
1803 gdbarch->nr_data = gdbarch_data_registry.nr;
aebd7893 1804 gdbarch->data = GDBARCH_OBSTACK_CALLOC (gdbarch, gdbarch->nr_data, void *);
b3cc3077 1805}
3c875b6f 1806
76860b5f 1807/* Initialize the current value of the specified per-architecture
b3cc3077
JB
1808 data-pointer. */
1809
95160752 1810void
030f20e1
AC
1811deprecated_set_gdbarch_data (struct gdbarch *gdbarch,
1812 struct gdbarch_data *data,
1813 void *pointer)
95160752
AC
1814{
1815 gdb_assert (data->index < gdbarch->nr_data);
aebd7893 1816 gdb_assert (gdbarch->data[data->index] == NULL);
030f20e1 1817 gdb_assert (data->pre_init == NULL);
95160752
AC
1818 gdbarch->data[data->index] = pointer;
1819}
1820
104c1213
JM
1821/* Return the current value of the specified per-architecture
1822 data-pointer. */
1823
1824void *
451fbdda 1825gdbarch_data (struct gdbarch *gdbarch, struct gdbarch_data *data)
104c1213 1826{
451fbdda 1827 gdb_assert (data->index < gdbarch->nr_data);
030f20e1 1828 if (gdbarch->data[data->index] == NULL)
76860b5f 1829 {
030f20e1
AC
1830 /* The data-pointer isn't initialized, call init() to get a
1831 value. */
1832 if (data->pre_init != NULL)
1833 /* Mid architecture creation: pass just the obstack, and not
1834 the entire architecture, as that way it isn't possible for
1835 pre-init code to refer to undefined architecture
1836 fields. */
1837 gdbarch->data[data->index] = data->pre_init (gdbarch->obstack);
1838 else if (gdbarch->initialized_p
1839 && data->post_init != NULL)
1840 /* Post architecture creation: pass the entire architecture
1841 (as all fields are valid), but be careful to also detect
1842 recursive references. */
1843 {
1844 gdb_assert (data->init_p);
1845 data->init_p = 0;
1846 gdbarch->data[data->index] = data->post_init (gdbarch);
1847 data->init_p = 1;
1848 }
1849 else
1850 /* The architecture initialization hasn't completed - punt -
1851 hope that the caller knows what they are doing. Once
1852 deprecated_set_gdbarch_data has been initialized, this can be
1853 changed to an internal error. */
1854 return NULL;
76860b5f
AC
1855 gdb_assert (gdbarch->data[data->index] != NULL);
1856 }
451fbdda 1857 return gdbarch->data[data->index];
104c1213
JM
1858}
1859
1860
1861
f44c642f 1862/* Keep a registry of swapped data required by GDB modules. */
104c1213
JM
1863
1864struct gdbarch_swap
1865{
1866 void *swap;
1867 struct gdbarch_swap_registration *source;
1868 struct gdbarch_swap *next;
1869};
1870
1871struct gdbarch_swap_registration
1872{
1873 void *data;
1874 unsigned long sizeof_data;
1875 gdbarch_swap_ftype *init;
1876 struct gdbarch_swap_registration *next;
1877};
1878
f44c642f 1879struct gdbarch_swap_registry
104c1213
JM
1880{
1881 int nr;
1882 struct gdbarch_swap_registration *registrations;
1883};
1884
f44c642f 1885struct gdbarch_swap_registry gdbarch_swap_registry =
104c1213
JM
1886{
1887 0, NULL,
1888};
1889
1890void
046a4708
AC
1891deprecated_register_gdbarch_swap (void *data,
1892 unsigned long sizeof_data,
1893 gdbarch_swap_ftype *init)
104c1213
JM
1894{
1895 struct gdbarch_swap_registration **rego;
f44c642f 1896 for (rego = &gdbarch_swap_registry.registrations;
104c1213
JM
1897 (*rego) != NULL;
1898 rego = &(*rego)->next);
1899 (*rego) = XMALLOC (struct gdbarch_swap_registration);
1900 (*rego)->next = NULL;
1901 (*rego)->init = init;
1902 (*rego)->data = data;
1903 (*rego)->sizeof_data = sizeof_data;
1904}
1905
40af4b0c 1906static void
7de2341d 1907current_gdbarch_swap_init_hack (void)
104c1213
JM
1908{
1909 struct gdbarch_swap_registration *rego;
7de2341d 1910 struct gdbarch_swap **curr = &current_gdbarch->swap;
f44c642f 1911 for (rego = gdbarch_swap_registry.registrations;
104c1213
JM
1912 rego != NULL;
1913 rego = rego->next)
1914 {
1915 if (rego->data != NULL)
1916 {
7de2341d
AC
1917 (*curr) = GDBARCH_OBSTACK_ZALLOC (current_gdbarch,
1918 struct gdbarch_swap);
104c1213 1919 (*curr)->source = rego;
7de2341d
AC
1920 (*curr)->swap = gdbarch_obstack_zalloc (current_gdbarch,
1921 rego->sizeof_data);
104c1213 1922 (*curr)->next = NULL;
104c1213
JM
1923 curr = &(*curr)->next;
1924 }
1925 if (rego->init != NULL)
1926 rego->init ();
1927 }
1928}
1929
7de2341d
AC
1930static struct gdbarch *
1931current_gdbarch_swap_out_hack (void)
104c1213 1932{
7de2341d 1933 struct gdbarch *old_gdbarch = current_gdbarch;
104c1213 1934 struct gdbarch_swap *curr;
7de2341d
AC
1935
1936 gdb_assert (old_gdbarch != NULL);
1937 for (curr = old_gdbarch->swap;
104c1213
JM
1938 curr != NULL;
1939 curr = curr->next)
7de2341d
AC
1940 {
1941 memcpy (curr->swap, curr->source->data, curr->source->sizeof_data);
1942 memset (curr->source->data, 0, curr->source->sizeof_data);
1943 }
1944 current_gdbarch = NULL;
1945 return old_gdbarch;
104c1213
JM
1946}
1947
1948static void
7de2341d 1949current_gdbarch_swap_in_hack (struct gdbarch *new_gdbarch)
104c1213
JM
1950{
1951 struct gdbarch_swap *curr;
7de2341d
AC
1952
1953 gdb_assert (current_gdbarch == NULL);
1954 for (curr = new_gdbarch->swap;
104c1213
JM
1955 curr != NULL;
1956 curr = curr->next)
1957 memcpy (curr->source->data, curr->swap, curr->source->sizeof_data);
7de2341d 1958 current_gdbarch = new_gdbarch;
104c1213
JM
1959}
1960
1961
f44c642f 1962/* Keep a registry of the architectures known by GDB. */
104c1213 1963
4b9b3959 1964struct gdbarch_registration
104c1213
JM
1965{
1966 enum bfd_architecture bfd_architecture;
1967 gdbarch_init_ftype *init;
4b9b3959 1968 gdbarch_dump_tdep_ftype *dump_tdep;
104c1213 1969 struct gdbarch_list *arches;
4b9b3959 1970 struct gdbarch_registration *next;
104c1213
JM
1971};
1972
f44c642f 1973static struct gdbarch_registration *gdbarch_registry = NULL;
104c1213 1974
b4a20239
AC
1975static void
1976append_name (const char ***buf, int *nr, const char *name)
1977{
1978 *buf = xrealloc (*buf, sizeof (char**) * (*nr + 1));
1979 (*buf)[*nr] = name;
1980 *nr += 1;
1981}
1982
1983const char **
1984gdbarch_printable_names (void)
1985{
7996bcec
AC
1986 /* Accumulate a list of names based on the registed list of
1987 architectures. */
1988 enum bfd_architecture a;
1989 int nr_arches = 0;
1990 const char **arches = NULL;
1991 struct gdbarch_registration *rego;
1992 for (rego = gdbarch_registry;
1993 rego != NULL;
1994 rego = rego->next)
b4a20239 1995 {
7996bcec
AC
1996 const struct bfd_arch_info *ap;
1997 ap = bfd_lookup_arch (rego->bfd_architecture, 0);
1998 if (ap == NULL)
1999 internal_error (__FILE__, __LINE__,
2000 "gdbarch_architecture_names: multi-arch unknown");
2001 do
2002 {
2003 append_name (&arches, &nr_arches, ap->printable_name);
2004 ap = ap->next;
2005 }
2006 while (ap != NULL);
b4a20239 2007 }
7996bcec
AC
2008 append_name (&arches, &nr_arches, NULL);
2009 return arches;
b4a20239
AC
2010}
2011
2012
104c1213 2013void
4b9b3959
AC
2014gdbarch_register (enum bfd_architecture bfd_architecture,
2015 gdbarch_init_ftype *init,
2016 gdbarch_dump_tdep_ftype *dump_tdep)
104c1213 2017{
4b9b3959 2018 struct gdbarch_registration **curr;
104c1213 2019 const struct bfd_arch_info *bfd_arch_info;
ec3d358c 2020 /* Check that BFD recognizes this architecture */
104c1213
JM
2021 bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
2022 if (bfd_arch_info == NULL)
2023 {
8e65ff28
AC
2024 internal_error (__FILE__, __LINE__,
2025 "gdbarch: Attempt to register unknown architecture (%d)",
2026 bfd_architecture);
104c1213
JM
2027 }
2028 /* Check that we haven't seen this architecture before */
f44c642f 2029 for (curr = &gdbarch_registry;
104c1213
JM
2030 (*curr) != NULL;
2031 curr = &(*curr)->next)
2032 {
2033 if (bfd_architecture == (*curr)->bfd_architecture)
8e65ff28
AC
2034 internal_error (__FILE__, __LINE__,
2035 "gdbarch: Duplicate registraration of architecture (%s)",
2036 bfd_arch_info->printable_name);
104c1213
JM
2037 }
2038 /* log it */
2039 if (gdbarch_debug)
2040 fprintf_unfiltered (gdb_stdlog, "register_gdbarch_init (%s, 0x%08lx)\n",
2041 bfd_arch_info->printable_name,
2042 (long) init);
2043 /* Append it */
4b9b3959 2044 (*curr) = XMALLOC (struct gdbarch_registration);
104c1213
JM
2045 (*curr)->bfd_architecture = bfd_architecture;
2046 (*curr)->init = init;
4b9b3959 2047 (*curr)->dump_tdep = dump_tdep;
104c1213
JM
2048 (*curr)->arches = NULL;
2049 (*curr)->next = NULL;
4b9b3959
AC
2050}
2051
2052void
2053register_gdbarch_init (enum bfd_architecture bfd_architecture,
2054 gdbarch_init_ftype *init)
2055{
2056 gdbarch_register (bfd_architecture, init, NULL);
104c1213 2057}
104c1213
JM
2058
2059
2060/* Look for an architecture using gdbarch_info. Base search on only
2061 BFD_ARCH_INFO and BYTE_ORDER. */
2062
2063struct gdbarch_list *
2064gdbarch_list_lookup_by_info (struct gdbarch_list *arches,
2065 const struct gdbarch_info *info)
2066{
2067 for (; arches != NULL; arches = arches->next)
2068 {
2069 if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
2070 continue;
2071 if (info->byte_order != arches->gdbarch->byte_order)
2072 continue;
4be87837
DJ
2073 if (info->osabi != arches->gdbarch->osabi)
2074 continue;
104c1213
JM
2075 return arches;
2076 }
2077 return NULL;
2078}
2079
2080
ebdba546
AC
2081/* Find an architecture that matches the specified INFO. Create a new
2082 architecture if needed. Return that new architecture. Assumes
2083 that there is no current architecture. */
104c1213 2084
ebdba546
AC
2085static struct gdbarch *
2086find_arch_by_info (struct gdbarch *old_gdbarch, struct gdbarch_info info)
104c1213
JM
2087{
2088 struct gdbarch *new_gdbarch;
4b9b3959 2089 struct gdbarch_registration *rego;
104c1213 2090
ebdba546
AC
2091 /* The existing architecture has been swapped out - all this code
2092 works from a clean slate. */
2093 gdb_assert (current_gdbarch == NULL);
2094
b732d07d 2095 /* Fill in missing parts of the INFO struct using a number of
ebdba546
AC
2096 sources: "set ..."; INFOabfd supplied; and the existing
2097 architecture. */
2098 gdbarch_info_fill (old_gdbarch, &info);
4be87837 2099
b732d07d
AC
2100 /* Must have found some sort of architecture. */
2101 gdb_assert (info.bfd_arch_info != NULL);
104c1213
JM
2102
2103 if (gdbarch_debug)
2104 {
2105 fprintf_unfiltered (gdb_stdlog,
ebdba546 2106 "find_arch_by_info: info.bfd_arch_info %s\n",
104c1213
JM
2107 (info.bfd_arch_info != NULL
2108 ? info.bfd_arch_info->printable_name
2109 : "(null)"));
2110 fprintf_unfiltered (gdb_stdlog,
ebdba546 2111 "find_arch_by_info: info.byte_order %d (%s)\n",
104c1213 2112 info.byte_order,
d7449b42 2113 (info.byte_order == BFD_ENDIAN_BIG ? "big"
778eb05e 2114 : info.byte_order == BFD_ENDIAN_LITTLE ? "little"
104c1213 2115 : "default"));
4be87837 2116 fprintf_unfiltered (gdb_stdlog,
ebdba546 2117 "find_arch_by_info: info.osabi %d (%s)\n",
4be87837 2118 info.osabi, gdbarch_osabi_name (info.osabi));
104c1213 2119 fprintf_unfiltered (gdb_stdlog,
ebdba546 2120 "find_arch_by_info: info.abfd 0x%lx\n",
104c1213
JM
2121 (long) info.abfd);
2122 fprintf_unfiltered (gdb_stdlog,
ebdba546 2123 "find_arch_by_info: info.tdep_info 0x%lx\n",
104c1213
JM
2124 (long) info.tdep_info);
2125 }
2126
ebdba546 2127 /* Find the tdep code that knows about this architecture. */
b732d07d
AC
2128 for (rego = gdbarch_registry;
2129 rego != NULL;
2130 rego = rego->next)
2131 if (rego->bfd_architecture == info.bfd_arch_info->arch)
2132 break;
2133 if (rego == NULL)
2134 {
2135 if (gdbarch_debug)
ebdba546
AC
2136 fprintf_unfiltered (gdb_stdlog, "find_arch_by_info: "
2137 "No matching architecture\n");
b732d07d
AC
2138 return 0;
2139 }
2140
ebdba546 2141 /* Ask the tdep code for an architecture that matches "info". */
104c1213
JM
2142 new_gdbarch = rego->init (info, rego->arches);
2143
ebdba546
AC
2144 /* Did the tdep code like it? No. Reject the change and revert to
2145 the old architecture. */
104c1213
JM
2146 if (new_gdbarch == NULL)
2147 {
2148 if (gdbarch_debug)
ebdba546
AC
2149 fprintf_unfiltered (gdb_stdlog, "find_arch_by_info: "
2150 "Target rejected architecture\n");
2151 return NULL;
104c1213
JM
2152 }
2153
ebdba546
AC
2154 /* Is this a pre-existing architecture (as determined by already
2155 being initialized)? Move it to the front of the architecture
2156 list (keeping the list sorted Most Recently Used). */
2157 if (new_gdbarch->initialized_p)
104c1213 2158 {
ebdba546
AC
2159 struct gdbarch_list **list;
2160 struct gdbarch_list *this;
104c1213 2161 if (gdbarch_debug)
ebdba546
AC
2162 fprintf_unfiltered (gdb_stdlog, "find_arch_by_info: "
2163 "Previous architecture 0x%08lx (%s) selected\n",
104c1213
JM
2164 (long) new_gdbarch,
2165 new_gdbarch->bfd_arch_info->printable_name);
ebdba546
AC
2166 /* Find the existing arch in the list. */
2167 for (list = &rego->arches;
2168 (*list) != NULL && (*list)->gdbarch != new_gdbarch;
2169 list = &(*list)->next);
2170 /* It had better be in the list of architectures. */
2171 gdb_assert ((*list) != NULL && (*list)->gdbarch == new_gdbarch);
2172 /* Unlink THIS. */
2173 this = (*list);
2174 (*list) = this->next;
2175 /* Insert THIS at the front. */
2176 this->next = rego->arches;
2177 rego->arches = this;
2178 /* Return it. */
2179 return new_gdbarch;
104c1213
JM
2180 }
2181
ebdba546
AC
2182 /* It's a new architecture. */
2183 if (gdbarch_debug)
2184 fprintf_unfiltered (gdb_stdlog, "find_arch_by_info: "
2185 "New architecture 0x%08lx (%s) selected\n",
2186 (long) new_gdbarch,
2187 new_gdbarch->bfd_arch_info->printable_name);
2188
2189 /* Insert the new architecture into the front of the architecture
2190 list (keep the list sorted Most Recently Used). */
0f79675b
AC
2191 {
2192 struct gdbarch_list *this = XMALLOC (struct gdbarch_list);
2193 this->next = rego->arches;
2194 this->gdbarch = new_gdbarch;
2195 rego->arches = this;
2196 }
104c1213 2197
4b9b3959
AC
2198 /* Check that the newly installed architecture is valid. Plug in
2199 any post init values. */
2200 new_gdbarch->dump_tdep = rego->dump_tdep;
104c1213 2201 verify_gdbarch (new_gdbarch);
ebdba546 2202 new_gdbarch->initialized_p = 1;
104c1213 2203
ebdba546
AC
2204 /* Initialize any per-architecture swap areas. This phase requires
2205 a valid global CURRENT_GDBARCH. Set it momentarially, and then
2206 swap the entire architecture out. */
2207 current_gdbarch = new_gdbarch;
7de2341d 2208 current_gdbarch_swap_init_hack ();
ebdba546 2209 current_gdbarch_swap_out_hack ();
67c2c32c 2210
4b9b3959 2211 if (gdbarch_debug)
ebdba546
AC
2212 gdbarch_dump (new_gdbarch, gdb_stdlog);
2213
2214 return new_gdbarch;
2215}
2216
2217struct gdbarch *
2218gdbarch_find_by_info (struct gdbarch_info info)
2219{
2220 /* Save the previously selected architecture, setting the global to
2221 NULL. This stops things like gdbarch->init() trying to use the
2222 previous architecture's configuration. The previous architecture
2223 may not even be of the same architecture family. The most recent
2224 architecture of the same family is found at the head of the
2225 rego->arches list. */
2226 struct gdbarch *old_gdbarch = current_gdbarch_swap_out_hack ();
2227
2228 /* Find the specified architecture. */
2229 struct gdbarch *new_gdbarch = find_arch_by_info (old_gdbarch, info);
2230
2231 /* Restore the existing architecture. */
2232 gdb_assert (current_gdbarch == NULL);
2233 current_gdbarch_swap_in_hack (old_gdbarch);
4b9b3959 2234
ebdba546 2235 return new_gdbarch;
104c1213
JM
2236}
2237
ebdba546
AC
2238/* Make the specified architecture current, swapping the existing one
2239 out. */
2240
2241void
2242deprecated_current_gdbarch_select_hack (struct gdbarch *new_gdbarch)
2243{
2244 gdb_assert (new_gdbarch != NULL);
2245 gdb_assert (current_gdbarch != NULL);
2246 gdb_assert (new_gdbarch->initialized_p);
2247 current_gdbarch_swap_out_hack ();
2248 current_gdbarch_swap_in_hack (new_gdbarch);
2249 architecture_changed_event ();
2250}
104c1213 2251
104c1213 2252extern void _initialize_gdbarch (void);
b4a20239 2253
104c1213 2254void
34620563 2255_initialize_gdbarch (void)
104c1213 2256{
59233f88
AC
2257 struct cmd_list_element *c;
2258
59233f88 2259 add_show_from_set (add_set_cmd ("arch",
104c1213
JM
2260 class_maintenance,
2261 var_zinteger,
2262 (char *)&gdbarch_debug,
3d9a5942 2263 "Set architecture debugging.\\n\\
59233f88
AC
2264When non-zero, architecture debugging is enabled.", &setdebuglist),
2265 &showdebuglist);
2266 c = add_set_cmd ("archdebug",
2267 class_maintenance,
2268 var_zinteger,
2269 (char *)&gdbarch_debug,
3d9a5942 2270 "Set architecture debugging.\\n\\
59233f88
AC
2271When non-zero, architecture debugging is enabled.", &setlist);
2272
2273 deprecate_cmd (c, "set debug arch");
2274 deprecate_cmd (add_show_from_set (c, &showlist), "show debug arch");
104c1213
JM
2275}
2276EOF
2277
2278# close things off
2279exec 1>&2
2280#../move-if-change new-gdbarch.c gdbarch.c
59233f88 2281compare_new gdbarch.c
This page took 0.733098 seconds and 4 git commands to generate.