elf64_freebsd.c revision 39960
14Srgrimes/*-
24Srgrimes * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3295Sjtc * All rights reserved.
44Srgrimes *
5295Sjtc * Redistribution and use in source and binary forms, with or without
6295Sjtc * modification, are permitted provided that the following conditions
7468Sjtc * are met:
84Srgrimes * 1. Redistributions of source code must retain the above copyright
9468Sjtc *    notice, this list of conditions and the following disclaimer.
104Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
114Srgrimes *    notice, this list of conditions and the following disclaimer in the
124Srgrimes *    documentation and/or other materials provided with the distribution.
13468Sjtc *
144Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15295Sjtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1631Salm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2031Salm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244Srgrimes * SUCH DAMAGE.
254Srgrimes *
264Srgrimes *	$Id: elf_freebsd.c,v 1.4 1998/10/04 09:12:15 msmith Exp $
2731Salm */
284Srgrimes
294Srgrimes#include <sys/param.h>
304Srgrimes#include <sys/exec.h>
314Srgrimes#include <sys/reboot.h>
324Srgrimes#include <sys/linker.h>
334Srgrimes#include <string.h>
344Srgrimes#include <machine/bootinfo.h>
354Srgrimes#include <machine/elf.h>
364Srgrimes#include <stand.h>
374Srgrimes
384Srgrimes#include "bootstrap.h"
394Srgrimes#include "libi386.h"
404Srgrimes#include "btxv86.h"
414Srgrimes
424Srgrimesstatic int	elf_exec(struct loaded_module *amp);
434Srgrimes
444Srgrimesstruct module_format i386_elf = { elf_loadmodule, elf_exec };
454Srgrimes
464Srgrimesstatic struct bootinfo	bi;
474Srgrimes
484Srgrimes/*
494Srgrimes * There is an a.out kernel and one or more a.out modules loaded.
504Srgrimes * We wish to start executing the kernel image, so make such
514Srgrimes * preparations as are required, and do so.
524Srgrimes */
534Srgrimesstatic int
544Srgrimeself_exec(struct loaded_module *mp)
554Srgrimes{
564Srgrimes    struct module_metadata	*md;
574Srgrimes    Elf_Ehdr 			*ehdr;
584Srgrimes    vm_offset_t			entry, bootinfop;
594Srgrimes    int				boothowto, err, bootdev;
604Srgrimes    struct bootinfo		*bi;
614Srgrimes    vm_offset_t			ssym, esym;
624Srgrimes
634Srgrimes    if ((md = mod_findmetadata(mp, MODINFOMD_ELFHDR)) == NULL)
644Srgrimes	return(EFTYPE);			/* XXX actually EFUCKUP */
654Srgrimes    ehdr = (Elf_Ehdr *)&(md->md_data);
664Srgrimes
674Srgrimes    /* XXX allow override? */
684Srgrimes    setenv("kernelname", mp->m_name, 1);
694Srgrimes
704Srgrimes    if ((err = bi_load(mp->m_args, &boothowto, &bootdev, &bootinfop)) != 0)
714Srgrimes	return(err);
724Srgrimes    entry = ehdr->e_entry & 0xffffff;
734Srgrimes
744Srgrimes    ssym = esym = 0;
754Srgrimes#if 0 /* XXX something wrong with the symbol tables */
764Srgrimes    if ((md = mod_findmetadata(mp, MODINFOMD_ELFSSYM)) != NULL)
774Srgrimes	ssym = *((vm_offset_t *)&(md->md_data));
784Srgrimes    if ((md = mod_findmetadata(mp, MODINFOMD_ELFESYM)) != NULL)
794Srgrimes	esym = *((vm_offset_t *)&(md->md_data));
804Srgrimes    if (ssym == 0 || esym == 0)
814Srgrimes	ssym = esym = 0;		/* sanity */
824Srgrimes#endif
834Srgrimes    bi = (struct bootinfo *)PTOV(bootinfop);
844Srgrimes    bi->bi_symtab = ssym;
854Srgrimes    bi->bi_esymtab = esym;
864Srgrimes
874Srgrimes
884Srgrimes#ifdef DEBUG
894Srgrimes    printf("Start @ 0x%lx ...\n", entry);
904Srgrimes#endif
914Srgrimes
924Srgrimes    __exec((void *)entry, boothowto, bootdev, 0, 0, 0, bootinfop);
934Srgrimes
944Srgrimes    panic("exec returned");
954Srgrimes}
964Srgrimes