1 /* Sysroff object format dumper.
2 Copyright (C) 1994-2023 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 3 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., 51 Franklin Street - Fifth Floor, 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. */
29 #include "safe-ctype.h"
30 #include "libiberty.h"
36 static int segmented_p
;
38 static int addrsize
= 4;
41 static void derived_type (void);
44 getCHARS (unsigned char *ptr
, int *idx
, int size
, int max
)
51 return _("*undefined*");
55 /* PR 17512: file: 13caced2. */
57 return _("*corrupt*");
58 /* Got to work out the length of the string from self. */
66 return _("*corrupt*");
70 r
= xcalloc (b
+ 1, 1);
71 memcpy (r
, ptr
+ oc
, b
);
78 dh (unsigned char *ptr
, int size
)
84 printf ("\n************************************************************\n");
86 for (i
= 0; i
< size
; i
+= span
)
88 for (j
= 0; j
< span
; j
++)
91 printf ("%02x ", ptr
[i
+ j
]);
96 for (j
= 0; j
< span
&& j
+ i
< size
; j
++)
100 if (c
< 32 || c
> 127)
110 fillup (unsigned char *ptr
)
122 if (fread (ptr
, size
, 1, file
) != 1)
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
, int max
)
151 res
.data
= (unsigned char *) xmalloc (size
);
153 for (i
= 0; i
< size
; i
++)
154 res
.data
[i
] = byte
< max
? ptr
[byte
++] : 0;
160 getINT (unsigned char *ptr
, int *idx
, int size
, int max
)
167 /* PR 17512: file: id:000001,src:000002,op:flip1,pos:45. */
168 /* Prevent infinite loops re-reading beyond the end of the buffer. */
169 fatal (_("ICE: getINT: Out of buffer space"));
187 n
= (ptr
[byte
+ 0] << 8) + ptr
[byte
+ 1];
190 n
= (((unsigned) ptr
[byte
+ 0] << 24) + (ptr
[byte
+ 1] << 16)
191 + (ptr
[byte
+ 2] << 8) + (ptr
[byte
+ 3]));
194 fatal (_("Unsupported read size: %d"), size
);
202 getBITS (unsigned char *ptr
, int *idx
, int size
, int max
)
212 return (ptr
[byte
] >> (8 - bit
- size
)) & ((1 << size
) - 1);
216 itheader (char *name
, int icode
)
218 printf ("\n%s 0x%02x\n", name
, icode
);
228 for (i
= 0; i
< indent
; i
++)
245 printf ("%d (", y
->len
);
247 for (x
= 0; x
< y
->len
; x
++)
248 printf ("(%02x %c)", y
->data
[x
],
249 ISPRINT (y
->data
[x
]) ? y
->data
[x
] : '.');
254 #define SYSROFF_PRINT
255 #define SYSROFF_SWAP_IN
259 /* FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
260 hack the special case of the tr block, which has no contents. So we
261 implement our own functions for reading in and printing out the tr
264 #define IT_tr_CODE 0x7f
267 sysroff_swap_tr_in (void)
269 unsigned char raw
[255];
271 memset (raw
, 0, 255);
276 sysroff_print_tr_out (void)
278 itheader ("tr", IT_tr_CODE
);
288 if ((c
& 0x7f) != type
)
299 sysroff_swap_cs_in (&dummy
);
300 sysroff_print_cs_out (&dummy
);
307 sysroff_swap_dln_in (&dummy
);
308 sysroff_print_dln_out (&dummy
);
315 sysroff_swap_hd_in (&dummy
);
316 addrsize
= dummy
.afl
;
317 sysroff_print_hd_out (&dummy
);
324 sysroff_swap_dar_in (&dummy
);
325 sysroff_print_dar_out (&dummy
);
332 sysroff_swap_dsy_in (&dummy
);
333 sysroff_print_dsy_out (&dummy
);
340 sysroff_swap_dfp_in (&dummy
);
341 sysroff_print_dfp_out (&dummy
);
348 sysroff_swap_dso_in (&dummy
);
349 sysroff_print_dso_out (&dummy
);
356 sysroff_swap_dpt_in (&dummy
);
357 sysroff_print_dpt_out (&dummy
);
364 sysroff_swap_den_in (&dummy
);
365 sysroff_print_den_out (&dummy
);
372 sysroff_swap_dbt_in (&dummy
);
373 sysroff_print_dbt_out (&dummy
);
380 sysroff_swap_dty_in (&dummy
);
381 sysroff_print_dty_out (&dummy
);
388 sysroff_swap_un_in (&dummy
);
389 sysroff_print_un_out (&dummy
);
396 sysroff_swap_sc_in (&dummy
);
397 sysroff_print_sc_out (&dummy
);
404 sysroff_swap_er_in (&dummy
);
405 sysroff_print_er_out (&dummy
);
412 sysroff_swap_ed_in (&dummy
);
413 sysroff_print_ed_out (&dummy
);
420 sysroff_swap_sh_in (&dummy
);
421 sysroff_print_sh_out (&dummy
);
428 sysroff_swap_ob_in (&dummy
);
429 sysroff_print_ob_out (&dummy
);
436 sysroff_swap_rl_in (&dummy
);
437 sysroff_print_rl_out (&dummy
);
444 sysroff_swap_du_in (&dummy
);
446 sysroff_print_du_out (&dummy
);
453 sysroff_swap_dus_in (&dummy
);
454 sysroff_print_dus_out (&dummy
);
461 sysroff_swap_dul_in (&dummy
);
462 sysroff_print_dul_out (&dummy
);
469 sysroff_swap_dss_in (&dummy
);
470 sysroff_print_dss_out (&dummy
);
477 sysroff_swap_hs_in (&dummy
);
478 sysroff_print_hs_out (&dummy
);
485 sysroff_swap_dps_in (&dummy
);
486 sysroff_print_dps_out (&dummy
);
491 sysroff_swap_tr_in ();
492 sysroff_print_tr_out ();
499 sysroff_swap_dds_in (&dummy
);
500 sysroff_print_dds_out (&dummy
);
505 printf (_("GOT A %x\n"), c
);
523 printf (_("WANTED %x!!\n"), x
);
539 dump_symbol_info (void)
541 tab (1, _("SYMBOL INFO"));
543 while (opt (IT_dsy_CODE
))
545 if (opt (IT_dty_CODE
))
559 tab (1, _("DERIVED TYPE"));
563 if (opt (IT_dpp_CODE
))
568 else if (opt (IT_dfp_CODE
))
573 else if (opt (IT_den_CODE
))
578 else if (opt (IT_den_CODE
))
583 else if (opt (IT_dds_CODE
))
588 else if (opt (IT_dar_CODE
))
591 else if (opt (IT_dpt_CODE
))
594 else if (opt (IT_dul_CODE
))
597 else if (opt (IT_dse_CODE
))
600 else if (opt (IT_dot_CODE
))
616 tab (1, _("MODULE***\n"));
627 while (getone (c
) && c
!= IT_tr_CODE
);
645 ATTRIBUTE_NORETURN
static void
646 show_usage (FILE *ffile
, int status
)
648 fprintf (ffile
, _("Usage: %s [option(s)] in-file\n"), program_name
);
649 fprintf (ffile
, _("Print a human readable interpretation of a SYSROFF object file\n"));
650 fprintf (ffile
, _(" The options are:\n\
651 -h --help Display this information\n\
652 -v --version Print the program's version number\n"));
654 if (REPORT_BUGS_TO
[0] && status
== 0)
655 fprintf (ffile
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
660 main (int ac
, char **av
)
662 char *input_file
= NULL
;
664 static struct option long_options
[] =
666 {"help", no_argument
, 0, 'h'},
667 {"version", no_argument
, 0, 'V'},
668 {NULL
, no_argument
, 0, 0}
671 #ifdef HAVE_LC_MESSAGES
672 setlocale (LC_MESSAGES
, "");
674 setlocale (LC_CTYPE
, "");
675 bindtextdomain (PACKAGE
, LOCALEDIR
);
676 textdomain (PACKAGE
);
678 program_name
= av
[0];
679 xmalloc_set_program_name (program_name
);
680 bfd_set_error_program_name (program_name
);
682 expandargv (&ac
, &av
);
684 while ((option
= getopt_long (ac
, av
, "HhVv", long_options
, (int *) NULL
)) != EOF
)
690 show_usage (stdout
, 0);
694 print_version ("sysdump");
700 show_usage (stderr
, 1);
705 /* The input and output files may be named on the command line. */
708 input_file
= av
[optind
];
711 fatal (_("no input file specified"));
713 file
= fopen (input_file
, FOPEN_RB
);
716 fatal (_("cannot open input file %s"), input_file
);