2 * Initial implementation:
3 * Copyright (c) 2001 Robert Drehmel
6 * As long as the above copyright statement and this notice remain
7 * unchanged, you can do what ever you want with this file.
10 * Copyright (c) 2008 - 2012 Marius Strobl <marius@FreeBSD.org>
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
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.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * FreeBSD/sparc64 kernel loader - machine dependent part
41 * - implements copyin and readin functions that map kernel
42 * pages on demand. The machine independent code does not
43 * know the size of the kernel early enough to pre-enter
44 * TTEs and install just one 4MB mapping seemed to limiting
49 #include <sys/param.h>
51 #include <sys/linker.h>
52 #include <sys/queue.h>
53 #include <sys/types.h>
54 #ifdef LOADER_ZFS_SUPPORT
56 #include "../zfs/libzfs.h"
60 #include <machine/asi.h>
61 #include <machine/cmt.h>
62 #include <machine/cpufunc.h>
63 #include <machine/elf.h>
64 #include <machine/fireplane.h>
65 #include <machine/jbus.h>
66 #include <machine/lsu.h>
67 #include <machine/metadata.h>
68 #include <machine/tte.h>
69 #include <machine/tlb.h>
70 #include <machine/upa.h>
71 #include <machine/ver.h>
72 #include <machine/vmparam.h>
74 #include "bootstrap.h"
78 extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
83 LOADSZ = 0x1000000 /* for kernel and modules */
86 /* At least Sun Fire V1280 require page sized allocations to be claimed. */
87 CTASSERT(HEAPSZ % PAGE_SIZE == 0);
89 static struct mmu_ops {
90 void (*tlb_init)(void);
91 int (*mmu_mapin)(vm_offset_t va, vm_size_t len);
94 typedef void kernel_entry_t(vm_offset_t mdp, u_long o1, u_long o2, u_long o3,
97 static inline u_long dtlb_get_data_sun4u(u_int, u_int);
98 static int dtlb_enter_sun4u(u_int, u_long data, vm_offset_t);
99 static vm_offset_t dtlb_va_to_pa_sun4u(vm_offset_t);
100 static inline u_long itlb_get_data_sun4u(u_int, u_int);
101 static int itlb_enter_sun4u(u_int, u_long data, vm_offset_t);
102 static vm_offset_t itlb_va_to_pa_sun4u(vm_offset_t);
103 static void itlb_relocate_locked0_sun4u(void);
104 extern vm_offset_t md_load(char *, vm_offset_t *);
105 static int sparc64_autoload(void);
106 static ssize_t sparc64_readin(const int, vm_offset_t, const size_t);
107 static ssize_t sparc64_copyin(const void *, vm_offset_t, size_t);
108 static vm_offset_t claim_virt(vm_offset_t, size_t, int);
109 static vm_offset_t alloc_phys(size_t, int);
110 static int map_phys(int, size_t, vm_offset_t, vm_offset_t);
111 static void release_phys(vm_offset_t, u_int);
112 static int __elfN(exec)(struct preloaded_file *);
113 static int mmu_mapin_sun4u(vm_offset_t, vm_size_t);
114 static vm_offset_t init_heap(void);
115 static phandle_t find_bsp_sun4u(phandle_t, uint32_t);
116 const char *cpu_cpuid_prop_sun4u(void);
117 uint32_t cpu_get_mid_sun4u(void);
118 static void tlb_init_sun4u(void);
121 typedef u_int64_t tte_t;
123 static void pmap_print_tlb_sun4u(void);
124 static void pmap_print_tte_sun4u(tte_t, tte_t);
127 static struct mmu_ops mmu_ops_sun4u = { tlb_init_sun4u, mmu_mapin_sun4u };
130 struct tlb_entry *dtlb_store;
131 struct tlb_entry *itlb_store;
135 static u_int dtlb_slot_max;
136 static u_int itlb_slot_max;
137 static u_int tlb_locked;
139 static vm_offset_t curkva = 0;
140 static vm_offset_t heapva;
142 static char bootpath[64];
143 static phandle_t root;
145 #ifdef LOADER_ZFS_SUPPORT
146 static struct zfs_devdesc zfs_currdev;
150 * Machine dependent structures that the machine independent
153 struct devsw *devsw[] = {
154 #ifdef LOADER_DISK_SUPPORT
157 #ifdef LOADER_NET_SUPPORT
160 #ifdef LOADER_ZFS_SUPPORT
166 struct arch_switch archsw;
168 static struct file_format sparc64_elf = {
173 struct file_format *file_formats[] = {
178 struct fs_ops *file_system[] = {
179 #ifdef LOADER_ZFS_SUPPORT
182 #ifdef LOADER_UFS_SUPPORT
185 #ifdef LOADER_CD9660_SUPPORT
188 #ifdef LOADER_ZIP_SUPPORT
191 #ifdef LOADER_GZIP_SUPPORT
194 #ifdef LOADER_BZIP2_SUPPORT
197 #ifdef LOADER_NFS_SUPPORT
200 #ifdef LOADER_TFTP_SUPPORT
206 struct netif_driver *netif_drivers[] = {
207 #ifdef LOADER_NET_SUPPORT
213 extern struct console ofwconsole;
214 struct console *consoles[] = {
221 watch_phys_set_mask(vm_offset_t pa, u_long mask)
225 stxa(AA_DMMU_PWPR, ASI_DMMU, pa & (((2UL << 38) - 1) << 3));
226 lsucr = ldxa(0, ASI_LSU_CTL_REG);
227 lsucr = ((lsucr | LSU_PW) & ~LSU_PM_MASK) |
228 (mask << LSU_PM_SHIFT);
229 stxa(0, ASI_LSU_CTL_REG, lsucr);
234 watch_phys_set(vm_offset_t pa, int sz)
238 off = (u_long)pa & 7;
239 /* Test for misaligned watch points. */
242 return (watch_phys_set_mask(pa, ((1 << sz) - 1) << off));
247 watch_virt_set_mask(vm_offset_t va, u_long mask)
251 stxa(AA_DMMU_VWPR, ASI_DMMU, va & (((2UL << 41) - 1) << 3));
252 lsucr = ldxa(0, ASI_LSU_CTL_REG);
253 lsucr = ((lsucr | LSU_VW) & ~LSU_VM_MASK) |
254 (mask << LSU_VM_SHIFT);
255 stxa(0, ASI_LSU_CTL_REG, lsucr);
260 watch_virt_set(vm_offset_t va, int sz)
264 off = (u_long)va & 7;
265 /* Test for misaligned watch points. */
268 return (watch_virt_set_mask(va, ((1 << sz) - 1) << off));
276 sparc64_autoload(void)
283 sparc64_readin(const int fd, vm_offset_t va, const size_t len)
286 mmu_ops->mmu_mapin(va, len);
287 return (read(fd, (void *)va, len));
291 sparc64_copyin(const void *src, vm_offset_t dest, size_t len)
294 mmu_ops->mmu_mapin(dest, len);
295 memcpy((void *)dest, src, len);
303 claim_virt(vm_offset_t virt, size_t size, int align)
307 if (OF_call_method("claim", mmu, 3, 1, virt, size, align, &mva) == -1)
308 return ((vm_offset_t)-1);
313 alloc_phys(size_t size, int align)
315 cell_t phys_hi, phys_low;
317 if (OF_call_method("claim", memory, 2, 2, size, align, &phys_low,
319 return ((vm_offset_t)-1);
320 return ((vm_offset_t)phys_hi << 32 | phys_low);
324 map_phys(int mode, size_t size, vm_offset_t virt, vm_offset_t phys)
327 return (OF_call_method("map", mmu, 5, 0, (uint32_t)phys,
328 (uint32_t)(phys >> 32), virt, size, mode));
332 release_phys(vm_offset_t phys, u_int size)
335 (void)OF_call_method("release", memory, 3, 0, (uint32_t)phys,
336 (uint32_t)(phys >> 32), size);
340 __elfN(exec)(struct preloaded_file *fp)
342 struct file_metadata *fmp;
348 if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == 0)
350 e = (Elf_Ehdr *)&fmp->md_data;
352 if ((error = md_load(fp->f_args, &mdp)) != 0)
355 printf("jumping to kernel entry at %#lx.\n", e->e_entry);
357 pmap_print_tlb_sun4u();
364 OF_release((void *)heapva, HEAPSZ);
366 ((kernel_entry_t *)entry)(mdp, 0, 0, 0, openfirmware);
368 panic("%s: exec returned", __func__);
372 dtlb_get_data_sun4u(u_int tlb, u_int slot)
376 slot = TLB_DAR_SLOT(tlb, slot);
378 * We read ASI_DTLB_DATA_ACCESS_REG twice back-to-back in order to
379 * work around errata of USIII and beyond.
381 pstate = rdpr(pstate);
382 wrpr(pstate, pstate & ~PSTATE_IE, 0);
383 (void)ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
384 data = ldxa(slot, ASI_DTLB_DATA_ACCESS_REG);
385 wrpr(pstate, pstate, 0);
390 itlb_get_data_sun4u(u_int tlb, u_int slot)
394 slot = TLB_DAR_SLOT(tlb, slot);
396 * We read ASI_DTLB_DATA_ACCESS_REG twice back-to-back in order to
397 * work around errata of USIII and beyond.
399 pstate = rdpr(pstate);
400 wrpr(pstate, pstate & ~PSTATE_IE, 0);
401 (void)ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
402 data = ldxa(slot, ASI_ITLB_DATA_ACCESS_REG);
403 wrpr(pstate, pstate, 0);
408 dtlb_va_to_pa_sun4u(vm_offset_t va)
413 pstate = rdpr(pstate);
414 wrpr(pstate, pstate & ~PSTATE_IE, 0);
415 for (i = 0; i < dtlb_slot_max; i++) {
416 reg = ldxa(TLB_DAR_SLOT(tlb_locked, i),
417 ASI_DTLB_TAG_READ_REG);
418 if (TLB_TAR_VA(reg) != va)
420 reg = dtlb_get_data_sun4u(tlb_locked, i);
421 wrpr(pstate, pstate, 0);
423 if (cpu_impl == CPU_IMPL_SPARC64V ||
424 cpu_impl >= CPU_IMPL_ULTRASPARCIII)
425 return (reg & TD_PA_CH_MASK);
426 return (reg & TD_PA_SF_MASK);
428 wrpr(pstate, pstate, 0);
433 itlb_va_to_pa_sun4u(vm_offset_t va)
438 pstate = rdpr(pstate);
439 wrpr(pstate, pstate & ~PSTATE_IE, 0);
440 for (i = 0; i < itlb_slot_max; i++) {
441 reg = ldxa(TLB_DAR_SLOT(tlb_locked, i),
442 ASI_ITLB_TAG_READ_REG);
443 if (TLB_TAR_VA(reg) != va)
445 reg = itlb_get_data_sun4u(tlb_locked, i);
446 wrpr(pstate, pstate, 0);
448 if (cpu_impl == CPU_IMPL_SPARC64V ||
449 cpu_impl >= CPU_IMPL_ULTRASPARCIII)
450 return (reg & TD_PA_CH_MASK);
451 return (reg & TD_PA_SF_MASK);
453 wrpr(pstate, pstate, 0);
458 dtlb_enter_sun4u(u_int index, u_long data, vm_offset_t virt)
461 return (OF_call_method("SUNW,dtlb-load", mmu, 3, 0, index, data,
466 itlb_enter_sun4u(u_int index, u_long data, vm_offset_t virt)
469 if (cpu_impl == CPU_IMPL_ULTRASPARCIIIp && index == 0 &&
471 panic("%s: won't enter locked TLB entry at index 0 on USIII+",
473 return (OF_call_method("SUNW,itlb-load", mmu, 3, 0, index, data,
478 itlb_relocate_locked0_sun4u(void)
480 u_long data, pstate, tag;
483 if (cpu_impl != CPU_IMPL_ULTRASPARCIIIp)
486 pstate = rdpr(pstate);
487 wrpr(pstate, pstate & ~PSTATE_IE, 0);
489 data = itlb_get_data_sun4u(tlb_locked, 0);
490 if ((data & (TD_V | TD_L)) != (TD_V | TD_L)) {
491 wrpr(pstate, pstate, 0);
495 /* Flush the mapping of slot 0. */
496 tag = ldxa(TLB_DAR_SLOT(tlb_locked, 0), ASI_ITLB_TAG_READ_REG);
497 stxa(TLB_DEMAP_VA(TLB_TAR_VA(tag)) | TLB_DEMAP_PRIMARY |
498 TLB_DEMAP_PAGE, ASI_IMMU_DEMAP, 0);
499 flush(0); /* The USIII-family ignores the address. */
502 * Search a replacement slot != 0 and enter the data and tag
503 * that formerly were in slot 0.
505 for (i = 1; i < itlb_slot_max; i++) {
506 if ((itlb_get_data_sun4u(tlb_locked, i) & TD_V) != 0)
509 stxa(AA_IMMU_TAR, ASI_IMMU, tag);
510 stxa(TLB_DAR_SLOT(tlb_locked, i), ASI_ITLB_DATA_ACCESS_REG,
512 flush(0); /* The USIII-family ignores the address. */
515 wrpr(pstate, pstate, 0);
516 if (i == itlb_slot_max)
517 panic("%s: could not find a replacement slot", __func__);
521 mmu_mapin_sun4u(vm_offset_t va, vm_size_t len)
527 if (va + len > curkva)
530 pa = (vm_offset_t)-1;
531 len += va & PAGE_MASK_4M;
534 if (dtlb_va_to_pa_sun4u(va) == (vm_offset_t)-1 ||
535 itlb_va_to_pa_sun4u(va) == (vm_offset_t)-1) {
536 /* Allocate a physical page, claim the virtual area. */
537 if (pa == (vm_offset_t)-1) {
538 pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M);
539 if (pa == (vm_offset_t)-1)
540 panic("%s: out of memory", __func__);
541 mva = claim_virt(va, PAGE_SIZE_4M, 0);
543 panic("%s: can't claim virtual page "
544 "(wanted %#lx, got %#lx)",
547 * The mappings may have changed, be paranoid.
552 * Actually, we can only allocate two pages less at
553 * most (depending on the kernel TSB size).
555 if (dtlb_slot >= dtlb_slot_max)
556 panic("%s: out of dtlb_slots", __func__);
557 if (itlb_slot >= itlb_slot_max)
558 panic("%s: out of itlb_slots", __func__);
559 data = TD_V | TD_4M | TD_PA(pa) | TD_L | TD_CP |
561 dtlb_store[dtlb_slot].te_pa = pa;
562 dtlb_store[dtlb_slot].te_va = va;
563 index = dtlb_slot_max - dtlb_slot - 1;
564 if (dtlb_enter_sun4u(index, data, va) < 0)
565 panic("%s: can't enter dTLB slot %d data "
566 "%#lx va %#lx", __func__, index, data,
569 itlb_store[itlb_slot].te_pa = pa;
570 itlb_store[itlb_slot].te_va = va;
571 index = itlb_slot_max - itlb_slot - 1;
572 if (itlb_enter_sun4u(index, data, va) < 0)
573 panic("%s: can't enter iTLB slot %d data "
574 "%#lx va %#lxd", __func__, index, data,
577 pa = (vm_offset_t)-1;
579 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len;
582 if (pa != (vm_offset_t)-1)
583 release_phys(pa, PAGE_SIZE_4M);
591 /* There is no need for continuous physical heap memory. */
592 heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32);
597 find_bsp_sun4u(phandle_t node, uint32_t bspid)
599 char type[sizeof("cpu")];
603 for (; node > 0; node = OF_peer(node)) {
604 child = OF_child(node);
606 child = find_bsp_sun4u(child, bspid);
610 if (OF_getprop(node, "device_type", type,
613 if (strcmp(type, "cpu") != 0)
615 if (OF_getprop(node, cpu_cpuid_prop_sun4u(), &cpuid,
626 cpu_cpuid_prop_sun4u(void)
630 case CPU_IMPL_SPARC64:
631 case CPU_IMPL_SPARC64V:
632 case CPU_IMPL_ULTRASPARCI:
633 case CPU_IMPL_ULTRASPARCII:
634 case CPU_IMPL_ULTRASPARCIIi:
635 case CPU_IMPL_ULTRASPARCIIe:
636 return ("upa-portid");
637 case CPU_IMPL_ULTRASPARCIII:
638 case CPU_IMPL_ULTRASPARCIIIp:
639 case CPU_IMPL_ULTRASPARCIIIi:
640 case CPU_IMPL_ULTRASPARCIIIip:
642 case CPU_IMPL_ULTRASPARCIV:
643 case CPU_IMPL_ULTRASPARCIVp:
651 cpu_get_mid_sun4u(void)
655 case CPU_IMPL_SPARC64:
656 case CPU_IMPL_SPARC64V:
657 case CPU_IMPL_ULTRASPARCI:
658 case CPU_IMPL_ULTRASPARCII:
659 case CPU_IMPL_ULTRASPARCIIi:
660 case CPU_IMPL_ULTRASPARCIIe:
661 return (UPA_CR_GET_MID(ldxa(0, ASI_UPA_CONFIG_REG)));
662 case CPU_IMPL_ULTRASPARCIII:
663 case CPU_IMPL_ULTRASPARCIIIp:
664 return (FIREPLANE_CR_GET_AID(ldxa(AA_FIREPLANE_CONFIG,
665 ASI_FIREPLANE_CONFIG_REG)));
666 case CPU_IMPL_ULTRASPARCIIIi:
667 case CPU_IMPL_ULTRASPARCIIIip:
668 return (JBUS_CR_GET_JID(ldxa(0, ASI_JBUS_CONFIG_REG)));
669 case CPU_IMPL_ULTRASPARCIV:
670 case CPU_IMPL_ULTRASPARCIVp:
671 return (INTR_ID_GET_ID(ldxa(AA_INTR_ID, ASI_INTR_ID)));
682 cpu_impl = VER_IMPL(rdpr(ver));
684 case CPU_IMPL_SPARC64:
685 case CPU_IMPL_ULTRASPARCI:
686 case CPU_IMPL_ULTRASPARCII:
687 case CPU_IMPL_ULTRASPARCIIi:
688 case CPU_IMPL_ULTRASPARCIIe:
689 tlb_locked = TLB_DAR_T32;
691 case CPU_IMPL_ULTRASPARCIII:
692 case CPU_IMPL_ULTRASPARCIIIp:
693 case CPU_IMPL_ULTRASPARCIIIi:
694 case CPU_IMPL_ULTRASPARCIIIip:
695 case CPU_IMPL_ULTRASPARCIV:
696 case CPU_IMPL_ULTRASPARCIVp:
697 tlb_locked = TLB_DAR_T16;
699 case CPU_IMPL_SPARC64V:
700 tlb_locked = TLB_DAR_FTLB;
703 bsp = find_bsp_sun4u(OF_child(root), cpu_get_mid_sun4u());
705 panic("%s: no node for bootcpu?!?!", __func__);
707 if (OF_getprop(bsp, "#dtlb-entries", &dtlb_slot_max,
708 sizeof(dtlb_slot_max)) == -1 ||
709 OF_getprop(bsp, "#itlb-entries", &itlb_slot_max,
710 sizeof(itlb_slot_max)) == -1)
711 panic("%s: can't get TLB slot max.", __func__);
713 if (cpu_impl == CPU_IMPL_ULTRASPARCIIIp) {
715 printf("pre fixup:\n");
716 pmap_print_tlb_sun4u();
720 * Relocate the locked entry in it16 slot 0 (if existent)
721 * as part of working around Cheetah+ erratum 34.
723 itlb_relocate_locked0_sun4u();
726 printf("post fixup:\n");
727 pmap_print_tlb_sun4u();
731 dtlb_store = malloc(dtlb_slot_max * sizeof(*dtlb_store));
732 itlb_store = malloc(itlb_slot_max * sizeof(*itlb_store));
733 if (dtlb_store == NULL || itlb_store == NULL)
734 panic("%s: can't allocate TLB store", __func__);
737 #ifdef LOADER_ZFS_SUPPORT
739 sparc64_zfs_probe(void)
742 char alias[64], devname[sizeof(alias) + sizeof(":x") - 1];
743 char type[sizeof("device_type")];
744 char *bdev, *dev, *odev;
747 phandle_t aliases, options;
749 /* Get the GUID of the ZFS pool on the boot device. */
751 zfs_probe_dev(bootpath, &guid);
754 * Get the GUIDs of the ZFS pools on any additional disks listed in
755 * the boot-device environment variable.
757 if ((aliases = OF_finddevice("/aliases")) == -1)
759 options = OF_finddevice("/options");
760 len = OF_getproplen(options, "boot-device");
763 bdev = odev = malloc(len + 1);
766 if (OF_getprop(options, "boot-device", bdev, len) <= 0)
769 while ((dev = strsep(&bdev, " ")) != NULL) {
773 (void)OF_getprop(aliases, dev, alias, sizeof(alias));
775 * Don't probe the boot disk twice. Note that bootpath
776 * includes the partition specifier.
778 if (strncmp(alias, bootpath, strlen(alias)) == 0)
780 if (OF_getprop(OF_finddevice(alias), "device_type", type,
783 if (strcmp(type, "block") != 0)
786 /* Find freebsd-zfs slices in the VTOC. */
787 fd = open(alias, O_RDONLY);
790 lseek(fd, 0, SEEK_SET);
791 if (read(fd, &vtoc, sizeof(vtoc)) != sizeof(vtoc)) {
797 for (part = 0; part < 8; part++) {
798 if (part == 2 || vtoc.part[part].tag !=
799 VTOC_TAG_FREEBSD_ZFS)
801 (void)sprintf(devname, "%s:%c", alias, part + 'a');
802 if (zfs_probe_dev(devname, NULL) == ENXIO)
810 zfs_currdev.pool_guid = guid;
811 zfs_currdev.root_guid = 0;
812 zfs_currdev.d_dev = &zfs_dev;
813 zfs_currdev.d_type = zfs_currdev.d_dev->dv_type;
816 #endif /* LOADER_ZFS_SUPPORT */
819 main(int (*openfirm)(void *))
825 * Tell the Open Firmware functions where they find the OFW gate.
829 archsw.arch_getdev = ofw_getdev;
830 archsw.arch_copyin = sparc64_copyin;
831 archsw.arch_copyout = ofw_copyout;
832 archsw.arch_readin = sparc64_readin;
833 archsw.arch_autoload = sparc64_autoload;
834 #ifdef LOADER_ZFS_SUPPORT
835 archsw.arch_zfs_probe = sparc64_zfs_probe;
838 if (init_heap() == (vm_offset_t)-1)
840 setheap((void *)heapva, (void *)(heapva + HEAPSZ));
843 * Probe for a console.
847 if ((root = OF_peer(0)) == -1)
848 panic("%s: can't get root phandle", __func__);
849 OF_getprop(root, "compatible", compatible, sizeof(compatible));
850 mmu_ops = &mmu_ops_sun4u;
855 * Set up the current device.
857 OF_getprop(chosen, "bootpath", bootpath, sizeof(bootpath));
860 * Initialize devices.
862 for (dp = devsw; *dp != 0; dp++)
863 if ((*dp)->dv_init != 0)
866 #ifdef LOADER_ZFS_SUPPORT
867 if (zfs_currdev.pool_guid != 0) {
868 (void)strncpy(bootpath, zfs_fmtdev(&zfs_currdev),
869 sizeof(bootpath) - 1);
870 bootpath[sizeof(bootpath) - 1] = '\0';
875 * Sun compatible bootable CD-ROMs have a disk label placed before
876 * the ISO 9660 data, with the actual file system being in the first
877 * partition, while the other partitions contain pseudo disk labels
878 * with embedded boot blocks for different architectures, which may
879 * be followed by UFS file systems.
880 * The firmware will set the boot path to the partition it boots from
881 * ('f' in the sun4u/sun4v case), but we want the kernel to be loaded
882 * from the ISO 9660 file system ('a'), so the boot path needs to be
885 if (bootpath[strlen(bootpath) - 2] == ':' &&
886 bootpath[strlen(bootpath) - 1] == 'f')
887 bootpath[strlen(bootpath) - 1] = 'a';
889 env_setenv("currdev", EV_VOLATILE, bootpath,
890 ofw_setcurrdev, env_nounset);
891 env_setenv("loaddev", EV_VOLATILE, bootpath,
892 env_noset, env_nounset);
895 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
896 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
897 printf("bootpath=\"%s\"\n", bootpath);
899 /* Give control to the machine independent loader code. */
904 COMMAND_SET(heap, "heap", "show heap usage", command_heap);
907 command_heap(int argc, char *argv[])
911 printf("heap base at %p, top at %p, upper limit at %p\n", heapva,
912 sbrk(0), heapva + HEAPSZ);
916 COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
919 command_reboot(int argc, char *argv[])
923 for (i = 0; devsw[i] != NULL; ++i)
924 if (devsw[i]->dv_cleanup != NULL)
925 (devsw[i]->dv_cleanup)();
927 printf("Rebooting...\n");
931 /* provide this for panic, as it's not in the startup code */
940 static const char *const page_sizes[] = {
941 " 8k", " 64k", "512k", " 4m"
945 pmap_print_tte_sun4u(tte_t tag, tte_t tte)
949 page_sizes[(tte >> TD_SIZE_SHIFT) & TD_SIZE_MASK],
950 tag & TD_G ? "G" : " ");
951 printf(tte & TD_W ? "W " : " ");
952 printf(tte & TD_P ? "\e[33mP\e[0m " : " ");
953 printf(tte & TD_E ? "E " : " ");
954 printf(tte & TD_CV ? "CV " : " ");
955 printf(tte & TD_CP ? "CP " : " ");
956 printf(tte & TD_L ? "\e[32mL\e[0m " : " ");
957 printf(tte & TD_IE ? "IE " : " ");
958 printf(tte & TD_NFO ? "NFO " : " ");
959 printf("pa=0x%lx va=0x%lx ctx=%ld\n",
960 TD_PA(tte), TLB_TAR_VA(tag), TLB_TAR_CTX(tag));
964 pmap_print_tlb_sun4u(void)
970 pstate = rdpr(pstate);
971 for (i = 0; i < itlb_slot_max; i++) {
972 wrpr(pstate, pstate & ~PSTATE_IE, 0);
973 tte = itlb_get_data_sun4u(tlb_locked, i);
974 wrpr(pstate, pstate, 0);
977 tag = ldxa(TLB_DAR_SLOT(tlb_locked, i),
978 ASI_ITLB_TAG_READ_REG);
979 printf("iTLB-%2u: ", i);
980 pmap_print_tte_sun4u(tag, tte);
982 for (i = 0; i < dtlb_slot_max; i++) {
983 wrpr(pstate, pstate & ~PSTATE_IE, 0);
984 tte = dtlb_get_data_sun4u(tlb_locked, i);
985 wrpr(pstate, pstate, 0);
988 tag = ldxa(TLB_DAR_SLOT(tlb_locked, i),
989 ASI_DTLB_TAG_READ_REG);
990 printf("dTLB-%2u: ", i);
991 pmap_print_tte_sun4u(tag, tte);