1 /* Sysroff object format dumper.
2 Copyright (C) 1994 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 02111-1307, USA. */
21 /* Written by Steve Chamberlain <sac@cygnus.com>.
23 This program reads a SYSROFF object file and prints it in an
24 almost human readable form to stdout. */
28 #include <libiberty.h>
33 #define PROGRAM_VERSION "1.0"
37 static int segmented_p;
46 char *r = xmalloc (a, b);
52 getCHARS (ptr, idx, size, max)
68 /* Got to work out the length of the string from self */
74 r = xcalloc (b + 1, 1);
75 memcpy (r, ptr + oc, b);
89 printf ("\n************************************************************\n");
91 for (i = 0; i < size; i += span)
93 for (j = 0; j < span && j + i < size; j++)
95 printf ("%02x ", ptr[i + j]);
100 for (i = 0; i < size; i += span)
102 for (j = 0; j < span && j + i < size; j++)
105 if (c < 32 || c > 127)
120 size = getc (file) - 2;
121 fread (ptr, 1, size, file);
122 sum = code + size + 2;
123 for (i = 0; i < size; i++)
128 if ((sum & 0xff) != 0xff)
130 printf ("SUM IS %x\n", sum);
138 getBARRAY (ptr, idx, dsize, max)
147 int size = ptr[byte++];
149 res.data = (unsigned char *) xmalloc (size);
150 for (i = 0; i < size; i++)
152 res.data[i] = ptr[byte++];
158 getINT (ptr, idx, size, max)
183 n = (ptr[byte + 0] << 8) + ptr[byte + 1];
186 n = (ptr[byte + 0] << 24) + (ptr[byte + 1] << 16) + (ptr[byte + 2] << 8) + (ptr[byte + 3]);
196 getBITS (ptr, idx, size)
206 return (ptr[byte] >> (8 - bit - size)) & ((1 << size) - 1);
210 itheader (name, code)
214 printf ("\n%s 0x%02x\n", name, code);
222 for (i = 0; i < indent; i++)
240 printf ("%d (", y->len);
241 for (x = 0; x < y->len; x++)
243 printf ("(%02x %c)", y->data[x], isprint (y->data[x]) ? y->data[x] : '.');
248 #define SYSROFF_PRINT
249 #define SYSROFF_SWAP_IN
254 * FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
255 * hack the special case of the tr block, which has no contents. So we
256 * implement our own functions for reading in and printing out the tr
260 #define IT_tr_CODE 0x7f
271 sysroff_print_tr_out()
273 itheader("tr", IT_tr_CODE);
283 if ((c & 0x7f) != type)
294 sysroff_swap_cs_in (&dummy);
295 sysroff_print_cs_out (&dummy);
301 sysroff_swap_dln_in (&dummy);
302 sysroff_print_dln_out (&dummy);
308 sysroff_swap_hd_in (&dummy);
309 sysroff_print_hd_out (&dummy);
315 sysroff_swap_dar_in (&dummy);
316 sysroff_print_dar_out (&dummy);
322 sysroff_swap_dsy_in (&dummy);
323 sysroff_print_dsy_out (&dummy);
329 sysroff_swap_dfp_in (&dummy);
330 sysroff_print_dfp_out (&dummy);
336 sysroff_swap_dso_in (&dummy);
337 sysroff_print_dso_out (&dummy);
343 sysroff_swap_dpt_in (&dummy);
344 sysroff_print_dpt_out (&dummy);
350 sysroff_swap_den_in (&dummy);
351 sysroff_print_den_out (&dummy);
357 sysroff_swap_dbt_in (&dummy);
358 sysroff_print_dbt_out (&dummy);
364 sysroff_swap_dty_in (&dummy);
365 sysroff_print_dty_out (&dummy);
371 sysroff_swap_un_in (&dummy);
372 sysroff_print_un_out (&dummy);
378 sysroff_swap_sc_in (&dummy);
379 sysroff_print_sc_out (&dummy);
385 sysroff_swap_er_in (&dummy);
386 sysroff_print_er_out (&dummy);
392 sysroff_swap_ed_in (&dummy);
393 sysroff_print_ed_out (&dummy);
399 sysroff_swap_sh_in (&dummy);
400 sysroff_print_sh_out (&dummy);
406 sysroff_swap_ob_in (&dummy);
407 sysroff_print_ob_out (&dummy);
413 sysroff_swap_rl_in (&dummy);
414 sysroff_print_rl_out (&dummy);
420 sysroff_swap_du_in (&dummy);
422 sysroff_print_du_out (&dummy);
428 sysroff_swap_dus_in (&dummy);
429 sysroff_print_dus_out (&dummy);
435 sysroff_swap_dul_in (&dummy);
436 sysroff_print_dul_out (&dummy);
442 sysroff_swap_dss_in (&dummy);
443 sysroff_print_dss_out (&dummy);
449 sysroff_swap_hs_in (&dummy);
450 sysroff_print_hs_out (&dummy);
456 sysroff_swap_dps_in (&dummy);
457 sysroff_print_dps_out (&dummy);
462 sysroff_swap_tr_in ();
463 sysroff_print_tr_out ();
469 sysroff_swap_dds_in (&dummy);
470 sysroff_print_dds_out (&dummy);
474 printf ("GOT A %x\n", c);
491 while (opt (IT_un_CODE))
495 while (getone (IT_sc_CODE))
498 while (getone (IT_er_CODE))
501 while (getone (IT_ed_CODE))
509 while (getone (IT_sh_CODE))
511 while (getone (IT_ob_CODE))
513 while (getone (IT_rl_CODE))
524 printf ("WANTED %x!!\n", x);
542 static void derived_type ();
547 tab (1, "SYMBOL INFO");
548 while (opt (IT_dsy_CODE))
550 if (opt (IT_dty_CODE))
563 tab (1, "DERIVED TYPE");
566 if (opt (IT_dpp_CODE))
571 else if (opt (IT_dfp_CODE))
576 else if (opt (IT_den_CODE))
581 else if (opt (IT_den_CODE))
586 else if (opt (IT_dds_CODE))
591 else if (opt (IT_dar_CODE))
594 else if (opt (IT_dpt_CODE))
597 else if (opt (IT_dul_CODE))
600 else if (opt (IT_dse_CODE))
603 else if (opt (IT_dot_CODE))
616 tab (1, "PROGRAM STRUCTURE");
617 while (opt (IT_dps_CODE))
630 tab (1, "DEBUG LIST");
634 program_structure ();
646 tab (1, "MODULE***\n");
655 while (getone (c) && c != IT_tr_CODE);
687 show_usage (file, status)
691 fprintf (file, "Usage: %s [-hV] in-file\n", program_name);
698 printf ("%s: Print a human readable interpretation of a SYSROFF object file\n",
700 show_usage (stdout, 0);
708 char *input_file = NULL;
710 static struct option long_options[] =
712 {"help", no_argument, 0, 'h'},
713 {"version", no_argument, 0, 'V'},
714 {NULL, no_argument, 0, 0}
717 program_name = av[0];
718 xmalloc_set_program_name (program_name);
720 while ((opt = getopt_long (ac, av, "hV", long_options, (int *) NULL)) != EOF)
728 printf ("GNU %s version %s\n", program_name, PROGRAM_VERSION);
734 show_usage (stderr, 1);
739 /* The input and output files may be named on the command line. */
743 input_file = av[optind];
748 fprintf (stderr, "%s: no input file specified\n",
753 file = fopen (input_file, FOPEN_RB);
756 fprintf (stderr, "%s: cannot open input file %s\n",
757 program_name, input_file);