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. */
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++)
96 printf ("%02x ", ptr[i + j]);
101 for (j = 0; j < span && j + i < size; j++)
104 if (c < 32 || c > 127)
119 size = getc (file) - 2;
120 fread (ptr, 1, size, file);
121 sum = code + size + 2;
122 for (i = 0; i < size; i++)
127 if ((sum & 0xff) != 0xff)
129 printf ("SUM IS %x\n", sum);
137 getBARRAY (ptr, idx, dsize, max)
146 int size = ptr[byte++];
148 res.data = (unsigned char *) xmalloc (size);
149 for (i = 0; i < size; i++)
151 res.data[i] = ptr[byte++];
157 getINT (ptr, idx, size, max)
182 n = (ptr[byte + 0] << 8) + ptr[byte + 1];
185 n = (ptr[byte + 0] << 24) + (ptr[byte + 1] << 16) + (ptr[byte + 2] << 8) + (ptr[byte + 3]);
195 getBITS (ptr, idx, size)
205 return (ptr[byte] >> (8 - bit - size)) & ((1 << size) - 1);
209 itheader (name, code)
213 printf ("\n%s 0x%02x\n", name, code);
221 for (i = 0; i < indent; i++)
239 printf ("%d (", y->len);
240 for (x = 0; x < y->len; x++)
242 printf ("(%02x %c)", y->data[x], isprint (y->data[x]) ? y->data[x] : '.');
247 #define SYSROFF_PRINT
248 #define SYSROFF_SWAP_IN
253 * FIXME: sysinfo, which generates sysroff.[ch] from sysroff.info, can't
254 * hack the special case of the tr block, which has no contents. So we
255 * implement our own functions for reading in and printing out the tr
259 #define IT_tr_CODE 0x7f
270 sysroff_print_tr_out()
272 itheader("tr", IT_tr_CODE);
282 if ((c & 0x7f) != type)
293 sysroff_swap_cs_in (&dummy);
294 sysroff_print_cs_out (&dummy);
300 sysroff_swap_dln_in (&dummy);
301 sysroff_print_dln_out (&dummy);
307 sysroff_swap_hd_in (&dummy);
308 sysroff_print_hd_out (&dummy);
314 sysroff_swap_dar_in (&dummy);
315 sysroff_print_dar_out (&dummy);
321 sysroff_swap_dsy_in (&dummy);
322 sysroff_print_dsy_out (&dummy);
328 sysroff_swap_dfp_in (&dummy);
329 sysroff_print_dfp_out (&dummy);
335 sysroff_swap_dso_in (&dummy);
336 sysroff_print_dso_out (&dummy);
342 sysroff_swap_dpt_in (&dummy);
343 sysroff_print_dpt_out (&dummy);
349 sysroff_swap_den_in (&dummy);
350 sysroff_print_den_out (&dummy);
356 sysroff_swap_dbt_in (&dummy);
357 sysroff_print_dbt_out (&dummy);
363 sysroff_swap_dty_in (&dummy);
364 sysroff_print_dty_out (&dummy);
370 sysroff_swap_un_in (&dummy);
371 sysroff_print_un_out (&dummy);
377 sysroff_swap_sc_in (&dummy);
378 sysroff_print_sc_out (&dummy);
384 sysroff_swap_er_in (&dummy);
385 sysroff_print_er_out (&dummy);
391 sysroff_swap_ed_in (&dummy);
392 sysroff_print_ed_out (&dummy);
398 sysroff_swap_sh_in (&dummy);
399 sysroff_print_sh_out (&dummy);
405 sysroff_swap_ob_in (&dummy);
406 sysroff_print_ob_out (&dummy);
412 sysroff_swap_rl_in (&dummy);
413 sysroff_print_rl_out (&dummy);
419 sysroff_swap_du_in (&dummy);
421 sysroff_print_du_out (&dummy);
427 sysroff_swap_dus_in (&dummy);
428 sysroff_print_dus_out (&dummy);
434 sysroff_swap_dul_in (&dummy);
435 sysroff_print_dul_out (&dummy);
441 sysroff_swap_dss_in (&dummy);
442 sysroff_print_dss_out (&dummy);
448 sysroff_swap_hs_in (&dummy);
449 sysroff_print_hs_out (&dummy);
455 sysroff_swap_dps_in (&dummy);
456 sysroff_print_dps_out (&dummy);
461 sysroff_swap_tr_in ();
462 sysroff_print_tr_out ();
468 sysroff_swap_dds_in (&dummy);
469 sysroff_print_dds_out (&dummy);
473 printf ("GOT A %x\n", c);
490 while (opt (IT_un_CODE))
494 while (getone (IT_sc_CODE))
497 while (getone (IT_er_CODE))
500 while (getone (IT_ed_CODE))
508 while (getone (IT_sh_CODE))
510 while (getone (IT_ob_CODE))
512 while (getone (IT_rl_CODE))
523 printf ("WANTED %x!!\n", x);
541 static void derived_type ();
546 tab (1, "SYMBOL INFO");
547 while (opt (IT_dsy_CODE))
549 if (opt (IT_dty_CODE))
562 tab (1, "DERIVED TYPE");
565 if (opt (IT_dpp_CODE))
570 else if (opt (IT_dfp_CODE))
575 else if (opt (IT_den_CODE))
580 else if (opt (IT_den_CODE))
585 else if (opt (IT_dds_CODE))
590 else if (opt (IT_dar_CODE))
593 else if (opt (IT_dpt_CODE))
596 else if (opt (IT_dul_CODE))
599 else if (opt (IT_dse_CODE))
602 else if (opt (IT_dot_CODE))
615 tab (1, "PROGRAM STRUCTURE");
616 while (opt (IT_dps_CODE))
629 tab (1, "DEBUG LIST");
633 program_structure ();
645 tab (1, "MODULE***\n");
654 while (getone (c) && c != IT_tr_CODE);
686 show_usage (file, status)
690 fprintf (file, "Usage: %s [-hV] in-file\n", program_name);
697 printf ("%s: Print a human readable interpretation of a SYSROFF object file\n",
699 show_usage (stdout, 0);
707 char *input_file = NULL;
709 static struct option long_options[] =
711 {"help", no_argument, 0, 'h'},
712 {"version", no_argument, 0, 'V'},
713 {NULL, no_argument, 0, 0}
716 program_name = av[0];
717 xmalloc_set_program_name (program_name);
719 while ((opt = getopt_long (ac, av, "hV", long_options, (int *) NULL)) != EOF)
727 printf ("GNU %s version %s\n", program_name, PROGRAM_VERSION);
733 show_usage (stderr, 1);
738 /* The input and output files may be named on the command line. */
742 input_file = av[optind];
747 fprintf (stderr, "%s: no input file specified\n",
752 file = fopen (input_file, FOPEN_RB);
755 fprintf (stderr, "%s: cannot open input file %s\n",
756 program_name, input_file);