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