Path: blob/main/stand/efi/loader/arch/arm64/exec.c
34889 views
/*-1* Copyright (c) 2006 Marcel Moolenaar2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7*8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <stand.h>27#include <string.h>2829#include <sys/param.h>30#include <sys/linker.h>31#include <machine/elf.h>3233#include <bootstrap.h>3435#include <efi.h>36#include <efilib.h>3738#include "loader_efi.h"39#include "cache.h"4041static int elf64_exec(struct preloaded_file *amp);42static int elf64_obj_exec(struct preloaded_file *amp);4344static struct file_format arm64_elf = {45elf64_loadfile,46elf64_exec47};4849struct file_format *file_formats[] = {50&arm64_elf,51NULL52};5354static int55elf64_exec(struct preloaded_file *fp)56{57vm_offset_t modulep, kernendp;58vm_offset_t clean_addr;59size_t clean_size;60struct file_metadata *md;61Elf_Ehdr *ehdr;62int err;63void (*entry)(vm_offset_t);6465if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)66return(EFTYPE);6768ehdr = (Elf_Ehdr *)&(md->md_data);69entry = efi_translate(ehdr->e_entry);7071/*72* we have to cleanup here because net_cleanup() doesn't work after73* we call ExitBootServices74*/75dev_cleanup();7677efi_time_fini();78err = bi_load(fp->f_args, &modulep, &kernendp, true);79if (err != 0) {80efi_time_init();81return (err);82}8384/* Clean D-cache under kernel area and invalidate whole I-cache */85clean_addr = (vm_offset_t)efi_translate(fp->f_addr);86clean_size = (vm_offset_t)efi_translate(kernendp) - clean_addr;8788cpu_flush_dcache((void *)clean_addr, clean_size);89cpu_inval_icache();9091(*entry)(modulep);92panic("exec returned");93}9495static int96elf64_obj_exec(struct preloaded_file *fp)97{9899printf("%s called for preloaded file %p (=%s):\n", __func__, fp,100fp->f_name);101return (ENOSYS);102}103104105106