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