/* srconv.c -- Sysroff conversion program
- Copyright (C) 1994 Free Software Foundation, Inc.
+ Copyright 1994, 1995, 1996, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
This file is part of GNU Binutils.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
/* Written by Steve Chamberlain (sac@cygnus.com)
#define PROGRAM_VERSION "1.5"
/*#define FOOP1 1 */
-static int sh;
-static int h8300;
-static void wr_cs ();
-static void walk_tree_scope ();
-static void wr_globals ();
-static int find_base ();
+static int addrsize;
+static char *toolname;
+static char **rnames;
+
+static int get_member_id PARAMS ((int));
+static int get_ordinary_id PARAMS ((int));
+static char *section_translate PARAMS ((char *));
+static char *strip_suffix PARAMS ((char *));
+static void checksum PARAMS ((FILE *, char *, int, int));
+static void writeINT PARAMS ((int, char *, int *, int, FILE *));
+static void writeBITS PARAMS ((int, char *, int *, int));
+static void writeBARRAY PARAMS ((barray, char *, int *, int, FILE *));
+static void writeCHARS PARAMS ((char *, char *, int *, int, FILE *));
+static void wr_tr PARAMS ((void));
+static void wr_un PARAMS ((struct coff_ofile *, struct coff_sfile *, int, int));
+static void wr_hd PARAMS ((struct coff_ofile *));
+static void wr_sh PARAMS ((struct coff_ofile *, struct coff_section *));
+static void wr_ob PARAMS ((struct coff_ofile *, struct coff_section *));
+static void wr_rl PARAMS ((struct coff_ofile *, struct coff_section *));
+static void wr_object_body PARAMS ((struct coff_ofile *));
+static void wr_dps_start
+ PARAMS ((struct coff_sfile *, struct coff_section *, struct coff_scope *,
+ int, int));
+static void wr_dps_end
+ PARAMS ((struct coff_section *, struct coff_scope *, int));
+static int *nints PARAMS ((int));
+static void walk_tree_type_1
+ PARAMS ((struct coff_sfile *, struct coff_symbol *, struct coff_type *,
+ int));
+static void walk_tree_type
+ PARAMS ((struct coff_sfile *, struct coff_symbol *, struct coff_type *,
+ int));
+static void walk_tree_symbol
+ PARAMS ((struct coff_sfile *, struct coff_section *,
+ struct coff_symbol *, int));
+static void walk_tree_scope
+ PARAMS ((struct coff_section *, struct coff_sfile *, struct coff_scope *,
+ int, int));
+static void walk_tree_sfile
+ PARAMS ((struct coff_section *, struct coff_sfile *));
+static void wr_program_structure
+ PARAMS ((struct coff_ofile *, struct coff_sfile *));
+static void wr_du PARAMS ((struct coff_ofile *, struct coff_sfile *, int));
+static void wr_dus PARAMS ((struct coff_ofile *, struct coff_sfile *));
+static int find_base PARAMS ((struct coff_sfile *, struct coff_section *));
+static void wr_dln PARAMS ((struct coff_ofile *, struct coff_sfile *, int));
+static void wr_globals
+ PARAMS ((struct coff_ofile *, struct coff_sfile *, int));
+static void wr_debug PARAMS ((struct coff_ofile *));
+static void wr_cs PARAMS ((void));
+static int wr_sc PARAMS ((struct coff_ofile *, struct coff_sfile *));
+static void wr_er PARAMS ((struct coff_ofile *, struct coff_sfile *, int));
+static void wr_ed PARAMS ((struct coff_ofile *, struct coff_sfile *, int));
+static void wr_unit_info PARAMS ((struct coff_ofile *));
+static void wr_module PARAMS ((struct coff_ofile *));
+static int align PARAMS ((int));
+static void prescan PARAMS ((struct coff_ofile *));
+static void show_usage PARAMS ((FILE *, int));
+static void show_help PARAMS ((void));
+extern int main PARAMS ((int, char **));
static FILE *file;
static bfd *abfd;
static int base1 = 0x18;
static int base2 = 0x2018;
-char *
-xcalloc (a, b)
- int a;
- int b;
-{
- char *r = xmalloc (a * b);
- memset (r, 0, a * b);
- return r;
-}
-
static int
get_member_id (x)
int x;
int byte = *idx / 8;
if (size == -2)
- {
- if (sh)
- size = 4;
- else if (h8300)
- size = 2;
- }
+ size = addrsize;
else if (size == -1)
size = 0;
barray data;
char *ptr;
int *idx;
- int size;
+ int size ATTRIBUTE_UNUSED;
FILE *file;
{
int i;
struct coff_ofile *ptr;
struct coff_sfile *sfile;
int first;
- int nsecs;
+ int nsecs ATTRIBUTE_UNUSED;
{
struct IT_un un;
un.spare1 = 0;
- if (abfd->flags & EXEC_P)
+ if (bfd_get_file_flags (abfd) & EXEC_P)
un.format = FORMAT_LM;
else
un.format = FORMAT_OM;
un.spare1 = 0;
-#if 0
+#if 1
un.nsections = ptr->nsections - 1; /* Don't count the abs section */
#else
/*NEW - only count sections with size */
un.nextrefs++;
}
}
- if (sh)
- un.tool = "C_SH";
- else if (h8300)
- un.tool = "C_H8/300H";
+ un.tool = toolname;
un.tcd = DATE;
un.linker = "L_GX00";
un.lcd = DATE;
struct IT_hd hd;
hd.spare1 = 0;
- if (abfd->flags & EXEC_P)
+ if (bfd_get_file_flags (abfd) & EXEC_P)
{
hd.mt = MTYPE_ABS_LM;
}
hd.nu = p->nsources; /* Always one unit */
hd.code = 0; /* Always ASCII */
hd.ver = "0200"; /* Version 2.00 */
- switch (abfd->arch_info->arch)
+ switch (bfd_get_arch (abfd))
{
case bfd_arch_h8300:
hd.au = 8;
hd.si = 0;
- hd.afl = 2;
hd.spcsz = 32;
hd.segsz = 0;
hd.segsh = 0;
- hd.cpu = "H8300H";
- h8300 = 1;
+ switch (bfd_get_mach (abfd))
+ {
+ case bfd_mach_h8300:
+ hd.cpu = "H8300";
+ hd.afl = 2;
+ addrsize = 2;
+ toolname = "C_H8/300";
+ break;
+ case bfd_mach_h8300h:
+ hd.cpu = "H8300H";
+ hd.afl = 4;
+ addrsize = 4;
+ toolname = "C_H8/300H";
+ break;
+ case bfd_mach_h8300s:
+ hd.cpu = "H8300S";
+ hd.afl = 4;
+ addrsize = 4;
+ toolname = "C_H8/300S";
+ break;
+ default:
+ abort();
+ }
+ rnames = rname_h8300;
break;
case bfd_arch_sh:
hd.au = 8;
hd.segsz = 0;
hd.segsh = 0;
hd.cpu = "SH";
- sh = 1;
+ addrsize = 4;
+ toolname = "C_SH";
+ rnames = rname_sh;
break;
default:
abort ();
}
- if (!abfd->flags & EXEC_P)
+ if (! bfd_get_file_flags(abfd) & EXEC_P)
{
hd.ep = 0;
}
hd.os = "";
hd.sys = "";
- hd.mn = strip_suffix (abfd->filename);
-
+ hd.mn = strip_suffix (bfd_get_filename (abfd));
sysroff_swap_hd_out (file, &hd);
}
static void
wr_sh (p, sec)
- struct coff_ofile *p;
+ struct coff_ofile *p ATTRIBUTE_UNUSED;
struct coff_section *sec;
{
struct IT_sh sh;
static void
wr_ob (p, section)
- struct coff_ofile *p;
+ struct coff_ofile *p ATTRIBUTE_UNUSED;
struct coff_section *section;
{
- int i;
+ bfd_size_type i;
int first = 1;
unsigned char stuff[200];
if (first)
{
ob.saf = 1;
- if (abfd->flags & EXEC_P)
+ if (bfd_get_file_flags (abfd) & EXEC_P)
ob.address = section->address;
else
ob.address = 0;
i += todo;
}
/* Now fill the rest with blanks */
- while (i < section->size)
+ while (i < (bfd_size_type) section->size)
{
struct IT_ob ob;
int todo = 200; /* Copy in 200 byte lumps */
ob.spare = 0;
- if (i + todo > section->size)
+ if (i + todo > (bfd_size_type) section->size)
todo = section->size - i;
ob.saf = 0;
static void
wr_rl (ptr, sec)
- struct coff_ofile *ptr;
+ struct coff_ofile *ptr ATTRIBUTE_UNUSED;
struct coff_section *sec;
{
int nr = sec->nrelocs;
static void
wr_dps_start (sfile, section, scope, type, nest)
struct coff_sfile *sfile;
- struct coff_section *section;
+ struct coff_section *section ATTRIBUTE_UNUSED;
struct coff_scope *scope;
int type;
int nest;
static void
wr_dps_end (section, scope, type)
- struct coff_section *section;
- struct coff_scope *scope;
+ struct coff_section *section ATTRIBUTE_UNUSED;
+ struct coff_scope *scope ATTRIBUTE_UNUSED;
int type;
{
struct IT_dps dps;
return (int *) (xcalloc (sizeof (int), x));
}
-static void walk_tree_symbol ();
static void
walk_tree_type_1 (sfile, symbol, type, nest)
struct coff_sfile *sfile;
static void
walk_tree_symbol (sfile, section, symbol, nest)
struct coff_sfile *sfile;
- struct coff_section *section;
+ struct coff_section *section ATTRIBUTE_UNUSED;
struct coff_symbol *symbol;
int nest;
{
struct IT_dsy dsy;
- dsy.spare2 = 0;
+ memset(&dsy, 0, sizeof(dsy));
dsy.nesting = nest;
switch (symbol->type->type)
}
if (symbol->where->where == coff_where_register)
- {
- if (sh)
- dsy.reg = rname_sh[symbol->where->offset];
- else if (h8300)
- dsy.reg = rname_h8300[symbol->where->offset];
- }
+ dsy.reg = rnames[symbol->where->offset];
switch (symbol->visible->type)
{
int j;
unsigned int *lowest = (unsigned *) nints (p->nsections);
unsigned int *highest = (unsigned *) nints (p->nsections);
- du.spare = 0;
- du.format = abfd->flags & EXEC_P ? 0 : 1;
+ du.format = bfd_get_file_flags (abfd) & EXEC_P ? 0 : 1;
du.optimized = 0;
+ du.stackfrmt = 0;
+ du.spare = 0;
du.unit = n;
du.sections = p->nsections - 1;
du.san = (int *) xcalloc (sizeof (int), du.sections);
}
du.san[used] = i;
du.length[used] = highest[i] - lowest[i];
- du.address[used] = abfd->flags & EXEC_P ? lowest[i] : 0;
+ du.address[used] = bfd_get_file_flags (abfd) & EXEC_P ? lowest[i] : 0;
if (debug)
{
printf (" section %6s 0x%08x..0x%08x\n",
static void
wr_dus (p, sfile)
- struct coff_ofile *p;
+ struct coff_ofile *p ATTRIBUTE_UNUSED;
struct coff_sfile *sfile;
{
{
return sfile->section[section->number].low;
}
+
static void
wr_dln (p, sfile, n)
- struct coff_ofile *p;
+ struct coff_ofile *p ATTRIBUTE_UNUSED;
struct coff_sfile *sfile;
- int n;
+ int n ATTRIBUTE_UNUSED;
{
#if 0
wr_globals (p, sfile, n)
struct coff_ofile *p;
struct coff_sfile *sfile;
- int n;
+ int n ATTRIBUTE_UNUSED;
{
struct coff_symbol *sy;
for (sy = p->symbol_list_head;
{
/* Don't have a symbol set aside for this section, which means that nothing
in this file does anything for the section. */
- sc.format = !(abfd->flags & EXEC_P);
+ sc.format = !(bfd_get_file_flags (abfd) & EXEC_P);
sc.addr = 0;
sc.length = 0;
name = info[i].sec->name;
}
else
{
- if (abfd->flags & EXEC_P)
+ if (bfd_get_file_flags (abfd) & EXEC_P)
{
sc.format = 0;
sc.addr = symbol->where->offset;
{
sc.contents = CONTENTS_CODE;
}
+#if 0
/* NEW */
if (sc.length) {
+#endif
sysroff_swap_sc_out (file, &sc);
scount++;
+#if 0
}
+#endif
}
return scount;
}
static void
wr_er (ptr, sfile, first)
struct coff_ofile *ptr;
- struct coff_sfile *sfile;
+ struct coff_sfile *sfile ATTRIBUTE_UNUSED;
int first;
{
int idx = 0;
static void
wr_ed (ptr, sfile, first)
struct coff_ofile *ptr;
- struct coff_sfile *sfile;
+ struct coff_sfile *sfile ATTRIBUTE_UNUSED;
int first;
{
struct coff_symbol *s;
FILE *file;
int status;
{
- fprintf (file, "Usage: %s [-dhVq] in-file [out-file]\n", program_name);
+ fprintf (file, _("Usage: %s [-dhVq] in-file [out-file]\n"), program_name);
exit (status);
}
static void
show_help ()
{
- printf ("%s: Convert a COFF object file into a SYSROFF object file\n",
+ printf (_("%s: Convert a COFF object file into a SYSROFF object file\n"),
program_name);
show_usage (stdout, 0);
}
};
char **matching;
char *input_file;
-
char *output_file;
+
+#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
+ setlocale (LC_MESSAGES, "");
+#endif
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
program_name = av[0];
xmalloc_set_program_name (program_name);
show_help ();
/*NOTREACHED */
case 'V':
- printf ("GNU %s version %s\n", program_name, PROGRAM_VERSION);
+ printf (_("GNU %s version %s\n"), program_name, PROGRAM_VERSION);
exit (0);
/*NOTREACHED */
case 0:
show_usage (stderr, 1);
if (strcmp (input_file, output_file) == 0)
{
- fprintf (stderr,
- "%s: input and output files must be different\n",
- program_name);
- exit (1);
+ fatal (_("input and output files must be different"));
}
}
}
if (!input_file)
{
- fprintf (stderr, "%s: no input file specified\n",
- program_name);
- exit (1);
+ fatal (_("no input file specified"));
}
if (!output_file)
if (!file)
{
- fprintf (stderr, "%s: unable to open output file %s\n",
- program_name, output_file);
- exit (1);
+ fatal (_("unable to open output file %s"), output_file);
}
if (debug)