1 /* $NetBSD: arm32_machdep.c,v 1.44 2004/03/24 15:34:47 atatat Exp $ */
4 * SPDX-License-Identifier: BSD-4-Clause
6 * Copyright (c) 2004 Olivier Houchard
7 * Copyright (c) 1994-1998 Mark Brinicombe.
8 * Copyright (c) 1994 Brini.
11 * This code is derived from software written for Brini by Mark Brinicombe
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by Mark Brinicombe
24 * for the NetBSD Project.
25 * 4. The name of the company nor the name of the author may be used to
26 * endorse or promote products derived from this software without specific
27 * prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * Machine dependent functions for kernel setup
44 * Updated : 18/04/01 updated for new wscons
48 #include "opt_kstack_pages.h"
49 #include "opt_platform.h"
50 #include "opt_sched.h"
52 #include <sys/cdefs.h>
53 __FBSDID("$FreeBSD$");
55 #include <sys/param.h>
60 #include <sys/devmap.h>
62 #include <sys/imgact.h>
64 #include <sys/kernel.h>
66 #include <sys/linker.h>
67 #include <sys/msgbuf.h>
68 #include <sys/physmem.h>
69 #include <sys/reboot.h>
70 #include <sys/rwlock.h>
71 #include <sys/sched.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysent.h>
74 #include <sys/sysproto.h>
75 #include <sys/vmmeter.h>
77 #include <vm/vm_object.h>
78 #include <vm/vm_page.h>
79 #include <vm/vm_pager.h>
81 #include <machine/asm.h>
82 #include <machine/debug_monitor.h>
83 #include <machine/machdep.h>
84 #include <machine/metadata.h>
85 #include <machine/pcb.h>
86 #include <machine/platform.h>
87 #include <machine/sysarch.h>
88 #include <machine/undefined.h>
89 #include <machine/vfp.h>
90 #include <machine/vmparam.h>
93 #include <dev/fdt/fdt_common.h>
94 #include <machine/ofw_machdep.h>
98 #define debugf(fmt, args...) printf(fmt, ##args)
100 #define debugf(fmt, args...)
103 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
104 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \
105 defined(COMPAT_FREEBSD9)
106 #error FreeBSD/arm doesn't provide compatibility with releases prior to 10
111 #error FreeBSD requires ARMv6 or later
114 struct pcpu __pcpu[MAXCPU];
115 struct pcpu *pcpup = &__pcpu[0];
117 static struct trapframe proc0_tf;
118 uint32_t cpu_reset_address = 0;
120 vm_offset_t vector_page;
122 /* The address at which the kernel was loaded. Set early in initarm(). */
123 vm_paddr_t arm_physmem_kernaddr;
129 vm_offset_t systempage;
130 vm_offset_t irqstack;
131 vm_offset_t undstack;
132 vm_offset_t abtstack;
136 static delay_func *delay_impl;
137 static void *delay_arg;
140 struct kva_md_info kmi;
144 * Initialize the vector page, and select whether or not to
145 * relocate the vectors.
147 * NOTE: We expect the vector page to be mapped at its expected
151 extern unsigned int page0[], page0_data[];
153 arm_vector_init(vm_offset_t va, int which)
155 unsigned int *vectors = (int *) va;
156 unsigned int *vectors_data = vectors + (page0_data - page0);
160 * Loop through the vectors we're taking over, and copy the
161 * vector's insn and data word.
163 for (vec = 0; vec < ARM_NVEC; vec++) {
164 if ((which & (1 << vec)) == 0) {
165 /* Don't want to take over this vector. */
168 vectors[vec] = page0[vec];
169 vectors_data[vec] = page0_data[vec];
172 /* Now sync the vectors. */
173 icache_sync(va, (ARM_NVEC * 2) * sizeof(u_int));
179 cpu_startup(void *dummy)
181 struct pcb *pcb = thread0.td_pcb;
182 const unsigned int mbyte = 1024 * 1024;
186 vm_ksubmap_init(&kmi);
189 * Display the RAM layout.
191 printf("real memory = %ju (%ju MB)\n",
192 (uintmax_t)arm32_ptob(realmem),
193 (uintmax_t)arm32_ptob(realmem) / mbyte);
194 printf("avail memory = %ju (%ju MB)\n",
195 (uintmax_t)arm32_ptob(vm_free_count()),
196 (uintmax_t)arm32_ptob(vm_free_count()) / mbyte);
198 physmem_print_tables();
199 devmap_print_table();
203 vm_pager_bufferinit();
204 pcb->pcb_regs.sf_sp = (u_int)thread0.td_kstack +
205 USPACE_SVC_STACK_TOP;
206 pmap_set_pcb_pagedir(kernel_pmap, pcb);
209 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
212 * Flush the D-cache for non-DMA I/O so that the I-cache can
213 * be made coherent later.
216 cpu_flush_dcache(void *ptr, size_t len)
219 dcache_wb_poc((vm_offset_t)ptr, (vm_paddr_t)vtophys(ptr), len);
222 /* Get current clock frequency for the given cpu id. */
224 cpu_est_clockrate(int cpu_id, uint64_t *rate)
228 pc = pcpu_find(cpu_id);
229 if (pc == NULL || rate == NULL)
232 if (pc->pc_clock == 0)
235 *rate = pc->pc_clock;
244 CTR2(KTR_SPARE2, "cpu_idle(%d) at %d", busy, curcpu);
248 if (!sched_runnable())
253 CTR2(KTR_SPARE2, "cpu_idle(%d) at %d done", busy, curcpu);
257 cpu_idle_wakeup(int cpu)
268 if (PCPU_GET(cpuid) == 0)
269 cpu_initclocks_bsp();
273 cpu_initclocks_bsp();
279 arm_set_delay(delay_func *impl, void *arg)
282 KASSERT(impl != NULL, ("No DELAY implementation"));
292 delay_impl(usec, delay_arg);
298 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
301 pcpu->pc_mpidr = 0xffffffff;
311 if (td->td_md.md_spinlock_count == 0) {
312 cspr = disable_interrupts(PSR_I | PSR_F);
313 td->td_md.md_spinlock_count = 1;
314 td->td_md.md_saved_cspr = cspr;
317 td->td_md.md_spinlock_count++;
327 cspr = td->td_md.md_saved_cspr;
328 td->td_md.md_spinlock_count--;
329 if (td->td_md.md_spinlock_count == 0) {
331 restore_interrupts(cspr);
336 * Clear registers on exec
339 exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
341 struct trapframe *tf = td->td_frame;
343 memset(tf, 0, sizeof(*tf));
344 tf->tf_usr_sp = stack;
345 tf->tf_usr_lr = imgp->entry_addr;
346 tf->tf_svc_lr = 0x77777777;
347 tf->tf_pc = imgp->entry_addr;
348 tf->tf_spsr = PSR_USR32_MODE;
349 if ((register_t)imgp->entry_addr & 1)
350 tf->tf_spsr |= PSR_T;
355 * Get machine VFP context.
358 get_vfpcontext(struct thread *td, mcontext_vfp_t *vfp)
363 if (td == curthread) {
365 vfp_store(&pcb->pcb_vfpstate, false);
368 MPASS(TD_IS_SUSPENDED(td));
369 memcpy(vfp->mcv_reg, pcb->pcb_vfpstate.reg,
370 sizeof(vfp->mcv_reg));
371 vfp->mcv_fpscr = pcb->pcb_vfpstate.fpscr;
375 * Set machine VFP context.
378 set_vfpcontext(struct thread *td, mcontext_vfp_t *vfp)
383 if (td == curthread) {
388 MPASS(TD_IS_SUSPENDED(td));
389 memcpy(pcb->pcb_vfpstate.reg, vfp->mcv_reg,
390 sizeof(pcb->pcb_vfpstate.reg));
391 pcb->pcb_vfpstate.fpscr = vfp->mcv_fpscr;
396 arm_get_vfpstate(struct thread *td, void *args)
399 struct arm_get_vfpstate_args ua;
400 mcontext_vfp_t mcontext_vfp;
402 rv = copyin(args, &ua, sizeof(ua));
405 if (ua.mc_vfp_size != sizeof(mcontext_vfp_t))
408 get_vfpcontext(td, &mcontext_vfp);
410 bzero(&mcontext_vfp, sizeof(mcontext_vfp));
413 rv = copyout(&mcontext_vfp, ua.mc_vfp, sizeof(mcontext_vfp));
420 * Get machine context.
423 get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
425 struct trapframe *tf = td->td_frame;
426 __greg_t *gr = mcp->__gregs;
428 if (clear_ret & GET_MC_CLEAR_RET) {
430 gr[_REG_CPSR] = tf->tf_spsr & ~PSR_C;
432 gr[_REG_R0] = tf->tf_r0;
433 gr[_REG_CPSR] = tf->tf_spsr;
435 gr[_REG_R1] = tf->tf_r1;
436 gr[_REG_R2] = tf->tf_r2;
437 gr[_REG_R3] = tf->tf_r3;
438 gr[_REG_R4] = tf->tf_r4;
439 gr[_REG_R5] = tf->tf_r5;
440 gr[_REG_R6] = tf->tf_r6;
441 gr[_REG_R7] = tf->tf_r7;
442 gr[_REG_R8] = tf->tf_r8;
443 gr[_REG_R9] = tf->tf_r9;
444 gr[_REG_R10] = tf->tf_r10;
445 gr[_REG_R11] = tf->tf_r11;
446 gr[_REG_R12] = tf->tf_r12;
447 gr[_REG_SP] = tf->tf_usr_sp;
448 gr[_REG_LR] = tf->tf_usr_lr;
449 gr[_REG_PC] = tf->tf_pc;
451 mcp->mc_vfp_size = 0;
452 mcp->mc_vfp_ptr = NULL;
453 memset(&mcp->mc_spare, 0, sizeof(mcp->mc_spare));
459 * Set machine context.
461 * However, we don't set any but the user modifiable flags, and we won't
462 * touch the cs selector.
465 set_mcontext(struct thread *td, mcontext_t *mcp)
467 mcontext_vfp_t mc_vfp, *vfp;
468 struct trapframe *tf = td->td_frame;
469 const __greg_t *gr = mcp->__gregs;
473 * Make sure the processor mode has not been tampered with and
474 * interrupts have not been disabled.
476 spsr = gr[_REG_CPSR];
477 if ((spsr & PSR_MODE) != PSR_USR32_MODE ||
478 (spsr & (PSR_I | PSR_F)) != 0)
482 if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_size != sizeof(mc_vfp)) {
483 printf("%s: %s: Malformed mc_vfp_size: %d (0x%08X)\n",
484 td->td_proc->p_comm, __func__,
485 mcp->mc_vfp_size, mcp->mc_vfp_size);
486 } else if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_ptr == NULL) {
487 printf("%s: %s: c_vfp_size != 0 but mc_vfp_ptr == NULL\n",
488 td->td_proc->p_comm, __func__);
492 if (mcp->mc_vfp_size == sizeof(mc_vfp) && mcp->mc_vfp_ptr != NULL) {
493 if (copyin(mcp->mc_vfp_ptr, &mc_vfp, sizeof(mc_vfp)) != 0)
500 tf->tf_r0 = gr[_REG_R0];
501 tf->tf_r1 = gr[_REG_R1];
502 tf->tf_r2 = gr[_REG_R2];
503 tf->tf_r3 = gr[_REG_R3];
504 tf->tf_r4 = gr[_REG_R4];
505 tf->tf_r5 = gr[_REG_R5];
506 tf->tf_r6 = gr[_REG_R6];
507 tf->tf_r7 = gr[_REG_R7];
508 tf->tf_r8 = gr[_REG_R8];
509 tf->tf_r9 = gr[_REG_R9];
510 tf->tf_r10 = gr[_REG_R10];
511 tf->tf_r11 = gr[_REG_R11];
512 tf->tf_r12 = gr[_REG_R12];
513 tf->tf_usr_sp = gr[_REG_SP];
514 tf->tf_usr_lr = gr[_REG_LR];
515 tf->tf_pc = gr[_REG_PC];
516 tf->tf_spsr = gr[_REG_CPSR];
519 set_vfpcontext(td, vfp);
525 sendsig(catcher, ksi, mask)
532 struct trapframe *tf;
533 struct sigframe *fp, frame;
535 struct sysentvec *sysent;
542 PROC_LOCK_ASSERT(p, MA_OWNED);
543 sig = ksi->ksi_signo;
544 code = ksi->ksi_code;
546 mtx_assert(&psp->ps_mtx, MA_OWNED);
548 onstack = sigonstack(tf->tf_usr_sp);
550 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
553 /* Allocate and validate space for the signal handler context. */
554 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !(onstack) &&
555 SIGISMEMBER(psp->ps_sigonstack, sig)) {
556 fp = (struct sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
557 td->td_sigstk.ss_size);
558 #if defined(COMPAT_43)
559 td->td_sigstk.ss_flags |= SS_ONSTACK;
562 fp = (struct sigframe *)td->td_frame->tf_usr_sp;
564 /* make room on the stack */
567 /* make the stack aligned */
568 fp = (struct sigframe *)STACKALIGN(fp);
569 /* Populate the siginfo frame. */
570 bzero(&frame, sizeof(frame));
571 get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
573 get_vfpcontext(td, &frame.sf_vfp);
574 frame.sf_uc.uc_mcontext.mc_vfp_size = sizeof(fp->sf_vfp);
575 frame.sf_uc.uc_mcontext.mc_vfp_ptr = &fp->sf_vfp;
577 frame.sf_uc.uc_mcontext.mc_vfp_size = 0;
578 frame.sf_uc.uc_mcontext.mc_vfp_ptr = NULL;
580 frame.sf_si = ksi->ksi_info;
581 frame.sf_uc.uc_sigmask = *mask;
582 frame.sf_uc.uc_stack = td->td_sigstk;
583 frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ?
584 (onstack ? SS_ONSTACK : 0) : SS_DISABLE;
585 mtx_unlock(&psp->ps_mtx);
586 PROC_UNLOCK(td->td_proc);
588 /* Copy the sigframe out to the user's stack. */
589 if (copyout(&frame, fp, sizeof(*fp)) != 0) {
590 /* Process has trashed its stack. Kill it. */
591 CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp);
597 * Build context to run handler in. We invoke the handler
598 * directly, only returning via the trampoline. Note the
599 * trampoline version numbers are coordinated with machine-
600 * dependent code in libc.
604 tf->tf_r1 = (register_t)&fp->sf_si;
605 tf->tf_r2 = (register_t)&fp->sf_uc;
607 /* the trampoline uses r5 as the uc address */
608 tf->tf_r5 = (register_t)&fp->sf_uc;
609 tf->tf_pc = (register_t)catcher;
610 tf->tf_usr_sp = (register_t)fp;
611 sysent = p->p_sysent;
612 if (sysent->sv_sigcode_base != 0)
613 tf->tf_usr_lr = (register_t)sysent->sv_sigcode_base;
615 tf->tf_usr_lr = (register_t)(sysent->sv_psstrings -
616 *(sysent->sv_szsigcode));
617 /* Set the mode to enter in the signal handler */
619 if ((register_t)catcher & 1)
620 tf->tf_spsr |= PSR_T;
622 tf->tf_spsr &= ~PSR_T;
625 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_usr_lr,
629 mtx_lock(&psp->ps_mtx);
633 sys_sigreturn(td, uap)
635 struct sigreturn_args /* {
636 const struct __ucontext *sigcntxp;
644 if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
646 /* Restore register context. */
647 error = set_mcontext(td, &uc.uc_mcontext);
651 /* Restore signal mask. */
652 kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
654 return (EJUSTRETURN);
658 * Construct a PCB from a trapframe. This is called from kdb_trap() where
659 * we want to start a backtrace from the function that caused us to enter
660 * the debugger. We have the context in the trapframe, but base the trace
661 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
662 * enough for a backtrace.
665 makectx(struct trapframe *tf, struct pcb *pcb)
667 pcb->pcb_regs.sf_r4 = tf->tf_r4;
668 pcb->pcb_regs.sf_r5 = tf->tf_r5;
669 pcb->pcb_regs.sf_r6 = tf->tf_r6;
670 pcb->pcb_regs.sf_r7 = tf->tf_r7;
671 pcb->pcb_regs.sf_r8 = tf->tf_r8;
672 pcb->pcb_regs.sf_r9 = tf->tf_r9;
673 pcb->pcb_regs.sf_r10 = tf->tf_r10;
674 pcb->pcb_regs.sf_r11 = tf->tf_r11;
675 pcb->pcb_regs.sf_r12 = tf->tf_r12;
676 pcb->pcb_regs.sf_pc = tf->tf_pc;
677 pcb->pcb_regs.sf_lr = tf->tf_usr_lr;
678 pcb->pcb_regs.sf_sp = tf->tf_usr_sp;
684 set_curthread(&thread0);
685 pcpu_init(pcpup, 0, sizeof(struct pcpu));
686 pcpup->pc_mpidr = cp15_mpidr_get() & 0xFFFFFF;
687 PCPU_SET(curthread, &thread0);
694 init_proc0(vm_offset_t kstack)
696 proc_linkup0(&proc0, &thread0);
697 thread0.td_kstack = kstack;
698 thread0.td_kstack_pages = kstack_pages;
699 thread0.td_pcb = (struct pcb *)(thread0.td_kstack +
700 thread0.td_kstack_pages * PAGE_SIZE) - 1;
701 thread0.td_pcb->pcb_flags = 0;
702 thread0.td_pcb->pcb_vfpcpu = -1;
703 thread0.td_pcb->pcb_vfpstate.fpscr = VFPSCR_DN;
704 thread0.td_frame = &proc0_tf;
705 pcpup->pc_curpcb = thread0.td_pcb;
709 set_stackptrs(int cpu)
712 set_stackptr(PSR_IRQ32_MODE,
713 irqstack + ((IRQ_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
714 set_stackptr(PSR_ABT32_MODE,
715 abtstack + ((ABT_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
716 set_stackptr(PSR_UND32_MODE,
717 undstack + ((UND_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
726 if (boothowto & RB_KDB)
727 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
733 initarm(struct arm_boot_params *abp)
735 struct mem_region mem_regions[FDT_MEM_REGIONS];
737 vm_offset_t dtbp, kernelstack, dpcpu;
740 int err_devmap, mem_regions_sz;
742 char dts_version[255];
744 struct efi_map_header *efihdr;
747 /* get last allocated physical address */
748 arm_physmem_kernaddr = abp->abp_physaddr;
749 lastaddr = parse_boot_param(abp) - KERNVIRTADDR + arm_physmem_kernaddr;
755 * Find the dtb passed in by the boot loader.
757 kmdp = preload_search_by_type("elf kernel");
758 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
759 #if defined(FDT_DTB_STATIC)
761 * In case the device tree blob was not retrieved (from metadata) try
762 * to use the statically embedded one.
764 if (dtbp == (vm_offset_t)NULL)
765 dtbp = (vm_offset_t)&fdt_static_dtb;
768 if (OF_install(OFW_FDT, 0) == FALSE)
769 panic("Cannot install FDT");
771 if (OF_init((void *)dtbp) != 0)
772 panic("OF_init failed with the found device tree");
774 #if defined(LINUX_BOOT_ABI)
775 arm_parse_fdt_bootargs();
779 efihdr = (struct efi_map_header *)preload_search_info(kmdp,
780 MODINFO_METADATA | MODINFOMD_EFI_MAP);
781 if (efihdr != NULL) {
782 arm_add_efi_map_entries(efihdr, mem_regions, &mem_regions_sz);
786 /* Grab physical memory regions information from device tree. */
787 if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,NULL) != 0)
788 panic("Cannot get physical memory regions");
790 physmem_hardware_regions(mem_regions, mem_regions_sz);
792 /* Grab reserved memory regions information from device tree. */
793 if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
794 physmem_exclude_regions(mem_regions, mem_regions_sz,
795 EXFLAG_NODUMP | EXFLAG_NOALLOC);
798 * Set TEX remapping registers.
799 * Setup kernel page tables and switch to kernel L1 page table.
802 pmap_bootstrap_prepare(lastaddr);
805 * If EARLY_PRINTF support is enabled, we need to re-establish the
806 * mapping after pmap_bootstrap_prepare() switches to new page tables.
807 * Note that we can only do the remapping if the VA is outside the
808 * kernel, now that we have real virtual (not VA=PA) mappings in effect.
809 * Early printf does not work between the time pmap_set_tex() does
810 * cp15_prrr_set() and this code remaps the VA.
812 #if defined(EARLY_PRINTF) && defined(SOCDEV_PA) && defined(SOCDEV_VA) && SOCDEV_VA < KERNBASE
813 pmap_preboot_map_attr(SOCDEV_PA, SOCDEV_VA, 1024 * 1024,
814 VM_PROT_READ | VM_PROT_WRITE, VM_MEMATTR_DEVICE);
818 * Now that proper page tables are installed, call cpu_setup() to enable
819 * instruction and data caches and other chip-specific features.
823 /* Platform-specific initialisation */
824 platform_probe_and_attach();
827 /* Do basic tuning, hz etc */
831 * Allocate a page for the system page mapped to 0xffff0000
832 * This page will just contain the system vectors and can be
833 * shared by all processes.
835 systempage = pmap_preboot_get_pages(1);
837 /* Map the vector page. */
838 pmap_preboot_map_pages(systempage, ARM_VECTORS_HIGH, 1);
839 if (virtual_end >= ARM_VECTORS_HIGH)
840 virtual_end = ARM_VECTORS_HIGH - 1;
842 /* Allocate dynamic per-cpu area. */
843 dpcpu = pmap_preboot_get_vpages(DPCPU_SIZE / PAGE_SIZE);
844 dpcpu_init((void *)dpcpu, 0);
846 /* Allocate stacks for all modes */
847 irqstack = pmap_preboot_get_vpages(IRQ_STACK_SIZE * MAXCPU);
848 abtstack = pmap_preboot_get_vpages(ABT_STACK_SIZE * MAXCPU);
849 undstack = pmap_preboot_get_vpages(UND_STACK_SIZE * MAXCPU );
850 kernelstack = pmap_preboot_get_vpages(kstack_pages);
852 /* Allocate message buffer. */
853 msgbufp = (void *)pmap_preboot_get_vpages(
854 round_page(msgbufsize) / PAGE_SIZE);
857 * Pages were allocated during the secondary bootstrap for the
858 * stacks for different CPU modes.
859 * We must now set the r13 registers in the different CPU modes to
860 * point to these stacks.
861 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
862 * of the stack memory.
867 /* Establish static device mappings. */
868 err_devmap = platform_devmap_init();
869 devmap_bootstrap(0, NULL);
870 vm_max_kernel_address = platform_lastaddr();
873 * Only after the SOC registers block is mapped we can perform device
874 * tree fixups, as they may attempt to read parameters from hardware.
876 OF_interpret("perform-fixup", 0);
877 platform_gpio_init();
881 * If we made a mapping for EARLY_PRINTF after pmap_bootstrap_prepare(),
882 * undo it now that the normal console printf works.
884 #if defined(EARLY_PRINTF) && defined(SOCDEV_PA) && defined(SOCDEV_VA) && SOCDEV_VA < KERNBASE
885 pmap_kremove(SOCDEV_VA);
888 debugf("initarm: console initialized\n");
889 debugf(" arg1 kmdp = 0x%08x\n", (uint32_t)kmdp);
890 debugf(" boothowto = 0x%08x\n", boothowto);
891 debugf(" dtbp = 0x%08x\n", (uint32_t)dtbp);
892 debugf(" lastaddr1: 0x%08x\n", lastaddr);
895 env = kern_getenv("kernelname");
897 strlcpy(kernelname, env, sizeof(kernelname));
900 printf("WARNING: could not fully configure devmap, error=%d\n",
903 platform_late_init();
905 root = OF_finddevice("/");
906 if (OF_getprop(root, "freebsd,dts-version", dts_version, sizeof(dts_version)) > 0) {
907 if (strcmp(LINUX_DTS_VERSION, dts_version) != 0)
908 printf("WARNING: DTB version is %s while kernel expects %s, "
909 "please update the DTB in the ESP\n",
913 printf("WARNING: Cannot find freebsd,dts-version property, "
914 "cannot check DTB compliance\n");
918 * We must now clean the cache again....
919 * Cleaning may be done by reading new data to displace any
920 * dirty data in the cache. This will have happened in cpu_setttb()
921 * but since we are boot strapping the addresses used for the read
922 * may have just been remapped and thus the cache could be out
923 * of sync. A re-clean after the switch will cure this.
924 * After booting there are no gross relocations of the kernel thus
925 * this problem will not occur after initarm().
927 /* Set stack for exception handlers */
929 init_proc0(kernelstack);
930 arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
931 enable_interrupts(PSR_A);
934 /* Exclude the kernel (and all the things we allocated which immediately
935 * follow the kernel) from the VM allocation pool but not from crash
936 * dumps. virtual_avail is a global variable which tracks the kva we've
937 * "allocated" while setting up pmaps.
939 * Prepare the list of physical memory available to the vm subsystem.
941 physmem_exclude_region(abp->abp_physaddr,
942 pmap_preboot_get_pages(0) - abp->abp_physaddr, EXFLAG_NOALLOC);
943 physmem_init_kernel_globals();
945 init_param2(physmem);
946 /* Init message buffer. */
947 msgbufinit(msgbufp, msgbufsize);
950 /* Apply possible BP hardening. */
951 cpuinfo_init_bp_hardening();
952 return ((void *)STACKALIGN(thread0.td_pcb));