12084Smckusick /* Copyright (c) 1979 Regents of the University of California */ 22084Smckusick 3*2110Smckusic /* static char sccsid[] = "@(#)vars.h 1.2 01/10/81"; */ 42084Smckusick 52084Smckusick #include <stdio.h> 62084Smckusick 72084Smckusick /* 82084Smckusick * px - Berkeley Pascal interpreter 92084Smckusick * 102084Smckusick * Version 4.0, January 1981 112084Smckusick * 122084Smckusick * Original version by Ken Thompson 132084Smckusick * 142084Smckusick * Substantial revisions by Bill Joy and Chuck Haley 152084Smckusick * November-December 1976 162084Smckusick * 172084Smckusick * Rewritten for VAX 11/780 by Kirk McKusick 182084Smckusick * Fall 1978 192084Smckusick * 202084Smckusick * Rewritten in ``C'' using libpc by Kirk McKusick 212084Smckusick * Winter 1981 222084Smckusick * 232084Smckusick * Px is described in detail in the "PX 4.0 Implementation Notes" 242084Smckusick * The source code for px is in several major pieces: 252084Smckusick * 262084Smckusick * int.c C main program which reads in interpreter code 272084Smckusick * interp.c Driver including main interpreter loop and 282084Smckusick * the interpreter instructions grouped by their 292084Smckusick * positions in the interpreter table. 302084Smckusick * except.c Handlers for interpreter specific errors not 312084Smckusick * included in libpc. 322084Smckusick * utilities.c Interpreter exit, backtrace, and runtime statistics. 332084Smckusick * 342084Smckusick * In addition there are several headers defining mappings for panic 352084Smckusick * names into codes, and a definition of the interpreter transfer 362084Smckusick * table. These are made by the script make.ed1 in this directory and 372084Smckusick * the routine opc.c from ${PASCALDIR}. (see the makefile for details) 382084Smckusick */ 392084Smckusick #define PXPFILE "pmon.out" 402084Smckusick #define BITSPERBYTE 8 412084Smckusick #define BITSPERLONG (BITSPERBYTE * sizeof(long)) 422084Smckusick #define HZ 60 432084Smckusick #define TRUE 1 442084Smckusick #define FALSE 0 452084Smckusick #define MAXLVL 20 462084Smckusick #define NAMSIZ 76 472084Smckusick #define MAXFILES 32 482084Smckusick #define PREDEF 2 492084Smckusick #define STDLVL ((struct iorec *)(0x7ffffff1)) 502084Smckusick #define GLVL ((struct iorec *)(0x7ffffff0)) 512084Smckusick #define FILNIL ((struct iorec *)(0)) 522084Smckusick #define INPUT ((struct iorec *)(&input)) 532084Smckusick #define OUTPUT ((struct iorec *)(&output)) 542084Smckusick #define ERR ((struct iorec *)(&_err)) 552084Smckusick #define PX 0 /* normal run of px */ 562084Smckusick #define PIX 1 /* load and go */ 572084Smckusick #define PIPE 2 /* bootstrap via a pipe */ 582084Smckusick #define releq 0 59*2110Smckusic #define relne 2 60*2110Smckusic #define rellt 4 61*2110Smckusic #define relgt 6 62*2110Smckusic #define relle 8 63*2110Smckusic #define relge 10 642084Smckusick 652084Smckusick /* 662084Smckusick * interrupt and allocation routines 672084Smckusick */ 682084Smckusick extern long createtime; 692084Smckusick extern char *PALLOC(); 702084Smckusick extern char *malloc(); 712084Smckusick extern intr(); 722084Smckusick extern memsize(); 732084Smckusick extern except(); 742084Smckusick extern syserr(); 752084Smckusick extern liberr(); 762084Smckusick 772084Smckusick /* 782084Smckusick * stack routines 792084Smckusick */ 802084Smckusick extern short pop2(); 812084Smckusick extern long pop4(); 822084Smckusick extern double pop8(); 832084Smckusick extern char *pushsp(); 842084Smckusick 852084Smckusick /* 862084Smckusick * emulated pc types 872084Smckusick */ 882084Smckusick union progcntr { 892084Smckusick char *cp; 902084Smckusick unsigned char *ucp; 912084Smckusick short *sp; 922084Smckusick unsigned short *usp; 932084Smckusick long *lp; 942084Smckusick double *dp; 952084Smckusick struct hdr *hdrp; 962084Smckusick }; 972084Smckusick 982084Smckusick /* 992084Smckusick * THE RUNTIME DISPLAY 1002084Smckusick * 1012084Smckusick * The entries in the display point to the active static block marks. 1022084Smckusick * The first entry in the display is for the global variables, 1032084Smckusick * then the procedure or function at level one, etc. 1042084Smckusick * Each display entry points to a stack frame as shown: 1052084Smckusick * 1062084Smckusick * base of stack frame 1072084Smckusick * --------------- 1082084Smckusick * | | 1092084Smckusick * | block mark | 1102084Smckusick * | | 111*2110Smckusic * --------------- <-- display entry "stp" points here 112*2110Smckusic * | | <-- display entry "locvars" points here 1132084Smckusick * | local | 1142084Smckusick * | variables | 1152084Smckusick * | | 1162084Smckusick * --------------- 1172084Smckusick * | | 1182084Smckusick * | expression | 1192084Smckusick * | temporary | 1202084Smckusick * | storage | 1212084Smckusick * | | 1222084Smckusick * - - - - - - - - 1232084Smckusick * 1242084Smckusick * The information in the block mark is thus at positive offsets from 125*2110Smckusic * the display.stp pointer entries while the local variables are at negative 126*2110Smckusic * offsets from display.locvars. The block mark actually consists of 127*2110Smckusic * two parts. The first part is created at CALL and the second at entry, 128*2110Smckusic * i.e. BEGIN. Thus: 1292084Smckusick * 1302084Smckusick * ------------------------- 1312084Smckusick * | | 1322084Smckusick * | Saved lino | 1332084Smckusick * | Saved lc | 1342084Smckusick * | Saved dp | 1352084Smckusick * | | 1362084Smckusick * ------------------------- 1372084Smckusick * | | 1382084Smckusick * | Saved (dp) | 1392084Smckusick * | | 140*2110Smckusic * | Pointer to current | 141*2110Smckusic * | routine header info | 1422084Smckusick * | | 143*2110Smckusic * | Saved value of | 144*2110Smckusic * | "curfile" | 1452084Smckusick * | | 1462084Smckusick * | Empty tos value | 1472084Smckusick * | | 1482084Smckusick * ------------------------- 1492084Smckusick */ 1502084Smckusick 1512084Smckusick /* 1522084Smckusick * runtime display structure 1532084Smckusick */ 1542084Smckusick struct disp { 1552084Smckusick char *locvars; /* pointer to local variables */ 1562084Smckusick struct stack *stp; /* pointer to local stack frame */ 1572084Smckusick }; 1582084Smckusick 1592084Smckusick struct stack { 1602084Smckusick char *tos; /* pointer to top of stack frame */ 1612084Smckusick struct iorec *file; /* pointer to active file name */ 1622084Smckusick struct hdr { 1632084Smckusick long framesze; /* number of bytes of local vars */ 1642084Smckusick long nargs; /* number of bytes of arguments */ 1652084Smckusick short offset; /* offset of procedure in source file */ 1662084Smckusick char name[1]; /* name of active procedure */ 1672084Smckusick } *entry; 1682084Smckusick struct disp odisp; /* previous display value for this level */ 1692084Smckusick struct disp *dp; /* pointer to active display entry */ 1702084Smckusick union progcntr pc; /* previous location counter */ 1712084Smckusick long lino; /* previous line number */ 1722084Smckusick }; 1732084Smckusick 174*2110Smckusic union disply { 175*2110Smckusic struct disp frame[MAXLVL]; 176*2110Smckusic char *raw[2*MAXLVL]; 177*2110Smckusic }; 178*2110Smckusic 1792084Smckusick /* 1802084Smckusick * formal routine structure 1812084Smckusick */ 1822084Smckusick struct formalrtn { 1832084Smckusick char *entryaddr; 1842084Smckusick long cbn; 1852084Smckusick struct disp disp[2*MAXLVL]; 1862084Smckusick }; 1872084Smckusick 1882084Smckusick /* 1892084Smckusick * program variables 1902084Smckusick */ 191*2110Smckusic extern union disply _display; /* runtime display */ 192*2110Smckusic extern struct disp *_dp; /* ptr to active frame */ 193*2110Smckusic extern long _lino; /* current line number */ 194*2110Smckusic extern int _argc; /* number of passed args */ 195*2110Smckusic extern char **_argv; /* values of passed args */ 196*2110Smckusic extern long _nodump; /* 1 => no post mortum dump */ 197*2110Smckusic extern long _mode; /* execl by PX, PIPE, or PIX */ 198*2110Smckusic extern long _stlim; /* statement limit */ 199*2110Smckusic extern long _stcnt; /* statement count */ 200*2110Smckusic extern char *_maxptr; /* maximum valid pointer */ 201*2110Smckusic extern char *_minptr; /* minimum valid pointer */ 202*2110Smckusic extern long *_pcpcount; /* pointer to pxp buffer */ 203*2110Smckusic extern long _cntrs; /* number of counters */ 204*2110Smckusic extern long _rtns; /* number of routine cntrs */ 205*2110Smckusic 2062084Smckusick /* 2072084Smckusick * The file i/o routines maintain a notion of a "current file". 2082084Smckusick * A pointer to this file structure is kept in "curfile". 2092084Smckusick * 2102084Smckusick * file structures 2112084Smckusick */ 2122084Smckusick struct iorechd { 2132084Smckusick char *fileptr; /* ptr to file window */ 2142084Smckusick long lcount; /* number of lines printed */ 2152084Smckusick long llimit; /* maximum number of text lines */ 2162084Smckusick FILE *fbuf; /* FILE ptr */ 2172084Smckusick struct iorec *fchain; /* chain to next file */ 2182084Smckusick struct iorec *flev; /* ptr to associated file variable */ 2192084Smckusick char *pfname; /* ptr to name of file */ 2202084Smckusick short funit; /* file status flags */ 2212084Smckusick short fblk; /* index into active file table */ 2222084Smckusick long fsize; /* size of elements in the file */ 2232084Smckusick char fname[NAMSIZ]; /* name of associated UNIX file */ 2242084Smckusick }; 2252084Smckusick 2262084Smckusick struct iorec { 2272084Smckusick char *fileptr; /* ptr to file window */ 2282084Smckusick long lcount; /* number of lines printed */ 2292084Smckusick long llimit; /* maximum number of text lines */ 2302084Smckusick FILE *fbuf; /* FILE ptr */ 2312084Smckusick struct iorec *fchain; /* chain to next file */ 2322084Smckusick struct iorec *flev; /* ptr to associated file variable */ 2332084Smckusick char *pfname; /* ptr to name of file */ 2342084Smckusick short funit; /* file status flags */ 2352084Smckusick short fblk; /* index into active file table */ 2362084Smckusick long fsize; /* size of elements in the file */ 2372084Smckusick char fname[NAMSIZ]; /* name of associated UNIX file */ 2382084Smckusick char buf[BUFSIZ]; /* I/O buffer */ 2392084Smckusick char window[1]; /* file window element */ 2402084Smckusick }; 241*2110Smckusic 2422084Smckusick /* 2432084Smckusick * unit flags 2442084Smckusick */ 2452084Smckusick #define FDEF 0x80 /* 1 => reserved file name */ 2462084Smckusick #define FTEXT 0x40 /* 1 => text file, process EOLN */ 2472084Smckusick #define FWRITE 0x20 /* 1 => open for writing */ 2482084Smckusick #define FREAD 0x10 /* 1 => open for reading */ 2492084Smckusick #define TEMP 0x08 /* 1 => temporary file */ 2502084Smckusick #define SYNC 0x04 /* 1 => window is out of sync */ 2512084Smckusick #define EOLN 0x02 /* 1 => at end of line */ 2522084Smckusick #define EOFF 0x01 /* 1 => at end of file */ 2532084Smckusick 2542084Smckusick /* 2552084Smckusick * file routines 2562084Smckusick */ 2572084Smckusick extern struct iorec *GETNAME(); 2582084Smckusick extern char *MKTEMP(); 2592084Smckusick 2602084Smckusick /* 2612084Smckusick * file record variables 2622084Smckusick */ 2632084Smckusick extern struct iorechd _fchain; /* head of active file chain */ 2642084Smckusick extern struct iorec *_actfile[]; /* table of active files */ 2652084Smckusick extern long _filefre; /* last used entry in _actfile */ 2662084Smckusick 2672084Smckusick /* 2682084Smckusick * standard files 2692084Smckusick */ 2702084Smckusick extern struct iorechd input; 2712084Smckusick extern struct iorechd output; 2722084Smckusick extern struct iorechd _err; 273*2110Smckusic 2742084Smckusick /* 275*2110Smckusic * Px execution profile array 2762084Smckusick */ 277*2110Smckusic #ifdef PROFILE 278*2110Smckusic #define NUMOPS 256 279*2110Smckusic extern long _profcnts[NUMOPS]; 280*2110Smckusic #endif PROFILE 281