1*47822Sbostic /*- 2*47822Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*47822Sbostic * All rights reserved. 4*47822Sbostic * 5*47822Sbostic * %sccs.include.proprietary.c% 6*47822Sbostic * 7*47822Sbostic * @(#)defs.h 5.5 (Berkeley) 04/04/91 8*47822Sbostic */ 936559Sbostic 1036559Sbostic /* 1136559Sbostic * adb: common definitions 1236559Sbostic */ 1336559Sbostic 1436559Sbostic #include <sys/param.h> 1536559Sbostic #include <sys/user.h> 1636559Sbostic 1736559Sbostic #include <a.out.h> 1836559Sbostic 1936559Sbostic /* machine dependent types and definitions */ 2036559Sbostic #include "machdep.h" 2136559Sbostic 2236559Sbostic /* 2336559Sbostic * Signals. Adb catches SIGINT and SIGQUIT; the variables sigint and 2436559Sbostic * sigquit hold the original state for adb's children. 2536559Sbostic */ 2636559Sbostic sig_t sigint; /* original SIGINT state */ 2736559Sbostic sig_t sigquit; /* original SIGQUIT state */ 2836559Sbostic sig_t intcatch; /* interrupt catch routine, or SIG_IGN */ 2936559Sbostic 3036559Sbostic /* 3136559Sbostic * Address spaces. We distinguish only between instruction & data. 3236559Sbostic * The spaces NONE, INSTR, and DATA (without the STAR flag) are also used 3336559Sbostic * to tag symbols. 3436559Sbostic */ 3536559Sbostic #define SP_NONE 0 /* not in any space, just a number */ 3636559Sbostic #define SP_INSTR 1 /* instruction space */ 3736559Sbostic #define SP_DATA 2 /* data space */ 3836559Sbostic #define SP_STAR 4 /* or'ed in; see below */ 3936559Sbostic 4036559Sbostic /* 4136559Sbostic * The symbol and core files. 4236559Sbostic */ 4336559Sbostic struct { 4436559Sbostic char *name; /* file name */ 4536559Sbostic int fd; /* and descriptor */ 4636559Sbostic } symfile, corefile; 4736559Sbostic 4836559Sbostic /* 4936559Sbostic * File address maps. 5036559Sbostic */ 5136559Sbostic struct m1 { 5236559Sbostic addr_t b; /* begins at b */ 5336559Sbostic addr_t e; /* ends at e */ 5436559Sbostic addr_t f; /* with offset f */ 5536559Sbostic }; 5636559Sbostic struct map { 5736559Sbostic struct m1 m1; /* regular map */ 5836559Sbostic struct m1 m2; /* `star' (alternate) map */ 5936559Sbostic int ufd; /* unix file descriptor */ 6036559Sbostic }; 6136559Sbostic 6236559Sbostic struct map txtmap; /* the `?' or text file */ 6336559Sbostic struct map datmap; /* the `/' or data/core file */ 6436559Sbostic 6536559Sbostic /* 6636559Sbostic * Program and file I/O. 6736559Sbostic */ 6836559Sbostic enum rwmode { RWMODE_READ, RWMODE_WRITE }; 6936559Sbostic #define adbread(space, rmtaddr, localaddr, nbytes) \ 7036559Sbostic adbio(RWMODE_READ, space, rmtaddr, (caddr_t)(localaddr), nbytes) 7136559Sbostic #define adbwrite(space, rmtaddr, localaddr, nbytes) \ 7236559Sbostic adbio(RWMODE_WRITE, space, rmtaddr, (caddr_t)(localaddr), nbytes) 7336559Sbostic 7436559Sbostic addr_t vtophys(); /* -k: kernel virtual addr to physical */ 7536559Sbostic 7636559Sbostic /* 7736559Sbostic * Errors. errflag should be set to point to the error message when 7836559Sbostic * an error occurs. error(s) sets errflag to s and jumps back 7936559Sbostic * to the main loop via longjmp(). In some places this is unsafe 8036559Sbostic * or undesirable, and instead errflag is set directly; checkerr() 8136559Sbostic * can be used to test (and jump on) for such errors later. 8236559Sbostic * 8336559Sbostic * mkfault creates a `generic' error after a keyboard interrupt. 8436559Sbostic * 8536559Sbostic * Various error strings are defined in message.c and referenced 8636559Sbostic * through names below. 8736559Sbostic */ 8836559Sbostic char *errflag; /* the error, or NULL */ 8936559Sbostic int mkfault; /* interrupted; pretend an error */ 9036559Sbostic 9136559Sbostic #define iserr() (errflag || mkfault) 9236559Sbostic #define checkerr() \ 9336559Sbostic if (!iserr()) \ 9436559Sbostic /* void */; \ 9536559Sbostic else \ 9636559Sbostic error(errflag) 9736559Sbostic /* if checkerr() above is undefined, a function version is used instead */ 9836559Sbostic 9936559Sbostic /* 10036559Sbostic * Locations. 10136559Sbostic * 10236559Sbostic * HSZ and FSZ are defined here as the sizes of `half' and `full' words 10336559Sbostic * respectively. While these are not `locations', they are commonly used 10436559Sbostic * to set the value of dotinc. 10536559Sbostic */ 10636559Sbostic int gavedot; /* true iff this command set dot */ 10736559Sbostic addr_t dot; /* current location; but see also edot */ 10836559Sbostic addr_t ditto; /* previous dot */ 10936559Sbostic int dotinc; /* size of last object examined */ 11036559Sbostic 11136559Sbostic extern char ADDRWRAP[]; /* "address wrap around" */ 11236559Sbostic 11336559Sbostic /* compute dot+offset, checking for overflow */ 11436559Sbostic #define inkdot(o) (ADDRESS_WRAP(dot, dot+(o)) ? error(ADDRWRAP), 0 : dot+(o)) 11536559Sbostic /* if inkdot() above is undefined, a function version is used instead */ 11636559Sbostic 11736559Sbostic /* 11836559Sbostic * Expressions. 11936559Sbostic * 12036559Sbostic * oexpr() evaluates an optional expression; rexpr() does a required 12136559Sbostic * expression, and returns expv as a convenience. 12236559Sbostic * 12336559Sbostic * N.B.: edot is valid only if gavedot. 12436559Sbostic */ 12536559Sbostic int oexpr(); /* returns 1 if found expr, else 0 */ 12636559Sbostic expr_t rexpr(); /* aborts if no expression found */ 12736559Sbostic 12836559Sbostic expr_t edot; /* dot as an expression (possibly more bits) */ 12936559Sbostic int gavecount; /* true iff this command gave a count */ 13036559Sbostic expr_t ecount; /* repeat count from addr,count format */ 13136559Sbostic expr_t expv; /* value from last expression */ 13236559Sbostic expr_t var[36]; /* adb's 36 variables (0..9 then a..z) */ 13336559Sbostic 13436559Sbostic /* 13536559Sbostic * Input. 13636559Sbostic * 13736559Sbostic * The global lp points to the current input line. The routine 13836559Sbostic * readchar() picks up the next character, incrementing lp, but 13936559Sbostic * can read more if appropriate. lastc retains the most recently 14036559Sbostic * read character. unreadc() in effect `puts back' lastc. rdc() 14136559Sbostic * is like readchar() but skips white space. 14236559Sbostic */ 14336559Sbostic char *lp; /* pointer into current line */ 14436559Sbostic int lastc; /* character most recently read */ 14536559Sbostic int readchar(); /* get the next char */ 14636559Sbostic int rdc(); /* get the next nonblank char */ 14736559Sbostic #ifndef lint 14836559Sbostic #define unreadc() (lastc ? lp-- : 0) 14936559Sbostic #else 15036559Sbostic #define unreadc() (lp--) 15136559Sbostic #endif 15236559Sbostic #ifndef lint 15336559Sbostic #define readchar() (((lastc = *lp) == 0 ? 0 : lp++), lastc) 15436559Sbostic #endif 15536559Sbostic /* if readchar() above is undefined, a function version is used instead */ 15636559Sbostic #define eol(c) ((c) == '\n' || (c) == ';') 15736559Sbostic 15836559Sbostic /* 15936559Sbostic * Miscellaneous globals, functions, and macros. 16036559Sbostic */ 16136559Sbostic int kernel; /* debugging kernel (-k flag) */ 16236559Sbostic int kcore; /* have a post-mortem dump (-k + core) */ 16336559Sbostic int wtflag; /* adb => 0, adb -w => 2 */ 16436559Sbostic int radix; /* current radix (input and %r/%R formats) */ 16536559Sbostic int pid; /* process id being debugged, or 0 */ 16636559Sbostic int signo; /* signal that stopped process pid */ 16736559Sbostic int sigcode; /* extension info (machine dependent) */ 16836559Sbostic 16936559Sbostic addr_t maxoff; /* max offset for symbol match ($s) */ 17037342Sbostic #define MAXOFF 1024 /* default value */ 17136559Sbostic 17236559Sbostic int maxcol; /* max output column ($w) */ 17336559Sbostic #define MAXCOL 80 /* default value */ 17436559Sbostic 17536559Sbostic #define LINELEN 1024 /* max input line length */ 17636559Sbostic #define SYMLEN 1024 /* max symbol length */ 17736559Sbostic 17836559Sbostic int errno; /* our old friend */ 17936559Sbostic 18036559Sbostic /* 18136559Sbostic * checkfloat() returns an error string if a float or double is 18236559Sbostic * some sort of reserved bit pattern, such that trying to print it 18336559Sbostic * would cause a fault. It is called with the address of the 18436559Sbostic * float or double, and a 0 or 1 to indicate float and double 18536559Sbostic * respectively. checkfloat() returns NULL if the number is printable. 18636559Sbostic */ 18736559Sbostic char *checkfloat(); /* check a float or double for correctness */ 18836559Sbostic 18936559Sbostic struct reglist *reglookup(); /* find a register by name */ 19036559Sbostic 19136559Sbostic struct nlist *lookup(); /* look up a symbol */ 19236559Sbostic struct nlist *findsym(); /* like lookup, but allows an offset */ 19336559Sbostic struct nlist *nextlocal(); /* given a sym, return the next local sym */ 19436559Sbostic 19536559Sbostic struct nlist *symtab; /* symbol table */ 19636559Sbostic struct nlist *esymtab; /* end of symtab */ 19736559Sbostic 19836559Sbostic expr_t getreg(); /* returns the value in a register */ 19936559Sbostic 20036559Sbostic addr_t eval_localsym(); /* compute the address of a local symbol */ 20136559Sbostic 20236559Sbostic /* 20336559Sbostic * eqstr(a, b) is true iff the given strings compare equal. 20436559Sbostic * eqsym(a, b, c) is true if symbols a and b match, but allowing 20536559Sbostic * the `a' symbol to begin with the character `c'. 20636559Sbostic */ 20736559Sbostic #define eqstr(a, b) (*(a) == *(b) && strcmp(a, b) == 0) 20836559Sbostic #define eqsym(a, b, c) (eqstr(a, b) || *(a) == (c) && eqstr((a) + 1, b)) 20936559Sbostic 21036559Sbostic /* 21136559Sbostic * The user structure. 21236559Sbostic */ 21336559Sbostic union { 21436559Sbostic struct user user; /* the actual user struct */ 21536559Sbostic char upages[ctob(UPAGES)]; /* u. + kernel stack */ 21636559Sbostic } uu; 21736559Sbostic #define u uu.user 218