* defs.h, utils.c (free_current_contents): Change parameter to
[deliverable/binutils-gdb.git] / gdb / gdbarch.sh
CommitLineData
104c1213
JM
1#!/usr/local/bin/bash
2
3# Architecture commands for GDB, the GNU debugger.
59233f88 4# Copyright 1998-2000 Free Software Foundation, Inc.
104c1213
JM
5#
6# This file is part of GDB.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
59233f88
AC
22compare_new ()
23{
24 file=$1
25 if ! test -r ${file}
26 then
27 echo "${file} missing? cp new-${file} ${file}" 1>&2
28 elif diff -c ${file} new-${file}
29 then
30 echo "${file} unchanged" 1>&2
31 else
32 echo "${file} has changed? cp new-${file} ${file}" 1>&2
33 fi
34}
35
36
c0e8c252
AC
37# DEFAULT is a valid fallback definition of a MACRO when
38# multi-arch is not enabled.
39default_is_fallback_p ()
40{
41 [ "${default}" != "" -a "${invalid_p}" = "0" ]
c0e8c252
AC
42}
43
59233f88 44# Format of the input table
c0e8c252
AC
45read="class level macro returntype function formal actual attrib startup default invalid_p fmt print print_p description"
46
47do_read ()
48{
49 if eval read $read
50 then
51 test "${startup}" || startup=0
52 test "${fmt}" || fmt="%ld"
53 test "${print}" || print="(long) ${macro}"
54 #test "${default}" || default=0
55 :
56 else
57 false
58 fi
59}
60
104c1213 61
cff3e48b
JM
62# dump out/verify the doco
63for field in ${read}
64do
65 case ${field} in
66
67 class ) : ;;
c4093a6a 68
c0e8c252
AC
69 # # -> line disable
70 # f -> function
71 # hiding a function
72 # v -> variable
73 # hiding a variable
74 # i -> set from info
75 # hiding something from the ``struct info'' object
cff3e48b
JM
76
77 level ) : ;;
78
c0e8c252
AC
79 # See GDB_MULTI_ARCH description. Having GDB_MULTI_ARCH >=
80 # LEVEL is a predicate on checking that a given method is
81 # initialized (using INVALID_P).
cff3e48b
JM
82
83 macro ) : ;;
84
c0e8c252 85 # The name of the MACRO that this method is to be accessed by.
cff3e48b
JM
86
87 returntype ) : ;;
88
c0e8c252 89 # For functions, the return type; for variables, the data type
cff3e48b
JM
90
91 function ) : ;;
92
c0e8c252
AC
93 # For functions, the member function name; for variables, the
94 # variable name. Member function names are always prefixed with
95 # ``gdbarch_'' for name-space purity.
cff3e48b
JM
96
97 formal ) : ;;
98
c0e8c252
AC
99 # The formal argument list. It is assumed that the formal
100 # argument list includes the actual name of each list element.
101 # A function with no arguments shall have ``void'' as the
102 # formal argument list.
cff3e48b
JM
103
104 actual ) : ;;
105
c0e8c252
AC
106 # The list of actual arguments. The arguments specified shall
107 # match the FORMAL list given above. Functions with out
108 # arguments leave this blank.
cff3e48b
JM
109
110 attrib ) : ;;
111
c0e8c252
AC
112 # Any GCC attributes that should be attached to the function
113 # declaration. At present this field is unused.
cff3e48b 114
c0e8c252
AC
115 startup ) : ;;
116
117 # To help with the GDB startup a static gdbarch object is
118 # created. STARTUP is the value to insert into that static
119 # gdbarch object.
cff3e48b 120
c0e8c252
AC
121 # By default ``0'' is used.
122
123 default ) : ;;
cff3e48b 124
c0e8c252
AC
125 # Any initial value to assign to a new gdbarch object after it
126 # as been malloc()ed. Zero is used by default.
cff3e48b 127
c0e8c252
AC
128 # Specify a non-empty DEFAULT and a zero INVALID_P to create a
129 # fallback value or function for when multi-arch is disabled.
130 # Specify a zero DEFAULT function to make that fallback
131 # illegal to call.
cff3e48b 132
c4093a6a 133 invalid_p ) : ;;
cff3e48b 134
c0e8c252
AC
135 # A predicate equation that validates MEMBER. Non-zero is
136 # returned if the code creating the new architecture failed to
137 # initialize the MEMBER or initialized the member to something
138 # invalid. By default, a check that the value is no longer
139 # equal to DEFAULT ips performed. The equation ``0'' disables
140 # the invalid_p check.
cff3e48b
JM
141
142 fmt ) : ;;
143
c0e8c252
AC
144 # printf style format string that can be used to print out the
145 # MEMBER. Sometimes "%s" is useful. For functions, this is
146 # ignored and the function address is printed.
147
148 # By default ```%ld'' is used.
cff3e48b
JM
149
150 print ) : ;;
151
c0e8c252
AC
152 # An optional equation that casts MEMBER to a value suitable
153 # for formatting by FMT.
154
155 # By default ``(long)'' is used.
cff3e48b
JM
156
157 print_p ) : ;;
158
c0e8c252
AC
159 # An optional indicator for any predicte to wrap around the
160 # print member code.
161
162 # # -> Wrap print up in ``#ifdef MACRO''
163 # exp -> Wrap print up in ``if (${print_p}) ...
164 # ``'' -> No predicate
cff3e48b
JM
165
166 description ) : ;;
167
168 # Currently unused.
169
170 *) exit 1;;
171 esac
172done
173
174IFS=:
175
104c1213
JM
176function_list ()
177{
cff3e48b 178 # See below (DOCO) for description of each field
104c1213
JM
179 cat <<EOF |
180i:2:TARGET_ARCHITECTURE:const struct bfd_arch_info *:bfd_arch_info::::&bfd_default_arch_struct:::%s:TARGET_ARCHITECTURE->printable_name:TARGET_ARCHITECTURE != NULL
181#
182i:2:TARGET_BYTE_ORDER:int:byte_order::::BIG_ENDIAN
183#
c4093a6a 184v:1:TARGET_BFD_VMA_BIT:int:bfd_vma_bit::::8 * sizeof (void*):TARGET_ARCHITECTURE->bits_per_address:0
104c1213
JM
185v:1:TARGET_PTR_BIT:int:ptr_bit::::8 * sizeof (void*):0
186#v:1:TARGET_CHAR_BIT:int:char_bit::::8 * sizeof (char):0
187v:1:TARGET_SHORT_BIT:int:short_bit::::8 * sizeof (short):0
188v:1:TARGET_INT_BIT:int:int_bit::::8 * sizeof (int):0
189v:1:TARGET_LONG_BIT:int:long_bit::::8 * sizeof (long):0
190v:1:TARGET_LONG_LONG_BIT:int:long_long_bit::::8 * sizeof (LONGEST):0
191v:1:TARGET_FLOAT_BIT:int:float_bit::::8 * sizeof (float):0
192v:1:TARGET_DOUBLE_BIT:int:double_bit::::8 * sizeof (double):0
193v:1:TARGET_LONG_DOUBLE_BIT:int:long_double_bit::::8 * sizeof (long double):0
ba886e9d 194v:1:IEEE_FLOAT:int:ieee_float::::0:0:0:::
104c1213
JM
195#
196f:1:TARGET_READ_PC:CORE_ADDR:read_pc:int pid:pid::0:0
197f:1:TARGET_WRITE_PC:void:write_pc:CORE_ADDR val, int pid:val, pid::0:0
198f:1:TARGET_READ_FP:CORE_ADDR:read_fp:void:::0:0
199f:1:TARGET_WRITE_FP:void:write_fp:CORE_ADDR val:val::0:0
200f:1:TARGET_READ_SP:CORE_ADDR:read_sp:void:::0:0
201f:1:TARGET_WRITE_SP:void:write_sp:CORE_ADDR val:val::0:0
202#
203v:2:NUM_REGS:int:num_regs::::0:-1
204v:2:SP_REGNUM:int:sp_regnum::::0:-1
205v:2:FP_REGNUM:int:fp_regnum::::0:-1
206v:2:PC_REGNUM:int:pc_regnum::::0:-1
c0e8c252 207f:2:REGISTER_NAME:char *:register_name:int regnr:regnr:::legacy_register_name:0
104c1213
JM
208v:2:REGISTER_SIZE:int:register_size::::0:-1
209v:2:REGISTER_BYTES:int:register_bytes::::0:-1
210f:2:REGISTER_BYTE:int:register_byte:int reg_nr:reg_nr::0:0
211f:2:REGISTER_RAW_SIZE:int:register_raw_size:int reg_nr:reg_nr::0:0
212v:2:MAX_REGISTER_RAW_SIZE:int:max_register_raw_size::::0:-1
213f:2:REGISTER_VIRTUAL_SIZE:int:register_virtual_size:int reg_nr:reg_nr::0:0
214v:2:MAX_REGISTER_VIRTUAL_SIZE:int:max_register_virtual_size::::0:-1
215f:2:REGISTER_VIRTUAL_TYPE:struct type *:register_virtual_type:int reg_nr:reg_nr::0:0
216#
217v:1:USE_GENERIC_DUMMY_FRAMES:int:use_generic_dummy_frames::::0:-1
218v:2:CALL_DUMMY_LOCATION:int:call_dummy_location::::0:0
219f:2:CALL_DUMMY_ADDRESS:CORE_ADDR:call_dummy_address:void:::0:0:gdbarch->call_dummy_location == AT_ENTRY_POINT && gdbarch->call_dummy_address == 0:
220v:2:CALL_DUMMY_START_OFFSET:CORE_ADDR:call_dummy_start_offset::::0:-1::0x%08lx
221v:2:CALL_DUMMY_BREAKPOINT_OFFSET:CORE_ADDR:call_dummy_breakpoint_offset::::0:-1::0x%08lx
222v:1:CALL_DUMMY_BREAKPOINT_OFFSET_P:int:call_dummy_breakpoint_offset_p::::0:-1
223v:2:CALL_DUMMY_LENGTH:int:call_dummy_length::::0:-1::::CALL_DUMMY_LOCATION == BEFORE_TEXT_END || CALL_DUMMY_LOCATION == AFTER_TEXT_END
224f:2:PC_IN_CALL_DUMMY:int:pc_in_call_dummy:CORE_ADDR pc, CORE_ADDR sp, CORE_ADDR frame_address:pc, sp, frame_address::0:0
225v:1:CALL_DUMMY_P:int:call_dummy_p::::0:-1
c0e8c252
AC
226v:2:CALL_DUMMY_WORDS:LONGEST *:call_dummy_words::::0:legacy_call_dummy_words:0:0x%08lx
227v:2:SIZEOF_CALL_DUMMY_WORDS:int:sizeof_call_dummy_words::::0:legacy_sizeof_call_dummy_words:0:0x%08lx
104c1213
JM
228v:1:CALL_DUMMY_STACK_ADJUST_P:int:call_dummy_stack_adjust_p::::0:-1::0x%08lx
229v:2:CALL_DUMMY_STACK_ADJUST:int:call_dummy_stack_adjust::::0::gdbarch->call_dummy_stack_adjust_p && gdbarch->call_dummy_stack_adjust == 0:0x%08lx::CALL_DUMMY_STACK_ADJUST_P
230f:2:FIX_CALL_DUMMY:void:fix_call_dummy:char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs, struct value **args, struct type *type, int gcc_p:dummy, pc, fun, nargs, args, type, gcc_p::0:0
231#
232v:2:BELIEVE_PCC_PROMOTION:int:believe_pcc_promotion::::0:::::#
233v:2:BELIEVE_PCC_PROMOTION_TYPE:int:believe_pcc_promotion_type::::0:::::#
c0e8c252 234f:2:COERCE_FLOAT_TO_DOUBLE:int:coerce_float_to_double:struct type *formal, struct type *actual:formal, actual:::default_coerce_float_to_double:0
104c1213
JM
235f:1:GET_SAVED_REGISTER:void: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::generic_get_saved_register:0
236#
c0e8c252
AC
237f:1:REGISTER_CONVERTIBLE:int:register_convertible:int nr:nr:::generic_register_convertible_not:0
238f:2:REGISTER_CONVERT_TO_VIRTUAL:void:register_convert_to_virtual:int regnum, struct type *type, char *from, char *to:regnum, type, from, to:::0:0
239f:2:REGISTER_CONVERT_TO_RAW:void:register_convert_to_raw:struct type *type, int regnum, char *from, char *to:type, regnum, from, to:::0:0
104c1213 240#
4478b372
JB
241f:2:POINTER_TO_ADDRESS:CORE_ADDR:pointer_to_address:struct type *type, char *buf:type, buf:::generic_pointer_to_address:0
242f:2:ADDRESS_TO_POINTER:void:address_to_pointer:struct type *type, char *buf, CORE_ADDR addr:type, buf, addr:::generic_address_to_pointer:0
243#
71a9f22e 244f:2:RETURN_VALUE_ON_STACK:int:return_value_on_stack:struct type *type:type:::generic_return_value_on_stack_not:0
104c1213
JM
245f:2:EXTRACT_RETURN_VALUE:void:extract_return_value:struct type *type, char *regbuf, char *valbuf:type, regbuf, valbuf::0:0
246f:1:PUSH_ARGUMENTS:CORE_ADDR:push_arguments:int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr:nargs, args, sp, struct_return, struct_addr::0:0
c0e8c252
AC
247f:2:PUSH_DUMMY_FRAME:void:push_dummy_frame:void:-:::0
248f:1:PUSH_RETURN_ADDRESS:CORE_ADDR:push_return_address:CORE_ADDR pc, CORE_ADDR sp:pc, sp:::0
249f:2:POP_FRAME:void:pop_frame:void:-:::0
104c1213
JM
250#
251# I wish that these would just go away....
c0e8c252
AC
252f:2:D10V_MAKE_DADDR:CORE_ADDR:d10v_make_daddr:CORE_ADDR x:x:::0:0
253f:2:D10V_MAKE_IADDR:CORE_ADDR:d10v_make_iaddr:CORE_ADDR x:x:::0:0
254f:2:D10V_DADDR_P:int:d10v_daddr_p:CORE_ADDR x:x:::0
255f:2:D10V_IADDR_P:int:d10v_iaddr_p:CORE_ADDR x:x:::0
256f:2:D10V_CONVERT_DADDR_TO_RAW:CORE_ADDR:d10v_convert_daddr_to_raw:CORE_ADDR x:x:::0
257f:2:D10V_CONVERT_IADDR_TO_RAW:CORE_ADDR:d10v_convert_iaddr_to_raw:CORE_ADDR x:x:::0
104c1213 258#
c0e8c252
AC
259f:2:STORE_STRUCT_RETURN:void:store_struct_return:CORE_ADDR addr, CORE_ADDR sp:addr, sp:::0
260f:2:STORE_RETURN_VALUE:void:store_return_value:struct type *type, char *valbuf:type, valbuf:::0
261f:2:EXTRACT_STRUCT_VALUE_ADDRESS:CORE_ADDR:extract_struct_value_address:char *regbuf:regbuf:::0
262f:2:USE_STRUCT_CONVENTION:int:use_struct_convention:int gcc_p, struct type *value_type:gcc_p, value_type:::0
104c1213
JM
263#
264f:2:FRAME_INIT_SAVED_REGS:void:frame_init_saved_regs:struct frame_info *frame:frame::0:0
c0e8c252 265f:2:INIT_EXTRA_FRAME_INFO:void:init_extra_frame_info:int fromleaf, struct frame_info *frame:fromleaf, frame:::0
104c1213
JM
266#
267f:2:SKIP_PROLOGUE:CORE_ADDR:skip_prologue:CORE_ADDR ip:ip::0:0
268f:2:INNER_THAN:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs::0:0
c0e8c252 269f:2:BREAKPOINT_FROM_PC:unsigned char *:breakpoint_from_pc:CORE_ADDR *pcptr, int *lenptr:pcptr, lenptr:::legacy_breakpoint_from_pc:0
917317f4
JM
270f:2:MEMORY_INSERT_BREAKPOINT:int:memory_insert_breakpoint:CORE_ADDR addr, char *contents_cache:addr, contents_cache::0:default_memory_insert_breakpoint:0
271f:2:MEMORY_REMOVE_BREAKPOINT:int:memory_remove_breakpoint:CORE_ADDR addr, char *contents_cache:addr, contents_cache::0:default_memory_remove_breakpoint:0
104c1213
JM
272v:2:DECR_PC_AFTER_BREAK:CORE_ADDR:decr_pc_after_break::::0:-1
273v:2:FUNCTION_START_OFFSET:CORE_ADDR:function_start_offset::::0:-1
274#
c0e8c252 275f:2:REMOTE_TRANSLATE_XFER_ADDRESS:void:remote_translate_xfer_address:CORE_ADDR gdb_addr, int gdb_len, CORE_ADDR *rem_addr, int *rem_len:gdb_addr, gdb_len, rem_addr, rem_len:::generic_remote_translate_xfer_address:0
104c1213
JM
276#
277v:2:FRAME_ARGS_SKIP:CORE_ADDR:frame_args_skip::::0:-1
c0e8c252 278f:2:FRAMELESS_FUNCTION_INVOCATION:int:frameless_function_invocation:struct frame_info *fi:fi:::generic_frameless_function_invocation_not:0
104c1213
JM
279f:2:FRAME_CHAIN:CORE_ADDR:frame_chain:struct frame_info *frame:frame::0:0
280f:1:FRAME_CHAIN_VALID:int:frame_chain_valid:CORE_ADDR chain, struct frame_info *thisframe:chain, thisframe::0:0
281f:2:FRAME_SAVED_PC:CORE_ADDR:frame_saved_pc:struct frame_info *fi:fi::0:0
282f:2:FRAME_ARGS_ADDRESS:CORE_ADDR:frame_args_address:struct frame_info *fi:fi::0:0
283f:2:FRAME_LOCALS_ADDRESS:CORE_ADDR:frame_locals_address:struct frame_info *fi:fi::0:0
284f:2:SAVED_PC_AFTER_CALL:CORE_ADDR:saved_pc_after_call:struct frame_info *frame:frame::0:0
285f:2:FRAME_NUM_ARGS:int:frame_num_args:struct frame_info *frame:frame::0:0
286#
287EOF
288 grep -v '^#'
289}
290
291
292# dump it out
293if true
294then
295 exec > new-gdbarch
c0e8c252 296 function_list | while do_read # eval read $read
104c1213
JM
297 do
298 cat <<EOF
299${class} ${macro}(${actual})
300 ${returntype} ${function} ($formal)${attrib}
301 level=${level}
c0e8c252 302 startup=${startup}
104c1213 303 default=${default}
c4093a6a 304 invalid_p=${invalid_p}
104c1213
JM
305 fmt=${fmt}
306 print=${print}
307 print_p=${print_p}
308 description=${description}
309EOF
310 done
311 exec 1>&2
312fi
313
314copyright ()
315{
316cat <<EOF
59233f88
AC
317/* *INDENT-OFF* */ /* THIS FILE IS GENERATED */
318
104c1213
JM
319/* Dynamic architecture support for GDB, the GNU debugger.
320 Copyright 1998-1999, Free Software Foundation, Inc.
321
322 This file is part of GDB.
323
324 This program is free software; you can redistribute it and/or modify
325 it under the terms of the GNU General Public License as published by
326 the Free Software Foundation; either version 2 of the License, or
327 (at your option) any later version.
328
329 This program is distributed in the hope that it will be useful,
330 but WITHOUT ANY WARRANTY; without even the implied warranty of
331 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
332 GNU General Public License for more details.
333
334 You should have received a copy of the GNU General Public License
335 along with this program; if not, write to the Free Software
336 Foundation, Inc., 59 Temple Place - Suite 330,
337 Boston, MA 02111-1307, USA. */
338
104c1213
JM
339/* This file was created with the aid of \`\`gdbarch.sh''.
340
341 The bourn shell script \`\`gdbarch.sh'' creates the files
342 \`\`new-gdbarch.c'' and \`\`new-gdbarch.h and then compares them
343 against the existing \`\`gdbarch.[hc]''. Any differences found
344 being reported.
345
346 If editing this file, please also run gdbarch.sh and merge any
347 changes into that script. Conversely, when makeing sweeping changes
348 to this file, modifying gdbarch.sh and using its output may prove
349 easier. */
350
351EOF
352}
353
354#
355# The .h file
356#
357
358exec > new-gdbarch.h
359copyright
360cat <<EOF
361#ifndef GDBARCH_H
362#define GDBARCH_H
363
364struct frame_info;
365struct value;
366
367
368#ifndef GDB_MULTI_ARCH
369#define GDB_MULTI_ARCH 0
370#endif
371
372extern struct gdbarch *current_gdbarch;
373
374
375/* See gdb/doc/gdbint.texi for a discussion of the GDB_MULTI_ARCH
376 macro */
377
378
379/* If any of the following are defined, the target wasn't correctly
380 converted. */
381
104c1213
JM
382#if GDB_MULTI_ARCH
383#if defined (EXTRA_FRAME_INFO)
384#error "EXTRA_FRAME_INFO: replaced by struct frame_extra_info"
385#endif
386#endif
387
388#if GDB_MULTI_ARCH
389#if defined (FRAME_FIND_SAVED_REGS)
390#error "FRAME_FIND_SAVED_REGS: replaced by FRAME_INIT_SAVED_REGS"
391#endif
392#endif
393EOF
394
395# function typedef's
396echo ""
397echo ""
398echo "/* The following are pre-initialized by GDBARCH. */"
c0e8c252 399function_list | while do_read # eval read $read
104c1213
JM
400do
401 case "${class}" in
402 "i" )
403 echo ""
404 echo "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);"
405 echo "/* set_gdbarch_${function}() - not applicable - pre-initialized. */"
406 echo "#if GDB_MULTI_ARCH"
407 echo "#if (GDB_MULTI_ARCH > 1) || !defined (${macro})"
408 echo "#define ${macro} (gdbarch_${function} (current_gdbarch))"
409 echo "#endif"
410 echo "#endif"
411 ;;
412 esac
413done
414
415# function typedef's
416echo ""
417echo ""
418echo "/* The following are initialized by the target dependant code. */"
c0e8c252 419function_list | while do_read # eval read $read
104c1213
JM
420do
421 case "${class}" in
422 "v" )
423 echo ""
424 echo "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);"
425 echo "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, ${returntype} ${function});"
ba886e9d
AC
426 if ! default_is_fallback_p
427 then
428 echo "#if GDB_MULTI_ARCH"
429 fi
104c1213
JM
430 echo "#if (GDB_MULTI_ARCH > 1) || !defined (${macro})"
431 echo "#define ${macro} (gdbarch_${function} (current_gdbarch))"
432 echo "#endif"
ba886e9d
AC
433 if ! default_is_fallback_p
434 then
435 echo "#endif"
436 fi
104c1213
JM
437 ;;
438 "f" )
439 echo ""
440 echo "typedef ${returntype} (gdbarch_${function}_ftype) (${formal});"
441 if [ "${formal}" = "void" ]
442 then
443 echo "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);"
444 else
445 echo "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch, ${formal});"
446 fi
447 echo "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, gdbarch_${function}_ftype *${function});"
c0e8c252
AC
448 if ! default_is_fallback_p
449 then
450 echo "#if GDB_MULTI_ARCH"
451 fi
104c1213
JM
452 echo "#if (GDB_MULTI_ARCH > 1) || !defined (${macro})"
453 if [ "${actual}" = "" ]
454 then
455 echo "#define ${macro}() (gdbarch_${function} (current_gdbarch))"
456 elif [ "${actual}" = "-" ]
457 then
458 echo "#define ${macro} (gdbarch_${function} (current_gdbarch))"
459 else
460 echo "#define ${macro}(${actual}) (gdbarch_${function} (current_gdbarch, ${actual}))"
461 fi
462 echo "#endif"
c0e8c252
AC
463 if ! default_is_fallback_p
464 then
465 echo "#endif"
466 fi
104c1213
JM
467 ;;
468 esac
469done
470
471# close it off
472cat <<EOF
473
474extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
475
476
477/* Mechanism for co-ordinating the selection of a specific
478 architecture.
479
480 GDB targets (*-tdep.c) can register an interest in a specific
481 architecture. Other GDB components can register a need to maintain
482 per-architecture data.
483
484 The mechanisms below ensures that there is only a loose connection
485 between the set-architecture command and the various GDB
486 components. Each component can independantly register their need
487 to maintain architecture specific data with gdbarch.
488
489 Pragmatics:
490
491 Previously, a single TARGET_ARCHITECTURE_HOOK was provided. It
492 didn't scale.
493
494 The more traditional mega-struct containing architecture specific
495 data for all the various GDB components was also considered. Since
496 GDB is built from a variable number of (fairly independant)
497 components it was determined that the global aproach was not
498 applicable. */
499
500
501/* Register a new architectural family with GDB.
502
503 Register support for the specified ARCHITECTURE with GDB. When
504 gdbarch determines that the specified architecture has been
505 selected, the corresponding INIT function is called.
506
507 --
508
509 The INIT function takes two parameters: INFO which contains the
510 information available to gdbarch about the (possibly new)
511 architecture; ARCHES which is a list of the previously created
512 \`\`struct gdbarch'' for this architecture.
513
514 The INIT function parameter INFO shall, as far as possible, be
515 pre-initialized with information obtained from INFO.ABFD or
516 previously selected architecture (if similar). INIT shall ensure
517 that the INFO.BYTE_ORDER is non-zero.
518
519 The INIT function shall return any of: NULL - indicating that it
520 doesn't reconize the selected architecture; an existing \`\`struct
521 gdbarch'' from the ARCHES list - indicating that the new
522 architecture is just a synonym for an earlier architecture (see
523 gdbarch_list_lookup_by_info()); a newly created \`\`struct gdbarch''
524 - that describes the selected architecture (see
525 gdbarch_alloc()). */
526
527struct gdbarch_list
528{
529 struct gdbarch *gdbarch;
530 struct gdbarch_list *next;
531};
532
533struct gdbarch_info
534{
535 /* Use default: bfd_arch_unknown (ZERO). */
536 enum bfd_architecture bfd_architecture;
537
538 /* Use default: NULL (ZERO). */
539 const struct bfd_arch_info *bfd_arch_info;
540
541 /* Use default: 0 (ZERO). */
542 int byte_order;
543
544 /* Use default: NULL (ZERO). */
545 bfd *abfd;
546
547 /* Use default: NULL (ZERO). */
548 struct gdbarch_tdep_info *tdep_info;
549};
550
551typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
552
553extern void register_gdbarch_init (enum bfd_architecture architecture, gdbarch_init_ftype *);
554
555
556/* Helper function. Search the list of ARCHES for a GDBARCH that
557 matches the information provided by INFO. */
558
559extern struct gdbarch_list *gdbarch_list_lookup_by_info (struct gdbarch_list *arches, const struct gdbarch_info *info);
560
561
562/* Helper function. Create a preliminary \`\`struct gdbarch''. Perform
563 basic initialization using values obtained from the INFO andTDEP
564 parameters. set_gdbarch_*() functions are called to complete the
565 initialization of the object. */
566
567extern struct gdbarch *gdbarch_alloc (const struct gdbarch_info *info, struct gdbarch_tdep *tdep);
568
569
058f20d5
JB
570/* Helper function. Free a partially-constructed \`\`struct gdbarch''. */
571extern void gdbarch_free (struct gdbarch *);
572
573
104c1213
JM
574/* Helper function. Force an update of the current architecture. Used
575 by legacy targets that have added their own target specific
576 architecture manipulation commands.
577
578 The INFO parameter shall be fully initialized (\`\`memset (&INFO,
579 sizeof (info), 0)'' set relevant fields) before gdbarch_update() is
580 called. gdbarch_update() shall initialize any \`\`default'' fields
581 using information obtained from the previous architecture or
582 INFO.ABFD (if specified) before calling the corresponding
583 architectures INIT function. */
584
585extern int gdbarch_update (struct gdbarch_info info);
586
587
588
589/* Register per-architecture data-pointer.
590
591 Reserve space for a per-architecture data-pointer. An identifier
592 for the reserved data-pointer is returned. That identifer should
593 be saved in a local static.
594
595 When a new architecture is selected, INIT() is called. When a
596 previous architecture is re-selected, the per-architecture
597 data-pointer for that previous architecture is restored (INIT() is
598 not called).
599
600 INIT() shall return the initial value for the per-architecture
601 data-pointer for the current architecture.
602
603 Multiple registrarants for any architecture are allowed (and
604 strongly encouraged). */
605
606typedef void *(gdbarch_data_ftype) (void);
607extern struct gdbarch_data *register_gdbarch_data (gdbarch_data_ftype *init);
608
609/* Return the value of the per-architecture data-pointer for the
610 current architecture. */
611
612extern void *gdbarch_data (struct gdbarch_data*);
613
614
615
616/* Register per-architecture memory region.
617
618 Provide a memory-region swap mechanism. Per-architecture memory
619 region are created. These memory regions are swapped whenever the
620 architecture is changed. For a new architecture, the memory region
621 is initialized with zero (0) and the INIT function is called.
622
623 Memory regions are swapped / initialized in the order that they are
624 registered. NULL DATA and/or INIT values can be specified.
625
626 New code should use register_gdbarch_data(). */
627
628typedef void (gdbarch_swap_ftype) (void);
629extern void register_gdbarch_swap (void *data, unsigned long size, gdbarch_swap_ftype *init);
e514a9d6 630#define REGISTER_GDBARCH_SWAP(VAR) register_gdbarch_swap (&(VAR), sizeof ((VAR)), NULL)
104c1213
JM
631
632
633
634/* The target-system-dependant byte order is dynamic */
635
636/* TARGET_BYTE_ORDER_SELECTABLE_P determines if the target endianness
637 is selectable at runtime. The user can use the \`\`set endian''
638 command to change it. TARGET_BYTE_ORDER_AUTO is nonzero when
639 target_byte_order should be auto-detected (from the program image
640 say). */
641
642#if GDB_MULTI_ARCH
643/* Multi-arch GDB is always bi-endian. */
644#define TARGET_BYTE_ORDER_SELECTABLE_P 1
645#endif
646
647#ifndef TARGET_BYTE_ORDER_SELECTABLE_P
648/* compat - Catch old targets that define TARGET_BYTE_ORDER_SLECTABLE
649 when they should have defined TARGET_BYTE_ORDER_SELECTABLE_P 1 */
650#ifdef TARGET_BYTE_ORDER_SELECTABLE
651#define TARGET_BYTE_ORDER_SELECTABLE_P 1
652#else
653#define TARGET_BYTE_ORDER_SELECTABLE_P 0
654#endif
655#endif
656
657extern int target_byte_order;
658#ifdef TARGET_BYTE_ORDER_SELECTABLE
659/* compat - Catch old targets that define TARGET_BYTE_ORDER_SELECTABLE
660 and expect defs.h to re-define TARGET_BYTE_ORDER. */
661#undef TARGET_BYTE_ORDER
662#endif
663#ifndef TARGET_BYTE_ORDER
664#define TARGET_BYTE_ORDER (target_byte_order + 0)
665#endif
666
667extern int target_byte_order_auto;
668#ifndef TARGET_BYTE_ORDER_AUTO
669#define TARGET_BYTE_ORDER_AUTO (target_byte_order_auto + 0)
670#endif
671
672
673
674/* The target-system-dependant BFD architecture is dynamic */
675
676extern int target_architecture_auto;
677#ifndef TARGET_ARCHITECTURE_AUTO
678#define TARGET_ARCHITECTURE_AUTO (target_architecture_auto + 0)
679#endif
680
681extern const struct bfd_arch_info *target_architecture;
682#ifndef TARGET_ARCHITECTURE
683#define TARGET_ARCHITECTURE (target_architecture + 0)
684#endif
685
686/* Notify the target dependant backend of a change to the selected
687 architecture. A zero return status indicates that the target did
688 not like the change. */
689
690extern int (*target_architecture_hook) (const struct bfd_arch_info *);
691
692
693
694/* The target-system-dependant disassembler is semi-dynamic */
695
696#include "dis-asm.h" /* Get defs for disassemble_info */
697
698extern int dis_asm_read_memory (bfd_vma memaddr, bfd_byte *myaddr,
ff844c8d 699 unsigned int len, disassemble_info *info);
104c1213
JM
700
701extern void dis_asm_memory_error (int status, bfd_vma memaddr,
702 disassemble_info *info);
703
704extern void dis_asm_print_address (bfd_vma addr,
705 disassemble_info *info);
706
707extern int (*tm_print_insn) (bfd_vma, disassemble_info*);
708extern disassemble_info tm_print_insn_info;
709#ifndef TARGET_PRINT_INSN
710#define TARGET_PRINT_INSN(vma, info) (*tm_print_insn) (vma, info)
711#endif
712#ifndef TARGET_PRINT_INSN_INFO
713#define TARGET_PRINT_INSN_INFO (&tm_print_insn_info)
714#endif
715
716
717
718/* Explicit test for D10V architecture.
719 USE of these macro's is *STRONGLY* discouraged. */
720
721#define GDB_TARGET_IS_D10V (TARGET_ARCHITECTURE->arch == bfd_arch_d10v)
104c1213
JM
722
723
724/* Fallback definition for EXTRACT_STRUCT_VALUE_ADDRESS */
725#ifndef EXTRACT_STRUCT_VALUE_ADDRESS
726#define EXTRACT_STRUCT_VALUE_ADDRESS_P (0)
727#define EXTRACT_STRUCT_VALUE_ADDRESS(X) (internal_error ("gdbarch: EXTRACT_STRUCT_VALUE_ADDRESS"), 0)
728#else
729#ifndef EXTRACT_STRUCT_VALUE_ADDRESS_P
730#define EXTRACT_STRUCT_VALUE_ADDRESS_P (1)
731#endif
732#endif
733
734
104c1213
JM
735/* Set the dynamic target-system-dependant parameters (architecture,
736 byte-order, ...) using information found in the BFD */
737
738extern void set_gdbarch_from_file (bfd *);
739
740
741/* Explicitly set the dynamic target-system-dependant parameters based
742 on bfd_architecture and machine. */
743
744extern void set_architecture_from_arch_mach (enum bfd_architecture, unsigned long);
745
746
e514a9d6
JM
747/* Initialize the current architecture to the "first" one we find on
748 our list. */
749
750extern void initialize_current_architecture (void);
751
104c1213
JM
752/* Helper function for targets that don't know how my arguments are
753 being passed */
754
755extern int frame_num_args_unknown (struct frame_info *fi);
756
757
758/* gdbarch trace variable */
759extern int gdbarch_debug;
760
761extern void gdbarch_dump (void);
762
763#endif
764EOF
765exec 1>&2
766#../move-if-change new-gdbarch.h gdbarch.h
59233f88 767compare_new gdbarch.h
104c1213
JM
768
769
770#
771# C file
772#
773
774exec > new-gdbarch.c
775copyright
776cat <<EOF
777
778#include "defs.h"
7355ddba 779#include "arch-utils.h"
104c1213
JM
780
781#if GDB_MULTI_ARCH
782#include "gdbcmd.h"
783#include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
784#else
785/* Just include everything in sight so that the every old definition
786 of macro is visible. */
787#include "gdb_string.h"
788#include <ctype.h>
789#include "symtab.h"
790#include "frame.h"
791#include "inferior.h"
792#include "breakpoint.h"
0596389c 793#include "gdb_wait.h"
104c1213
JM
794#include "gdbcore.h"
795#include "gdbcmd.h"
796#include "target.h"
797#include "gdbthread.h"
798#include "annotate.h"
799#include "symfile.h" /* for overlay functions */
800#endif
801#include "symcat.h"
802
803
804/* Static function declarations */
805
806static void verify_gdbarch (struct gdbarch *gdbarch);
807static void init_gdbarch_data (struct gdbarch *);
808static void init_gdbarch_swap (struct gdbarch *);
809static void swapout_gdbarch_swap (struct gdbarch *);
810static void swapin_gdbarch_swap (struct gdbarch *);
811
812/* Convenience macro for allocting typesafe memory. */
813
814#ifndef XMALLOC
815#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
816#endif
817
818
819/* Non-zero if we want to trace architecture code. */
820
821#ifndef GDBARCH_DEBUG
822#define GDBARCH_DEBUG 0
823#endif
824int gdbarch_debug = GDBARCH_DEBUG;
825
826EOF
827
828# gdbarch open the gdbarch object
829echo ""
830echo "/* Maintain the struct gdbarch object */"
831echo ""
832echo "struct gdbarch"
833echo "{"
834echo " /* basic architectural information */"
c0e8c252 835function_list | while do_read # eval read $read
104c1213
JM
836do
837 case "${class}" in
838 "i" ) echo " ${returntype} ${function};" ;;
839 esac
840done
841echo ""
842echo " /* target specific vector. */"
843echo " struct gdbarch_tdep *tdep;"
844echo ""
845echo " /* per-architecture data-pointers */"
846echo " int nr_data;"
847echo " void **data;"
848echo ""
849echo " /* per-architecture swap-regions */"
850echo " struct gdbarch_swap *swap;"
851echo ""
852cat <<EOF
853 /* Multi-arch values.
854
855 When extending this structure you must:
856
857 Add the field below.
858
859 Declare set/get functions and define the corresponding
860 macro in gdbarch.h.
861
862 gdbarch_alloc(): If zero/NULL is not a suitable default,
863 initialize the new field.
864
865 verify_gdbarch(): Confirm that the target updated the field
866 correctly.
867
868 gdbarch_dump(): Add a fprintf_unfiltered call to so that the new
869 field is dumped out
870
c0e8c252 871 \`\`startup_gdbarch()'': Append an initial value to the static
104c1213
JM
872 variable (base values on the host's c-type system).
873
874 get_gdbarch(): Implement the set/get functions (probably using
875 the macro's as shortcuts).
876
877 */
878
879EOF
c0e8c252 880function_list | while do_read # eval read $read
104c1213
JM
881do
882 case "${class}" in
883 "v" ) echo " ${returntype} ${function};" ;;
884 "f" ) echo " gdbarch_${function}_ftype *${function}${attrib};" ;;
885 esac
886done
887echo "};"
888
889# A pre-initialized vector
890echo ""
891echo ""
892cat <<EOF
893/* The default architecture uses host values (for want of a better
894 choice). */
895EOF
896echo ""
897echo "extern const struct bfd_arch_info bfd_default_arch_struct;"
898echo ""
c0e8c252 899echo "struct gdbarch startup_gdbarch = {"
104c1213 900echo " /* basic architecture information */"
c0e8c252 901function_list | while do_read # eval read $read
104c1213
JM
902do
903 case "${class}" in
63ddd37d 904 "i" )
c0e8c252 905 echo " ${startup},"
63ddd37d 906 ;;
104c1213
JM
907 esac
908done
909cat <<EOF
910 /* target specific vector */
911 NULL,
912 /*per-architecture data-pointers and swap regions */
913 0, NULL, NULL,
914 /* Multi-arch values */
915EOF
c0e8c252 916function_list | while do_read # eval read $read
104c1213
JM
917do
918 case "${class}" in
63ddd37d 919 "f" | "v" )
c0e8c252 920 echo " ${startup},"
63ddd37d 921 ;;
104c1213
JM
922 esac
923done
924cat <<EOF
c0e8c252 925 /* startup_gdbarch() */
104c1213 926};
c0e8c252 927struct gdbarch *current_gdbarch = &startup_gdbarch;
104c1213
JM
928EOF
929
930# Create a new gdbarch struct
931echo ""
932echo ""
933cat <<EOF
934/* Create a new \`\`struct gdbarch'' based in information provided by
935 \`\`struct gdbarch_info''. */
936EOF
937echo ""
938cat <<EOF
939struct gdbarch *
940gdbarch_alloc (const struct gdbarch_info *info,
941 struct gdbarch_tdep *tdep)
942{
943 struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
944 memset (gdbarch, 0, sizeof (*gdbarch));
945
946 gdbarch->tdep = tdep;
947EOF
948echo ""
c0e8c252 949function_list | while do_read # eval read $read
104c1213
JM
950do
951 case "${class}" in
952 "i" ) echo " gdbarch->${function} = info->${function};"
953 esac
954done
955echo ""
956echo " /* Force the explicit initialization of these. */"
c0e8c252 957function_list | while do_read # eval read $read
104c1213
JM
958do
959 case "${class}" in
960 "f" | "v" )
c0e8c252 961 if [ "${default}" != "" -a "${default}" != "0" ]
104c1213 962 then
c0e8c252 963 echo " gdbarch->${function} = ${default};"
104c1213
JM
964 fi
965 ;;
966 esac
967done
968cat <<EOF
969 /* gdbarch_alloc() */
970
971 return gdbarch;
972}
973EOF
974
058f20d5
JB
975# Free a gdbarch struct.
976echo ""
977echo ""
978cat <<EOF
979/* Free a gdbarch struct. This should never happen in normal
980 operation --- once you've created a gdbarch, you keep it around.
981 However, if an architecture's init function encounters an error
982 building the structure, it may need to clean up a partially
983 constructed gdbarch. */
984void
985gdbarch_free (struct gdbarch *arch)
986{
987 /* At the moment, this is trivial. */
988 free (arch);
989}
990EOF
991
104c1213
JM
992# verify a new architecture
993echo ""
994echo ""
995echo "/* Ensure that all values in a GDBARCH are reasonable. */"
996echo ""
997cat <<EOF
998static void
999verify_gdbarch (struct gdbarch *gdbarch)
1000{
1001 /* Only perform sanity checks on a multi-arch target. */
1002 if (GDB_MULTI_ARCH <= 0)
1003 return;
1004 /* fundamental */
1005 if (gdbarch->byte_order == 0)
1006 internal_error ("verify_gdbarch: byte-order unset");
1007 if (gdbarch->bfd_arch_info == NULL)
1008 internal_error ("verify_gdbarch: bfd_arch_info unset");
1009 /* Check those that need to be defined for the given multi-arch level. */
1010EOF
c0e8c252 1011function_list | while do_read # eval read $read
104c1213
JM
1012do
1013 case "${class}" in
1014 "f" | "v" )
c0e8c252
AC
1015 if [ "${invalid_p}" = "0" ]
1016 then
1017 echo " /* Skip verify of ${function}, invalid_p == 0 */"
1018 elif [ "${invalid_p}" ]
104c1213 1019 then
c0e8c252
AC
1020 echo " if ((GDB_MULTI_ARCH >= ${level})"
1021 echo " && (${invalid_p}))"
1022 echo " internal_error (\"gdbarch: verify_gdbarch: ${function} invalid\");"
1023 elif [ "${default}" ]
104c1213 1024 then
c0e8c252
AC
1025 echo " if ((GDB_MULTI_ARCH >= ${level})"
1026 echo " && (gdbarch->${function} == ${default}))"
1027 echo " internal_error (\"gdbarch: verify_gdbarch: ${function} invalid\");"
104c1213
JM
1028 fi
1029 ;;
1030 esac
1031done
1032cat <<EOF
1033}
1034EOF
1035
1036# dump the structure
1037echo ""
1038echo ""
1039echo "/* Print out the details of the current architecture. */"
1040echo ""
1041cat <<EOF
1042void
1043gdbarch_dump (void)
1044{
1045EOF
c0e8c252 1046function_list | while do_read # eval read $read
104c1213
JM
1047do
1048 case "${class}" in
1049 "f" )
1050 echo " fprintf_unfiltered (gdb_stdlog,"
1051 echo " \"gdbarch_update: ${macro} = 0x%08lx\\n\","
1052 echo " (long) current_gdbarch->${function}"
1053 echo " /*${macro} ()*/);"
1054 ;;
1055 * )
104c1213
JM
1056 if [ "${print_p}" = "#" ]
1057 then
1058 echo "#ifdef ${macro}"
1059 echo " fprintf_unfiltered (gdb_stdlog,"
1060 echo " \"gdbarch_update: ${macro} = ${fmt}\\n\","
1061 echo " ${print});"
1062 echo "#endif"
1063 elif [ "${print_p}" ]
1064 then
1065 echo " if (${print_p})"
1066 echo " fprintf_unfiltered (gdb_stdlog,"
1067 echo " \"gdbarch_update: ${macro} = ${fmt}\\n\","
1068 echo " ${print});"
1069 else
1070 echo " fprintf_unfiltered (gdb_stdlog,"
1071 echo " \"gdbarch_update: ${macro} = ${fmt}\\n\","
1072 echo " ${print});"
1073 fi
1074 ;;
1075 esac
1076done
1077echo "}"
1078
1079
1080# GET/SET
1081echo ""
1082cat <<EOF
1083struct gdbarch_tdep *
1084gdbarch_tdep (struct gdbarch *gdbarch)
1085{
1086 if (gdbarch_debug >= 2)
104c1213
JM
1087 fprintf_unfiltered (gdb_stdlog, "gdbarch_tdep called\n");
1088 return gdbarch->tdep;
1089}
1090EOF
1091echo ""
c0e8c252 1092function_list | while do_read # eval read $read
104c1213
JM
1093do
1094 case "${class}" in
1095 "f" )
1096 echo ""
1097 echo "${returntype}"
1098 if [ "${formal}" = "void" ]
1099 then
1100 echo "gdbarch_${function} (struct gdbarch *gdbarch)"
1101 else
1102 echo "gdbarch_${function} (struct gdbarch *gdbarch, ${formal})"
1103 fi
1104 echo "{"
c0e8c252
AC
1105 if default_is_fallback_p && [ "${default}" != "0" ]
1106 then
1107 echo " if (GDB_MULTI_ARCH == 0)"
1108 if [ "${returntype}" = "void" ]
1109 then
1110 echo " {"
1111 echo " ${default} (${actual});"
1112 echo " return;"
1113 echo " }"
1114 else
1115 echo " return ${default} (${actual});"
1116 fi
1117 fi
104c1213
JM
1118 echo " if (gdbarch->${function} == 0)"
1119 echo " internal_error (\"gdbarch: gdbarch_${function} invalid\");"
1120 echo " if (gdbarch_debug >= 2)"
104c1213
JM
1121 echo " fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\n\");"
1122 test "${actual}" = "-" && actual=""
1123 if [ "${returntype}" = "void" ]
1124 then
1125 echo " gdbarch->${function} (${actual});"
1126 else
1127 echo " return gdbarch->${function} (${actual});"
1128 fi
1129 echo "}"
1130 echo ""
1131 echo "void"
1132 echo "set_gdbarch_${function} (struct gdbarch *gdbarch,"
cff3e48b 1133 echo " `echo ${function} | sed -e 's/./ /g'` gdbarch_${function}_ftype ${function})"
104c1213
JM
1134 echo "{"
1135 echo " gdbarch->${function} = ${function};"
1136 echo "}"
1137 ;;
1138 "v" )
1139 echo ""
1140 echo "${returntype}"
1141 echo "gdbarch_${function} (struct gdbarch *gdbarch)"
1142 echo "{"
ba886e9d
AC
1143 if default_is_fallback_p && [ "${default}" != "0" ]
1144 then
1145 echo " if (GDB_MULTI_ARCH == 0)"
1146 echo " return ${default};"
1147 fi
c0e8c252
AC
1148 if [ "${invalid_p}" = "0" ]
1149 then
1150 echo " /* Skip verify of ${function}, invalid_p == 0 */"
1151 elif [ "${invalid_p}" ]
104c1213 1152 then
c4093a6a 1153 echo " if (${invalid_p})"
104c1213 1154 echo " internal_error (\"gdbarch: gdbarch_${function} invalid\");"
c0e8c252 1155 elif [ "${default}" ]
104c1213 1156 then
c0e8c252 1157 echo " if (gdbarch->${function} == ${default})"
104c1213
JM
1158 echo " internal_error (\"gdbarch: gdbarch_${function} invalid\");"
1159 fi
1160 echo " if (gdbarch_debug >= 2)"
104c1213
JM
1161 echo " fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\n\");"
1162 echo " return gdbarch->${function};"
1163 echo "}"
1164 echo ""
1165 echo "void"
1166 echo "set_gdbarch_${function} (struct gdbarch *gdbarch,"
cff3e48b 1167 echo " `echo ${function} | sed -e 's/./ /g'` ${returntype} ${function})"
104c1213
JM
1168 echo "{"
1169 echo " gdbarch->${function} = ${function};"
1170 echo "}"
1171 ;;
1172 "i" )
1173 echo ""
1174 echo "${returntype}"
1175 echo "gdbarch_${function} (struct gdbarch *gdbarch)"
1176 echo "{"
1177 echo " if (gdbarch_debug >= 2)"
104c1213
JM
1178 echo " fprintf_unfiltered (gdb_stdlog, \"gdbarch_${function} called\n\");"
1179 echo " return gdbarch->${function};"
1180 echo "}"
1181 ;;
1182 esac
1183done
1184
1185# All the trailing guff
1186cat <<EOF
1187
1188
1189/* Keep a registrary of per-architecture data-pointers required by GDB
1190 modules. */
1191
1192struct gdbarch_data
1193{
1194 int index;
1195};
1196
1197struct gdbarch_data_registration
1198{
1199 gdbarch_data_ftype *init;
1200 struct gdbarch_data *data;
1201 struct gdbarch_data_registration *next;
1202};
1203
1204struct gdbarch_data_registrary
1205{
1206 int nr;
1207 struct gdbarch_data_registration *registrations;
1208};
1209
1210struct gdbarch_data_registrary gdbarch_data_registrary =
1211{
1212 0, NULL,
1213};
1214
1215struct gdbarch_data *
1216register_gdbarch_data (gdbarch_data_ftype *init)
1217{
1218 struct gdbarch_data_registration **curr;
1219 for (curr = &gdbarch_data_registrary.registrations;
1220 (*curr) != NULL;
1221 curr = &(*curr)->next);
1222 (*curr) = XMALLOC (struct gdbarch_data_registration);
1223 (*curr)->next = NULL;
1224 (*curr)->init = init;
1225 (*curr)->data = XMALLOC (struct gdbarch_data);
1226 (*curr)->data->index = gdbarch_data_registrary.nr++;
1227 return (*curr)->data;
1228}
1229
1230
1231/* Walk through all the registered users initializing each in turn. */
1232
1233static void
1234init_gdbarch_data (struct gdbarch *gdbarch)
1235{
1236 struct gdbarch_data_registration *rego;
1237 gdbarch->nr_data = gdbarch_data_registrary.nr + 1;
1238 gdbarch->data = xmalloc (sizeof (void*) * gdbarch->nr_data);
1239 for (rego = gdbarch_data_registrary.registrations;
1240 rego != NULL;
1241 rego = rego->next)
1242 {
1243 if (rego->data->index < gdbarch->nr_data)
1244 gdbarch->data[rego->data->index] = rego->init ();
1245 }
1246}
1247
1248
1249/* Return the current value of the specified per-architecture
1250 data-pointer. */
1251
1252void *
1253gdbarch_data (data)
1254 struct gdbarch_data *data;
1255{
1256 if (data->index >= current_gdbarch->nr_data)
1257 internal_error ("gdbarch_data: request for non-existant data.");
1258 return current_gdbarch->data[data->index];
1259}
1260
1261
1262
1263/* Keep a registrary of swaped data required by GDB modules. */
1264
1265struct gdbarch_swap
1266{
1267 void *swap;
1268 struct gdbarch_swap_registration *source;
1269 struct gdbarch_swap *next;
1270};
1271
1272struct gdbarch_swap_registration
1273{
1274 void *data;
1275 unsigned long sizeof_data;
1276 gdbarch_swap_ftype *init;
1277 struct gdbarch_swap_registration *next;
1278};
1279
1280struct gdbarch_swap_registrary
1281{
1282 int nr;
1283 struct gdbarch_swap_registration *registrations;
1284};
1285
1286struct gdbarch_swap_registrary gdbarch_swap_registrary =
1287{
1288 0, NULL,
1289};
1290
1291void
1292register_gdbarch_swap (void *data,
1293 unsigned long sizeof_data,
1294 gdbarch_swap_ftype *init)
1295{
1296 struct gdbarch_swap_registration **rego;
1297 for (rego = &gdbarch_swap_registrary.registrations;
1298 (*rego) != NULL;
1299 rego = &(*rego)->next);
1300 (*rego) = XMALLOC (struct gdbarch_swap_registration);
1301 (*rego)->next = NULL;
1302 (*rego)->init = init;
1303 (*rego)->data = data;
1304 (*rego)->sizeof_data = sizeof_data;
1305}
1306
1307
1308static void
1309init_gdbarch_swap (struct gdbarch *gdbarch)
1310{
1311 struct gdbarch_swap_registration *rego;
1312 struct gdbarch_swap **curr = &gdbarch->swap;
1313 for (rego = gdbarch_swap_registrary.registrations;
1314 rego != NULL;
1315 rego = rego->next)
1316 {
1317 if (rego->data != NULL)
1318 {
1319 (*curr) = XMALLOC (struct gdbarch_swap);
1320 (*curr)->source = rego;
1321 (*curr)->swap = xmalloc (rego->sizeof_data);
1322 (*curr)->next = NULL;
1323 memset (rego->data, 0, rego->sizeof_data);
1324 curr = &(*curr)->next;
1325 }
1326 if (rego->init != NULL)
1327 rego->init ();
1328 }
1329}
1330
1331static void
1332swapout_gdbarch_swap (struct gdbarch *gdbarch)
1333{
1334 struct gdbarch_swap *curr;
1335 for (curr = gdbarch->swap;
1336 curr != NULL;
1337 curr = curr->next)
1338 memcpy (curr->swap, curr->source->data, curr->source->sizeof_data);
1339}
1340
1341static void
1342swapin_gdbarch_swap (struct gdbarch *gdbarch)
1343{
1344 struct gdbarch_swap *curr;
1345 for (curr = gdbarch->swap;
1346 curr != NULL;
1347 curr = curr->next)
1348 memcpy (curr->source->data, curr->swap, curr->source->sizeof_data);
1349}
1350
1351
1352/* Keep a registrary of the architectures known by GDB. */
1353
1354struct gdbarch_init_registration
1355{
1356 enum bfd_architecture bfd_architecture;
1357 gdbarch_init_ftype *init;
1358 struct gdbarch_list *arches;
1359 struct gdbarch_init_registration *next;
1360};
1361
1362static struct gdbarch_init_registration *gdbarch_init_registrary = NULL;
1363
1364void
1365register_gdbarch_init (enum bfd_architecture bfd_architecture,
1366 gdbarch_init_ftype *init)
1367{
1368 struct gdbarch_init_registration **curr;
1369 const struct bfd_arch_info *bfd_arch_info;
1370 /* Check that BFD reconizes this architecture */
1371 bfd_arch_info = bfd_lookup_arch (bfd_architecture, 0);
1372 if (bfd_arch_info == NULL)
1373 {
1374 internal_error ("gdbarch: Attempt to register unknown architecture (%d)", bfd_architecture);
1375 }
1376 /* Check that we haven't seen this architecture before */
1377 for (curr = &gdbarch_init_registrary;
1378 (*curr) != NULL;
1379 curr = &(*curr)->next)
1380 {
1381 if (bfd_architecture == (*curr)->bfd_architecture)
1382 internal_error ("gdbarch: Duplicate registraration of architecture (%s)",
1383 bfd_arch_info->printable_name);
1384 }
1385 /* log it */
1386 if (gdbarch_debug)
1387 fprintf_unfiltered (gdb_stdlog, "register_gdbarch_init (%s, 0x%08lx)\n",
1388 bfd_arch_info->printable_name,
1389 (long) init);
1390 /* Append it */
1391 (*curr) = XMALLOC (struct gdbarch_init_registration);
1392 (*curr)->bfd_architecture = bfd_architecture;
1393 (*curr)->init = init;
1394 (*curr)->arches = NULL;
1395 (*curr)->next = NULL;
1396}
1397
1398
1399
1400/* Look for an architecture using gdbarch_info. Base search on only
1401 BFD_ARCH_INFO and BYTE_ORDER. */
1402
1403struct gdbarch_list *
1404gdbarch_list_lookup_by_info (struct gdbarch_list *arches,
1405 const struct gdbarch_info *info)
1406{
1407 for (; arches != NULL; arches = arches->next)
1408 {
1409 if (info->bfd_arch_info != arches->gdbarch->bfd_arch_info)
1410 continue;
1411 if (info->byte_order != arches->gdbarch->byte_order)
1412 continue;
1413 return arches;
1414 }
1415 return NULL;
1416}
1417
1418
1419/* Update the current architecture. Return ZERO if the update request
1420 failed. */
1421
1422int
1423gdbarch_update (struct gdbarch_info info)
1424{
1425 struct gdbarch *new_gdbarch;
1426 struct gdbarch_list **list;
1427 struct gdbarch_init_registration *rego;
1428
1429 /* Fill in any missing bits. Most important is the bfd_architecture
1430 which is used to select the target architecture. */
1431 if (info.bfd_architecture == bfd_arch_unknown)
1432 {
1433 if (info.bfd_arch_info != NULL)
1434 info.bfd_architecture = info.bfd_arch_info->arch;
1435 else if (info.abfd != NULL)
1436 info.bfd_architecture = bfd_get_arch (info.abfd);
1437 /* FIXME - should query BFD for its default architecture. */
1438 else
1439 info.bfd_architecture = current_gdbarch->bfd_arch_info->arch;
1440 }
1441 if (info.bfd_arch_info == NULL)
1442 {
1443 if (target_architecture_auto && info.abfd != NULL)
1444 info.bfd_arch_info = bfd_get_arch_info (info.abfd);
1445 else
1446 info.bfd_arch_info = current_gdbarch->bfd_arch_info;
1447 }
1448 if (info.byte_order == 0)
1449 {
1450 if (target_byte_order_auto && info.abfd != NULL)
1451 info.byte_order = (bfd_big_endian (info.abfd) ? BIG_ENDIAN
1452 : bfd_little_endian (info.abfd) ? LITTLE_ENDIAN
1453 : 0);
1454 else
1455 info.byte_order = current_gdbarch->byte_order;
1456 /* FIXME - should query BFD for its default byte-order. */
1457 }
1458 /* A default for abfd? */
1459
1460 /* Find the target that knows about this architecture. */
1461 for (rego = gdbarch_init_registrary;
1462 rego != NULL && rego->bfd_architecture != info.bfd_architecture;
1463 rego = rego->next);
1464 if (rego == NULL)
1465 {
1466 if (gdbarch_debug)
1467 fprintf_unfiltered (gdb_stdlog, "gdbarch_update: No matching architecture\n");
1468 return 0;
1469 }
1470
1471 if (gdbarch_debug)
1472 {
1473 fprintf_unfiltered (gdb_stdlog,
1474 "gdbarch_update: info.bfd_architecture %d (%s)\n",
1475 info.bfd_architecture,
1476 bfd_lookup_arch (info.bfd_architecture, 0)->printable_name);
1477 fprintf_unfiltered (gdb_stdlog,
1478 "gdbarch_update: info.bfd_arch_info %s\n",
1479 (info.bfd_arch_info != NULL
1480 ? info.bfd_arch_info->printable_name
1481 : "(null)"));
1482 fprintf_unfiltered (gdb_stdlog,
1483 "gdbarch_update: info.byte_order %d (%s)\n",
1484 info.byte_order,
1485 (info.byte_order == BIG_ENDIAN ? "big"
1486 : info.byte_order == LITTLE_ENDIAN ? "little"
1487 : "default"));
1488 fprintf_unfiltered (gdb_stdlog,
1489 "gdbarch_update: info.abfd 0x%lx\n",
1490 (long) info.abfd);
1491 fprintf_unfiltered (gdb_stdlog,
1492 "gdbarch_update: info.tdep_info 0x%lx\n",
1493 (long) info.tdep_info);
1494 }
1495
1496 /* Ask the target for a replacement architecture. */
1497 new_gdbarch = rego->init (info, rego->arches);
1498
1499 /* Did the target like it? No. Reject the change. */
1500 if (new_gdbarch == NULL)
1501 {
1502 if (gdbarch_debug)
1503 fprintf_unfiltered (gdb_stdlog, "gdbarch_update: Target rejected architecture\n");
1504 return 0;
1505 }
1506
1507 /* Did the architecture change? No. Do nothing. */
1508 if (current_gdbarch == new_gdbarch)
1509 {
1510 if (gdbarch_debug)
1511 fprintf_unfiltered (gdb_stdlog, "gdbarch_update: Architecture 0x%08lx (%s) unchanged\n",
1512 (long) new_gdbarch,
1513 new_gdbarch->bfd_arch_info->printable_name);
1514 return 1;
1515 }
1516
1517 /* Swap all data belonging to the old target out */
1518 swapout_gdbarch_swap (current_gdbarch);
1519
1520 /* Is this a pre-existing architecture? Yes. Swap it in. */
1521 for (list = &rego->arches;
1522 (*list) != NULL;
1523 list = &(*list)->next)
1524 {
1525 if ((*list)->gdbarch == new_gdbarch)
1526 {
1527 if (gdbarch_debug)
1528 fprintf_unfiltered (gdb_stdlog, "gdbarch_update: Previous architecture 0x%08lx (%s) selected\n",
1529 (long) new_gdbarch,
1530 new_gdbarch->bfd_arch_info->printable_name);
1531 current_gdbarch = new_gdbarch;
1532 swapin_gdbarch_swap (new_gdbarch);
1533 return 1;
1534 }
1535 }
1536
1537 /* Append this new architecture to this targets list. */
1538 (*list) = XMALLOC (struct gdbarch_list);
1539 (*list)->next = NULL;
1540 (*list)->gdbarch = new_gdbarch;
1541
1542 /* Switch to this new architecture. Dump it out. */
1543 current_gdbarch = new_gdbarch;
1544 if (gdbarch_debug)
1545 {
1546 fprintf_unfiltered (gdb_stdlog,
1547 "gdbarch_update: New architecture 0x%08lx (%s) selected\n",
1548 (long) new_gdbarch,
1549 new_gdbarch->bfd_arch_info->printable_name);
1550 gdbarch_dump ();
1551 }
1552
1553 /* Check that the newly installed architecture is valid. */
1554 verify_gdbarch (new_gdbarch);
1555
1556 /* Initialize the per-architecture memory (swap) areas.
1557 CURRENT_GDBARCH must be update before these modules are
1558 called. */
1559 init_gdbarch_swap (new_gdbarch);
1560
1561 /* Initialize the per-architecture data-pointer of all parties that
1562 registered an interest in this architecture. CURRENT_GDBARCH
1563 must be updated before these modules are called. */
1564 init_gdbarch_data (new_gdbarch);
1565
1566 return 1;
1567}
1568
1569
1570
1571/* Functions to manipulate the endianness of the target. */
1572
1573#ifdef TARGET_BYTE_ORDER_SELECTABLE
1574/* compat - Catch old targets that expect a selectable byte-order to
1575 default to BIG_ENDIAN */
1576#ifndef TARGET_BYTE_ORDER_DEFAULT
1577#define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
1578#endif
1579#endif
1580#if !TARGET_BYTE_ORDER_SELECTABLE_P
1581#ifndef TARGET_BYTE_ORDER_DEFAULT
1582/* compat - Catch old non byte-order selectable targets that do not
1583 define TARGET_BYTE_ORDER_DEFAULT and instead expect
1584 TARGET_BYTE_ORDER to be used as the default. For targets that
1585 defined neither TARGET_BYTE_ORDER nor TARGET_BYTE_ORDER_DEFAULT the
1586 below will get a strange compiler warning. */
1587#define TARGET_BYTE_ORDER_DEFAULT TARGET_BYTE_ORDER
1588#endif
1589#endif
1590#ifndef TARGET_BYTE_ORDER_DEFAULT
1591#define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN /* arbitrary */
1592#endif
1593int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
1594int target_byte_order_auto = 1;
1595
1596/* Chain containing the \"set endian\" commands. */
1597static struct cmd_list_element *endianlist = NULL;
1598
1599/* Called by \`\`show endian''. */
1600static void
1601show_endian (char *args, int from_tty)
1602{
1603 char *msg =
1604 (TARGET_BYTE_ORDER_AUTO
1605 ? "The target endianness is set automatically (currently %s endian)\n"
1606 : "The target is assumed to be %s endian\n");
1607 printf_unfiltered (msg, (TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little"));
1608}
1609
1610/* Called if the user enters \`\`set endian'' without an argument. */
1611static void
1612set_endian (char *args, int from_tty)
1613{
1614 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
1615 show_endian (args, from_tty);
1616}
1617
1618/* Called by \`\`set endian big''. */
1619static void
1620set_endian_big (char *args, int from_tty)
1621{
1622 if (TARGET_BYTE_ORDER_SELECTABLE_P)
1623 {
1624 target_byte_order = BIG_ENDIAN;
1625 target_byte_order_auto = 0;
1626 if (GDB_MULTI_ARCH)
1627 {
1628 struct gdbarch_info info;
1629 memset (&info, 0, sizeof info);
1630 info.byte_order = BIG_ENDIAN;
1631 gdbarch_update (info);
1632 }
1633 }
1634 else
1635 {
1636 printf_unfiltered ("Byte order is not selectable.");
1637 show_endian (args, from_tty);
1638 }
1639}
1640
1641/* Called by \`\`set endian little''. */
1642static void
1643set_endian_little (char *args, int from_tty)
1644{
1645 if (TARGET_BYTE_ORDER_SELECTABLE_P)
1646 {
1647 target_byte_order = LITTLE_ENDIAN;
1648 target_byte_order_auto = 0;
1649 if (GDB_MULTI_ARCH)
1650 {
1651 struct gdbarch_info info;
1652 memset (&info, 0, sizeof info);
1653 info.byte_order = LITTLE_ENDIAN;
1654 gdbarch_update (info);
1655 }
1656 }
1657 else
1658 {
1659 printf_unfiltered ("Byte order is not selectable.");
1660 show_endian (args, from_tty);
1661 }
1662}
1663
1664/* Called by \`\`set endian auto''. */
1665static void
1666set_endian_auto (char *args, int from_tty)
1667{
1668 if (TARGET_BYTE_ORDER_SELECTABLE_P)
1669 {
1670 target_byte_order_auto = 1;
1671 }
1672 else
1673 {
1674 printf_unfiltered ("Byte order is not selectable.");
1675 show_endian (args, from_tty);
1676 }
1677}
1678
1679/* Set the endianness from a BFD. */
1680static void
1681set_endian_from_file (bfd *abfd)
1682{
1683 if (TARGET_BYTE_ORDER_SELECTABLE_P)
1684 {
1685 int want;
1686
1687 if (bfd_big_endian (abfd))
1688 want = BIG_ENDIAN;
1689 else
1690 want = LITTLE_ENDIAN;
1691 if (TARGET_BYTE_ORDER_AUTO)
1692 target_byte_order = want;
1693 else if (TARGET_BYTE_ORDER != want)
1694 warning ("%s endian file does not match %s endian target.",
1695 want == BIG_ENDIAN ? "big" : "little",
1696 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
1697 }
1698 else
1699 {
1700 if (bfd_big_endian (abfd)
1701 ? TARGET_BYTE_ORDER != BIG_ENDIAN
1702 : TARGET_BYTE_ORDER == BIG_ENDIAN)
1703 warning ("%s endian file does not match %s endian target.",
1704 bfd_big_endian (abfd) ? "big" : "little",
1705 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
1706 }
1707}
1708
1709
1710
1711/* Functions to manipulate the architecture of the target */
1712
1713enum set_arch { set_arch_auto, set_arch_manual };
1714
1715int target_architecture_auto = 1;
1716extern const struct bfd_arch_info bfd_default_arch_struct;
1717const struct bfd_arch_info *target_architecture = &bfd_default_arch_struct;
1718int (*target_architecture_hook) (const struct bfd_arch_info *ap);
1719
1720static void show_endian (char *, int);
1721static void set_endian (char *, int);
1722static void set_endian_big (char *, int);
1723static void set_endian_little (char *, int);
1724static void set_endian_auto (char *, int);
1725static void set_endian_from_file (bfd *);
1726static int arch_ok (const struct bfd_arch_info *arch);
1727static void set_arch (const struct bfd_arch_info *arch, enum set_arch type);
1728static void show_architecture (char *, int);
1729static void set_architecture (char *, int);
1730static void info_architecture (char *, int);
1731static void set_architecture_from_file (bfd *);
1732
1733/* Do the real work of changing the current architecture */
1734
1735static int
1736arch_ok (const struct bfd_arch_info *arch)
1737{
1738 /* Should be performing the more basic check that the binary is
1739 compatible with GDB. */
1740 /* Check with the target that the architecture is valid. */
1741 return (target_architecture_hook == NULL
1742 || target_architecture_hook (arch));
1743}
1744
1745static void
1746set_arch (const struct bfd_arch_info *arch,
1747 enum set_arch type)
1748{
1749 switch (type)
1750 {
1751 case set_arch_auto:
1752 if (!arch_ok (arch))
1753 warning ("Target may not support %s architecture",
1754 arch->printable_name);
1755 target_architecture = arch;
1756 break;
1757 case set_arch_manual:
1758 if (!arch_ok (arch))
1759 {
1760 printf_unfiltered ("Target does not support \`%s' architecture.\n",
1761 arch->printable_name);
1762 }
1763 else
1764 {
1765 target_architecture_auto = 0;
1766 target_architecture = arch;
1767 }
1768 break;
1769 }
1770 if (gdbarch_debug)
1771 gdbarch_dump ();
1772}
1773
1774/* Called if the user enters \`\`show architecture'' without an argument. */
1775static void
1776show_architecture (char *args, int from_tty)
1777{
1778 const char *arch;
1779 arch = TARGET_ARCHITECTURE->printable_name;
1780 if (target_architecture_auto)
1781 printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
1782 else
1783 printf_filtered ("The target architecture is assumed to be %s\n", arch);
1784}
1785
1786/* Called if the user enters \`\`set architecture'' with or without an
1787 argument. */
1788static void
1789set_architecture (char *args, int from_tty)
1790{
1791 if (args == NULL)
1792 {
1793 printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
1794 }
1795 else if (strcmp (args, "auto") == 0)
1796 {
1797 target_architecture_auto = 1;
1798 }
1799 else if (GDB_MULTI_ARCH)
1800 {
1801 const struct bfd_arch_info *arch = bfd_scan_arch (args);
1802 if (arch == NULL)
1803 printf_unfiltered ("Architecture \`%s' not reconized.\n", args);
1804 else
1805 {
1806 struct gdbarch_info info;
1807 memset (&info, 0, sizeof info);
1808 info.bfd_arch_info = arch;
1809 if (gdbarch_update (info))
1810 target_architecture_auto = 0;
1811 else
1812 printf_unfiltered ("Architecture \`%s' not reconized.\n", args);
1813 }
1814 }
1815 else
1816 {
1817 const struct bfd_arch_info *arch = bfd_scan_arch (args);
1818 if (arch != NULL)
1819 set_arch (arch, set_arch_manual);
1820 else
1821 printf_unfiltered ("Architecture \`%s' not reconized.\n", args);
1822 }
1823}
1824
1825/* Called if the user enters \`\`info architecture'' without an argument. */
1826static void
1827info_architecture (char *args, int from_tty)
1828{
1829 enum bfd_architecture a;
1830 if (GDB_MULTI_ARCH)
1831 {
1832 if (gdbarch_init_registrary != NULL)
1833 {
1834 struct gdbarch_init_registration *rego;
1835 printf_filtered ("Available architectures are:\n");
1836 for (rego = gdbarch_init_registrary;
1837 rego != NULL;
1838 rego = rego->next)
1839 {
1840 const struct bfd_arch_info *ap;
1841 ap = bfd_lookup_arch (rego->bfd_architecture, 0);
1842 if (ap != NULL)
1843 {
1844 do
1845 {
1846 printf_filtered (" %s", ap->printable_name);
1847 ap = ap->next;
1848 }
1849 while (ap != NULL);
1850 printf_filtered ("\n");
1851 }
1852 }
1853 }
1854 else
1855 {
1856 printf_filtered ("There are no available architectures.\n");
1857 }
1858 return;
1859 }
1860 printf_filtered ("Available architectures are:\n");
1861 for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
1862 {
1863 const struct bfd_arch_info *ap = bfd_lookup_arch (a, 0);
1864 if (ap != NULL)
1865 {
1866 do
1867 {
1868 printf_filtered (" %s", ap->printable_name);
1869 ap = ap->next;
1870 }
1871 while (ap != NULL);
1872 printf_filtered ("\n");
1873 }
1874 }
1875}
1876
1877/* Set the architecture from arch/machine */
1878void
1879set_architecture_from_arch_mach (arch, mach)
1880 enum bfd_architecture arch;
1881 unsigned long mach;
1882{
1883 const struct bfd_arch_info *wanted = bfd_lookup_arch (arch, mach);
1884 if (wanted != NULL)
1885 set_arch (wanted, set_arch_manual);
1886 else
1887 internal_error ("gdbarch: hardwired architecture/machine not reconized");
1888}
1889
1890/* Set the architecture from a BFD */
1891static void
1892set_architecture_from_file (bfd *abfd)
1893{
1894 const struct bfd_arch_info *wanted = bfd_get_arch_info (abfd);
1895 if (target_architecture_auto)
1896 {
1897 set_arch (wanted, set_arch_auto);
1898 }
1899 else if (wanted != target_architecture)
1900 {
1901 warning ("%s architecture file may be incompatible with %s target.",
1902 wanted->printable_name,
1903 target_architecture->printable_name);
1904 }
1905}
1906
1907
1908/* Misc helper functions for targets. */
1909
1910int
1911frame_num_args_unknown (fi)
1912 struct frame_info *fi;
1913{
1914 return -1;
1915}
1916
1917
1918int
1919generic_register_convertible_not (num)
1920 int num;
1921{
1922 return 0;
1923}
1924
4478b372 1925
104c1213
JM
1926/* Disassembler */
1927
1928/* Pointer to the target-dependent disassembly function. */
1929int (*tm_print_insn) (bfd_vma, disassemble_info *);
1930disassemble_info tm_print_insn_info;
1931
1932
1933
1934/* Set the dynamic target-system-dependant parameters (architecture,
1935 byte-order) using information found in the BFD */
1936
1937void
1938set_gdbarch_from_file (abfd)
1939 bfd *abfd;
1940{
1941 if (GDB_MULTI_ARCH)
1942 {
1943 struct gdbarch_info info;
1944 memset (&info, 0, sizeof info);
1945 info.abfd = abfd;
1946 gdbarch_update (info);
1947 return;
1948 }
1949 set_architecture_from_file (abfd);
1950 set_endian_from_file (abfd);
1951}
1952
1953
e514a9d6
JM
1954/* Initialize the current architecture. */
1955void
1956initialize_current_architecture ()
1957{
1958 if (GDB_MULTI_ARCH)
1959 {
1960 struct gdbarch_init_registration *rego;
1961 const struct bfd_arch_info *chosen = NULL;
1962 for (rego = gdbarch_init_registrary; rego != NULL; rego = rego->next)
1963 {
1964 const struct bfd_arch_info *ap
1965 = bfd_lookup_arch (rego->bfd_architecture, 0);
1966
1967 /* Choose the first architecture alphabetically. */
1968 if (chosen == NULL
1969 || strcmp (ap->printable_name, chosen->printable_name) < 0)
1970 chosen = ap;
1971 }
1972
1973 if (chosen != NULL)
1974 {
1975 struct gdbarch_info info;
1976 memset (&info, 0, sizeof info);
1977 info.bfd_arch_info = chosen;
1978 gdbarch_update (info);
1979 }
1980 }
1981}
1982
104c1213
JM
1983extern void _initialize_gdbarch (void);
1984void
1985_initialize_gdbarch ()
1986{
59233f88
AC
1987 struct cmd_list_element *c;
1988
104c1213
JM
1989 add_prefix_cmd ("endian", class_support, set_endian,
1990 "Set endianness of target.",
1991 &endianlist, "set endian ", 0, &setlist);
1992 add_cmd ("big", class_support, set_endian_big,
1993 "Set target as being big endian.", &endianlist);
1994 add_cmd ("little", class_support, set_endian_little,
1995 "Set target as being little endian.", &endianlist);
1996 add_cmd ("auto", class_support, set_endian_auto,
1997 "Select target endianness automatically.", &endianlist);
1998 add_cmd ("endian", class_support, show_endian,
1999 "Show endianness of target.", &showlist);
2000
2001 add_cmd ("architecture", class_support, set_architecture,
2002 "Set architecture of target.", &setlist);
2003 add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
2004 add_cmd ("architecture", class_support, show_architecture,
2005 "Show architecture of target.", &showlist);
2006 add_cmd ("architecture", class_support, info_architecture,
2007 "List supported target architectures", &infolist);
2008
2009 INIT_DISASSEMBLE_INFO_NO_ARCH (tm_print_insn_info, gdb_stdout, (fprintf_ftype)fprintf_filtered);
2010 tm_print_insn_info.flavour = bfd_target_unknown_flavour;
2011 tm_print_insn_info.read_memory_func = dis_asm_read_memory;
2012 tm_print_insn_info.memory_error_func = dis_asm_memory_error;
2013 tm_print_insn_info.print_address_func = dis_asm_print_address;
2014
59233f88 2015 add_show_from_set (add_set_cmd ("arch",
104c1213
JM
2016 class_maintenance,
2017 var_zinteger,
2018 (char *)&gdbarch_debug,
2019 "Set architecture debugging.\n\\
59233f88
AC
2020When non-zero, architecture debugging is enabled.", &setdebuglist),
2021 &showdebuglist);
2022 c = add_set_cmd ("archdebug",
2023 class_maintenance,
2024 var_zinteger,
2025 (char *)&gdbarch_debug,
2026 "Set architecture debugging.\n\\
2027When non-zero, architecture debugging is enabled.", &setlist);
2028
2029 deprecate_cmd (c, "set debug arch");
2030 deprecate_cmd (add_show_from_set (c, &showlist), "show debug arch");
104c1213
JM
2031}
2032EOF
2033
2034# close things off
2035exec 1>&2
2036#../move-if-change new-gdbarch.c gdbarch.c
59233f88 2037compare_new gdbarch.c
This page took 0.166011 seconds and 4 git commands to generate.