2 * Copyright (c) 2006 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/linker.h>
35 #include <machine/elf.h>
37 #include <bootstrap.h>
42 #include "loader_efi.h"
45 #include "platform/acfreebsd.h"
47 #define ACPI_SYSTEM_XFACE
48 #define ACPI_USE_SYSTEM_INTTYPES
52 static EFI_GUID acpi_guid = ACPI_TABLE_GUID;
53 static EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID;
55 static int elf64_exec(struct preloaded_file *amp);
56 static int elf64_obj_exec(struct preloaded_file *amp);
58 int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp);
60 static struct file_format arm64_elf = {
65 struct file_format *file_formats[] = {
71 elf64_exec(struct preloaded_file *fp)
73 vm_offset_t modulep, kernendp;
74 vm_offset_t clean_addr;
76 struct file_metadata *md;
77 ACPI_TABLE_RSDP *rsdp;
81 void (*entry)(vm_offset_t);
83 rsdp = efi_get_table(&acpi20_guid);
85 rsdp = efi_get_table(&acpi_guid);
88 sprintf(buf, "0x%016llx", (unsigned long long)rsdp);
89 setenv("hint.acpi.0.rsdp", buf, 1);
90 revision = rsdp->Revision;
93 sprintf(buf, "%d", revision);
94 setenv("hint.acpi.0.revision", buf, 1);
95 strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId));
96 buf[sizeof(rsdp->OemId)] = '\0';
97 setenv("hint.acpi.0.oem", buf, 1);
98 sprintf(buf, "0x%016x", rsdp->RsdtPhysicalAddress);
99 setenv("hint.acpi.0.rsdt", buf, 1);
101 /* XXX extended checksum? */
102 sprintf(buf, "0x%016llx",
103 (unsigned long long)rsdp->XsdtPhysicalAddress);
104 setenv("hint.acpi.0.xsdt", buf, 1);
105 sprintf(buf, "%d", rsdp->Length);
106 setenv("hint.acpi.0.xsdt_length", buf, 1);
110 if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
113 ehdr = (Elf_Ehdr *)&(md->md_data);
114 entry = efi_translate(ehdr->e_entry);
117 err = bi_load(fp->f_args, &modulep, &kernendp);
125 /* Clean D-cache under kernel area and invalidate whole I-cache */
126 clean_addr = (vm_offset_t)efi_translate(fp->f_addr);
127 clean_size = (vm_offset_t)efi_translate(kernendp) - clean_addr;
129 cpu_flush_dcache((void *)clean_addr, clean_size);
130 cpu_inval_icache(NULL, 0);
133 panic("exec returned");
137 elf64_obj_exec(struct preloaded_file *fp)
140 printf("%s called for preloaded file %p (=%s):\n", __func__, fp,