16018b877Sbostic /*-
2*5da4261cSbostic  * Copyright (c) 1980, 1993
3*5da4261cSbostic  *	The Regents of the University of California.  All rights reserved.
46018b877Sbostic  *
56018b877Sbostic  * %sccs.include.redist.c%
665ac3e67Sdist  */
7e82c2e90Slinton 
865ac3e67Sdist #ifndef lint
9*5da4261cSbostic static char sccsid[] = "@(#)start.c	8.1 (Berkeley) 06/06/93";
106018b877Sbostic #endif /* not lint */
11c4b5ba38Smckusick 
12e82c2e90Slinton /*
13e82c2e90Slinton  * Begin execution.
14e82c2e90Slinton  *
15e82c2e90Slinton  * For px, pstart does a traced exec to read in px and then stop.  But we
16e82c2e90Slinton  * want control after px has read in the obj file and before it starts
173a0a088bSlinton  * executing.  The zeroth argument to px tells it to give us control
18e82c2e90Slinton  * by sending itself a signal just prior to interpreting.
19e82c2e90Slinton  *
20e82c2e90Slinton  * We set a "END_BP" breakpoint at the end of the code so that the
21e82c2e90Slinton  * process data doesn't disappear after the program terminates.
22e82c2e90Slinton  */
23e82c2e90Slinton 
24e82c2e90Slinton #include "defs.h"
25e82c2e90Slinton #include <signal.h>
26e82c2e90Slinton #include "process.h"
27e82c2e90Slinton #include "machine.h"
283a0a088bSlinton #include "main.h"
29e82c2e90Slinton #include "breakpoint.h"
30e82c2e90Slinton #include "source.h"
31e82c2e90Slinton #include "object.h"
32e82c2e90Slinton #include "mappings.h"
33e82c2e90Slinton #include "sym.h"
34e82c2e90Slinton #include "process.rep"
35e82c2e90Slinton 
36e82c2e90Slinton #include "pxinfo.h"
37e82c2e90Slinton 
start(argv,infile,outfile)38e82c2e90Slinton start(argv, infile, outfile)
39e82c2e90Slinton char **argv;
40e82c2e90Slinton char *infile, *outfile;
41e82c2e90Slinton {
423a0a088bSlinton     char *cmd;
43e82c2e90Slinton 
44e82c2e90Slinton     setsigtrace();
4532dc4fbcSmckusick     cmd = "px";
463a0a088bSlinton     pstart(process, cmd, argv, infile, outfile);
47e82c2e90Slinton     if (process->status == STOPPED) {
483a0a088bSlinton 	TRAPARGS *ap, t;
493a0a088bSlinton 
50e82c2e90Slinton 	pcont(process);
51e82c2e90Slinton 	if (process->status != STOPPED) {
523a0a088bSlinton 	    if (option('t')) {
533a0a088bSlinton 		quit(process->exitval);
543a0a088bSlinton 	    } else {
55e82c2e90Slinton 		panic("px exited with %d", process->exitval);
56e82c2e90Slinton 	    }
573a0a088bSlinton 	}
58c4b5ba38Smckusick #ifdef tahoe
59c4b5ba38Smckusick 	dread(&ap, process->fp, sizeof(ap));
60c4b5ba38Smckusick 	ap = (TRAPARGS *)((unsigned)ap - 4);
61c4b5ba38Smckusick 	dread(&RETLOC, process->fp - 8, sizeof(RETLOC));
62c4b5ba38Smckusick #else
63e82c2e90Slinton 	dread(&ap, process->fp + 2*sizeof(int), sizeof(ap));
64c4b5ba38Smckusick #endif
65e82c2e90Slinton 	dread(&t, ap, sizeof(TRAPARGS));
66c4b5ba38Smckusick 
67c4b5ba38Smckusick #define NARGS 5
68c4b5ba38Smckusick #ifdef tahoe
69c4b5ba38Smckusick #	define STKNARGS (sizeof(int)*(NARGS+1))
70c4b5ba38Smckusick #	define NARGLOC  t.trp_removed
71c4b5ba38Smckusick #else
72c4b5ba38Smckusick #	define STKNARGS (NARGS)
73c4b5ba38Smckusick #	define NARGLOC  t.nargs
74c4b5ba38Smckusick #endif
75c4b5ba38Smckusick 	if (NARGLOC != STKNARGS) {
763a0a088bSlinton 	    if (option('t')) {
773a0a088bSlinton 		unsetsigtraces(process);
783a0a088bSlinton 		pcont(process);
793a0a088bSlinton 		quit(process->exitval);
803a0a088bSlinton 	    } else {
81e82c2e90Slinton 		panic("start: args out of sync");
82e82c2e90Slinton 	    }
833a0a088bSlinton 	}
84e82c2e90Slinton 	DISPLAY = t.disp;
85e82c2e90Slinton 	DP = t.dp;
86e82c2e90Slinton 	ENDOFF = t.objstart;
8732dc4fbcSmckusick 	PCADDR = t.pcaddr;
88e82c2e90Slinton 	LOOPADDR = t.loopaddr;
89e82c2e90Slinton 	pc = 0;
90e82c2e90Slinton 	curfunc = program;
91e82c2e90Slinton 	if (objsize != 0) {
92e82c2e90Slinton 	    addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0);
93e82c2e90Slinton 	}
94e82c2e90Slinton     }
95e82c2e90Slinton }
96e82c2e90Slinton 
97e82c2e90Slinton /*
98e82c2e90Slinton  * Note the termination of the program.  We do this so as to avoid
99e82c2e90Slinton  * having the process exit, which would make the values of variables
100e82c2e90Slinton  * inaccessible.
101e82c2e90Slinton  *
102e82c2e90Slinton  * Although the END_BP should really be deleted, it is taken
103e82c2e90Slinton  * care of by fixbps the next time the program runs.
104e82c2e90Slinton  */
105e82c2e90Slinton 
endprogram()106e82c2e90Slinton endprogram()
107e82c2e90Slinton {
108e82c2e90Slinton     if (ss_variables) {
109e82c2e90Slinton 	prvarnews();
110e82c2e90Slinton     }
111e82c2e90Slinton     printf("\nexecution completed\n");
112e82c2e90Slinton     curfunc = program;
1138c071c2cSlinton     skimsource(srcfilename(pc));
114e82c2e90Slinton     curline = lastlinenum;
115e82c2e90Slinton     erecover();
116e82c2e90Slinton }
117e82c2e90Slinton 
118e82c2e90Slinton /*
119e82c2e90Slinton  * set up what signals we want to trace
120e82c2e90Slinton  */
121e82c2e90Slinton 
setsigtrace()122e82c2e90Slinton LOCAL setsigtrace()
123e82c2e90Slinton {
124e82c2e90Slinton     register PROCESS *p;
125e82c2e90Slinton 
126e82c2e90Slinton     p = process;
127e8826853Slinton     psigtrace(p, SIGINT, TRUE);
128e8826853Slinton     psigtrace(p, SIGTRAP, TRUE);
129e8826853Slinton     psigtrace(p, SIGIOT, TRUE);
13021ec37d2Slinton     psigtrace(p, SIGILL, TRUE);
1318c071c2cSlinton     psigtrace(p, SIGBUS, TRUE);
132e82c2e90Slinton }
133