main.c revision 182766
1/*- 2 * Initial implementation: 3 * Copyright (c) 2001 Robert Drehmel 4 * All rights reserved. 5 * 6 * As long as the above copyright statement and this notice remain 7 * unchanged, you can do what ever you want with this file. 8 */ 9 10#include <sys/cdefs.h> 11__FBSDID("$FreeBSD: head/sys/boot/sparc64/loader/main.c 182766 2008-09-04 19:41:54Z marius $"); 12 13/* 14 * FreeBSD/sparc64 kernel loader - machine dependent part 15 * 16 * - implements copyin and readin functions that map kernel 17 * pages on demand. The machine independent code does not 18 * know the size of the kernel early enough to pre-enter 19 * TTEs and install just one 4MB mapping seemed to limiting 20 * to me. 21 */ 22 23#include <stand.h> 24#include <sys/exec.h> 25#include <sys/param.h> 26#include <sys/queue.h> 27#include <sys/linker.h> 28#include <sys/types.h> 29 30#include <vm/vm.h> 31#include <machine/asi.h> 32#include <machine/cpufunc.h> 33#include <machine/elf.h> 34#include <machine/lsu.h> 35#include <machine/metadata.h> 36#include <machine/tte.h> 37#include <machine/tlb.h> 38#include <machine/upa.h> 39#include <machine/ver.h> 40 41#include "bootstrap.h" 42#include "libofw.h" 43#include "dev_net.h" 44 45extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[]; 46 47enum { 48 HEAPVA = 0x800000, 49 HEAPSZ = 0x1000000, 50 LOADSZ = 0x1000000 /* for kernel and modules */ 51}; 52 53static struct mmu_ops { 54 void (*tlb_init)(void); 55 int (*mmu_mapin)(vm_offset_t va, vm_size_t len); 56} *mmu_ops; 57 58typedef void kernel_entry_t(vm_offset_t mdp, u_long o1, u_long o2, u_long o3, 59 void *openfirmware); 60 61static inline u_long dtlb_get_data_sun4u(int slot); 62static void dtlb_enter_sun4u(u_long vpn, u_long data); 63static vm_offset_t dtlb_va_to_pa_sun4u(vm_offset_t); 64static inline u_long itlb_get_data_sun4u(int slot); 65static void itlb_enter_sun4u(u_long vpn, u_long data); 66static vm_offset_t itlb_va_to_pa_sun4u(vm_offset_t); 67extern vm_offset_t md_load(char *, vm_offset_t *); 68static int sparc64_autoload(void); 69static ssize_t sparc64_readin(const int, vm_offset_t, const size_t); 70static ssize_t sparc64_copyin(const void *, vm_offset_t, size_t); 71static void sparc64_maphint(vm_offset_t, size_t); 72static vm_offset_t claim_virt(vm_offset_t, size_t, int); 73static vm_offset_t alloc_phys(size_t, int); 74static int map_phys(int, size_t, vm_offset_t, vm_offset_t); 75static void release_phys(vm_offset_t, u_int); 76static int __elfN(exec)(struct preloaded_file *); 77static int mmu_mapin_sun4u(vm_offset_t, vm_size_t); 78static int mmu_mapin_sun4v(vm_offset_t, vm_size_t); 79static vm_offset_t init_heap(void); 80static void tlb_init_sun4u(void); 81static void tlb_init_sun4v(void); 82 83#ifdef LOADER_DEBUG 84typedef u_int64_t tte_t; 85 86static void pmap_print_tlb_sun4u(void); 87static void pmap_print_tte_sun4u(tte_t, tte_t); 88#endif 89 90static struct mmu_ops mmu_ops_sun4u = { tlb_init_sun4u, mmu_mapin_sun4u }; 91static struct mmu_ops mmu_ops_sun4v = { tlb_init_sun4v, mmu_mapin_sun4v }; 92 93/* sun4u */ 94struct tlb_entry *dtlb_store; 95struct tlb_entry *itlb_store; 96int dtlb_slot; 97int itlb_slot; 98int cpu_impl; 99static int dtlb_slot_max; 100static int itlb_slot_max; 101 102/* sun4v */ 103static struct tlb_entry *tlb_store; 104static int is_sun4v = 0; 105/* 106 * no direct TLB access on sun4v 107 * we somewhat arbitrarily declare enough 108 * slots to cover a 4GB AS with 4MB pages 109 */ 110#define SUN4V_TLB_SLOT_MAX (1 << 10) 111 112static vm_offset_t curkva = 0; 113static vm_offset_t heapva; 114 115static phandle_t root; 116 117/* 118 * Machine dependent structures that the machine independent 119 * loader part uses. 120 */ 121struct devsw *devsw[] = { 122#ifdef LOADER_DISK_SUPPORT 123 &ofwdisk, 124#endif 125#ifdef LOADER_NET_SUPPORT 126 &netdev, 127#endif 128 0 129}; 130struct arch_switch archsw; 131 132static struct file_format sparc64_elf = { 133 __elfN(loadfile), 134 __elfN(exec) 135}; 136struct file_format *file_formats[] = { 137 &sparc64_elf, 138 0 139}; 140struct fs_ops *file_system[] = { 141#ifdef LOADER_UFS_SUPPORT 142 &ufs_fsops, 143#endif 144#ifdef LOADER_CD9660_SUPPORT 145 &cd9660_fsops, 146#endif 147#ifdef LOADER_ZIP_SUPPORT 148 &zipfs_fsops, 149#endif 150#ifdef LOADER_GZIP_SUPPORT 151 &gzipfs_fsops, 152#endif 153#ifdef LOADER_BZIP2_SUPPORT 154 &bzipfs_fsops, 155#endif 156#ifdef LOADER_NFS_SUPPORT 157 &nfs_fsops, 158#endif 159#ifdef LOADER_TFTP_SUPPORT 160 &tftp_fsops, 161#endif 162 0 163}; 164struct netif_driver *netif_drivers[] = { 165#ifdef LOADER_NET_SUPPORT 166 &ofwnet, 167#endif 168 0 169}; 170 171extern struct console ofwconsole; 172struct console *consoles[] = { 173 &ofwconsole, 174 0 175}; 176 177#ifdef LOADER_DEBUG 178static int 179watch_phys_set_mask(vm_offset_t pa, u_long mask) 180{ 181 u_long lsucr; 182 183 stxa(AA_DMMU_PWPR, ASI_DMMU, pa & (((2UL << 38) - 1) << 3)); 184 lsucr = ldxa(0, ASI_LSU_CTL_REG); 185 lsucr = ((lsucr | LSU_PW) & ~LSU_PM_MASK) | 186 (mask << LSU_PM_SHIFT); 187 stxa(0, ASI_LSU_CTL_REG, lsucr); 188 return (0); 189} 190 191static int 192watch_phys_set(vm_offset_t pa, int sz) 193{ 194 u_long off; 195 196 off = (u_long)pa & 7; 197 /* Test for misaligned watch points. */ 198 if (off + sz > 8) 199 return (-1); 200 return (watch_phys_set_mask(pa, ((1 << sz) - 1) << off)); 201} 202 203 204static int 205watch_virt_set_mask(vm_offset_t va, u_long mask) 206{ 207 u_long lsucr; 208 209 stxa(AA_DMMU_VWPR, ASI_DMMU, va & (((2UL << 41) - 1) << 3)); 210 lsucr = ldxa(0, ASI_LSU_CTL_REG); 211 lsucr = ((lsucr | LSU_VW) & ~LSU_VM_MASK) | 212 (mask << LSU_VM_SHIFT); 213 stxa(0, ASI_LSU_CTL_REG, lsucr); 214 return (0); 215} 216 217static int 218watch_virt_set(vm_offset_t va, int sz) 219{ 220 u_long off; 221 222 off = (u_long)va & 7; 223 /* Test for misaligned watch points. */ 224 if (off + sz > 8) 225 return (-1); 226 return (watch_virt_set_mask(va, ((1 << sz) - 1) << off)); 227} 228#endif 229 230/* 231 * archsw functions 232 */ 233static int 234sparc64_autoload(void) 235{ 236 237 printf("nothing to autoload yet.\n"); 238 return (0); 239} 240 241static ssize_t 242sparc64_readin(const int fd, vm_offset_t va, const size_t len) 243{ 244 245 mmu_ops->mmu_mapin(va, len); 246 return (read(fd, (void *)va, len)); 247} 248 249static ssize_t 250sparc64_copyin(const void *src, vm_offset_t dest, size_t len) 251{ 252 253 mmu_ops->mmu_mapin(dest, len); 254 memcpy((void *)dest, src, len); 255 return (len); 256} 257 258static void 259sparc64_maphint(vm_offset_t va, size_t len) 260{ 261 vm_paddr_t pa; 262 vm_offset_t mva; 263 size_t size; 264 int i, free_excess = 0; 265 266 if (!is_sun4v) 267 return; 268 269 if (tlb_store[va >> 22].te_pa != -1) 270 return; 271 272 /* round up to nearest 4MB page */ 273 size = (len + PAGE_MASK_4M) & ~PAGE_MASK_4M; 274#if 0 275 pa = alloc_phys(PAGE_SIZE_256M, PAGE_SIZE_256M); 276 277 if (pa != -1) 278 free_excess = 1; 279 else 280#endif 281 pa = alloc_phys(size, PAGE_SIZE_256M); 282 if (pa == -1) 283 pa = alloc_phys(size, PAGE_SIZE_4M); 284 if (pa == -1) 285 panic("%s: out of memory", __func__); 286 287 for (i = 0; i < size; i += PAGE_SIZE_4M) { 288 mva = claim_virt(va + i, PAGE_SIZE_4M, 0); 289 if (mva != (va + i)) 290 panic("%s: can't claim virtual page " 291 "(wanted %#lx, got %#lx)", 292 __func__, va, mva); 293 294 tlb_store[mva >> 22].te_pa = pa + i; 295 if (map_phys(-1, PAGE_SIZE_4M, mva, pa + i) != 0) 296 printf("%s: can't map physical page\n", __func__); 297 } 298 if (free_excess) 299 release_phys(pa, PAGE_SIZE_256M); 300} 301 302/* 303 * other MD functions 304 */ 305static vm_offset_t 306claim_virt(vm_offset_t virt, size_t size, int align) 307{ 308 vm_offset_t mva; 309 310 if (OF_call_method("claim", mmu, 3, 1, virt, size, align, &mva) == -1) 311 return ((vm_offset_t)-1); 312 return (mva); 313} 314 315static vm_offset_t 316alloc_phys(size_t size, int align) 317{ 318 cell_t phys_hi, phys_low; 319 320 if (OF_call_method("claim", memory, 2, 2, size, align, &phys_low, 321 &phys_hi) == -1) 322 return ((vm_offset_t)-1); 323 return ((vm_offset_t)phys_hi << 32 | phys_low); 324} 325 326static int 327map_phys(int mode, size_t size, vm_offset_t virt, vm_offset_t phys) 328{ 329 330 return (OF_call_method("map", mmu, 5, 0, (uint32_t)phys, 331 (uint32_t)(phys >> 32), virt, size, mode)); 332} 333 334static void 335release_phys(vm_offset_t phys, u_int size) 336{ 337 338 (void)OF_call_method("release", memory, 3, 0, (uint32_t)phys, 339 (uint32_t)(phys >> 32), size); 340} 341 342static int 343__elfN(exec)(struct preloaded_file *fp) 344{ 345 struct file_metadata *fmp; 346 vm_offset_t mdp; 347 Elf_Addr entry; 348 Elf_Ehdr *e; 349 int error; 350 351 if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == 0) 352 return (EFTYPE); 353 e = (Elf_Ehdr *)&fmp->md_data; 354 355 if ((error = md_load(fp->f_args, &mdp)) != 0) 356 return (error); 357 358 printf("jumping to kernel entry at %#lx.\n", e->e_entry); 359#if LOADER_DEBUG 360 pmap_print_tlb_sun4u(); 361#endif 362 363 entry = e->e_entry; 364 365 OF_release((void *)heapva, HEAPSZ); 366 367 ((kernel_entry_t *)entry)(mdp, 0, 0, 0, openfirmware); 368 369 panic("%s: exec returned", __func__); 370} 371 372static inline u_long 373dtlb_get_data_sun4u(int slot) 374{ 375 376 /* 377 * We read ASI_DTLB_DATA_ACCESS_REG twice in order to work 378 * around errata of USIII and beyond. 379 */ 380 (void)ldxa(TLB_DAR_SLOT(slot), ASI_DTLB_DATA_ACCESS_REG); 381 return (ldxa(TLB_DAR_SLOT(slot), ASI_DTLB_DATA_ACCESS_REG)); 382} 383 384static inline u_long 385itlb_get_data_sun4u(int slot) 386{ 387 388 /* 389 * We read ASI_ITLB_DATA_ACCESS_REG twice in order to work 390 * around errata of USIII and beyond. 391 */ 392 (void)ldxa(TLB_DAR_SLOT(slot), ASI_ITLB_DATA_ACCESS_REG); 393 return (ldxa(TLB_DAR_SLOT(slot), ASI_ITLB_DATA_ACCESS_REG)); 394} 395 396static vm_offset_t 397dtlb_va_to_pa_sun4u(vm_offset_t va) 398{ 399 u_long pstate, reg; 400 int i; 401 402 pstate = rdpr(pstate); 403 wrpr(pstate, pstate & ~PSTATE_IE, 0); 404 for (i = 0; i < dtlb_slot_max; i++) { 405 reg = ldxa(TLB_DAR_SLOT(i), ASI_DTLB_TAG_READ_REG); 406 if (TLB_TAR_VA(reg) != va) 407 continue; 408 reg = dtlb_get_data_sun4u(i); 409 wrpr(pstate, pstate, 0); 410 if (cpu_impl >= CPU_IMPL_ULTRASPARCIII) 411 return ((reg & TD_PA_CH_MASK) >> TD_PA_SHIFT); 412 return ((reg & TD_PA_SF_MASK) >> TD_PA_SHIFT); 413 } 414 wrpr(pstate, pstate, 0); 415 return (-1); 416} 417 418static vm_offset_t 419itlb_va_to_pa_sun4u(vm_offset_t va) 420{ 421 u_long pstate, reg; 422 int i; 423 424 pstate = rdpr(pstate); 425 wrpr(pstate, pstate & ~PSTATE_IE, 0); 426 for (i = 0; i < itlb_slot_max; i++) { 427 reg = ldxa(TLB_DAR_SLOT(i), ASI_ITLB_TAG_READ_REG); 428 if (TLB_TAR_VA(reg) != va) 429 continue; 430 reg = itlb_get_data_sun4u(i); 431 wrpr(pstate, pstate, 0); 432 if (cpu_impl >= CPU_IMPL_ULTRASPARCIII) 433 return ((reg & TD_PA_CH_MASK) >> TD_PA_SHIFT); 434 return ((reg & TD_PA_SF_MASK) >> TD_PA_SHIFT); 435 } 436 wrpr(pstate, pstate, 0); 437 return (-1); 438} 439 440static void 441dtlb_enter_sun4u(u_long vpn, u_long data) 442{ 443 u_long reg; 444 445 reg = rdpr(pstate); 446 wrpr(pstate, reg & ~PSTATE_IE, 0); 447 stxa(AA_DMMU_TAR, ASI_DMMU, 448 TLB_TAR_VA(vpn) | TLB_TAR_CTX(TLB_CTX_KERNEL)); 449 stxa(0, ASI_DTLB_DATA_IN_REG, data); 450 membar(Sync); 451 wrpr(pstate, reg, 0); 452} 453 454static void 455itlb_enter_sun4u(u_long vpn, u_long data) 456{ 457 u_long reg; 458 459 reg = rdpr(pstate); 460 wrpr(pstate, reg & ~PSTATE_IE, 0); 461 stxa(AA_IMMU_TAR, ASI_IMMU, 462 TLB_TAR_VA(vpn) | TLB_TAR_CTX(TLB_CTX_KERNEL)); 463 stxa(0, ASI_ITLB_DATA_IN_REG, data); 464 membar(Sync); 465 wrpr(pstate, reg, 0); 466} 467 468static int 469mmu_mapin_sun4u(vm_offset_t va, vm_size_t len) 470{ 471 vm_offset_t pa, mva; 472 u_long data; 473 474 if (va + len > curkva) 475 curkva = va + len; 476 477 pa = (vm_offset_t)-1; 478 len += va & PAGE_MASK_4M; 479 va &= ~PAGE_MASK_4M; 480 while (len) { 481 if (dtlb_va_to_pa_sun4u(va) == (vm_offset_t)-1 || 482 itlb_va_to_pa_sun4u(va) == (vm_offset_t)-1) { 483 /* Allocate a physical page, claim the virtual area. */ 484 if (pa == (vm_offset_t)-1) { 485 pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M); 486 if (pa == (vm_offset_t)-1) 487 panic("%s: out of memory", __func__); 488 mva = claim_virt(va, PAGE_SIZE_4M, 0); 489 if (mva != va) 490 panic("%s: can't claim virtual page " 491 "(wanted %#lx, got %#lx)", 492 __func__, va, mva); 493 /* 494 * The mappings may have changed, be paranoid. 495 */ 496 continue; 497 } 498 /* 499 * Actually, we can only allocate two pages less at 500 * most (depending on the kernel TSB size). 501 */ 502 if (dtlb_slot >= dtlb_slot_max) 503 panic("%s: out of dtlb_slots", __func__); 504 if (itlb_slot >= itlb_slot_max) 505 panic("%s: out of itlb_slots", __func__); 506 data = TD_V | TD_4M | TD_PA(pa) | TD_L | TD_CP | 507 TD_CV | TD_P | TD_W; 508 dtlb_store[dtlb_slot].te_pa = pa; 509 dtlb_store[dtlb_slot].te_va = va; 510 itlb_store[itlb_slot].te_pa = pa; 511 itlb_store[itlb_slot].te_va = va; 512 dtlb_slot++; 513 itlb_slot++; 514 dtlb_enter_sun4u(va, data); 515 itlb_enter_sun4u(va, data); 516 pa = (vm_offset_t)-1; 517 } 518 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len; 519 va += PAGE_SIZE_4M; 520 } 521 if (pa != (vm_offset_t)-1) 522 release_phys(pa, PAGE_SIZE_4M); 523 return (0); 524} 525 526static int 527mmu_mapin_sun4v(vm_offset_t va, vm_size_t len) 528{ 529 vm_offset_t pa, mva; 530 531 if (va + len > curkva) 532 curkva = va + len; 533 534 pa = (vm_offset_t)-1; 535 len += va & PAGE_MASK_4M; 536 va &= ~PAGE_MASK_4M; 537 while (len) { 538 if ((va >> 22) > SUN4V_TLB_SLOT_MAX) 539 panic("%s: trying to map more than 4GB", __func__); 540 if (tlb_store[va >> 22].te_pa == -1) { 541 /* Allocate a physical page, claim the virtual area */ 542 if (pa == (vm_offset_t)-1) { 543 pa = alloc_phys(PAGE_SIZE_4M, PAGE_SIZE_4M); 544 if (pa == (vm_offset_t)-1) 545 panic("%s: out of memory", __func__); 546 mva = claim_virt(va, PAGE_SIZE_4M, 0); 547 if (mva != va) 548 panic("%s: can't claim virtual page " 549 "(wanted %#lx, got %#lx)", 550 __func__, va, mva); 551 } 552 553 tlb_store[va >> 22].te_pa = pa; 554 if (map_phys(-1, PAGE_SIZE_4M, va, pa) == -1) 555 printf("%s: can't map physical page\n", 556 __func__); 557 pa = (vm_offset_t)-1; 558 } 559 len -= len > PAGE_SIZE_4M ? PAGE_SIZE_4M : len; 560 va += PAGE_SIZE_4M; 561 } 562 if (pa != (vm_offset_t)-1) 563 release_phys(pa, PAGE_SIZE_4M); 564 return (0); 565} 566 567static vm_offset_t 568init_heap(void) 569{ 570 571 /* There is no need for continuous physical heap memory. */ 572 heapva = (vm_offset_t)OF_claim((void *)HEAPVA, HEAPSZ, 32); 573 return (heapva); 574} 575 576static void 577tlb_init_sun4u(void) 578{ 579 phandle_t child; 580 char buf[128]; 581 u_int bootcpu; 582 u_int cpu; 583 584 cpu_impl = VER_IMPL(rdpr(ver)); 585 bootcpu = UPA_CR_GET_MID(ldxa(0, ASI_UPA_CONFIG_REG)); 586 for (child = OF_child(root); child != 0; child = OF_peer(child)) { 587 if (OF_getprop(child, "device_type", buf, sizeof(buf)) <= 0) 588 continue; 589 if (strcmp(buf, "cpu") != 0) 590 continue; 591 if (OF_getprop(child, cpu_impl < CPU_IMPL_ULTRASPARCIII ? 592 "upa-portid" : "portid", &cpu, sizeof(cpu)) <= 0) 593 continue; 594 if (cpu == bootcpu) 595 break; 596 } 597 if (cpu != bootcpu) 598 panic("%s: no node for bootcpu?!?!", __func__); 599 600 if (OF_getprop(child, "#dtlb-entries", &dtlb_slot_max, 601 sizeof(dtlb_slot_max)) == -1 || 602 OF_getprop(child, "#itlb-entries", &itlb_slot_max, 603 sizeof(itlb_slot_max)) == -1) 604 panic("%s: can't get TLB slot max.", __func__); 605 dtlb_store = malloc(dtlb_slot_max * sizeof(*dtlb_store)); 606 itlb_store = malloc(itlb_slot_max * sizeof(*itlb_store)); 607 if (dtlb_store == NULL || itlb_store == NULL) 608 panic("%s: can't allocate TLB store", __func__); 609} 610 611static void 612tlb_init_sun4v(void) 613{ 614 615 tlb_store = malloc(SUN4V_TLB_SLOT_MAX * sizeof(*tlb_store)); 616 memset(tlb_store, 0xFF, SUN4V_TLB_SLOT_MAX * sizeof(*tlb_store)); 617} 618 619int 620main(int (*openfirm)(void *)) 621{ 622 char bootpath[64]; 623 char compatible[32]; 624 struct devsw **dp; 625 626 /* 627 * Tell the Open Firmware functions where they find the OFW gate. 628 */ 629 OF_init(openfirm); 630 631 archsw.arch_getdev = ofw_getdev; 632 archsw.arch_copyin = sparc64_copyin; 633 archsw.arch_copyout = ofw_copyout; 634 archsw.arch_readin = sparc64_readin; 635 archsw.arch_autoload = sparc64_autoload; 636 archsw.arch_maphint = sparc64_maphint; 637 638 init_heap(); 639 setheap((void *)heapva, (void *)(heapva + HEAPSZ)); 640 641 /* 642 * Probe for a console. 643 */ 644 cons_probe(); 645 646 if ((root = OF_peer(0)) == -1) 647 panic("%s: can't get root phandle", __func__); 648 OF_getprop(root, "compatible", compatible, sizeof(compatible)); 649 if (!strcmp(compatible, "sun4v")) { 650 printf("\nBooting with sun4v support.\n"); 651 mmu_ops = &mmu_ops_sun4v; 652 is_sun4v = 1; 653 } else { 654 printf("\nBooting with sun4u support.\n"); 655 mmu_ops = &mmu_ops_sun4u; 656 } 657 658 mmu_ops->tlb_init(); 659 660 /* 661 * Initialize devices. 662 */ 663 for (dp = devsw; *dp != 0; dp++) { 664 if ((*dp)->dv_init != 0) 665 (*dp)->dv_init(); 666 } 667 668 /* 669 * Set up the current device. 670 */ 671 OF_getprop(chosen, "bootpath", bootpath, sizeof(bootpath)); 672 673 /* 674 * Sun compatible bootable CD-ROMs have a disk label placed 675 * before the cd9660 data, with the actual filesystem being 676 * in the first partition, while the other partitions contain 677 * pseudo disk labels with embedded boot blocks for different 678 * architectures, which may be followed by UFS filesystems. 679 * The firmware will set the boot path to the partition it 680 * boots from ('f' in the sun4u case), but we want the kernel 681 * to be loaded from the cd9660 fs ('a'), so the boot path 682 * needs to be altered. 683 */ 684 if (bootpath[strlen(bootpath) - 2] == ':' && 685 bootpath[strlen(bootpath) - 1] == 'f') { 686 bootpath[strlen(bootpath) - 1] = 'a'; 687 printf("Boot path set to %s\n", bootpath); 688 } 689 690 env_setenv("currdev", EV_VOLATILE, bootpath, 691 ofw_setcurrdev, env_nounset); 692 env_setenv("loaddev", EV_VOLATILE, bootpath, 693 env_noset, env_nounset); 694 695 printf("\n"); 696 printf("%s, Revision %s\n", bootprog_name, bootprog_rev); 697 printf("(%s, %s)\n", bootprog_maker, bootprog_date); 698 printf("bootpath=\"%s\"\n", bootpath); 699 700 /* Give control to the machine independent loader code. */ 701 interact(); 702 return (1); 703} 704 705COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot); 706 707static int 708command_reboot(int argc, char *argv[]) 709{ 710 int i; 711 712 for (i = 0; devsw[i] != NULL; ++i) 713 if (devsw[i]->dv_cleanup != NULL) 714 (devsw[i]->dv_cleanup)(); 715 716 printf("Rebooting...\n"); 717 OF_exit(); 718} 719 720/* provide this for panic, as it's not in the startup code */ 721void 722exit(int code) 723{ 724 725 OF_exit(); 726} 727 728#ifdef LOADER_DEBUG 729static const char *page_sizes[] = { 730 " 8k", " 64k", "512k", " 4m" 731}; 732 733static void 734pmap_print_tte_sun4u(tte_t tag, tte_t tte) 735{ 736 737 printf("%s %s ", 738 page_sizes[(tte & TD_SIZE_MASK) >> TD_SIZE_SHIFT], 739 tag & TD_G ? "G" : " "); 740 printf(tte & TD_W ? "W " : " "); 741 printf(tte & TD_P ? "\e[33mP\e[0m " : " "); 742 printf(tte & TD_E ? "E " : " "); 743 printf(tte & TD_CV ? "CV " : " "); 744 printf(tte & TD_CP ? "CP " : " "); 745 printf(tte & TD_L ? "\e[32mL\e[0m " : " "); 746 printf(tte & TD_IE ? "IE " : " "); 747 printf(tte & TD_NFO ? "NFO " : " "); 748 printf("pa=0x%lx va=0x%lx ctx=%ld\n", 749 TD_PA(tte), TLB_TAR_VA(tag), TLB_TAR_CTX(tag)); 750} 751 752static void 753pmap_print_tlb_sun4u(void) 754{ 755 tte_t tag, tte; 756 u_long pstate; 757 int i; 758 759 pstate = rdpr(pstate); 760 for (i = 0; i < itlb_slot_max; i++) { 761 wrpr(pstate, pstate & ~PSTATE_IE, 0); 762 tte = itlb_get_data_sun4u(i); 763 wrpr(pstate, pstate, 0); 764 if (!(tte & TD_V)) 765 continue; 766 tag = ldxa(TLB_DAR_SLOT(i), ASI_ITLB_TAG_READ_REG); 767 printf("iTLB-%2u: ", i); 768 pmap_print_tte_sun4u(tag, tte); 769 } 770 for (i = 0; i < dtlb_slot_max; i++) { 771 wrpr(pstate, pstate & ~PSTATE_IE, 0); 772 tte = dtlb_get_data_sun4u(i); 773 wrpr(pstate, pstate, 0); 774 if (!(tte & TD_V)) 775 continue; 776 tag = ldxa(TLB_DAR_SLOT(i), ASI_DTLB_TAG_READ_REG); 777 printf("dTLB-%2u: ", i); 778 pmap_print_tte_sun4u(tag, tte); 779 } 780} 781#endif 782