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