1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 /* static char sccsid[] = "@(#)vars.h 1.6 03/06/81"; */ 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 43 #define MAXLVL 20 44 #define NAMSIZ 76 45 #define MAXFILES 32 46 #define PREDEF 2 47 #ifdef VAX 48 #define STDLVL ((struct iorec *)(0x7ffffff1)) 49 #define GLVL ((struct iorec *)(0x7ffffff0)) 50 #else 51 #define STDLVL ((struct iorec *)(0xfff1)) 52 #define GLVL ((struct iorec *)(0xfff0)) 53 #endif VAX 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 */ 61 #define releq 0 62 #define relne 2 63 #define rellt 4 64 #define relgt 6 65 #define relle 8 66 #define relge 10 67 typedef enum {FALSE, TRUE} bool; 68 69 /* 70 * interrupt and allocation routines 71 */ 72 extern long createtime; 73 extern char *PALLOC(); 74 extern char *malloc(); 75 extern long time(); 76 extern intr(); 77 extern memsize(); 78 extern except(); 79 extern syserr(); 80 extern liberr(); 81 82 /* 83 * stack routines and structures 84 */ 85 struct sze8 { 86 char element[8]; 87 }; 88 extern short pop2(); 89 extern long pop4(); 90 extern double pop8(); 91 extern struct sze8 popsze8(); 92 extern char *pushsp(); 93 94 /* 95 * emulated pc types 96 */ 97 union progcntr { 98 char *cp; 99 unsigned char *ucp; 100 short *sp; 101 unsigned short *usp; 102 long *lp; 103 double *dbp; 104 struct hdr *hdrp; 105 }; 106 107 /* 108 * THE RUNTIME DISPLAY 109 * 110 * The entries in the display point to the active static block marks. 111 * The first entry in the display is for the global variables, 112 * then the procedure or function at level one, etc. 113 * Each display entry points to a stack frame as shown: 114 * 115 * base of stack frame 116 * --------------- 117 * | | 118 * | block mark | 119 * | | 120 * --------------- <-- display entry "stp" points here 121 * | | <-- display entry "locvars" points here 122 * | local | 123 * | variables | 124 * | | 125 * --------------- 126 * | | 127 * | expression | 128 * | temporary | 129 * | storage | 130 * | | 131 * - - - - - - - - 132 * 133 * The information in the block mark is thus at positive offsets from 134 * the display.stp pointer entries while the local variables are at negative 135 * offsets from display.locvars. The block mark actually consists of 136 * two parts. The first part is created at CALL and the second at entry, 137 * i.e. BEGIN. Thus: 138 * 139 * ------------------------- 140 * | | 141 * | Saved lino | 142 * | Saved lc | 143 * | Saved dp | 144 * | | 145 * ------------------------- 146 * | | 147 * | Saved (dp) | 148 * | | 149 * | Pointer to current | 150 * | routine header info | 151 * | | 152 * | Saved value of | 153 * | "curfile" | 154 * | | 155 * | Empty tos value | 156 * | | 157 * ------------------------- 158 */ 159 160 /* 161 * runtime display structure 162 */ 163 struct disp { 164 char *locvars; /* pointer to local variables */ 165 struct stack *stp; /* pointer to local stack frame */ 166 }; 167 168 struct stack { 169 char *tos; /* pointer to top of stack frame */ 170 struct iorec *file; /* pointer to active file name */ 171 struct hdr { 172 long framesze; /* number of bytes of local vars */ 173 long nargs; /* number of bytes of arguments */ 174 bool tests; /* TRUE => perform runtime tests */ 175 short offset; /* offset of procedure in source file */ 176 char name[1]; /* name of active procedure */ 177 } *entry; 178 struct disp odisp; /* previous display value for this level */ 179 struct disp *dp; /* pointer to active display entry */ 180 union progcntr pc; /* previous location counter */ 181 long lino; /* previous line number */ 182 }; 183 184 union disply { 185 struct disp frame[MAXLVL]; 186 char *raw[2*MAXLVL]; 187 }; 188 189 /* 190 * formal routine structure 191 */ 192 struct formalrtn { 193 char *entryaddr; 194 long cbn; 195 struct disp disp[2*MAXLVL]; 196 }; 197 198 /* 199 * program variables 200 */ 201 extern union disply _display; /* runtime display */ 202 extern struct disp *_dp; /* ptr to active frame */ 203 extern long _lino; /* current line number */ 204 extern int _argc; /* number of passed args */ 205 extern char **_argv; /* values of passed args */ 206 extern bool _nodump; /* TRUE => no post mortum dump */ 207 extern bool _runtst; /* TRUE => runtime tests */ 208 extern long _mode; /* execl by PX, PIPE, or PIX */ 209 extern long _stlim; /* statement limit */ 210 extern long _stcnt; /* statement count */ 211 extern long _seed; /* random number seed */ 212 extern char *_maxptr; /* maximum valid pointer */ 213 extern char *_minptr; /* minimum valid pointer */ 214 extern long *_pcpcount; /* pointer to pxp buffer */ 215 extern long _cntrs; /* number of counters */ 216 extern long _rtns; /* number of routine cntrs */ 217 218 /* 219 * The file i/o routines maintain a notion of a "current file". 220 * A pointer to this file structure is kept in "curfile". 221 * 222 * file structures 223 */ 224 struct iorechd { 225 char *fileptr; /* ptr to file window */ 226 long lcount; /* number of lines printed */ 227 long llimit; /* maximum number of text lines */ 228 FILE *fbuf; /* FILE ptr */ 229 struct iorec *fchain; /* chain to next file */ 230 struct iorec *flev; /* ptr to associated file variable */ 231 char *pfname; /* ptr to name of file */ 232 short funit; /* file status flags */ 233 short fblk; /* index into active file table */ 234 long fsize; /* size of elements in the file */ 235 char fname[NAMSIZ]; /* name of associated UNIX file */ 236 }; 237 238 struct iorec { 239 char *fileptr; /* ptr to file window */ 240 long lcount; /* number of lines printed */ 241 long llimit; /* maximum number of text lines */ 242 FILE *fbuf; /* FILE ptr */ 243 struct iorec *fchain; /* chain to next file */ 244 struct iorec *flev; /* ptr to associated file variable */ 245 char *pfname; /* ptr to name of file */ 246 short funit; /* file status flags */ 247 short fblk; /* index into active file table */ 248 long fsize; /* size of elements in the file */ 249 char fname[NAMSIZ]; /* name of associated UNIX file */ 250 char buf[BUFSIZ]; /* I/O buffer */ 251 char window[1]; /* file window element */ 252 }; 253 254 /* 255 * unit flags 256 */ 257 #define FDEF 0x80 /* 1 => reserved file name */ 258 #define FTEXT 0x40 /* 1 => text file, process EOLN */ 259 #define FWRITE 0x20 /* 1 => open for writing */ 260 #define FREAD 0x10 /* 1 => open for reading */ 261 #define TEMP 0x08 /* 1 => temporary file */ 262 #define SYNC 0x04 /* 1 => window is out of sync */ 263 #define EOLN 0x02 /* 1 => at end of line */ 264 #define EOFF 0x01 /* 1 => at end of file */ 265 266 /* 267 * file routines 268 */ 269 extern struct iorec *GETNAME(); 270 extern char *MKTEMP(); 271 272 /* 273 * file record variables 274 */ 275 extern struct iorechd _fchain; /* head of active file chain */ 276 extern struct iorec *_actfile[]; /* table of active files */ 277 extern long _filefre; /* last used entry in _actfile */ 278 279 /* 280 * standard files 281 */ 282 extern struct iorechd input; 283 extern struct iorechd output; 284 extern struct iorechd _err; 285 286 /* 287 * Px execution profile array 288 */ 289 #ifdef PROFILE 290 #define NUMOPS 256 291 extern long _profcnts[NUMOPS]; 292 #endif PROFILE 293