1 /* Sysroff object format dumper.
2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* Written by Steve Chamberlain <sac@cygnus.com>.
25 This program reads a SYSROFF object file and prints it in an
26 almost human readable form to stdout. */
30 #include "safe-ctype.h"
33 #include "libiberty.h"
38 static int segmented_p
;
40 static int addrsize
= 4;
43 static void dh (unsigned char *, int);
44 static void itheader (char *, int);
46 static void tabout (void);
47 static void pbarray (barray
*);
48 static int getone (int);
50 static void must (int);
51 static void tab (int, char *);
52 static void dump_symbol_info (void);
53 static void derived_type (void);
54 static void module (void);
55 static void show_usage (FILE *, int);
57 extern char *getCHARS (unsigned char *, int *, int, int);
58 extern int fillup (char *);
59 extern barray
getBARRAY (unsigned char *, int *, int, int);
60 extern int getINT (unsigned char *, int *, int, int);
61 extern int getBITS (char *, int *, int, int);
62 extern void sysroff_swap_tr_in (void);
63 extern void sysroff_print_tr_out (void);
64 extern int main (int, char **);
67 getCHARS (unsigned char *ptr
, int *idx
, int size
, int max
)
78 /* Got to work out the length of the string from self. */
84 r
= xcalloc (b
+ 1, 1);
85 memcpy (r
, ptr
+ oc
, b
);
92 dh (unsigned char *ptr
, int size
)
98 printf ("\n************************************************************\n");
100 for (i
= 0; i
< size
; i
+= span
)
102 for (j
= 0; j
< span
; j
++)
105 printf ("%02x ", ptr
[i
+ j
]);
110 for (j
= 0; j
< span
&& j
+ i
< size
; j
++)
114 if (c
< 32 || c
> 127)
130 size
= getc (file
) - 2;
131 fread (ptr
, 1, size
, file
);
132 sum
= code
+ size
+ 2;
134 for (i
= 0; i
< size
; i
++)
137 if ((sum
& 0xff) != 0xff)
138 printf ("SUM IS %x\n", sum
);
147 getBARRAY (unsigned char *ptr
, int *idx
, int dsize ATTRIBUTE_UNUSED
,
148 int max ATTRIBUTE_UNUSED
)
153 int size
= ptr
[byte
++];
156 res
.data
= (unsigned char *) xmalloc (size
);
158 for (i
= 0; i
< size
; i
++)
159 res
.data
[i
] = ptr
[byte
++];
165 getINT (unsigned char *ptr
, int *idx
, int size
, int max
)
187 n
= (ptr
[byte
+ 0] << 8) + ptr
[byte
+ 1];
190 n
= (ptr
[byte
+ 0] << 24) + (ptr
[byte
+ 1] << 16) + (ptr
[byte
+ 2] << 8) + (ptr
[byte
+ 3]);
201 getBITS (char *ptr
, int *idx
, int size
, int max
)
211 return (ptr
[byte
] >> (8 - bit
- size
)) & ((1 << size
) - 1);
215 itheader (char *name
, int code
)
217 printf ("\n%s 0x%02x\n", name
, code
);
227 for (i
= 0; i
< indent
; i
++)
244 printf ("%d (", y
->len
);
246 for (x
= 0; x
< y
->len
; x
++)
247 printf ("(%02x %c)", y
->data
[x
],
248 ISPRINT (y
->data
[x
]) ? y
->data
[x
] : '.');
253 #define SYSROFF_PRINT
254 #define SYSROFF_SWAP_IN
258 /* FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
259 hack the special case of the tr block, which has no contents. So we
260 implement our own functions for reading in and printing out the tr
263 #define IT_tr_CODE 0x7f
266 sysroff_swap_tr_in (void)
270 memset (raw
, 0, 255);
275 sysroff_print_tr_out (void)
277 itheader ("tr", IT_tr_CODE
);
287 if ((c
& 0x7f) != type
)
298 sysroff_swap_cs_in (&dummy
);
299 sysroff_print_cs_out (&dummy
);
306 sysroff_swap_dln_in (&dummy
);
307 sysroff_print_dln_out (&dummy
);
314 sysroff_swap_hd_in (&dummy
);
315 addrsize
= dummy
.afl
;
316 sysroff_print_hd_out (&dummy
);
323 sysroff_swap_dar_in (&dummy
);
324 sysroff_print_dar_out (&dummy
);
331 sysroff_swap_dsy_in (&dummy
);
332 sysroff_print_dsy_out (&dummy
);
339 sysroff_swap_dfp_in (&dummy
);
340 sysroff_print_dfp_out (&dummy
);
347 sysroff_swap_dso_in (&dummy
);
348 sysroff_print_dso_out (&dummy
);
355 sysroff_swap_dpt_in (&dummy
);
356 sysroff_print_dpt_out (&dummy
);
363 sysroff_swap_den_in (&dummy
);
364 sysroff_print_den_out (&dummy
);
371 sysroff_swap_dbt_in (&dummy
);
372 sysroff_print_dbt_out (&dummy
);
379 sysroff_swap_dty_in (&dummy
);
380 sysroff_print_dty_out (&dummy
);
387 sysroff_swap_un_in (&dummy
);
388 sysroff_print_un_out (&dummy
);
395 sysroff_swap_sc_in (&dummy
);
396 sysroff_print_sc_out (&dummy
);
403 sysroff_swap_er_in (&dummy
);
404 sysroff_print_er_out (&dummy
);
411 sysroff_swap_ed_in (&dummy
);
412 sysroff_print_ed_out (&dummy
);
419 sysroff_swap_sh_in (&dummy
);
420 sysroff_print_sh_out (&dummy
);
427 sysroff_swap_ob_in (&dummy
);
428 sysroff_print_ob_out (&dummy
);
435 sysroff_swap_rl_in (&dummy
);
436 sysroff_print_rl_out (&dummy
);
443 sysroff_swap_du_in (&dummy
);
445 sysroff_print_du_out (&dummy
);
452 sysroff_swap_dus_in (&dummy
);
453 sysroff_print_dus_out (&dummy
);
460 sysroff_swap_dul_in (&dummy
);
461 sysroff_print_dul_out (&dummy
);
468 sysroff_swap_dss_in (&dummy
);
469 sysroff_print_dss_out (&dummy
);
476 sysroff_swap_hs_in (&dummy
);
477 sysroff_print_hs_out (&dummy
);
484 sysroff_swap_dps_in (&dummy
);
485 sysroff_print_dps_out (&dummy
);
490 sysroff_swap_tr_in ();
491 sysroff_print_tr_out ();
498 sysroff_swap_dds_in (&dummy
);
499 sysroff_print_dds_out (&dummy
);
504 printf ("GOT A %x\n", c
);
520 /* This is no longer used. */
523 unit_info_list (void)
525 while (opt (IT_un_CODE
))
529 while (getone (IT_sc_CODE
))
532 while (getone (IT_er_CODE
))
535 while (getone (IT_ed_CODE
))
544 /* This is no longer used. */
547 object_body_list (void)
549 while (getone (IT_sh_CODE
))
551 while (getone (IT_ob_CODE
))
553 while (getone (IT_rl_CODE
))
564 printf ("WANTED %x!!\n", x
);
581 dump_symbol_info (void)
583 tab (1, "SYMBOL INFO");
585 while (opt (IT_dsy_CODE
))
587 if (opt (IT_dty_CODE
))
601 tab (1, "DERIVED TYPE");
605 if (opt (IT_dpp_CODE
))
610 else if (opt (IT_dfp_CODE
))
615 else if (opt (IT_den_CODE
))
620 else if (opt (IT_den_CODE
))
625 else if (opt (IT_dds_CODE
))
630 else if (opt (IT_dar_CODE
))
633 else if (opt (IT_dpt_CODE
))
636 else if (opt (IT_dul_CODE
))
639 else if (opt (IT_dse_CODE
))
642 else if (opt (IT_dot_CODE
))
654 /* This is no longer used. */
657 program_structure (void)
659 tab (1, "PROGRAM STRUCTURE");
660 while (opt (IT_dps_CODE
))
674 /* This is no longer used. */
679 tab (1, "DEBUG LIST");
683 program_structure ();
697 tab (1, "MODULE***\n");
706 while (getone (c
) && c
!= IT_tr_CODE
);
738 show_usage (FILE *file
, int status
)
740 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
741 fprintf (file
, _("Print a human readable interpretation of a SYSROFF object file\n"));
742 fprintf (file
, _(" The options are:\n\
743 -h --help Display this information\n\
744 -v --version Print the program's version number\n"));
747 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
752 main (int ac
, char **av
)
754 char *input_file
= NULL
;
756 static struct option long_options
[] =
758 {"help", no_argument
, 0, 'h'},
759 {"version", no_argument
, 0, 'V'},
760 {NULL
, no_argument
, 0, 0}
763 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
764 setlocale (LC_MESSAGES
, "");
766 #if defined (HAVE_SETLOCALE)
767 setlocale (LC_CTYPE
, "");
769 bindtextdomain (PACKAGE
, LOCALEDIR
);
770 textdomain (PACKAGE
);
772 program_name
= av
[0];
773 xmalloc_set_program_name (program_name
);
775 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
, (int *) NULL
)) != EOF
)
781 show_usage (stdout
, 0);
785 print_version ("sysdump");
791 show_usage (stderr
, 1);
796 /* The input and output files may be named on the command line. */
799 input_file
= av
[optind
];
802 fatal (_("no input file specified"));
804 file
= fopen (input_file
, FOPEN_RB
);
807 fatal (_("cannot open input file %s"), input_file
);