]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/machdep.c
Allocate right number of pages for the bounced buffers crossing the page.
[FreeBSD/FreeBSD.git] / sys / arm64 / arm64 / machdep.c
1 /*-
2  * Copyright (c) 2014 Andrew Turner
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27
28 #include "opt_acpi.h"
29 #include "opt_platform.h"
30 #include "opt_ddb.h"
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/buf.h>
38 #include <sys/bus.h>
39 #include <sys/cons.h>
40 #include <sys/cpu.h>
41 #include <sys/csan.h>
42 #include <sys/devmap.h>
43 #include <sys/efi.h>
44 #include <sys/exec.h>
45 #include <sys/imgact.h>
46 #include <sys/kdb.h>
47 #include <sys/kernel.h>
48 #include <sys/ktr.h>
49 #include <sys/limits.h>
50 #include <sys/linker.h>
51 #include <sys/msgbuf.h>
52 #include <sys/pcpu.h>
53 #include <sys/physmem.h>
54 #include <sys/proc.h>
55 #include <sys/ptrace.h>
56 #include <sys/reboot.h>
57 #include <sys/rwlock.h>
58 #include <sys/sched.h>
59 #include <sys/signalvar.h>
60 #include <sys/syscallsubr.h>
61 #include <sys/sysent.h>
62 #include <sys/sysproto.h>
63 #include <sys/ucontext.h>
64 #include <sys/vdso.h>
65 #include <sys/vmmeter.h>
66
67 #include <vm/vm.h>
68 #include <vm/vm_param.h>
69 #include <vm/vm_kern.h>
70 #include <vm/vm_object.h>
71 #include <vm/vm_page.h>
72 #include <vm/vm_phys.h>
73 #include <vm/pmap.h>
74 #include <vm/vm_map.h>
75 #include <vm/vm_pager.h>
76
77 #include <machine/armreg.h>
78 #include <machine/cpu.h>
79 #include <machine/debug_monitor.h>
80 #include <machine/kdb.h>
81 #include <machine/machdep.h>
82 #include <machine/metadata.h>
83 #include <machine/md_var.h>
84 #include <machine/pcb.h>
85 #include <machine/reg.h>
86 #include <machine/undefined.h>
87 #include <machine/vmparam.h>
88
89 #ifdef VFP
90 #include <machine/vfp.h>
91 #endif
92
93 #ifdef DEV_ACPI
94 #include <contrib/dev/acpica/include/acpi.h>
95 #include <machine/acpica_machdep.h>
96 #endif
97
98 #ifdef FDT
99 #include <dev/fdt/fdt_common.h>
100 #include <dev/ofw/openfirm.h>
101 #endif
102
103 static void get_fpcontext(struct thread *td, mcontext_t *mcp);
104 static void set_fpcontext(struct thread *td, mcontext_t *mcp);
105
106 enum arm64_bus arm64_bus_method = ARM64_BUS_NONE;
107
108 struct pcpu __pcpu[MAXCPU];
109
110 static struct trapframe proc0_tf;
111
112 int early_boot = 1;
113 int cold = 1;
114 static int boot_el;
115
116 struct kva_md_info kmi;
117
118 int64_t dczva_line_size;        /* The size of cache line the dc zva zeroes */
119 int has_pan;
120
121 /*
122  * Physical address of the EFI System Table. Stashed from the metadata hints
123  * passed into the kernel and used by the EFI code to call runtime services.
124  */
125 vm_paddr_t efi_systbl_phys;
126 static struct efi_map_header *efihdr;
127
128 /* pagezero_* implementations are provided in support.S */
129 void pagezero_simple(void *);
130 void pagezero_cache(void *);
131
132 /* pagezero_simple is default pagezero */
133 void (*pagezero)(void *p) = pagezero_simple;
134
135 int (*apei_nmi)(void);
136
137 static void
138 pan_setup(void)
139 {
140         uint64_t id_aa64mfr1;
141
142         id_aa64mfr1 = READ_SPECIALREG(id_aa64mmfr1_el1);
143         if (ID_AA64MMFR1_PAN_VAL(id_aa64mfr1) != ID_AA64MMFR1_PAN_NONE)
144                 has_pan = 1;
145 }
146
147 void
148 pan_enable(void)
149 {
150
151         /*
152          * The LLVM integrated assembler doesn't understand the PAN
153          * PSTATE field. Because of this we need to manually create
154          * the instruction in an asm block. This is equivalent to:
155          * msr pan, #1
156          *
157          * This sets the PAN bit, stopping the kernel from accessing
158          * memory when userspace can also access it unless the kernel
159          * uses the userspace load/store instructions.
160          */
161         if (has_pan) {
162                 WRITE_SPECIALREG(sctlr_el1,
163                     READ_SPECIALREG(sctlr_el1) & ~SCTLR_SPAN);
164                 __asm __volatile(".inst 0xd500409f | (0x1 << 8)");
165         }
166 }
167
168 bool
169 has_hyp(void)
170 {
171
172         return (boot_el == 2);
173 }
174
175 static void
176 cpu_startup(void *dummy)
177 {
178         vm_paddr_t size;
179         int i;
180
181         printf("real memory  = %ju (%ju MB)\n", ptoa((uintmax_t)realmem),
182             ptoa((uintmax_t)realmem) / 1024 / 1024);
183
184         if (bootverbose) {
185                 printf("Physical memory chunk(s):\n");
186                 for (i = 0; phys_avail[i + 1] != 0; i += 2) {
187                         size = phys_avail[i + 1] - phys_avail[i];
188                         printf("%#016jx - %#016jx, %ju bytes (%ju pages)\n",
189                             (uintmax_t)phys_avail[i],
190                             (uintmax_t)phys_avail[i + 1] - 1,
191                             (uintmax_t)size, (uintmax_t)size / PAGE_SIZE);
192                 }
193         }
194
195         printf("avail memory = %ju (%ju MB)\n",
196             ptoa((uintmax_t)vm_free_count()),
197             ptoa((uintmax_t)vm_free_count()) / 1024 / 1024);
198
199         undef_init();
200         install_cpu_errata();
201
202         vm_ksubmap_init(&kmi);
203         bufinit();
204         vm_pager_bufferinit();
205 }
206
207 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
208
209 static void
210 late_ifunc_resolve(void *dummy __unused)
211 {
212         link_elf_late_ireloc();
213 }
214 SYSINIT(late_ifunc_resolve, SI_SUB_CPU, SI_ORDER_ANY, late_ifunc_resolve, NULL);
215
216 int
217 cpu_idle_wakeup(int cpu)
218 {
219
220         return (0);
221 }
222
223 int
224 fill_regs(struct thread *td, struct reg *regs)
225 {
226         struct trapframe *frame;
227
228         frame = td->td_frame;
229         regs->sp = frame->tf_sp;
230         regs->lr = frame->tf_lr;
231         regs->elr = frame->tf_elr;
232         regs->spsr = frame->tf_spsr;
233
234         memcpy(regs->x, frame->tf_x, sizeof(regs->x));
235
236 #ifdef COMPAT_FREEBSD32
237         /*
238          * We may be called here for a 32bits process, if we're using a
239          * 64bits debugger. If so, put PC and SPSR where it expects it.
240          */
241         if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
242                 regs->x[15] = frame->tf_elr;
243                 regs->x[16] = frame->tf_spsr;
244         }
245 #endif
246         return (0);
247 }
248
249 int
250 set_regs(struct thread *td, struct reg *regs)
251 {
252         struct trapframe *frame;
253
254         frame = td->td_frame;
255         frame->tf_sp = regs->sp;
256         frame->tf_lr = regs->lr;
257         frame->tf_elr = regs->elr;
258         frame->tf_spsr &= ~PSR_FLAGS;
259         frame->tf_spsr |= regs->spsr & PSR_FLAGS;
260
261         memcpy(frame->tf_x, regs->x, sizeof(frame->tf_x));
262
263 #ifdef COMPAT_FREEBSD32
264         if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
265                 /*
266                  * We may be called for a 32bits process if we're using
267                  * a 64bits debugger. If so, get PC and SPSR from where
268                  * it put it.
269                  */
270                 frame->tf_elr = regs->x[15];
271                 frame->tf_spsr = regs->x[16] & PSR_FLAGS;
272         }
273 #endif
274         return (0);
275 }
276
277 int
278 fill_fpregs(struct thread *td, struct fpreg *regs)
279 {
280 #ifdef VFP
281         struct pcb *pcb;
282
283         pcb = td->td_pcb;
284         if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
285                 /*
286                  * If we have just been running VFP instructions we will
287                  * need to save the state to memcpy it below.
288                  */
289                 if (td == curthread)
290                         vfp_save_state(td, pcb);
291
292                 KASSERT(pcb->pcb_fpusaved == &pcb->pcb_fpustate,
293                     ("Called fill_fpregs while the kernel is using the VFP"));
294                 memcpy(regs->fp_q, pcb->pcb_fpustate.vfp_regs,
295                     sizeof(regs->fp_q));
296                 regs->fp_cr = pcb->pcb_fpustate.vfp_fpcr;
297                 regs->fp_sr = pcb->pcb_fpustate.vfp_fpsr;
298         } else
299 #endif
300                 memset(regs, 0, sizeof(*regs));
301         return (0);
302 }
303
304 int
305 set_fpregs(struct thread *td, struct fpreg *regs)
306 {
307 #ifdef VFP
308         struct pcb *pcb;
309
310         pcb = td->td_pcb;
311         KASSERT(pcb->pcb_fpusaved == &pcb->pcb_fpustate,
312             ("Called set_fpregs while the kernel is using the VFP"));
313         memcpy(pcb->pcb_fpustate.vfp_regs, regs->fp_q, sizeof(regs->fp_q));
314         pcb->pcb_fpustate.vfp_fpcr = regs->fp_cr;
315         pcb->pcb_fpustate.vfp_fpsr = regs->fp_sr;
316 #endif
317         return (0);
318 }
319
320 int
321 fill_dbregs(struct thread *td, struct dbreg *regs)
322 {
323         struct debug_monitor_state *monitor;
324         int count, i;
325         uint8_t debug_ver, nbkpts;
326
327         memset(regs, 0, sizeof(*regs));
328
329         extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_DebugVer_SHIFT,
330             &debug_ver);
331         extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_BRPs_SHIFT,
332             &nbkpts);
333
334         /*
335          * The BRPs field contains the number of breakpoints - 1. Armv8-A
336          * allows the hardware to provide 2-16 breakpoints so this won't
337          * overflow an 8 bit value.
338          */
339         count = nbkpts + 1;
340
341         regs->db_info = debug_ver;
342         regs->db_info <<= 8;
343         regs->db_info |= count;
344
345         monitor = &td->td_pcb->pcb_dbg_regs;
346         if ((monitor->dbg_flags & DBGMON_ENABLED) != 0) {
347                 for (i = 0; i < count; i++) {
348                         regs->db_regs[i].dbr_addr = monitor->dbg_bvr[i];
349                         regs->db_regs[i].dbr_ctrl = monitor->dbg_bcr[i];
350                 }
351         }
352
353         return (0);
354 }
355
356 int
357 set_dbregs(struct thread *td, struct dbreg *regs)
358 {
359         struct debug_monitor_state *monitor;
360         int count;
361         int i;
362
363         monitor = &td->td_pcb->pcb_dbg_regs;
364         count = 0;
365         monitor->dbg_enable_count = 0;
366         for (i = 0; i < DBG_BRP_MAX; i++) {
367                 /* TODO: Check these values */
368                 monitor->dbg_bvr[i] = regs->db_regs[i].dbr_addr;
369                 monitor->dbg_bcr[i] = regs->db_regs[i].dbr_ctrl;
370                 if ((monitor->dbg_bcr[i] & 1) != 0)
371                         monitor->dbg_enable_count++;
372         }
373         if (monitor->dbg_enable_count > 0)
374                 monitor->dbg_flags |= DBGMON_ENABLED;
375
376         return (0);
377 }
378
379 #ifdef COMPAT_FREEBSD32
380 int
381 fill_regs32(struct thread *td, struct reg32 *regs)
382 {
383         int i;
384         struct trapframe *tf;
385
386         tf = td->td_frame;
387         for (i = 0; i < 13; i++)
388                 regs->r[i] = tf->tf_x[i];
389         /* For arm32, SP is r13 and LR is r14 */
390         regs->r_sp = tf->tf_x[13];
391         regs->r_lr = tf->tf_x[14];
392         regs->r_pc = tf->tf_elr;
393         regs->r_cpsr = tf->tf_spsr;
394
395         return (0);
396 }
397
398 int
399 set_regs32(struct thread *td, struct reg32 *regs)
400 {
401         int i;
402         struct trapframe *tf;
403
404         tf = td->td_frame;
405         for (i = 0; i < 13; i++)
406                 tf->tf_x[i] = regs->r[i];
407         /* For arm 32, SP is r13 an LR is r14 */
408         tf->tf_x[13] = regs->r_sp;
409         tf->tf_x[14] = regs->r_lr;
410         tf->tf_elr = regs->r_pc;
411         tf->tf_spsr = regs->r_cpsr;
412
413         return (0);
414 }
415
416 int
417 fill_fpregs32(struct thread *td, struct fpreg32 *regs)
418 {
419
420         printf("ARM64TODO: fill_fpregs32");
421         return (EDOOFUS);
422 }
423
424 int
425 set_fpregs32(struct thread *td, struct fpreg32 *regs)
426 {
427
428         printf("ARM64TODO: set_fpregs32");
429         return (EDOOFUS);
430 }
431
432 int
433 fill_dbregs32(struct thread *td, struct dbreg32 *regs)
434 {
435
436         printf("ARM64TODO: fill_dbregs32");
437         return (EDOOFUS);
438 }
439
440 int
441 set_dbregs32(struct thread *td, struct dbreg32 *regs)
442 {
443
444         printf("ARM64TODO: set_dbregs32");
445         return (EDOOFUS);
446 }
447 #endif
448
449 int
450 ptrace_set_pc(struct thread *td, u_long addr)
451 {
452
453         td->td_frame->tf_elr = addr;
454         return (0);
455 }
456
457 int
458 ptrace_single_step(struct thread *td)
459 {
460
461         td->td_frame->tf_spsr |= PSR_SS;
462         td->td_pcb->pcb_flags |= PCB_SINGLE_STEP;
463         return (0);
464 }
465
466 int
467 ptrace_clear_single_step(struct thread *td)
468 {
469
470         td->td_frame->tf_spsr &= ~PSR_SS;
471         td->td_pcb->pcb_flags &= ~PCB_SINGLE_STEP;
472         return (0);
473 }
474
475 void
476 exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
477 {
478         struct trapframe *tf = td->td_frame;
479
480         memset(tf, 0, sizeof(struct trapframe));
481
482         tf->tf_x[0] = stack;
483         tf->tf_sp = STACKALIGN(stack);
484         tf->tf_lr = imgp->entry_addr;
485         tf->tf_elr = imgp->entry_addr;
486 }
487
488 /* Sanity check these are the same size, they will be memcpy'd to and fro */
489 CTASSERT(sizeof(((struct trapframe *)0)->tf_x) ==
490     sizeof((struct gpregs *)0)->gp_x);
491 CTASSERT(sizeof(((struct trapframe *)0)->tf_x) ==
492     sizeof((struct reg *)0)->x);
493
494 int
495 get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
496 {
497         struct trapframe *tf = td->td_frame;
498
499         if (clear_ret & GET_MC_CLEAR_RET) {
500                 mcp->mc_gpregs.gp_x[0] = 0;
501                 mcp->mc_gpregs.gp_spsr = tf->tf_spsr & ~PSR_C;
502         } else {
503                 mcp->mc_gpregs.gp_x[0] = tf->tf_x[0];
504                 mcp->mc_gpregs.gp_spsr = tf->tf_spsr;
505         }
506
507         memcpy(&mcp->mc_gpregs.gp_x[1], &tf->tf_x[1],
508             sizeof(mcp->mc_gpregs.gp_x[1]) * (nitems(mcp->mc_gpregs.gp_x) - 1));
509
510         mcp->mc_gpregs.gp_sp = tf->tf_sp;
511         mcp->mc_gpregs.gp_lr = tf->tf_lr;
512         mcp->mc_gpregs.gp_elr = tf->tf_elr;
513         get_fpcontext(td, mcp);
514
515         return (0);
516 }
517
518 int
519 set_mcontext(struct thread *td, mcontext_t *mcp)
520 {
521         struct trapframe *tf = td->td_frame;
522         uint32_t spsr;
523
524         spsr = mcp->mc_gpregs.gp_spsr;
525         if ((spsr & PSR_M_MASK) != PSR_M_EL0t ||
526             (spsr & PSR_AARCH32) != 0 ||
527             (spsr & PSR_DAIF) != (td->td_frame->tf_spsr & PSR_DAIF))
528                 return (EINVAL); 
529
530         memcpy(tf->tf_x, mcp->mc_gpregs.gp_x, sizeof(tf->tf_x));
531
532         tf->tf_sp = mcp->mc_gpregs.gp_sp;
533         tf->tf_lr = mcp->mc_gpregs.gp_lr;
534         tf->tf_elr = mcp->mc_gpregs.gp_elr;
535         tf->tf_spsr = mcp->mc_gpregs.gp_spsr;
536         set_fpcontext(td, mcp);
537
538         return (0);
539 }
540
541 static void
542 get_fpcontext(struct thread *td, mcontext_t *mcp)
543 {
544 #ifdef VFP
545         struct pcb *curpcb;
546
547         critical_enter();
548
549         curpcb = curthread->td_pcb;
550
551         if ((curpcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
552                 /*
553                  * If we have just been running VFP instructions we will
554                  * need to save the state to memcpy it below.
555                  */
556                 vfp_save_state(td, curpcb);
557
558                 KASSERT(curpcb->pcb_fpusaved == &curpcb->pcb_fpustate,
559                     ("Called get_fpcontext while the kernel is using the VFP"));
560                 KASSERT((curpcb->pcb_fpflags & ~PCB_FP_USERMASK) == 0,
561                     ("Non-userspace FPU flags set in get_fpcontext"));
562                 memcpy(mcp->mc_fpregs.fp_q, curpcb->pcb_fpustate.vfp_regs,
563                     sizeof(mcp->mc_fpregs));
564                 mcp->mc_fpregs.fp_cr = curpcb->pcb_fpustate.vfp_fpcr;
565                 mcp->mc_fpregs.fp_sr = curpcb->pcb_fpustate.vfp_fpsr;
566                 mcp->mc_fpregs.fp_flags = curpcb->pcb_fpflags;
567                 mcp->mc_flags |= _MC_FP_VALID;
568         }
569
570         critical_exit();
571 #endif
572 }
573
574 static void
575 set_fpcontext(struct thread *td, mcontext_t *mcp)
576 {
577 #ifdef VFP
578         struct pcb *curpcb;
579
580         critical_enter();
581
582         if ((mcp->mc_flags & _MC_FP_VALID) != 0) {
583                 curpcb = curthread->td_pcb;
584
585                 /*
586                  * Discard any vfp state for the current thread, we
587                  * are about to override it.
588                  */
589                 vfp_discard(td);
590
591                 KASSERT(curpcb->pcb_fpusaved == &curpcb->pcb_fpustate,
592                     ("Called set_fpcontext while the kernel is using the VFP"));
593                 memcpy(curpcb->pcb_fpustate.vfp_regs, mcp->mc_fpregs.fp_q,
594                     sizeof(mcp->mc_fpregs));
595                 curpcb->pcb_fpustate.vfp_fpcr = mcp->mc_fpregs.fp_cr;
596                 curpcb->pcb_fpustate.vfp_fpsr = mcp->mc_fpregs.fp_sr;
597                 curpcb->pcb_fpflags = mcp->mc_fpregs.fp_flags & PCB_FP_USERMASK;
598         }
599
600         critical_exit();
601 #endif
602 }
603
604 void
605 cpu_idle(int busy)
606 {
607
608         spinlock_enter();
609         if (!busy)
610                 cpu_idleclock();
611         if (!sched_runnable())
612                 __asm __volatile(
613                     "dsb sy \n"
614                     "wfi    \n");
615         if (!busy)
616                 cpu_activeclock();
617         spinlock_exit();
618 }
619
620 void
621 cpu_halt(void)
622 {
623
624         /* We should have shutdown by now, if not enter a low power sleep */
625         intr_disable();
626         while (1) {
627                 __asm __volatile("wfi");
628         }
629 }
630
631 /*
632  * Flush the D-cache for non-DMA I/O so that the I-cache can
633  * be made coherent later.
634  */
635 void
636 cpu_flush_dcache(void *ptr, size_t len)
637 {
638
639         /* ARM64TODO TBD */
640 }
641
642 /* Get current clock frequency for the given CPU ID. */
643 int
644 cpu_est_clockrate(int cpu_id, uint64_t *rate)
645 {
646         struct pcpu *pc;
647
648         pc = pcpu_find(cpu_id);
649         if (pc == NULL || rate == NULL)
650                 return (EINVAL);
651
652         if (pc->pc_clock == 0)
653                 return (EOPNOTSUPP);
654
655         *rate = pc->pc_clock;
656         return (0);
657 }
658
659 void
660 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
661 {
662
663         pcpu->pc_acpi_id = 0xffffffff;
664         pcpu->pc_mpidr = 0xffffffff;
665 }
666
667 void
668 spinlock_enter(void)
669 {
670         struct thread *td;
671         register_t daif;
672
673         td = curthread;
674         if (td->td_md.md_spinlock_count == 0) {
675                 daif = intr_disable();
676                 td->td_md.md_spinlock_count = 1;
677                 td->td_md.md_saved_daif = daif;
678                 critical_enter();
679         } else
680                 td->td_md.md_spinlock_count++;
681 }
682
683 void
684 spinlock_exit(void)
685 {
686         struct thread *td;
687         register_t daif;
688
689         td = curthread;
690         daif = td->td_md.md_saved_daif;
691         td->td_md.md_spinlock_count--;
692         if (td->td_md.md_spinlock_count == 0) {
693                 critical_exit();
694                 intr_restore(daif);
695         }
696 }
697
698 #ifndef _SYS_SYSPROTO_H_
699 struct sigreturn_args {
700         ucontext_t *ucp;
701 };
702 #endif
703
704 int
705 sys_sigreturn(struct thread *td, struct sigreturn_args *uap)
706 {
707         ucontext_t uc;
708         int error;
709
710         if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
711                 return (EFAULT);
712
713         error = set_mcontext(td, &uc.uc_mcontext);
714         if (error != 0)
715                 return (error);
716
717         /* Restore signal mask. */
718         kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
719
720         return (EJUSTRETURN);
721 }
722
723 /*
724  * Construct a PCB from a trapframe. This is called from kdb_trap() where
725  * we want to start a backtrace from the function that caused us to enter
726  * the debugger. We have the context in the trapframe, but base the trace
727  * on the PCB. The PCB doesn't have to be perfect, as long as it contains
728  * enough for a backtrace.
729  */
730 void
731 makectx(struct trapframe *tf, struct pcb *pcb)
732 {
733         int i;
734
735         for (i = 0; i < PCB_LR; i++)
736                 pcb->pcb_x[i] = tf->tf_x[i];
737
738         pcb->pcb_x[PCB_LR] = tf->tf_lr;
739         pcb->pcb_pc = tf->tf_elr;
740         pcb->pcb_sp = tf->tf_sp;
741 }
742
743 void
744 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
745 {
746         struct thread *td;
747         struct proc *p;
748         struct trapframe *tf;
749         struct sigframe *fp, frame;
750         struct sigacts *psp;
751         struct sysentvec *sysent;
752         int onstack, sig;
753
754         td = curthread;
755         p = td->td_proc;
756         PROC_LOCK_ASSERT(p, MA_OWNED);
757
758         sig = ksi->ksi_signo;
759         psp = p->p_sigacts;
760         mtx_assert(&psp->ps_mtx, MA_OWNED);
761
762         tf = td->td_frame;
763         onstack = sigonstack(tf->tf_sp);
764
765         CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
766             catcher, sig);
767
768         /* Allocate and validate space for the signal handler context. */
769         if ((td->td_pflags & TDP_ALTSTACK) != 0 && !onstack &&
770             SIGISMEMBER(psp->ps_sigonstack, sig)) {
771                 fp = (struct sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
772                     td->td_sigstk.ss_size);
773 #if defined(COMPAT_43)
774                 td->td_sigstk.ss_flags |= SS_ONSTACK;
775 #endif
776         } else {
777                 fp = (struct sigframe *)td->td_frame->tf_sp;
778         }
779
780         /* Make room, keeping the stack aligned */
781         fp--;
782         fp = (struct sigframe *)STACKALIGN(fp);
783
784         /* Fill in the frame to copy out */
785         bzero(&frame, sizeof(frame));
786         get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
787         frame.sf_si = ksi->ksi_info;
788         frame.sf_uc.uc_sigmask = *mask;
789         frame.sf_uc.uc_stack = td->td_sigstk;
790         frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ?
791             (onstack ? SS_ONSTACK : 0) : SS_DISABLE;
792         mtx_unlock(&psp->ps_mtx);
793         PROC_UNLOCK(td->td_proc);
794
795         /* Copy the sigframe out to the user's stack. */
796         if (copyout(&frame, fp, sizeof(*fp)) != 0) {
797                 /* Process has trashed its stack. Kill it. */
798                 CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp);
799                 PROC_LOCK(p);
800                 sigexit(td, SIGILL);
801         }
802
803         tf->tf_x[0]= sig;
804         tf->tf_x[1] = (register_t)&fp->sf_si;
805         tf->tf_x[2] = (register_t)&fp->sf_uc;
806
807         tf->tf_elr = (register_t)catcher;
808         tf->tf_sp = (register_t)fp;
809         sysent = p->p_sysent;
810         if (sysent->sv_sigcode_base != 0)
811                 tf->tf_lr = (register_t)sysent->sv_sigcode_base;
812         else
813                 tf->tf_lr = (register_t)(sysent->sv_psstrings -
814                     *(sysent->sv_szsigcode));
815
816         CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_elr,
817             tf->tf_sp);
818
819         PROC_LOCK(p);
820         mtx_lock(&psp->ps_mtx);
821 }
822
823 static void
824 init_proc0(vm_offset_t kstack)
825 {
826         struct pcpu *pcpup = &__pcpu[0];
827
828         proc_linkup0(&proc0, &thread0);
829         thread0.td_kstack = kstack;
830         thread0.td_kstack_pages = KSTACK_PAGES;
831         thread0.td_pcb = (struct pcb *)(thread0.td_kstack +
832             thread0.td_kstack_pages * PAGE_SIZE) - 1;
833         thread0.td_pcb->pcb_fpflags = 0;
834         thread0.td_pcb->pcb_fpusaved = &thread0.td_pcb->pcb_fpustate;
835         thread0.td_pcb->pcb_vfpcpu = UINT_MAX;
836         thread0.td_frame = &proc0_tf;
837         pcpup->pc_curpcb = thread0.td_pcb;
838 }
839
840 typedef struct {
841         uint32_t type;
842         uint64_t phys_start;
843         uint64_t virt_start;
844         uint64_t num_pages;
845         uint64_t attr;
846 } EFI_MEMORY_DESCRIPTOR;
847
848 typedef void (*efi_map_entry_cb)(struct efi_md *);
849
850 static void
851 foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb)
852 {
853         struct efi_md *map, *p;
854         size_t efisz;
855         int ndesc, i;
856
857         /*
858          * Memory map data provided by UEFI via the GetMemoryMap
859          * Boot Services API.
860          */
861         efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
862         map = (struct efi_md *)((uint8_t *)efihdr + efisz); 
863
864         if (efihdr->descriptor_size == 0)
865                 return;
866         ndesc = efihdr->memory_size / efihdr->descriptor_size;
867
868         for (i = 0, p = map; i < ndesc; i++,
869             p = efi_next_descriptor(p, efihdr->descriptor_size)) {
870                 cb(p);
871         }
872 }
873
874 static void
875 exclude_efi_map_entry(struct efi_md *p)
876 {
877
878         switch (p->md_type) {
879         case EFI_MD_TYPE_CODE:
880         case EFI_MD_TYPE_DATA:
881         case EFI_MD_TYPE_BS_CODE:
882         case EFI_MD_TYPE_BS_DATA:
883         case EFI_MD_TYPE_FREE:
884                 /*
885                  * We're allowed to use any entry with these types.
886                  */
887                 break;
888         default:
889                 physmem_exclude_region(p->md_phys, p->md_pages * PAGE_SIZE,
890                     EXFLAG_NOALLOC);
891         }
892 }
893
894 static void
895 exclude_efi_map_entries(struct efi_map_header *efihdr)
896 {
897
898         foreach_efi_map_entry(efihdr, exclude_efi_map_entry);
899 }
900
901 static void
902 add_efi_map_entry(struct efi_md *p)
903 {
904
905         switch (p->md_type) {
906         case EFI_MD_TYPE_RT_DATA:
907                 /*
908                  * Runtime data will be excluded after the DMAP
909                  * region is created to stop it from being added
910                  * to phys_avail.
911                  */
912         case EFI_MD_TYPE_CODE:
913         case EFI_MD_TYPE_DATA:
914         case EFI_MD_TYPE_BS_CODE:
915         case EFI_MD_TYPE_BS_DATA:
916         case EFI_MD_TYPE_FREE:
917                 /*
918                  * We're allowed to use any entry with these types.
919                  */
920                 physmem_hardware_region(p->md_phys,
921                     p->md_pages * PAGE_SIZE);
922                 break;
923         }
924 }
925
926 static void
927 add_efi_map_entries(struct efi_map_header *efihdr)
928 {
929
930         foreach_efi_map_entry(efihdr, add_efi_map_entry);
931 }
932
933 static void
934 print_efi_map_entry(struct efi_md *p)
935 {
936         const char *type;
937         static const char *types[] = {
938                 "Reserved",
939                 "LoaderCode",
940                 "LoaderData",
941                 "BootServicesCode",
942                 "BootServicesData",
943                 "RuntimeServicesCode",
944                 "RuntimeServicesData",
945                 "ConventionalMemory",
946                 "UnusableMemory",
947                 "ACPIReclaimMemory",
948                 "ACPIMemoryNVS",
949                 "MemoryMappedIO",
950                 "MemoryMappedIOPortSpace",
951                 "PalCode",
952                 "PersistentMemory"
953         };
954
955         if (p->md_type < nitems(types))
956                 type = types[p->md_type];
957         else
958                 type = "<INVALID>";
959         printf("%23s %012lx %12p %08lx ", type, p->md_phys,
960             p->md_virt, p->md_pages);
961         if (p->md_attr & EFI_MD_ATTR_UC)
962                 printf("UC ");
963         if (p->md_attr & EFI_MD_ATTR_WC)
964                 printf("WC ");
965         if (p->md_attr & EFI_MD_ATTR_WT)
966                 printf("WT ");
967         if (p->md_attr & EFI_MD_ATTR_WB)
968                 printf("WB ");
969         if (p->md_attr & EFI_MD_ATTR_UCE)
970                 printf("UCE ");
971         if (p->md_attr & EFI_MD_ATTR_WP)
972                 printf("WP ");
973         if (p->md_attr & EFI_MD_ATTR_RP)
974                 printf("RP ");
975         if (p->md_attr & EFI_MD_ATTR_XP)
976                 printf("XP ");
977         if (p->md_attr & EFI_MD_ATTR_NV)
978                 printf("NV ");
979         if (p->md_attr & EFI_MD_ATTR_MORE_RELIABLE)
980                 printf("MORE_RELIABLE ");
981         if (p->md_attr & EFI_MD_ATTR_RO)
982                 printf("RO ");
983         if (p->md_attr & EFI_MD_ATTR_RT)
984                 printf("RUNTIME");
985         printf("\n");
986 }
987
988 static void
989 print_efi_map_entries(struct efi_map_header *efihdr)
990 {
991
992         printf("%23s %12s %12s %8s %4s\n",
993             "Type", "Physical", "Virtual", "#Pages", "Attr");
994         foreach_efi_map_entry(efihdr, print_efi_map_entry);
995 }
996
997 #ifdef FDT
998 static void
999 try_load_dtb(caddr_t kmdp)
1000 {
1001         vm_offset_t dtbp;
1002
1003         dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
1004 #if defined(FDT_DTB_STATIC)
1005         /*
1006          * In case the device tree blob was not retrieved (from metadata) try
1007          * to use the statically embedded one.
1008          */
1009         if (dtbp == 0)
1010                 dtbp = (vm_offset_t)&fdt_static_dtb;
1011 #endif
1012
1013         if (dtbp == (vm_offset_t)NULL) {
1014                 printf("ERROR loading DTB\n");
1015                 return;
1016         }
1017
1018         if (OF_install(OFW_FDT, 0) == FALSE)
1019                 panic("Cannot install FDT");
1020
1021         if (OF_init((void *)dtbp) != 0)
1022                 panic("OF_init failed with the found device tree");
1023
1024         parse_fdt_bootargs();
1025 }
1026 #endif
1027
1028 static bool
1029 bus_probe(void)
1030 {
1031         bool has_acpi, has_fdt;
1032         char *order, *env;
1033
1034         has_acpi = has_fdt = false;
1035
1036 #ifdef FDT
1037         has_fdt = (OF_peer(0) != 0);
1038 #endif
1039 #ifdef DEV_ACPI
1040         has_acpi = (AcpiOsGetRootPointer() != 0);
1041 #endif
1042
1043         env = kern_getenv("kern.cfg.order");
1044         if (env != NULL) {
1045                 order = env;
1046                 while (order != NULL) {
1047                         if (has_acpi &&
1048                             strncmp(order, "acpi", 4) == 0 &&
1049                             (order[4] == ',' || order[4] == '\0')) {
1050                                 arm64_bus_method = ARM64_BUS_ACPI;
1051                                 break;
1052                         }
1053                         if (has_fdt &&
1054                             strncmp(order, "fdt", 3) == 0 &&
1055                             (order[3] == ',' || order[3] == '\0')) {
1056                                 arm64_bus_method = ARM64_BUS_FDT;
1057                                 break;
1058                         }
1059                         order = strchr(order, ',');
1060                 }
1061                 freeenv(env);
1062
1063                 /* If we set the bus method it is valid */
1064                 if (arm64_bus_method != ARM64_BUS_NONE)
1065                         return (true);
1066         }
1067         /* If no order or an invalid order was set use the default */
1068         if (arm64_bus_method == ARM64_BUS_NONE) {
1069                 if (has_fdt)
1070                         arm64_bus_method = ARM64_BUS_FDT;
1071                 else if (has_acpi)
1072                         arm64_bus_method = ARM64_BUS_ACPI;
1073         }
1074
1075         /*
1076          * If no option was set the default is valid, otherwise we are
1077          * setting one to get cninit() working, then calling panic to tell
1078          * the user about the invalid bus setup.
1079          */
1080         return (env == NULL);
1081 }
1082
1083 static void
1084 cache_setup(void)
1085 {
1086         int dczva_line_shift;
1087         uint32_t dczid_el0;
1088
1089         identify_cache(READ_SPECIALREG(ctr_el0));
1090
1091         dczid_el0 = READ_SPECIALREG(dczid_el0);
1092
1093         /* Check if dc zva is not prohibited */
1094         if (dczid_el0 & DCZID_DZP)
1095                 dczva_line_size = 0;
1096         else {
1097                 /* Same as with above calculations */
1098                 dczva_line_shift = DCZID_BS_SIZE(dczid_el0);
1099                 dczva_line_size = sizeof(int) << dczva_line_shift;
1100
1101                 /* Change pagezero function */
1102                 pagezero = pagezero_cache;
1103         }
1104 }
1105
1106 int
1107 memory_mapping_mode(vm_paddr_t pa)
1108 {
1109         struct efi_md *map, *p;
1110         size_t efisz;
1111         int ndesc, i;
1112
1113         if (efihdr == NULL)
1114                 return (VM_MEMATTR_WRITE_BACK);
1115
1116         /*
1117          * Memory map data provided by UEFI via the GetMemoryMap
1118          * Boot Services API.
1119          */
1120         efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
1121         map = (struct efi_md *)((uint8_t *)efihdr + efisz);
1122
1123         if (efihdr->descriptor_size == 0)
1124                 return (VM_MEMATTR_WRITE_BACK);
1125         ndesc = efihdr->memory_size / efihdr->descriptor_size;
1126
1127         for (i = 0, p = map; i < ndesc; i++,
1128             p = efi_next_descriptor(p, efihdr->descriptor_size)) {
1129                 if (pa < p->md_phys ||
1130                     pa >= p->md_phys + p->md_pages * EFI_PAGE_SIZE)
1131                         continue;
1132                 if (p->md_type == EFI_MD_TYPE_IOMEM ||
1133                     p->md_type == EFI_MD_TYPE_IOPORT)
1134                         return (VM_MEMATTR_DEVICE);
1135                 else if ((p->md_attr & EFI_MD_ATTR_WB) != 0 ||
1136                     p->md_type == EFI_MD_TYPE_RECLAIM)
1137                         return (VM_MEMATTR_WRITE_BACK);
1138                 else if ((p->md_attr & EFI_MD_ATTR_WT) != 0)
1139                         return (VM_MEMATTR_WRITE_THROUGH);
1140                 else if ((p->md_attr & EFI_MD_ATTR_WC) != 0)
1141                         return (VM_MEMATTR_WRITE_COMBINING);
1142                 break;
1143         }
1144
1145         return (VM_MEMATTR_DEVICE);
1146 }
1147
1148 void
1149 initarm(struct arm64_bootparams *abp)
1150 {
1151         struct efi_fb *efifb;
1152         struct pcpu *pcpup;
1153         char *env;
1154 #ifdef FDT
1155         struct mem_region mem_regions[FDT_MEM_REGIONS];
1156         int mem_regions_sz;
1157 #endif
1158         vm_offset_t lastaddr;
1159         caddr_t kmdp;
1160         bool valid;
1161
1162         boot_el = abp->boot_el;
1163
1164         /* Parse loader or FDT boot parametes. Determine last used address. */
1165         lastaddr = parse_boot_param(abp);
1166
1167         /* Find the kernel address */
1168         kmdp = preload_search_by_type("elf kernel");
1169         if (kmdp == NULL)
1170                 kmdp = preload_search_by_type("elf64 kernel");
1171
1172         identify_cpu(0);
1173         update_special_regs(0);
1174
1175         link_elf_ireloc(kmdp);
1176         try_load_dtb(kmdp);
1177
1178         efi_systbl_phys = MD_FETCH(kmdp, MODINFOMD_FW_HANDLE, vm_paddr_t);
1179
1180         /* Load the physical memory ranges */
1181         efihdr = (struct efi_map_header *)preload_search_info(kmdp,
1182             MODINFO_METADATA | MODINFOMD_EFI_MAP);
1183         if (efihdr != NULL)
1184                 add_efi_map_entries(efihdr);
1185 #ifdef FDT
1186         else {
1187                 /* Grab physical memory regions information from device tree. */
1188                 if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,
1189                     NULL) != 0)
1190                         panic("Cannot get physical memory regions");
1191                 physmem_hardware_regions(mem_regions, mem_regions_sz);
1192         }
1193         if (fdt_get_reserved_mem(mem_regions, &mem_regions_sz) == 0)
1194                 physmem_exclude_regions(mem_regions, mem_regions_sz,
1195                     EXFLAG_NODUMP | EXFLAG_NOALLOC);
1196 #endif
1197
1198         /* Exclude the EFI framebuffer from our view of physical memory. */
1199         efifb = (struct efi_fb *)preload_search_info(kmdp,
1200             MODINFO_METADATA | MODINFOMD_EFI_FB);
1201         if (efifb != NULL)
1202                 physmem_exclude_region(efifb->fb_addr, efifb->fb_size,
1203                     EXFLAG_NOALLOC);
1204
1205         /* Set the pcpu data, this is needed by pmap_bootstrap */
1206         pcpup = &__pcpu[0];
1207         pcpu_init(pcpup, 0, sizeof(struct pcpu));
1208
1209         /*
1210          * Set the pcpu pointer with a backup in tpidr_el1 to be
1211          * loaded when entering the kernel from userland.
1212          */
1213         __asm __volatile(
1214             "mov x18, %0 \n"
1215             "msr tpidr_el1, %0" :: "r"(pcpup));
1216
1217         PCPU_SET(curthread, &thread0);
1218         PCPU_SET(midr, get_midr());
1219
1220         /* Do basic tuning, hz etc */
1221         init_param1();
1222
1223         cache_setup();
1224         pan_setup();
1225
1226         /* Bootstrap enough of pmap  to enter the kernel proper */
1227         pmap_bootstrap(abp->kern_l0pt, abp->kern_l1pt,
1228             KERNBASE - abp->kern_delta, lastaddr - KERNBASE);
1229         /* Exclude entries neexed in teh DMAP region, but not phys_avail */
1230         if (efihdr != NULL)
1231                 exclude_efi_map_entries(efihdr);
1232         physmem_init_kernel_globals();
1233
1234         devmap_bootstrap(0, NULL);
1235
1236         valid = bus_probe();
1237
1238         cninit();
1239         set_ttbr0(abp->kern_ttbr0);
1240         cpu_tlb_flushID();
1241
1242         if (!valid)
1243                 panic("Invalid bus configuration: %s",
1244                     kern_getenv("kern.cfg.order"));
1245
1246         /*
1247          * Dump the boot metadata. We have to wait for cninit() since console
1248          * output is required. If it's grossly incorrect the kernel will never
1249          * make it this far.
1250          */
1251         if (getenv_is_true("debug.dump_modinfo_at_boot"))
1252                 preload_dump();
1253
1254         init_proc0(abp->kern_stack);
1255         msgbufinit(msgbufp, msgbufsize);
1256         mutex_init();
1257         init_param2(physmem);
1258
1259         dbg_init();
1260         kdb_init();
1261         pan_enable();
1262
1263         kcsan_cpu_init(0);
1264
1265         env = kern_getenv("kernelname");
1266         if (env != NULL)
1267                 strlcpy(kernelname, env, sizeof(kernelname));
1268
1269         if (boothowto & RB_VERBOSE) {
1270                 if (efihdr != NULL)
1271                         print_efi_map_entries(efihdr);
1272                 physmem_print_tables();
1273         }
1274
1275         early_boot = 0;
1276 }
1277
1278 void
1279 dbg_init(void)
1280 {
1281
1282         /* Clear OS lock */
1283         WRITE_SPECIALREG(oslar_el1, 0);
1284
1285         /* This permits DDB to use debug registers for watchpoints. */
1286         dbg_monitor_init();
1287
1288         /* TODO: Eventually will need to initialize debug registers here. */
1289 }
1290
1291 #ifdef DDB
1292 #include <ddb/ddb.h>
1293
1294 DB_SHOW_COMMAND(specialregs, db_show_spregs)
1295 {
1296 #define PRINT_REG(reg)  \
1297     db_printf(__STRING(reg) " = %#016lx\n", READ_SPECIALREG(reg))
1298
1299         PRINT_REG(actlr_el1);
1300         PRINT_REG(afsr0_el1);
1301         PRINT_REG(afsr1_el1);
1302         PRINT_REG(aidr_el1);
1303         PRINT_REG(amair_el1);
1304         PRINT_REG(ccsidr_el1);
1305         PRINT_REG(clidr_el1);
1306         PRINT_REG(contextidr_el1);
1307         PRINT_REG(cpacr_el1);
1308         PRINT_REG(csselr_el1);
1309         PRINT_REG(ctr_el0);
1310         PRINT_REG(currentel);
1311         PRINT_REG(daif);
1312         PRINT_REG(dczid_el0);
1313         PRINT_REG(elr_el1);
1314         PRINT_REG(esr_el1);
1315         PRINT_REG(far_el1);
1316 #if 0
1317         /* ARM64TODO: Enable VFP before reading floating-point registers */
1318         PRINT_REG(fpcr);
1319         PRINT_REG(fpsr);
1320 #endif
1321         PRINT_REG(id_aa64afr0_el1);
1322         PRINT_REG(id_aa64afr1_el1);
1323         PRINT_REG(id_aa64dfr0_el1);
1324         PRINT_REG(id_aa64dfr1_el1);
1325         PRINT_REG(id_aa64isar0_el1);
1326         PRINT_REG(id_aa64isar1_el1);
1327         PRINT_REG(id_aa64pfr0_el1);
1328         PRINT_REG(id_aa64pfr1_el1);
1329         PRINT_REG(id_afr0_el1);
1330         PRINT_REG(id_dfr0_el1);
1331         PRINT_REG(id_isar0_el1);
1332         PRINT_REG(id_isar1_el1);
1333         PRINT_REG(id_isar2_el1);
1334         PRINT_REG(id_isar3_el1);
1335         PRINT_REG(id_isar4_el1);
1336         PRINT_REG(id_isar5_el1);
1337         PRINT_REG(id_mmfr0_el1);
1338         PRINT_REG(id_mmfr1_el1);
1339         PRINT_REG(id_mmfr2_el1);
1340         PRINT_REG(id_mmfr3_el1);
1341 #if 0
1342         /* Missing from llvm */
1343         PRINT_REG(id_mmfr4_el1);
1344 #endif
1345         PRINT_REG(id_pfr0_el1);
1346         PRINT_REG(id_pfr1_el1);
1347         PRINT_REG(isr_el1);
1348         PRINT_REG(mair_el1);
1349         PRINT_REG(midr_el1);
1350         PRINT_REG(mpidr_el1);
1351         PRINT_REG(mvfr0_el1);
1352         PRINT_REG(mvfr1_el1);
1353         PRINT_REG(mvfr2_el1);
1354         PRINT_REG(revidr_el1);
1355         PRINT_REG(sctlr_el1);
1356         PRINT_REG(sp_el0);
1357         PRINT_REG(spsel);
1358         PRINT_REG(spsr_el1);
1359         PRINT_REG(tcr_el1);
1360         PRINT_REG(tpidr_el0);
1361         PRINT_REG(tpidr_el1);
1362         PRINT_REG(tpidrro_el0);
1363         PRINT_REG(ttbr0_el1);
1364         PRINT_REG(ttbr1_el1);
1365         PRINT_REG(vbar_el1);
1366 #undef PRINT_REG
1367 }
1368
1369 DB_SHOW_COMMAND(vtop, db_show_vtop)
1370 {
1371         uint64_t phys;
1372
1373         if (have_addr) {
1374                 phys = arm64_address_translate_s1e1r(addr);
1375                 db_printf("EL1 physical address reg (read):  0x%016lx\n", phys);
1376                 phys = arm64_address_translate_s1e1w(addr);
1377                 db_printf("EL1 physical address reg (write): 0x%016lx\n", phys);
1378                 phys = arm64_address_translate_s1e0r(addr);
1379                 db_printf("EL0 physical address reg (read):  0x%016lx\n", phys);
1380                 phys = arm64_address_translate_s1e0w(addr);
1381                 db_printf("EL0 physical address reg (write): 0x%016lx\n", phys);
1382         } else
1383                 db_printf("show vtop <virt_addr>\n");
1384 }
1385 #endif