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