1 /* Sysroff object format dumper.
2 Copyright 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005
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., 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"
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 int main (int, char **);
60 getCHARS (unsigned char *ptr
, int *idx
, int size
, int max
)
71 /* Got to work out the length of the string from self. */
77 r
= xcalloc (b
+ 1, 1);
78 memcpy (r
, ptr
+ oc
, b
);
85 dh (unsigned char *ptr
, int size
)
91 printf ("\n************************************************************\n");
93 for (i
= 0; i
< size
; i
+= span
)
95 for (j
= 0; j
< span
; j
++)
98 printf ("%02x ", ptr
[i
+ j
]);
103 for (j
= 0; j
< span
&& j
+ i
< size
; j
++)
107 if (c
< 32 || c
> 127)
117 fillup (unsigned char *ptr
)
123 size
= getc (file
) - 2;
124 fread (ptr
, 1, size
, file
);
125 sum
= code
+ size
+ 2;
127 for (i
= 0; i
< size
; i
++)
130 if ((sum
& 0xff) != 0xff)
131 printf ("SUM IS %x\n", sum
);
140 getBARRAY (unsigned char *ptr
, int *idx
, int dsize ATTRIBUTE_UNUSED
,
141 int max ATTRIBUTE_UNUSED
)
146 int size
= ptr
[byte
++];
149 res
.data
= (unsigned char *) xmalloc (size
);
151 for (i
= 0; i
< size
; i
++)
152 res
.data
[i
] = ptr
[byte
++];
158 getINT (unsigned char *ptr
, int *idx
, int size
, int max
)
180 n
= (ptr
[byte
+ 0] << 8) + ptr
[byte
+ 1];
183 n
= (ptr
[byte
+ 0] << 24) + (ptr
[byte
+ 1] << 16) + (ptr
[byte
+ 2] << 8) + (ptr
[byte
+ 3]);
194 getBITS (unsigned char *ptr
, int *idx
, int size
, int max
)
204 return (ptr
[byte
] >> (8 - bit
- size
)) & ((1 << size
) - 1);
208 itheader (char *name
, int code
)
210 printf ("\n%s 0x%02x\n", name
, code
);
220 for (i
= 0; i
< indent
; i
++)
237 printf ("%d (", y
->len
);
239 for (x
= 0; x
< y
->len
; x
++)
240 printf ("(%02x %c)", y
->data
[x
],
241 ISPRINT (y
->data
[x
]) ? y
->data
[x
] : '.');
246 #define SYSROFF_PRINT
247 #define SYSROFF_SWAP_IN
251 /* FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
252 hack the special case of the tr block, which has no contents. So we
253 implement our own functions for reading in and printing out the tr
256 #define IT_tr_CODE 0x7f
259 sysroff_swap_tr_in (void)
261 unsigned char raw
[255];
263 memset (raw
, 0, 255);
268 sysroff_print_tr_out (void)
270 itheader ("tr", IT_tr_CODE
);
280 if ((c
& 0x7f) != type
)
291 sysroff_swap_cs_in (&dummy
);
292 sysroff_print_cs_out (&dummy
);
299 sysroff_swap_dln_in (&dummy
);
300 sysroff_print_dln_out (&dummy
);
307 sysroff_swap_hd_in (&dummy
);
308 addrsize
= dummy
.afl
;
309 sysroff_print_hd_out (&dummy
);
316 sysroff_swap_dar_in (&dummy
);
317 sysroff_print_dar_out (&dummy
);
324 sysroff_swap_dsy_in (&dummy
);
325 sysroff_print_dsy_out (&dummy
);
332 sysroff_swap_dfp_in (&dummy
);
333 sysroff_print_dfp_out (&dummy
);
340 sysroff_swap_dso_in (&dummy
);
341 sysroff_print_dso_out (&dummy
);
348 sysroff_swap_dpt_in (&dummy
);
349 sysroff_print_dpt_out (&dummy
);
356 sysroff_swap_den_in (&dummy
);
357 sysroff_print_den_out (&dummy
);
364 sysroff_swap_dbt_in (&dummy
);
365 sysroff_print_dbt_out (&dummy
);
372 sysroff_swap_dty_in (&dummy
);
373 sysroff_print_dty_out (&dummy
);
380 sysroff_swap_un_in (&dummy
);
381 sysroff_print_un_out (&dummy
);
388 sysroff_swap_sc_in (&dummy
);
389 sysroff_print_sc_out (&dummy
);
396 sysroff_swap_er_in (&dummy
);
397 sysroff_print_er_out (&dummy
);
404 sysroff_swap_ed_in (&dummy
);
405 sysroff_print_ed_out (&dummy
);
412 sysroff_swap_sh_in (&dummy
);
413 sysroff_print_sh_out (&dummy
);
420 sysroff_swap_ob_in (&dummy
);
421 sysroff_print_ob_out (&dummy
);
428 sysroff_swap_rl_in (&dummy
);
429 sysroff_print_rl_out (&dummy
);
436 sysroff_swap_du_in (&dummy
);
438 sysroff_print_du_out (&dummy
);
445 sysroff_swap_dus_in (&dummy
);
446 sysroff_print_dus_out (&dummy
);
453 sysroff_swap_dul_in (&dummy
);
454 sysroff_print_dul_out (&dummy
);
461 sysroff_swap_dss_in (&dummy
);
462 sysroff_print_dss_out (&dummy
);
469 sysroff_swap_hs_in (&dummy
);
470 sysroff_print_hs_out (&dummy
);
477 sysroff_swap_dps_in (&dummy
);
478 sysroff_print_dps_out (&dummy
);
483 sysroff_swap_tr_in ();
484 sysroff_print_tr_out ();
491 sysroff_swap_dds_in (&dummy
);
492 sysroff_print_dds_out (&dummy
);
497 printf ("GOT A %x\n", c
);
515 printf ("WANTED %x!!\n", x
);
532 dump_symbol_info (void)
534 tab (1, "SYMBOL INFO");
536 while (opt (IT_dsy_CODE
))
538 if (opt (IT_dty_CODE
))
552 tab (1, "DERIVED TYPE");
556 if (opt (IT_dpp_CODE
))
561 else if (opt (IT_dfp_CODE
))
566 else if (opt (IT_den_CODE
))
571 else if (opt (IT_den_CODE
))
576 else if (opt (IT_dds_CODE
))
581 else if (opt (IT_dar_CODE
))
584 else if (opt (IT_dpt_CODE
))
587 else if (opt (IT_dul_CODE
))
590 else if (opt (IT_dse_CODE
))
593 else if (opt (IT_dot_CODE
))
609 tab (1, "MODULE***\n");
618 while (getone (c
) && c
!= IT_tr_CODE
);
639 show_usage (FILE *file
, int status
)
641 fprintf (file
, _("Usage: %s [option(s)] in-file\n"), program_name
);
642 fprintf (file
, _("Print a human readable interpretation of a SYSROFF object file\n"));
643 fprintf (file
, _(" The options are:\n\
644 -h --help Display this information\n\
645 -v --version Print the program's version number\n"));
648 fprintf (file
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
653 main (int ac
, char **av
)
655 char *input_file
= NULL
;
657 static struct option long_options
[] =
659 {"help", no_argument
, 0, 'h'},
660 {"version", no_argument
, 0, 'V'},
661 {NULL
, no_argument
, 0, 0}
664 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
665 setlocale (LC_MESSAGES
, "");
667 #if defined (HAVE_SETLOCALE)
668 setlocale (LC_CTYPE
, "");
670 bindtextdomain (PACKAGE
, LOCALEDIR
);
671 textdomain (PACKAGE
);
673 program_name
= av
[0];
674 xmalloc_set_program_name (program_name
);
676 while ((opt
= getopt_long (ac
, av
, "HhVv", long_options
, (int *) NULL
)) != EOF
)
682 show_usage (stdout
, 0);
686 print_version ("sysdump");
692 show_usage (stderr
, 1);
697 /* The input and output files may be named on the command line. */
700 input_file
= av
[optind
];
703 fatal (_("no input file specified"));
705 file
= fopen (input_file
, FOPEN_RB
);
708 fatal (_("cannot open input file %s"), input_file
);