BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / pascal / pdx / process / start.c
CommitLineData
505bf312
KB
1/*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
af359dea
C
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
f644bb55 32 */
b4b7c436 33
f644bb55 34#ifndef lint
af359dea 35static char sccsid[] = "@(#)start.c 5.4 (Berkeley) 4/16/91";
505bf312 36#endif /* not lint */
82d3cd01 37
b4b7c436
ML
38/*
39 * Begin execution.
40 *
41 * For px, pstart does a traced exec to read in px and then stop. But we
42 * want control after px has read in the obj file and before it starts
da31632a 43 * executing. The zeroth argument to px tells it to give us control
b4b7c436
ML
44 * by sending itself a signal just prior to interpreting.
45 *
46 * We set a "END_BP" breakpoint at the end of the code so that the
47 * process data doesn't disappear after the program terminates.
48 */
49
50#include "defs.h"
51#include <signal.h>
52#include "process.h"
53#include "machine.h"
da31632a 54#include "main.h"
b4b7c436
ML
55#include "breakpoint.h"
56#include "source.h"
57#include "object.h"
58#include "mappings.h"
59#include "sym.h"
60#include "process.rep"
61
82d3cd01 62#include "pxinfo.h"
b4b7c436 63
b4b7c436
ML
64start(argv, infile, outfile)
65char **argv;
66char *infile, *outfile;
67{
eb010214 68 char *cmd;
b4b7c436 69
eb010214 70 setsigtrace();
24ba2374 71 cmd = "px";
eb010214
ML
72 pstart(process, cmd, argv, infile, outfile);
73 if (process->status == STOPPED) {
82d3cd01 74 TRAPARGS *ap, t;
da31632a 75
82d3cd01
KM
76 pcont(process);
77 if (process->status != STOPPED) {
78 if (option('t')) {
79 quit(process->exitval);
80 } else {
81 panic("px exited with %d", process->exitval);
eb010214 82 }
82d3cd01
KM
83 }
84#ifdef tahoe
85 dread(&ap, process->fp, sizeof(ap));
86 ap = (TRAPARGS *)((unsigned)ap - 4);
87 dread(&RETLOC, process->fp - 8, sizeof(RETLOC));
88#else
89 dread(&ap, process->fp + 2*sizeof(int), sizeof(ap));
90#endif
91 dread(&t, ap, sizeof(TRAPARGS));
92
93#define NARGS 5
94#ifdef tahoe
95# define STKNARGS (sizeof(int)*(NARGS+1))
96# define NARGLOC t.trp_removed
97#else
98# define STKNARGS (NARGS)
99# define NARGLOC t.nargs
100#endif
101 if (NARGLOC != STKNARGS) {
102 if (option('t')) {
103 unsetsigtraces(process);
104 pcont(process);
105 quit(process->exitval);
106 } else {
107 panic("start: args out of sync");
eb010214 108 }
82d3cd01
KM
109 }
110 DISPLAY = t.disp;
111 DP = t.dp;
112 ENDOFF = t.objstart;
24ba2374 113 PCADDR = t.pcaddr;
82d3cd01 114 LOOPADDR = t.loopaddr;
eb010214
ML
115 pc = 0;
116 curfunc = program;
117 if (objsize != 0) {
118 addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0);
b4b7c436 119 }
eb010214 120 }
b4b7c436
ML
121}
122
123/*
124 * Note the termination of the program. We do this so as to avoid
125 * having the process exit, which would make the values of variables
126 * inaccessible.
127 *
128 * Although the END_BP should really be deleted, it is taken
129 * care of by fixbps the next time the program runs.
130 */
131
132endprogram()
133{
eb010214
ML
134 if (ss_variables) {
135 prvarnews();
136 }
137 printf("\nexecution completed\n");
138 curfunc = program;
cc7a61ee 139 skimsource(srcfilename(pc));
eb010214
ML
140 curline = lastlinenum;
141 erecover();
b4b7c436
ML
142}
143
144/*
145 * set up what signals we want to trace
146 */
147
148LOCAL setsigtrace()
149{
eb010214 150 register PROCESS *p;
b4b7c436 151
eb010214
ML
152 p = process;
153 psigtrace(p, SIGINT, TRUE);
154 psigtrace(p, SIGTRAP, TRUE);
155 psigtrace(p, SIGIOT, TRUE);
5642e311 156 psigtrace(p, SIGILL, TRUE);
cc7a61ee 157 psigtrace(p, SIGBUS, TRUE);
b4b7c436 158}