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