xref: /freebsd/stand/efi/loader/arch/arm64/exec.c (revision 3e15b01d6914c927e37d1699645783acf286655c)
1 /*-
2  * Copyright (c) 2006 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <stand.h>
28 #include <string.h>
29 
30 #include <sys/param.h>
31 #include <sys/linker.h>
32 #include <machine/elf.h>
33 
34 #include <bootstrap.h>
35 
36 #include <efi.h>
37 #include <efilib.h>
38 
39 #include "loader_efi.h"
40 #include "cache.h"
41 
42 static int elf64_exec(struct preloaded_file *amp);
43 static int elf64_obj_exec(struct preloaded_file *amp);
44 
45 int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp,
46     bool exit_bs);
47 
48 static struct file_format arm64_elf = {
49 	elf64_loadfile,
50 	elf64_exec
51 };
52 
53 struct file_format *file_formats[] = {
54 	&arm64_elf,
55 	NULL
56 };
57 
58 static int
elf64_exec(struct preloaded_file * fp)59 elf64_exec(struct preloaded_file *fp)
60 {
61 	vm_offset_t modulep, kernendp;
62 	vm_offset_t clean_addr;
63 	size_t clean_size;
64 	struct file_metadata *md;
65 	Elf_Ehdr *ehdr;
66 	int err;
67 	void (*entry)(vm_offset_t);
68 
69 	if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
70         	return(EFTYPE);
71 
72 	ehdr = (Elf_Ehdr *)&(md->md_data);
73 	entry = efi_translate(ehdr->e_entry);
74 
75 	efi_time_fini();
76 	err = bi_load(fp->f_args, &modulep, &kernendp, true);
77 	if (err != 0) {
78 		efi_time_init();
79 		return (err);
80 	}
81 
82 	dev_cleanup();
83 
84 	/* Clean D-cache under kernel area and invalidate whole I-cache */
85 	clean_addr = (vm_offset_t)efi_translate(fp->f_addr);
86 	clean_size = (vm_offset_t)efi_translate(kernendp) - clean_addr;
87 
88 	cpu_flush_dcache((void *)clean_addr, clean_size);
89 	cpu_inval_icache();
90 
91 	(*entry)(modulep);
92 	panic("exec returned");
93 }
94 
95 static int
elf64_obj_exec(struct preloaded_file * fp)96 elf64_obj_exec(struct preloaded_file *fp)
97 {
98 
99 	printf("%s called for preloaded file %p (=%s):\n", __func__, fp,
100 	    fp->f_name);
101 	return (ENOSYS);
102 }
103 
104