12192efc0SMitchell Horne /*- 22192efc0SMitchell Horne * Copyright (c) 2001 Benno Rice <benno@FreeBSD.org> 32192efc0SMitchell Horne * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com> 42192efc0SMitchell Horne * All rights reserved. 52192efc0SMitchell Horne * 62192efc0SMitchell Horne * Redistribution and use in source and binary forms, with or without 72192efc0SMitchell Horne * modification, are permitted provided that the following conditions 82192efc0SMitchell Horne * are met: 92192efc0SMitchell Horne * 1. Redistributions of source code must retain the above copyright 102192efc0SMitchell Horne * notice, this list of conditions and the following disclaimer. 112192efc0SMitchell Horne * 2. Redistributions in binary form must reproduce the above copyright 122192efc0SMitchell Horne * notice, this list of conditions and the following disclaimer in the 132192efc0SMitchell Horne * documentation and/or other materials provided with the distribution. 142192efc0SMitchell Horne * 152192efc0SMitchell Horne * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 162192efc0SMitchell Horne * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 172192efc0SMitchell Horne * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 182192efc0SMitchell Horne * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 192192efc0SMitchell Horne * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 202192efc0SMitchell Horne * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 212192efc0SMitchell Horne * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 222192efc0SMitchell Horne * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 232192efc0SMitchell Horne * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 242192efc0SMitchell Horne * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 252192efc0SMitchell Horne * SUCH DAMAGE. 262192efc0SMitchell Horne */ 272192efc0SMitchell Horne 282192efc0SMitchell Horne #include <sys/cdefs.h> 292192efc0SMitchell Horne __FBSDID("$FreeBSD$"); 302192efc0SMitchell Horne 312192efc0SMitchell Horne #include <sys/param.h> 322192efc0SMitchell Horne #include <sys/linker.h> 332192efc0SMitchell Horne 342192efc0SMitchell Horne #include <machine/md_var.h> 352192efc0SMitchell Horne #include <machine/metadata.h> 362192efc0SMitchell Horne #include <machine/elf.h> 372192efc0SMitchell Horne 382192efc0SMitchell Horne #include <stand.h> 392192efc0SMitchell Horne 402192efc0SMitchell Horne #include <efi.h> 412192efc0SMitchell Horne #include <efilib.h> 422192efc0SMitchell Horne 432192efc0SMitchell Horne #include "bootstrap.h" 442192efc0SMitchell Horne #include "loader_efi.h" 452192efc0SMitchell Horne 46*ed87efbeSRoger Pau Monné extern int bi_load(char *, vm_offset_t *, vm_offset_t *, bool); 472192efc0SMitchell Horne 482192efc0SMitchell Horne static int 492192efc0SMitchell Horne __elfN(exec)(struct preloaded_file *fp) 502192efc0SMitchell Horne { 512192efc0SMitchell Horne struct file_metadata *fmp; 522192efc0SMitchell Horne vm_offset_t modulep, kernend; 532192efc0SMitchell Horne Elf_Ehdr *e; 542192efc0SMitchell Horne int error; 552192efc0SMitchell Horne void (*entry)(void *); 562192efc0SMitchell Horne 572192efc0SMitchell Horne if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) 582192efc0SMitchell Horne return (EFTYPE); 592192efc0SMitchell Horne 602192efc0SMitchell Horne e = (Elf_Ehdr *)&fmp->md_data; 612192efc0SMitchell Horne 622192efc0SMitchell Horne efi_time_fini(); 632192efc0SMitchell Horne 642192efc0SMitchell Horne entry = efi_translate(e->e_entry); 652192efc0SMitchell Horne 664f8212c8SJessica Clarke printf("Kernel entry at %p...\n", entry); 672192efc0SMitchell Horne printf("Kernel args: %s\n", fp->f_args); 682192efc0SMitchell Horne 69*ed87efbeSRoger Pau Monné if ((error = bi_load(fp->f_args, &modulep, &kernend, true)) != 0) { 702192efc0SMitchell Horne efi_time_init(); 712192efc0SMitchell Horne return (error); 722192efc0SMitchell Horne } 732192efc0SMitchell Horne 742192efc0SMitchell Horne /* 752192efc0SMitchell Horne * At this point we've called ExitBootServices, so we can't call 762192efc0SMitchell Horne * printf or any other function that uses Boot Services 772192efc0SMitchell Horne */ 782192efc0SMitchell Horne dev_cleanup(); 792192efc0SMitchell Horne 802192efc0SMitchell Horne (*entry)((void *)modulep); 812192efc0SMitchell Horne panic("exec returned"); 822192efc0SMitchell Horne } 832192efc0SMitchell Horne 842192efc0SMitchell Horne static struct file_format riscv_elf = { 852192efc0SMitchell Horne __elfN(loadfile), 862192efc0SMitchell Horne __elfN(exec) 872192efc0SMitchell Horne }; 882192efc0SMitchell Horne 892192efc0SMitchell Horne struct file_format *file_formats[] = { 902192efc0SMitchell Horne &riscv_elf, 912192efc0SMitchell Horne NULL 922192efc0SMitchell Horne }; 93