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

Defined functions

add_nlist defined in line 118; used 4 times
read_nlist defined in line 30; used 1 times

Defined variables

bad_nl defined in line 19; used 8 times
end_vector defined in line 19; used 6 times
good_nl defined in line 19; used 4 times
int_nl defined in line 19; used 5 times
nl defined in line 18; used 5 times
np defined in line 18; used 20 times
sep_nl defined in line 20; used 4 times
trap_nl defined in line 20; used 7 times
vers_nl defined in line 20; used 5 times

Defined macros

BAD_NAME defined in line 25; used 1 times
  • in line 59
END_NAME defined in line 22; used 1 times
  • in line 53
GOOD_NAME defined in line 24; used 1 times
  • in line 57
INT_NAME defined in line 23; used 1 times
  • in line 55
SEPID_NAME defined in line 27; used 1 times
  • in line 65
TRAP_NAME defined in line 26; used 1 times
  • in line 61
VERSION defined in line 28; used 1 times
  • in line 63
round defined in line 83; used 2 times
Last modified: 1983-10-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1102
Valid CSS Valid XHTML 1.0 Strict