122159Sdist /* 222159Sdist * Copyright (c) 1980 Regents of the University of California. 322159Sdist * All rights reserved. The Berkeley software License Agreement 422159Sdist * specifies the terms and conditions for redistribution. 522159Sdist * 6*36537Smckusick * @(#)vars.h 5.3 (Berkeley) 01/09/89 722159Sdist */ 82084Smckusick 92084Smckusick #include <stdio.h> 102084Smckusick 112084Smckusick /* 122084Smckusick * px - Berkeley Pascal interpreter 132084Smckusick * 142084Smckusick * Version 4.0, January 1981 152084Smckusick * 162084Smckusick * Original version by Ken Thompson 172084Smckusick * 182084Smckusick * Substantial revisions by Bill Joy and Chuck Haley 192084Smckusick * November-December 1976 202084Smckusick * 212084Smckusick * Rewritten for VAX 11/780 by Kirk McKusick 222084Smckusick * Fall 1978 232084Smckusick * 242084Smckusick * Rewritten in ``C'' using libpc by Kirk McKusick 252084Smckusick * Winter 1981 262084Smckusick * 272084Smckusick * Px is described in detail in the "PX 4.0 Implementation Notes" 282084Smckusick * The source code for px is in several major pieces: 292084Smckusick * 302084Smckusick * int.c C main program which reads in interpreter code 312084Smckusick * interp.c Driver including main interpreter loop and 322084Smckusick * the interpreter instructions grouped by their 332084Smckusick * positions in the interpreter table. 342084Smckusick * utilities.c Interpreter exit, backtrace, and runtime statistics. 352084Smckusick * 362084Smckusick * In addition there are several headers defining mappings for panic 372084Smckusick * names into codes, and a definition of the interpreter transfer 382084Smckusick * table. These are made by the script make.ed1 in this directory and 392084Smckusick * the routine opc.c from ${PASCALDIR}. (see the makefile for details) 402084Smckusick */ 412084Smckusick #define PXPFILE "pmon.out" 422084Smckusick #define BITSPERBYTE 8 432084Smckusick #define BITSPERLONG (BITSPERBYTE * sizeof(long)) 4410237Smckusick #define HZ 100 452084Smckusick #define NAMSIZ 76 462084Smckusick #define MAXFILES 32 472084Smckusick #define PREDEF 2 4810236Smckusick #ifdef ADDR32 4929987Smckusick #ifndef tahoe 502084Smckusick #define STDLVL ((struct iorec *)(0x7ffffff1)) 512084Smckusick #define GLVL ((struct iorec *)(0x7ffffff0)) 5229987Smckusick #else tahoe 5329987Smckusick #define STDLVL ((struct iorec *)(0xbffffff1)) 5429987Smckusick #define GLVL ((struct iorec *)(0xbffffff0)) 5529987Smckusick #endif tahoe 5610236Smckusick #endif ADDR32 5710236Smckusick #ifdef ADDR16 582953Smckusic #define STDLVL ((struct iorec *)(0xfff1)) 592953Smckusic #define GLVL ((struct iorec *)(0xfff0)) 6010236Smckusick #endif ADDR16 612084Smckusick #define FILNIL ((struct iorec *)(0)) 622084Smckusick #define INPUT ((struct iorec *)(&input)) 632084Smckusick #define OUTPUT ((struct iorec *)(&output)) 642084Smckusick #define ERR ((struct iorec *)(&_err)) 652084Smckusick #define PX 0 /* normal run of px */ 662084Smckusick #define PIX 1 /* load and go */ 672084Smckusick #define PIPE 2 /* bootstrap via a pipe */ 685660Slinton #define PDX 3 /* invoked by the debugger "pdx" */ 692084Smckusick #define releq 0 702110Smckusic #define relne 2 712110Smckusic #define rellt 4 722110Smckusic #define relgt 6 732110Smckusic #define relle 8 742110Smckusic #define relge 10 752953Smckusic typedef enum {FALSE, TRUE} bool; 762084Smckusick 772084Smckusick /* 782084Smckusick * interrupt and allocation routines 792084Smckusick */ 802084Smckusick extern long createtime; 812084Smckusick extern char *PALLOC(); 822084Smckusick extern char *malloc(); 832953Smckusic extern long time(); 842084Smckusick extern intr(); 852084Smckusick extern memsize(); 862084Smckusick extern syserr(); 872084Smckusick extern liberr(); 882084Smckusick 892084Smckusick /* 902234Smckusic * stack routines and structures 912084Smckusick */ 922234Smckusic struct sze8 { 932234Smckusic char element[8]; 942234Smckusic }; 952084Smckusick 962084Smckusick /* 972084Smckusick * emulated pc types 982084Smckusick */ 992084Smckusick union progcntr { 1002084Smckusick char *cp; 1012084Smckusick unsigned char *ucp; 1022084Smckusick short *sp; 1032084Smckusick unsigned short *usp; 1042084Smckusick long *lp; 1052953Smckusic double *dbp; 1062084Smckusick struct hdr *hdrp; 107*36537Smckusick struct sze8 *s8p; 1082084Smckusick }; 1092084Smckusick 1102084Smckusick /* 1112084Smckusick * THE RUNTIME DISPLAY 1122084Smckusick * 1132084Smckusick * The entries in the display point to the active static block marks. 1142084Smckusick * The first entry in the display is for the global variables, 1152084Smckusick * then the procedure or function at level one, etc. 1162084Smckusick * Each display entry points to a stack frame as shown: 1172084Smckusick * 1182084Smckusick * base of stack frame 1192084Smckusick * --------------- 1202084Smckusick * | | 1212084Smckusick * | block mark | 1222084Smckusick * | | 1232110Smckusic * --------------- <-- display entry "stp" points here 1242110Smckusic * | | <-- display entry "locvars" points here 1252084Smckusick * | local | 1262084Smckusick * | variables | 1272084Smckusick * | | 1282084Smckusick * --------------- 1292084Smckusick * | | 1302084Smckusick * | expression | 1312084Smckusick * | temporary | 1322084Smckusick * | storage | 1332084Smckusick * | | 1342084Smckusick * - - - - - - - - 1352084Smckusick * 1362084Smckusick * The information in the block mark is thus at positive offsets from 1372110Smckusic * the display.stp pointer entries while the local variables are at negative 1382110Smckusic * offsets from display.locvars. The block mark actually consists of 1392110Smckusic * two parts. The first part is created at CALL and the second at entry, 1402110Smckusic * i.e. BEGIN. Thus: 1412084Smckusick * 1422084Smckusick * ------------------------- 1432084Smckusick * | | 1442084Smckusick * | Saved lino | 1452084Smckusick * | Saved lc | 1462084Smckusick * | Saved dp | 1472084Smckusick * | | 1482084Smckusick * ------------------------- 1492084Smckusick * | | 1502084Smckusick * | Saved (dp) | 1512084Smckusick * | | 1522110Smckusic * | Pointer to current | 1532110Smckusic * | routine header info | 1542084Smckusick * | | 1552110Smckusic * | Saved value of | 1562110Smckusic * | "curfile" | 1572084Smckusick * | | 1582084Smckusick * | Empty tos value | 1592084Smckusick * | | 1602084Smckusick * ------------------------- 1612084Smckusick */ 1622084Smckusick 1632084Smckusick /* 1642084Smckusick * program variables 1652084Smckusick */ 16610574Smckusick extern union display _display; /* runtime display */ 16710574Smckusick extern struct dispsave *_dp; /* ptr to active frame */ 1682110Smckusic extern long _lino; /* current line number */ 1692110Smckusic extern int _argc; /* number of passed args */ 1702110Smckusic extern char **_argv; /* values of passed args */ 1712953Smckusic extern bool _nodump; /* TRUE => no post mortum dump */ 17210574Smckusick extern long _runtst; /* TRUE => runtime tests */ 1732110Smckusic extern long _mode; /* execl by PX, PIPE, or PIX */ 1742110Smckusic extern long _stlim; /* statement limit */ 1752110Smckusic extern long _stcnt; /* statement count */ 1762176Smckusic extern long _seed; /* random number seed */ 1772110Smckusic extern char *_maxptr; /* maximum valid pointer */ 1782110Smckusic extern char *_minptr; /* minimum valid pointer */ 1792110Smckusic extern long *_pcpcount; /* pointer to pxp buffer */ 1802110Smckusic extern long _cntrs; /* number of counters */ 1812110Smckusic extern long _rtns; /* number of routine cntrs */ 1822110Smckusic 1832084Smckusick /* 1842084Smckusick * The file i/o routines maintain a notion of a "current file". 1852084Smckusick * A pointer to this file structure is kept in "curfile". 1862084Smckusick * 1872084Smckusick * file structures 1882084Smckusick */ 1892084Smckusick struct iorechd { 1902084Smckusick char *fileptr; /* ptr to file window */ 1912084Smckusick long lcount; /* number of lines printed */ 1922084Smckusick long llimit; /* maximum number of text lines */ 1932084Smckusick FILE *fbuf; /* FILE ptr */ 1942084Smckusick struct iorec *fchain; /* chain to next file */ 1952084Smckusick struct iorec *flev; /* ptr to associated file variable */ 1962084Smckusick char *pfname; /* ptr to name of file */ 1972084Smckusick short funit; /* file status flags */ 1982084Smckusick short fblk; /* index into active file table */ 1992084Smckusick long fsize; /* size of elements in the file */ 2002084Smckusick char fname[NAMSIZ]; /* name of associated UNIX file */ 2012084Smckusick }; 2022084Smckusick 2032084Smckusick struct iorec { 2042084Smckusick char *fileptr; /* ptr to file window */ 2052084Smckusick long lcount; /* number of lines printed */ 2062084Smckusick long llimit; /* maximum number of text lines */ 2072084Smckusick FILE *fbuf; /* FILE ptr */ 2082084Smckusick struct iorec *fchain; /* chain to next file */ 2092084Smckusick struct iorec *flev; /* ptr to associated file variable */ 2102084Smckusick char *pfname; /* ptr to name of file */ 2112084Smckusick short funit; /* file status flags */ 2122084Smckusick short fblk; /* index into active file table */ 2132084Smckusick long fsize; /* size of elements in the file */ 2142084Smckusick char fname[NAMSIZ]; /* name of associated UNIX file */ 2152084Smckusick char buf[BUFSIZ]; /* I/O buffer */ 2162084Smckusick char window[1]; /* file window element */ 2172084Smckusick }; 2182110Smckusic 2192084Smckusick /* 2202084Smckusick * unit flags 2212084Smckusick */ 2222084Smckusick #define FDEF 0x80 /* 1 => reserved file name */ 2232084Smckusick #define FTEXT 0x40 /* 1 => text file, process EOLN */ 2242084Smckusick #define FWRITE 0x20 /* 1 => open for writing */ 2252084Smckusick #define FREAD 0x10 /* 1 => open for reading */ 2262084Smckusick #define TEMP 0x08 /* 1 => temporary file */ 2272084Smckusick #define SYNC 0x04 /* 1 => window is out of sync */ 2282084Smckusick #define EOLN 0x02 /* 1 => at end of line */ 2292084Smckusick #define EOFF 0x01 /* 1 => at end of file */ 2302084Smckusick 2312084Smckusick /* 2322084Smckusick * file routines 2332084Smckusick */ 2342084Smckusick extern struct iorec *GETNAME(); 2352084Smckusick extern char *MKTEMP(); 2362084Smckusick 2372084Smckusick /* 2382084Smckusick * file record variables 2392084Smckusick */ 2402084Smckusick extern struct iorechd _fchain; /* head of active file chain */ 2412084Smckusick extern struct iorec *_actfile[]; /* table of active files */ 2422084Smckusick extern long _filefre; /* last used entry in _actfile */ 2432084Smckusick 2442084Smckusick /* 2452084Smckusick * standard files 2462084Smckusick */ 2472084Smckusick extern struct iorechd input; 2482084Smckusick extern struct iorechd output; 2492084Smckusick extern struct iorechd _err; 2502110Smckusic 2512084Smckusick /* 2522110Smckusic * Px execution profile array 2532084Smckusick */ 2542110Smckusic #ifdef PROFILE 2552110Smckusic #define NUMOPS 256 2562110Smckusic extern long _profcnts[NUMOPS]; 2572110Smckusic #endif PROFILE 258