diff options
author | V3n3RiX <venerix@redcorelinux.org> | 2017-10-09 18:53:29 +0100 |
---|---|---|
committer | V3n3RiX <venerix@redcorelinux.org> | 2017-10-09 18:53:29 +0100 |
commit | 4f2d7949f03e1c198bc888f2d05f421d35c57e21 (patch) | |
tree | ba5f07bf3f9d22d82e54a462313f5d244036c768 /sys-boot/milo/files |
reinit the tree, so we can have metadata
Diffstat (limited to 'sys-boot/milo/files')
-rw-r--r-- | sys-boot/milo/files/README-gentoo | 98 | ||||
-rw-r--r-- | sys-boot/milo/files/linux-2.2.25-gcc3-milo.diff | 123 | ||||
-rw-r--r-- | sys-boot/milo/files/milo-2.2-18-gcc3-gentoo.diff | 174 | ||||
-rw-r--r-- | sys-boot/milo/files/mkserial_no.c | 45 | ||||
-rw-r--r-- | sys-boot/milo/files/objstrip.c | 282 |
5 files changed, 722 insertions, 0 deletions
diff --git a/sys-boot/milo/files/README-gentoo b/sys-boot/milo/files/README-gentoo new file mode 100644 index 000000000000..5ad8c753ba09 --- /dev/null +++ b/sys-boot/milo/files/README-gentoo @@ -0,0 +1,98 @@ +# Copyright 1999-2004 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# +############################################## +# Gentoo Linux MILO images. +#################################################### +# +# What is MILO? +# +### + +MILO is an AlphaLinux bootloader, which is usually used to load the Linux +Operating System on Alpha machines that dont have SRM. + +There are two families of firmware on Alpha, ARC and SRM. ARC was developed +for use with Windows NT, and cannot support Linux. Some Alpha's were +distributed with only ARC firmware, for use specifically with Windows NT, +these machines would not be able to run any OS except for Windows NT without +MILO. + +If you do have SRM, or the option of using SRM, you should be using the aboot +bootloader, unless you really know what you are doing. + +NOTE: if you have srm, but would like to dual boot with Windows NT, or use ARC + firmware, you might find MILO more useful than aboot. There are other + reasons also, booting a kernel from a reiserfs partition, for example. + +NOTE: The Gentoo MILO images are slightly different to the standard + MILO images, they have been patched to compile with gcc3 and + work with the latest linux-2.2 kernel and drivers. You can + also optimise your MILO image, to maximise the performance of the + MILO pager! woooo! + +FIXME: will there be a boot speed improvement from optimising MILO? +FIXME: what about performance of the call_pal routines (or at least the + overhead of calling them, as they are hand coded asm), will + that improve system performance? + +##################################################### +# +# How do i use these images to boot? +# +#### + +NOTE: Read the MILO-HOWTO in this directory now! + There is an explanation and description of all the ways you can + start MILO, including SRM, Floppy, Flash and Debug Monitor. + +In this directory you will find the MILO images, you can use these to +make MILO boot floppies, or install them to a FAT partition. + +There are instructions below for making a MILO boot floppy. + + +1. insert the disk you would like to make a MILO floppy. + +2. fdformat /dev/fd0 + + Obviously, if the disk is already formatted you can skip + this step. + +3. mformat a: + + this will create a MSDOS file system (FAT) on the floppy. + +4. mcopy milo-2.4.18-gentoo-<your alpha> a:\milo + + install the milo image for your machine onto the new floppy. + +5. mcopy linload.exe a:\linload.exe + _OR_ if you have a Ruffian machine: + mcopy ldmilo.exe a:\ldmilo.exe + + install the milo loader, note that ruffians dont use ldlinux.exe + by default, if your system expects ldlinux.exe, just copy that file + instead. the ldmilo included in this ebuild contains the fixes by Jay + Eastabrook, sometimes called "Jay's Hacked Version". + +6. echo -ne '\125\252' | dd of=/dev/fd0 bs=1 seek=510 count=2 conv=notrunc + + this might not be nescessary on all machines, but some ARCs expect the + floppy to be marked bootable, this fakes the magic. + +7. reboot, and set ARCs to boot your shiny new MILO floppy! + +##################################################### +# +# BUGS +# +#### + +These MILO images are not extensively tested, if you use one +PLEASE, PLEASE, PLEASE tell me! i need to know which systems +it works on and which ones it doesnt. + +if you dont want to enter a bug in http://bugs.gentoo.org/ + +you can just email me a quick note to taviso@gentoo.org diff --git a/sys-boot/milo/files/linux-2.2.25-gcc3-milo.diff b/sys-boot/milo/files/linux-2.2.25-gcc3-milo.diff new file mode 100644 index 000000000000..d99769f91c9f --- /dev/null +++ b/sys-boot/milo/files/linux-2.2.25-gcc3-milo.diff @@ -0,0 +1,123 @@ +diff -ru --minimal linux/arch/alpha/kernel/process.c linux/arch/alpha/kernel/process.c +--- linux/arch/alpha/kernel/process.c 2001-03-25 17:37:29.000000000 +0100 ++++ linux/arch/alpha/kernel/process.c 2003-06-02 20:20:19.000000000 +0100 +@@ -57,7 +57,7 @@ + static struct fs_struct init_fs = INIT_FS; + static struct files_struct init_files = INIT_FILES; + static struct signal_struct init_signals = INIT_SIGNALS; +-struct mm_struct init_mm = INIT_MM; ++struct mm_struct init_mm; + + union task_union init_task_union __attribute__((section("init_task"))) + = { task: INIT_TASK }; +diff -ru --minimal linux/drivers/char/tty_io.c linux/drivers/char/tty_io.c +--- linux/drivers/char/tty_io.c 2002-05-21 00:32:34.000000000 +0100 ++++ linux/drivers/char/tty_io.c 2003-06-02 20:05:08.000000000 +0100 +@@ -756,15 +756,17 @@ + } + + /* Semaphore to protect creating and releasing a tty */ +-static struct semaphore tty_sem = MUTEX; ++static struct semaphore tty_sem; + + static void down_tty_sem(int index) + { ++ tty_sem = MUTEX; + down(&tty_sem); + } + + static void up_tty_sem(int index) + { ++ tty_sem = MUTEX; + up(&tty_sem); + } + +@@ -785,6 +787,7 @@ + int retval=0; + int idx; + ++ tty_sem = MUTEX; + driver = get_tty_driver(device); + if (!driver) + return -ENODEV; +diff -ru --minimal linux/fs/super.c linux/fs/super.c +--- linux/fs/super.c 2001-11-02 16:39:08.000000000 +0000 ++++ linux/fs/super.c 2003-06-02 20:13:53.000000000 +0100 +@@ -42,7 +42,7 @@ + * unmounting a filesystem and re-mounting it (or something + * else). + */ +-static struct semaphore mount_sem = MUTEX; ++static struct semaphore mount_sem; + + extern void wait_for_keypress(void); + extern struct file_operations * get_blkfops(unsigned int major); +@@ -730,6 +730,7 @@ + int retval; + struct inode * inode = get_empty_inode(); + ++ mount_sem = MUTEX; + retval = -ENOMEM; + if (!inode) + goto out; +@@ -859,6 +860,7 @@ + struct vfsmount *vfsmnt; + int error; + ++ mount_sem = MUTEX; + error = -EACCES; + if (!(flags & MS_RDONLY) && dev && is_read_only(dev)) + goto out; +diff -ru --minimal linux/kernel/sys.c linux/kernel/sys.c +--- linux/kernel/sys.c 2002-09-16 17:26:33.000000000 +0100 ++++ linux/kernel/sys.c 2003-06-02 20:00:20.000000000 +0100 +@@ -866,12 +866,13 @@ + * rather than a semaphore. Anybody want to implement + * one? + */ +-struct semaphore uts_sem = MUTEX; ++struct semaphore uts_sem; + + asmlinkage int sys_newuname(struct new_utsname * name) + { + int errno = 0; + ++ uts_sem = MUTEX; + down(&uts_sem); + if (copy_to_user(name,&system_utsname,sizeof *name)) + errno = -EFAULT; +@@ -883,6 +884,7 @@ + { + int errno; + ++ uts_sem = MUTEX; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + if (len < 0 || len > __NEW_UTS_LEN) +@@ -901,6 +903,7 @@ + { + int i, errno; + ++ uts_sem = MUTEX; + if (len < 0) + return -EINVAL; + down(&uts_sem); +@@ -922,6 +925,7 @@ + { + int errno; + ++ uts_sem = MUTEX; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + if (len < 0 || len > __NEW_UTS_LEN) +diff -ru --minimal linux/include/asm-alpha/errno.h linux/include/asm-alpha/errno.h +--- linux/include/asm-alpha/errno.h 2001-03-25 17:31:06.000000000 +0100 ++++ linux/include/asm-alpha/errno.h 2003-06-02 23:48:45.000000000 +0100 +@@ -134,6 +134,7 @@ + #define ELIBMAX 125 /* Attempting to link in too many shared libraries */ + #define ELIBEXEC 126 /* Cannot exec a shared library directly */ + #define ERESTART 127 /* Interrupted system call should be restarted */ ++#define EHASHCOLLISION 127 /* reiserfs hash collision */ + #define ESTRPIPE 128 /* Streams pipe error */ + + #define ENOMEDIUM 129 /* No medium found */ diff --git a/sys-boot/milo/files/milo-2.2-18-gcc3-gentoo.diff b/sys-boot/milo/files/milo-2.2-18-gcc3-gentoo.diff new file mode 100644 index 000000000000..2fa897df6e90 --- /dev/null +++ b/sys-boot/milo/files/milo-2.2-18-gcc3-gentoo.diff @@ -0,0 +1,174 @@ +diff -u -r --minimal milo-2.2-18.orig/config.in milo-2.2-18/config.in +--- milo-2.2-18.orig/config.in 2001-07-18 15:58:30.000000000 +0100 ++++ milo-2.2-18/config.in 2003-06-05 18:52:06.000000000 +0100 +@@ -5,7 +5,7 @@ + + comment 'Alpha Linux Miniloader setup' + # +-string 'Path to kernel sources' KSRC /usr/src/linux ++string 'Path to kernel sources' KSRC ${WORKDIR}/linux + choice 'Alpha system type' \ + "Alpha-XLT MINI_ALPHA_XLT \ + Alpha-XL MINI_ALPHA_XL \ +diff -u -r --minimal milo-2.2-18.orig/devices.c milo-2.2-18/devices.c +--- milo-2.2-18.orig/devices.c 2001-07-18 16:59:38.000000000 +0100 ++++ milo-2.2-18/devices.c 2003-06-05 18:52:06.000000000 +0100 +@@ -98,7 +98,7 @@ + struct fs_struct init_fs = INIT_FS; + struct files_struct init_files = INIT_FILES; + struct signal_struct init_signals = INIT_SIGNALS; +-struct mm_struct init_mm = INIT_MM; ++struct mm_struct init_mm; + + unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */ + +@@ -1213,7 +1213,7 @@ + } + + +-void __wake_up(struct wait_queue **p, unsigned int mode, unsigned int wq_mode) ++void __wake_up(struct wait_queue **p, unsigned int mode) + { + wake_up(p); + } +diff -u -r --minimal milo-2.2-18.orig/Documentation/defconfig.milo milo-2.2-18/Documentation/defconfig.milo +--- milo-2.2-18.orig/Documentation/defconfig.milo 2001-07-19 10:59:45.000000000 +0100 ++++ milo-2.2-18/Documentation/defconfig.milo 2003-06-05 18:52:06.000000000 +0100 +@@ -5,7 +5,7 @@ + # + # Alpha Linux Miniloader setup + # +-KSRC=/usr/src/linux ++KSRC=${WORKDIR}/linux + # MINI_ALPHA_XLT is not set + # MINI_ALPHA_XL is not set + # MINI_ALPHA_BOOK1 is not set +@@ -36,7 +36,7 @@ + # MINI_VGA_RAW2 is not set + MINI_TGA_CONSOLE=y + MINI_EXTERNAL_FONT=y +-MINI_FONT_FILE=/usr/lib/kbd/consolefonts/default8x16.gz ++MINI_FONT_FILE=/usr/share/consolefonts/default8x16.psfu.gz + MILO_CONFIG_EXT2FS=y + MILO_CONFIG_MSDOSFS=y + MILO_CONFIG_REISERFS=y +diff -u -r --minimal milo-2.2-18.orig/hwrpb.c milo-2.2-18/hwrpb.c +--- milo-2.2-18.orig/hwrpb.c 2001-07-18 14:38:38.000000000 +0100 ++++ milo-2.2-18/hwrpb.c 2003-06-05 18:52:06.000000000 +0100 +@@ -368,9 +368,17 @@ + percpu = + (struct percpu_struct *) (((char *) hwrpb) + + hwrpb->processor_offset); +- percpu->serial_no[0] = 0x73695f78756e694c; ++#ifndef MILO_SERIAL_NUMBER0 ++#define MILO_SERIAL_NUMBER0 0x73695f78756e694c ++#endif /* MILO_SERIAL_NUMBER0 */ ++ ++#ifndef MILO_SERIAL_NUMBER1 ++#define MILO_SERIAL_NUMBER1 0x002174616572475f; ++#endif /* MILO_SERIAL_NUMBER1 */ ++ ++ percpu->serial_no[0] = MILO_SERIAL_NUMBER0; + /* :-) */ +- percpu->serial_no[1] = 0x002174616572475f; ++ percpu->serial_no[1] = MILO_SERIAL_NUMBER1; + percpu->type = cpuid(); + + /* +diff -u -r --minimal milo-2.2-18.orig/Makefile milo-2.2-18/Makefile +--- milo-2.2-18.orig/Makefile 2001-07-18 17:15:31.000000000 +0100 ++++ milo-2.2-18/Makefile 2003-06-05 18:52:06.000000000 +0100 +@@ -54,8 +54,8 @@ + # + + LINKFLAGS = -non_shared -N -T milo.lds +-CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \ +- -fno-strict-aliasing -mcpu=ev5 -pipe -mno-fp-regs \ ++CFLAGS += -Wall -Wstrict-prototypes -fomit-frame-pointer \ ++ -fno-strict-aliasing -pipe -mno-fp-regs \ + -ffixed-8 -Wa,-mev6 -D__KERNEL__ -D__linux__ \ + -I$(KSRC)/include + +diff -u -r --minimal milo-2.2-18.orig/milo.c milo-2.2-18/milo.c +--- milo-2.2-18.orig/milo.c 2001-07-18 14:38:38.000000000 +0100 ++++ milo-2.2-18/milo.c 2003-06-05 19:16:16.000000000 +0100 +@@ -1436,9 +1436,10 @@ + { + extern U64 milo_memory_size; + +- printk("MILO (%s):\n", alpha_mv.vector_name); +- printk(" Built against Linux " UTS_RELEASE "\n"); ++ printk("Gentoo MILO (%s):\n", alpha_mv.vector_name); ++ printk(" Built against Gentoo Linux Kernel " UTS_RELEASE "\n"); + printk(" Using compiler " LINUX_COMPILER "\n"); ++ printk("\nWelcome to the Gentoo Linux MIniLOader\n"); + + #if 0 + /* what sort of video do we have? */ +@@ -1792,7 +1793,7 @@ + /* parse commands forever */ + while (1) { + +- printk("MILO> "); ++ printk("MILO > "); + + kbd_gets(command_string, 256); + printk_rows = 0; +diff -u -r --minimal milo-2.2-18.orig/tools/scripts/allfiles milo-2.2-18/tools/scripts/allfiles +--- milo-2.2-18.orig/tools/scripts/allfiles 2001-07-11 18:27:02.000000000 +0100 ++++ milo-2.2-18/tools/scripts/allfiles 2003-06-05 18:52:06.000000000 +0100 +@@ -1,7 +1,7 @@ + #!/bin/bash + + LOC=kernel/objs +-KSRC=/usr/src/linux/ ++KSRC=${WORKDIR}/linux + + rm -rf $LOC + +diff -u -r --minimal milo-2.2-18.orig/tools/scripts/build milo-2.2-18/tools/scripts/build +--- milo-2.2-18.orig/tools/scripts/build 2001-07-18 16:58:29.000000000 +0100 ++++ milo-2.2-18/tools/scripts/build 2003-06-05 19:14:25.000000000 +0100 +@@ -1,29 +1,9 @@ + #!/bin/bash + set -e + +-RELEASE=2.2-17 ++RELEASE=2.2-18-Gentoo + +-for i in \ +- "Alpha-XLT XLT" \ +- "Alpha-XL XL" \ +- "AlphaBook1 BOOK1" \ +- "Avanti AVANTI" \ +- "Cabriolet CABRIOLET" \ +- "EB66 EB66" \ +- "EB66+ EB66P" \ +- "EB64+ EB64P" \ +- "EB164 EB164" \ +- "PC164 PC164" \ +- "LX164 LX164" \ +- "SX164 SX164" \ +- "Noname NONAME" \ +- "Takara TAKARA" \ +- "Mikasa MIKASA" \ +- "Alcor ALCOR" \ +- "Miata MIATA" \ +- "Ruffian RUFFIAN" \ +- "Platform2000 P2K" \ +- "UDB UDB" ++for i in __MILO_ARCHES__ + do + short=`echo $i | awk '{print $1}'` + long=`echo $i | awk '{print $2}'` +diff -u -r --minimal milo-2.2-18.orig/tools/scripts/buildkernels milo-2.2-18/tools/scripts/buildkernels +--- milo-2.2-18.orig/tools/scripts/buildkernels 1999-08-19 14:08:55.000000000 +0100 ++++ milo-2.2-18/tools/scripts/buildkernels 2003-06-05 18:52:06.000000000 +0100 +@@ -1,6 +1,6 @@ + #!/bin/bash + +-LINUX=/usr/src/linux ++LINUX=${WORKDIR}/linux + KOUT=$(dirname `pwd`)/linux + + set -e diff --git a/sys-boot/milo/files/mkserial_no.c b/sys-boot/milo/files/mkserial_no.c new file mode 100644 index 000000000000..b4650447584f --- /dev/null +++ b/sys-boot/milo/files/mkserial_no.c @@ -0,0 +1,45 @@ +#include <stdio.h> + +/* some example serial numbers for the MILO bootloader */ +/* gcc -o mkserial_no mkserial_no.c */ +/* taviso@gentoo.org 2003 */ + +/* NOTE: remember you need a 0x00 (NULL terminator) at the end */ + +int main() +{ + long long serial_no[2]; + + /* 1) Linux_is_Great! */ + /* s i _ x u n i L */ + serial_no[0] = 0x73695f78756e694c; + /* ! t a e r G _ */ + serial_no[1] = 0x002174616572475f; + + /* 2) Gentoo Linux. */ + /* L o o t n e G */ + serial_no[0] = 0x4c206f6f746e6547; + /* . x u n i */ + serial_no[1] = 0x0000002e78756e69; + + /* 3) Gentoo/Alpha. */ + /* A / o o t n e G */ + serial_no[0] = 0x412f6f6f746e6547; + /* .a h p l */ + serial_no[1] = 0x0000002e6168706c; + + /* 4) Gentoo MILO. */ + /* M o o t n e G */ + serial_no[0] = 0x4d206f6f746e6547; + /* . O L I */ + serial_no[1] = 0x000000002e4f4c49; + + /* 5) |d|i|g|i|t|a|l| */ + /* i | g | i | d | */ + serial_no[0] = 0x697c677c697c647c; + /* | l | a | t | */ + serial_no[1] = 0x007c6c7c617c747c; + + printf ("serial number:\t%s\n", (char*) serial_no); + return (0); +} diff --git a/sys-boot/milo/files/objstrip.c b/sys-boot/milo/files/objstrip.c new file mode 100644 index 000000000000..bbda40330708 --- /dev/null +++ b/sys-boot/milo/files/objstrip.c @@ -0,0 +1,282 @@ +/* + * arch/alpha/boot/tools/objstrip.c + * + * Strip the object file headers/trailers from an executable (ELF or ECOFF). + * + * Copyright (C) 1996 David Mosberger-Tang. + */ +/* + * Converts an ECOFF or ELF object file into a bootable file. The + * object file must be a OMAGIC file (i.e., data and bss follow immediatly + * behind the text). See DEC "Assembly Language Programmer's Guide" + * documentation for details. The SRM boot process is documented in + * the Alpha AXP Architecture Reference Manual, Second Edition by + * Richard L. Sites and Richard T. Witek. + */ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include <sys/fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include <linux/a.out.h> +#include <linux/coff.h> +#include <linux/param.h> +#include <linux/string.h> +#ifdef __ELF__ +# include <asm/elf.h> +# include <linux/elf.h> +#endif + +/* bootfile size must be multiple of BLOCK_SIZE: */ +#define BLOCK_SIZE 512 + +const char * prog_name; + + +void +usage (void) +{ + fprintf(stderr, + "usage: %s [-v] -p file primary\n" + " %s [-vb] file [secondary]\n", prog_name, prog_name); + exit(1); +} + + +int +main (int argc, char *argv[]) +{ + size_t nwritten, tocopy, n, mem_size, fil_size, pad = 0; + int fd, ofd, i, j, verbose = 0, primary = 0; + char buf[8192], *inname; + struct exec * aout; /* includes file & aout header */ + long offset; +#ifdef __ELF__ + struct elfhdr *elf; + struct elf_phdr *elf_phdr; /* program header */ + unsigned long long e_entry; +#endif + + prog_name = argv[0]; + + for (i = 1; i < argc && argv[i][0] == '-'; ++i) { + for (j = 1; argv[i][j]; ++j) { + switch (argv[i][j]) { + case 'v': + verbose = ~verbose; + break; + + case 'b': + pad = BLOCK_SIZE; + break; + + case 'p': + primary = 1; /* make primary bootblock */ + break; + } + } + } + + if (i >= argc) { + usage(); + } + inname = argv[i++]; + + fd = open(inname, O_RDONLY); + if (fd == -1) { + perror("open"); + exit(1); + } + + ofd = 1; + if (i < argc) { + ofd = open(argv[i++], O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd == -1) { + perror("open"); + exit(1); + } + } + + if (primary) { + /* generate bootblock for primary loader */ + + unsigned long bb[64], sum = 0; + struct stat st; + off_t size; + int i; + + if (ofd == 1) { + usage(); + } + + if (fstat(fd, &st) == -1) { + perror("fstat"); + exit(1); + } + + size = (st.st_size + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1); + memset(bb, 0, sizeof(bb)); + strcpy((char *) bb, "Linux SRM bootblock"); + bb[60] = size / BLOCK_SIZE; /* count */ + bb[61] = 1; /* starting sector # */ + bb[62] = 0; /* flags---must be 0 */ + for (i = 0; i < 63; ++i) { + sum += bb[i]; + } + bb[63] = sum; + if (write(ofd, bb, sizeof(bb)) != sizeof(bb)) { + perror("boot-block write"); + exit(1); + } + printf("%lu\n", size); + return 0; + } + + /* read and inspect exec header: */ + + if (read(fd, buf, sizeof(buf)) < 0) { + perror("read"); + exit(1); + } + +#ifdef __ELF__ + elf = (struct elfhdr *) buf; + + if (elf->e_ident[0] == 0x7f && strncmp(elf->e_ident + 1, "ELF", 3) == 0) { + if (elf->e_type != ET_EXEC) { + fprintf(stderr, "%s: %s is not an ELF executable\n", + prog_name, inname); + exit(1); + } + if (!elf_check_arch(elf)) { + fprintf(stderr, "%s: is not for this processor (e_machine=%d)\n", + prog_name, elf->e_machine); + exit(1); + } + if (elf->e_phnum != 1) { + fprintf(stderr, + "%s: %d program headers (forgot to link with -N?)\n", + prog_name, elf->e_phnum); + } + + e_entry = elf->e_entry; + + lseek(fd, elf->e_phoff, SEEK_SET); + if (read(fd, buf, sizeof(*elf_phdr)) != sizeof(*elf_phdr)) { + perror("read"); + exit(1); + } + + elf_phdr = (struct elf_phdr *) buf; + offset = elf_phdr->p_offset; + mem_size = elf_phdr->p_memsz; + fil_size = elf_phdr->p_filesz; + + /* work around ELF bug: */ + if (elf_phdr->p_vaddr < e_entry) { + unsigned long delta = e_entry - elf_phdr->p_vaddr; + offset += delta; + mem_size -= delta; + fil_size -= delta; + elf_phdr->p_vaddr += delta; + } + + if (verbose) { + fprintf(stderr, "%s: extracting %#016lx-%#016lx (at %lx)\n", + prog_name, (long) elf_phdr->p_vaddr, + elf_phdr->p_vaddr + fil_size, offset); + } + } else +#endif + { + aout = (struct exec *) buf; + + if (!(aout->fh.f_flags & COFF_F_EXEC)) { + fprintf(stderr, "%s: %s is not in executable format\n", + prog_name, inname); + exit(1); + } + + if (aout->fh.f_opthdr != sizeof(aout->ah)) { + fprintf(stderr, "%s: %s has unexpected optional header size\n", + prog_name, inname); + exit(1); + } + + if (N_MAGIC(*aout) != OMAGIC) { + fprintf(stderr, "%s: %s is not an OMAGIC file\n", + prog_name, inname); + exit(1); + } + offset = N_TXTOFF(*aout); + fil_size = aout->ah.tsize + aout->ah.dsize; + mem_size = fil_size + aout->ah.bsize; + + if (verbose) { + fprintf(stderr, "%s: extracting %#016lx-%#016lx (at %lx)\n", + prog_name, aout->ah.text_start, + aout->ah.text_start + fil_size, offset); + } + } + + if (lseek(fd, offset, SEEK_SET) != offset) { + perror("lseek"); + exit(1); + } + + if (verbose) { + fprintf(stderr, "%s: copying %lu byte from %s\n", + prog_name, (unsigned long) fil_size, inname); + } + + tocopy = fil_size; + while (tocopy > 0) { + n = tocopy; + if (n > sizeof(buf)) { + n = sizeof(buf); + } + tocopy -= n; + if ((size_t) read(fd, buf, n) != n) { + perror("read"); + exit(1); + } + do { + nwritten = write(ofd, buf, n); + if ((ssize_t) nwritten == -1) { + perror("write"); + exit(1); + } + n -= nwritten; + } while (n > 0); + } + + if (pad) { + mem_size = ((mem_size + pad - 1) / pad) * pad; + } + + tocopy = mem_size - fil_size; + if (tocopy > 0) { + fprintf(stderr, + "%s: zero-filling bss and aligning to %lu with %lu bytes\n", + prog_name, pad, (unsigned long) tocopy); + + memset(buf, 0x00, sizeof(buf)); + do { + n = tocopy; + if (n > sizeof(buf)) { + n = sizeof(buf); + } + nwritten = write(ofd, buf, n); + if ((ssize_t) nwritten == -1) { + perror("write"); + exit(1); + } + tocopy -= nwritten; + } while (tocopy > 0); + } + return 0; +} |