15510Slinton /* Copyright (c) 1982 Regents of the University of California */
25510Slinton 
3*5714Slinton static char sccsid[] = "@(#)start.c 1.3 02/07/82";
45510Slinton 
55510Slinton /*
65510Slinton  * Begin execution.
75510Slinton  *
85510Slinton  * For px, pstart does a traced exec to read in px and then stop.  But we
95510Slinton  * want control after px has read in the obj file and before it starts
105653Slinton  * executing.  The zeroth argument to px tells it to give us control
115510Slinton  * by sending itself a signal just prior to interpreting.
125510Slinton  *
135510Slinton  * We set a "END_BP" breakpoint at the end of the code so that the
145510Slinton  * process data doesn't disappear after the program terminates.
155510Slinton  */
165510Slinton 
175510Slinton #include "defs.h"
185510Slinton #include <signal.h>
195510Slinton #include "process.h"
205510Slinton #include "machine.h"
215653Slinton #include "main.h"
225510Slinton #include "breakpoint.h"
235510Slinton #include "source.h"
245510Slinton #include "object.h"
255510Slinton #include "mappings.h"
265510Slinton #include "sym.h"
275510Slinton #include "process.rep"
285510Slinton 
29*5714Slinton #   if (isvaxpx)
30*5714Slinton #       include "pxinfo.h"
31*5714Slinton #   endif
325510Slinton 
335510Slinton LOCAL PROCESS pbuf;
345510Slinton 
355510Slinton start(argv, infile, outfile)
365510Slinton char **argv;
375510Slinton char *infile, *outfile;
385510Slinton {
39*5714Slinton     char *cmd;
405510Slinton 
41*5714Slinton     process = &pbuf;
42*5714Slinton     setsigtrace();
43*5714Slinton #   if (isvaxpx)
44*5714Slinton 	cmd = "px";
45*5714Slinton #   else
46*5714Slinton 	cmd = argv[0];
47*5714Slinton #   endif
48*5714Slinton     pstart(process, cmd, argv, infile, outfile);
49*5714Slinton     if (process->status == STOPPED) {
50*5714Slinton #       if (isvaxpx)
51*5714Slinton 	    TRAPARGS *ap, t;
525653Slinton 
53*5714Slinton 	    pcont(process);
54*5714Slinton 	    if (process->status != STOPPED) {
55*5714Slinton 		if (option('t')) {
56*5714Slinton 		    quit(process->exitval);
57*5714Slinton 		} else {
58*5714Slinton 		    panic("px exited with %d", process->exitval);
595510Slinton 		}
60*5714Slinton 	    }
61*5714Slinton 	    dread(&ap, process->fp + 2*sizeof(int), sizeof(ap));
62*5714Slinton 	    dread(&t, ap, sizeof(TRAPARGS));
63*5714Slinton 	    if (t.nargs != 5) {
64*5714Slinton 		if (option('t')) {
65*5714Slinton 		    unsetsigtraces(process);
66*5714Slinton 		    pcont(process);
67*5714Slinton 		    quit(process->exitval);
68*5714Slinton 		} else {
69*5714Slinton 		    panic("start: args out of sync");
70*5714Slinton 		}
71*5714Slinton 	    }
72*5714Slinton 	    DISPLAY = t.disp;
73*5714Slinton 	    DP = t.dp;
74*5714Slinton 	    ENDOFF = t.objstart;
75*5714Slinton 	    PCADDRP = t.pcaddrp;
76*5714Slinton 	    LOOPADDR = t.loopaddr;
77*5714Slinton #       endif
78*5714Slinton 	pc = 0;
79*5714Slinton 	curfunc = program;
80*5714Slinton 	if (objsize != 0) {
81*5714Slinton 	    addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0);
825510Slinton 	}
83*5714Slinton     } else {
84*5714Slinton 	panic("could not start program");
85*5714Slinton     }
865510Slinton }
875510Slinton 
885510Slinton /*
895510Slinton  * Note the termination of the program.  We do this so as to avoid
905510Slinton  * having the process exit, which would make the values of variables
915510Slinton  * inaccessible.
925510Slinton  *
935510Slinton  * Although the END_BP should really be deleted, it is taken
945510Slinton  * care of by fixbps the next time the program runs.
955510Slinton  */
965510Slinton 
975510Slinton endprogram()
985510Slinton {
99*5714Slinton     char *filename;
1005510Slinton 
101*5714Slinton     if (ss_variables) {
102*5714Slinton 	prvarnews();
103*5714Slinton     }
104*5714Slinton     printf("\nexecution completed\n");
105*5714Slinton     curfunc = program;
106*5714Slinton     if ((filename = srcfilename(pc)) != cursource) {
107*5714Slinton 	skimsource(filename);
108*5714Slinton     }
109*5714Slinton     curline = lastlinenum;
110*5714Slinton     erecover();
1115510Slinton }
1125510Slinton 
1135510Slinton /*
1145510Slinton  * set up what signals we want to trace
1155510Slinton  */
1165510Slinton 
1175510Slinton LOCAL setsigtrace()
1185510Slinton {
119*5714Slinton     register int i;
120*5714Slinton     register PROCESS *p;
1215510Slinton 
122*5714Slinton     p = process;
123*5714Slinton     psigtrace(p, SIGINT, TRUE);
124*5714Slinton     psigtrace(p, SIGTRAP, TRUE);
125*5714Slinton     psigtrace(p, SIGIOT, TRUE);
1265510Slinton }
127