17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5c56c1e58Sgirish * Common Development and Distribution License (the "License"). 6c56c1e58Sgirish * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 220e751525SEric Saxe * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/types.h> 277c478bd9Sstevel@tonic-gate #include <sys/systm.h> 287c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 297c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 307c478bd9Sstevel@tonic-gate #include <sys/disp.h> 317c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 327c478bd9Sstevel@tonic-gate #include <sys/promif.h> 337c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 34986fd29aSsetje #include <sys/promimpl.h> 35986fd29aSsetje #include <sys/platform_module.h> 367c478bd9Sstevel@tonic-gate #include <sys/clock.h> 377c478bd9Sstevel@tonic-gate #include <sys/pte.h> 387c478bd9Sstevel@tonic-gate #include <sys/scb.h> 397c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 407c478bd9Sstevel@tonic-gate #include <sys/stack.h> 417c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 427c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 437c478bd9Sstevel@tonic-gate #include <vm/as.h> 447c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 457c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 467c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 477c478bd9Sstevel@tonic-gate #include <sys/vtrace.h> 487c478bd9Sstevel@tonic-gate #include <sys/trap.h> 497c478bd9Sstevel@tonic-gate #include <sys/machtrap.h> 507c478bd9Sstevel@tonic-gate #include <sys/privregs.h> 517c478bd9Sstevel@tonic-gate #include <sys/machpcb.h> 527c478bd9Sstevel@tonic-gate #include <sys/proc.h> 537c478bd9Sstevel@tonic-gate #include <sys/cpupart.h> 547c478bd9Sstevel@tonic-gate #include <sys/pset.h> 557c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 567c478bd9Sstevel@tonic-gate #include <sys/copyops.h> 577c478bd9Sstevel@tonic-gate #include <sys/panic.h> 587c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> /* for bootops */ 59fb2f18f8Sesaxe #include <sys/pg.h> 607c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 617c478bd9Sstevel@tonic-gate #include <sys/fpras.h> 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 647c478bd9Sstevel@tonic-gate #include <sys/debug.h> 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 677c478bd9Sstevel@tonic-gate #include <sys/lgrp.h> 687c478bd9Sstevel@tonic-gate #include <sys/traptrace.h> 69986fd29aSsetje 70986fd29aSsetje #include <sys/kobj_impl.h> 71986fd29aSsetje #include <sys/kdi_machimpl.h> 72986fd29aSsetje 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * External Routines: 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate extern void map_wellknown_devices(void); 77c56c1e58Sgirish extern void hsvc_setup(void); 781ae08745Sheppo extern void mach_descrip_startup_init(void); 793b890a5bSjb145095 extern void mach_soft_state_init(void); 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate int dcache_size; 827c478bd9Sstevel@tonic-gate int dcache_linesize; 837c478bd9Sstevel@tonic-gate int icache_size; 847c478bd9Sstevel@tonic-gate int icache_linesize; 857c478bd9Sstevel@tonic-gate int ecache_size; 867c478bd9Sstevel@tonic-gate int ecache_alignsize; 877c478bd9Sstevel@tonic-gate int ecache_associativity; 887c478bd9Sstevel@tonic-gate int ecache_setsize; /* max possible e$ setsize */ 897c478bd9Sstevel@tonic-gate int cpu_setsize; /* max e$ setsize of configured cpus */ 907c478bd9Sstevel@tonic-gate int dcache_line_mask; /* spitfire only */ 917c478bd9Sstevel@tonic-gate int vac_size; /* cache size in bytes */ 927c478bd9Sstevel@tonic-gate uint_t vac_mask; /* VAC alignment consistency mask */ 937c478bd9Sstevel@tonic-gate int vac_shift; /* log2(vac_size) for ppmapout() */ 947c478bd9Sstevel@tonic-gate int vac = 0; /* virtual address cache type (none == 0) */ 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * fpRAS. An individual sun4* machine class (or perhaps subclass, 987c478bd9Sstevel@tonic-gate * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements 997c478bd9Sstevel@tonic-gate * the fpRAS feature. The feature can be suppressed by setting fpras_disable 1007c478bd9Sstevel@tonic-gate * or the mechanism can be disabled for individual copy operations with 1017c478bd9Sstevel@tonic-gate * fpras_disableids. All these are checked in post_startup() code so 1027c478bd9Sstevel@tonic-gate * fpras_disable and fpras_disableids can be set in /etc/system. 1037c478bd9Sstevel@tonic-gate * If/when fpRAS is implemented on non-sun4 architectures these 1047c478bd9Sstevel@tonic-gate * definitions will need to move up to the common level. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate int fpras_implemented; 1077c478bd9Sstevel@tonic-gate int fpras_disable; 1087c478bd9Sstevel@tonic-gate int fpras_disableids; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * Static Routines: 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate static void kern_splr_preprom(void); 1147c478bd9Sstevel@tonic-gate static void kern_splx_postprom(void); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 1187c478bd9Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate void 122986fd29aSsetje mlsetup(struct regs *rp, kfpu_t *fp) 1237c478bd9Sstevel@tonic-gate { 1247c478bd9Sstevel@tonic-gate struct machpcb *mpcb; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate extern char t0stack[]; 1277c478bd9Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1287c478bd9Sstevel@tonic-gate extern disp_t cpu0_disp; 1297c478bd9Sstevel@tonic-gate unsigned long long pa; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 1327c478bd9Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp; 1337c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 1347c478bd9Sstevel@tonic-gate 135986fd29aSsetje /* drop into kmdb on boot -d */ 136986fd29aSsetje if (boothowto & RB_DEBUGENTER) 137986fd29aSsetje kmdb_enter(); 138986fd29aSsetje 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * initialize cpu_self 1417c478bd9Sstevel@tonic-gate */ 1427c478bd9Sstevel@tonic-gate cpu0.cpu_self = &cpu0; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * initialize t0 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - REGOFF; 1487c478bd9Sstevel@tonic-gate /* Can't use va_to_pa here - wait until prom_ initialized */ 1497c478bd9Sstevel@tonic-gate t0.t_stkbase = t0stack; 1507c478bd9Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 1517c478bd9Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 1527c478bd9Sstevel@tonic-gate t0.t_procp = &p0; 1537c478bd9Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 1547c478bd9Sstevel@tonic-gate t0.t_lwp = &lwp0; 1557c478bd9Sstevel@tonic-gate t0.t_forw = &t0; 1567c478bd9Sstevel@tonic-gate t0.t_back = &t0; 1577c478bd9Sstevel@tonic-gate t0.t_next = &t0; 1587c478bd9Sstevel@tonic-gate t0.t_prev = &t0; 1597c478bd9Sstevel@tonic-gate t0.t_cpu = &cpu0; /* loaded by _start */ 1607c478bd9Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 1617c478bd9Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 1627c478bd9Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 1630b70c467Sakolb t0.t_bindflag = (uchar_t)default_binding_mode; 1647c478bd9Sstevel@tonic-gate t0.t_cpupart = &cp_default; 1657c478bd9Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 1667c478bd9Sstevel@tonic-gate t0.t_copyops = NULL; 1677c478bd9Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate lwp0.lwp_thread = &t0; 1707c478bd9Sstevel@tonic-gate lwp0.lwp_procp = &p0; 1717c478bd9Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp; 1727c478bd9Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate mpcb = lwptompcb(&lwp0); 1757c478bd9Sstevel@tonic-gate mpcb->mpcb_fpu = fp; 1767c478bd9Sstevel@tonic-gate mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q; 1777c478bd9Sstevel@tonic-gate mpcb->mpcb_thread = &t0; 1787c478bd9Sstevel@tonic-gate lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate p0.p_exec = NULL; 1817c478bd9Sstevel@tonic-gate p0.p_stat = SRUN; 1827c478bd9Sstevel@tonic-gate p0.p_flag = SSYS; 1837c478bd9Sstevel@tonic-gate p0.p_tlist = &t0; 1847c478bd9Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 1857c478bd9Sstevel@tonic-gate p0.p_stkpageszc = 0; 1867c478bd9Sstevel@tonic-gate p0.p_as = &kas; 1877c478bd9Sstevel@tonic-gate p0.p_lockp = &p0lock; 1887c478bd9Sstevel@tonic-gate p0.p_utraps = NULL; 1897c478bd9Sstevel@tonic-gate p0.p_brkpageszc = 0; 1902cb27123Saguzovsk p0.p_t1_lgrpid = LGRP_NONE; 1912cb27123Saguzovsk p0.p_tr_lgrpid = LGRP_NONE; 1927c478bd9Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate CPU->cpu_thread = &t0; 1957c478bd9Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 1967c478bd9Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 1977c478bd9Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 1987c478bd9Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 1997c478bd9Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 2007c478bd9Sstevel@tonic-gate CPU->cpu_flags = CPU_RUNNING; 2017c478bd9Sstevel@tonic-gate CPU->cpu_id = getprocessorid(); 2027c478bd9Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* 205ae115bc7Smrj * Initialize thread/cpu microstate accounting 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 2087c478bd9Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Initialize lists of available and active CPUs. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate cpu_list_init(CPU); 2147c478bd9Sstevel@tonic-gate 215affbd3ccSkchow cpu_vm_data_init(CPU); 216affbd3ccSkchow 2170e751525SEric Saxe pg_cpu_bootstrap(CPU); 2180e751525SEric Saxe 2197c478bd9Sstevel@tonic-gate (void) prom_set_preprom(kern_splr_preprom); 2207c478bd9Sstevel@tonic-gate (void) prom_set_postprom(kern_splx_postprom); 2217c478bd9Sstevel@tonic-gate PRM_INFO("mlsetup: now ok to call prom_printf"); 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate mpcb->mpcb_pa = va_to_pa(t0.t_stk); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* 2267c478bd9Sstevel@tonic-gate * Claim the physical and virtual resources used by panicbuf, 2277c478bd9Sstevel@tonic-gate * then map panicbuf. This operation removes the phys and 2287c478bd9Sstevel@tonic-gate * virtual addresses from the free lists. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf) 2317c478bd9Sstevel@tonic-gate prom_panic("Can't claim panicbuf virtual address"); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0) 2347c478bd9Sstevel@tonic-gate prom_panic("Can't allocate retained panicbuf physical address"); 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0) 2377c478bd9Sstevel@tonic-gate prom_panic("Can't map panicbuf"); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate PRM_DEBUG(panicbuf); 2407c478bd9Sstevel@tonic-gate PRM_DEBUG(pa); 2417c478bd9Sstevel@tonic-gate 242c56c1e58Sgirish /* 243c56c1e58Sgirish * Negotiate hypervisor services, if any 244c56c1e58Sgirish */ 245c56c1e58Sgirish hsvc_setup(); 2463b890a5bSjb145095 mach_soft_state_init(); 247c56c1e58Sgirish 2487c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * initialize the trap trace buffer for the boot cpu 2517c478bd9Sstevel@tonic-gate * XXX todo, dynamically allocate this buffer too 2527c478bd9Sstevel@tonic-gate */ 2537c478bd9Sstevel@tonic-gate ctlp = &trap_trace_ctl[CPU->cpu_id]; 2547c478bd9Sstevel@tonic-gate ctlp->d.vaddr_base = trap_tr0; 2557c478bd9Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0; 2567c478bd9Sstevel@tonic-gate ctlp->d.limit = TRAP_TSIZE; /* XXX dynamic someday */ 2577c478bd9Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(trap_tr0); 258db6d2ee3Ssvemuri #endif /* TRAPTRACE */ 2591ae08745Sheppo 2601ae08745Sheppo /* 2611ae08745Sheppo * Initialize the Machine Description kernel framework 2621ae08745Sheppo */ 2631ae08745Sheppo 2641ae08745Sheppo mach_descrip_startup_init(); 2651ae08745Sheppo 2667c478bd9Sstevel@tonic-gate /* 2677c478bd9Sstevel@tonic-gate * initialize HV trap trace buffer for the boot cpu 2687c478bd9Sstevel@tonic-gate */ 269db6d2ee3Ssvemuri mach_htraptrace_setup(CPU->cpu_id); 270db6d2ee3Ssvemuri mach_htraptrace_configure(CPU->cpu_id); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * lgroup framework initialization. This must be done prior 2747c478bd9Sstevel@tonic-gate * to devices being mapped. 2757c478bd9Sstevel@tonic-gate */ 276*d5d7cf4eSJonathan Chew lgrp_init(LGRP_INIT_STAGE1); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate cpu_setup(); 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate if (boothowto & RB_HALT) { 2817c478bd9Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 2827c478bd9Sstevel@tonic-gate prom_enter_mon(); 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate setcputype(); 2867c478bd9Sstevel@tonic-gate map_wellknown_devices(); 2877c478bd9Sstevel@tonic-gate setcpudelay(); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate /* 2917c478bd9Sstevel@tonic-gate * These routines are called immediately before and 2927c478bd9Sstevel@tonic-gate * immediately after calling into the firmware. The 2937c478bd9Sstevel@tonic-gate * firmware is significantly confused by preemption - 2947c478bd9Sstevel@tonic-gate * particularly on MP machines - but also on UP's too. 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate static int saved_spl; 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate static void 3007c478bd9Sstevel@tonic-gate kern_splr_preprom(void) 3017c478bd9Sstevel@tonic-gate { 3027c478bd9Sstevel@tonic-gate saved_spl = spl7(); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate static void 3067c478bd9Sstevel@tonic-gate kern_splx_postprom(void) 3077c478bd9Sstevel@tonic-gate { 3087c478bd9Sstevel@tonic-gate splx(saved_spl); 3097c478bd9Sstevel@tonic-gate } 310986fd29aSsetje 311986fd29aSsetje 312986fd29aSsetje /* 313986fd29aSsetje * WARNING 314986fd29aSsetje * The code fom here to the end of mlsetup.c runs before krtld has 315986fd29aSsetje * knitted unix and genunix together. It can call routines in unix, 316986fd29aSsetje * but calls into genunix will fail spectacularly. More specifically, 317986fd29aSsetje * calls to prom_*, bop_* and str* will work, everything else is 318986fd29aSsetje * caveat emptor. 319986fd29aSsetje * 320986fd29aSsetje * Also note that while #ifdef sun4u is generally a bad idea, they 321986fd29aSsetje * exist here to concentrate the dangerous code into a single file. 322986fd29aSsetje */ 323986fd29aSsetje 324986fd29aSsetje static char * 325986fd29aSsetje getcpulist(void) 326986fd29aSsetje { 327986fd29aSsetje pnode_t node; 328986fd29aSsetje /* big enough for OBP_NAME and for a reasonably sized OBP_COMPATIBLE. */ 329986fd29aSsetje static char cpubuf[5 * OBP_MAXDRVNAME]; 330986fd29aSsetje int nlen, clen, i; 331986fd29aSsetje #ifdef sun4u 332986fd29aSsetje char dname[OBP_MAXDRVNAME]; 333986fd29aSsetje #endif 334986fd29aSsetje 335986fd29aSsetje node = prom_findnode_bydevtype(prom_rootnode(), OBP_CPU); 336986fd29aSsetje if (node != OBP_NONODE && node != OBP_BADNODE) { 337986fd29aSsetje if ((nlen = prom_getproplen(node, OBP_NAME)) <= 0 || 338986fd29aSsetje nlen > sizeof (cpubuf) || 339986fd29aSsetje prom_getprop(node, OBP_NAME, cpubuf) <= 0) 340986fd29aSsetje prom_panic("no name in cpu node"); 341986fd29aSsetje 342986fd29aSsetje /* nlen includes the terminating null character */ 343986fd29aSsetje #ifdef sun4v 344986fd29aSsetje if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0) { 345986fd29aSsetje #else /* sun4u */ 346986fd29aSsetje /* 347986fd29aSsetje * For the CMT case, need check the parent "core" 348986fd29aSsetje * node for the compatible property. 349986fd29aSsetje */ 350986fd29aSsetje if ((clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 || 351986fd29aSsetje ((node = prom_parentnode(node)) != OBP_NONODE && 352986fd29aSsetje node != OBP_BADNODE && 353986fd29aSsetje (clen = prom_getproplen(node, OBP_COMPATIBLE)) > 0 && 354986fd29aSsetje prom_getprop(node, OBP_DEVICETYPE, dname) > 0 && 355986fd29aSsetje strcmp(dname, "core") == 0)) { 356986fd29aSsetje #endif 357986fd29aSsetje if ((clen + nlen) > sizeof (cpubuf)) 358986fd29aSsetje prom_panic("cpu node \"compatible\" too long"); 359986fd29aSsetje /* read in compatible, leaving space for ':' */ 360986fd29aSsetje if (prom_getprop(node, OBP_COMPATIBLE, 361986fd29aSsetje &cpubuf[nlen]) != clen) 362986fd29aSsetje prom_panic("cpu node \"compatible\" error"); 363986fd29aSsetje clen += nlen; /* total length */ 364986fd29aSsetje /* convert all null characters to ':' */ 365986fd29aSsetje clen--; /* except the final one... */ 366986fd29aSsetje for (i = 0; i < clen; i++) 367986fd29aSsetje if (cpubuf[i] == '\0') 368986fd29aSsetje cpubuf[i] = ':'; 369986fd29aSsetje } 370986fd29aSsetje #ifdef sun4u 371986fd29aSsetje /* 372986fd29aSsetje * Some PROMs return SUNW,UltraSPARC when they actually have 373986fd29aSsetje * SUNW,UltraSPARC-II cpus. SInce we're now filtering out all 374986fd29aSsetje * SUNW,UltraSPARC systems during the boot phase, we can safely 375986fd29aSsetje * point the auxv CPU value at SUNW,UltraSPARC-II. 376986fd29aSsetje */ 377986fd29aSsetje if (strcmp("SUNW,UltraSPARC", cpubuf) == 0) 378986fd29aSsetje (void) strcpy(cpubuf, "SUNW,UltraSPARC-II"); 379986fd29aSsetje #endif 380986fd29aSsetje return (cpubuf); 381986fd29aSsetje } else 382986fd29aSsetje return (NULL); 383986fd29aSsetje } 384986fd29aSsetje 385986fd29aSsetje /* 386986fd29aSsetje * called immediately from _start to stich the 387986fd29aSsetje * primary modules together 388986fd29aSsetje */ 389986fd29aSsetje void 390986fd29aSsetje kobj_start(void *cif) 391986fd29aSsetje { 392986fd29aSsetje Ehdr *ehdr; 393986fd29aSsetje Phdr *phdr; 394986fd29aSsetje uint32_t eadr, padr; 395986fd29aSsetje val_t bootaux[BA_NUM]; 396986fd29aSsetje int i; 397986fd29aSsetje 398986fd29aSsetje prom_init("kernel", cif); 399986fd29aSsetje bop_init(); 400986fd29aSsetje #ifdef DEBUG 401986fd29aSsetje if (bop_getproplen("stop-me") != -1) 402986fd29aSsetje prom_enter_mon(); 403986fd29aSsetje #endif 404986fd29aSsetje 405986fd29aSsetje if (bop_getprop("elfheader-address", (caddr_t)&eadr) == -1) 406986fd29aSsetje prom_panic("no ELF image"); 407986fd29aSsetje ehdr = (Ehdr *)(uintptr_t)eadr; 408986fd29aSsetje for (i = 0; i < BA_NUM; i++) 409986fd29aSsetje bootaux[i].ba_val = NULL; 410986fd29aSsetje bootaux[BA_PHNUM].ba_val = ehdr->e_phnum; 411986fd29aSsetje bootaux[BA_PHENT].ba_val = ehdr->e_phentsize; 412986fd29aSsetje bootaux[BA_LDNAME].ba_ptr = NULL; 413986fd29aSsetje 414986fd29aSsetje padr = eadr + ehdr->e_phoff; 415986fd29aSsetje bootaux[BA_PHDR].ba_ptr = (void *)(uintptr_t)padr; 416986fd29aSsetje for (i = 0; i < ehdr->e_phnum; i++) { 417986fd29aSsetje phdr = (Phdr *)((uintptr_t)padr + i * ehdr->e_phentsize); 418986fd29aSsetje if (phdr->p_type == PT_DYNAMIC) { 419986fd29aSsetje bootaux[BA_DYNAMIC].ba_ptr = (void *)phdr->p_vaddr; 420986fd29aSsetje break; 421986fd29aSsetje } 422986fd29aSsetje } 423986fd29aSsetje 424986fd29aSsetje bootaux[BA_LPAGESZ].ba_val = MMU_PAGESIZE4M; 425986fd29aSsetje bootaux[BA_PAGESZ].ba_val = MMU_PAGESIZE; 426986fd29aSsetje bootaux[BA_IFLUSH].ba_val = 1; 427986fd29aSsetje bootaux[BA_CPU].ba_ptr = getcpulist(); 428986fd29aSsetje bootaux[BA_MMU].ba_ptr = NULL; 429986fd29aSsetje 430986fd29aSsetje kobj_init(cif, NULL, bootops, bootaux); 431986fd29aSsetje 432986fd29aSsetje /* kernel stitched together; we can now test #pragma's */ 433986fd29aSsetje if (&plat_setprop_enter != NULL) { 434986fd29aSsetje prom_setprop_enter = &plat_setprop_enter; 435986fd29aSsetje prom_setprop_exit = &plat_setprop_exit; 436986fd29aSsetje ASSERT(prom_setprop_exit != NULL); 437986fd29aSsetje } 438986fd29aSsetje 439986fd29aSsetje } 440986fd29aSsetje 441986fd29aSsetje /* 442986fd29aSsetje * Create modpath from kernel name. 443986fd29aSsetje * If we booted: 444986fd29aSsetje * /platform/`uname -i`/kernel/sparcv9/unix 445986fd29aSsetje * or 446986fd29aSsetje * /platform/`uname -m`/kernel/sparcv9/unix 447986fd29aSsetje * 448986fd29aSsetje * then make the modpath: 449986fd29aSsetje * /platform/`uname -i`/kernel /platform/`uname -m`/kernel 450986fd29aSsetje * 451986fd29aSsetje * otherwise, make the modpath the dir the kernel was 452986fd29aSsetje * loaded from, minus any sparcv9 extension 453986fd29aSsetje * 454986fd29aSsetje * note the sparcv9 dir is optional since a unix -> sparcv9/unix 455986fd29aSsetje * symlink is available as a shortcut. 456986fd29aSsetje */ 457986fd29aSsetje void 458986fd29aSsetje mach_modpath(char *path, const char *fname) 459986fd29aSsetje { 460986fd29aSsetje char *p; 461986fd29aSsetje int len, compat; 462986fd29aSsetje const char prefix[] = "/platform/"; 463986fd29aSsetje char platname[MAXPATHLEN]; 464986fd29aSsetje #ifdef sun4u 465986fd29aSsetje char defname[] = "sun4u"; 466986fd29aSsetje #else 467986fd29aSsetje char defname[] = "sun4v"; 468986fd29aSsetje #endif 469986fd29aSsetje const char suffix[] = "/kernel"; 470986fd29aSsetje const char isastr[] = "/sparcv9"; 471986fd29aSsetje 472986fd29aSsetje /* 473986fd29aSsetje * check for /platform 474986fd29aSsetje */ 475986fd29aSsetje p = (char *)fname; 476986fd29aSsetje if (strncmp(p, prefix, sizeof (prefix) - 1) != 0) 477986fd29aSsetje goto nopath; 478986fd29aSsetje p += sizeof (prefix) - 1; 479986fd29aSsetje 480986fd29aSsetje /* 481986fd29aSsetje * check for the default name or the platform name. 482986fd29aSsetje * also see if we used the 'compatible' name 483986fd29aSsetje * (platname == default) 484986fd29aSsetje */ 485986fd29aSsetje (void) bop_getprop("impl-arch-name", platname); 486986fd29aSsetje compat = strcmp(platname, defname) == 0; 487986fd29aSsetje len = strlen(platname); 488986fd29aSsetje if (strncmp(p, platname, len) == 0) 489986fd29aSsetje p += len; 490986fd29aSsetje else if (strncmp(p, defname, sizeof (defname) - 1) == 0) 491986fd29aSsetje p += sizeof (defname) - 1; 492986fd29aSsetje else 493986fd29aSsetje goto nopath; 494986fd29aSsetje 495986fd29aSsetje /* 496986fd29aSsetje * check for /kernel/sparcv9 or just /kernel 497986fd29aSsetje */ 498986fd29aSsetje if (strncmp(p, suffix, sizeof (suffix) - 1) != 0) 499986fd29aSsetje goto nopath; 500986fd29aSsetje p += sizeof (suffix) - 1; 501986fd29aSsetje if (strncmp(p, isastr, sizeof (isastr) - 1) == 0) 502986fd29aSsetje p += sizeof (isastr) - 1; 503986fd29aSsetje 504986fd29aSsetje /* 505986fd29aSsetje * check we're at the last component 506986fd29aSsetje */ 507986fd29aSsetje if (p != strrchr(fname, '/')) 508986fd29aSsetje goto nopath; 509986fd29aSsetje 510986fd29aSsetje /* 511986fd29aSsetje * everything is kosher; setup modpath 512986fd29aSsetje */ 513986fd29aSsetje (void) strcpy(path, "/platform/"); 514986fd29aSsetje (void) strcat(path, platname); 515986fd29aSsetje (void) strcat(path, "/kernel"); 516986fd29aSsetje if (!compat) { 517986fd29aSsetje (void) strcat(path, " /platform/"); 518986fd29aSsetje (void) strcat(path, defname); 519986fd29aSsetje (void) strcat(path, "/kernel"); 520986fd29aSsetje } 521986fd29aSsetje return; 522986fd29aSsetje 523986fd29aSsetje nopath: 524986fd29aSsetje /* 525986fd29aSsetje * Construct the directory path from the filename. 526986fd29aSsetje */ 527986fd29aSsetje if ((p = strrchr(fname, '/')) == NULL) 528986fd29aSsetje return; 529986fd29aSsetje 530986fd29aSsetje while (p > fname && *(p - 1) == '/') 531986fd29aSsetje p--; /* remove trailing '/' characters */ 532986fd29aSsetje if (p == fname) 533986fd29aSsetje p++; /* so "/" -is- the modpath in this case */ 534986fd29aSsetje 535986fd29aSsetje /* 536986fd29aSsetje * Remove optional isa-dependent directory name - the module 537986fd29aSsetje * subsystem will put this back again (!) 538986fd29aSsetje */ 539986fd29aSsetje len = p - fname; 540986fd29aSsetje if (len > sizeof (isastr) - 1 && 541986fd29aSsetje strncmp(&fname[len - (sizeof (isastr) - 1)], isastr, 542986fd29aSsetje sizeof (isastr) - 1) == 0) 543986fd29aSsetje p -= sizeof (isastr) - 1; 544986fd29aSsetje (void) strncpy(path, fname, p - fname); 545986fd29aSsetje } 546