1 /* Sysroff object format dumper.
2 Copyright (C) 1994, 95, 98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* Written by Steve Chamberlain <sac@cygnus.com>.
24 This program reads a SYSROFF object file and prints it in an
25 almost human readable form to stdout. */
32 #include <libiberty.h>
36 #define PROGRAM_VERSION "1.0"
39 static int segmented_p
;
41 static int addrsize
= 4;
45 getCHARS (ptr
, idx
, size
, max
)
61 /* Got to work out the length of the string from self */
67 r
= xcalloc (b
+ 1, 1);
68 memcpy (r
, ptr
+ oc
, b
);
82 printf ("\n************************************************************\n");
84 for (i
= 0; i
< size
; i
+= span
)
86 for (j
= 0; j
< span
; j
++)
89 printf ("%02x ", ptr
[i
+ j
]);
94 for (j
= 0; j
< span
&& j
+ i
< size
; j
++)
97 if (c
< 32 || c
> 127)
112 size
= getc (file
) - 2;
113 fread (ptr
, 1, size
, file
);
114 sum
= code
+ size
+ 2;
115 for (i
= 0; i
< size
; i
++)
120 if ((sum
& 0xff) != 0xff)
122 printf ("SUM IS %x\n", sum
);
131 getBARRAY (ptr
, idx
, dsize
, max
)
140 int size
= ptr
[byte
++];
142 res
.data
= (unsigned char *) xmalloc (size
);
143 for (i
= 0; i
< size
; i
++)
145 res
.data
[i
] = ptr
[byte
++];
151 getINT (ptr
, idx
, size
, max
)
176 n
= (ptr
[byte
+ 0] << 8) + ptr
[byte
+ 1];
179 n
= (ptr
[byte
+ 0] << 24) + (ptr
[byte
+ 1] << 16) + (ptr
[byte
+ 2] << 8) + (ptr
[byte
+ 3]);
189 getBITS (ptr
, idx
, size
, max
)
202 return (ptr
[byte
] >> (8 - bit
- size
)) & ((1 << size
) - 1);
206 itheader (name
, code
)
210 printf ("\n%s 0x%02x\n", name
, code
);
218 for (i
= 0; i
< indent
; i
++)
236 printf ("%d (", y
->len
);
237 for (x
= 0; x
< y
->len
; x
++)
239 printf ("(%02x %c)", y
->data
[x
], isprint (y
->data
[x
]) ? y
->data
[x
] : '.');
244 #define SYSROFF_PRINT
245 #define SYSROFF_SWAP_IN
250 * FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
251 * hack the special case of the tr block, which has no contents. So we
252 * implement our own functions for reading in and printing out the tr
256 #define IT_tr_CODE 0x7f
267 sysroff_print_tr_out()
269 itheader("tr", IT_tr_CODE
);
279 if ((c
& 0x7f) != type
)
290 sysroff_swap_cs_in (&dummy
);
291 sysroff_print_cs_out (&dummy
);
297 sysroff_swap_dln_in (&dummy
);
298 sysroff_print_dln_out (&dummy
);
304 sysroff_swap_hd_in (&dummy
);
305 addrsize
= dummy
.afl
;
306 sysroff_print_hd_out (&dummy
);
312 sysroff_swap_dar_in (&dummy
);
313 sysroff_print_dar_out (&dummy
);
319 sysroff_swap_dsy_in (&dummy
);
320 sysroff_print_dsy_out (&dummy
);
326 sysroff_swap_dfp_in (&dummy
);
327 sysroff_print_dfp_out (&dummy
);
333 sysroff_swap_dso_in (&dummy
);
334 sysroff_print_dso_out (&dummy
);
340 sysroff_swap_dpt_in (&dummy
);
341 sysroff_print_dpt_out (&dummy
);
347 sysroff_swap_den_in (&dummy
);
348 sysroff_print_den_out (&dummy
);
354 sysroff_swap_dbt_in (&dummy
);
355 sysroff_print_dbt_out (&dummy
);
361 sysroff_swap_dty_in (&dummy
);
362 sysroff_print_dty_out (&dummy
);
368 sysroff_swap_un_in (&dummy
);
369 sysroff_print_un_out (&dummy
);
375 sysroff_swap_sc_in (&dummy
);
376 sysroff_print_sc_out (&dummy
);
382 sysroff_swap_er_in (&dummy
);
383 sysroff_print_er_out (&dummy
);
389 sysroff_swap_ed_in (&dummy
);
390 sysroff_print_ed_out (&dummy
);
396 sysroff_swap_sh_in (&dummy
);
397 sysroff_print_sh_out (&dummy
);
403 sysroff_swap_ob_in (&dummy
);
404 sysroff_print_ob_out (&dummy
);
410 sysroff_swap_rl_in (&dummy
);
411 sysroff_print_rl_out (&dummy
);
417 sysroff_swap_du_in (&dummy
);
419 sysroff_print_du_out (&dummy
);
425 sysroff_swap_dus_in (&dummy
);
426 sysroff_print_dus_out (&dummy
);
432 sysroff_swap_dul_in (&dummy
);
433 sysroff_print_dul_out (&dummy
);
439 sysroff_swap_dss_in (&dummy
);
440 sysroff_print_dss_out (&dummy
);
446 sysroff_swap_hs_in (&dummy
);
447 sysroff_print_hs_out (&dummy
);
453 sysroff_swap_dps_in (&dummy
);
454 sysroff_print_dps_out (&dummy
);
459 sysroff_swap_tr_in ();
460 sysroff_print_tr_out ();
466 sysroff_swap_dds_in (&dummy
);
467 sysroff_print_dds_out (&dummy
);
471 printf ("GOT A %x\n", c
);
487 /* This is no longer used. */
492 while (opt (IT_un_CODE
))
496 while (getone (IT_sc_CODE
))
499 while (getone (IT_er_CODE
))
502 while (getone (IT_ed_CODE
))
511 /* This is no longer used. */
516 while (getone (IT_sh_CODE
))
518 while (getone (IT_ob_CODE
))
520 while (getone (IT_rl_CODE
))
533 printf ("WANTED %x!!\n", x
);
551 static void derived_type ();
556 tab (1, "SYMBOL INFO");
557 while (opt (IT_dsy_CODE
))
559 if (opt (IT_dty_CODE
))
572 tab (1, "DERIVED TYPE");
575 if (opt (IT_dpp_CODE
))
580 else if (opt (IT_dfp_CODE
))
585 else if (opt (IT_den_CODE
))
590 else if (opt (IT_den_CODE
))
595 else if (opt (IT_dds_CODE
))
600 else if (opt (IT_dar_CODE
))
603 else if (opt (IT_dpt_CODE
))
606 else if (opt (IT_dul_CODE
))
609 else if (opt (IT_dse_CODE
))
612 else if (opt (IT_dot_CODE
))
624 /* This is no longer used. */
629 tab (1, "PROGRAM STRUCTURE");
630 while (opt (IT_dps_CODE
))
644 /* This is no longer used. */
649 tab (1, "DEBUG LIST");
653 program_structure ();
667 tab (1, "MODULE***\n");
676 while (getone (c
) && c
!= IT_tr_CODE
);
708 show_usage (file
, status
)
712 fprintf (file
, _("Usage: %s [-hV] in-file\n"), program_name
);
719 printf (_("%s: Print a human readable interpretation of a SYSROFF object file\n"),
721 show_usage (stdout
, 0);
729 char *input_file
= NULL
;
731 static struct option long_options
[] =
733 {"help", no_argument
, 0, 'h'},
734 {"version", no_argument
, 0, 'V'},
735 {NULL
, no_argument
, 0, 0}
738 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
739 setlocale (LC_MESSAGES
, "");
741 bindtextdomain (PACKAGE
, LOCALEDIR
);
742 textdomain (PACKAGE
);
744 program_name
= av
[0];
745 xmalloc_set_program_name (program_name
);
747 while ((opt
= getopt_long (ac
, av
, "hV", long_options
, (int *) NULL
)) != EOF
)
755 printf (_("GNU %s version %s\n"), program_name
, PROGRAM_VERSION
);
761 show_usage (stderr
, 1);
766 /* The input and output files may be named on the command line. */
770 input_file
= av
[optind
];
775 fprintf (stderr
, _("%s: no input file specified\n"),
780 file
= fopen (input_file
, FOPEN_RB
);
783 fprintf (stderr
, _("%s: cannot open input file %s\n"),
784 program_name
, input_file
);