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 */ 2639833Speter 27119482Sobrien#include <sys/cdefs.h> 28119482Sobrien__FBSDID("$FreeBSD: releng/11.0/sys/boot/i386/libi386/elf32_freebsd.c 199806 2009-11-25 16:36:07Z trasz $"); 29119482Sobrien 3039833Speter#include <sys/param.h> 3139833Speter#include <sys/exec.h> 3239833Speter#include <sys/linker.h> 3339833Speter#include <string.h> 3439833Speter#include <machine/bootinfo.h> 3539833Speter#include <machine/elf.h> 3639833Speter#include <stand.h> 3739833Speter 3839833Speter#include "bootstrap.h" 3939833Speter#include "libi386.h" 4039833Speter#include "btxv86.h" 4139833Speter 42114379Speterstatic int elf32_exec(struct preloaded_file *amp); 43134459Siedowsestatic int elf32_obj_exec(struct preloaded_file *amp); 4439833Speter 45114379Speterstruct file_format i386_elf = { elf32_loadfile, elf32_exec }; 46134459Siedowsestruct file_format i386_elf_obj = { elf32_obj_loadfile, elf32_obj_exec }; 4739833Speter 4839833Speter/* 49163708Sru * There is an ELF kernel and one or more ELF modules loaded. 5039833Speter * We wish to start executing the kernel image, so make such 5139833Speter * preparations as are required, and do so. 5239833Speter */ 5339833Speterstatic int 54114379Speterelf32_exec(struct preloaded_file *fp) 5539833Speter{ 5659854Sbp struct file_metadata *md; 5739833Speter Elf_Ehdr *ehdr; 58114379Speter vm_offset_t entry, bootinfop, modulep, kernend; 5939902Smsmith int boothowto, err, bootdev; 6039833Speter 6159854Sbp if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) 62199806Strasz return(EFTYPE); 6339833Speter ehdr = (Elf_Ehdr *)&(md->md_data); 6439833Speter 65114379Speter err = bi_load32(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend); 66114379Speter if (err != 0) 6739902Smsmith return(err); 68163914Sru entry = ehdr->e_entry & 0xffffff; 6939902Smsmith 7039833Speter#ifdef DEBUG 7139833Speter printf("Start @ 0x%lx ...\n", entry); 7239833Speter#endif 7339833Speter 7461659Sps dev_cleanup(); 75114379Speter __exec((void *)entry, boothowto, bootdev, 0, 0, 0, bootinfop, modulep, kernend); 7639833Speter 7739833Speter panic("exec returned"); 7839833Speter} 79134459Siedowse 80134459Siedowsestatic int 81134459Siedowseelf32_obj_exec(struct preloaded_file *fp) 82134459Siedowse{ 83134459Siedowse return (EFTYPE); 84134459Siedowse} 85