BSD 4_3_Net_2 development
[unix-history] / .ref-8c8a5b54e79564c14fc7a2823a21a8f048449bcf / 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 *
5 * %sccs.include.redist.c%
f644bb55 6 */
b4b7c436 7
f644bb55 8#ifndef lint
505bf312
KB
9static char sccsid[] = "@(#)start.c 5.4 (Berkeley) %G%";
10#endif /* not lint */
82d3cd01 11
b4b7c436
ML
12/*
13 * Begin execution.
14 *
15 * For px, pstart does a traced exec to read in px and then stop. But we
16 * want control after px has read in the obj file and before it starts
da31632a 17 * executing. The zeroth argument to px tells it to give us control
b4b7c436
ML
18 * by sending itself a signal just prior to interpreting.
19 *
20 * We set a "END_BP" breakpoint at the end of the code so that the
21 * process data doesn't disappear after the program terminates.
22 */
23
24#include "defs.h"
25#include <signal.h>
26#include "process.h"
27#include "machine.h"
da31632a 28#include "main.h"
b4b7c436
ML
29#include "breakpoint.h"
30#include "source.h"
31#include "object.h"
32#include "mappings.h"
33#include "sym.h"
34#include "process.rep"
35
82d3cd01 36#include "pxinfo.h"
b4b7c436 37
b4b7c436
ML
38start(argv, infile, outfile)
39char **argv;
40char *infile, *outfile;
41{
eb010214 42 char *cmd;
b4b7c436 43
eb010214 44 setsigtrace();
24ba2374 45 cmd = "px";
eb010214
ML
46 pstart(process, cmd, argv, infile, outfile);
47 if (process->status == STOPPED) {
82d3cd01 48 TRAPARGS *ap, t;
da31632a 49
82d3cd01
KM
50 pcont(process);
51 if (process->status != STOPPED) {
52 if (option('t')) {
53 quit(process->exitval);
54 } else {
55 panic("px exited with %d", process->exitval);
eb010214 56 }
82d3cd01
KM
57 }
58#ifdef tahoe
59 dread(&ap, process->fp, sizeof(ap));
60 ap = (TRAPARGS *)((unsigned)ap - 4);
61 dread(&RETLOC, process->fp - 8, sizeof(RETLOC));
62#else
63 dread(&ap, process->fp + 2*sizeof(int), sizeof(ap));
64#endif
65 dread(&t, ap, sizeof(TRAPARGS));
66
67#define NARGS 5
68#ifdef tahoe
69# define STKNARGS (sizeof(int)*(NARGS+1))
70# define NARGLOC t.trp_removed
71#else
72# define STKNARGS (NARGS)
73# define NARGLOC t.nargs
74#endif
75 if (NARGLOC != STKNARGS) {
76 if (option('t')) {
77 unsetsigtraces(process);
78 pcont(process);
79 quit(process->exitval);
80 } else {
81 panic("start: args out of sync");
eb010214 82 }
82d3cd01
KM
83 }
84 DISPLAY = t.disp;
85 DP = t.dp;
86 ENDOFF = t.objstart;
24ba2374 87 PCADDR = t.pcaddr;
82d3cd01 88 LOOPADDR = t.loopaddr;
eb010214
ML
89 pc = 0;
90 curfunc = program;
91 if (objsize != 0) {
92 addbp(lastaddr(), END_BP, NIL, NIL, NIL, 0);
b4b7c436 93 }
eb010214 94 }
b4b7c436
ML
95}
96
97/*
98 * Note the termination of the program. We do this so as to avoid
99 * having the process exit, which would make the values of variables
100 * inaccessible.
101 *
102 * Although the END_BP should really be deleted, it is taken
103 * care of by fixbps the next time the program runs.
104 */
105
106endprogram()
107{
eb010214
ML
108 if (ss_variables) {
109 prvarnews();
110 }
111 printf("\nexecution completed\n");
112 curfunc = program;
cc7a61ee 113 skimsource(srcfilename(pc));
eb010214
ML
114 curline = lastlinenum;
115 erecover();
b4b7c436
ML
116}
117
118/*
119 * set up what signals we want to trace
120 */
121
122LOCAL setsigtrace()
123{
eb010214 124 register PROCESS *p;
b4b7c436 125
eb010214
ML
126 p = process;
127 psigtrace(p, SIGINT, TRUE);
128 psigtrace(p, SIGTRAP, TRUE);
129 psigtrace(p, SIGIOT, TRUE);
5642e311 130 psigtrace(p, SIGILL, TRUE);
cc7a61ee 131 psigtrace(p, SIGBUS, TRUE);
b4b7c436 132}