machdep.c revision 331988
1/*	$NetBSD: arm32_machdep.c,v 1.44 2004/03/24 15:34:47 atatat Exp $	*/
2
3/*-
4 * Copyright (c) 2004 Olivier Houchard
5 * Copyright (c) 1994-1998 Mark Brinicombe.
6 * Copyright (c) 1994 Brini.
7 * All rights reserved.
8 *
9 * This code is derived from software written for Brini by Mark Brinicombe
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *	This product includes software developed by Mark Brinicombe
22 *	for the NetBSD Project.
23 * 4. The name of the company nor the name of the author may be used to
24 *    endorse or promote products derived from this software without specific
25 *    prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
28 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * Machine dependent functions for kernel setup
40 *
41 * Created      : 17/09/94
42 * Updated	: 18/04/01 updated for new wscons
43 */
44
45#include "opt_compat.h"
46#include "opt_ddb.h"
47#include "opt_kstack_pages.h"
48#include "opt_platform.h"
49#include "opt_sched.h"
50#include "opt_timer.h"
51
52#include <sys/cdefs.h>
53__FBSDID("$FreeBSD: stable/11/sys/arm/arm/machdep.c 331988 2018-04-04 06:11:05Z mmel $");
54
55#include <sys/param.h>
56#include <sys/buf.h>
57#include <sys/bus.h>
58#include <sys/cons.h>
59#include <sys/cpu.h>
60#include <sys/devmap.h>
61#include <sys/efi.h>
62#include <sys/imgact.h>
63#include <sys/kdb.h>
64#include <sys/kernel.h>
65#include <sys/linker.h>
66#include <sys/msgbuf.h>
67#include <sys/reboot.h>
68#include <sys/rwlock.h>
69#include <sys/sched.h>
70#include <sys/syscallsubr.h>
71#include <sys/sysent.h>
72#include <sys/sysproto.h>
73#include <sys/vmmeter.h>
74
75#include <vm/vm_object.h>
76#include <vm/vm_page.h>
77#include <vm/vm_pager.h>
78
79#include <machine/debug_monitor.h>
80#include <machine/machdep.h>
81#include <machine/metadata.h>
82#include <machine/pcb.h>
83#include <machine/physmem.h>
84#include <machine/platform.h>
85#include <machine/sysarch.h>
86#include <machine/undefined.h>
87#include <machine/vfp.h>
88#include <machine/vmparam.h>
89
90#ifdef FDT
91#include <dev/fdt/fdt_common.h>
92#include <machine/ofw_machdep.h>
93#endif
94
95#ifdef DEBUG
96#define	debugf(fmt, args...) printf(fmt, ##args)
97#else
98#define	debugf(fmt, args...)
99#endif
100
101#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
102    defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \
103    defined(COMPAT_FREEBSD9)
104#error FreeBSD/arm doesn't provide compatibility with releases prior to 10
105#endif
106
107struct pcpu __pcpu[MAXCPU];
108struct pcpu *pcpup = &__pcpu[0];
109
110static struct trapframe proc0_tf;
111uint32_t cpu_reset_address = 0;
112int cold = 1;
113vm_offset_t vector_page;
114
115int (*_arm_memcpy)(void *, void *, int, int) = NULL;
116int (*_arm_bzero)(void *, int, int) = NULL;
117int _min_memcpy_size = 0;
118int _min_bzero_size = 0;
119
120extern int *end;
121
122#ifdef FDT
123vm_paddr_t pmap_pa;
124#if __ARM_ARCH >= 6
125vm_offset_t systempage;
126vm_offset_t irqstack;
127vm_offset_t undstack;
128vm_offset_t abtstack;
129#else
130/*
131 * This is the number of L2 page tables required for covering max
132 * (hypothetical) memsize of 4GB and all kernel mappings (vectors, msgbuf,
133 * stacks etc.), uprounded to be divisible by 4.
134 */
135#define KERNEL_PT_MAX	78
136static struct pv_addr kernel_pt_table[KERNEL_PT_MAX];
137struct pv_addr systempage;
138static struct pv_addr msgbufpv;
139struct pv_addr irqstack;
140struct pv_addr undstack;
141struct pv_addr abtstack;
142static struct pv_addr kernelstack;
143#endif /* __ARM_ARCH >= 6 */
144#endif /* FDT */
145
146#ifdef MULTIDELAY
147static delay_func *delay_impl;
148static void *delay_arg;
149#endif
150
151struct kva_md_info kmi;
152
153/*
154 * arm32_vector_init:
155 *
156 *	Initialize the vector page, and select whether or not to
157 *	relocate the vectors.
158 *
159 *	NOTE: We expect the vector page to be mapped at its expected
160 *	destination.
161 */
162
163extern unsigned int page0[], page0_data[];
164void
165arm_vector_init(vm_offset_t va, int which)
166{
167	unsigned int *vectors = (int *) va;
168	unsigned int *vectors_data = vectors + (page0_data - page0);
169	int vec;
170
171	/*
172	 * Loop through the vectors we're taking over, and copy the
173	 * vector's insn and data word.
174	 */
175	for (vec = 0; vec < ARM_NVEC; vec++) {
176		if ((which & (1 << vec)) == 0) {
177			/* Don't want to take over this vector. */
178			continue;
179		}
180		vectors[vec] = page0[vec];
181		vectors_data[vec] = page0_data[vec];
182	}
183
184	/* Now sync the vectors. */
185	icache_sync(va, (ARM_NVEC * 2) * sizeof(u_int));
186
187	vector_page = va;
188#if __ARM_ARCH < 6
189	if (va == ARM_VECTORS_HIGH) {
190		/*
191		 * Enable high vectors in the system control reg (SCTLR).
192		 *
193		 * Assume the MD caller knows what it's doing here, and really
194		 * does want the vector page relocated.
195		 *
196		 * Note: This has to be done here (and not just in
197		 * cpu_setup()) because the vector page needs to be
198		 * accessible *before* cpu_startup() is called.
199		 * Think ddb(9) ...
200		 */
201		cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
202	}
203#endif
204}
205
206static void
207cpu_startup(void *dummy)
208{
209	struct pcb *pcb = thread0.td_pcb;
210	const unsigned int mbyte = 1024 * 1024;
211#if __ARM_ARCH < 6 && !defined(ARM_CACHE_LOCK_ENABLE)
212	vm_page_t m;
213#endif
214
215	identify_arm_cpu();
216
217	vm_ksubmap_init(&kmi);
218
219	/*
220	 * Display the RAM layout.
221	 */
222	printf("real memory  = %ju (%ju MB)\n",
223	    (uintmax_t)arm32_ptob(realmem),
224	    (uintmax_t)arm32_ptob(realmem) / mbyte);
225	printf("avail memory = %ju (%ju MB)\n",
226	    (uintmax_t)arm32_ptob(vm_cnt.v_free_count),
227	    (uintmax_t)arm32_ptob(vm_cnt.v_free_count) / mbyte);
228	if (bootverbose) {
229		arm_physmem_print_tables();
230		devmap_print_table();
231	}
232
233	bufinit();
234	vm_pager_bufferinit();
235	pcb->pcb_regs.sf_sp = (u_int)thread0.td_kstack +
236	    USPACE_SVC_STACK_TOP;
237	pmap_set_pcb_pagedir(kernel_pmap, pcb);
238#if __ARM_ARCH < 6
239	vector_page_setprot(VM_PROT_READ);
240	pmap_postinit();
241#ifdef ARM_CACHE_LOCK_ENABLE
242	pmap_kenter_user(ARM_TP_ADDRESS, ARM_TP_ADDRESS);
243	arm_lock_cache_line(ARM_TP_ADDRESS);
244#else
245	m = vm_page_alloc(NULL, 0, VM_ALLOC_NOOBJ | VM_ALLOC_ZERO);
246	pmap_kenter_user(ARM_TP_ADDRESS, VM_PAGE_TO_PHYS(m));
247#endif
248	*(uint32_t *)ARM_RAS_START = 0;
249	*(uint32_t *)ARM_RAS_END = 0xffffffff;
250#endif
251}
252
253SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
254
255/*
256 * Flush the D-cache for non-DMA I/O so that the I-cache can
257 * be made coherent later.
258 */
259void
260cpu_flush_dcache(void *ptr, size_t len)
261{
262
263	dcache_wb_poc((vm_offset_t)ptr, (vm_paddr_t)vtophys(ptr), len);
264}
265
266/* Get current clock frequency for the given cpu id. */
267int
268cpu_est_clockrate(int cpu_id, uint64_t *rate)
269{
270
271	return (ENXIO);
272}
273
274void
275cpu_idle(int busy)
276{
277
278	CTR2(KTR_SPARE2, "cpu_idle(%d) at %d", busy, curcpu);
279	spinlock_enter();
280#ifndef NO_EVENTTIMERS
281	if (!busy)
282		cpu_idleclock();
283#endif
284	if (!sched_runnable())
285		cpu_sleep(0);
286#ifndef NO_EVENTTIMERS
287	if (!busy)
288		cpu_activeclock();
289#endif
290	spinlock_exit();
291	CTR2(KTR_SPARE2, "cpu_idle(%d) at %d done", busy, curcpu);
292}
293
294int
295cpu_idle_wakeup(int cpu)
296{
297
298	return (0);
299}
300
301/*
302 * Most ARM platforms don't need to do anything special to init their clocks
303 * (they get intialized during normal device attachment), and by not defining a
304 * cpu_initclocks() function they get this generic one.  Any platform that needs
305 * to do something special can just provide their own implementation, which will
306 * override this one due to the weak linkage.
307 */
308void
309arm_generic_initclocks(void)
310{
311
312#ifndef NO_EVENTTIMERS
313#ifdef SMP
314	if (PCPU_GET(cpuid) == 0)
315		cpu_initclocks_bsp();
316	else
317		cpu_initclocks_ap();
318#else
319	cpu_initclocks_bsp();
320#endif
321#endif
322}
323__weak_reference(arm_generic_initclocks, cpu_initclocks);
324
325#ifdef MULTIDELAY
326void
327arm_set_delay(delay_func *impl, void *arg)
328{
329
330	KASSERT(impl != NULL, ("No DELAY implementation"));
331	delay_impl = impl;
332	delay_arg = arg;
333}
334
335void
336DELAY(int usec)
337{
338
339	delay_impl(usec, delay_arg);
340}
341#endif
342
343void
344cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
345{
346}
347
348void
349spinlock_enter(void)
350{
351	struct thread *td;
352	register_t cspr;
353
354	td = curthread;
355	if (td->td_md.md_spinlock_count == 0) {
356		cspr = disable_interrupts(PSR_I | PSR_F);
357		td->td_md.md_spinlock_count = 1;
358		td->td_md.md_saved_cspr = cspr;
359	} else
360		td->td_md.md_spinlock_count++;
361	critical_enter();
362}
363
364void
365spinlock_exit(void)
366{
367	struct thread *td;
368	register_t cspr;
369
370	td = curthread;
371	critical_exit();
372	cspr = td->td_md.md_saved_cspr;
373	td->td_md.md_spinlock_count--;
374	if (td->td_md.md_spinlock_count == 0)
375		restore_interrupts(cspr);
376}
377
378/*
379 * Clear registers on exec
380 */
381void
382exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
383{
384	struct trapframe *tf = td->td_frame;
385
386	memset(tf, 0, sizeof(*tf));
387	tf->tf_usr_sp = stack;
388	tf->tf_usr_lr = imgp->entry_addr;
389	tf->tf_svc_lr = 0x77777777;
390	tf->tf_pc = imgp->entry_addr;
391	tf->tf_spsr = PSR_USR32_MODE;
392}
393
394
395#ifdef VFP
396/*
397 * Get machine VFP context.
398 */
399void
400get_vfpcontext(struct thread *td, mcontext_vfp_t *vfp)
401{
402	struct pcb *pcb;
403
404	pcb = td->td_pcb;
405	if (td == curthread) {
406		critical_enter();
407		vfp_store(&pcb->pcb_vfpstate, false);
408		critical_exit();
409	} else
410		MPASS(TD_IS_SUSPENDED(td));
411	memcpy(vfp->mcv_reg, pcb->pcb_vfpstate.reg,
412	    sizeof(vfp->mcv_reg));
413	vfp->mcv_fpscr = pcb->pcb_vfpstate.fpscr;
414}
415
416/*
417 * Set machine VFP context.
418 */
419void
420set_vfpcontext(struct thread *td, mcontext_vfp_t *vfp)
421{
422	struct pcb *pcb;
423
424	pcb = td->td_pcb;
425	if (td == curthread) {
426		critical_enter();
427		vfp_discard(td);
428		critical_exit();
429	} else
430		MPASS(TD_IS_SUSPENDED(td));
431	memcpy(pcb->pcb_vfpstate.reg, vfp->mcv_reg,
432	    sizeof(pcb->pcb_vfpstate.reg));
433	pcb->pcb_vfpstate.fpscr = vfp->mcv_fpscr;
434}
435#endif
436
437int
438arm_get_vfpstate(struct thread *td, void *args)
439{
440	int rv;
441	struct arm_get_vfpstate_args ua;
442	mcontext_vfp_t	mcontext_vfp;
443
444	rv = copyin(args, &ua, sizeof(ua));
445	if (rv != 0)
446		return (rv);
447	if (ua.mc_vfp_size != sizeof(mcontext_vfp_t))
448		return (EINVAL);
449#ifdef VFP
450	get_vfpcontext(td, &mcontext_vfp);
451#else
452	bzero(&mcontext_vfp, sizeof(mcontext_vfp));
453#endif
454
455	rv = copyout(&mcontext_vfp, ua.mc_vfp,  sizeof(mcontext_vfp));
456	if (rv != 0)
457		return (rv);
458	return (0);
459}
460
461/*
462 * Get machine context.
463 */
464int
465get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
466{
467	struct trapframe *tf = td->td_frame;
468	__greg_t *gr = mcp->__gregs;
469
470	if (clear_ret & GET_MC_CLEAR_RET) {
471		gr[_REG_R0] = 0;
472		gr[_REG_CPSR] = tf->tf_spsr & ~PSR_C;
473	} else {
474		gr[_REG_R0]   = tf->tf_r0;
475		gr[_REG_CPSR] = tf->tf_spsr;
476	}
477	gr[_REG_R1]   = tf->tf_r1;
478	gr[_REG_R2]   = tf->tf_r2;
479	gr[_REG_R3]   = tf->tf_r3;
480	gr[_REG_R4]   = tf->tf_r4;
481	gr[_REG_R5]   = tf->tf_r5;
482	gr[_REG_R6]   = tf->tf_r6;
483	gr[_REG_R7]   = tf->tf_r7;
484	gr[_REG_R8]   = tf->tf_r8;
485	gr[_REG_R9]   = tf->tf_r9;
486	gr[_REG_R10]  = tf->tf_r10;
487	gr[_REG_R11]  = tf->tf_r11;
488	gr[_REG_R12]  = tf->tf_r12;
489	gr[_REG_SP]   = tf->tf_usr_sp;
490	gr[_REG_LR]   = tf->tf_usr_lr;
491	gr[_REG_PC]   = tf->tf_pc;
492
493	mcp->mc_vfp_size = 0;
494	mcp->mc_vfp_ptr = NULL;
495	memset(&mcp->mc_spare, 0, sizeof(mcp->mc_spare));
496
497	return (0);
498}
499
500/*
501 * Set machine context.
502 *
503 * However, we don't set any but the user modifiable flags, and we won't
504 * touch the cs selector.
505 */
506int
507set_mcontext(struct thread *td, mcontext_t *mcp)
508{
509	mcontext_vfp_t mc_vfp, *vfp;
510	struct trapframe *tf = td->td_frame;
511	const __greg_t *gr = mcp->__gregs;
512	int spsr;
513
514	/*
515	 * Make sure the processor mode has not been tampered with and
516	 * interrupts have not been disabled.
517	 */
518	spsr = gr[_REG_CPSR];
519	if ((spsr & PSR_MODE) != PSR_USR32_MODE ||
520	    (spsr & (PSR_I | PSR_F)) != 0)
521		return (EINVAL);
522
523#ifdef WITNESS
524	if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_size != sizeof(mc_vfp)) {
525		printf("%s: %s: Malformed mc_vfp_size: %d (0x%08X)\n",
526		    td->td_proc->p_comm, __func__,
527		    mcp->mc_vfp_size, mcp->mc_vfp_size);
528	} else if (mcp->mc_vfp_size != 0 && mcp->mc_vfp_ptr == NULL) {
529		printf("%s: %s: c_vfp_size != 0 but mc_vfp_ptr == NULL\n",
530		    td->td_proc->p_comm, __func__);
531	}
532#endif
533
534	if (mcp->mc_vfp_size == sizeof(mc_vfp) && mcp->mc_vfp_ptr != NULL) {
535		if (copyin(mcp->mc_vfp_ptr, &mc_vfp, sizeof(mc_vfp)) != 0)
536			return (EFAULT);
537		vfp = &mc_vfp;
538	} else {
539		vfp = NULL;
540	}
541
542	tf->tf_r0 = gr[_REG_R0];
543	tf->tf_r1 = gr[_REG_R1];
544	tf->tf_r2 = gr[_REG_R2];
545	tf->tf_r3 = gr[_REG_R3];
546	tf->tf_r4 = gr[_REG_R4];
547	tf->tf_r5 = gr[_REG_R5];
548	tf->tf_r6 = gr[_REG_R6];
549	tf->tf_r7 = gr[_REG_R7];
550	tf->tf_r8 = gr[_REG_R8];
551	tf->tf_r9 = gr[_REG_R9];
552	tf->tf_r10 = gr[_REG_R10];
553	tf->tf_r11 = gr[_REG_R11];
554	tf->tf_r12 = gr[_REG_R12];
555	tf->tf_usr_sp = gr[_REG_SP];
556	tf->tf_usr_lr = gr[_REG_LR];
557	tf->tf_pc = gr[_REG_PC];
558	tf->tf_spsr = gr[_REG_CPSR];
559#ifdef VFP
560	if (vfp != NULL)
561		set_vfpcontext(td, vfp);
562#endif
563	return (0);
564}
565
566void
567sendsig(catcher, ksi, mask)
568	sig_t catcher;
569	ksiginfo_t *ksi;
570	sigset_t *mask;
571{
572	struct thread *td;
573	struct proc *p;
574	struct trapframe *tf;
575	struct sigframe *fp, frame;
576	struct sigacts *psp;
577	struct sysentvec *sysent;
578	int onstack;
579	int sig;
580	int code;
581
582	td = curthread;
583	p = td->td_proc;
584	PROC_LOCK_ASSERT(p, MA_OWNED);
585	sig = ksi->ksi_signo;
586	code = ksi->ksi_code;
587	psp = p->p_sigacts;
588	mtx_assert(&psp->ps_mtx, MA_OWNED);
589	tf = td->td_frame;
590	onstack = sigonstack(tf->tf_usr_sp);
591
592	CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
593	    catcher, sig);
594
595	/* Allocate and validate space for the signal handler context. */
596	if ((td->td_pflags & TDP_ALTSTACK) != 0 && !(onstack) &&
597	    SIGISMEMBER(psp->ps_sigonstack, sig)) {
598		fp = (struct sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
599		    td->td_sigstk.ss_size);
600#if defined(COMPAT_43)
601		td->td_sigstk.ss_flags |= SS_ONSTACK;
602#endif
603	} else
604		fp = (struct sigframe *)td->td_frame->tf_usr_sp;
605
606	/* make room on the stack */
607	fp--;
608
609	/* make the stack aligned */
610	fp = (struct sigframe *)STACKALIGN(fp);
611	/* Populate the siginfo frame. */
612	get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
613#ifdef VFP
614	get_vfpcontext(td, &frame.sf_vfp);
615	frame.sf_uc.uc_mcontext.mc_vfp_size = sizeof(fp->sf_vfp);
616	frame.sf_uc.uc_mcontext.mc_vfp_ptr = &fp->sf_vfp;
617#else
618	frame.sf_uc.uc_mcontext.mc_vfp_size = 0;
619	frame.sf_uc.uc_mcontext.mc_vfp_ptr = NULL;
620#endif
621	frame.sf_si = ksi->ksi_info;
622	frame.sf_uc.uc_sigmask = *mask;
623	frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK )
624	    ? ((onstack) ? SS_ONSTACK : 0) : SS_DISABLE;
625	frame.sf_uc.uc_stack = td->td_sigstk;
626	mtx_unlock(&psp->ps_mtx);
627	PROC_UNLOCK(td->td_proc);
628
629	/* Copy the sigframe out to the user's stack. */
630	if (copyout(&frame, fp, sizeof(*fp)) != 0) {
631		/* Process has trashed its stack. Kill it. */
632		CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp);
633		PROC_LOCK(p);
634		sigexit(td, SIGILL);
635	}
636
637	/*
638	 * Build context to run handler in.  We invoke the handler
639	 * directly, only returning via the trampoline.  Note the
640	 * trampoline version numbers are coordinated with machine-
641	 * dependent code in libc.
642	 */
643
644	tf->tf_r0 = sig;
645	tf->tf_r1 = (register_t)&fp->sf_si;
646	tf->tf_r2 = (register_t)&fp->sf_uc;
647
648	/* the trampoline uses r5 as the uc address */
649	tf->tf_r5 = (register_t)&fp->sf_uc;
650	tf->tf_pc = (register_t)catcher;
651	tf->tf_usr_sp = (register_t)fp;
652	sysent = p->p_sysent;
653	if (sysent->sv_sigcode_base != 0)
654		tf->tf_usr_lr = (register_t)sysent->sv_sigcode_base;
655	else
656		tf->tf_usr_lr = (register_t)(sysent->sv_psstrings -
657		    *(sysent->sv_szsigcode));
658	/* Set the mode to enter in the signal handler */
659#if __ARM_ARCH >= 7
660	if ((register_t)catcher & 1)
661		tf->tf_spsr |= PSR_T;
662	else
663		tf->tf_spsr &= ~PSR_T;
664#endif
665
666	CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_usr_lr,
667	    tf->tf_usr_sp);
668
669	PROC_LOCK(p);
670	mtx_lock(&psp->ps_mtx);
671}
672
673int
674sys_sigreturn(td, uap)
675	struct thread *td;
676	struct sigreturn_args /* {
677		const struct __ucontext *sigcntxp;
678	} */ *uap;
679{
680	ucontext_t uc;
681	int error;
682
683	if (uap == NULL)
684		return (EFAULT);
685	if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
686		return (EFAULT);
687	/* Restore register context. */
688	error = set_mcontext(td, &uc.uc_mcontext);
689	if (error != 0)
690		return (error);
691
692	/* Restore signal mask. */
693	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
694
695	return (EJUSTRETURN);
696}
697
698/*
699 * Construct a PCB from a trapframe. This is called from kdb_trap() where
700 * we want to start a backtrace from the function that caused us to enter
701 * the debugger. We have the context in the trapframe, but base the trace
702 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
703 * enough for a backtrace.
704 */
705void
706makectx(struct trapframe *tf, struct pcb *pcb)
707{
708	pcb->pcb_regs.sf_r4 = tf->tf_r4;
709	pcb->pcb_regs.sf_r5 = tf->tf_r5;
710	pcb->pcb_regs.sf_r6 = tf->tf_r6;
711	pcb->pcb_regs.sf_r7 = tf->tf_r7;
712	pcb->pcb_regs.sf_r8 = tf->tf_r8;
713	pcb->pcb_regs.sf_r9 = tf->tf_r9;
714	pcb->pcb_regs.sf_r10 = tf->tf_r10;
715	pcb->pcb_regs.sf_r11 = tf->tf_r11;
716	pcb->pcb_regs.sf_r12 = tf->tf_r12;
717	pcb->pcb_regs.sf_pc = tf->tf_pc;
718	pcb->pcb_regs.sf_lr = tf->tf_usr_lr;
719	pcb->pcb_regs.sf_sp = tf->tf_usr_sp;
720}
721
722void
723pcpu0_init(void)
724{
725#if __ARM_ARCH >= 6
726	set_curthread(&thread0);
727#endif
728	pcpu_init(pcpup, 0, sizeof(struct pcpu));
729	PCPU_SET(curthread, &thread0);
730}
731
732/*
733 * Initialize proc0
734 */
735void
736init_proc0(vm_offset_t kstack)
737{
738	proc_linkup0(&proc0, &thread0);
739	thread0.td_kstack = kstack;
740	thread0.td_pcb = (struct pcb *)
741		(thread0.td_kstack + kstack_pages * PAGE_SIZE) - 1;
742	thread0.td_pcb->pcb_flags = 0;
743	thread0.td_pcb->pcb_vfpcpu = -1;
744	thread0.td_pcb->pcb_vfpstate.fpscr = VFPSCR_DN;
745	thread0.td_frame = &proc0_tf;
746	pcpup->pc_curpcb = thread0.td_pcb;
747}
748
749#if __ARM_ARCH >= 6
750void
751set_stackptrs(int cpu)
752{
753
754	set_stackptr(PSR_IRQ32_MODE,
755	    irqstack + ((IRQ_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
756	set_stackptr(PSR_ABT32_MODE,
757	    abtstack + ((ABT_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
758	set_stackptr(PSR_UND32_MODE,
759	    undstack + ((UND_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
760}
761#else
762void
763set_stackptrs(int cpu)
764{
765
766	set_stackptr(PSR_IRQ32_MODE,
767	    irqstack.pv_va + ((IRQ_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
768	set_stackptr(PSR_ABT32_MODE,
769	    abtstack.pv_va + ((ABT_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
770	set_stackptr(PSR_UND32_MODE,
771	    undstack.pv_va + ((UND_STACK_SIZE * PAGE_SIZE) * (cpu + 1)));
772}
773#endif
774
775static void
776arm_kdb_init(void)
777{
778
779	kdb_init();
780#ifdef KDB
781	if (boothowto & RB_KDB)
782		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
783#endif
784}
785
786#ifdef FDT
787#if __ARM_ARCH < 6
788void *
789initarm(struct arm_boot_params *abp)
790{
791	struct mem_region mem_regions[FDT_MEM_REGIONS];
792	struct pv_addr kernel_l1pt;
793	struct pv_addr dpcpu;
794	vm_offset_t dtbp, freemempos, l2_start, lastaddr;
795	uint64_t memsize;
796	uint32_t l2size;
797	char *env;
798	void *kmdp;
799	u_int l1pagetable;
800	int i, j, err_devmap, mem_regions_sz;
801
802	lastaddr = parse_boot_param(abp);
803	arm_physmem_kernaddr = abp->abp_physaddr;
804
805	memsize = 0;
806
807	cpuinfo_init();
808	set_cpufuncs();
809
810	/*
811	 * Find the dtb passed in by the boot loader.
812	 */
813	kmdp = preload_search_by_type("elf kernel");
814	if (kmdp != NULL)
815		dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
816	else
817		dtbp = (vm_offset_t)NULL;
818
819#if defined(FDT_DTB_STATIC)
820	/*
821	 * In case the device tree blob was not retrieved (from metadata) try
822	 * to use the statically embedded one.
823	 */
824	if (dtbp == (vm_offset_t)NULL)
825		dtbp = (vm_offset_t)&fdt_static_dtb;
826#endif
827
828	if (OF_install(OFW_FDT, 0) == FALSE)
829		panic("Cannot install FDT");
830
831	if (OF_init((void *)dtbp) != 0)
832		panic("OF_init failed with the found device tree");
833
834	/* Grab physical memory regions information from device tree. */
835	if (fdt_get_mem_regions(mem_regions, &mem_regions_sz, &memsize) != 0)
836		panic("Cannot get physical memory regions");
837	arm_physmem_hardware_regions(mem_regions, mem_regions_sz);
838
839	/* Grab reserved memory regions information from device tree. */
840	if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
841		arm_physmem_exclude_regions(mem_regions, mem_regions_sz,
842		    EXFLAG_NODUMP | EXFLAG_NOALLOC);
843
844	/* Platform-specific initialisation */
845	platform_probe_and_attach();
846
847	pcpu0_init();
848
849	/* Do basic tuning, hz etc */
850	init_param1();
851
852	/* Calculate number of L2 tables needed for mapping vm_page_array */
853	l2size = (memsize / PAGE_SIZE) * sizeof(struct vm_page);
854	l2size = (l2size >> L1_S_SHIFT) + 1;
855
856	/*
857	 * Add one table for end of kernel map, one for stacks, msgbuf and
858	 * L1 and L2 tables map and one for vectors map.
859	 */
860	l2size += 3;
861
862	/* Make it divisible by 4 */
863	l2size = (l2size + 3) & ~3;
864
865	freemempos = (lastaddr + PAGE_MASK) & ~PAGE_MASK;
866
867	/* Define a macro to simplify memory allocation */
868#define valloc_pages(var, np)						\
869	alloc_pages((var).pv_va, (np));					\
870	(var).pv_pa = (var).pv_va + (abp->abp_physaddr - KERNVIRTADDR);
871
872#define alloc_pages(var, np)						\
873	(var) = freemempos;						\
874	freemempos += (np * PAGE_SIZE);					\
875	memset((char *)(var), 0, ((np) * PAGE_SIZE));
876
877	while (((freemempos - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) != 0)
878		freemempos += PAGE_SIZE;
879	valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
880
881	for (i = 0, j = 0; i < l2size; ++i) {
882		if (!(i % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
883			valloc_pages(kernel_pt_table[i],
884			    L2_TABLE_SIZE / PAGE_SIZE);
885			j = i;
886		} else {
887			kernel_pt_table[i].pv_va = kernel_pt_table[j].pv_va +
888			    L2_TABLE_SIZE_REAL * (i - j);
889			kernel_pt_table[i].pv_pa =
890			    kernel_pt_table[i].pv_va - KERNVIRTADDR +
891			    abp->abp_physaddr;
892
893		}
894	}
895	/*
896	 * Allocate a page for the system page mapped to 0x00000000
897	 * or 0xffff0000. This page will just contain the system vectors
898	 * and can be shared by all processes.
899	 */
900	valloc_pages(systempage, 1);
901
902	/* Allocate dynamic per-cpu area. */
903	valloc_pages(dpcpu, DPCPU_SIZE / PAGE_SIZE);
904	dpcpu_init((void *)dpcpu.pv_va, 0);
905
906	/* Allocate stacks for all modes */
907	valloc_pages(irqstack, IRQ_STACK_SIZE * MAXCPU);
908	valloc_pages(abtstack, ABT_STACK_SIZE * MAXCPU);
909	valloc_pages(undstack, UND_STACK_SIZE * MAXCPU);
910	valloc_pages(kernelstack, kstack_pages * MAXCPU);
911	valloc_pages(msgbufpv, round_page(msgbufsize) / PAGE_SIZE);
912
913	/*
914	 * Now we start construction of the L1 page table
915	 * We start by mapping the L2 page tables into the L1.
916	 * This means that we can replace L1 mappings later on if necessary
917	 */
918	l1pagetable = kernel_l1pt.pv_va;
919
920	/*
921	 * Try to map as much as possible of kernel text and data using
922	 * 1MB section mapping and for the rest of initial kernel address
923	 * space use L2 coarse tables.
924	 *
925	 * Link L2 tables for mapping remainder of kernel (modulo 1MB)
926	 * and kernel structures
927	 */
928	l2_start = lastaddr & ~(L1_S_OFFSET);
929	for (i = 0 ; i < l2size - 1; i++)
930		pmap_link_l2pt(l1pagetable, l2_start + i * L1_S_SIZE,
931		    &kernel_pt_table[i]);
932
933	pmap_curmaxkvaddr = l2_start + (l2size - 1) * L1_S_SIZE;
934
935	/* Map kernel code and data */
936	pmap_map_chunk(l1pagetable, KERNVIRTADDR, abp->abp_physaddr,
937	   (((uint32_t)(lastaddr) - KERNVIRTADDR) + PAGE_MASK) & ~PAGE_MASK,
938	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
939
940	/* Map L1 directory and allocated L2 page tables */
941	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
942	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
943
944	pmap_map_chunk(l1pagetable, kernel_pt_table[0].pv_va,
945	    kernel_pt_table[0].pv_pa,
946	    L2_TABLE_SIZE_REAL * l2size,
947	    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
948
949	/* Map allocated DPCPU, stacks and msgbuf */
950	pmap_map_chunk(l1pagetable, dpcpu.pv_va, dpcpu.pv_pa,
951	    freemempos - dpcpu.pv_va,
952	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
953
954	/* Link and map the vector page */
955	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH,
956	    &kernel_pt_table[l2size - 1]);
957	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
958	    VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, PTE_CACHE);
959
960	/* Establish static device mappings. */
961	err_devmap = platform_devmap_init();
962	devmap_bootstrap(l1pagetable, NULL);
963	vm_max_kernel_address = platform_lastaddr();
964
965	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2)) | DOMAIN_CLIENT);
966	pmap_pa = kernel_l1pt.pv_pa;
967	cpu_setttb(kernel_l1pt.pv_pa);
968	cpu_tlb_flushID();
969	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2));
970
971	/*
972	 * Now that proper page tables are installed, call cpu_setup() to enable
973	 * instruction and data caches and other chip-specific features.
974	 */
975	cpu_setup();
976
977	/*
978	 * Only after the SOC registers block is mapped we can perform device
979	 * tree fixups, as they may attempt to read parameters from hardware.
980	 */
981	OF_interpret("perform-fixup", 0);
982
983	platform_gpio_init();
984
985	cninit();
986
987	debugf("initarm: console initialized\n");
988	debugf(" arg1 kmdp = 0x%08x\n", (uint32_t)kmdp);
989	debugf(" boothowto = 0x%08x\n", boothowto);
990	debugf(" dtbp = 0x%08x\n", (uint32_t)dtbp);
991	arm_print_kenv();
992
993	env = kern_getenv("kernelname");
994	if (env != NULL) {
995		strlcpy(kernelname, env, sizeof(kernelname));
996		freeenv(env);
997	}
998
999	if (err_devmap != 0)
1000		printf("WARNING: could not fully configure devmap, error=%d\n",
1001		    err_devmap);
1002
1003	platform_late_init();
1004
1005	/*
1006	 * Pages were allocated during the secondary bootstrap for the
1007	 * stacks for different CPU modes.
1008	 * We must now set the r13 registers in the different CPU modes to
1009	 * point to these stacks.
1010	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
1011	 * of the stack memory.
1012	 */
1013	cpu_control(CPU_CONTROL_MMU_ENABLE, CPU_CONTROL_MMU_ENABLE);
1014
1015	set_stackptrs(0);
1016
1017	/*
1018	 * We must now clean the cache again....
1019	 * Cleaning may be done by reading new data to displace any
1020	 * dirty data in the cache. This will have happened in cpu_setttb()
1021	 * but since we are boot strapping the addresses used for the read
1022	 * may have just been remapped and thus the cache could be out
1023	 * of sync. A re-clean after the switch will cure this.
1024	 * After booting there are no gross relocations of the kernel thus
1025	 * this problem will not occur after initarm().
1026	 */
1027	cpu_idcache_wbinv_all();
1028
1029	undefined_init();
1030
1031	init_proc0(kernelstack.pv_va);
1032
1033	arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
1034	pmap_bootstrap(freemempos, &kernel_l1pt);
1035	msgbufp = (void *)msgbufpv.pv_va;
1036	msgbufinit(msgbufp, msgbufsize);
1037	mutex_init();
1038
1039	/*
1040	 * Exclude the kernel (and all the things we allocated which immediately
1041	 * follow the kernel) from the VM allocation pool but not from crash
1042	 * dumps.  virtual_avail is a global variable which tracks the kva we've
1043	 * "allocated" while setting up pmaps.
1044	 *
1045	 * Prepare the list of physical memory available to the vm subsystem.
1046	 */
1047	arm_physmem_exclude_region(abp->abp_physaddr,
1048	    (virtual_avail - KERNVIRTADDR), EXFLAG_NOALLOC);
1049	arm_physmem_init_kernel_globals();
1050
1051	init_param2(physmem);
1052	dbg_monitor_init();
1053	arm_kdb_init();
1054
1055	return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -
1056	    sizeof(struct pcb)));
1057}
1058#else /* __ARM_ARCH < 6 */
1059void *
1060initarm(struct arm_boot_params *abp)
1061{
1062	struct mem_region mem_regions[FDT_MEM_REGIONS];
1063	vm_paddr_t lastaddr;
1064	vm_offset_t dtbp, kernelstack, dpcpu;
1065	char *env;
1066	void *kmdp;
1067	int err_devmap, mem_regions_sz;
1068#ifdef EFI
1069	struct efi_map_header *efihdr;
1070#endif
1071
1072	/* get last allocated physical address */
1073	arm_physmem_kernaddr = abp->abp_physaddr;
1074	lastaddr = parse_boot_param(abp) - KERNVIRTADDR + arm_physmem_kernaddr;
1075
1076	set_cpufuncs();
1077	cpuinfo_init();
1078
1079	/*
1080	 * Find the dtb passed in by the boot loader.
1081	 */
1082	kmdp = preload_search_by_type("elf kernel");
1083	dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
1084#if defined(FDT_DTB_STATIC)
1085	/*
1086	 * In case the device tree blob was not retrieved (from metadata) try
1087	 * to use the statically embedded one.
1088	 */
1089	if (dtbp == (vm_offset_t)NULL)
1090		dtbp = (vm_offset_t)&fdt_static_dtb;
1091#endif
1092
1093	if (OF_install(OFW_FDT, 0) == FALSE)
1094		panic("Cannot install FDT");
1095
1096	if (OF_init((void *)dtbp) != 0)
1097		panic("OF_init failed with the found device tree");
1098
1099#if defined(LINUX_BOOT_ABI)
1100	arm_parse_fdt_bootargs();
1101#endif
1102
1103#ifdef EFI
1104	efihdr = (struct efi_map_header *)preload_search_info(kmdp,
1105	    MODINFO_METADATA | MODINFOMD_EFI_MAP);
1106	if (efihdr != NULL) {
1107		arm_add_efi_map_entries(efihdr, mem_regions, &mem_regions_sz);
1108	} else
1109#endif
1110	{
1111		/* Grab physical memory regions information from device tree. */
1112		if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,NULL) != 0)
1113			panic("Cannot get physical memory regions");
1114	}
1115	arm_physmem_hardware_regions(mem_regions, mem_regions_sz);
1116
1117	/* Grab reserved memory regions information from device tree. */
1118	if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
1119		arm_physmem_exclude_regions(mem_regions, mem_regions_sz,
1120		    EXFLAG_NODUMP | EXFLAG_NOALLOC);
1121
1122	/*
1123	 * Set TEX remapping registers.
1124	 * Setup kernel page tables and switch to kernel L1 page table.
1125	 */
1126	pmap_set_tex();
1127	pmap_bootstrap_prepare(lastaddr);
1128
1129	/*
1130	 * If EARLY_PRINTF support is enabled, we need to re-establish the
1131	 * mapping after pmap_bootstrap_prepare() switches to new page tables.
1132	 * Note that we can only do the remapping if the VA is outside the
1133	 * kernel, now that we have real virtual (not VA=PA) mappings in effect.
1134	 * Early printf does not work between the time pmap_set_tex() does
1135	 * cp15_prrr_set() and this code remaps the VA.
1136	 */
1137#if defined(EARLY_PRINTF) && defined(SOCDEV_PA) && defined(SOCDEV_VA) && SOCDEV_VA < KERNBASE
1138	pmap_preboot_map_attr(SOCDEV_PA, SOCDEV_VA, 1024 * 1024,
1139	    VM_PROT_READ | VM_PROT_WRITE, VM_MEMATTR_DEVICE);
1140#endif
1141
1142	/*
1143	 * Now that proper page tables are installed, call cpu_setup() to enable
1144	 * instruction and data caches and other chip-specific features.
1145	 */
1146	cpu_setup();
1147
1148	/* Platform-specific initialisation */
1149	platform_probe_and_attach();
1150	pcpu0_init();
1151
1152	/* Do basic tuning, hz etc */
1153	init_param1();
1154
1155	/*
1156	 * Allocate a page for the system page mapped to 0xffff0000
1157	 * This page will just contain the system vectors and can be
1158	 * shared by all processes.
1159	 */
1160	systempage = pmap_preboot_get_pages(1);
1161
1162	/* Map the vector page. */
1163	pmap_preboot_map_pages(systempage, ARM_VECTORS_HIGH,  1);
1164	if (virtual_end >= ARM_VECTORS_HIGH)
1165		virtual_end = ARM_VECTORS_HIGH - 1;
1166
1167	/* Allocate dynamic per-cpu area. */
1168	dpcpu = pmap_preboot_get_vpages(DPCPU_SIZE / PAGE_SIZE);
1169	dpcpu_init((void *)dpcpu, 0);
1170
1171	/* Allocate stacks for all modes */
1172	irqstack    = pmap_preboot_get_vpages(IRQ_STACK_SIZE * MAXCPU);
1173	abtstack    = pmap_preboot_get_vpages(ABT_STACK_SIZE * MAXCPU);
1174	undstack    = pmap_preboot_get_vpages(UND_STACK_SIZE * MAXCPU );
1175	kernelstack = pmap_preboot_get_vpages(kstack_pages * MAXCPU);
1176
1177	/* Allocate message buffer. */
1178	msgbufp = (void *)pmap_preboot_get_vpages(
1179	    round_page(msgbufsize) / PAGE_SIZE);
1180
1181	/*
1182	 * Pages were allocated during the secondary bootstrap for the
1183	 * stacks for different CPU modes.
1184	 * We must now set the r13 registers in the different CPU modes to
1185	 * point to these stacks.
1186	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
1187	 * of the stack memory.
1188	 */
1189	set_stackptrs(0);
1190	mutex_init();
1191
1192	/* Establish static device mappings. */
1193	err_devmap = platform_devmap_init();
1194	devmap_bootstrap(0, NULL);
1195	vm_max_kernel_address = platform_lastaddr();
1196
1197	/*
1198	 * Only after the SOC registers block is mapped we can perform device
1199	 * tree fixups, as they may attempt to read parameters from hardware.
1200	 */
1201	OF_interpret("perform-fixup", 0);
1202	platform_gpio_init();
1203	cninit();
1204
1205	/*
1206	 * If we made a mapping for EARLY_PRINTF after pmap_bootstrap_prepare(),
1207	 * undo it now that the normal console printf works.
1208	 */
1209#if defined(EARLY_PRINTF) && defined(SOCDEV_PA) && defined(SOCDEV_VA) && SOCDEV_VA < KERNBASE
1210	pmap_kremove(SOCDEV_VA);
1211#endif
1212
1213	debugf("initarm: console initialized\n");
1214	debugf(" arg1 kmdp = 0x%08x\n", (uint32_t)kmdp);
1215	debugf(" boothowto = 0x%08x\n", boothowto);
1216	debugf(" dtbp = 0x%08x\n", (uint32_t)dtbp);
1217	debugf(" lastaddr1: 0x%08x\n", lastaddr);
1218	arm_print_kenv();
1219
1220	env = kern_getenv("kernelname");
1221	if (env != NULL)
1222		strlcpy(kernelname, env, sizeof(kernelname));
1223
1224	if (err_devmap != 0)
1225		printf("WARNING: could not fully configure devmap, error=%d\n",
1226		    err_devmap);
1227
1228	platform_late_init();
1229
1230	/*
1231	 * We must now clean the cache again....
1232	 * Cleaning may be done by reading new data to displace any
1233	 * dirty data in the cache. This will have happened in cpu_setttb()
1234	 * but since we are boot strapping the addresses used for the read
1235	 * may have just been remapped and thus the cache could be out
1236	 * of sync. A re-clean after the switch will cure this.
1237	 * After booting there are no gross relocations of the kernel thus
1238	 * this problem will not occur after initarm().
1239	 */
1240	/* Set stack for exception handlers */
1241	undefined_init();
1242	init_proc0(kernelstack);
1243	arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
1244	enable_interrupts(PSR_A);
1245	pmap_bootstrap(0);
1246
1247	/* Exclude the kernel (and all the things we allocated which immediately
1248	 * follow the kernel) from the VM allocation pool but not from crash
1249	 * dumps.  virtual_avail is a global variable which tracks the kva we've
1250	 * "allocated" while setting up pmaps.
1251	 *
1252	 * Prepare the list of physical memory available to the vm subsystem.
1253	 */
1254	arm_physmem_exclude_region(abp->abp_physaddr,
1255		pmap_preboot_get_pages(0) - abp->abp_physaddr, EXFLAG_NOALLOC);
1256	arm_physmem_init_kernel_globals();
1257
1258	init_param2(physmem);
1259	/* Init message buffer. */
1260	msgbufinit(msgbufp, msgbufsize);
1261	dbg_monitor_init();
1262	arm_kdb_init();
1263	/* Apply possible BP hardening. */
1264	cpuinfo_init_bp_hardening();
1265	return ((void *)STACKALIGN(thread0.td_pcb));
1266
1267}
1268
1269#endif /* __ARM_ARCH < 6 */
1270#endif /* FDT */
1271