gen-aout.c 3.2 KB

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