Home | History | Annotate | Line # | Download | only in vax1k
vax1k_exec.c revision 1.1
      1  1.1  ragge /*	$NetBSD: vax1k_exec.c,v 1.1 1998/08/21 13:25:47 ragge Exp $	*/
      2  1.1  ragge 
      3  1.1  ragge /*
      4  1.1  ragge  * Copyright (c) 1993, 1994 Christopher G. Demetriou
      5  1.1  ragge  * All rights reserved.
      6  1.1  ragge  *
      7  1.1  ragge  * Redistribution and use in source and binary forms, with or without
      8  1.1  ragge  * modification, are permitted provided that the following conditions
      9  1.1  ragge  * are met:
     10  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     11  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     12  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     15  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     16  1.1  ragge  *    must display the following acknowledgement:
     17  1.1  ragge  *      This product includes software developed by Christopher G. Demetriou.
     18  1.1  ragge  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  ragge  *    derived from this software without specific prior written permission
     20  1.1  ragge  *
     21  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  ragge  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  ragge  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  ragge  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  ragge  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  ragge  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  ragge  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  ragge  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  ragge  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  ragge  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  ragge  */
     32  1.1  ragge 
     33  1.1  ragge /*
     34  1.1  ragge  * Exec glue to provide compatibility with older NetBSD vax1k exectuables.
     35  1.1  ragge  *
     36  1.1  ragge  * Because NetBSD/vax now uses 4k page size, older binaries (that started
     37  1.1  ragge  * on an 1k boundary) cannot be mmap'ed. Therefore they are read in
     38  1.1  ragge  * (via vn_rdwr) as OMAGIC binaries and executed. This will use a little
     39  1.1  ragge  * bit more memory, but otherwise won't affect the execution speed.
     40  1.1  ragge  */
     41  1.1  ragge 
     42  1.1  ragge #include <sys/param.h>
     43  1.1  ragge #include <sys/systm.h>
     44  1.1  ragge #include <sys/proc.h>
     45  1.1  ragge #include <sys/malloc.h>
     46  1.1  ragge #include <sys/vnode.h>
     47  1.1  ragge #include <sys/exec.h>
     48  1.1  ragge #include <sys/resourcevar.h>
     49  1.1  ragge 
     50  1.1  ragge #include <vm/vm.h>
     51  1.1  ragge 
     52  1.1  ragge #include <compat/vax1k/vax1k_exec.h>
     53  1.1  ragge 
     54  1.1  ragge int	exec_vax1k_prep_anymagic
     55  1.1  ragge 	    __P((struct proc *, struct exec_package *, int));
     56  1.1  ragge 
     57  1.1  ragge /*
     58  1.1  ragge  * exec_vax1k_makecmds(): Check if it's an a.out-format executable
     59  1.1  ragge  * with an vax1k magic number.
     60  1.1  ragge  *
     61  1.1  ragge  * Given a proc pointer and an exec package pointer, see if the referent
     62  1.1  ragge  * of the epp is in a.out format.  Just check 'standard' magic numbers for
     63  1.1  ragge  * this architecture.
     64  1.1  ragge  *
     65  1.1  ragge  * This function, in the former case, or the hook, in the latter, is
     66  1.1  ragge  * responsible for creating a set of vmcmds which can be used to build
     67  1.1  ragge  * the process's vm space and inserting them into the exec package.
     68  1.1  ragge  */
     69  1.1  ragge 
     70  1.1  ragge int
     71  1.1  ragge exec_vax1k_makecmds(p, epp)
     72  1.1  ragge 	struct proc *p;
     73  1.1  ragge 	struct exec_package *epp;
     74  1.1  ragge {
     75  1.1  ragge 	u_long midmag, magic;
     76  1.1  ragge 	u_short mid;
     77  1.1  ragge 	int error;
     78  1.1  ragge 	struct exec *execp = epp->ep_hdr;
     79  1.1  ragge 
     80  1.1  ragge 	if (epp->ep_hdrvalid < sizeof(struct exec))
     81  1.1  ragge 		return ENOEXEC;
     82  1.1  ragge 
     83  1.1  ragge 	midmag = ntohl(execp->a_midmag);
     84  1.1  ragge 	mid = (midmag >> 16) & 0x3ff;
     85  1.1  ragge 	magic = midmag & 0xffff;
     86  1.1  ragge 
     87  1.1  ragge 	midmag = mid << 16 | magic;
     88  1.1  ragge 
     89  1.1  ragge 	switch (midmag) {
     90  1.1  ragge 	case (MID_VAX1K << 16) | ZMAGIC:
     91  1.1  ragge 		error = exec_vax1k_prep_anymagic(p, epp, 0);
     92  1.1  ragge 		break;
     93  1.1  ragge 
     94  1.1  ragge 	case (MID_VAX1K << 16) | NMAGIC:
     95  1.1  ragge 	case (MID_VAX1K << 16) | OMAGIC:
     96  1.1  ragge 		error = exec_vax1k_prep_anymagic(p, epp, sizeof(struct exec));
     97  1.1  ragge 		break;
     98  1.1  ragge 
     99  1.1  ragge 	default:
    100  1.1  ragge 		error = ENOEXEC;
    101  1.1  ragge 	}
    102  1.1  ragge 
    103  1.1  ragge 	if (error)
    104  1.1  ragge 		kill_vmcmds(&epp->ep_vmcmds);
    105  1.1  ragge 
    106  1.1  ragge 	return error;
    107  1.1  ragge }
    108  1.1  ragge 
    109  1.1  ragge /*
    110  1.1  ragge  * exec_vax1k_prep_anymagic(): Prepare an vax1k ?MAGIC binary's exec package
    111  1.1  ragge  *
    112  1.1  ragge  * First, set of the various offsets/lengths in the exec package.
    113  1.1  ragge  * Note that all code is mapped RW; no protection, but because it is
    114  1.1  ragge  * only used for compatibility it won't hurt.
    115  1.1  ragge  *
    116  1.1  ragge  */
    117  1.1  ragge int
    118  1.1  ragge exec_vax1k_prep_anymagic(p, epp, off)
    119  1.1  ragge         struct proc *p;
    120  1.1  ragge         struct exec_package *epp;
    121  1.1  ragge 	int off;
    122  1.1  ragge {
    123  1.1  ragge 	long etmp, tmp;
    124  1.1  ragge         struct exec *execp = epp->ep_hdr;
    125  1.1  ragge 
    126  1.1  ragge         epp->ep_taddr = execp->a_entry & ~(VAX1K_USRTEXT - 1);
    127  1.1  ragge 	epp->ep_tsize = execp->a_text + execp->a_data;
    128  1.1  ragge 	epp->ep_daddr = epp->ep_tsize + epp->ep_taddr;
    129  1.1  ragge 	epp->ep_dsize = execp->a_bss;
    130  1.1  ragge         epp->ep_entry = execp->a_entry;
    131  1.1  ragge 
    132  1.1  ragge         /* set up command for text segment */
    133  1.1  ragge         NEW_VMCMD(&epp->ep_vmcmds, vax1k_map_readvn,
    134  1.1  ragge 	    epp->ep_tsize,  epp->ep_taddr, epp->ep_vp, off,
    135  1.1  ragge 	    VM_PROT_WRITE|VM_PROT_READ|VM_PROT_EXECUTE);
    136  1.1  ragge 
    137  1.1  ragge 	tmp = round_page(epp->ep_daddr);
    138  1.1  ragge 	etmp = execp->a_bss - (tmp - epp->ep_daddr);
    139  1.1  ragge 
    140  1.1  ragge         /* set up command for bss segment */
    141  1.1  ragge 	if (etmp > 0)
    142  1.1  ragge 	        NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, etmp, tmp, NULLVP, 0,
    143  1.1  ragge 		    VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
    144  1.1  ragge 
    145  1.1  ragge         return exec_aout_setup_stack(p, epp);
    146  1.1  ragge }
    147