[BACK]Return to headersize.c CVS log [TXT][DIR] Up to [local] / sys / arch / alpha / stand

Annotation of sys/arch/alpha/stand/headersize.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: headersize.c,v 1.8 2005/08/10 16:58:42 todd Exp $     */
                      2: /*     $NetBSD: headersize.c,v 1.5 1996/09/23 04:32:59 cgd Exp $       */
                      3:
                      4: /*
                      5:  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Author: Chris G. Demetriou
                      9:  *
                     10:  * Permission to use, copy, modify and distribute this software and
                     11:  * its documentation is hereby granted, provided that both the copyright
                     12:  * notice and this permission notice appear in all copies of the
                     13:  * software, derivative works or modified versions, and any portions
                     14:  * thereof, and that both notices appear in supporting documentation.
                     15:  *
                     16:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     17:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
                     18:  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     19:  *
                     20:  * Carnegie Mellon requests users of this software to return to
                     21:  *
                     22:  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
                     23:  *  School of Computer Science
                     24:  *  Carnegie Mellon University
                     25:  *  Pittsburgh PA 15213-3890
                     26:  *
                     27:  * any improvements or extensions that they make and grant Carnegie the
                     28:  * rights to redistribute these changes.
                     29:  */
                     30:
                     31: #define        ELFSIZE         64
                     32:
                     33: #include <sys/types.h>
                     34: #include <sys/fcntl.h>
                     35: #include <sys/exec.h>
                     36: #include <sys/exec_ecoff.h>
                     37: #include <sys/exec_elf.h>
                     38:
                     39: #include <unistd.h>
                     40: #include <stdio.h>
                     41: #include <err.h>
                     42:
                     43: #define        HDR_BUFSIZE     512
                     44:
                     45: int
                     46: main(argc, argv)
                     47:        int argc;
                     48:        char *argv[];
                     49: {
                     50:        char buf[HDR_BUFSIZE], *fname;
                     51: #ifdef ALPHA_BOOT_ELF
                     52:        Elf64_Ehdr *elfp;
                     53: #endif
                     54:        int fd;
                     55:        unsigned long loadaddr;
                     56:
                     57:        if (argc != 3)
                     58:                errx(1, "must be given two arguments (load addr, file name)");
                     59:        if (sscanf(argv[1], "%lx", &loadaddr) != 1)
                     60:                errx(1, "load addr argument (%s) not valid", argv[1]);
                     61:        fname = argv[2];
                     62:
                     63:        if ((fd = open(fname, O_RDONLY, 0)) == -1)
                     64:                err(1, "%s: open failed", fname);
                     65:
                     66:        if (read(fd, &buf, HDR_BUFSIZE) < HDR_BUFSIZE)
                     67:                err(1, "%s: read failed", fname);
                     68: #ifdef ALPHA_BOOT_ELF
                     69:        elfp = (Elf64_Ehdr *)buf;
                     70: #endif
                     71:
                     72: #ifdef ALPHA_BOOT_ELF
                     73:        if (memcmp(ELFMAG, elfp->e_ident, SELFMAG) == 0) {
                     74:                Elf64_Phdr phdr;
                     75:
                     76:                /* XXX assume the first segment is the one we want */
                     77:                if (lseek(fd, elfp->e_phoff, SEEK_SET) == -1)
                     78:                        err(1, "%s: lseek phdr failed", fname);
                     79:                if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr))
                     80:                        err(1, "%s: read phdr failed", fname);
                     81:
                     82:                printf("%ld\n", phdr.p_offset + (loadaddr - phdr.p_vaddr));
                     83:        }
                     84:        else
                     85: #endif
                     86:                errx(1, "%s: bad magic number", fname);
                     87:
                     88:        close(fd);
                     89:        exit(0);
                     90: }

CVSweb