| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cpu_exec.c,v 1.50 2007/03/04 06:00:12 christos Exp $ */ | | 1 | /* $NetBSD: cpu_exec.c,v 1.51 2008/11/15 11:17:57 ad Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1992, 1993 | | 4 | * Copyright (c) 1992, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by Ralph | | 7 | * This code is derived from software contributed to Berkeley by Ralph |
8 | * Campbell. | | 8 | * Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -25,111 +25,105 @@ | | | @@ -25,111 +25,105 @@ |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | * | | 33 | * |
34 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 | | 34 | * @(#)machdep.c 8.3 (Berkeley) 1/12/94 |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <sys/cdefs.h> | | 37 | #include <sys/cdefs.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.50 2007/03/04 06:00:12 christos Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.51 2008/11/15 11:17:57 ad Exp $"); |
39 | | | 39 | |
40 | #include "opt_compat_netbsd.h" | | 40 | #include "opt_compat_netbsd.h" |
41 | #include "opt_compat_ultrix.h" | | 41 | #include "opt_compat_ultrix.h" |
42 | #include "opt_execfmt.h" | | 42 | #include "opt_execfmt.h" |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/systm.h> | | 45 | #include <sys/systm.h> |
46 | #include <sys/proc.h> | | 46 | #include <sys/proc.h> |
47 | #include <sys/malloc.h> | | 47 | #include <sys/malloc.h> |
48 | #include <sys/vnode.h> | | 48 | #include <sys/vnode.h> |
49 | #include <sys/exec.h> | | 49 | #include <sys/exec.h> |
50 | #include <sys/resourcevar.h> | | 50 | #include <sys/resourcevar.h> |
51 | | | 51 | |
52 | #include <uvm/uvm_extern.h> | | 52 | #include <uvm/uvm_extern.h> |
53 | | | 53 | |
54 | #ifdef EXEC_ECOFF | | 54 | #ifdef EXEC_ECOFF |
55 | #include <sys/exec_ecoff.h> | | 55 | #include <sys/exec_ecoff.h> |
56 | #endif | | 56 | #endif |
57 | #include <sys/exec_elf.h> /* mandatory */ | | 57 | #include <sys/exec_elf.h> /* mandatory */ |
58 | #ifdef COMPAT_09 | | | |
59 | #include <machine/bsd-aout.h> | | 58 | #include <machine/bsd-aout.h> |
60 | #endif | | | |
61 | #include <machine/reg.h> | | 59 | #include <machine/reg.h> |
62 | #include <mips/regnum.h> /* symbolic register indices */ | | 60 | #include <mips/regnum.h> /* symbolic register indices */ |
63 | | | 61 | |
64 | int mips_elf_makecmds(struct lwp *, struct exec_package *); | | 62 | int mips_elf_makecmds(struct lwp *, struct exec_package *); |
65 | | | 63 | |
66 | | | 64 | |
67 | /* | | 65 | /* |
68 | * cpu_exec_aout_makecmds(): | | 66 | * cpu_exec_aout_makecmds(): |
69 | * cpu-dependent a.out format hook for execve(). | | 67 | * cpu-dependent a.out format hook for execve(). |
70 | * | | 68 | * |
71 | * Determine of the given exec package refers to something which we | | 69 | * Determine of the given exec package refers to something which we |
72 | * understand and, if so, set up the vmcmds for it. | | 70 | * understand and, if so, set up the vmcmds for it. |
73 | * | | 71 | * |
74 | */ | | 72 | */ |
75 | int | | 73 | int |
76 | cpu_exec_aout_makecmds(l, epp) | | 74 | cpu_exec_aout_makecmds(l, epp) |
77 | struct lwp *l; | | 75 | struct lwp *l; |
78 | struct exec_package *epp; | | 76 | struct exec_package *epp; |
79 | { | | 77 | { |
80 | int error; | | 78 | int error; |
81 | | | 79 | |
82 | /* If COMPAT_09 is defined, allow loading of old-style 4.4bsd a.out | | 80 | /* If COMPAT_09 is defined, allow loading of old-style 4.4bsd a.out |
83 | executables. */ | | 81 | executables. */ |
84 | #ifdef COMPAT_09 | | | |
85 | struct bsd_aouthdr *hdr = (struct bsd_aouthdr *)epp->ep_hdr; | | 82 | struct bsd_aouthdr *hdr = (struct bsd_aouthdr *)epp->ep_hdr; |
86 | | | 83 | |
87 | /* Only handle paged files (laziness). */ | | 84 | /* Only handle paged files (laziness). */ |
88 | if (hdr->a_magic != BSD_ZMAGIC) | | 85 | if (hdr->a_magic != BSD_ZMAGIC) |
89 | #endif | | | |
90 | { | | 86 | { |
91 | /* If that failed, try old NetBSD-1.1 elf format */ | | 87 | /* If that failed, try old NetBSD-1.1 elf format */ |
92 | error = mips_elf_makecmds (l, epp); | | 88 | error = mips_elf_makecmds (l, epp); |
93 | return error; | | 89 | return error; |
94 | } | | 90 | } |
95 | | | 91 | |
96 | #ifdef COMPAT_09 | | | |
97 | error = vn_marktext(epp->ep_vp); | | 92 | error = vn_marktext(epp->ep_vp); |
98 | if (error) | | 93 | if (error) |
99 | return (error); | | 94 | return (error); |
100 | | | 95 | |
101 | epp->ep_taddr = 0x1000; | | 96 | epp->ep_taddr = 0x1000; |
102 | epp->ep_entry = hdr->a_entry; | | 97 | epp->ep_entry = hdr->a_entry; |
103 | epp->ep_tsize = hdr->a_text; | | 98 | epp->ep_tsize = hdr->a_text; |
104 | epp->ep_daddr = epp->ep_taddr + hdr->a_text; | | 99 | epp->ep_daddr = epp->ep_taddr + hdr->a_text; |
105 | epp->ep_dsize = hdr->a_data + hdr->a_bss; | | 100 | epp->ep_dsize = hdr->a_data + hdr->a_bss; |
106 | | | 101 | |
107 | /* set up command for text segment */ | | 102 | /* set up command for text segment */ |
108 | NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_pagedvn, hdr->a_text, | | 103 | NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_pagedvn, hdr->a_text, |
109 | epp->ep_taddr, epp->ep_vp, 0, VM_PROT_READ|VM_PROT_EXECUTE); | | 104 | epp->ep_taddr, epp->ep_vp, 0, VM_PROT_READ|VM_PROT_EXECUTE); |
110 | | | 105 | |
111 | /* set up command for data segment */ | | 106 | /* set up command for data segment */ |
112 | NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_pagedvn, hdr->a_data, | | 107 | NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_pagedvn, hdr->a_data, |
113 | epp->ep_daddr, epp->ep_vp, hdr->a_text, | | 108 | epp->ep_daddr, epp->ep_vp, hdr->a_text, |
114 | VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); | | 109 | VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); |
115 | | | 110 | |
116 | /* set up command for bss segment */ | | 111 | /* set up command for bss segment */ |
117 | NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, hdr->a_bss, | | 112 | NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, hdr->a_bss, |
118 | epp->ep_daddr + hdr->a_data, NULLVP, 0, | | 113 | epp->ep_daddr + hdr->a_data, NULLVP, 0, |
119 | VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); | | 114 | VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); |
120 | | | 115 | |
121 | return (*epp->ep_esch->ep_setup_stack)(p, epp); | | 116 | return (*epp->ep_esch->ep_setup_stack)(p, epp); |
122 | #endif | | | |
123 | } | | 117 | } |
124 | | | 118 | |
125 | #ifdef EXEC_ECOFF | | 119 | #ifdef EXEC_ECOFF |
126 | void | | 120 | void |
127 | cpu_exec_ecoff_setregs(l, epp, stack) | | 121 | cpu_exec_ecoff_setregs(l, epp, stack) |
128 | struct lwp *l; | | 122 | struct lwp *l; |
129 | struct exec_package *epp; | | 123 | struct exec_package *epp; |
130 | u_long stack; | | 124 | u_long stack; |
131 | { | | 125 | { |
132 | struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr; | | 126 | struct ecoff_exechdr *execp = (struct ecoff_exechdr *)epp->ep_hdr; |
133 | struct frame *f = (struct frame *)l->l_md.md_regs; | | 127 | struct frame *f = (struct frame *)l->l_md.md_regs; |
134 | | | 128 | |
135 | f->f_regs[_R_GP] = (register_t)execp->a.gp_value; | | 129 | f->f_regs[_R_GP] = (register_t)execp->a.gp_value; |