elf32_freebsd.c revision 119482
1290569Sdelphij/*-
2166255Sdelphij * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3166255Sdelphij * All rights reserved.
4166255Sdelphij *
5166255Sdelphij * Redistribution and use in source and binary forms, with or without
6166255Sdelphij * modification, are permitted provided that the following conditions
7166255Sdelphij * are met:
8166255Sdelphij * 1. Redistributions of source code must retain the above copyright
9166255Sdelphij *    notice, this list of conditions and the following disclaimer.
10166255Sdelphij * 2. Redistributions in binary form must reproduce the above copyright
11166255Sdelphij *    notice, this list of conditions and the following disclaimer in the
12166255Sdelphij *    documentation and/or other materials provided with the distribution.
13166255Sdelphij *
14166255Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15166255Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16166255Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17166255Sdelphij * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18166255Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19166255Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20166255Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21166255Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22166255Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23166255Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24166255Sdelphij * SUCH DAMAGE.
25166255Sdelphij */
26166255Sdelphij
27166255Sdelphij#include <sys/cdefs.h>
28290569Sdelphij__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/elf32_freebsd.c 119482 2003-08-25 23:28:32Z obrien $");
29166255Sdelphij
30166255Sdelphij#include <sys/param.h>
31166255Sdelphij#include <sys/exec.h>
32166255Sdelphij#include <sys/linker.h>
33166255Sdelphij#include <string.h>
34166255Sdelphij#include <machine/bootinfo.h>
35166255Sdelphij#include <machine/elf.h>
36170053Sdelphij#include <stand.h>
37166255Sdelphij
38166255Sdelphij#include "bootstrap.h"
39166255Sdelphij#include "libi386.h"
40166255Sdelphij#include "btxv86.h"
41166255Sdelphij
42166255Sdelphijstatic int	elf32_exec(struct preloaded_file *amp);
43166255Sdelphij
44170357Sdelphijstruct file_format i386_elf = { elf32_loadfile, elf32_exec };
45166255Sdelphij
46166255Sdelphij/*
47166255Sdelphij * There is an a.out kernel and one or more a.out modules loaded.
48166255Sdelphij * We wish to start executing the kernel image, so make such
49166255Sdelphij * preparations as are required, and do so.
50166255Sdelphij */
51166255Sdelphijstatic int
52166255Sdelphijelf32_exec(struct preloaded_file *fp)
53166255Sdelphij{
54166255Sdelphij    struct file_metadata	*md;
55166255Sdelphij    Elf_Ehdr 			*ehdr;
56166255Sdelphij    vm_offset_t			entry, bootinfop, modulep, kernend;
57166255Sdelphij    int				boothowto, err, bootdev;
58166255Sdelphij
59166255Sdelphij    if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
60166255Sdelphij	return(EFTYPE);			/* XXX actually EFUCKUP */
61166255Sdelphij    ehdr = (Elf_Ehdr *)&(md->md_data);
62166255Sdelphij
63166255Sdelphij    err = bi_load32(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend);
64166255Sdelphij    if (err != 0)
65166255Sdelphij	return(err);
66166255Sdelphij    entry = ehdr->e_entry & 0xffffff;
67166255Sdelphij
68166255Sdelphij#ifdef DEBUG
69166255Sdelphij    printf("Start @ 0x%lx ...\n", entry);
70166255Sdelphij#endif
71166255Sdelphij
72166255Sdelphij    dev_cleanup();
73180126Sdelphij    __exec((void *)entry, boothowto, bootdev, 0, 0, 0, bootinfop, modulep, kernend);
74166255Sdelphij
75166255Sdelphij    panic("exec returned");
76166255Sdelphij}
77166255Sdelphij