1 /* Startup for apout. Parse arguments, load the binary, and run it.
4 * $Date: Mon 31 Oct 2016 03:46:15 AM CET $
9 /* The following array holds the FILE pointers that correspond to open file
10 * descriptors. Only fds which are not ttys have FILE * pointers
13 char *streammode[NFILE]; /* Mode for each file - used for dup */
15 /* The following two buffers are used as */
16 /* part of the translation from virtal */
17 /* absolute filenames to native ones. We */
18 /* only have 2 buffers, so if you call */
19 /* xlate_filename() 3 times, the 1st return */
20 /* value will be destroyed. */
21 static char realfilename[2][2 * MAXPATHLEN];
23 static int whichrfn = 0;
24 char *apout_root = NULL; /* Root dir for simulated a.out */
28 int inst_debug = 0, /* Print a line before each instruction */
29 trap_debug = 0, /* Print details of each trap */
30 jsr_debug = 0, /* Print out each jsr */
31 fp_debug = 0; /* Print out each floating-point instruction */
32 FILE *dbg_file = NULL; /* Debugging output file */
33 char *progname = NULL; /* The program's name - used in debugging */
38 fprintf(stderr, "Usage: apout");
40 fprintf(stderr, " [-inst] [-trap] [-jsr] [-fp]");
42 fprintf(stderr, " pdp11_binary\n");
46 int main(int argc, char **argv)
50 /* Ensure, before we start, that certain types are right */
51 assert(sizeof(int8_t) == 1);
52 assert(sizeof(u_int8_t) == 1);
53 assert(sizeof(int16_t) == 2);
54 assert(sizeof(u_int16_t) == 2);
55 assert(sizeof(int32_t) == 4);
56 assert(sizeof(u_int32_t) == 4);
60 if (!strcmp(argv[1], "-help"))
62 if (!strcmp(argv[1], "--help"))
67 if (!strcmp(argv[1], "-inst")) {
73 if (!strcmp(argv[1], "-trap")) {
79 if (!strcmp(argv[1], "-jsr")) {
85 if (!strcmp(argv[1], "-fp")) {
93 if (inst_debug | trap_debug | jsr_debug | fp_debug)
94 dbg_file = fopen("apout.dbg", "w");
97 /* Prepare arg list for emulated environment */
102 for (i = 0; i < argc; i++)
105 /* Initialise the stream pointers */
106 for (i = 3; i < NFILE; i++) {
108 streammode[i] = NULL;
117 /* Set the translation to a fictitious */
118 /* root filesystem */
119 if ((apout_root = getenv("APOUT_ROOT"))) {
120 set_apout_root(apout_root);
122 #ifdef APOUT_DONT_ASSUME_ROOT
124 "APOUT_ROOT env variable not set before running apout\n");
131 /* Try to load the binary as an a.out */
132 if (load_a_out(argv[0], NULL, 1) == -1) {
133 fprintf(stderr, "Apout - couldn't load %s\n", argv[0]);
137 /* Other emulated systems (RT-11) can go here */
139 run(); /* Now run the binary */
143 /* Translate from a filename to one which is possibly rooted in $APOUT_ROOT.
144 * Note we return a pointer to one of two buffers. The caller does not
145 * have to free the returned pointer, but successive calls will destroy
146 * calls from >2 calls earlier.
148 char *xlate_filename(char *name)
155 return ("."); /* Undocumented, but used in V7 */
157 return (name); /* Relative, keep it relative */
158 strcpy(rfn[i], name); /* Copy name into buffer */
159 whichrfn = 1 - whichrfn; /* Switch to other buffer next time */
160 return (realfilename[i]);
163 void set_apout_root(char *dirname)
165 strcpy(realfilename[0], dirname);
166 strcpy(realfilename[1], dirname);
167 rfn[0] = realfilename[0];
168 rfn[0] += strlen(realfilename[0]);
169 rfn[1] = realfilename[1];
170 rfn[1] += strlen(realfilename[1]);