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