1 /* Sysroff object format dumper.
2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2009
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 3 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., 51 Franklin Street - Fifth Floor, 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"
31 #include "libiberty.h"
37 static int segmented_p
;
39 static int addrsize
= 4;
42 static void dh (unsigned char *, int);
43 static void itheader (char *, int);
45 static void tabout (void);
46 static void pbarray (barray
*);
47 static int getone (int);
49 static void must (int);
50 static void tab (int, char *);
51 static void dump_symbol_info (void);
52 static void derived_type (void);
53 static void module (void);
54 static void show_usage (FILE *, int);
56 extern int main (int, char **);
59 getCHARS (unsigned char *ptr
, int *idx
, int size
, int max
)
70 /* Got to work out the length of the string from self. */
76 r
= xcalloc (b
+ 1, 1);
77 memcpy (r
, ptr
+ oc
, b
);
84 dh (unsigned char *ptr
, int size
)
90 printf ("\n************************************************************\n");
92 for (i
= 0; i
< size
; i
+= span
)
94 for (j
= 0; j
< span
; j
++)
97 printf ("%02x ", ptr
[i
+ j
]);
102 for (j
= 0; j
< span
&& j
+ i
< size
; j
++)
106 if (c
< 32 || c
> 127)
116 fillup (unsigned char *ptr
)
128 if (fread (ptr
, size
, 1, file
) != 1)
131 sum
= code
+ size
+ 2;
133 for (i
= 0; i
< size
; i
++)
136 if ((sum
& 0xff) != 0xff)
137 printf ("SUM IS %x\n", sum
);
146 getBARRAY (unsigned char *ptr
, int *idx
, int dsize ATTRIBUTE_UNUSED
,
147 int max ATTRIBUTE_UNUSED
)
152 int size
= ptr
[byte
++];
155 res
.data
= (unsigned char *) xmalloc (size
);
157 for (i
= 0; i
< size
; i
++)
158 res
.data
[i
] = ptr
[byte
++];
164 getINT (unsigned char *ptr
, int *idx
, int size
, int max
)
186 n
= (ptr
[byte
+ 0] << 8) + ptr
[byte
+ 1];
189 n
= (ptr
[byte
+ 0] << 24) + (ptr
[byte
+ 1] << 16) + (ptr
[byte
+ 2] << 8) + (ptr
[byte
+ 3]);
200 getBITS (unsigned char *ptr
, int *idx
, int size
, int max
)
210 return (ptr
[byte
] >> (8 - bit
- size
)) & ((1 << size
) - 1);
214 itheader (char *name
, int code
)
216 printf ("\n%s 0x%02x\n", name
, code
);
226 for (i
= 0; i
< indent
; i
++)
243 printf ("%d (", y
->len
);
245 for (x
= 0; x
< y
->len
; x
++)
246 printf ("(%02x %c)", y
->data
[x
],
247 ISPRINT (y
->data
[x
]) ? y
->data
[x
] : '.');
252 #define SYSROFF_PRINT
253 #define SYSROFF_SWAP_IN
257 /* FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
258 hack the special case of the tr block, which has no contents. So we
259 implement our own functions for reading in and printing out the tr
262 #define IT_tr_CODE 0x7f
265 sysroff_swap_tr_in (void)
267 unsigned char raw
[255];
269 memset (raw
, 0, 255);
274 sysroff_print_tr_out (void)
276 itheader ("tr", IT_tr_CODE
);
286 if ((c
& 0x7f) != type
)
297 sysroff_swap_cs_in (&dummy
);
298 sysroff_print_cs_out (&dummy
);
305 sysroff_swap_dln_in (&dummy
);
306 sysroff_print_dln_out (&dummy
);
313 sysroff_swap_hd_in (&dummy
);
314 addrsize
= dummy
.afl
;
315 sysroff_print_hd_out (&dummy
);
322 sysroff_swap_dar_in (&dummy
);
323 sysroff_print_dar_out (&dummy
);
330 sysroff_swap_dsy_in (&dummy
);
331 sysroff_print_dsy_out (&dummy
);
338 sysroff_swap_dfp_in (&dummy
);
339 sysroff_print_dfp_out (&dummy
);
346 sysroff_swap_dso_in (&dummy
);
347 sysroff_print_dso_out (&dummy
);
354 sysroff_swap_dpt_in (&dummy
);
355 sysroff_print_dpt_out (&dummy
);
362 sysroff_swap_den_in (&dummy
);
363 sysroff_print_den_out (&dummy
);
370 sysroff_swap_dbt_in (&dummy
);
371 sysroff_print_dbt_out (&dummy
);
378 sysroff_swap_dty_in (&dummy
);
379 sysroff_print_dty_out (&dummy
);
386 sysroff_swap_un_in (&dummy
);
387 sysroff_print_un_out (&dummy
);
394 sysroff_swap_sc_in (&dummy
);
395 sysroff_print_sc_out (&dummy
);
402 sysroff_swap_er_in (&dummy
);
403 sysroff_print_er_out (&dummy
);
410 sysroff_swap_ed_in (&dummy
);
411 sysroff_print_ed_out (&dummy
);
418 sysroff_swap_sh_in (&dummy
);
419 sysroff_print_sh_out (&dummy
);
426 sysroff_swap_ob_in (&dummy
);
427 sysroff_print_ob_out (&dummy
);
434 sysroff_swap_rl_in (&dummy
);
435 sysroff_print_rl_out (&dummy
);
442 sysroff_swap_du_in (&dummy
);
444 sysroff_print_du_out (&dummy
);
451 sysroff_swap_dus_in (&dummy
);
452 sysroff_print_dus_out (&dummy
);
459 sysroff_swap_dul_in (&dummy
);
460 sysroff_print_dul_out (&dummy
);
467 sysroff_swap_dss_in (&dummy
);
468 sysroff_print_dss_out (&dummy
);
475 sysroff_swap_hs_in (&dummy
);
476 sysroff_print_hs_out (&dummy
);
483 sysroff_swap_dps_in (&dummy
);
484 sysroff_print_dps_out (&dummy
);
489 sysroff_swap_tr_in ();
490 sysroff_print_tr_out ();
497 sysroff_swap_dds_in (&dummy
);
498 sysroff_print_dds_out (&dummy
);
503 printf ("GOT A %x\n", c
);
521 printf ("WANTED %x!!\n", x
);
537 dump_symbol_info (void)
539 tab (1, "SYMBOL INFO");
541 while (opt (IT_dsy_CODE
))
543 if (opt (IT_dty_CODE
))
557 tab (1, "DERIVED TYPE");
561 if (opt (IT_dpp_CODE
))
566 else if (opt (IT_dfp_CODE
))
571 else if (opt (IT_den_CODE
))
576 else if (opt (IT_den_CODE
))
581 else if (opt (IT_dds_CODE
))
586 else if (opt (IT_dar_CODE
))
589 else if (opt (IT_dpt_CODE
))
592 else if (opt (IT_dul_CODE
))
595 else if (opt (IT_dse_CODE
))
598 else if (opt (IT_dot_CODE
))
614 tab (1, "MODULE***\n");
623 while (getone (c
) && c
!= IT_tr_CODE
);
644 show_usage (FILE *file
, int status
)
646 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
647 fprintf (file
, _("Print a human readable interpretation of a SYSROFF object file\n"));
648 fprintf (file
, _(" The options are:\n\
649 -h --help Display this information\n\
650 -v --version Print the program's version number\n"));
652 if (REPORT_BUGS_TO
[0] && status
== 0)
653 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
658 main (int ac
, char **av
)
660 char *input_file
= NULL
;
662 static struct option long_options
[] =
664 {"help", no_argument
, 0, 'h'},
665 {"version", no_argument
, 0, 'V'},
666 {NULL
, no_argument
, 0, 0}
669 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
670 setlocale (LC_MESSAGES
, "");
672 #if defined (HAVE_SETLOCALE)
673 setlocale (LC_CTYPE
, "");
675 bindtextdomain (PACKAGE
, LOCALEDIR
);
676 textdomain (PACKAGE
);
678 program_name
= av
[0];
679 xmalloc_set_program_name (program_name
);
681 expandargv (&ac
, &av
);
683 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
, (int *) NULL
)) != EOF
)
689 show_usage (stdout
, 0);
693 print_version ("sysdump");
699 show_usage (stderr
, 1);
704 /* The input and output files may be named on the command line. */
707 input_file
= av
[optind
];
710 fatal (_("no input file specified"));
712 file
= fopen (input_file
, FOPEN_RB
);
715 fatal (_("cannot open input file %s"), input_file
);