1 /* $NetBSD: loadfile_ecoff.c,v 1.12 2008/04/28 20:24:06 martin Exp $ */
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center and by Christos Zoulas.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 #include <lib/libsa/stand.h>
35 #include <lib/libkern/libkern.h>
46 #include <sys/param.h>
54 loadfile_coff(int fd
, struct ecoff_exechdr
*coff
, u_long
*marks
, int flags
)
56 paddr_t offset
= marks
[MARK_START
];
57 paddr_t minp
= ~0, maxp
= 0, pos
;
60 /* some ports dont use the offset */
64 if (lseek(fd
, ECOFF_TXTOFF(coff
), SEEK_SET
) == -1) {
69 if (coff
->a
.tsize
!= 0) {
70 if (flags
& LOAD_TEXT
) {
71 PROGRESS(("%lu", coff
->a
.tsize
));
72 nr
= READ(fd
, coff
->a
.text_start
, coff
->a
.tsize
);
76 if (nr
!= coff
->a
.tsize
) {
82 if (lseek(fd
, coff
->a
.tsize
, SEEK_CUR
) == -1) {
87 if (flags
& (COUNT_TEXT
|LOAD_TEXT
)) {
88 pos
= coff
->a
.text_start
;
98 if (coff
->a
.dsize
!= 0) {
99 if (flags
& LOAD_DATA
) {
100 PROGRESS(("+%lu", coff
->a
.dsize
));
101 nr
= READ(fd
, coff
->a
.data_start
, coff
->a
.dsize
);
106 if (nr
!= coff
->a
.dsize
) {
112 if (flags
& (COUNT_DATA
|LOAD_DATA
)) {
113 pos
= coff
->a
.data_start
;
116 pos
+= coff
->a
.dsize
;
123 if (coff
->a
.bsize
!= 0) {
124 if (flags
& LOAD_BSS
) {
125 PROGRESS(("+%lu", coff
->a
.bsize
));
126 BZERO(coff
->a
.bss_start
, coff
->a
.bsize
);
128 if (flags
& (COUNT_BSS
|LOAD_BSS
)) {
129 pos
= coff
->a
.bss_start
;
138 marks
[MARK_START
] = LOADADDR(minp
);
139 marks
[MARK_ENTRY
] = LOADADDR(coff
->a
.entry
);
140 marks
[MARK_NSYM
] = 1; /* XXX: Kernel needs >= 0 */
141 marks
[MARK_SYM
] = LOADADDR(maxp
);
142 marks
[MARK_END
] = LOADADDR(maxp
);
143 marks
[MARK_DATA
] = LOADADDR(coff
->a
.data_start
);
147 #endif /* BOOT_ECOFF */