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