2 * Copyright (c) 2014 Andrew Turner
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include "opt_platform.h"
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/systm.h>
42 #include <sys/devmap.h>
45 #include <sys/imgact.h>
47 #include <sys/kernel.h>
49 #include <sys/limits.h>
50 #include <sys/linker.h>
51 #include <sys/msgbuf.h>
53 #include <sys/physmem.h>
55 #include <sys/ptrace.h>
56 #include <sys/reboot.h>
58 #include <sys/rwlock.h>
59 #include <sys/sched.h>
60 #include <sys/signalvar.h>
61 #include <sys/syscallsubr.h>
62 #include <sys/sysent.h>
63 #include <sys/sysproto.h>
64 #include <sys/ucontext.h>
66 #include <sys/vmmeter.h>
69 #include <vm/vm_param.h>
70 #include <vm/vm_kern.h>
71 #include <vm/vm_object.h>
72 #include <vm/vm_page.h>
73 #include <vm/vm_phys.h>
75 #include <vm/vm_map.h>
76 #include <vm/vm_pager.h>
78 #include <machine/armreg.h>
79 #include <machine/cpu.h>
80 #include <machine/debug_monitor.h>
81 #include <machine/kdb.h>
82 #include <machine/machdep.h>
83 #include <machine/metadata.h>
84 #include <machine/md_var.h>
85 #include <machine/pcb.h>
86 #include <machine/undefined.h>
87 #include <machine/vmparam.h>
90 #include <machine/vfp.h>
94 #include <contrib/dev/acpica/include/acpi.h>
95 #include <machine/acpica_machdep.h>
99 #include <dev/fdt/fdt_common.h>
100 #include <dev/ofw/openfirm.h>
103 enum arm64_bus arm64_bus_method = ARM64_BUS_NONE;
106 * XXX: The .bss is assumed to be in the boot CPU NUMA domain. If not we
107 * could relocate this, but will need to keep the same virtual address as
108 * it's reverenced by the EARLY_COUNTER macro.
112 #if defined(PERTHREAD_SSP)
114 * The boot SSP canary. Will be replaced with a per-thread canary when
115 * scheduling has started.
117 uintptr_t boot_canary = 0x49a2d892bc05a0b1ul;
120 static struct trapframe proc0_tf;
126 struct kva_md_info kmi;
128 int64_t dczva_line_size; /* The size of cache line the dc zva zeroes */
132 * Physical address of the EFI System Table. Stashed from the metadata hints
133 * passed into the kernel and used by the EFI code to call runtime services.
135 vm_paddr_t efi_systbl_phys;
136 static struct efi_map_header *efihdr;
138 /* pagezero_* implementations are provided in support.S */
139 void pagezero_simple(void *);
140 void pagezero_cache(void *);
142 /* pagezero_simple is default pagezero */
143 void (*pagezero)(void *p) = pagezero_simple;
145 int (*apei_nmi)(void);
147 #if defined(PERTHREAD_SSP_WARNING)
149 print_ssp_warning(void *data __unused)
151 printf("WARNING: Per-thread SSP is enabled but the compiler is too old to support it\n");
153 SYSINIT(ssp_warn, SI_SUB_COPYRIGHT, SI_ORDER_ANY, print_ssp_warning, NULL);
154 SYSINIT(ssp_warn2, SI_SUB_LAST, SI_ORDER_ANY, print_ssp_warning, NULL);
160 uint64_t id_aa64mfr1;
162 id_aa64mfr1 = READ_SPECIALREG(id_aa64mmfr1_el1);
163 if (ID_AA64MMFR1_PAN_VAL(id_aa64mfr1) != ID_AA64MMFR1_PAN_NONE)
172 * The LLVM integrated assembler doesn't understand the PAN
173 * PSTATE field. Because of this we need to manually create
174 * the instruction in an asm block. This is equivalent to:
177 * This sets the PAN bit, stopping the kernel from accessing
178 * memory when userspace can also access it unless the kernel
179 * uses the userspace load/store instructions.
182 WRITE_SPECIALREG(sctlr_el1,
183 READ_SPECIALREG(sctlr_el1) & ~SCTLR_SPAN);
184 __asm __volatile(".inst 0xd500409f | (0x1 << 8)");
192 return (boot_el == 2);
196 cpu_startup(void *dummy)
201 printf("real memory = %ju (%ju MB)\n", ptoa((uintmax_t)realmem),
202 ptoa((uintmax_t)realmem) / 1024 / 1024);
205 printf("Physical memory chunk(s):\n");
206 for (i = 0; phys_avail[i + 1] != 0; i += 2) {
207 size = phys_avail[i + 1] - phys_avail[i];
208 printf("%#016jx - %#016jx, %ju bytes (%ju pages)\n",
209 (uintmax_t)phys_avail[i],
210 (uintmax_t)phys_avail[i + 1] - 1,
211 (uintmax_t)size, (uintmax_t)size / PAGE_SIZE);
215 printf("avail memory = %ju (%ju MB)\n",
216 ptoa((uintmax_t)vm_free_count()),
217 ptoa((uintmax_t)vm_free_count()) / 1024 / 1024);
220 install_cpu_errata();
222 vm_ksubmap_init(&kmi);
224 vm_pager_bufferinit();
227 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
230 late_ifunc_resolve(void *dummy __unused)
232 link_elf_late_ireloc();
234 SYSINIT(late_ifunc_resolve, SI_SUB_CPU, SI_ORDER_ANY, late_ifunc_resolve, NULL);
237 cpu_idle_wakeup(int cpu)
250 if (!sched_runnable())
263 /* We should have shutdown by now, if not enter a low power sleep */
266 __asm __volatile("wfi");
271 * Flush the D-cache for non-DMA I/O so that the I-cache can
272 * be made coherent later.
275 cpu_flush_dcache(void *ptr, size_t len)
281 /* Get current clock frequency for the given CPU ID. */
283 cpu_est_clockrate(int cpu_id, uint64_t *rate)
287 pc = pcpu_find(cpu_id);
288 if (pc == NULL || rate == NULL)
291 if (pc->pc_clock == 0)
294 *rate = pc->pc_clock;
299 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
302 pcpu->pc_acpi_id = 0xffffffff;
303 pcpu->pc_mpidr_low = 0xffffffff;
304 pcpu->pc_mpidr_high = 0xffffffff;
314 if (td->td_md.md_spinlock_count == 0) {
315 daif = intr_disable();
316 td->td_md.md_spinlock_count = 1;
317 td->td_md.md_saved_daif = daif;
320 td->td_md.md_spinlock_count++;
330 daif = td->td_md.md_saved_daif;
331 td->td_md.md_spinlock_count--;
332 if (td->td_md.md_spinlock_count == 0) {
339 * Construct a PCB from a trapframe. This is called from kdb_trap() where
340 * we want to start a backtrace from the function that caused us to enter
341 * the debugger. We have the context in the trapframe, but base the trace
342 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
343 * enough for a backtrace.
346 makectx(struct trapframe *tf, struct pcb *pcb)
350 for (i = 0; i < nitems(pcb->pcb_x); i++)
351 pcb->pcb_x[i] = tf->tf_x[i];
353 /* NB: pcb_lr is the PC, see PC_REGS() in db_machdep.h */
354 pcb->pcb_lr = tf->tf_elr;
355 pcb->pcb_sp = tf->tf_sp;
359 init_proc0(vm_offset_t kstack)
363 pcpup = cpuid_to_pcpu[0];
364 MPASS(pcpup != NULL);
366 proc_linkup0(&proc0, &thread0);
367 thread0.td_kstack = kstack;
368 thread0.td_kstack_pages = kstack_pages;
369 #if defined(PERTHREAD_SSP)
370 thread0.td_md.md_canary = boot_canary;
372 thread0.td_pcb = (struct pcb *)(thread0.td_kstack +
373 thread0.td_kstack_pages * PAGE_SIZE) - 1;
374 thread0.td_pcb->pcb_fpflags = 0;
375 thread0.td_pcb->pcb_fpusaved = &thread0.td_pcb->pcb_fpustate;
376 thread0.td_pcb->pcb_vfpcpu = UINT_MAX;
377 thread0.td_frame = &proc0_tf;
378 ptrauth_thread0(&thread0);
379 pcpup->pc_curpcb = thread0.td_pcb;
382 * Unmask SError exceptions. They are used to signal a RAS failure,
383 * or other hardware error.
389 * Get an address to be used to write to kernel data that may be mapped
390 * read-only, e.g. to patch kernel code.
393 arm64_get_writable_addr(vm_offset_t addr, vm_offset_t *out)
397 /* Check if the page is writable */
398 if (PAR_SUCCESS(arm64_address_translate_s1e1w(addr))) {
404 * Find the physical address of the given page.
406 if (!pmap_klookup(addr, &pa)) {
411 * If it is within the DMAP region and is writable use that.
413 if (PHYS_IN_DMAP(pa)) {
414 addr = PHYS_TO_DMAP(pa);
415 if (PAR_SUCCESS(arm64_address_translate_s1e1w(addr))) {
424 typedef void (*efi_map_entry_cb)(struct efi_md *, void *argp);
427 foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void *argp)
429 struct efi_md *map, *p;
434 * Memory map data provided by UEFI via the GetMemoryMap
437 efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
438 map = (struct efi_md *)((uint8_t *)efihdr + efisz);
440 if (efihdr->descriptor_size == 0)
442 ndesc = efihdr->memory_size / efihdr->descriptor_size;
444 for (i = 0, p = map; i < ndesc; i++,
445 p = efi_next_descriptor(p, efihdr->descriptor_size)) {
451 exclude_efi_map_entry(struct efi_md *p, void *argp __unused)
454 switch (p->md_type) {
455 case EFI_MD_TYPE_CODE:
456 case EFI_MD_TYPE_DATA:
457 case EFI_MD_TYPE_BS_CODE:
458 case EFI_MD_TYPE_BS_DATA:
459 case EFI_MD_TYPE_FREE:
461 * We're allowed to use any entry with these types.
465 physmem_exclude_region(p->md_phys, p->md_pages * EFI_PAGE_SIZE,
471 exclude_efi_map_entries(struct efi_map_header *efihdr)
474 foreach_efi_map_entry(efihdr, exclude_efi_map_entry, NULL);
478 add_efi_map_entry(struct efi_md *p, void *argp __unused)
481 switch (p->md_type) {
482 case EFI_MD_TYPE_RECLAIM:
484 * The recomended location for ACPI tables. Map into the
485 * DMAP so we can access them from userspace via /dev/mem.
487 case EFI_MD_TYPE_RT_CODE:
489 * Some UEFI implementations put the system table in the
490 * runtime code section. Include it in the DMAP, but will
491 * be excluded from phys_avail later.
493 case EFI_MD_TYPE_RT_DATA:
495 * Runtime data will be excluded after the DMAP
496 * region is created to stop it from being added
499 case EFI_MD_TYPE_CODE:
500 case EFI_MD_TYPE_DATA:
501 case EFI_MD_TYPE_BS_CODE:
502 case EFI_MD_TYPE_BS_DATA:
503 case EFI_MD_TYPE_FREE:
505 * We're allowed to use any entry with these types.
507 physmem_hardware_region(p->md_phys,
508 p->md_pages * EFI_PAGE_SIZE);
514 add_efi_map_entries(struct efi_map_header *efihdr)
516 foreach_efi_map_entry(efihdr, add_efi_map_entry, NULL);
520 print_efi_map_entry(struct efi_md *p, void *argp __unused)
523 static const char *types[] = {
529 "RuntimeServicesCode",
530 "RuntimeServicesData",
531 "ConventionalMemory",
536 "MemoryMappedIOPortSpace",
541 if (p->md_type < nitems(types))
542 type = types[p->md_type];
545 printf("%23s %012lx %012lx %08lx ", type, p->md_phys,
546 p->md_virt, p->md_pages);
547 if (p->md_attr & EFI_MD_ATTR_UC)
549 if (p->md_attr & EFI_MD_ATTR_WC)
551 if (p->md_attr & EFI_MD_ATTR_WT)
553 if (p->md_attr & EFI_MD_ATTR_WB)
555 if (p->md_attr & EFI_MD_ATTR_UCE)
557 if (p->md_attr & EFI_MD_ATTR_WP)
559 if (p->md_attr & EFI_MD_ATTR_RP)
561 if (p->md_attr & EFI_MD_ATTR_XP)
563 if (p->md_attr & EFI_MD_ATTR_NV)
565 if (p->md_attr & EFI_MD_ATTR_MORE_RELIABLE)
566 printf("MORE_RELIABLE ");
567 if (p->md_attr & EFI_MD_ATTR_RO)
569 if (p->md_attr & EFI_MD_ATTR_RT)
575 print_efi_map_entries(struct efi_map_header *efihdr)
578 printf("%23s %12s %12s %8s %4s\n",
579 "Type", "Physical", "Virtual", "#Pages", "Attr");
580 foreach_efi_map_entry(efihdr, print_efi_map_entry, NULL);
584 * Map the passed in VA in EFI space to a void * using the efi memory table to
585 * find the PA and return it in the DMAP, if it exists. We're used between the
586 * calls to pmap_bootstrap() and physmem_init_kernel_globals() to parse CFG
587 * tables We assume that either the entry you are mapping fits within its page,
588 * or if it spills to the next page, that's contiguous in PA and in the DMAP.
589 * All observed tables obey the first part of this precondition.
591 struct early_map_data
598 efi_early_map_entry(struct efi_md *p, void *argp)
600 struct early_map_data *emdp = argp;
605 if ((p->md_attr & EFI_MD_ATTR_RT) == 0)
608 e = p->md_virt + p->md_pages * EFI_PAGE_SIZE;
609 if (emdp->va < s || emdp->va >= e)
611 emdp->pa = p->md_phys + (emdp->va - p->md_virt);
615 efi_early_map(vm_offset_t va)
617 struct early_map_data emd = { .va = va };
619 foreach_efi_map_entry(efihdr, efi_early_map_entry, &emd);
622 return (void *)PHYS_TO_DMAP(emd.pa);
627 * When booted via kboot, the prior kernel will pass in reserved memory areas in
628 * a EFI config table. We need to find that table and walk through it excluding
629 * the memory ranges in it. btw, this is called too early for the printf to do
630 * anything since msgbufp isn't initialized, let alone a console...
633 exclude_efi_memreserve(vm_offset_t efi_systbl_phys)
635 struct efi_systbl *systbl;
636 struct uuid efi_memreserve = LINUX_EFI_MEMRESERVE_TABLE;
638 systbl = (struct efi_systbl *)PHYS_TO_DMAP(efi_systbl_phys);
639 if (systbl == NULL) {
640 printf("can't map systbl\n");
643 if (systbl->st_hdr.th_sig != EFI_SYSTBL_SIG) {
644 printf("Bad signature for systbl %#lx\n", systbl->st_hdr.th_sig);
649 * We don't yet have the pmap system booted enough to create a pmap for
650 * the efi firmware's preferred address space from the GetMemoryMap()
651 * table. The st_cfgtbl is a VA in this space, so we need to do the
652 * mapping ourselves to a kernel VA with efi_early_map. We assume that
653 * the cfgtbl entries don't span a page. Other pointers are PAs, as
656 if (systbl->st_cfgtbl == 0) /* Failsafe st_entries should == 0 in this case */
658 for (int i = 0; i < systbl->st_entries; i++) {
659 struct efi_cfgtbl *cfgtbl;
660 struct linux_efi_memreserve *mr;
662 cfgtbl = efi_early_map(systbl->st_cfgtbl + i * sizeof(*cfgtbl));
664 panic("Can't map the config table entry %d\n", i);
665 if (memcmp(&cfgtbl->ct_uuid, &efi_memreserve, sizeof(struct uuid)) != 0)
669 * cfgtbl points are either VA or PA, depending on the GUID of
670 * the table. memreserve GUID pointers are PA and not converted
671 * after a SetVirtualAddressMap(). The list's mr_next pointer
674 mr = (struct linux_efi_memreserve *)PHYS_TO_DMAP(
675 (vm_offset_t)cfgtbl->ct_data);
677 for (int j = 0; j < mr->mr_count; j++) {
678 struct linux_efi_memreserve_entry *mre;
680 mre = &mr->mr_entry[j];
681 physmem_exclude_region(mre->mre_base, mre->mre_size,
682 EXFLAG_NODUMP | EXFLAG_NOALLOC);
684 if (mr->mr_next == 0)
686 mr = (struct linux_efi_memreserve *)PHYS_TO_DMAP(mr->mr_next);
694 try_load_dtb(caddr_t kmdp)
698 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
699 #if defined(FDT_DTB_STATIC)
701 * In case the device tree blob was not retrieved (from metadata) try
702 * to use the statically embedded one.
705 dtbp = (vm_offset_t)&fdt_static_dtb;
708 if (dtbp == (vm_offset_t)NULL) {
710 printf("ERROR loading DTB\n");
715 if (OF_install(OFW_FDT, 0) == FALSE)
716 panic("Cannot install FDT");
718 if (OF_init((void *)dtbp) != 0)
719 panic("OF_init failed with the found device tree");
721 parse_fdt_bootargs();
728 bool has_acpi, has_fdt;
731 has_acpi = has_fdt = false;
734 has_fdt = (OF_peer(0) != 0);
737 has_acpi = (AcpiOsGetRootPointer() != 0);
740 env = kern_getenv("kern.cfg.order");
743 while (order != NULL) {
745 strncmp(order, "acpi", 4) == 0 &&
746 (order[4] == ',' || order[4] == '\0')) {
747 arm64_bus_method = ARM64_BUS_ACPI;
751 strncmp(order, "fdt", 3) == 0 &&
752 (order[3] == ',' || order[3] == '\0')) {
753 arm64_bus_method = ARM64_BUS_FDT;
756 order = strchr(order, ',');
758 order++; /* Skip comma */
762 /* If we set the bus method it is valid */
763 if (arm64_bus_method != ARM64_BUS_NONE)
766 /* If no order or an invalid order was set use the default */
767 if (arm64_bus_method == ARM64_BUS_NONE) {
769 arm64_bus_method = ARM64_BUS_FDT;
771 arm64_bus_method = ARM64_BUS_ACPI;
775 * If no option was set the default is valid, otherwise we are
776 * setting one to get cninit() working, then calling panic to tell
777 * the user about the invalid bus setup.
779 return (env == NULL);
785 int dczva_line_shift;
788 identify_cache(READ_SPECIALREG(ctr_el0));
790 dczid_el0 = READ_SPECIALREG(dczid_el0);
792 /* Check if dc zva is not prohibited */
793 if (dczid_el0 & DCZID_DZP)
796 /* Same as with above calculations */
797 dczva_line_shift = DCZID_BS_SIZE(dczid_el0);
798 dczva_line_size = sizeof(int) << dczva_line_shift;
800 /* Change pagezero function */
801 pagezero = pagezero_cache;
806 memory_mapping_mode(vm_paddr_t pa)
808 struct efi_md *map, *p;
813 return (VM_MEMATTR_WRITE_BACK);
816 * Memory map data provided by UEFI via the GetMemoryMap
819 efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
820 map = (struct efi_md *)((uint8_t *)efihdr + efisz);
822 if (efihdr->descriptor_size == 0)
823 return (VM_MEMATTR_WRITE_BACK);
824 ndesc = efihdr->memory_size / efihdr->descriptor_size;
826 for (i = 0, p = map; i < ndesc; i++,
827 p = efi_next_descriptor(p, efihdr->descriptor_size)) {
828 if (pa < p->md_phys ||
829 pa >= p->md_phys + p->md_pages * EFI_PAGE_SIZE)
831 if (p->md_type == EFI_MD_TYPE_IOMEM ||
832 p->md_type == EFI_MD_TYPE_IOPORT)
833 return (VM_MEMATTR_DEVICE);
834 else if ((p->md_attr & EFI_MD_ATTR_WB) != 0 ||
835 p->md_type == EFI_MD_TYPE_RECLAIM)
836 return (VM_MEMATTR_WRITE_BACK);
837 else if ((p->md_attr & EFI_MD_ATTR_WT) != 0)
838 return (VM_MEMATTR_WRITE_THROUGH);
839 else if ((p->md_attr & EFI_MD_ATTR_WC) != 0)
840 return (VM_MEMATTR_WRITE_COMBINING);
844 return (VM_MEMATTR_DEVICE);
848 initarm(struct arm64_bootparams *abp)
850 struct efi_fb *efifb;
854 struct mem_region mem_regions[FDT_MEM_REGIONS];
857 char dts_version[255];
859 vm_offset_t lastaddr;
863 TSRAW(&thread0, TS_ENTER, __func__, NULL);
865 boot_el = abp->boot_el;
867 /* Parse loader or FDT boot parametes. Determine last used address. */
868 lastaddr = parse_boot_param(abp);
870 /* Find the kernel address */
871 kmdp = preload_search_by_type("elf kernel");
873 kmdp = preload_search_by_type("elf64 kernel");
876 update_special_regs(0);
878 link_elf_ireloc(kmdp);
883 efi_systbl_phys = MD_FETCH(kmdp, MODINFOMD_FW_HANDLE, vm_paddr_t);
885 /* Load the physical memory ranges */
886 efihdr = (struct efi_map_header *)preload_search_info(kmdp,
887 MODINFO_METADATA | MODINFOMD_EFI_MAP);
889 add_efi_map_entries(efihdr);
892 /* Grab physical memory regions information from device tree. */
893 if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,
895 panic("Cannot get physical memory regions");
896 physmem_hardware_regions(mem_regions, mem_regions_sz);
898 if (fdt_get_reserved_mem(mem_regions, &mem_regions_sz) == 0)
899 physmem_exclude_regions(mem_regions, mem_regions_sz,
900 EXFLAG_NODUMP | EXFLAG_NOALLOC);
903 /* Exclude the EFI framebuffer from our view of physical memory. */
904 efifb = (struct efi_fb *)preload_search_info(kmdp,
905 MODINFO_METADATA | MODINFOMD_EFI_FB);
907 physmem_exclude_region(efifb->fb_addr, efifb->fb_size,
910 /* Set the pcpu data, this is needed by pmap_bootstrap */
912 pcpu_init(pcpup, 0, sizeof(struct pcpu));
915 * Set the pcpu pointer with a backup in tpidr_el1 to be
916 * loaded when entering the kernel from userland.
920 "msr tpidr_el1, %0" :: "r"(pcpup));
922 /* locore.S sets sp_el0 to &thread0 so no need to set it here. */
923 PCPU_SET(curthread, &thread0);
924 PCPU_SET(midr, get_midr());
926 /* Do basic tuning, hz etc */
932 /* Bootstrap enough of pmap to enter the kernel proper */
933 pmap_bootstrap(KERNBASE - abp->kern_delta, lastaddr - KERNBASE);
934 /* Exclude entries needed in the DMAP region, but not phys_avail */
936 exclude_efi_map_entries(efihdr);
937 /* Do the same for reserve entries in the EFI MEMRESERVE table */
938 if (efi_systbl_phys != 0)
939 exclude_efi_memreserve(efi_systbl_phys);
940 physmem_init_kernel_globals();
942 devmap_bootstrap(0, NULL);
947 set_ttbr0(abp->kern_ttbr0);
951 panic("Invalid bus configuration: %s",
952 kern_getenv("kern.cfg.order"));
955 * Check if pointer authentication is available on this system, and
956 * if so enable its use. This needs to be called before init_proc0
957 * as that will configure the thread0 pointer authentication keys.
962 * Dump the boot metadata. We have to wait for cninit() since console
963 * output is required. If it's grossly incorrect the kernel will never
966 if (getenv_is_true("debug.dump_modinfo_at_boot"))
969 init_proc0(abp->kern_stack);
970 msgbufinit(msgbufp, msgbufsize);
972 init_param2(physmem);
977 if ((boothowto & RB_KDB) != 0)
978 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
984 env = kern_getenv("kernelname");
986 strlcpy(kernelname, env, sizeof(kernelname));
989 if (arm64_bus_method == ARM64_BUS_FDT) {
990 root = OF_finddevice("/");
991 if (OF_getprop(root, "freebsd,dts-version", dts_version, sizeof(dts_version)) > 0) {
992 if (strcmp(LINUX_DTS_VERSION, dts_version) != 0)
993 printf("WARNING: DTB version is %s while kernel expects %s, "
994 "please update the DTB in the ESP\n",
998 printf("WARNING: Cannot find freebsd,dts-version property, "
999 "cannot check DTB compliance\n");
1004 if (boothowto & RB_VERBOSE) {
1006 print_efi_map_entries(efihdr);
1007 physmem_print_tables();
1020 WRITE_SPECIALREG(oslar_el1, 0);
1022 /* This permits DDB to use debug registers for watchpoints. */
1025 /* TODO: Eventually will need to initialize debug registers here. */
1029 #include <ddb/ddb.h>
1031 DB_SHOW_COMMAND(specialregs, db_show_spregs)
1033 #define PRINT_REG(reg) \
1034 db_printf(__STRING(reg) " = %#016lx\n", READ_SPECIALREG(reg))
1036 PRINT_REG(actlr_el1);
1037 PRINT_REG(afsr0_el1);
1038 PRINT_REG(afsr1_el1);
1039 PRINT_REG(aidr_el1);
1040 PRINT_REG(amair_el1);
1041 PRINT_REG(ccsidr_el1);
1042 PRINT_REG(clidr_el1);
1043 PRINT_REG(contextidr_el1);
1044 PRINT_REG(cpacr_el1);
1045 PRINT_REG(csselr_el1);
1047 PRINT_REG(currentel);
1049 PRINT_REG(dczid_el0);
1054 /* ARM64TODO: Enable VFP before reading floating-point registers */
1058 PRINT_REG(id_aa64afr0_el1);
1059 PRINT_REG(id_aa64afr1_el1);
1060 PRINT_REG(id_aa64dfr0_el1);
1061 PRINT_REG(id_aa64dfr1_el1);
1062 PRINT_REG(id_aa64isar0_el1);
1063 PRINT_REG(id_aa64isar1_el1);
1064 PRINT_REG(id_aa64pfr0_el1);
1065 PRINT_REG(id_aa64pfr1_el1);
1066 PRINT_REG(id_afr0_el1);
1067 PRINT_REG(id_dfr0_el1);
1068 PRINT_REG(id_isar0_el1);
1069 PRINT_REG(id_isar1_el1);
1070 PRINT_REG(id_isar2_el1);
1071 PRINT_REG(id_isar3_el1);
1072 PRINT_REG(id_isar4_el1);
1073 PRINT_REG(id_isar5_el1);
1074 PRINT_REG(id_mmfr0_el1);
1075 PRINT_REG(id_mmfr1_el1);
1076 PRINT_REG(id_mmfr2_el1);
1077 PRINT_REG(id_mmfr3_el1);
1079 /* Missing from llvm */
1080 PRINT_REG(id_mmfr4_el1);
1082 PRINT_REG(id_pfr0_el1);
1083 PRINT_REG(id_pfr1_el1);
1085 PRINT_REG(mair_el1);
1086 PRINT_REG(midr_el1);
1087 PRINT_REG(mpidr_el1);
1088 PRINT_REG(mvfr0_el1);
1089 PRINT_REG(mvfr1_el1);
1090 PRINT_REG(mvfr2_el1);
1091 PRINT_REG(revidr_el1);
1092 PRINT_REG(sctlr_el1);
1095 PRINT_REG(spsr_el1);
1097 PRINT_REG(tpidr_el0);
1098 PRINT_REG(tpidr_el1);
1099 PRINT_REG(tpidrro_el0);
1100 PRINT_REG(ttbr0_el1);
1101 PRINT_REG(ttbr1_el1);
1102 PRINT_REG(vbar_el1);
1106 DB_SHOW_COMMAND(vtop, db_show_vtop)
1111 phys = arm64_address_translate_s1e1r(addr);
1112 db_printf("EL1 physical address reg (read): 0x%016lx\n", phys);
1113 phys = arm64_address_translate_s1e1w(addr);
1114 db_printf("EL1 physical address reg (write): 0x%016lx\n", phys);
1115 phys = arm64_address_translate_s1e0r(addr);
1116 db_printf("EL0 physical address reg (read): 0x%016lx\n", phys);
1117 phys = arm64_address_translate_s1e0w(addr);
1118 db_printf("EL0 physical address reg (write): 0x%016lx\n", phys);
1120 db_printf("show vtop <virt_addr>\n");