xref: /netbsd-src/sys/arch/hppa/stand/common/exec_som.c (revision 6d3ceb1d619615401b17c9aa3e4bc674a1cb048b)
1*6d3ceb1dSskrll /*	$NetBSD: exec_som.c,v 1.1 2014/02/24 07:23:43 skrll Exp $	*/
2*6d3ceb1dSskrll 
3*6d3ceb1dSskrll /*	$OpenBSD: exec_som.c,v 1.1 1999/12/23 04:10:30 mickey Exp $	*/
4*6d3ceb1dSskrll 
5*6d3ceb1dSskrll /*
6*6d3ceb1dSskrll  * Copyright (c) 1999 Michael Shalayeff
7*6d3ceb1dSskrll  * All rights reserved.
8*6d3ceb1dSskrll  *
9*6d3ceb1dSskrll  * Redistribution and use in source and binary forms, with or without
10*6d3ceb1dSskrll  * modification, are permitted provided that the following conditions
11*6d3ceb1dSskrll  * are met:
12*6d3ceb1dSskrll  * 1. Redistributions of source code must retain the above copyright
13*6d3ceb1dSskrll  *    notice, this list of conditions and the following disclaimer.
14*6d3ceb1dSskrll  * 2. Redistributions in binary form must reproduce the above copyright
15*6d3ceb1dSskrll  *    notice, this list of conditions and the following disclaimer in the
16*6d3ceb1dSskrll  *    documentation and/or other materials provided with the distribution.
17*6d3ceb1dSskrll  *
18*6d3ceb1dSskrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*6d3ceb1dSskrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*6d3ceb1dSskrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*6d3ceb1dSskrll  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22*6d3ceb1dSskrll  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23*6d3ceb1dSskrll  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24*6d3ceb1dSskrll  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*6d3ceb1dSskrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26*6d3ceb1dSskrll  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27*6d3ceb1dSskrll  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28*6d3ceb1dSskrll  * THE POSSIBILITY OF SUCH DAMAGE.
29*6d3ceb1dSskrll  */
30*6d3ceb1dSskrll 
31*6d3ceb1dSskrll 
32*6d3ceb1dSskrll #include <sys/param.h>
33*6d3ceb1dSskrll #include "libsa.h"
34*6d3ceb1dSskrll #include <machine/exec.h>
35*6d3ceb1dSskrll #include <lib/libsa/exec.h>
36*6d3ceb1dSskrll 
37*6d3ceb1dSskrll int
som_probe(int fd,union x_header * hdr)38*6d3ceb1dSskrll som_probe(int fd, union x_header *hdr)
39*6d3ceb1dSskrll {
40*6d3ceb1dSskrll 	return !SOM_BADMAGIC(&hdr->x_som);
41*6d3ceb1dSskrll }
42*6d3ceb1dSskrll 
43*6d3ceb1dSskrll 
44*6d3ceb1dSskrll int
som_load(int fd,struct x_param * xp)45*6d3ceb1dSskrll som_load(int fd, struct x_param *xp)
46*6d3ceb1dSskrll {
47*6d3ceb1dSskrll 	struct som_filehdr *xf = &xp->xp_hdr->x_som;
48*6d3ceb1dSskrll 	struct som_exec_aux x;
49*6d3ceb1dSskrll 
50*6d3ceb1dSskrll 	if (lseek(fd, xf->aux_loc, SEEK_SET) < 0 ||
51*6d3ceb1dSskrll 	    read (fd, &x, sizeof(x)) != sizeof(x)) {
52*6d3ceb1dSskrll 		if (!errno)
53*6d3ceb1dSskrll 			errno = EIO;
54*6d3ceb1dSskrll 		return -1;
55*6d3ceb1dSskrll 	}
56*6d3ceb1dSskrll 
57*6d3ceb1dSskrll 	xp->xp_entry = x.a_entry;
58*6d3ceb1dSskrll 
59*6d3ceb1dSskrll 	xp->text.size = round_page(x.a_tsize);
60*6d3ceb1dSskrll 	xp->data.size = round_page(x.a_dsize);
61*6d3ceb1dSskrll 	xp->bss.size = x.a_bsize;
62*6d3ceb1dSskrll 	xp->sym.size = xf->sym_total * sizeof(struct som_sym);
63*6d3ceb1dSskrll 	xp->str.size = xf->strings_size;
64*6d3ceb1dSskrll 
65*6d3ceb1dSskrll 	xp->text.foff = x.a_tfile;
66*6d3ceb1dSskrll 	xp->data.foff = x.a_dfile;
67*6d3ceb1dSskrll 	xp->bss.foff = 0;
68*6d3ceb1dSskrll 	if (xf->sym_total) {
69*6d3ceb1dSskrll 		xp->sym.foff = xf->sym_loc;
70*6d3ceb1dSskrll 		xp->str.foff = xf->strings_loc;
71*6d3ceb1dSskrll 	}
72*6d3ceb1dSskrll 
73*6d3ceb1dSskrll 	xp->text.addr = x.a_tmem;
74*6d3ceb1dSskrll 	xp->data.addr = x.a_dmem;
75*6d3ceb1dSskrll 	xp->bss.addr = xp->data.addr + x.a_dsize;
76*6d3ceb1dSskrll 	xp->sym.addr = xp->bss.addr + xp->bss.size;
77*6d3ceb1dSskrll 	xp->str.addr = xp->sym.addr + xp->sym.size;
78*6d3ceb1dSskrll 
79*6d3ceb1dSskrll 	return 0;
80*6d3ceb1dSskrll }
81*6d3ceb1dSskrll 
82*6d3ceb1dSskrll int
som_ldsym(int fd,struct x_param * xp)83*6d3ceb1dSskrll som_ldsym(int fd, struct x_param *xp)
84*6d3ceb1dSskrll {
85*6d3ceb1dSskrll 	return -1;
86*6d3ceb1dSskrll }
87