home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / src / binutils.2 / bfd / gen-aout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  2.7 KB  |  98 lines

  1. /* Generate parameters for an a.out system.
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of BFD, the Binary File Descriptor library.
  5.  
  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.
  10.  
  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.
  15.  
  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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "/usr/include/a.out.h"
  21. #include <stdio.h>
  22.  
  23. /* Stuffed value of "ABCD" in a long, followed by a 0. */
  24. long int str[2] = { 0x41424344, 0x0 };
  25.  
  26. int
  27. main (argc, argv)
  28.      int argc; char** argv;
  29. {
  30.   struct exec my_exec;
  31.   int page_size;
  32.   char *target;
  33.   FILE *file = fopen("gen-aout", "r");
  34.   if (file == NULL) {
  35.       fprintf(stderr, "Cannot open gen-aout!\n");
  36.       return -1;
  37.   }
  38.   if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
  39.       fprintf(stderr, "Cannot read gen-aout!\n");
  40.       return -1;
  41.   }
  42.  
  43.   target = argv[1];
  44.   if (target == NULL) {
  45.       fprintf(stderr, "Usage: gen-aout target_name\n");
  46.       exit (-1);
  47.   }
  48.  
  49.   if (strcmp ((char *)&str[0], "ABCD") == 0)
  50.     printf("#define TARGET_IS_BIG_ENDIAN_P\n");
  51.   else
  52.     printf("#define TARGET_IS_LITTLE_ENDIAN_P\n");
  53.  
  54. #ifdef N_TXTOFF
  55.   page_size = N_TXTOFF(my_exec);
  56.   if (page_size == 0)
  57.     printf("#define N_HEADER_IN_TEXT(x) 1\n");
  58.   else
  59.     printf("#define N_HEADER_IN_TEXT(x) 0\n");
  60. #endif
  61.  
  62.   printf("#define BYTES_IN_WORD 4\n");
  63.   printf("#define ARCH 32\n");
  64.   if (my_exec.a_entry == 0) {
  65.       printf("#define ENTRY_CAN_BE_ZERO\n");
  66.       printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
  67.   }
  68.   else {
  69.       printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
  70.       printf("/*#define N_SHARED_LIB(x) 0\n*/");
  71.   }
  72.  
  73.   printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
  74.  
  75. #ifdef PAGSIZ
  76.   if (page_size == 0)
  77.     page_size = PAGSIZ;
  78. #endif
  79.   if (page_size != 0)
  80.     printf("#define PAGE_SIZE %d\n", page_size);
  81.   else
  82.     printf("/* #define PAGE_SIZE ??? */\n");
  83.   printf("#define SEGMENT_SIZE PAGE_SIZE\n");
  84.  
  85.   printf("#define DEFAULT_ARCH bfd_arch_m68k\n");
  86.  
  87.   printf("\n#define MY(OP) CAT(%s_,OP)\n", target);
  88.   printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
  89.  
  90.   printf("#include \"bfd.h\"\n");
  91.   printf("#include \"sysdep.h\"\n");
  92.   printf("#include \"libbfd.h\"\n");
  93.   printf("#include \"libaout.h\"\n");
  94.   printf("\n#include \"aout-target.h\"\n");
  95.  
  96.   return 0;
  97. }
  98.