00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "/usr/include/a.out.h"
00022 #include <stdio.h>
00023
00024 #ifndef _
00025 #define _(X) X
00026 #endif
00027
00028 int
00029 main (argc, argv)
00030 int argc; char** argv;
00031 {
00032 struct exec my_exec;
00033 int page_size;
00034 char *target = "unknown", *arch = "unknown";
00035 FILE *file = fopen("gen-aout", "r");
00036
00037 if (file == NULL) {
00038 fprintf(stderr, "Cannot open gen-aout!\n");
00039 return -1;
00040 }
00041 if (fread(&my_exec, sizeof(struct exec), 1, file) != 1) {
00042 fprintf(stderr, "Cannot read gen-aout!\n");
00043 return -1;
00044 }
00045
00046 target = argv[1];
00047 if (target == NULL) {
00048 fprintf(stderr, "Usage: gen-aout target_name\n");
00049 exit (1);
00050 }
00051
00052 #ifdef N_TXTOFF
00053 page_size = N_TXTOFF(my_exec);
00054 if (page_size == 0)
00055 printf("#define N_HEADER_IN_TEXT(x) 1\n");
00056 else
00057 printf("#define N_HEADER_IN_TEXT(x) 0\n");
00058 #endif
00059
00060 printf("#define BYTES_IN_WORD %d\n", sizeof (int));
00061 if (my_exec.a_entry == 0) {
00062 printf("#define ENTRY_CAN_BE_ZERO\n");
00063 printf("#define N_SHARED_LIB(x) 0 /* Avoids warning */\n");
00064 }
00065 else {
00066 printf("/*#define ENTRY_CAN_BE_ZERO*/\n");
00067 printf("/*#define N_SHARED_LIB(x) 0*/\n");
00068 }
00069
00070 printf("#define TEXT_START_ADDR %d\n", my_exec.a_entry);
00071
00072 #ifdef PAGSIZ
00073 if (page_size == 0)
00074 page_size = PAGSIZ;
00075 #endif
00076 if (page_size != 0)
00077 printf("#define TARGET_PAGE_SIZE %d\n", page_size);
00078 else
00079 printf("/* #define TARGET_PAGE_SIZE ??? */\n");
00080 printf("#define SEGMENT_SIZE TARGET_PAGE_SIZE\n");
00081
00082 #ifdef vax
00083 arch = "vax";
00084 #endif
00085 #ifdef m68k
00086 arch = "m68k";
00087 #endif
00088 if (arch[0] == '1')
00089 {
00090 fprintf (stderr, _("warning: preprocessor substituted architecture name inside string;"));
00091 fprintf (stderr, _(" fix DEFAULT_ARCH in the output file yourself\n"));
00092 arch = "unknown";
00093 }
00094 printf("#define DEFAULT_ARCH bfd_arch_%s\n\n", arch);
00095
00096 printf("/* Do not \"beautify\" the CONCAT* macro args. Traditional C will not");
00097 printf(" remove whitespace added here, and thus will fail to concatenate");
00098 printf(" the tokens. */");
00099 printf("\n#define MY(OP) CONCAT2 (%s_,OP)\n\n", target);
00100 printf("#define TARGETNAME \"a.out-%s\"\n\n", target);
00101
00102 printf("#include \"bfd.h\"\n");
00103 printf("#include \"sysdep.h\"\n");
00104 printf("#include \"libbfd.h\"\n");
00105 printf("#include \"libaout.h\"\n");
00106 printf("\n#include \"aout-target.h\"\n");
00107
00108 return 0;
00109 }