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