Annotation of 43BSDReno/sbin/enpload/enpload.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Computer Consoles Inc.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted
                      9:  * provided that: (1) source distributions retain this entire copyright
                     10:  * notice and comment, and (2) distributions including binaries display
                     11:  * the following acknowledgement:  ``This product includes software
                     12:  * developed by the University of California, Berkeley and its contributors''
                     13:  * in the documentation or other materials provided with the distribution
                     14:  * and in all advertising materials mentioning features or use of this
                     15:  * software. Neither the name of the University nor the names of its
                     16:  * contributors may be used to endorse or promote products derived
                     17:  * from this software without specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: char copyright[] =
                     25: "@(#) Copyright (c) 1988 The Regents of the University of California.\n\
                     26:  All rights reserved.\n";
                     27: #endif /* not lint */
                     28: 
                     29: #ifndef lint
                     30: static char sccsid[] = "@(#)enpload.c  5.3 (Berkeley) 6/1/90";
                     31: #endif /* not lint */
                     32: 
                     33: /*
                     34:  * CMC Ethernet ``Microcode'' Loader.
                     35:  */
                     36: #include <stdio.h>
                     37: #include <a.out.h>
                     38: 
                     39: #include <sys/types.h>
                     40: #include <sys/file.h>
                     41: #include <sys/ioctl.h>
                     42: #include <tahoeif/if_enpreg.h>
                     43: 
                     44: char   *dev;
                     45: 
                     46: main(argc, argv)
                     47:        int argc;
                     48:        char *argv[];
                     49: {
                     50:        int enp = -1, fd, first = 1, nostart = 0;
                     51: 
                     52:        argc--, argv++;
                     53:        if (argc > 0) {
                     54:                enp = open(dev = argv[0], O_RDWR);
                     55:                if (enp < 0) {
                     56:                        fprintf(stderr, "enpload: ");
                     57:                        perror(dev);
                     58:                        exit(-1);
                     59:                }
                     60:                argc--, argv++;
                     61:        }
                     62:        for (; argc > 0; argc--, argv++) {
                     63:                if (strcmp(argv[0], "-s") == 0 || strcmp(argv[0], "-S") == 0) {
                     64:                        nostart++;
                     65:                        continue;
                     66:                }
                     67:                if (first) {
                     68:                        /*
                     69:                         * Reset device before first file is loaded.
                     70:                         */
                     71:                        if (ioctl(enp, ENPIORESET) < 0) {
                     72:                                fprintf(stderr, "enpload: %s: ", dev);
                     73:                                perror("ioctl (ENPIORESET)");
                     74:                                exit(-1);
                     75:                        }
                     76:                        first = !first;
                     77:                }
                     78:                if ((fd = open(argv[0], O_RDONLY)) < 0) {
                     79:                        fprintf(stderr, "enpload: "), perror(argv[0]);
                     80:                        exit(1);
                     81:                }
                     82:                enpload(enp, fd, argv[0]);
                     83:                close(fd);
                     84:        }
                     85:        if (enp != -1 && !nostart && ioctl(enp, ENPIOGO) < 0) {
                     86:                fprintf(stderr, "enpload: ");
                     87:                perror("ioctl (ENPIOGO)");
                     88:                exit(-1);
                     89:        }
                     90:        exit(0);
                     91: }
                     92: 
                     93: #define        RELO            0x03FFFF        /* relocation offset */
                     94: #define        ENPMSTART       0x0             /* start of memory */
                     95: #define        BSIZE           512             /* buffer size */
                     96: char   buff[BSIZE];
                     97: char   zbuf[BSIZE];
                     98: 
                     99: enpload(enp, fd, filename)
                    100:        int enp, fd;
                    101:        char *filename;
                    102: {
                    103:        int cnt, size, lstart;
                    104:        struct exec hdr;
                    105: 
                    106:        if (read(fd, &hdr, sizeof (hdr)) != sizeof (hdr)) {
                    107:                fprintf(stderr, "enpload: %s: Read short (header).\n",
                    108:                   filename);
                    109:                exit(1);
                    110:        }
                    111:        if (N_BADMAG(hdr)) {
                    112:                fprintf(stderr, "enpload: %s: Bad magic number.\n", filename);
                    113:                exit(1);
                    114:        }
                    115:        size = hdr.a_text + hdr.a_data;
                    116:        lstart = (ENPMSTART + (hdr.a_entry & RELO)) - 0x1000;
                    117: 
                    118:        printf("%s: Loading %s...", dev, filename);
                    119:        (void) lseek(enp, lstart + size, L_SET);
                    120:        while (hdr.a_bss >= BSIZE) {
                    121:                if (write(enp, zbuf, BSIZE) != BSIZE) {
                    122:                        fprintf(stderr, "enpload: Bss write error.\n");
                    123:                        exit(-1);
                    124:                }
                    125:                hdr.a_bss -= BSIZE;
                    126:        }
                    127:        if (hdr.a_bss > 0 && write(enp, zbuf, hdr.a_bss) != hdr.a_bss) {
                    128:                fprintf(stderr, "enpload: Bss write error.\n");
                    129:                exit(-1);
                    130:        }
                    131:        (void) lseek(enp, lstart, L_SET);
                    132:        while (size > BSIZE) {
                    133:                cnt = read(fd, buff, BSIZE);
                    134:                size -= cnt;
                    135:                if (write(enp, buff, cnt) != cnt) {
                    136:                        fprintf(stderr, "enpload: Write error.\n");
                    137:                        exit(-1);
                    138:                }
                    139:        }
                    140:        if (size > 0) {
                    141:                cnt = read(fd, buff, size);
                    142:                if (write(enp, buff, cnt) != cnt) {
                    143:                        fprintf(stderr, "enpload: Write error.\n");
                    144:                        exit(-1);
                    145:                }
                    146:        }
                    147:        printf("done.\n");
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.