Commit | Line | Data |
---|---|---|
1e2b51bb KM |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | ||
79029c32 | 3 | /* static char sccsid[] = "@(#)vars.h 1.8 %G%"; */ |
1e2b51bb KM |
4 | |
5 | #include <stdio.h> | |
6 | ||
7 | /* | |
8 | * px - Berkeley Pascal interpreter | |
9 | * | |
10 | * Version 4.0, January 1981 | |
11 | * | |
12 | * Original version by Ken Thompson | |
13 | * | |
14 | * Substantial revisions by Bill Joy and Chuck Haley | |
15 | * November-December 1976 | |
16 | * | |
17 | * Rewritten for VAX 11/780 by Kirk McKusick | |
18 | * Fall 1978 | |
19 | * | |
20 | * Rewritten in ``C'' using libpc by Kirk McKusick | |
21 | * Winter 1981 | |
22 | * | |
23 | * Px is described in detail in the "PX 4.0 Implementation Notes" | |
24 | * The source code for px is in several major pieces: | |
25 | * | |
26 | * int.c C main program which reads in interpreter code | |
27 | * interp.c Driver including main interpreter loop and | |
28 | * the interpreter instructions grouped by their | |
29 | * positions in the interpreter table. | |
30 | * except.c Handlers for interpreter specific errors not | |
31 | * included in libpc. | |
32 | * utilities.c Interpreter exit, backtrace, and runtime statistics. | |
33 | * | |
34 | * In addition there are several headers defining mappings for panic | |
35 | * names into codes, and a definition of the interpreter transfer | |
36 | * table. These are made by the script make.ed1 in this directory and | |
37 | * the routine opc.c from ${PASCALDIR}. (see the makefile for details) | |
38 | */ | |
39 | #define PXPFILE "pmon.out" | |
40 | #define BITSPERBYTE 8 | |
41 | #define BITSPERLONG (BITSPERBYTE * sizeof(long)) | |
42 | #define HZ 60 | |
1e2b51bb KM |
43 | #define MAXLVL 20 |
44 | #define NAMSIZ 76 | |
45 | #define MAXFILES 32 | |
46 | #define PREDEF 2 | |
9a92014d | 47 | #ifdef VAX |
1e2b51bb KM |
48 | #define STDLVL ((struct iorec *)(0x7ffffff1)) |
49 | #define GLVL ((struct iorec *)(0x7ffffff0)) | |
9a92014d KM |
50 | #else |
51 | #define STDLVL ((struct iorec *)(0xfff1)) | |
52 | #define GLVL ((struct iorec *)(0xfff0)) | |
53 | #endif VAX | |
1e2b51bb KM |
54 | #define FILNIL ((struct iorec *)(0)) |
55 | #define INPUT ((struct iorec *)(&input)) | |
56 | #define OUTPUT ((struct iorec *)(&output)) | |
57 | #define ERR ((struct iorec *)(&_err)) | |
58 | #define PX 0 /* normal run of px */ | |
59 | #define PIX 1 /* load and go */ | |
60 | #define PIPE 2 /* bootstrap via a pipe */ | |
79029c32 | 61 | #define PDX 3 /* invoked by the debugger "pdx" */ |
1e2b51bb | 62 | #define releq 0 |
15834a19 KM |
63 | #define relne 2 |
64 | #define rellt 4 | |
65 | #define relgt 6 | |
66 | #define relle 8 | |
67 | #define relge 10 | |
9a92014d | 68 | typedef enum {FALSE, TRUE} bool; |
1e2b51bb KM |
69 | |
70 | /* | |
71 | * interrupt and allocation routines | |
72 | */ | |
73 | extern long createtime; | |
74 | extern char *PALLOC(); | |
75 | extern char *malloc(); | |
9a92014d | 76 | extern long time(); |
1e2b51bb KM |
77 | extern intr(); |
78 | extern memsize(); | |
79 | extern except(); | |
80 | extern syserr(); | |
81 | extern liberr(); | |
82 | ||
83 | /* | |
796c7f60 | 84 | * stack routines and structures |
1e2b51bb | 85 | */ |
796c7f60 KM |
86 | struct sze8 { |
87 | char element[8]; | |
88 | }; | |
1e2b51bb KM |
89 | extern short pop2(); |
90 | extern long pop4(); | |
91 | extern double pop8(); | |
796c7f60 | 92 | extern struct sze8 popsze8(); |
1e2b51bb KM |
93 | extern char *pushsp(); |
94 | ||
95 | /* | |
96 | * emulated pc types | |
97 | */ | |
98 | union progcntr { | |
99 | char *cp; | |
100 | unsigned char *ucp; | |
101 | short *sp; | |
102 | unsigned short *usp; | |
103 | long *lp; | |
9a92014d | 104 | double *dbp; |
1e2b51bb KM |
105 | struct hdr *hdrp; |
106 | }; | |
107 | \f | |
108 | /* | |
109 | * THE RUNTIME DISPLAY | |
110 | * | |
111 | * The entries in the display point to the active static block marks. | |
112 | * The first entry in the display is for the global variables, | |
113 | * then the procedure or function at level one, etc. | |
114 | * Each display entry points to a stack frame as shown: | |
115 | * | |
116 | * base of stack frame | |
117 | * --------------- | |
118 | * | | | |
119 | * | block mark | | |
120 | * | | | |
15834a19 KM |
121 | * --------------- <-- display entry "stp" points here |
122 | * | | <-- display entry "locvars" points here | |
1e2b51bb KM |
123 | * | local | |
124 | * | variables | | |
125 | * | | | |
126 | * --------------- | |
127 | * | | | |
128 | * | expression | | |
129 | * | temporary | | |
130 | * | storage | | |
131 | * | | | |
132 | * - - - - - - - - | |
133 | * | |
134 | * The information in the block mark is thus at positive offsets from | |
15834a19 KM |
135 | * the display.stp pointer entries while the local variables are at negative |
136 | * offsets from display.locvars. The block mark actually consists of | |
137 | * two parts. The first part is created at CALL and the second at entry, | |
138 | * i.e. BEGIN. Thus: | |
1e2b51bb KM |
139 | * |
140 | * ------------------------- | |
141 | * | | | |
142 | * | Saved lino | | |
143 | * | Saved lc | | |
144 | * | Saved dp | | |
145 | * | | | |
146 | * ------------------------- | |
147 | * | | | |
148 | * | Saved (dp) | | |
149 | * | | | |
15834a19 KM |
150 | * | Pointer to current | |
151 | * | routine header info | | |
1e2b51bb | 152 | * | | |
15834a19 KM |
153 | * | Saved value of | |
154 | * | "curfile" | | |
1e2b51bb KM |
155 | * | | |
156 | * | Empty tos value | | |
157 | * | | | |
158 | * ------------------------- | |
159 | */ | |
160 | \f | |
161 | /* | |
162 | * runtime display structure | |
163 | */ | |
164 | struct disp { | |
165 | char *locvars; /* pointer to local variables */ | |
166 | struct stack *stp; /* pointer to local stack frame */ | |
167 | }; | |
168 | ||
169 | struct stack { | |
170 | char *tos; /* pointer to top of stack frame */ | |
171 | struct iorec *file; /* pointer to active file name */ | |
172 | struct hdr { | |
173 | long framesze; /* number of bytes of local vars */ | |
174 | long nargs; /* number of bytes of arguments */ | |
9a92014d | 175 | bool tests; /* TRUE => perform runtime tests */ |
1e2b51bb KM |
176 | short offset; /* offset of procedure in source file */ |
177 | char name[1]; /* name of active procedure */ | |
178 | } *entry; | |
179 | struct disp odisp; /* previous display value for this level */ | |
180 | struct disp *dp; /* pointer to active display entry */ | |
181 | union progcntr pc; /* previous location counter */ | |
182 | long lino; /* previous line number */ | |
183 | }; | |
184 | ||
15834a19 KM |
185 | union disply { |
186 | struct disp frame[MAXLVL]; | |
187 | char *raw[2*MAXLVL]; | |
188 | }; | |
189 | ||
1e2b51bb KM |
190 | /* |
191 | * formal routine structure | |
192 | */ | |
193 | struct formalrtn { | |
6b4e6ddb KM |
194 | char *fentryaddr; /* formal entry point */ |
195 | long fbn; /* block number of function */ | |
196 | struct disp fdisp[ MAXLVL ]; /* saved at first passing */ | |
1e2b51bb KM |
197 | }; |
198 | ||
199 | /* | |
200 | * program variables | |
201 | */ | |
15834a19 KM |
202 | extern union disply _display; /* runtime display */ |
203 | extern struct disp *_dp; /* ptr to active frame */ | |
204 | extern long _lino; /* current line number */ | |
205 | extern int _argc; /* number of passed args */ | |
206 | extern char **_argv; /* values of passed args */ | |
9a92014d KM |
207 | extern bool _nodump; /* TRUE => no post mortum dump */ |
208 | extern bool _runtst; /* TRUE => runtime tests */ | |
15834a19 KM |
209 | extern long _mode; /* execl by PX, PIPE, or PIX */ |
210 | extern long _stlim; /* statement limit */ | |
211 | extern long _stcnt; /* statement count */ | |
50d6e33c | 212 | extern long _seed; /* random number seed */ |
15834a19 KM |
213 | extern char *_maxptr; /* maximum valid pointer */ |
214 | extern char *_minptr; /* minimum valid pointer */ | |
215 | extern long *_pcpcount; /* pointer to pxp buffer */ | |
216 | extern long _cntrs; /* number of counters */ | |
217 | extern long _rtns; /* number of routine cntrs */ | |
218 | \f | |
1e2b51bb KM |
219 | /* |
220 | * The file i/o routines maintain a notion of a "current file". | |
221 | * A pointer to this file structure is kept in "curfile". | |
222 | * | |
223 | * file structures | |
224 | */ | |
225 | struct iorechd { | |
226 | char *fileptr; /* ptr to file window */ | |
227 | long lcount; /* number of lines printed */ | |
228 | long llimit; /* maximum number of text lines */ | |
229 | FILE *fbuf; /* FILE ptr */ | |
230 | struct iorec *fchain; /* chain to next file */ | |
231 | struct iorec *flev; /* ptr to associated file variable */ | |
232 | char *pfname; /* ptr to name of file */ | |
233 | short funit; /* file status flags */ | |
234 | short fblk; /* index into active file table */ | |
235 | long fsize; /* size of elements in the file */ | |
236 | char fname[NAMSIZ]; /* name of associated UNIX file */ | |
237 | }; | |
238 | ||
239 | struct iorec { | |
240 | char *fileptr; /* ptr to file window */ | |
241 | long lcount; /* number of lines printed */ | |
242 | long llimit; /* maximum number of text lines */ | |
243 | FILE *fbuf; /* FILE ptr */ | |
244 | struct iorec *fchain; /* chain to next file */ | |
245 | struct iorec *flev; /* ptr to associated file variable */ | |
246 | char *pfname; /* ptr to name of file */ | |
247 | short funit; /* file status flags */ | |
248 | short fblk; /* index into active file table */ | |
249 | long fsize; /* size of elements in the file */ | |
250 | char fname[NAMSIZ]; /* name of associated UNIX file */ | |
251 | char buf[BUFSIZ]; /* I/O buffer */ | |
252 | char window[1]; /* file window element */ | |
253 | }; | |
15834a19 | 254 | \f |
1e2b51bb KM |
255 | /* |
256 | * unit flags | |
257 | */ | |
258 | #define FDEF 0x80 /* 1 => reserved file name */ | |
259 | #define FTEXT 0x40 /* 1 => text file, process EOLN */ | |
260 | #define FWRITE 0x20 /* 1 => open for writing */ | |
261 | #define FREAD 0x10 /* 1 => open for reading */ | |
262 | #define TEMP 0x08 /* 1 => temporary file */ | |
263 | #define SYNC 0x04 /* 1 => window is out of sync */ | |
264 | #define EOLN 0x02 /* 1 => at end of line */ | |
265 | #define EOFF 0x01 /* 1 => at end of file */ | |
266 | ||
267 | /* | |
268 | * file routines | |
269 | */ | |
270 | extern struct iorec *GETNAME(); | |
271 | extern char *MKTEMP(); | |
272 | ||
273 | /* | |
274 | * file record variables | |
275 | */ | |
276 | extern struct iorechd _fchain; /* head of active file chain */ | |
277 | extern struct iorec *_actfile[]; /* table of active files */ | |
278 | extern long _filefre; /* last used entry in _actfile */ | |
279 | ||
280 | /* | |
281 | * standard files | |
282 | */ | |
283 | extern struct iorechd input; | |
284 | extern struct iorechd output; | |
285 | extern struct iorechd _err; | |
15834a19 | 286 | |
1e2b51bb | 287 | /* |
15834a19 | 288 | * Px execution profile array |
1e2b51bb | 289 | */ |
15834a19 KM |
290 | #ifdef PROFILE |
291 | #define NUMOPS 256 | |
292 | extern long _profcnts[NUMOPS]; | |
293 | #endif PROFILE |