Home | History | Annotate | Line # | Download | only in libsa
loadfile_ecoff.c revision 1.1
      1 /* $NetBSD: loadfile_ecoff.c,v 1.1 2001/10/30 23:51:03 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      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.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     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.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1992, 1993
     42  *	The Regents of the University of California.  All rights reserved.
     43  *
     44  * This code is derived from software contributed to Berkeley by
     45  * Ralph Campbell.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. All advertising materials mentioning features or use of this software
     56  *    must display the following acknowledgement:
     57  *	This product includes software developed by the University of
     58  *	California, Berkeley and its contributors.
     59  * 4. Neither the name of the University nor the names of its contributors
     60  *    may be used to endorse or promote products derived from this software
     61  *    without specific prior written permission.
     62  *
     63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  * SUCH DAMAGE.
     74  *
     75  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
     76  */
     77 
     78 static int
     79 coff_exec(fd, coff, marks, flags)
     80 	int fd;
     81 	struct ecoff_exechdr *coff;
     82 	u_long *marks;
     83 	int flags;
     84 {
     85 	paddr_t offset = marks[MARK_START];
     86 	paddr_t minp = ~0, maxp = 0, pos;
     87 
     88 	/* Read in text. */
     89 	if (lseek(fd, ECOFF_TXTOFF(coff), SEEK_SET) == -1)  {
     90 		WARN(("lseek text"));
     91 		return 1;
     92 	}
     93 
     94 	if (coff->a.tsize != 0) {
     95 		if (flags & LOAD_TEXT) {
     96 			PROGRESS(("%lu", coff->a.tsize));
     97 			if (READ(fd, coff->a.text_start, coff->a.tsize) !=
     98 			    coff->a.tsize) {
     99 				return 1;
    100 			}
    101 		}
    102 		else {
    103 			if (lseek(fd, coff->a.tsize, SEEK_CUR) == -1) {
    104 				WARN(("read text"));
    105 				return 1;
    106 			}
    107 		}
    108 		if (flags & (COUNT_TEXT|LOAD_TEXT)) {
    109 			pos = coff->a.text_start;
    110 			if (minp > pos)
    111 				minp = pos;
    112 			pos += coff->a.tsize;
    113 			if (maxp < pos)
    114 				maxp = pos;
    115 		}
    116 	}
    117 
    118 	/* Read in data. */
    119 	if (coff->a.dsize != 0) {
    120 		if (flags & LOAD_DATA) {
    121 			PROGRESS(("+%lu", coff->a.dsize));
    122 			if (READ(fd, coff->a.data_start, coff->a.dsize) !=
    123 			    coff->a.dsize) {
    124 				WARN(("read data"));
    125 				return 1;
    126 			}
    127 		}
    128 		if (flags & (COUNT_DATA|LOAD_DATA)) {
    129 			pos = coff->a.data_start;
    130 			if (minp > pos)
    131 				minp = pos;
    132 			pos += coff->a.dsize;
    133 			if (maxp < pos)
    134 				maxp = pos;
    135 		}
    136 	}
    137 
    138 	/* Zero out bss. */
    139 	if (coff->a.bsize != 0) {
    140 		if (flags & LOAD_BSS) {
    141 			PROGRESS(("+%lu", coff->a.bsize));
    142 			BZERO(coff->a.bss_start, coff->a.bsize);
    143 		}
    144 		if (flags & (COUNT_BSS|LOAD_BSS)) {
    145 			pos = coff->a.bss_start;
    146 			if (minp > pos)
    147 				minp = pos;
    148 			pos = coff->a.bsize;
    149 			if (maxp < pos)
    150 				maxp = pos;
    151 		}
    152 	}
    153 
    154 	marks[MARK_START] = LOADADDR(minp);
    155 	marks[MARK_ENTRY] = LOADADDR(coff->a.entry);
    156 	marks[MARK_NSYM] = 1;	/* XXX: Kernel needs >= 0 */
    157 	marks[MARK_SYM] = LOADADDR(maxp);
    158 	marks[MARK_END] = LOADADDR(maxp);
    159 	return 0;
    160 }
    161