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 /*
228906SEric.Saxe@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/systm.h>
280Sstevel@tonic-gate #include <sys/archsystm.h>
290Sstevel@tonic-gate #include <sys/machsystm.h>
300Sstevel@tonic-gate #include <sys/disp.h>
310Sstevel@tonic-gate #include <sys/autoconf.h>
320Sstevel@tonic-gate #include <sys/promif.h>
330Sstevel@tonic-gate #include <sys/prom_plat.h>
345648Ssetje #include <sys/promimpl.h>
355648Ssetje #include <sys/platform_module.h>
360Sstevel@tonic-gate #include <sys/clock.h>
370Sstevel@tonic-gate #include <sys/pte.h>
380Sstevel@tonic-gate #include <sys/scb.h>
390Sstevel@tonic-gate #include <sys/cpu.h>
400Sstevel@tonic-gate #include <sys/stack.h>
410Sstevel@tonic-gate #include <sys/intreg.h>
420Sstevel@tonic-gate #include <sys/ivintr.h>
430Sstevel@tonic-gate #include <vm/as.h>
440Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
450Sstevel@tonic-gate #include <sys/reboot.h>
460Sstevel@tonic-gate #include <sys/sysmacros.h>
470Sstevel@tonic-gate #include <sys/vtrace.h>
480Sstevel@tonic-gate #include <sys/trap.h>
490Sstevel@tonic-gate #include <sys/machtrap.h>
500Sstevel@tonic-gate #include <sys/privregs.h>
510Sstevel@tonic-gate #include <sys/machpcb.h>
520Sstevel@tonic-gate #include <sys/proc.h>
530Sstevel@tonic-gate #include <sys/cpupart.h>
540Sstevel@tonic-gate #include <sys/pset.h>
550Sstevel@tonic-gate #include <sys/cpu_module.h>
560Sstevel@tonic-gate #include <sys/copyops.h>
570Sstevel@tonic-gate #include <sys/panic.h>
580Sstevel@tonic-gate #include <sys/bootconf.h> /* for bootops */
593434Sesaxe #include <sys/pg.h>
600Sstevel@tonic-gate #include <sys/kdi.h>
610Sstevel@tonic-gate #include <sys/fpras.h>
620Sstevel@tonic-gate
630Sstevel@tonic-gate #include <sys/prom_debug.h>
640Sstevel@tonic-gate #include <sys/debug.h>
650Sstevel@tonic-gate
660Sstevel@tonic-gate #include <sys/sunddi.h>
670Sstevel@tonic-gate #include <sys/lgrp.h>
680Sstevel@tonic-gate #include <sys/traptrace.h>
695648Ssetje
705648Ssetje #include <sys/kobj_impl.h>
715648Ssetje #include <sys/kdi_machimpl.h>
725648Ssetje
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate * External Routines:
750Sstevel@tonic-gate */
760Sstevel@tonic-gate extern void map_wellknown_devices(void);
771592Sgirish extern void hsvc_setup(void);
781991Sheppo extern void mach_descrip_startup_init(void);
793266Sjb145095 extern void mach_soft_state_init(void);
800Sstevel@tonic-gate
810Sstevel@tonic-gate int dcache_size;
820Sstevel@tonic-gate int dcache_linesize;
830Sstevel@tonic-gate int icache_size;
840Sstevel@tonic-gate int icache_linesize;
850Sstevel@tonic-gate int ecache_size;
860Sstevel@tonic-gate int ecache_alignsize;
870Sstevel@tonic-gate int ecache_associativity;
880Sstevel@tonic-gate int ecache_setsize; /* max possible e$ setsize */
890Sstevel@tonic-gate int cpu_setsize; /* max e$ setsize of configured cpus */
900Sstevel@tonic-gate int dcache_line_mask; /* spitfire only */
910Sstevel@tonic-gate int vac_size; /* cache size in bytes */
920Sstevel@tonic-gate uint_t vac_mask; /* VAC alignment consistency mask */
930Sstevel@tonic-gate int vac_shift; /* log2(vac_size) for ppmapout() */
940Sstevel@tonic-gate int vac = 0; /* virtual address cache type (none == 0) */
950Sstevel@tonic-gate
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate * fpRAS. An individual sun4* machine class (or perhaps subclass,
980Sstevel@tonic-gate * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements
990Sstevel@tonic-gate * the fpRAS feature. The feature can be suppressed by setting fpras_disable
1000Sstevel@tonic-gate * or the mechanism can be disabled for individual copy operations with
1010Sstevel@tonic-gate * fpras_disableids. All these are checked in post_startup() code so
1020Sstevel@tonic-gate * fpras_disable and fpras_disableids can be set in /etc/system.
1030Sstevel@tonic-gate * If/when fpRAS is implemented on non-sun4 architectures these
1040Sstevel@tonic-gate * definitions will need to move up to the common level.
1050Sstevel@tonic-gate */
1060Sstevel@tonic-gate int fpras_implemented;
1070Sstevel@tonic-gate int fpras_disable;
1080Sstevel@tonic-gate int fpras_disableids;
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * Static Routines:
1120Sstevel@tonic-gate */
1130Sstevel@tonic-gate static void kern_splr_preprom(void);
1140Sstevel@tonic-gate static void kern_splx_postprom(void);
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function
1180Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion.
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate void
mlsetup(struct regs * rp,kfpu_t * fp)1225648Ssetje mlsetup(struct regs *rp, kfpu_t *fp)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate struct machpcb *mpcb;
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate extern char t0stack[];
1270Sstevel@tonic-gate extern struct classfuncs sys_classfuncs;
1280Sstevel@tonic-gate extern disp_t cpu0_disp;
1290Sstevel@tonic-gate unsigned long long pa;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate #ifdef TRAPTRACE
1320Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp;
1330Sstevel@tonic-gate #endif /* TRAPTRACE */
1340Sstevel@tonic-gate
1355648Ssetje /* drop into kmdb on boot -d */
1365648Ssetje if (boothowto & RB_DEBUGENTER)
1375648Ssetje kmdb_enter();
1385648Ssetje
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate * initialize cpu_self
1410Sstevel@tonic-gate */
1420Sstevel@tonic-gate cpu0.cpu_self = &cpu0;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate /*
1450Sstevel@tonic-gate * initialize t0
1460Sstevel@tonic-gate */
1470Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - REGOFF;
1480Sstevel@tonic-gate /* Can't use va_to_pa here - wait until prom_ initialized */
1490Sstevel@tonic-gate t0.t_stkbase = t0stack;
1500Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3;
1510Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
1520Sstevel@tonic-gate t0.t_procp = &p0;
1530Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock;
1540Sstevel@tonic-gate t0.t_lwp = &lwp0;
1550Sstevel@tonic-gate t0.t_forw = &t0;
1560Sstevel@tonic-gate t0.t_back = &t0;
1570Sstevel@tonic-gate t0.t_next = &t0;
1580Sstevel@tonic-gate t0.t_prev = &t0;
1590Sstevel@tonic-gate t0.t_cpu = &cpu0; /* loaded by _start */
1600Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp;
1610Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE;
1620Sstevel@tonic-gate t0.t_bind_pset = PS_NONE;
1636298Sakolb t0.t_bindflag = (uchar_t)default_binding_mode;
1640Sstevel@tonic-gate t0.t_cpupart = &cp_default;
1650Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread;
1660Sstevel@tonic-gate t0.t_copyops = NULL;
1670Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU);
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate lwp0.lwp_thread = &t0;
1700Sstevel@tonic-gate lwp0.lwp_procp = &p0;
1710Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp;
1720Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate mpcb = lwptompcb(&lwp0);
1750Sstevel@tonic-gate mpcb->mpcb_fpu = fp;
1760Sstevel@tonic-gate mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q;
1770Sstevel@tonic-gate mpcb->mpcb_thread = &t0;
1780Sstevel@tonic-gate lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu;
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate p0.p_exec = NULL;
1810Sstevel@tonic-gate p0.p_stat = SRUN;
1820Sstevel@tonic-gate p0.p_flag = SSYS;
1830Sstevel@tonic-gate p0.p_tlist = &t0;
1840Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE;
1850Sstevel@tonic-gate p0.p_stkpageszc = 0;
1860Sstevel@tonic-gate p0.p_as = &kas;
1870Sstevel@tonic-gate p0.p_lockp = &p0lock;
1880Sstevel@tonic-gate p0.p_utraps = NULL;
1890Sstevel@tonic-gate p0.p_brkpageszc = 0;
1904426Saguzovsk p0.p_t1_lgrpid = LGRP_NONE;
1914426Saguzovsk p0.p_tr_lgrpid = LGRP_NONE;
1920Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault);
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate CPU->cpu_thread = &t0;
1950Sstevel@tonic-gate CPU->cpu_dispthread = &t0;
1960Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t));
1970Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp;
1980Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU;
1990Sstevel@tonic-gate CPU->cpu_idle_thread = &t0;
2000Sstevel@tonic-gate CPU->cpu_flags = CPU_RUNNING;
2010Sstevel@tonic-gate CPU->cpu_id = getprocessorid();
2020Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri;
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate /*
2053446Smrj * Initialize thread/cpu microstate accounting
2060Sstevel@tonic-gate */
2070Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM);
2080Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM);
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate /*
2110Sstevel@tonic-gate * Initialize lists of available and active CPUs.
2120Sstevel@tonic-gate */
2130Sstevel@tonic-gate cpu_list_init(CPU);
2140Sstevel@tonic-gate
215414Skchow cpu_vm_data_init(CPU);
216414Skchow
2178906SEric.Saxe@Sun.COM pg_cpu_bootstrap(CPU);
2188906SEric.Saxe@Sun.COM
2190Sstevel@tonic-gate (void) prom_set_preprom(kern_splr_preprom);
2200Sstevel@tonic-gate (void) prom_set_postprom(kern_splx_postprom);
2210Sstevel@tonic-gate PRM_INFO("mlsetup: now ok to call prom_printf");
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate mpcb->mpcb_pa = va_to_pa(t0.t_stk);
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate /*
2260Sstevel@tonic-gate * Claim the physical and virtual resources used by panicbuf,
2270Sstevel@tonic-gate * then map panicbuf. This operation removes the phys and
2280Sstevel@tonic-gate * virtual addresses from the free lists.
2290Sstevel@tonic-gate */
2300Sstevel@tonic-gate if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf)
2310Sstevel@tonic-gate prom_panic("Can't claim panicbuf virtual address");
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0)
2340Sstevel@tonic-gate prom_panic("Can't allocate retained panicbuf physical address");
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0)
2370Sstevel@tonic-gate prom_panic("Can't map panicbuf");
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate PRM_DEBUG(panicbuf);
2400Sstevel@tonic-gate PRM_DEBUG(pa);
2410Sstevel@tonic-gate
2421592Sgirish /*
2431592Sgirish * Negotiate hypervisor services, if any
2441592Sgirish */
2451592Sgirish hsvc_setup();
2463266Sjb145095 mach_soft_state_init();
2471592Sgirish
2480Sstevel@tonic-gate #ifdef TRAPTRACE
2490Sstevel@tonic-gate /*
2500Sstevel@tonic-gate * initialize the trap trace buffer for the boot cpu
2510Sstevel@tonic-gate * XXX todo, dynamically allocate this buffer too
2520Sstevel@tonic-gate */
2530Sstevel@tonic-gate ctlp = &trap_trace_ctl[CPU->cpu_id];
2540Sstevel@tonic-gate ctlp->d.vaddr_base = trap_tr0;
2550Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0;
2560Sstevel@tonic-gate ctlp->d.limit = TRAP_TSIZE; /* XXX dynamic someday */
2570Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(trap_tr0);
2581077Ssvemuri #endif /* TRAPTRACE */
2591991Sheppo
2601991Sheppo /*
2611991Sheppo * Initialize the Machine Description kernel framework
2621991Sheppo */
2631991Sheppo
2641991Sheppo mach_descrip_startup_init();
2651991Sheppo
2660Sstevel@tonic-gate /*
2670Sstevel@tonic-gate * initialize HV trap trace buffer for the boot cpu
2680Sstevel@tonic-gate */
2691077Ssvemuri mach_htraptrace_setup(CPU->cpu_id);
2701077Ssvemuri mach_htraptrace_configure(CPU->cpu_id);
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate /*
2730Sstevel@tonic-gate * lgroup framework initialization. This must be done prior
2740Sstevel@tonic-gate * to devices being mapped.
2750Sstevel@tonic-gate */
276*10710Sjonathan.chew@sun.com lgrp_init(LGRP_INIT_STAGE1);
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate cpu_setup();
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate if (boothowto & RB_HALT) {
2810Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n");
2820Sstevel@tonic-gate prom_enter_mon();
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate setcputype();
2860Sstevel@tonic-gate map_wellknown_devices();
2870Sstevel@tonic-gate setcpudelay();
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate * These routines are called immediately before and
2920Sstevel@tonic-gate * immediately after calling into the firmware. The
2930Sstevel@tonic-gate * firmware is significantly confused by preemption -
2940Sstevel@tonic-gate * particularly on MP machines - but also on UP's too.
2950Sstevel@tonic-gate */
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate static int saved_spl;
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate static void
kern_splr_preprom(void)3000Sstevel@tonic-gate kern_splr_preprom(void)
3010Sstevel@tonic-gate {
3020Sstevel@tonic-gate saved_spl = spl7();
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate static void
kern_splx_postprom(void)3060Sstevel@tonic-gate kern_splx_postprom(void)
3070Sstevel@tonic-gate {
3080Sstevel@tonic-gate splx(saved_spl);
3090Sstevel@tonic-gate }
3105648Ssetje
3115648Ssetje
3125648Ssetje /*
3135648Ssetje * WARNING
3145648Ssetje * The code fom here to the end of mlsetup.c runs before krtld has
3155648Ssetje * knitted unix and genunix together. It can call routines in unix,
3165648Ssetje * but calls into genunix will fail spectacularly. More specifically,
3175648Ssetje * calls to prom_*, bop_* and str* will work, everything else is
3185648Ssetje * caveat emptor.
3195648Ssetje *
3205648Ssetje * Also note that while #ifdef sun4u is generally a bad idea, they
3215648Ssetje * exist here to concentrate the dangerous code into a single file.
3225648Ssetje */
3235648Ssetje
3245648Ssetje static char *
getcpulist(void)3255648Ssetje getcpulist(void)
3265648Ssetje {
3275648Ssetje pnode_t node;
3285648Ssetje /* big enough for OBP_NAME and for a reasonably sized OBP_COMPATIBLE. */
3295648Ssetje static char cpubuf[5 * OBP_MAXDRVNAME];
3305648Ssetje int nlen, clen, i;
3315648Ssetje #ifdef sun4u
3325648Ssetje char dname[OBP_MAXDRVNAME];
3335648Ssetje #endif
3345648Ssetje
3355648Ssetje node = prom_findnode_bydevtype(prom_rootnode(), OBP_CPU);
3365648Ssetje if (node != OBP_NONODE && node != OBP_BADNODE) {
3375648Ssetje if ((nlen = prom_getproplen(node, OBP_NAME)) <= 0 ||
3385648Ssetje nlen > sizeof (cpubuf) ||
3395648Ssetje prom_getprop(node, OBP_NAME, cpubuf) <= 0)
3405648Ssetje prom_panic("no name in cpu node");
3415648Ssetje
3425648Ssetje /* nlen includes the terminating null character */
3435648Ssetje #ifdef sun4v
3445648Ssetje if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0) {
3455648Ssetje #else /* sun4u */
3465648Ssetje /*
3475648Ssetje * For the CMT case, need check the parent "core"
3485648Ssetje * node for the compatible property.
3495648Ssetje */
3505648Ssetje if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 ||
3515648Ssetje ((node = prom_parentnode(node)) != OBP_NONODE &&
3525648Ssetje node != OBP_BADNODE &&
3535648Ssetje (clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 &&
3545648Ssetje prom_getprop(node, OBP_DEVICETYPE, dname) > 0 &&
3555648Ssetje strcmp(dname, "core") == 0)) {
3565648Ssetje #endif
3575648Ssetje if ((clen + nlen) > sizeof (cpubuf))
3585648Ssetje prom_panic("cpu node \"compatible\" too long");
3595648Ssetje /* read in compatible, leaving space for ':' */
3605648Ssetje if (prom_getprop(node, OBP_COMPATIBLE,
3615648Ssetje &cpubuf[nlen]) != clen)
3625648Ssetje prom_panic("cpu node \"compatible\" error");
3635648Ssetje clen += nlen; /* total length */
3645648Ssetje /* convert all null characters to ':' */
3655648Ssetje clen--; /* except the final one... */
3665648Ssetje for (i = 0; i < clen; i++)
3675648Ssetje if (cpubuf[i] == '\0')
3685648Ssetje cpubuf[i] = ':';
3695648Ssetje }
3705648Ssetje #ifdef sun4u
3715648Ssetje /*
3725648Ssetje * Some PROMs return SUNW,UltraSPARC when they actually have
3735648Ssetje * SUNW,UltraSPARC-II cpus. SInce we're now filtering out all
3745648Ssetje * SUNW,UltraSPARC systems during the boot phase, we can safely
3755648Ssetje * point the auxv CPU value at SUNW,UltraSPARC-II.
3765648Ssetje */
3775648Ssetje if (strcmp("SUNW,UltraSPARC", cpubuf) == 0)
3785648Ssetje (void) strcpy(cpubuf, "SUNW,UltraSPARC-II");
3795648Ssetje #endif
3805648Ssetje return (cpubuf);
3815648Ssetje } else
3825648Ssetje return (NULL);
3835648Ssetje }
3845648Ssetje
3855648Ssetje /*
3865648Ssetje * called immediately from _start to stich the
3875648Ssetje * primary modules together
3885648Ssetje */
3895648Ssetje void
3905648Ssetje kobj_start(void *cif)
3915648Ssetje {
3925648Ssetje Ehdr *ehdr;
3935648Ssetje Phdr *phdr;
3945648Ssetje uint32_t eadr, padr;
3955648Ssetje val_t bootaux[BA_NUM];
3965648Ssetje int i;
3975648Ssetje
3985648Ssetje prom_init("kernel", cif);
3995648Ssetje bop_init();
4005648Ssetje #ifdef DEBUG
4015648Ssetje if (bop_getproplen("stop-me") != -1)
4025648Ssetje prom_enter_mon();
4035648Ssetje #endif
4045648Ssetje
4055648Ssetje if (bop_getprop("elfheader-address", (caddr_t)&eadr) == -1)
4065648Ssetje prom_panic("no ELF image");
4075648Ssetje ehdr = (Ehdr *)(uintptr_t)eadr;
4085648Ssetje for (i = 0; i < BA_NUM; i++)
4095648Ssetje bootaux[i].ba_val = NULL;
4105648Ssetje bootaux[BA_PHNUM].ba_val = ehdr->e_phnum;
4115648Ssetje bootaux[BA_PHENT].ba_val = ehdr->e_phentsize;
4125648Ssetje bootaux[BA_LDNAME].ba_ptr = NULL;
4135648Ssetje
4145648Ssetje padr = eadr + ehdr->e_phoff;
4155648Ssetje bootaux[BA_PHDR].ba_ptr = (void *)(uintptr_t)padr;
4165648Ssetje for (i = 0; i < ehdr->e_phnum; i++) {
4175648Ssetje phdr = (Phdr *)((uintptr_t)padr + i * ehdr->e_phentsize);
4185648Ssetje if (phdr->p_type == PT_DYNAMIC) {
4195648Ssetje bootaux[BA_DYNAMIC].ba_ptr = (void *)phdr->p_vaddr;
4205648Ssetje break;
4215648Ssetje }
4225648Ssetje }
4235648Ssetje
4245648Ssetje bootaux[BA_LPAGESZ].ba_val = MMU_PAGESIZE4M;
4255648Ssetje bootaux[BA_PAGESZ].ba_val = MMU_PAGESIZE;
4265648Ssetje bootaux[BA_IFLUSH].ba_val = 1;
4275648Ssetje bootaux[BA_CPU].ba_ptr = getcpulist();
4285648Ssetje bootaux[BA_MMU].ba_ptr = NULL;
4295648Ssetje
4305648Ssetje kobj_init(cif, NULL, bootops, bootaux);
4315648Ssetje
4325648Ssetje /* kernel stitched together; we can now test #pragma's */
4335648Ssetje if (&plat_setprop_enter != NULL) {
4345648Ssetje prom_setprop_enter = &plat_setprop_enter;
4355648Ssetje prom_setprop_exit = &plat_setprop_exit;
4365648Ssetje ASSERT(prom_setprop_exit != NULL);
4375648Ssetje }
4385648Ssetje
4395648Ssetje }
4405648Ssetje
4415648Ssetje /*
4425648Ssetje * Create modpath from kernel name.
4435648Ssetje * If we booted:
4445648Ssetje * /platform/`uname -i`/kernel/sparcv9/unix
4455648Ssetje * or
4465648Ssetje * /platform/`uname -m`/kernel/sparcv9/unix
4475648Ssetje *
4485648Ssetje * then make the modpath:
4495648Ssetje * /platform/`uname -i`/kernel /platform/`uname -m`/kernel
4505648Ssetje *
4515648Ssetje * otherwise, make the modpath the dir the kernel was
4525648Ssetje * loaded from, minus any sparcv9 extension
4535648Ssetje *
4545648Ssetje * note the sparcv9 dir is optional since a unix -> sparcv9/unix
4555648Ssetje * symlink is available as a shortcut.
4565648Ssetje */
4575648Ssetje void
4585648Ssetje mach_modpath(char *path, const char *fname)
4595648Ssetje {
4605648Ssetje char *p;
4615648Ssetje int len, compat;
4625648Ssetje const char prefix[] = "/platform/";
4635648Ssetje char platname[MAXPATHLEN];
4645648Ssetje #ifdef sun4u
4655648Ssetje char defname[] = "sun4u";
4665648Ssetje #else
4675648Ssetje char defname[] = "sun4v";
4685648Ssetje #endif
4695648Ssetje const char suffix[] = "/kernel";
4705648Ssetje const char isastr[] = "/sparcv9";
4715648Ssetje
4725648Ssetje /*
4735648Ssetje * check for /platform
4745648Ssetje */
4755648Ssetje p = (char *)fname;
4765648Ssetje if (strncmp(p, prefix, sizeof (prefix) - 1) != 0)
4775648Ssetje goto nopath;
4785648Ssetje p += sizeof (prefix) - 1;
4795648Ssetje
4805648Ssetje /*
4815648Ssetje * check for the default name or the platform name.
4825648Ssetje * also see if we used the 'compatible' name
4835648Ssetje * (platname == default)
4845648Ssetje */
4855648Ssetje (void) bop_getprop("impl-arch-name", platname);
4865648Ssetje compat = strcmp(platname, defname) == 0;
4875648Ssetje len = strlen(platname);
4885648Ssetje if (strncmp(p, platname, len) == 0)
4895648Ssetje p += len;
4905648Ssetje else if (strncmp(p, defname, sizeof (defname) - 1) == 0)
4915648Ssetje p += sizeof (defname) - 1;
4925648Ssetje else
4935648Ssetje goto nopath;
4945648Ssetje
4955648Ssetje /*
4965648Ssetje * check for /kernel/sparcv9 or just /kernel
4975648Ssetje */
4985648Ssetje if (strncmp(p, suffix, sizeof (suffix) - 1) != 0)
4995648Ssetje goto nopath;
5005648Ssetje p += sizeof (suffix) - 1;
5015648Ssetje if (strncmp(p, isastr, sizeof (isastr) - 1) == 0)
5025648Ssetje p += sizeof (isastr) - 1;
5035648Ssetje
5045648Ssetje /*
5055648Ssetje * check we're at the last component
5065648Ssetje */
5075648Ssetje if (p != strrchr(fname, '/'))
5085648Ssetje goto nopath;
5095648Ssetje
5105648Ssetje /*
5115648Ssetje * everything is kosher; setup modpath
5125648Ssetje */
5135648Ssetje (void) strcpy(path, "/platform/");
5145648Ssetje (void) strcat(path, platname);
51510047SPramod.Batni@Sun.COM (void) strcat(path, "/kernel");
5165648Ssetje if (!compat) {
51710047SPramod.Batni@Sun.COM (void) strcat(path, " /platform/");
5185648Ssetje (void) strcat(path, defname);
51910047SPramod.Batni@Sun.COM (void) strcat(path, "/kernel");
5205648Ssetje }
5215648Ssetje return;
5225648Ssetje
5235648Ssetje nopath:
5245648Ssetje /*
5255648Ssetje * Construct the directory path from the filename.
5265648Ssetje */
5275648Ssetje if ((p = strrchr(fname, '/')) == NULL)
5285648Ssetje return;
5295648Ssetje
5305648Ssetje while (p > fname && *(p - 1) == '/')
5315648Ssetje p--; /* remove trailing '/' characters */
5325648Ssetje if (p == fname)
5335648Ssetje p++; /* so "/" -is- the modpath in this case */
5345648Ssetje
5355648Ssetje /*
5365648Ssetje * Remove optional isa-dependent directory name - the module
5375648Ssetje * subsystem will put this back again (!)
5385648Ssetje */
5395648Ssetje len = p - fname;
5405648Ssetje if (len > sizeof (isastr) - 1 &&
5415648Ssetje strncmp(&fname[len - (sizeof (isastr) - 1)], isastr,
5425648Ssetje sizeof (isastr) - 1) == 0)
5435648Ssetje p -= sizeof (isastr) - 1;
5445648Ssetje (void) strncpy(path, fname, p - fname);
5455648Ssetje }
546