2 * Copyright (c) 2014 Andrew Turner
3 * Copyright (c) 2015-2017 Ruslan Bukin <br@bsdpad.com>
6 * Portions of this software were developed by SRI International and the
7 * University of Cambridge Computer Laboratory under DARPA/AFRL contract
8 * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
10 * Portions of this software were developed by the University of Cambridge
11 * Computer Laboratory as part of the CTSRD Project, with support from the
12 * UK Higher Education Innovation Fund (HEIF).
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "opt_platform.h"
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
42 #include <sys/systm.h>
47 #include <sys/devmap.h>
49 #include <sys/imgact.h>
51 #include <sys/kernel.h>
53 #include <sys/limits.h>
54 #include <sys/linker.h>
55 #include <sys/msgbuf.h>
58 #include <sys/ptrace.h>
59 #include <sys/reboot.h>
60 #include <sys/rwlock.h>
61 #include <sys/sched.h>
62 #include <sys/signalvar.h>
63 #include <sys/syscallsubr.h>
64 #include <sys/sysent.h>
65 #include <sys/sysproto.h>
66 #include <sys/tslog.h>
67 #include <sys/ucontext.h>
68 #include <sys/vmmeter.h>
71 #include <vm/vm_param.h>
72 #include <vm/vm_kern.h>
73 #include <vm/vm_object.h>
74 #include <vm/vm_page.h>
75 #include <vm/vm_phys.h>
77 #include <vm/vm_map.h>
78 #include <vm/vm_pager.h>
80 #include <machine/riscvreg.h>
81 #include <machine/cpu.h>
82 #include <machine/kdb.h>
83 #include <machine/machdep.h>
84 #include <machine/pcb.h>
85 #include <machine/reg.h>
86 #include <machine/trap.h>
87 #include <machine/vmparam.h>
88 #include <machine/intr.h>
89 #include <machine/sbi.h>
91 #include <machine/asm.h>
94 #include <machine/fpe.h>
98 #include <dev/fdt/fdt_common.h>
99 #include <dev/ofw/openfirm.h>
102 static void get_fpcontext(struct thread *td, mcontext_t *mcp);
103 static void set_fpcontext(struct thread *td, mcontext_t *mcp);
105 struct pcpu __pcpu[MAXCPU];
107 static struct trapframe proc0_tf;
114 #define DTB_SIZE_MAX (1024 * 1024)
116 vm_paddr_t physmap[PHYS_AVAIL_ENTRIES];
119 struct kva_md_info kmi;
121 int64_t dcache_line_size; /* The minimum D cache line size */
122 int64_t icache_line_size; /* The minimum I cache line size */
123 int64_t idcache_line_size; /* The minimum cache line size */
125 uint32_t boot_hart; /* The hart we booted on. */
131 cpu_startup(void *dummy)
137 printf("real memory = %ju (%ju MB)\n", ptoa((uintmax_t)realmem),
138 ptoa((uintmax_t)realmem) / (1024 * 1024));
141 * Display any holes after the first chunk of extended memory.
146 printf("Physical memory chunk(s):\n");
147 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
150 size = phys_avail[indx + 1] - phys_avail[indx];
152 "0x%016jx - 0x%016jx, %ju bytes (%ju pages)\n",
153 (uintmax_t)phys_avail[indx],
154 (uintmax_t)phys_avail[indx + 1] - 1,
155 (uintmax_t)size, (uintmax_t)size / PAGE_SIZE);
159 vm_ksubmap_init(&kmi);
161 printf("avail memory = %ju (%ju MB)\n",
162 ptoa((uintmax_t)vm_free_count()),
163 ptoa((uintmax_t)vm_free_count()) / (1024 * 1024));
165 devmap_print_table();
168 vm_pager_bufferinit();
171 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
174 cpu_idle_wakeup(int cpu)
181 fill_regs(struct thread *td, struct reg *regs)
183 struct trapframe *frame;
185 frame = td->td_frame;
186 regs->sepc = frame->tf_sepc;
187 regs->sstatus = frame->tf_sstatus;
188 regs->ra = frame->tf_ra;
189 regs->sp = frame->tf_sp;
190 regs->gp = frame->tf_gp;
191 regs->tp = frame->tf_tp;
193 memcpy(regs->t, frame->tf_t, sizeof(regs->t));
194 memcpy(regs->s, frame->tf_s, sizeof(regs->s));
195 memcpy(regs->a, frame->tf_a, sizeof(regs->a));
201 set_regs(struct thread *td, struct reg *regs)
203 struct trapframe *frame;
205 frame = td->td_frame;
206 frame->tf_sepc = regs->sepc;
207 frame->tf_ra = regs->ra;
208 frame->tf_sp = regs->sp;
209 frame->tf_gp = regs->gp;
210 frame->tf_tp = regs->tp;
212 memcpy(frame->tf_t, regs->t, sizeof(frame->tf_t));
213 memcpy(frame->tf_s, regs->s, sizeof(frame->tf_s));
214 memcpy(frame->tf_a, regs->a, sizeof(frame->tf_a));
220 fill_fpregs(struct thread *td, struct fpreg *regs)
227 if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
229 * If we have just been running FPE instructions we will
230 * need to save the state to memcpy it below.
235 memcpy(regs->fp_x, pcb->pcb_x, sizeof(regs->fp_x));
236 regs->fp_fcsr = pcb->pcb_fcsr;
239 memset(regs, 0, sizeof(*regs));
245 set_fpregs(struct thread *td, struct fpreg *regs)
248 struct trapframe *frame;
251 frame = td->td_frame;
254 memcpy(pcb->pcb_x, regs->fp_x, sizeof(regs->fp_x));
255 pcb->pcb_fcsr = regs->fp_fcsr;
256 pcb->pcb_fpflags |= PCB_FP_STARTED;
257 frame->tf_sstatus &= ~SSTATUS_FS_MASK;
258 frame->tf_sstatus |= SSTATUS_FS_CLEAN;
265 fill_dbregs(struct thread *td, struct dbreg *regs)
268 panic("fill_dbregs");
272 set_dbregs(struct thread *td, struct dbreg *regs)
279 ptrace_set_pc(struct thread *td, u_long addr)
282 td->td_frame->tf_sepc = addr;
287 ptrace_single_step(struct thread *td)
295 ptrace_clear_single_step(struct thread *td)
303 exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
305 struct trapframe *tf;
311 memset(tf, 0, sizeof(struct trapframe));
314 tf->tf_sp = STACKALIGN(stack);
315 tf->tf_ra = imgp->entry_addr;
316 tf->tf_sepc = imgp->entry_addr;
318 pcb->pcb_fpflags &= ~PCB_FP_STARTED;
321 /* Sanity check these are the same size, they will be memcpy'd to and fro */
322 CTASSERT(sizeof(((struct trapframe *)0)->tf_a) ==
323 sizeof((struct gpregs *)0)->gp_a);
324 CTASSERT(sizeof(((struct trapframe *)0)->tf_s) ==
325 sizeof((struct gpregs *)0)->gp_s);
326 CTASSERT(sizeof(((struct trapframe *)0)->tf_t) ==
327 sizeof((struct gpregs *)0)->gp_t);
328 CTASSERT(sizeof(((struct trapframe *)0)->tf_a) ==
329 sizeof((struct reg *)0)->a);
330 CTASSERT(sizeof(((struct trapframe *)0)->tf_s) ==
331 sizeof((struct reg *)0)->s);
332 CTASSERT(sizeof(((struct trapframe *)0)->tf_t) ==
333 sizeof((struct reg *)0)->t);
335 /* Support for FDT configurations only. */
339 get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
341 struct trapframe *tf = td->td_frame;
343 memcpy(mcp->mc_gpregs.gp_t, tf->tf_t, sizeof(mcp->mc_gpregs.gp_t));
344 memcpy(mcp->mc_gpregs.gp_s, tf->tf_s, sizeof(mcp->mc_gpregs.gp_s));
345 memcpy(mcp->mc_gpregs.gp_a, tf->tf_a, sizeof(mcp->mc_gpregs.gp_a));
347 if (clear_ret & GET_MC_CLEAR_RET) {
348 mcp->mc_gpregs.gp_a[0] = 0;
349 mcp->mc_gpregs.gp_t[0] = 0; /* clear syscall error */
352 mcp->mc_gpregs.gp_ra = tf->tf_ra;
353 mcp->mc_gpregs.gp_sp = tf->tf_sp;
354 mcp->mc_gpregs.gp_gp = tf->tf_gp;
355 mcp->mc_gpregs.gp_tp = tf->tf_tp;
356 mcp->mc_gpregs.gp_sepc = tf->tf_sepc;
357 mcp->mc_gpregs.gp_sstatus = tf->tf_sstatus;
358 get_fpcontext(td, mcp);
364 set_mcontext(struct thread *td, mcontext_t *mcp)
366 struct trapframe *tf;
371 * Permit changes to the USTATUS bits of SSTATUS.
373 * Ignore writes to read-only bits (SD, XS).
375 * Ignore writes to the FS field as set_fpcontext() will set
378 if (((mcp->mc_gpregs.gp_sstatus ^ tf->tf_sstatus) &
379 ~(SSTATUS_SD | SSTATUS_XS_MASK | SSTATUS_FS_MASK | SSTATUS_UPIE |
383 memcpy(tf->tf_t, mcp->mc_gpregs.gp_t, sizeof(tf->tf_t));
384 memcpy(tf->tf_s, mcp->mc_gpregs.gp_s, sizeof(tf->tf_s));
385 memcpy(tf->tf_a, mcp->mc_gpregs.gp_a, sizeof(tf->tf_a));
387 tf->tf_ra = mcp->mc_gpregs.gp_ra;
388 tf->tf_sp = mcp->mc_gpregs.gp_sp;
389 tf->tf_gp = mcp->mc_gpregs.gp_gp;
390 tf->tf_sepc = mcp->mc_gpregs.gp_sepc;
391 tf->tf_sstatus = mcp->mc_gpregs.gp_sstatus;
392 set_fpcontext(td, mcp);
398 get_fpcontext(struct thread *td, mcontext_t *mcp)
405 curpcb = curthread->td_pcb;
407 KASSERT(td->td_pcb == curpcb, ("Invalid fpe pcb"));
409 if ((curpcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
411 * If we have just been running FPE instructions we will
412 * need to save the state to memcpy it below.
416 KASSERT((curpcb->pcb_fpflags & ~PCB_FP_USERMASK) == 0,
417 ("Non-userspace FPE flags set in get_fpcontext"));
418 memcpy(mcp->mc_fpregs.fp_x, curpcb->pcb_x,
419 sizeof(mcp->mc_fpregs));
420 mcp->mc_fpregs.fp_fcsr = curpcb->pcb_fcsr;
421 mcp->mc_fpregs.fp_flags = curpcb->pcb_fpflags;
422 mcp->mc_flags |= _MC_FP_VALID;
430 set_fpcontext(struct thread *td, mcontext_t *mcp)
436 td->td_frame->tf_sstatus &= ~SSTATUS_FS_MASK;
437 td->td_frame->tf_sstatus |= SSTATUS_FS_OFF;
442 if ((mcp->mc_flags & _MC_FP_VALID) != 0) {
443 curpcb = curthread->td_pcb;
444 /* FPE usage is enabled, override registers. */
445 memcpy(curpcb->pcb_x, mcp->mc_fpregs.fp_x,
446 sizeof(mcp->mc_fpregs));
447 curpcb->pcb_fcsr = mcp->mc_fpregs.fp_fcsr;
448 curpcb->pcb_fpflags = mcp->mc_fpregs.fp_flags & PCB_FP_USERMASK;
449 td->td_frame->tf_sstatus |= SSTATUS_FS_CLEAN;
463 if (!sched_runnable())
478 __asm __volatile("wfi");
482 * Flush the D-cache for non-DMA I/O so that the I-cache can
483 * be made coherent later.
486 cpu_flush_dcache(void *ptr, size_t len)
492 /* Get current clock frequency for the given CPU ID. */
494 cpu_est_clockrate(int cpu_id, uint64_t *rate)
497 panic("cpu_est_clockrate");
501 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
512 if (td->td_md.md_spinlock_count == 0) {
513 reg = intr_disable();
514 td->td_md.md_spinlock_count = 1;
515 td->td_md.md_saved_sstatus_ie = reg;
518 td->td_md.md_spinlock_count++;
525 register_t sstatus_ie;
528 sstatus_ie = td->td_md.md_saved_sstatus_ie;
529 td->td_md.md_spinlock_count--;
530 if (td->td_md.md_spinlock_count == 0) {
532 intr_restore(sstatus_ie);
536 #ifndef _SYS_SYSPROTO_H_
537 struct sigreturn_args {
543 sys_sigreturn(struct thread *td, struct sigreturn_args *uap)
548 if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
551 error = set_mcontext(td, &uc.uc_mcontext);
555 /* Restore signal mask. */
556 kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
558 return (EJUSTRETURN);
562 * Construct a PCB from a trapframe. This is called from kdb_trap() where
563 * we want to start a backtrace from the function that caused us to enter
564 * the debugger. We have the context in the trapframe, but base the trace
565 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
566 * enough for a backtrace.
569 makectx(struct trapframe *tf, struct pcb *pcb)
572 memcpy(pcb->pcb_s, tf->tf_s, sizeof(tf->tf_s));
574 pcb->pcb_ra = tf->tf_sepc;
575 pcb->pcb_sp = tf->tf_sp;
576 pcb->pcb_gp = tf->tf_gp;
577 pcb->pcb_tp = tf->tf_tp;
581 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
583 struct sigframe *fp, frame;
584 struct sysentvec *sysent;
585 struct trapframe *tf;
594 PROC_LOCK_ASSERT(p, MA_OWNED);
596 sig = ksi->ksi_signo;
598 mtx_assert(&psp->ps_mtx, MA_OWNED);
601 onstack = sigonstack(tf->tf_sp);
603 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
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);
612 fp = (struct sigframe *)td->td_frame->tf_sp;
615 /* Make room, keeping the stack aligned */
617 fp = (struct sigframe *)STACKALIGN(fp);
619 /* Fill in the frame to copy out */
620 bzero(&frame, sizeof(frame));
621 get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
622 frame.sf_si = ksi->ksi_info;
623 frame.sf_uc.uc_sigmask = *mask;
624 frame.sf_uc.uc_stack = td->td_sigstk;
625 frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ?
626 (onstack ? SS_ONSTACK : 0) : SS_DISABLE;
627 mtx_unlock(&psp->ps_mtx);
628 PROC_UNLOCK(td->td_proc);
630 /* Copy the sigframe out to the user's stack. */
631 if (copyout(&frame, fp, sizeof(*fp)) != 0) {
632 /* Process has trashed its stack. Kill it. */
633 CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp);
639 tf->tf_a[1] = (register_t)&fp->sf_si;
640 tf->tf_a[2] = (register_t)&fp->sf_uc;
642 tf->tf_sepc = (register_t)catcher;
643 tf->tf_sp = (register_t)fp;
645 sysent = p->p_sysent;
646 if (sysent->sv_sigcode_base != 0)
647 tf->tf_ra = (register_t)sysent->sv_sigcode_base;
649 tf->tf_ra = (register_t)(sysent->sv_psstrings -
650 *(sysent->sv_szsigcode));
652 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_sepc,
656 mtx_lock(&psp->ps_mtx);
660 init_proc0(vm_offset_t kstack)
666 proc_linkup0(&proc0, &thread0);
667 thread0.td_kstack = kstack;
668 thread0.td_kstack_pages = KSTACK_PAGES;
669 thread0.td_pcb = (struct pcb *)(thread0.td_kstack +
670 thread0.td_kstack_pages * PAGE_SIZE) - 1;
671 thread0.td_pcb->pcb_fpflags = 0;
672 thread0.td_frame = &proc0_tf;
673 pcpup->pc_curpcb = thread0.td_pcb;
677 add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
680 u_int i, insert_idx, _physmap_idx;
682 _physmap_idx = *physmap_idxp;
688 * Find insertion point while checking for overlap. Start off by
689 * assuming the new entry will be added to the end.
691 insert_idx = _physmap_idx;
692 for (i = 0; i <= _physmap_idx; i += 2) {
693 if (base < physmap[i + 1]) {
694 if (base + length <= physmap[i]) {
698 if (boothowto & RB_VERBOSE)
700 "Overlapping memory regions, ignoring second region\n");
705 /* See if we can prepend to the next entry. */
706 if (insert_idx <= _physmap_idx &&
707 base + length == physmap[insert_idx]) {
708 physmap[insert_idx] = base;
712 /* See if we can append to the previous entry. */
713 if (insert_idx > 0 && base == physmap[insert_idx - 1]) {
714 physmap[insert_idx - 1] += length;
719 *physmap_idxp = _physmap_idx;
720 if (_physmap_idx == PHYS_AVAIL_ENTRIES) {
722 "Too many segments in the physical address map, giving up\n");
727 * Move the last 'N' entries down to make room for the new
730 for (i = _physmap_idx; i > insert_idx; i -= 2) {
731 physmap[i] = physmap[i - 2];
732 physmap[i + 1] = physmap[i - 1];
735 /* Insert the new entry. */
736 physmap[insert_idx] = base;
737 physmap[insert_idx + 1] = base + length;
739 printf("physmap[%d] = 0x%016lx\n", insert_idx, base);
740 printf("physmap[%d] = 0x%016lx\n", insert_idx + 1, base + length);
746 try_load_dtb(caddr_t kmdp, vm_offset_t dtbp)
749 #if defined(FDT_DTB_STATIC)
750 dtbp = (vm_offset_t)&fdt_static_dtb;
753 if (dtbp == (vm_offset_t)NULL) {
754 printf("ERROR loading DTB\n");
758 if (OF_install(OFW_FDT, 0) == FALSE)
759 panic("Cannot install FDT");
761 if (OF_init((void *)dtbp) != 0)
762 panic("OF_init failed with the found device tree");
772 dcache_line_size = 0;
773 icache_line_size = 0;
774 idcache_line_size = 0;
778 * Fake up a boot descriptor table.
779 * RISCVTODO: This needs to be done via loader (when it's available).
782 fake_preload_metadata(struct riscv_bootparams *rvbp __unused)
784 static uint32_t fake_preload[35];
786 vm_offset_t zstart = 0, zend = 0;
788 vm_offset_t lastaddr;
793 fake_preload[i++] = MODINFO_NAME;
794 fake_preload[i++] = strlen("kernel") + 1;
795 strcpy((char*)&fake_preload[i++], "kernel");
797 fake_preload[i++] = MODINFO_TYPE;
798 fake_preload[i++] = strlen("elf64 kernel") + 1;
799 strcpy((char*)&fake_preload[i++], "elf64 kernel");
801 fake_preload[i++] = MODINFO_ADDR;
802 fake_preload[i++] = sizeof(vm_offset_t);
803 *(vm_offset_t *)&fake_preload[i++] =
804 (vm_offset_t)(KERNBASE + KERNENTRY);
806 fake_preload[i++] = MODINFO_SIZE;
807 fake_preload[i++] = sizeof(vm_offset_t);
808 fake_preload[i++] = (vm_offset_t)&end -
809 (vm_offset_t)(KERNBASE + KERNENTRY);
814 if (*(uint32_t *)KERNVIRTADDR == MAGIC_TRAMP_NUMBER) {
815 fake_preload[i++] = MODINFO_METADATA|MODINFOMD_SSYM;
816 fake_preload[i++] = sizeof(vm_offset_t);
817 fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 4);
818 fake_preload[i++] = MODINFO_METADATA|MODINFOMD_ESYM;
819 fake_preload[i++] = sizeof(vm_offset_t);
820 fake_preload[i++] = *(uint32_t *)(KERNVIRTADDR + 8);
821 lastaddr = *(uint32_t *)(KERNVIRTADDR + 8);
823 zstart = *(uint32_t *)(KERNVIRTADDR + 4);
824 db_fetch_ksymtab(zstart, zend);
828 lastaddr = (vm_offset_t)&end;
829 fake_preload[i++] = 0;
831 preload_metadata = (void *)fake_preload;
837 initriscv(struct riscv_bootparams *rvbp)
839 struct mem_region mem_regions[FDT_MEM_REGIONS];
841 vm_offset_t rstart, rend;
844 vm_offset_t lastaddr;
849 TSRAW(&thread0, TS_ENTER, __func__, NULL);
851 /* Set the pcpu data, this is needed by pmap_bootstrap */
853 pcpu_init(pcpup, 0, sizeof(struct pcpu));
854 pcpup->pc_hart = boot_hart;
856 /* Set the pcpu pointer */
857 __asm __volatile("mv tp, %0" :: "r"(pcpup));
859 PCPU_SET(curthread, &thread0);
861 /* Initialize SBI interface. */
864 /* Set the module data location */
865 lastaddr = fake_preload_metadata(rvbp);
867 /* Find the kernel address */
868 kmdp = preload_search_by_type("elf kernel");
870 kmdp = preload_search_by_type("elf64 kernel");
872 boothowto = RB_VERBOSE | RB_SINGLE;
873 boothowto = RB_VERBOSE;
878 try_load_dtb(kmdp, rvbp->dtbp_virt);
881 /* Load the physical memory ranges */
885 /* Grab physical memory regions information from device tree. */
886 if (fdt_get_mem_regions(mem_regions, &mem_regions_sz, NULL) != 0)
887 panic("Cannot get physical memory regions");
890 e = s + DTB_SIZE_MAX;
892 for (i = 0; i < mem_regions_sz; i++) {
893 rstart = mem_regions[i].mr_start;
894 rend = (mem_regions[i].mr_start + mem_regions[i].mr_size);
896 if ((rstart < s) && (rend > e)) {
897 /* Exclude DTB region. */
898 add_physmap_entry(rstart, (s - rstart), physmap, &physmap_idx);
899 add_physmap_entry(e, (rend - e), physmap, &physmap_idx);
901 add_physmap_entry(mem_regions[i].mr_start,
902 mem_regions[i].mr_size, physmap, &physmap_idx);
907 /* Do basic tuning, hz etc */
912 /* Bootstrap enough of pmap to enter the kernel proper */
913 kernlen = (lastaddr - KERNBASE);
914 pmap_bootstrap(rvbp->kern_l1pt, mem_regions[0].mr_start, kernlen);
916 /* Establish static device mappings */
917 devmap_bootstrap(0, NULL);
921 init_proc0(rvbp->kern_stack);
923 msgbufinit(msgbufp, msgbufsize);
925 init_param2(physmem);
935 bzero(void *buf, size_t len)