elf32_freebsd.c revision 114379
139833Speter/*- 239833Speter * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 339833Speter * All rights reserved. 439833Speter * 539833Speter * Redistribution and use in source and binary forms, with or without 639833Speter * modification, are permitted provided that the following conditions 739833Speter * are met: 839833Speter * 1. Redistributions of source code must retain the above copyright 939833Speter * notice, this list of conditions and the following disclaimer. 1039833Speter * 2. Redistributions in binary form must reproduce the above copyright 1139833Speter * notice, this list of conditions and the following disclaimer in the 1239833Speter * documentation and/or other materials provided with the distribution. 1339833Speter * 1439833Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1539833Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1639833Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1739833Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1839833Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1939833Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2039833Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2139833Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2239833Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2339833Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2439833Speter * SUCH DAMAGE. 2539833Speter * 2650477Speter * $FreeBSD: head/sys/boot/i386/libi386/elf32_freebsd.c 114379 2003-05-01 03:56:30Z peter $ 2739833Speter */ 2839833Speter 2939833Speter#include <sys/param.h> 3039833Speter#include <sys/exec.h> 3139833Speter#include <sys/linker.h> 3239833Speter#include <string.h> 3339833Speter#include <machine/bootinfo.h> 3439833Speter#include <machine/elf.h> 3539833Speter#include <stand.h> 3639833Speter 3739833Speter#include "bootstrap.h" 3839833Speter#include "libi386.h" 3939833Speter#include "btxv86.h" 4039833Speter 41114379Speterstatic int elf32_exec(struct preloaded_file *amp); 4239833Speter 43114379Speterstruct file_format i386_elf = { elf32_loadfile, elf32_exec }; 4439833Speter 4539833Speter/* 4639833Speter * There is an a.out kernel and one or more a.out modules loaded. 4739833Speter * We wish to start executing the kernel image, so make such 4839833Speter * preparations as are required, and do so. 4939833Speter */ 5039833Speterstatic int 51114379Speterelf32_exec(struct preloaded_file *fp) 5239833Speter{ 5359854Sbp struct file_metadata *md; 5439833Speter Elf_Ehdr *ehdr; 55114379Speter vm_offset_t entry, bootinfop, modulep, kernend; 5639902Smsmith int boothowto, err, bootdev; 5739833Speter 5859854Sbp if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) 5939833Speter return(EFTYPE); /* XXX actually EFUCKUP */ 6039833Speter ehdr = (Elf_Ehdr *)&(md->md_data); 6139833Speter 62114379Speter err = bi_load32(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend); 63114379Speter if (err != 0) 6439902Smsmith return(err); 6539902Smsmith entry = ehdr->e_entry & 0xffffff; 6639902Smsmith 6739833Speter#ifdef DEBUG 6839833Speter printf("Start @ 0x%lx ...\n", entry); 6939833Speter#endif 7039833Speter 7161659Sps dev_cleanup(); 72114379Speter __exec((void *)entry, boothowto, bootdev, 0, 0, 0, bootinfop, modulep, kernend); 7339833Speter 7439833Speter panic("exec returned"); 7539833Speter} 76