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