175fd0b74Schristos /* Generate parameters for an a.out system.
2*e992f068Schristos Copyright (C) 1990-2022 Free Software Foundation, Inc.
375fd0b74Schristos
475fd0b74Schristos This file is part of BFD, the Binary File Descriptor library.
575fd0b74Schristos
675fd0b74Schristos This program is free software; you can redistribute it and/or modify
775fd0b74Schristos it under the terms of the GNU General Public License as published by
875fd0b74Schristos the Free Software Foundation; either version 3 of the License, or
975fd0b74Schristos (at your option) any later version.
1075fd0b74Schristos
1175fd0b74Schristos This program is distributed in the hope that it will be useful,
1275fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
1375fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1475fd0b74Schristos GNU General Public License for more details.
1575fd0b74Schristos
1675fd0b74Schristos You should have received a copy of the GNU General Public License
1775fd0b74Schristos along with this program; if not, write to the Free Software
1875fd0b74Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1975fd0b74Schristos MA 02110-1301, USA. */
2075fd0b74Schristos
2175fd0b74Schristos #include "/usr/include/a.out.h"
2275fd0b74Schristos #include <stdio.h>
2375fd0b74Schristos
2475fd0b74Schristos #ifndef _
2575fd0b74Schristos #define _(X) X
2675fd0b74Schristos #endif
2775fd0b74Schristos
2875fd0b74Schristos int
main(int argc,char ** argv)2975fd0b74Schristos main (int argc, char** argv)
3075fd0b74Schristos {
3175fd0b74Schristos struct exec my_exec;
3275fd0b74Schristos int page_size;
3375fd0b74Schristos char * target;
3475fd0b74Schristos char * arch = "unknown";
3575fd0b74Schristos FILE * file;
3675fd0b74Schristos
3775fd0b74Schristos target = argv[1];
3875fd0b74Schristos if (target == NULL)
3975fd0b74Schristos {
4075fd0b74Schristos fprintf (stderr, "Usage: gen-aout target_name\n");
4175fd0b74Schristos exit (1);
4275fd0b74Schristos }
4375fd0b74Schristos
4475fd0b74Schristos file = fopen ("gen-aout", "r");
4575fd0b74Schristos if (file == NULL)
4675fd0b74Schristos {
4775fd0b74Schristos fprintf (stderr, "Cannot open gen-aout!\n");
4875fd0b74Schristos return -1;
4975fd0b74Schristos }
5075fd0b74Schristos
5175fd0b74Schristos if (fread (&my_exec, sizeof (struct exec), 1, file) != 1)
5275fd0b74Schristos {
5375fd0b74Schristos fprintf(stderr, "Cannot read gen-aout!\n");
5475fd0b74Schristos return -1;
5575fd0b74Schristos }
5675fd0b74Schristos
5775fd0b74Schristos fclose (file);
5875fd0b74Schristos
5975fd0b74Schristos #ifdef N_TXTOFF
6075fd0b74Schristos page_size = N_TXTOFF (&my_exec);
6175fd0b74Schristos if (page_size == 0)
6275fd0b74Schristos printf ("#define N_HEADER_IN_TEXT(x) 1\n");
6375fd0b74Schristos else
6475fd0b74Schristos printf ("#define N_HEADER_IN_TEXT(x) 0\n");
6575fd0b74Schristos #endif
6675fd0b74Schristos
6775fd0b74Schristos printf("#define BYTES_IN_WORD %d\n", sizeof (int));
6875fd0b74Schristos if (my_exec.a_entry == 0)
6975fd0b74Schristos {
7075fd0b74Schristos printf ("#define ENTRY_CAN_BE_ZERO\n");
7175fd0b74Schristos printf ("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
7275fd0b74Schristos }
7375fd0b74Schristos else
7475fd0b74Schristos {
7575fd0b74Schristos printf ("/*#define ENTRY_CAN_BE_ZERO*/\n");
7675fd0b74Schristos printf ("/*#define N_SHARED_LIB(x) 0*/\n");
7775fd0b74Schristos }
7875fd0b74Schristos
7975fd0b74Schristos printf ("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
8075fd0b74Schristos
8175fd0b74Schristos #ifdef PAGSIZ
8275fd0b74Schristos if (page_size == 0)
8375fd0b74Schristos page_size = PAGSIZ;
8475fd0b74Schristos #endif
8575fd0b74Schristos
8675fd0b74Schristos if (page_size != 0)
8775fd0b74Schristos printf ("#define TARGET_PAGE_SIZE %d\n", page_size);
8875fd0b74Schristos else
8975fd0b74Schristos printf ("/* #define TARGET_PAGE_SIZE ??? */\n");
9075fd0b74Schristos
9175fd0b74Schristos printf ("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
9275fd0b74Schristos
9375fd0b74Schristos #ifdef vax
9475fd0b74Schristos arch = "vax";
9575fd0b74Schristos #endif
9675fd0b74Schristos if (arch[0] == '1')
9775fd0b74Schristos {
9875fd0b74Schristos fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
9975fd0b74Schristos fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n"));
10075fd0b74Schristos arch = "unknown";
10175fd0b74Schristos }
10275fd0b74Schristos printf ("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
10375fd0b74Schristos
10475fd0b74Schristos printf ("/* Do not \"beautify\" the CONCAT* macro args. Traditional C will not");
10575fd0b74Schristos printf (" remove whitespace added here, and thus will fail to concatenate");
10675fd0b74Schristos printf (" the tokens. */");
10775fd0b74Schristos printf ("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
10875fd0b74Schristos printf ("#define TARGETNAME \"a.out-%s\"\n\n", target);
10975fd0b74Schristos
11075fd0b74Schristos printf ("#include \"sysdep.h\"\n");
11175fd0b74Schristos printf ("#include \"bfd.h\"\n");
11275fd0b74Schristos printf ("#include \"libbfd.h\"\n");
11375fd0b74Schristos printf ("#include \"libaout.h\"\n");
11475fd0b74Schristos printf ("\n#include \"aout-target.h\"\n");
11575fd0b74Schristos
11675fd0b74Schristos return 0;
11775fd0b74Schristos }
118