1*3d8817e4Smiod /* Generate parameters for an a.out system.
2*3d8817e4Smiod Copyright 1990, 1991, 1992, 1993, 1994, 1995, 2001, 2002
3*3d8817e4Smiod Free Software Foundation, Inc.
4*3d8817e4Smiod
5*3d8817e4Smiod This file is part of BFD, the Binary File Descriptor library.
6*3d8817e4Smiod
7*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
8*3d8817e4Smiod it under the terms of the GNU General Public License as published by
9*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or
10*3d8817e4Smiod (at your option) any later version.
11*3d8817e4Smiod
12*3d8817e4Smiod This program is distributed in the hope that it will be useful,
13*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
14*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*3d8817e4Smiod GNU General Public License for more details.
16*3d8817e4Smiod
17*3d8817e4Smiod You should have received a copy of the GNU General Public License
18*3d8817e4Smiod along with this program; if not, write to the Free Software
19*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20*3d8817e4Smiod
21*3d8817e4Smiod #include "/usr/include/a.out.h"
22*3d8817e4Smiod #include <stdio.h>
23*3d8817e4Smiod
24*3d8817e4Smiod #ifndef _
25*3d8817e4Smiod #define _(X) X
26*3d8817e4Smiod #endif
27*3d8817e4Smiod
28*3d8817e4Smiod int
main(argc,argv)29*3d8817e4Smiod main (argc, argv)
30*3d8817e4Smiod int argc; char** argv;
31*3d8817e4Smiod {
32*3d8817e4Smiod struct exec my_exec;
33*3d8817e4Smiod int page_size;
34*3d8817e4Smiod char *target = "unknown", *arch = "unknown";
35*3d8817e4Smiod FILE *file = fopen("gen-aout", "r");
36*3d8817e4Smiod
37*3d8817e4Smiod if (file == NULL) {
38*3d8817e4Smiod fprintf(stderr, "Cannot open gen-aout!\n");
39*3d8817e4Smiod return -1;
40*3d8817e4Smiod }
41*3d8817e4Smiod if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
42*3d8817e4Smiod fprintf(stderr, "Cannot read gen-aout!\n");
43*3d8817e4Smiod return -1;
44*3d8817e4Smiod }
45*3d8817e4Smiod
46*3d8817e4Smiod target = argv[1];
47*3d8817e4Smiod if (target == NULL) {
48*3d8817e4Smiod fprintf(stderr, "Usage: gen-aout target_name\n");
49*3d8817e4Smiod exit (1);
50*3d8817e4Smiod }
51*3d8817e4Smiod
52*3d8817e4Smiod #ifdef N_TXTOFF
53*3d8817e4Smiod page_size = N_TXTOFF(my_exec);
54*3d8817e4Smiod if (page_size == 0)
55*3d8817e4Smiod printf("#define N_HEADER_IN_TEXT(x) 1\n");
56*3d8817e4Smiod else
57*3d8817e4Smiod printf("#define N_HEADER_IN_TEXT(x) 0\n");
58*3d8817e4Smiod #endif
59*3d8817e4Smiod
60*3d8817e4Smiod printf("#define BYTES_IN_WORD %d\n", sizeof (int));
61*3d8817e4Smiod if (my_exec.a_entry == 0) {
62*3d8817e4Smiod printf("#define ENTRY_CAN_BE_ZERO\n");
63*3d8817e4Smiod printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
64*3d8817e4Smiod }
65*3d8817e4Smiod else {
66*3d8817e4Smiod printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
67*3d8817e4Smiod printf("/*#define N_SHARED_LIB(x) 0*/\n");
68*3d8817e4Smiod }
69*3d8817e4Smiod
70*3d8817e4Smiod printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
71*3d8817e4Smiod
72*3d8817e4Smiod #ifdef PAGSIZ
73*3d8817e4Smiod if (page_size == 0)
74*3d8817e4Smiod page_size = PAGSIZ;
75*3d8817e4Smiod #endif
76*3d8817e4Smiod if (page_size != 0)
77*3d8817e4Smiod printf("#define TARGET_PAGE_SIZE %d\n", page_size);
78*3d8817e4Smiod else
79*3d8817e4Smiod printf("/* #define TARGET_PAGE_SIZE ??? */\n");
80*3d8817e4Smiod printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
81*3d8817e4Smiod
82*3d8817e4Smiod #ifdef vax
83*3d8817e4Smiod arch = "vax";
84*3d8817e4Smiod #endif
85*3d8817e4Smiod #ifdef m68k
86*3d8817e4Smiod arch = "m68k";
87*3d8817e4Smiod #endif
88*3d8817e4Smiod if (arch[0] == '1')
89*3d8817e4Smiod {
90*3d8817e4Smiod fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
91*3d8817e4Smiod fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n"));
92*3d8817e4Smiod arch = "unknown";
93*3d8817e4Smiod }
94*3d8817e4Smiod printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
95*3d8817e4Smiod
96*3d8817e4Smiod printf("/* Do not \"beautify\" the CONCAT* macro args. Traditional C will not");
97*3d8817e4Smiod printf(" remove whitespace added here, and thus will fail to concatenate");
98*3d8817e4Smiod printf(" the tokens. */");
99*3d8817e4Smiod printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
100*3d8817e4Smiod printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
101*3d8817e4Smiod
102*3d8817e4Smiod printf("#include \"bfd.h\"\n");
103*3d8817e4Smiod printf("#include \"sysdep.h\"\n");
104*3d8817e4Smiod printf("#include \"libbfd.h\"\n");
105*3d8817e4Smiod printf("#include \"libaout.h\"\n");
106*3d8817e4Smiod printf("\n#include \"aout-target.h\"\n");
107*3d8817e4Smiod
108*3d8817e4Smiod return 0;
109*3d8817e4Smiod }
110