1*22514Sdist /*
2*22514Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22514Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22514Sdist  * specifies the terms and conditions for redistribution.
5*22514Sdist  */
65510Slinton 
7*22514Sdist #ifndef lint
8*22514Sdist static char sccsid[] = "@(#)start.c	5.1 (Berkeley) 06/06/85";
9*22514Sdist #endif not lint
105510Slinton /*
115510Slinton  * Begin execution.
125510Slinton  *
135510Slinton  * For px, pstart does a traced exec to read in px and then stop.  But we
145510Slinton  * want control after px has read in the obj file and before it starts
155653Slinton  * executing.  The zeroth argument to px tells it to give us control
165510Slinton  * by sending itself a signal just prior to interpreting.
175510Slinton  *
185510Slinton  * We set a "END_BP" breakpoint at the end of the code so that the
195510Slinton  * process data doesn't disappear after the program terminates.
205510Slinton  */
215510Slinton 
225510Slinton #include "defs.h"
235510Slinton #include <signal.h>
245510Slinton #include "process.h"
255510Slinton #include "machine.h"
265653Slinton #include "main.h"
275510Slinton #include "breakpoint.h"
285510Slinton #include "source.h"
295510Slinton #include "object.h"
305510Slinton #include "mappings.h"
315510Slinton #include "sym.h"
325510Slinton #include "process.rep"
335510Slinton 
345714Slinton #   if (isvaxpx)
355714Slinton #       include "pxinfo.h"
365714Slinton #   endif
375510Slinton 
385510Slinton start(argv, infile, outfile)
395510Slinton char **argv;
405510Slinton char *infile, *outfile;
415510Slinton {
425714Slinton     char *cmd;
435510Slinton 
445714Slinton     setsigtrace();
455714Slinton #   if (isvaxpx)
465714Slinton 	cmd = "px";
475714Slinton #   else
485714Slinton 	cmd = argv[0];
495714Slinton #   endif
505714Slinton     pstart(process, cmd, argv, infile, outfile);
515714Slinton     if (process->status == STOPPED) {
525714Slinton #       if (isvaxpx)
535714Slinton 	    TRAPARGS *ap, t;
545653Slinton 
555714Slinton 	    pcont(process);
565714Slinton 	    if (process->status != STOPPED) {
575714Slinton 		if (option('t')) {
585714Slinton 		    quit(process->exitval);
595714Slinton 		} else {
605714Slinton 		    panic("px exited with %d", process->exitval);
615510Slinton 		}
625714Slinton 	    }
635714Slinton 	    dread(&ap, process->fp + 2*sizeof(int), sizeof(ap));
645714Slinton 	    dread(&t, ap, sizeof(TRAPARGS));
655714Slinton 	    if (t.nargs != 5) {
665714Slinton 		if (option('t')) {
675714Slinton 		    unsetsigtraces(process);
685714Slinton 		    pcont(process);
695714Slinton 		    quit(process->exitval);
705714Slinton 		} else {
715714Slinton 		    panic("start: args out of sync");
725714Slinton 		}
735714Slinton 	    }
745714Slinton 	    DISPLAY = t.disp;
755714Slinton 	    DP = t.dp;
765714Slinton 	    ENDOFF = t.objstart;
775714Slinton 	    PCADDRP = t.pcaddrp;
785714Slinton 	    LOOPADDR = t.loopaddr;
795714Slinton #       endif
805714Slinton 	pc = 0;
815714Slinton 	curfunc = program;
825714Slinton 	if (objsize != 0) {
835714Slinton 	    addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0);
845510Slinton 	}
855714Slinton     }
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 {
995714Slinton     if (ss_variables) {
1005714Slinton 	prvarnews();
1015714Slinton     }
1025714Slinton     printf("\nexecution completed\n");
1035714Slinton     curfunc = program;
1045761Slinton     skimsource(srcfilename(pc));
1055714Slinton     curline = lastlinenum;
1065714Slinton     erecover();
1075510Slinton }
1085510Slinton 
1095510Slinton /*
1105510Slinton  * set up what signals we want to trace
1115510Slinton  */
1125510Slinton 
1135510Slinton LOCAL setsigtrace()
1145510Slinton {
1155714Slinton     register int i;
1165714Slinton     register PROCESS *p;
1175510Slinton 
1185714Slinton     p = process;
1195714Slinton     psigtrace(p, SIGINT, TRUE);
1205714Slinton     psigtrace(p, SIGTRAP, TRUE);
1215714Slinton     psigtrace(p, SIGIOT, TRUE);
1225739Slinton     psigtrace(p, SIGILL, TRUE);
1235761Slinton     psigtrace(p, SIGBUS, TRUE);
1245510Slinton }
125