1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)read_nlist.c	2.2 (2.11BSD GTE) 1/10/94
   7:  */
   8: 
   9: /*
  10:  * Read all the symbols we'll need for the devices we want to configure
  11:  * These are -- The probe, attach and handler routines for each device,
  12:  * and a few symbols that we'll need later on.
  13:  */
  14: 
  15: #include <machine/autoconfig.h>
  16: #include <sys/param.h>
  17: #include <sys/file.h>
  18: #include <a.out.h>
  19: #include <stdio.h>
  20: #include "dtab.h"
  21: 
  22: extern  char    *strdup();
  23: extern  char    *nlist_name;    /* file we read the namelist from */
  24: extern int  guess_ndev; /* number of lines read from dtab */
  25: extern int  debug;
  26: extern int  kmem;
  27: extern int  pflag;
  28: NLIST   *nl, *np, *int_nl, *good_nl, *bad_nl, *trap_nl, *sep_nl, *vers_nl,
  29:     *add_nlist(), *end_vector, *next_nl;
  30: 
  31: #define END_NAME    "endvec"
  32: #define NEXTIV_NAME "_nextiv"   /* floating vector allocator */
  33: #define INT_NAME    "_conf_int"
  34: #define GOOD_NAME   "CGOOD"
  35: #define BAD_NAME    "CBAD"
  36: #define TRAP_NAME   "trap"
  37: #define SEPID_NAME  "KERN_NONSEP"   /* KERN_NONSEP */
  38: #define VERSION     "_version"
  39: 
  40: read_nlist()
  41: {
  42:     register NLIST  **lp,
  43:             *nnp;
  44:     register DTAB   *dp;
  45:     struct exec head;
  46:     struct ovlhdr   ovhead;
  47:     HAND    *already = (HAND *)NULL,
  48:         *sp;
  49:     off_t   offst;
  50:     int unix_fd;
  51:     short   cnt;
  52:     char    tname[20],
  53:         unix_vers[100],
  54:         core_vers[100],
  55:         *calloc();
  56:     NLIST   *add_nlist();
  57: 
  58:     np = nl = (NLIST *)calloc(guess_ndev + 10,sizeof(NLIST));
  59:     for (dp = devs; dp != NULL; dp = dp->dt_next) {
  60:         sprintf(tname, "_%sprobe", dp->dt_name);
  61:         dp->dt_probe = add_nlist(tname);
  62:         sprintf(tname, "_%sattach", dp->dt_name);
  63:         dp->dt_attach = add_nlist(tname);
  64:         sprintf(tname, "_%sVec", dp->dt_name);
  65:         dp->dt_setvec = add_nlist(tname);
  66:         for (sp = dp->dt_handlers;sp;sp = sp->s_next)
  67:             sp->s_nl = add_nlist(sp->s_str);
  68:     }
  69:     end_vector = np++;
  70:     end_vector->n_un.n_name = END_NAME;
  71:     int_nl = np++;
  72:     int_nl->n_un.n_name = INT_NAME;
  73:     good_nl = np++;
  74:     good_nl->n_un.n_name = GOOD_NAME;
  75:     bad_nl = np++;
  76:     bad_nl->n_un.n_name = BAD_NAME;
  77:     next_nl = np++;
  78:     next_nl->n_un.n_name = NEXTIV_NAME;
  79:     trap_nl = np++;
  80:     trap_nl->n_un.n_name = TRAP_NAME;
  81:     vers_nl = np++;
  82:     vers_nl->n_un.n_name = VERSION;
  83:     sep_nl = np++;
  84:     sep_nl->n_un.n_name = SEPID_NAME;
  85: 
  86:     if ((unix_fd = open(nlist_name,O_RDONLY)) < 0) {
  87:         perror(nlist_name);
  88:         exit(AC_SETUP);
  89:     }
  90:     nlist(nlist_name,nl);
  91:     if (debug || pflag)
  92:         for (np = nl; np->n_un.n_name; np++)
  93:             printf("%s = %o\n", np->n_un.n_name, np->n_value);
  94:     for (np = end_vector; np <= trap_nl; np++)
  95:         if (!np->n_value) {
  96:             fprintf(stderr,"%s: couldn't find symbols in %s.\n",myname,nlist_name);
  97:             exit(AC_SETUP);
  98:         }
  99:     if (!debug) {
 100: #define round(x) (ctob(stoc(ctos(btoc(x)))))
 101:         lseek(unix_fd,(off_t)0,L_SET);
 102:         read(unix_fd,(char *)&head,sizeof(head));
 103:         offst = (off_t)vers_nl->n_value + (off_t)head.a_text + sizeof(head);
 104:         if (head.a_magic == A_MAGIC2 || head.a_magic == A_MAGIC5)
 105:             offst -= (off_t)round(head.a_text);
 106:         if (head.a_magic == A_MAGIC5 || head.a_magic == A_MAGIC6) {
 107:             read(unix_fd,(char *)&ovhead,sizeof(ovhead));
 108:             offst += sizeof(ovhead);
 109:             if (head.a_magic == A_MAGIC5)
 110:                 offst -= (off_t)round(ovhead.max_ovl);
 111:             for (cnt = 0;cnt < NOVL;++cnt)
 112:                 offst += (off_t)ovhead.ov_siz[cnt];
 113:         }
 114:         lseek(unix_fd,offst,L_SET);
 115:         read(unix_fd,unix_vers,sizeof(unix_vers));
 116:         lseek(kmem,(off_t)vers_nl->n_value,L_SET);
 117:         read(kmem,core_vers,sizeof(core_vers));
 118:         unix_vers[99] = core_vers[99] = EOS;    /* Just in case! */
 119:         if (strcmp(unix_vers,core_vers)) {
 120:             fprintf(stderr,"%s: %s is not the running version.\n",myname,nlist_name);
 121:             exit(AC_SETUP);
 122:         }
 123:     }
 124:     close(unix_fd);
 125: }
 126: 
 127: /*
 128:  * If the passed symbol is in the nlist table, return pointer to it,
 129:  * otherwise add it to the table and return a pointer to new entry.
 130:  */
 131: NLIST *
 132: add_nlist(name)
 133: char    *name;
 134: {
 135:     register NLIST  *n;
 136: 
 137:     for (n = nl;n < np;++n)
 138:         if (!strcmp(n->n_un.n_name, name))
 139:             return(n);
 140:     np->n_un.n_name = strdup(name);
 141:     return(np++);
 142: }

Defined functions

add_nlist defined in line 131; used 6 times
read_nlist defined in line 40; used 1 times

Defined variables

bad_nl defined in line 28; used 7 times
end_vector defined in line 29; used 5 times
good_nl defined in line 28; used 3 times
int_nl defined in line 28; used 4 times
next_nl defined in line 29; used 3 times
nl defined in line 28; used 4 times
np defined in line 28; used 21 times
sep_nl defined in line 28; used 3 times
trap_nl defined in line 28; used 6 times
vers_nl defined in line 28; used 4 times

Defined macros

BAD_NAME defined in line 35; used 1 times
  • in line 76
END_NAME defined in line 31; used 1 times
  • in line 70
GOOD_NAME defined in line 34; used 1 times
  • in line 74
INT_NAME defined in line 33; used 1 times
  • in line 72
NEXTIV_NAME defined in line 32; used 1 times
  • in line 78
SEPID_NAME defined in line 37; used 1 times
  • in line 84
TRAP_NAME defined in line 36; used 1 times
  • in line 80
VERSION defined in line 38; used 1 times
  • in line 82
round defined in line 100; used 2 times
Last modified: 1994-01-15
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 174
Valid CSS Valid XHTML 1.0 Strict