summaryrefslogtreecommitdiff
path: root/sys/arch/alpha/stand/headersize.c
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1996-10-30 22:41:57 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1996-10-30 22:41:57 +0000
commit072b56c97e17e8e69ddab5a735b5297387a88a70 (patch)
tree22eaee09956502609c240ddff8a108d8733521f9 /sys/arch/alpha/stand/headersize.c
parentb85b15782739220b5bf2563ccdc7ac9e256a31d2 (diff)
Merge to NetBSD 961020. Retained our kernel APIs where NetBSD has changed.
-Wall -Wstrict-prototypes -Wmissing-prototypes too.
Diffstat (limited to 'sys/arch/alpha/stand/headersize.c')
-rw-r--r--sys/arch/alpha/stand/headersize.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/sys/arch/alpha/stand/headersize.c b/sys/arch/alpha/stand/headersize.c
index 3b2024e4f25..c7e853d5e18 100644
--- a/sys/arch/alpha/stand/headersize.c
+++ b/sys/arch/alpha/stand/headersize.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: headersize.c,v 1.3 1996/07/29 23:01:20 niklas Exp $ */
-/* $NetBSD: headersize.c,v 1.3.4.1 1996/06/13 18:35:33 cgd Exp $ */
+/* $OpenBSD: headersize.c,v 1.4 1996/10/30 22:40:30 niklas Exp $ */
+/* $NetBSD: headersize.c,v 1.5 1996/09/23 04:32:59 cgd Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -28,22 +28,58 @@
* rights to redistribute these changes.
*/
+#define ELFSIZE 64
+
#include <sys/types.h>
+#include <sys/fcntl.h>
#include <sys/exec.h>
#include <sys/exec_ecoff.h>
+#include <sys/exec_elf.h>
+
+#include <unistd.h>
+#include <stdio.h>
#define HDR_BUFSIZE 512
-main()
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
{
- char buf[HDR_BUFSIZE];
- struct ecoff_exechdr *execp;
+ char buf[HDR_BUFSIZE], *fname;
+ struct ecoff_exechdr *ecoffp;
+ Elf_Ehdr *elfp;
+ int fd;
+ unsigned long loadaddr;
+
+ if (argc != 3)
+ errx(1, "must be given two arguments (load addr, file name)");
+ if (sscanf(argv[1], "%lx", &loadaddr) != 1)
+ errx(1, "load addr argument (%s) not valid", argv[1]);
+ fname = argv[2];
+
+ if ((fd = open(fname, O_RDONLY, 0)) == -1)
+ err(1, "%s: open failed", 0);
+
+ if (read(fd, &buf, HDR_BUFSIZE) < HDR_BUFSIZE)
+ err(1, "%s: read failed", fname);
+ ecoffp = (struct ecoff_exechdr *)buf;
+ elfp = (Elf_Ehdr *)buf;
+
+ if (!ECOFF_BADMAG(ecoffp)) {
+ printf("%d\n", ECOFF_TXTOFF(ecoffp));
+ } else if (memcmp(Elf_e_ident, elfp->e_ident, Elf_e_siz) == 0) {
+ Elf_Phdr phdr;
+
+ /* XXX assume the first segment is the one we want */
+ if (lseek(fd, elfp->e_phoff, SEEK_SET) == -1)
+ err(1, "%s: lseek phdr failed", fname);
+ if (read(fd, (void *)&phdr, sizeof(phdr)) != sizeof(phdr))
+ err(1, "%s: read phdr failed", fname);
- if (read(0, &buf, HDR_BUFSIZE) < HDR_BUFSIZE) {
- perror("read");
- exit(1);
- }
- execp = (struct ecoff_exechdr *)buf;
+ printf("%d\n", phdr.p_offset + (loadaddr - phdr.p_vaddr));
+ } else
+ errx(1, "%s: bad magic number", fname);
- printf("%d\n", ECOFF_TXTOFF(execp));
+ close(fd);
}