exec_mvme.c revision 1.9 1 1.9 jdolecek /* $NetBSD: exec_mvme.c,v 1.9 2000/07/24 18:39:46 jdolecek 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.8 scw
46 1.8 scw /* This must agree with what locore.s expects */
47 1.8 scw typedef void (*kentry_t)(int, u_int, u_int, u_int, int, char *);
48 1.8 scw
49 1.8 scw
50 1.1 chuck /*ARGSUSED*/
51 1.1 chuck void
52 1.8 scw exec_mvme(file, flag, part)
53 1.1 chuck char *file;
54 1.1 chuck int flag;
55 1.8 scw int part;
56 1.1 chuck {
57 1.1 chuck char *loadaddr;
58 1.5 scw int io;
59 1.1 chuck struct exec x;
60 1.1 chuck int cc, magic;
61 1.8 scw kentry_t *entry;
62 1.5 scw char *cp;
63 1.5 scw int *ip;
64 1.1 chuck
65 1.1 chuck #ifdef DEBUG
66 1.8 scw printf("exec_mvme: partition=%d, file=%s flag=0x%x\n", part, file, flag);
67 1.1 chuck #endif
68 1.1 chuck
69 1.1 chuck io = open(file, 0);
70 1.1 chuck if (io < 0)
71 1.1 chuck return;
72 1.1 chuck
73 1.1 chuck /*
74 1.1 chuck * Read in the exec header, and validate it.
75 1.1 chuck */
76 1.4 scw if (read(io, (void *)&x, sizeof(x)) != sizeof(x))
77 1.1 chuck goto shread;
78 1.1 chuck if (N_BADMAG(x)) {
79 1.1 chuck errno = EFTYPE;
80 1.1 chuck goto closeout;
81 1.1 chuck }
82 1.1 chuck
83 1.1 chuck /*
84 1.1 chuck * note: on the mvme ports, the kernel is linked in such a way that
85 1.1 chuck * its entry point is the first item in .text, and thus a_entry can
86 1.1 chuck * be used to determine both the load address and the entry point.
87 1.1 chuck * (also note that we make use of the fact that the kernel will live
88 1.1 chuck * in a VA == PA range of memory ... otherwise we would take
89 1.1 chuck * loadaddr as a parameter and let the kernel relocate itself!)
90 1.1 chuck *
91 1.1 chuck * note that ZMAGIC files included the a.out header in the text area
92 1.1 chuck * so we must mask that off (has no effect on the other formats
93 1.1 chuck */
94 1.1 chuck loadaddr = (void *)(x.a_entry & ~sizeof(x));
95 1.1 chuck
96 1.1 chuck cp = loadaddr;
97 1.4 scw magic = (int)N_GETMAGIC(x);
98 1.1 chuck if (magic == ZMAGIC)
99 1.1 chuck cp += sizeof(x);
100 1.4 scw /*LINTED*/
101 1.8 scw entry = (kentry_t *) cp;
102 1.1 chuck
103 1.1 chuck /*
104 1.1 chuck * Leave a copy of the exec header before the text.
105 1.1 chuck * The sun3 kernel uses this to verify that the
106 1.1 chuck * symbols were loaded by this boot program.
107 1.1 chuck */
108 1.1 chuck bcopy(&x, cp - sizeof(x), sizeof(x));
109 1.1 chuck
110 1.1 chuck /*
111 1.1 chuck * Read in the text segment.
112 1.1 chuck */
113 1.7 jdolecek printf("%ld", x.a_text);
114 1.4 scw cc = (int)x.a_text;
115 1.1 chuck if (magic == ZMAGIC)
116 1.1 chuck cc = cc - sizeof(x); /* a.out header part of text in zmagic */
117 1.4 scw if (read(io, cp, (size_t)cc) != (size_t)cc)
118 1.1 chuck goto shread;
119 1.1 chuck cp += cc;
120 1.1 chuck
121 1.1 chuck /*
122 1.1 chuck * NMAGIC may have a gap between text and data.
123 1.1 chuck */
124 1.1 chuck if (magic == NMAGIC) {
125 1.4 scw int mask = N_PAGSIZ(x) - 1;
126 1.4 scw /*LINTED*/
127 1.1 chuck while ((int)cp & mask)
128 1.1 chuck *cp++ = 0;
129 1.1 chuck }
130 1.1 chuck
131 1.1 chuck /*
132 1.1 chuck * Read in the data segment.
133 1.1 chuck */
134 1.7 jdolecek printf("+%ld", x.a_data);
135 1.4 scw if (read(io, cp, (size_t)x.a_data) != (size_t)x.a_data)
136 1.1 chuck goto shread;
137 1.4 scw cp += (int)x.a_data;
138 1.1 chuck
139 1.1 chuck /*
140 1.1 chuck * Zero out the BSS section.
141 1.1 chuck * (Kernel doesn't care, but do it anyway.)
142 1.1 chuck */
143 1.7 jdolecek printf("+%ld", x.a_bss);
144 1.4 scw cc = (int)x.a_bss;
145 1.4 scw /*LINTED*/
146 1.1 chuck while ((int)cp & 3) {
147 1.1 chuck *cp++ = 0;
148 1.1 chuck --cc;
149 1.1 chuck }
150 1.4 scw /*LINTED*/
151 1.1 chuck ip = (int*)cp;
152 1.1 chuck cp += cc;
153 1.4 scw /*LINTED*/
154 1.1 chuck while ((char*)ip < cp)
155 1.1 chuck *ip++ = 0;
156 1.1 chuck
157 1.1 chuck /*
158 1.1 chuck * Read in the symbol table and strings.
159 1.1 chuck * (Always set the symtab size word.)
160 1.1 chuck */
161 1.4 scw *ip++ = (int)x.a_syms;
162 1.4 scw /*LINTED*/
163 1.1 chuck cp = (char*) ip;
164 1.1 chuck
165 1.1 chuck if (x.a_syms > 0 && (flag & RB_NOSYM) == 0) {
166 1.1 chuck
167 1.1 chuck /* Symbol table and string table length word. */
168 1.4 scw cc = (int)x.a_syms;
169 1.1 chuck printf("+[%d", cc);
170 1.1 chuck cc += sizeof(int); /* strtab length too */
171 1.4 scw if (read(io, cp, (size_t)cc) != (size_t)cc)
172 1.1 chuck goto shread;
173 1.4 scw cp += (int)x.a_syms;
174 1.4 scw /*LINTED*/
175 1.1 chuck ip = (int*)cp; /* points to strtab length */
176 1.1 chuck cp += sizeof(int);
177 1.1 chuck
178 1.1 chuck /* String table. Length word includes itself. */
179 1.1 chuck cc = *ip;
180 1.1 chuck printf("+%d]", cc);
181 1.1 chuck cc -= sizeof(int);
182 1.1 chuck if (cc <= 0)
183 1.1 chuck goto shread;
184 1.4 scw if (read(io, cp, (size_t)cc) != (size_t)cc)
185 1.1 chuck goto shread;
186 1.1 chuck cp += cc;
187 1.1 chuck }
188 1.1 chuck printf("=0x%x\n", cp - loadaddr);
189 1.1 chuck close(io);
190 1.1 chuck
191 1.4 scw printf("Start @ 0x%p ...\n", entry);
192 1.2 chuck (*entry)(flag, bugargs.ctrl_addr,
193 1.8 scw bugargs.ctrl_lun, bugargs.dev_lun, part, cp);
194 1.1 chuck printf("exec: kernel returned!\n");
195 1.1 chuck return;
196 1.1 chuck
197 1.1 chuck shread:
198 1.1 chuck printf("exec: short read\n");
199 1.1 chuck errno = EIO;
200 1.1 chuck closeout:
201 1.1 chuck close(io);
202 1.1 chuck return;
203 1.1 chuck }
204