12084Smckusick /* Copyright (c) 1979 Regents of the University of California */ 22084Smckusick 3*3435Smckusic /* static char sccsid[] = "@(#)vars.h 1.7 04/01/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 MAXLVL 20 442084Smckusick #define NAMSIZ 76 452084Smckusick #define MAXFILES 32 462084Smckusick #define PREDEF 2 472953Smckusic #ifdef VAX 482084Smckusick #define STDLVL ((struct iorec *)(0x7ffffff1)) 492084Smckusick #define GLVL ((struct iorec *)(0x7ffffff0)) 502953Smckusic #else 512953Smckusic #define STDLVL ((struct iorec *)(0xfff1)) 522953Smckusic #define GLVL ((struct iorec *)(0xfff0)) 532953Smckusic #endif VAX 542084Smckusick #define FILNIL ((struct iorec *)(0)) 552084Smckusick #define INPUT ((struct iorec *)(&input)) 562084Smckusick #define OUTPUT ((struct iorec *)(&output)) 572084Smckusick #define ERR ((struct iorec *)(&_err)) 582084Smckusick #define PX 0 /* normal run of px */ 592084Smckusick #define PIX 1 /* load and go */ 602084Smckusick #define PIPE 2 /* bootstrap via a pipe */ 612084Smckusick #define releq 0 622110Smckusic #define relne 2 632110Smckusic #define rellt 4 642110Smckusic #define relgt 6 652110Smckusic #define relle 8 662110Smckusic #define relge 10 672953Smckusic typedef enum {FALSE, TRUE} bool; 682084Smckusick 692084Smckusick /* 702084Smckusick * interrupt and allocation routines 712084Smckusick */ 722084Smckusick extern long createtime; 732084Smckusick extern char *PALLOC(); 742084Smckusick extern char *malloc(); 752953Smckusic extern long time(); 762084Smckusick extern intr(); 772084Smckusick extern memsize(); 782084Smckusick extern except(); 792084Smckusick extern syserr(); 802084Smckusick extern liberr(); 812084Smckusick 822084Smckusick /* 832234Smckusic * stack routines and structures 842084Smckusick */ 852234Smckusic struct sze8 { 862234Smckusic char element[8]; 872234Smckusic }; 882084Smckusick extern short pop2(); 892084Smckusick extern long pop4(); 902084Smckusick extern double pop8(); 912234Smckusic extern struct sze8 popsze8(); 922084Smckusick extern char *pushsp(); 932084Smckusick 942084Smckusick /* 952084Smckusick * emulated pc types 962084Smckusick */ 972084Smckusick union progcntr { 982084Smckusick char *cp; 992084Smckusick unsigned char *ucp; 1002084Smckusick short *sp; 1012084Smckusick unsigned short *usp; 1022084Smckusick long *lp; 1032953Smckusic double *dbp; 1042084Smckusick struct hdr *hdrp; 1052084Smckusick }; 1062084Smckusick 1072084Smckusick /* 1082084Smckusick * THE RUNTIME DISPLAY 1092084Smckusick * 1102084Smckusick * The entries in the display point to the active static block marks. 1112084Smckusick * The first entry in the display is for the global variables, 1122084Smckusick * then the procedure or function at level one, etc. 1132084Smckusick * Each display entry points to a stack frame as shown: 1142084Smckusick * 1152084Smckusick * base of stack frame 1162084Smckusick * --------------- 1172084Smckusick * | | 1182084Smckusick * | block mark | 1192084Smckusick * | | 1202110Smckusic * --------------- <-- display entry "stp" points here 1212110Smckusic * | | <-- display entry "locvars" points here 1222084Smckusick * | local | 1232084Smckusick * | variables | 1242084Smckusick * | | 1252084Smckusick * --------------- 1262084Smckusick * | | 1272084Smckusick * | expression | 1282084Smckusick * | temporary | 1292084Smckusick * | storage | 1302084Smckusick * | | 1312084Smckusick * - - - - - - - - 1322084Smckusick * 1332084Smckusick * The information in the block mark is thus at positive offsets from 1342110Smckusic * the display.stp pointer entries while the local variables are at negative 1352110Smckusic * offsets from display.locvars. The block mark actually consists of 1362110Smckusic * two parts. The first part is created at CALL and the second at entry, 1372110Smckusic * i.e. BEGIN. Thus: 1382084Smckusick * 1392084Smckusick * ------------------------- 1402084Smckusick * | | 1412084Smckusick * | Saved lino | 1422084Smckusick * | Saved lc | 1432084Smckusick * | Saved dp | 1442084Smckusick * | | 1452084Smckusick * ------------------------- 1462084Smckusick * | | 1472084Smckusick * | Saved (dp) | 1482084Smckusick * | | 1492110Smckusic * | Pointer to current | 1502110Smckusic * | routine header info | 1512084Smckusick * | | 1522110Smckusic * | Saved value of | 1532110Smckusic * | "curfile" | 1542084Smckusick * | | 1552084Smckusick * | Empty tos value | 1562084Smckusick * | | 1572084Smckusick * ------------------------- 1582084Smckusick */ 1592084Smckusick 1602084Smckusick /* 1612084Smckusick * runtime display structure 1622084Smckusick */ 1632084Smckusick struct disp { 1642084Smckusick char *locvars; /* pointer to local variables */ 1652084Smckusick struct stack *stp; /* pointer to local stack frame */ 1662084Smckusick }; 1672084Smckusick 1682084Smckusick struct stack { 1692084Smckusick char *tos; /* pointer to top of stack frame */ 1702084Smckusick struct iorec *file; /* pointer to active file name */ 1712084Smckusick struct hdr { 1722084Smckusick long framesze; /* number of bytes of local vars */ 1732084Smckusick long nargs; /* number of bytes of arguments */ 1742953Smckusic bool tests; /* TRUE => perform runtime tests */ 1752084Smckusick short offset; /* offset of procedure in source file */ 1762084Smckusick char name[1]; /* name of active procedure */ 1772084Smckusick } *entry; 1782084Smckusick struct disp odisp; /* previous display value for this level */ 1792084Smckusick struct disp *dp; /* pointer to active display entry */ 1802084Smckusick union progcntr pc; /* previous location counter */ 1812084Smckusick long lino; /* previous line number */ 1822084Smckusick }; 1832084Smckusick 1842110Smckusic union disply { 1852110Smckusic struct disp frame[MAXLVL]; 1862110Smckusic char *raw[2*MAXLVL]; 1872110Smckusic }; 1882110Smckusic 1892084Smckusick /* 1902084Smckusick * formal routine structure 1912084Smckusick */ 1922084Smckusick struct formalrtn { 193*3435Smckusic char *fentryaddr; /* formal entry point */ 194*3435Smckusic long fbn; /* block number of function */ 195*3435Smckusic struct disp fdisp[ MAXLVL ]; /* saved at first passing */ 1962084Smckusick }; 1972084Smckusick 1982084Smckusick /* 1992084Smckusick * program variables 2002084Smckusick */ 2012110Smckusic extern union disply _display; /* runtime display */ 2022110Smckusic extern struct disp *_dp; /* ptr to active frame */ 2032110Smckusic extern long _lino; /* current line number */ 2042110Smckusic extern int _argc; /* number of passed args */ 2052110Smckusic extern char **_argv; /* values of passed args */ 2062953Smckusic extern bool _nodump; /* TRUE => no post mortum dump */ 2072953Smckusic extern bool _runtst; /* TRUE => runtime tests */ 2082110Smckusic extern long _mode; /* execl by PX, PIPE, or PIX */ 2092110Smckusic extern long _stlim; /* statement limit */ 2102110Smckusic extern long _stcnt; /* statement count */ 2112176Smckusic extern long _seed; /* random number seed */ 2122110Smckusic extern char *_maxptr; /* maximum valid pointer */ 2132110Smckusic extern char *_minptr; /* minimum valid pointer */ 2142110Smckusic extern long *_pcpcount; /* pointer to pxp buffer */ 2152110Smckusic extern long _cntrs; /* number of counters */ 2162110Smckusic extern long _rtns; /* number of routine cntrs */ 2172110Smckusic 2182084Smckusick /* 2192084Smckusick * The file i/o routines maintain a notion of a "current file". 2202084Smckusick * A pointer to this file structure is kept in "curfile". 2212084Smckusick * 2222084Smckusick * file structures 2232084Smckusick */ 2242084Smckusick struct iorechd { 2252084Smckusick char *fileptr; /* ptr to file window */ 2262084Smckusick long lcount; /* number of lines printed */ 2272084Smckusick long llimit; /* maximum number of text lines */ 2282084Smckusick FILE *fbuf; /* FILE ptr */ 2292084Smckusick struct iorec *fchain; /* chain to next file */ 2302084Smckusick struct iorec *flev; /* ptr to associated file variable */ 2312084Smckusick char *pfname; /* ptr to name of file */ 2322084Smckusick short funit; /* file status flags */ 2332084Smckusick short fblk; /* index into active file table */ 2342084Smckusick long fsize; /* size of elements in the file */ 2352084Smckusick char fname[NAMSIZ]; /* name of associated UNIX file */ 2362084Smckusick }; 2372084Smckusick 2382084Smckusick struct iorec { 2392084Smckusick char *fileptr; /* ptr to file window */ 2402084Smckusick long lcount; /* number of lines printed */ 2412084Smckusick long llimit; /* maximum number of text lines */ 2422084Smckusick FILE *fbuf; /* FILE ptr */ 2432084Smckusick struct iorec *fchain; /* chain to next file */ 2442084Smckusick struct iorec *flev; /* ptr to associated file variable */ 2452084Smckusick char *pfname; /* ptr to name of file */ 2462084Smckusick short funit; /* file status flags */ 2472084Smckusick short fblk; /* index into active file table */ 2482084Smckusick long fsize; /* size of elements in the file */ 2492084Smckusick char fname[NAMSIZ]; /* name of associated UNIX file */ 2502084Smckusick char buf[BUFSIZ]; /* I/O buffer */ 2512084Smckusick char window[1]; /* file window element */ 2522084Smckusick }; 2532110Smckusic 2542084Smckusick /* 2552084Smckusick * unit flags 2562084Smckusick */ 2572084Smckusick #define FDEF 0x80 /* 1 => reserved file name */ 2582084Smckusick #define FTEXT 0x40 /* 1 => text file, process EOLN */ 2592084Smckusick #define FWRITE 0x20 /* 1 => open for writing */ 2602084Smckusick #define FREAD 0x10 /* 1 => open for reading */ 2612084Smckusick #define TEMP 0x08 /* 1 => temporary file */ 2622084Smckusick #define SYNC 0x04 /* 1 => window is out of sync */ 2632084Smckusick #define EOLN 0x02 /* 1 => at end of line */ 2642084Smckusick #define EOFF 0x01 /* 1 => at end of file */ 2652084Smckusick 2662084Smckusick /* 2672084Smckusick * file routines 2682084Smckusick */ 2692084Smckusick extern struct iorec *GETNAME(); 2702084Smckusick extern char *MKTEMP(); 2712084Smckusick 2722084Smckusick /* 2732084Smckusick * file record variables 2742084Smckusick */ 2752084Smckusick extern struct iorechd _fchain; /* head of active file chain */ 2762084Smckusick extern struct iorec *_actfile[]; /* table of active files */ 2772084Smckusick extern long _filefre; /* last used entry in _actfile */ 2782084Smckusick 2792084Smckusick /* 2802084Smckusick * standard files 2812084Smckusick */ 2822084Smckusick extern struct iorechd input; 2832084Smckusick extern struct iorechd output; 2842084Smckusick extern struct iorechd _err; 2852110Smckusic 2862084Smckusick /* 2872110Smckusic * Px execution profile array 2882084Smckusick */ 2892110Smckusic #ifdef PROFILE 2902110Smckusic #define NUMOPS 256 2912110Smckusic extern long _profcnts[NUMOPS]; 2922110Smckusic #endif PROFILE 293