2 * Copyright (c) 2013-2014 Robert N. M. Watson
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/linker.h>
37 #include <machine/bootinfo.h>
38 #include <machine/elf.h>
40 #include <bootstrap.h>
45 static int beri_elf64_loadfile(char *, uint64_t,
46 struct preloaded_file **);
47 static int beri_elf64_exec(struct preloaded_file *fp);
49 struct file_format beri_elf = {
50 .l_load = beri_elf64_loadfile,
51 .l_exec = beri_elf64_exec,
55 * bootinfo that we will pass onto the kernel; some fields derived from
56 * *boot2_bootinfop, others filled in by loader.
58 struct bootinfo bootinfo;
61 beri_elf64_loadfile(char *filename, uint64_t dest,
62 struct preloaded_file **result)
66 * Some platforms require invalidation of instruction caches here; we
67 * don't need that currently.
69 return (__elfN(loadfile)(filename, dest, result));
73 beri_elf64_exec(struct preloaded_file *fp)
75 void (*entry)(register_t, register_t, register_t, register_t);
76 struct file_metadata *md;
81 md = file_findmetadata(fp, MODINFOMD_ELFHDR);
83 printf("%s: file_findmetadata failed\n", fp->f_name);
86 ehdr = (Elf_Ehdr *)md->md_data;
88 error = md_load64(fp->f_args, &mdp, NULL);
90 printf("%s: md_load64 failed\n", fp->f_name);
94 entry = (void *)ehdr->e_entry;
95 printf("Kernel entry at %p\n", entry);
97 dev_cleanup(); /* XXXRW: Required? */
98 printf("Kernel args: %s\n", fp->f_args);
101 * Configure bootinfo for the loaded kernel. Some values are
102 * inherited from the bootinfo passed to us by boot2 (e.g., DTB
103 * pointer); others are local to the loader (e.g., kernel boot flags).
105 bzero(&bootinfo, sizeof(bootinfo));
106 bootinfo.bi_version = BOOTINFO_VERSION;
107 bootinfo.bi_size = sizeof(bootinfo);
108 bootinfo.bi_boot2opts = boot2_bootinfo.bi_boot2opts;
109 /* NB: bi_kernelname used only by boot2. */
110 /* NB: bi_nfs_diskless not yet. */
111 bootinfo.bi_dtb = boot2_bootinfo.bi_dtb;
112 bootinfo.bi_memsize = boot2_bootinfo.bi_memsize;
113 bootinfo.bi_modulep = mdp;
116 * XXXRW: For now, pass 'memsize' rather than dtb or bootinfo. This
117 * is the 'old' ABI spoken by Miniboot and the kernel. To pass in
118 * boot2opts, modules, etc, we will need to fix this to pass in at
121 (*entry)(boot2_argc, (register_t)boot2_argv, (register_t)boot2_envv,
122 (register_t)&bootinfo);
124 panic("exec returned");