10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51592Sgirish * Common Development and Distribution License (the "License"). 61592Sgirish * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 223434Sesaxe * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/archsystm.h> 310Sstevel@tonic-gate #include <sys/machsystm.h> 320Sstevel@tonic-gate #include <sys/disp.h> 330Sstevel@tonic-gate #include <sys/autoconf.h> 340Sstevel@tonic-gate #include <sys/promif.h> 350Sstevel@tonic-gate #include <sys/prom_plat.h> 36*5648Ssetje #include <sys/promimpl.h> 37*5648Ssetje #include <sys/platform_module.h> 380Sstevel@tonic-gate #include <sys/clock.h> 390Sstevel@tonic-gate #include <sys/pte.h> 400Sstevel@tonic-gate #include <sys/scb.h> 410Sstevel@tonic-gate #include <sys/cpu.h> 420Sstevel@tonic-gate #include <sys/stack.h> 430Sstevel@tonic-gate #include <sys/intreg.h> 440Sstevel@tonic-gate #include <sys/ivintr.h> 450Sstevel@tonic-gate #include <vm/as.h> 460Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 470Sstevel@tonic-gate #include <sys/reboot.h> 480Sstevel@tonic-gate #include <sys/sysmacros.h> 490Sstevel@tonic-gate #include <sys/vtrace.h> 500Sstevel@tonic-gate #include <sys/trap.h> 510Sstevel@tonic-gate #include <sys/machtrap.h> 520Sstevel@tonic-gate #include <sys/privregs.h> 530Sstevel@tonic-gate #include <sys/machpcb.h> 540Sstevel@tonic-gate #include <sys/proc.h> 550Sstevel@tonic-gate #include <sys/cpupart.h> 560Sstevel@tonic-gate #include <sys/pset.h> 570Sstevel@tonic-gate #include <sys/cpu_module.h> 580Sstevel@tonic-gate #include <sys/copyops.h> 590Sstevel@tonic-gate #include <sys/panic.h> 600Sstevel@tonic-gate #include <sys/bootconf.h> /* for bootops */ 613434Sesaxe #include <sys/pg.h> 620Sstevel@tonic-gate #include <sys/kdi.h> 630Sstevel@tonic-gate #include <sys/fpras.h> 640Sstevel@tonic-gate 650Sstevel@tonic-gate #include <sys/prom_debug.h> 660Sstevel@tonic-gate #include <sys/debug.h> 670Sstevel@tonic-gate 680Sstevel@tonic-gate #include <sys/sunddi.h> 690Sstevel@tonic-gate #include <sys/lgrp.h> 700Sstevel@tonic-gate #include <sys/traptrace.h> 71*5648Ssetje 72*5648Ssetje #include <sys/kobj_impl.h> 73*5648Ssetje #include <sys/kdi_machimpl.h> 74*5648Ssetje 750Sstevel@tonic-gate /* 760Sstevel@tonic-gate * External Routines: 770Sstevel@tonic-gate */ 780Sstevel@tonic-gate extern void map_wellknown_devices(void); 791592Sgirish extern void hsvc_setup(void); 801991Sheppo extern void mach_descrip_startup_init(void); 813266Sjb145095 extern void mach_soft_state_init(void); 820Sstevel@tonic-gate 830Sstevel@tonic-gate int dcache_size; 840Sstevel@tonic-gate int dcache_linesize; 850Sstevel@tonic-gate int icache_size; 860Sstevel@tonic-gate int icache_linesize; 870Sstevel@tonic-gate int ecache_size; 880Sstevel@tonic-gate int ecache_alignsize; 890Sstevel@tonic-gate int ecache_associativity; 900Sstevel@tonic-gate int ecache_setsize; /* max possible e$ setsize */ 910Sstevel@tonic-gate int cpu_setsize; /* max e$ setsize of configured cpus */ 920Sstevel@tonic-gate int dcache_line_mask; /* spitfire only */ 930Sstevel@tonic-gate int vac_size; /* cache size in bytes */ 940Sstevel@tonic-gate uint_t vac_mask; /* VAC alignment consistency mask */ 950Sstevel@tonic-gate int vac_shift; /* log2(vac_size) for ppmapout() */ 960Sstevel@tonic-gate int vac = 0; /* virtual address cache type (none == 0) */ 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * fpRAS. An individual sun4* machine class (or perhaps subclass, 1000Sstevel@tonic-gate * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements 1010Sstevel@tonic-gate * the fpRAS feature. The feature can be suppressed by setting fpras_disable 1020Sstevel@tonic-gate * or the mechanism can be disabled for individual copy operations with 1030Sstevel@tonic-gate * fpras_disableids. All these are checked in post_startup() code so 1040Sstevel@tonic-gate * fpras_disable and fpras_disableids can be set in /etc/system. 1050Sstevel@tonic-gate * If/when fpRAS is implemented on non-sun4 architectures these 1060Sstevel@tonic-gate * definitions will need to move up to the common level. 1070Sstevel@tonic-gate */ 1080Sstevel@tonic-gate int fpras_implemented; 1090Sstevel@tonic-gate int fpras_disable; 1100Sstevel@tonic-gate int fpras_disableids; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * Static Routines: 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate static void kern_splr_preprom(void); 1160Sstevel@tonic-gate static void kern_splx_postprom(void); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 1200Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate void 124*5648Ssetje mlsetup(struct regs *rp, kfpu_t *fp) 1250Sstevel@tonic-gate { 1260Sstevel@tonic-gate struct machpcb *mpcb; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate extern char t0stack[]; 1290Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1300Sstevel@tonic-gate extern disp_t cpu0_disp; 1310Sstevel@tonic-gate unsigned long long pa; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate #ifdef TRAPTRACE 1340Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp; 1350Sstevel@tonic-gate #endif /* TRAPTRACE */ 1360Sstevel@tonic-gate 137*5648Ssetje /* drop into kmdb on boot -d */ 138*5648Ssetje if (boothowto & RB_DEBUGENTER) 139*5648Ssetje kmdb_enter(); 140*5648Ssetje 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * initialize cpu_self 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate cpu0.cpu_self = &cpu0; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * initialize t0 1480Sstevel@tonic-gate */ 1490Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - REGOFF; 1500Sstevel@tonic-gate /* Can't use va_to_pa here - wait until prom_ initialized */ 1510Sstevel@tonic-gate t0.t_stkbase = t0stack; 1520Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 1530Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 1540Sstevel@tonic-gate t0.t_procp = &p0; 1550Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 1560Sstevel@tonic-gate t0.t_lwp = &lwp0; 1570Sstevel@tonic-gate t0.t_forw = &t0; 1580Sstevel@tonic-gate t0.t_back = &t0; 1590Sstevel@tonic-gate t0.t_next = &t0; 1600Sstevel@tonic-gate t0.t_prev = &t0; 1610Sstevel@tonic-gate t0.t_cpu = &cpu0; /* loaded by _start */ 1620Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 1630Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 1640Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 1650Sstevel@tonic-gate t0.t_cpupart = &cp_default; 1660Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 1670Sstevel@tonic-gate t0.t_copyops = NULL; 1680Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate lwp0.lwp_thread = &t0; 1710Sstevel@tonic-gate lwp0.lwp_procp = &p0; 1720Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp; 1730Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate mpcb = lwptompcb(&lwp0); 1760Sstevel@tonic-gate mpcb->mpcb_fpu = fp; 1770Sstevel@tonic-gate mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q; 1780Sstevel@tonic-gate mpcb->mpcb_thread = &t0; 1790Sstevel@tonic-gate lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate p0.p_exec = NULL; 1820Sstevel@tonic-gate p0.p_stat = SRUN; 1830Sstevel@tonic-gate p0.p_flag = SSYS; 1840Sstevel@tonic-gate p0.p_tlist = &t0; 1850Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 1860Sstevel@tonic-gate p0.p_stkpageszc = 0; 1870Sstevel@tonic-gate p0.p_as = &kas; 1880Sstevel@tonic-gate p0.p_lockp = &p0lock; 1890Sstevel@tonic-gate p0.p_utraps = NULL; 1900Sstevel@tonic-gate p0.p_brkpageszc = 0; 1914426Saguzovsk p0.p_t1_lgrpid = LGRP_NONE; 1924426Saguzovsk p0.p_tr_lgrpid = LGRP_NONE; 1930Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate CPU->cpu_thread = &t0; 1960Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 1970Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 1980Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 1990Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 2000Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 2010Sstevel@tonic-gate CPU->cpu_flags = CPU_RUNNING; 2020Sstevel@tonic-gate CPU->cpu_id = getprocessorid(); 2030Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate /* 2063446Smrj * Initialize thread/cpu microstate accounting 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 2090Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate /* 2120Sstevel@tonic-gate * Initialize lists of available and active CPUs. 2130Sstevel@tonic-gate */ 2140Sstevel@tonic-gate cpu_list_init(CPU); 2150Sstevel@tonic-gate 216414Skchow cpu_vm_data_init(CPU); 217414Skchow 2180Sstevel@tonic-gate (void) prom_set_preprom(kern_splr_preprom); 2190Sstevel@tonic-gate (void) prom_set_postprom(kern_splx_postprom); 2200Sstevel@tonic-gate PRM_INFO("mlsetup: now ok to call prom_printf"); 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate mpcb->mpcb_pa = va_to_pa(t0.t_stk); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate /* 2250Sstevel@tonic-gate * Claim the physical and virtual resources used by panicbuf, 2260Sstevel@tonic-gate * then map panicbuf. This operation removes the phys and 2270Sstevel@tonic-gate * virtual addresses from the free lists. 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf) 2300Sstevel@tonic-gate prom_panic("Can't claim panicbuf virtual address"); 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0) 2330Sstevel@tonic-gate prom_panic("Can't allocate retained panicbuf physical address"); 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0) 2360Sstevel@tonic-gate prom_panic("Can't map panicbuf"); 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate PRM_DEBUG(panicbuf); 2390Sstevel@tonic-gate PRM_DEBUG(pa); 2400Sstevel@tonic-gate 2411592Sgirish /* 2421592Sgirish * Negotiate hypervisor services, if any 2431592Sgirish */ 2441592Sgirish hsvc_setup(); 2453266Sjb145095 mach_soft_state_init(); 2461592Sgirish 2470Sstevel@tonic-gate #ifdef TRAPTRACE 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * initialize the trap trace buffer for the boot cpu 2500Sstevel@tonic-gate * XXX todo, dynamically allocate this buffer too 2510Sstevel@tonic-gate */ 2520Sstevel@tonic-gate ctlp = &trap_trace_ctl[CPU->cpu_id]; 2530Sstevel@tonic-gate ctlp->d.vaddr_base = trap_tr0; 2540Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0; 2550Sstevel@tonic-gate ctlp->d.limit = TRAP_TSIZE; /* XXX dynamic someday */ 2560Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(trap_tr0); 2571077Ssvemuri #endif /* TRAPTRACE */ 2581991Sheppo 2591991Sheppo /* 2601991Sheppo * Initialize the Machine Description kernel framework 2611991Sheppo */ 2621991Sheppo 2631991Sheppo mach_descrip_startup_init(); 2641991Sheppo 2650Sstevel@tonic-gate /* 2660Sstevel@tonic-gate * initialize HV trap trace buffer for the boot cpu 2670Sstevel@tonic-gate */ 2681077Ssvemuri mach_htraptrace_setup(CPU->cpu_id); 2691077Ssvemuri mach_htraptrace_configure(CPU->cpu_id); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * lgroup framework initialization. This must be done prior 2730Sstevel@tonic-gate * to devices being mapped. 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate lgrp_init(); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate cpu_setup(); 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate if (boothowto & RB_HALT) { 2800Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 2810Sstevel@tonic-gate prom_enter_mon(); 2820Sstevel@tonic-gate } 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate setcputype(); 2850Sstevel@tonic-gate map_wellknown_devices(); 2860Sstevel@tonic-gate setcpudelay(); 2870Sstevel@tonic-gate } 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate /* 2900Sstevel@tonic-gate * These routines are called immediately before and 2910Sstevel@tonic-gate * immediately after calling into the firmware. The 2920Sstevel@tonic-gate * firmware is significantly confused by preemption - 2930Sstevel@tonic-gate * particularly on MP machines - but also on UP's too. 2940Sstevel@tonic-gate */ 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate static int saved_spl; 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate static void 2990Sstevel@tonic-gate kern_splr_preprom(void) 3000Sstevel@tonic-gate { 3010Sstevel@tonic-gate saved_spl = spl7(); 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate static void 3050Sstevel@tonic-gate kern_splx_postprom(void) 3060Sstevel@tonic-gate { 3070Sstevel@tonic-gate splx(saved_spl); 3080Sstevel@tonic-gate } 309*5648Ssetje 310*5648Ssetje 311*5648Ssetje /* 312*5648Ssetje * WARNING 313*5648Ssetje * The code fom here to the end of mlsetup.c runs before krtld has 314*5648Ssetje * knitted unix and genunix together. It can call routines in unix, 315*5648Ssetje * but calls into genunix will fail spectacularly. More specifically, 316*5648Ssetje * calls to prom_*, bop_* and str* will work, everything else is 317*5648Ssetje * caveat emptor. 318*5648Ssetje * 319*5648Ssetje * Also note that while #ifdef sun4u is generally a bad idea, they 320*5648Ssetje * exist here to concentrate the dangerous code into a single file. 321*5648Ssetje */ 322*5648Ssetje 323*5648Ssetje static char * 324*5648Ssetje getcpulist(void) 325*5648Ssetje { 326*5648Ssetje pnode_t node; 327*5648Ssetje /* big enough for OBP_NAME and for a reasonably sized OBP_COMPATIBLE. */ 328*5648Ssetje static char cpubuf[5 * OBP_MAXDRVNAME]; 329*5648Ssetje int nlen, clen, i; 330*5648Ssetje #ifdef sun4u 331*5648Ssetje char dname[OBP_MAXDRVNAME]; 332*5648Ssetje #endif 333*5648Ssetje 334*5648Ssetje node = prom_findnode_bydevtype(prom_rootnode(), OBP_CPU); 335*5648Ssetje if (node != OBP_NONODE && node != OBP_BADNODE) { 336*5648Ssetje if ((nlen = prom_getproplen(node, OBP_NAME)) <= 0 || 337*5648Ssetje nlen > sizeof (cpubuf) || 338*5648Ssetje prom_getprop(node, OBP_NAME, cpubuf) <= 0) 339*5648Ssetje prom_panic("no name in cpu node"); 340*5648Ssetje 341*5648Ssetje /* nlen includes the terminating null character */ 342*5648Ssetje #ifdef sun4v 343*5648Ssetje if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0) { 344*5648Ssetje #else /* sun4u */ 345*5648Ssetje /* 346*5648Ssetje * For the CMT case, need check the parent "core" 347*5648Ssetje * node for the compatible property. 348*5648Ssetje */ 349*5648Ssetje if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 || 350*5648Ssetje ((node = prom_parentnode(node)) != OBP_NONODE && 351*5648Ssetje node != OBP_BADNODE && 352*5648Ssetje (clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 && 353*5648Ssetje prom_getprop(node, OBP_DEVICETYPE, dname) > 0 && 354*5648Ssetje strcmp(dname, "core") == 0)) { 355*5648Ssetje #endif 356*5648Ssetje if ((clen + nlen) > sizeof (cpubuf)) 357*5648Ssetje prom_panic("cpu node \"compatible\" too long"); 358*5648Ssetje /* read in compatible, leaving space for ':' */ 359*5648Ssetje if (prom_getprop(node, OBP_COMPATIBLE, 360*5648Ssetje &cpubuf[nlen]) != clen) 361*5648Ssetje prom_panic("cpu node \"compatible\" error"); 362*5648Ssetje clen += nlen; /* total length */ 363*5648Ssetje /* convert all null characters to ':' */ 364*5648Ssetje clen--; /* except the final one... */ 365*5648Ssetje for (i = 0; i < clen; i++) 366*5648Ssetje if (cpubuf[i] == '\0') 367*5648Ssetje cpubuf[i] = ':'; 368*5648Ssetje } 369*5648Ssetje #ifdef sun4u 370*5648Ssetje /* 371*5648Ssetje * Some PROMs return SUNW,UltraSPARC when they actually have 372*5648Ssetje * SUNW,UltraSPARC-II cpus. SInce we're now filtering out all 373*5648Ssetje * SUNW,UltraSPARC systems during the boot phase, we can safely 374*5648Ssetje * point the auxv CPU value at SUNW,UltraSPARC-II. 375*5648Ssetje */ 376*5648Ssetje if (strcmp("SUNW,UltraSPARC", cpubuf) == 0) 377*5648Ssetje (void) strcpy(cpubuf, "SUNW,UltraSPARC-II"); 378*5648Ssetje #endif 379*5648Ssetje return (cpubuf); 380*5648Ssetje } else 381*5648Ssetje return (NULL); 382*5648Ssetje } 383*5648Ssetje 384*5648Ssetje /* 385*5648Ssetje * called immediately from _start to stich the 386*5648Ssetje * primary modules together 387*5648Ssetje */ 388*5648Ssetje void 389*5648Ssetje kobj_start(void *cif) 390*5648Ssetje { 391*5648Ssetje Ehdr *ehdr; 392*5648Ssetje Phdr *phdr; 393*5648Ssetje uint32_t eadr, padr; 394*5648Ssetje val_t bootaux[BA_NUM]; 395*5648Ssetje int i; 396*5648Ssetje 397*5648Ssetje prom_init("kernel", cif); 398*5648Ssetje bop_init(); 399*5648Ssetje #ifdef DEBUG 400*5648Ssetje if (bop_getproplen("stop-me") != -1) 401*5648Ssetje prom_enter_mon(); 402*5648Ssetje #endif 403*5648Ssetje 404*5648Ssetje if (bop_getprop("elfheader-address", (caddr_t)&eadr) == -1) 405*5648Ssetje prom_panic("no ELF image"); 406*5648Ssetje ehdr = (Ehdr *)(uintptr_t)eadr; 407*5648Ssetje for (i = 0; i < BA_NUM; i++) 408*5648Ssetje bootaux[i].ba_val = NULL; 409*5648Ssetje bootaux[BA_PHNUM].ba_val = ehdr->e_phnum; 410*5648Ssetje bootaux[BA_PHENT].ba_val = ehdr->e_phentsize; 411*5648Ssetje bootaux[BA_LDNAME].ba_ptr = NULL; 412*5648Ssetje 413*5648Ssetje padr = eadr + ehdr->e_phoff; 414*5648Ssetje bootaux[BA_PHDR].ba_ptr = (void *)(uintptr_t)padr; 415*5648Ssetje for (i = 0; i < ehdr->e_phnum; i++) { 416*5648Ssetje phdr = (Phdr *)((uintptr_t)padr + i * ehdr->e_phentsize); 417*5648Ssetje if (phdr->p_type == PT_DYNAMIC) { 418*5648Ssetje bootaux[BA_DYNAMIC].ba_ptr = (void *)phdr->p_vaddr; 419*5648Ssetje break; 420*5648Ssetje } 421*5648Ssetje } 422*5648Ssetje 423*5648Ssetje bootaux[BA_LPAGESZ].ba_val = MMU_PAGESIZE4M; 424*5648Ssetje bootaux[BA_PAGESZ].ba_val = MMU_PAGESIZE; 425*5648Ssetje bootaux[BA_IFLUSH].ba_val = 1; 426*5648Ssetje bootaux[BA_CPU].ba_ptr = getcpulist(); 427*5648Ssetje bootaux[BA_MMU].ba_ptr = NULL; 428*5648Ssetje 429*5648Ssetje kobj_init(cif, NULL, bootops, bootaux); 430*5648Ssetje 431*5648Ssetje /* kernel stitched together; we can now test #pragma's */ 432*5648Ssetje if (&plat_setprop_enter != NULL) { 433*5648Ssetje prom_setprop_enter = &plat_setprop_enter; 434*5648Ssetje prom_setprop_exit = &plat_setprop_exit; 435*5648Ssetje ASSERT(prom_setprop_exit != NULL); 436*5648Ssetje } 437*5648Ssetje 438*5648Ssetje } 439*5648Ssetje 440*5648Ssetje /* 441*5648Ssetje * Create modpath from kernel name. 442*5648Ssetje * If we booted: 443*5648Ssetje * /platform/`uname -i`/kernel/sparcv9/unix 444*5648Ssetje * or 445*5648Ssetje * /platform/`uname -m`/kernel/sparcv9/unix 446*5648Ssetje * 447*5648Ssetje * then make the modpath: 448*5648Ssetje * /platform/`uname -i`/kernel /platform/`uname -m`/kernel 449*5648Ssetje * 450*5648Ssetje * otherwise, make the modpath the dir the kernel was 451*5648Ssetje * loaded from, minus any sparcv9 extension 452*5648Ssetje * 453*5648Ssetje * note the sparcv9 dir is optional since a unix -> sparcv9/unix 454*5648Ssetje * symlink is available as a shortcut. 455*5648Ssetje */ 456*5648Ssetje void 457*5648Ssetje mach_modpath(char *path, const char *fname) 458*5648Ssetje { 459*5648Ssetje char *p; 460*5648Ssetje int len, compat; 461*5648Ssetje const char prefix[] = "/platform/"; 462*5648Ssetje char platname[MAXPATHLEN]; 463*5648Ssetje #ifdef sun4u 464*5648Ssetje char defname[] = "sun4u"; 465*5648Ssetje #else 466*5648Ssetje char defname[] = "sun4v"; 467*5648Ssetje #endif 468*5648Ssetje const char suffix[] = "/kernel"; 469*5648Ssetje const char isastr[] = "/sparcv9"; 470*5648Ssetje 471*5648Ssetje /* 472*5648Ssetje * check for /platform 473*5648Ssetje */ 474*5648Ssetje p = (char *)fname; 475*5648Ssetje if (strncmp(p, prefix, sizeof (prefix) - 1) != 0) 476*5648Ssetje goto nopath; 477*5648Ssetje p += sizeof (prefix) - 1; 478*5648Ssetje 479*5648Ssetje /* 480*5648Ssetje * check for the default name or the platform name. 481*5648Ssetje * also see if we used the 'compatible' name 482*5648Ssetje * (platname == default) 483*5648Ssetje */ 484*5648Ssetje (void) bop_getprop("impl-arch-name", platname); 485*5648Ssetje compat = strcmp(platname, defname) == 0; 486*5648Ssetje len = strlen(platname); 487*5648Ssetje if (strncmp(p, platname, len) == 0) 488*5648Ssetje p += len; 489*5648Ssetje else if (strncmp(p, defname, sizeof (defname) - 1) == 0) 490*5648Ssetje p += sizeof (defname) - 1; 491*5648Ssetje else 492*5648Ssetje goto nopath; 493*5648Ssetje 494*5648Ssetje /* 495*5648Ssetje * check for /kernel/sparcv9 or just /kernel 496*5648Ssetje */ 497*5648Ssetje if (strncmp(p, suffix, sizeof (suffix) - 1) != 0) 498*5648Ssetje goto nopath; 499*5648Ssetje p += sizeof (suffix) - 1; 500*5648Ssetje if (strncmp(p, isastr, sizeof (isastr) - 1) == 0) 501*5648Ssetje p += sizeof (isastr) - 1; 502*5648Ssetje 503*5648Ssetje /* 504*5648Ssetje * check we're at the last component 505*5648Ssetje */ 506*5648Ssetje if (p != strrchr(fname, '/')) 507*5648Ssetje goto nopath; 508*5648Ssetje 509*5648Ssetje /* 510*5648Ssetje * everything is kosher; setup modpath 511*5648Ssetje */ 512*5648Ssetje (void) strcpy(path, "/platform/"); 513*5648Ssetje (void) strcat(path, platname); 514*5648Ssetje (void) strcat(path, "/kernel "); 515*5648Ssetje if (!compat) { 516*5648Ssetje (void) strcat(path, "/platform/"); 517*5648Ssetje (void) strcat(path, defname); 518*5648Ssetje (void) strcat(path, "/kernel "); 519*5648Ssetje } 520*5648Ssetje return; 521*5648Ssetje 522*5648Ssetje nopath: 523*5648Ssetje /* 524*5648Ssetje * Construct the directory path from the filename. 525*5648Ssetje */ 526*5648Ssetje if ((p = strrchr(fname, '/')) == NULL) 527*5648Ssetje return; 528*5648Ssetje 529*5648Ssetje while (p > fname && *(p - 1) == '/') 530*5648Ssetje p--; /* remove trailing '/' characters */ 531*5648Ssetje if (p == fname) 532*5648Ssetje p++; /* so "/" -is- the modpath in this case */ 533*5648Ssetje 534*5648Ssetje /* 535*5648Ssetje * Remove optional isa-dependent directory name - the module 536*5648Ssetje * subsystem will put this back again (!) 537*5648Ssetje */ 538*5648Ssetje len = p - fname; 539*5648Ssetje if (len > sizeof (isastr) - 1 && 540*5648Ssetje strncmp(&fname[len - (sizeof (isastr) - 1)], isastr, 541*5648Ssetje sizeof (isastr) - 1) == 0) 542*5648Ssetje p -= sizeof (isastr) - 1; 543*5648Ssetje (void) strncpy(path, fname, p - fname); 544*5648Ssetje } 545