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