gen-aout.c revision 78828
133965Sjdp/* Generate parameters for an a.out system. 278828Sobrien Copyright 1990, 1991, 1992, 1993, 1994, 1995 378828Sobrien Free Software Foundation, Inc. 433965Sjdp 533965SjdpThis file is part of BFD, the Binary File Descriptor library. 633965Sjdp 733965SjdpThis program is free software; you can redistribute it and/or modify 833965Sjdpit under the terms of the GNU General Public License as published by 933965Sjdpthe Free Software Foundation; either version 2 of the License, or 1033965Sjdp(at your option) any later version. 1133965Sjdp 1233965SjdpThis program is distributed in the hope that it will be useful, 1333965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of 1433965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1533965SjdpGNU General Public License for more details. 1633965Sjdp 1733965SjdpYou should have received a copy of the GNU General Public License 1833965Sjdpalong with this program; if not, write to the Free Software 1933965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2033965Sjdp 2133965Sjdp#include "/usr/include/a.out.h" 2233965Sjdp#include <stdio.h> 2333965Sjdp 2433965Sjdpint 2533965Sjdpmain (argc, argv) 2633965Sjdp int argc; char** argv; 2733965Sjdp{ 2833965Sjdp struct exec my_exec; 2933965Sjdp int page_size; 3033965Sjdp char *target = "unknown", *arch = "unknown"; 3133965Sjdp FILE *file = fopen("gen-aout", "r"); 3233965Sjdp 3333965Sjdp if (file == NULL) { 3433965Sjdp fprintf(stderr, "Cannot open gen-aout!\n"); 3533965Sjdp return -1; 3633965Sjdp } 3733965Sjdp if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) { 3833965Sjdp fprintf(stderr, "Cannot read gen-aout!\n"); 3933965Sjdp return -1; 4033965Sjdp } 4133965Sjdp 4233965Sjdp target = argv[1]; 4333965Sjdp if (target == NULL) { 4433965Sjdp fprintf(stderr, "Usage: gen-aout target_name\n"); 4533965Sjdp exit (1); 4633965Sjdp } 4733965Sjdp 4833965Sjdp#ifdef N_TXTOFF 4933965Sjdp page_size = N_TXTOFF(my_exec); 5033965Sjdp if (page_size == 0) 5133965Sjdp printf("#define N_HEADER_IN_TEXT(x) 1\n"); 5233965Sjdp else 5333965Sjdp printf("#define N_HEADER_IN_TEXT(x) 0\n"); 5433965Sjdp#endif 5533965Sjdp 5633965Sjdp printf("#define BYTES_IN_WORD %d\n", sizeof (int)); 5733965Sjdp if (my_exec.a_entry == 0) { 5833965Sjdp printf("#define ENTRY_CAN_BE_ZERO\n"); 5933965Sjdp printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n"); 6033965Sjdp } 6133965Sjdp else { 6233965Sjdp printf("/*#define ENTRY_CAN_BE_ZERO*/\n"); 6333965Sjdp printf("/*#define N_SHARED_LIB(x) 0*/\n"); 6433965Sjdp } 6533965Sjdp 6633965Sjdp printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry); 6733965Sjdp 6833965Sjdp#ifdef PAGSIZ 6933965Sjdp if (page_size == 0) 7033965Sjdp page_size = PAGSIZ; 7133965Sjdp#endif 7233965Sjdp if (page_size != 0) 7333965Sjdp printf("#define TARGET_PAGE_SIZE %d\n", page_size); 7433965Sjdp else 7533965Sjdp printf("/* #define TARGET_PAGE_SIZE ??? */\n"); 7633965Sjdp printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n"); 7733965Sjdp 7833965Sjdp#ifdef vax 7933965Sjdp arch = "vax"; 8033965Sjdp#endif 8133965Sjdp#ifdef m68k 8233965Sjdp arch = "m68k"; 8333965Sjdp#endif 8433965Sjdp if (arch[0] == '1') 8533965Sjdp { 8660484Sobrien fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;")); 8760484Sobrien fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n")); 8833965Sjdp arch = "unknown"; 8933965Sjdp } 9033965Sjdp printf("#define DEFAULT_ARCH bfd_arch_%s\n", arch); 9133965Sjdp 9233965Sjdp printf("\n#define MY(OP) CAT(%s_,OP)\n", target); 9333965Sjdp printf("#define TARGETNAME \"a.out-%s\"\n\n", target); 9433965Sjdp 9533965Sjdp printf("#include \"bfd.h\"\n"); 9633965Sjdp printf("#include \"sysdep.h\"\n"); 9733965Sjdp printf("#include \"libbfd.h\"\n"); 9833965Sjdp printf("#include \"libaout.h\"\n"); 9933965Sjdp printf("\n#include \"aout-target.h\"\n"); 10033965Sjdp 10133965Sjdp return 0; 10233965Sjdp} 103