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