exec_mvme.c revision 1.8 1 /* $NetBSD: exec_mvme.c,v 1.8 2000/07/24 09:25:53 scw Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1990, 1993
5 * The Regents of the University of California. 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 the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)boot.c 8.1 (Berkeley) 6/10/93
36 */
37
38 #include <sys/param.h>
39 #include <sys/reboot.h>
40 #include <machine/prom.h>
41 #include <sys/exec_aout.h>
42
43 #include "stand.h"
44 #include "libsa.h"
45
46
47 /* This must agree with what locore.s expects */
48 typedef void (*kentry_t)(int, u_int, u_int, u_int, int, char *);
49
50
51 /*ARGSUSED*/
52 void
53 exec_mvme(file, flag, part)
54 char *file;
55 int flag;
56 int part;
57 {
58 char *loadaddr;
59 int io;
60 struct exec x;
61 int cc, magic;
62 kentry_t *entry;
63 char *cp;
64 int *ip;
65
66 #ifdef DEBUG
67 printf("exec_mvme: partition=%d, file=%s flag=0x%x\n", part, file, flag);
68 #endif
69
70 io = open(file, 0);
71 if (io < 0)
72 return;
73
74 /*
75 * Read in the exec header, and validate it.
76 */
77 if (read(io, (void *)&x, sizeof(x)) != sizeof(x))
78 goto shread;
79 if (N_BADMAG(x)) {
80 errno = EFTYPE;
81 goto closeout;
82 }
83
84 /*
85 * note: on the mvme ports, the kernel is linked in such a way that
86 * its entry point is the first item in .text, and thus a_entry can
87 * be used to determine both the load address and the entry point.
88 * (also note that we make use of the fact that the kernel will live
89 * in a VA == PA range of memory ... otherwise we would take
90 * loadaddr as a parameter and let the kernel relocate itself!)
91 *
92 * note that ZMAGIC files included the a.out header in the text area
93 * so we must mask that off (has no effect on the other formats
94 */
95 loadaddr = (void *)(x.a_entry & ~sizeof(x));
96
97 cp = loadaddr;
98 magic = (int)N_GETMAGIC(x);
99 if (magic == ZMAGIC)
100 cp += sizeof(x);
101 /*LINTED*/
102 entry = (kentry_t *) cp;
103
104 /*
105 * Leave a copy of the exec header before the text.
106 * The sun3 kernel uses this to verify that the
107 * symbols were loaded by this boot program.
108 */
109 bcopy(&x, cp - sizeof(x), sizeof(x));
110
111 /*
112 * Read in the text segment.
113 */
114 printf("%ld", x.a_text);
115 cc = (int)x.a_text;
116 if (magic == ZMAGIC)
117 cc = cc - sizeof(x); /* a.out header part of text in zmagic */
118 if (read(io, cp, (size_t)cc) != (size_t)cc)
119 goto shread;
120 cp += cc;
121
122 /*
123 * NMAGIC may have a gap between text and data.
124 */
125 if (magic == NMAGIC) {
126 int mask = N_PAGSIZ(x) - 1;
127 /*LINTED*/
128 while ((int)cp & mask)
129 *cp++ = 0;
130 }
131
132 /*
133 * Read in the data segment.
134 */
135 printf("+%ld", x.a_data);
136 if (read(io, cp, (size_t)x.a_data) != (size_t)x.a_data)
137 goto shread;
138 cp += (int)x.a_data;
139
140 /*
141 * Zero out the BSS section.
142 * (Kernel doesn't care, but do it anyway.)
143 */
144 printf("+%ld", x.a_bss);
145 cc = (int)x.a_bss;
146 /*LINTED*/
147 while ((int)cp & 3) {
148 *cp++ = 0;
149 --cc;
150 }
151 /*LINTED*/
152 ip = (int*)cp;
153 cp += cc;
154 /*LINTED*/
155 while ((char*)ip < cp)
156 *ip++ = 0;
157
158 /*
159 * Read in the symbol table and strings.
160 * (Always set the symtab size word.)
161 */
162 *ip++ = (int)x.a_syms;
163 /*LINTED*/
164 cp = (char*) ip;
165
166 if (x.a_syms > 0 && (flag & RB_NOSYM) == 0) {
167
168 /* Symbol table and string table length word. */
169 cc = (int)x.a_syms;
170 printf("+[%d", cc);
171 cc += sizeof(int); /* strtab length too */
172 if (read(io, cp, (size_t)cc) != (size_t)cc)
173 goto shread;
174 cp += (int)x.a_syms;
175 /*LINTED*/
176 ip = (int*)cp; /* points to strtab length */
177 cp += sizeof(int);
178
179 /* String table. Length word includes itself. */
180 cc = *ip;
181 printf("+%d]", cc);
182 cc -= sizeof(int);
183 if (cc <= 0)
184 goto shread;
185 if (read(io, cp, (size_t)cc) != (size_t)cc)
186 goto shread;
187 cp += cc;
188 }
189 printf("=0x%x\n", cp - loadaddr);
190 close(io);
191
192 printf("Start @ 0x%p ...\n", entry);
193 (*entry)(flag, bugargs.ctrl_addr,
194 bugargs.ctrl_lun, bugargs.dev_lun, part, cp);
195 printf("exec: kernel returned!\n");
196 return;
197
198 shread:
199 printf("exec: short read\n");
200 errno = EIO;
201 closeout:
202 close(io);
203 return;
204 }
205