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