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 52006Sandrei * Common Development and Distribution License (the "License"). 62006Sandrei * 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> 273446Smrj #include <sys/sysmacros.h> 280Sstevel@tonic-gate #include <sys/disp.h> 290Sstevel@tonic-gate #include <sys/promif.h> 300Sstevel@tonic-gate #include <sys/clock.h> 310Sstevel@tonic-gate #include <sys/cpuvar.h> 320Sstevel@tonic-gate #include <sys/stack.h> 330Sstevel@tonic-gate #include <vm/as.h> 340Sstevel@tonic-gate #include <vm/hat.h> 350Sstevel@tonic-gate #include <sys/reboot.h> 360Sstevel@tonic-gate #include <sys/avintr.h> 370Sstevel@tonic-gate #include <sys/vtrace.h> 380Sstevel@tonic-gate #include <sys/proc.h> 390Sstevel@tonic-gate #include <sys/thread.h> 400Sstevel@tonic-gate #include <sys/cpupart.h> 410Sstevel@tonic-gate #include <sys/pset.h> 420Sstevel@tonic-gate #include <sys/copyops.h> 433434Sesaxe #include <sys/pg.h> 440Sstevel@tonic-gate #include <sys/disp.h> 450Sstevel@tonic-gate #include <sys/debug.h> 460Sstevel@tonic-gate #include <sys/sunddi.h> 470Sstevel@tonic-gate #include <sys/x86_archext.h> 480Sstevel@tonic-gate #include <sys/privregs.h> 490Sstevel@tonic-gate #include <sys/machsystm.h> 500Sstevel@tonic-gate #include <sys/ontrap.h> 510Sstevel@tonic-gate #include <sys/bootconf.h> 5210574SSherry.Moore@Sun.COM #include <sys/boot_console.h> 533446Smrj #include <sys/kdi_machimpl.h> 540Sstevel@tonic-gate #include <sys/archsystm.h> 550Sstevel@tonic-gate #include <sys/promif.h> 56748Sdmick #include <sys/pci_cfgspace.h> 575084Sjohnlev #ifdef __xpv 585084Sjohnlev #include <sys/hypervisor.h> 5910175SStuart.Maybee@Sun.COM #else 6010175SStuart.Maybee@Sun.COM #include <sys/xpv_support.h> 615084Sjohnlev #endif 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * some globals for patching the result of cpuid 650Sstevel@tonic-gate * to solve problems w/ creative cpu vendors 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate 680Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include; 690Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude; 700Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include; 710Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 74783Sdmick * Dummy spl priority masks 75783Sdmick */ 763446Smrj static unsigned char dummy_cpu_pri[MAXIPL + 1] = { 77783Sdmick 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 78783Sdmick 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf 79783Sdmick }; 80783Sdmick 8110574SSherry.Moore@Sun.COM /* 8210574SSherry.Moore@Sun.COM * Set console mode 8310574SSherry.Moore@Sun.COM */ 8410574SSherry.Moore@Sun.COM static void 8510574SSherry.Moore@Sun.COM set_console_mode(uint8_t val) 8610574SSherry.Moore@Sun.COM { 8710574SSherry.Moore@Sun.COM struct bop_regs rp = {0}; 8810574SSherry.Moore@Sun.COM 8910574SSherry.Moore@Sun.COM rp.eax.byte.ah = 0x0; 9010574SSherry.Moore@Sun.COM rp.eax.byte.al = val; 9110574SSherry.Moore@Sun.COM rp.ebx.word.bx = 0x0; 9210574SSherry.Moore@Sun.COM 9310574SSherry.Moore@Sun.COM BOP_DOINT(bootops, 0x10, &rp); 9410574SSherry.Moore@Sun.COM } 9510574SSherry.Moore@Sun.COM 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 990Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate void 1020Sstevel@tonic-gate mlsetup(struct regs *rp) 1030Sstevel@tonic-gate { 1049053Sjonathan.chew@sun.com u_longlong_t prop_value; 1050Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1060Sstevel@tonic-gate extern disp_t cpu0_disp; 1070Sstevel@tonic-gate extern char t0stack[]; 10810574SSherry.Moore@Sun.COM extern int post_fastreboot; 10910574SSherry.Moore@Sun.COM extern int console; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* 1140Sstevel@tonic-gate * initialize cpu_self 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate cpu[0]->cpu_self = cpu[0]; 1170Sstevel@tonic-gate 1185084Sjohnlev #if defined(__xpv) 1195084Sjohnlev /* 1205084Sjohnlev * Point at the hypervisor's virtual cpu structure 1215084Sjohnlev */ 1225084Sjohnlev cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0]; 1235084Sjohnlev #endif 1245084Sjohnlev 1250Sstevel@tonic-gate /* 126783Sdmick * Set up dummy cpu_pri_data values till psm spl code is 127783Sdmick * installed. This allows splx() to work on amd64. 128783Sdmick */ 129783Sdmick 130783Sdmick cpu[0]->cpu_pri_data = dummy_cpu_pri; 131783Sdmick 132783Sdmick /* 1330Sstevel@tonic-gate * check if we've got special bits to clear or set 1340Sstevel@tonic-gate * when checking cpu features 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate 1379053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_ecx_include", &prop_value) != 0) 1389053Sjonathan.chew@sun.com cpuid_feature_ecx_include = 0; 1399053Sjonathan.chew@sun.com else 1409053Sjonathan.chew@sun.com cpuid_feature_ecx_include = (uint32_t)prop_value; 1419053Sjonathan.chew@sun.com 1429053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0) 1439053Sjonathan.chew@sun.com cpuid_feature_ecx_exclude = 0; 1449053Sjonathan.chew@sun.com else 1459053Sjonathan.chew@sun.com cpuid_feature_ecx_exclude = (uint32_t)prop_value; 1469053Sjonathan.chew@sun.com 1479053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0) 1489053Sjonathan.chew@sun.com cpuid_feature_edx_include = 0; 1499053Sjonathan.chew@sun.com else 1509053Sjonathan.chew@sun.com cpuid_feature_edx_include = (uint32_t)prop_value; 1519053Sjonathan.chew@sun.com 1529053Sjonathan.chew@sun.com if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0) 1539053Sjonathan.chew@sun.com cpuid_feature_edx_exclude = 0; 1549053Sjonathan.chew@sun.com else 1559053Sjonathan.chew@sun.com cpuid_feature_edx_exclude = (uint32_t)prop_value; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate /* 15810698SDan.Mick@Sun.COM * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss. 15910698SDan.Mick@Sun.COM */ 16010698SDan.Mick@Sun.COM init_desctbls(); 16110698SDan.Mick@Sun.COM 16210698SDan.Mick@Sun.COM /* 16310698SDan.Mick@Sun.COM * lgrp_init() and possibly cpuid_pass1() need PCI config 16410698SDan.Mick@Sun.COM * space access 16510698SDan.Mick@Sun.COM */ 16610698SDan.Mick@Sun.COM #if defined(__xpv) 16710698SDan.Mick@Sun.COM if (DOMAIN_IS_INITDOMAIN(xen_info)) 16810698SDan.Mick@Sun.COM pci_cfgspace_init(); 16910698SDan.Mick@Sun.COM #else 17010698SDan.Mick@Sun.COM pci_cfgspace_init(); 17110698SDan.Mick@Sun.COM #endif 17210698SDan.Mick@Sun.COM 17310698SDan.Mick@Sun.COM /* 1740Sstevel@tonic-gate * The first lightweight pass (pass0) through the cpuid data 1750Sstevel@tonic-gate * was done in locore before mlsetup was called. Do the next 1760Sstevel@tonic-gate * pass in C code. 1770Sstevel@tonic-gate * 1780Sstevel@tonic-gate * The x86_feature bits are set here on the basis of the capabilities 1790Sstevel@tonic-gate * of the boot CPU. Note that if we choose to support CPUs that have 1800Sstevel@tonic-gate * different feature sets (at which point we would almost certainly 1810Sstevel@tonic-gate * want to set the feature bits to correspond to the feature 1820Sstevel@tonic-gate * minimum) this value may be altered. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate x86_feature = cpuid_pass1(cpu[0]); 1850Sstevel@tonic-gate 1865322Ssudheer #if !defined(__xpv) 1875322Ssudheer 18810175SStuart.Maybee@Sun.COM if (get_hwenv() == HW_XEN_HVM) 18910175SStuart.Maybee@Sun.COM xen_hvm_init(); 19010175SStuart.Maybee@Sun.COM 1915322Ssudheer /* 1925322Ssudheer * Patch the tsc_read routine with appropriate set of instructions, 1935322Ssudheer * depending on the processor family and architecure, to read the 1945322Ssudheer * time-stamp counter while ensuring no out-of-order execution. 1955322Ssudheer * Patch it while the kernel text is still writable. 1965322Ssudheer * 1975322Ssudheer * Note: tsc_read is not patched for intel processors whose family 1985322Ssudheer * is >6 and for amd whose family >f (in case they don't support rdtscp 1995322Ssudheer * instruction, unlikely). By default tsc_read will use cpuid for 2005322Ssudheer * serialization in such cases. The following code needs to be 2015322Ssudheer * revisited if intel processors of family >= f retains the 2025322Ssudheer * instruction serialization nature of mfence instruction. 2035338Ssudheer * Note: tsc_read is not patched for x86 processors which do 2045338Ssudheer * not support "mfence". By default tsc_read will use cpuid for 2055338Ssudheer * serialization in such cases. 2065741Smrj * 2075741Smrj * The Xen hypervisor does not correctly report whether rdtscp is 2085741Smrj * supported or not, so we must assume that it is not. 2095322Ssudheer */ 2109000SStuart.Maybee@Sun.COM if (get_hwenv() != HW_XEN_HVM && (x86_feature & X86_TSCP)) 2115322Ssudheer patch_tsc_read(X86_HAVE_TSCP); 2125322Ssudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_AMD && 2135338Ssudheer cpuid_getfamily(CPU) <= 0xf && (x86_feature & X86_SSE2) != 0) 2145322Ssudheer patch_tsc_read(X86_TSC_MFENCE); 2155322Ssudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_Intel && 2165338Ssudheer cpuid_getfamily(CPU) <= 6 && (x86_feature & X86_SSE2) != 0) 2176642Ssudheer patch_tsc_read(X86_TSC_LFENCE); 2185322Ssudheer 2195322Ssudheer #endif /* !__xpv */ 2200Sstevel@tonic-gate 2215084Sjohnlev #if defined(__i386) && !defined(__xpv) 2220Sstevel@tonic-gate /* 2230Sstevel@tonic-gate * Some i386 processors do not implement the rdtsc instruction, 2245322Ssudheer * or at least they do not implement it correctly. Patch them to 2255322Ssudheer * return 0. 2260Sstevel@tonic-gate */ 2275322Ssudheer if ((x86_feature & X86_TSC) == 0) 2285322Ssudheer patch_tsc_read(X86_NO_TSC); 2295084Sjohnlev #endif /* __i386 && !__xpv */ 2305084Sjohnlev 2318377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv) 2328377SBill.Holler@Sun.COM patch_memops(cpuid_getvendor(CPU)); 2338377SBill.Holler@Sun.COM #endif /* __amd64 && !__xpv */ 2348377SBill.Holler@Sun.COM 2355084Sjohnlev #if !defined(__xpv) 2365084Sjohnlev /* XXPV what, if anything, should be dorked with here under xen? */ 2373446Smrj 2383446Smrj /* 2393446Smrj * While we're thinking about the TSC, let's set up %cr4 so that 2403446Smrj * userland can issue rdtsc, and initialize the TSC_AUX value 2413446Smrj * (the cpuid) for the rdtscp instruction on appropriately 2423446Smrj * capable hardware. 2433446Smrj */ 2443446Smrj if (x86_feature & X86_TSC) 2453446Smrj setcr4(getcr4() & ~CR4_TSD); 2463446Smrj 2473446Smrj if (x86_feature & X86_TSCP) 2483446Smrj (void) wrmsr(MSR_AMD_TSCAUX, 0); 2493446Smrj 2503446Smrj if (x86_feature & X86_DE) 2513446Smrj setcr4(getcr4() | CR4_DE); 2525084Sjohnlev #endif /* __xpv */ 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate /* 2550Sstevel@tonic-gate * initialize t0 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - MINFRAME; 2580Sstevel@tonic-gate t0.t_stkbase = t0stack; 2590Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 2600Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 2610Sstevel@tonic-gate t0.t_procp = &p0; 2620Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 2630Sstevel@tonic-gate t0.t_lwp = &lwp0; 2640Sstevel@tonic-gate t0.t_forw = &t0; 2650Sstevel@tonic-gate t0.t_back = &t0; 2660Sstevel@tonic-gate t0.t_next = &t0; 2670Sstevel@tonic-gate t0.t_prev = &t0; 2680Sstevel@tonic-gate t0.t_cpu = cpu[0]; 2690Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 2700Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 2710Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 2726298Sakolb t0.t_bindflag = (uchar_t)default_binding_mode; 2730Sstevel@tonic-gate t0.t_cpupart = &cp_default; 2740Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 2750Sstevel@tonic-gate t0.t_copyops = NULL; 2760Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate lwp0.lwp_thread = &t0; 2793446Smrj lwp0.lwp_regs = (void *)rp; 2800Sstevel@tonic-gate lwp0.lwp_procp = &p0; 2810Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 2820Sstevel@tonic-gate 2830Sstevel@tonic-gate p0.p_exec = NULL; 2840Sstevel@tonic-gate p0.p_stat = SRUN; 2850Sstevel@tonic-gate p0.p_flag = SSYS; 2860Sstevel@tonic-gate p0.p_tlist = &t0; 2870Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 2880Sstevel@tonic-gate p0.p_stkpageszc = 0; 2890Sstevel@tonic-gate p0.p_as = &kas; 2900Sstevel@tonic-gate p0.p_lockp = &p0lock; 2910Sstevel@tonic-gate p0.p_brkpageszc = 0; 2924426Saguzovsk p0.p_t1_lgrpid = LGRP_NONE; 2934426Saguzovsk p0.p_tr_lgrpid = LGRP_NONE; 2940Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate CPU->cpu_thread = &t0; 2970Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 2980Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 2990Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 3000Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 3010Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 3020Sstevel@tonic-gate CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE; 3030Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate CPU->cpu_id = 0; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate CPU->cpu_pri = 12; /* initial PIL for the boot CPU */ 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* 3101217Srab * The kernel doesn't use LDTs unless a process explicitly requests one. 3110Sstevel@tonic-gate */ 3125084Sjohnlev p0.p_ldt_desc = null_sdesc; 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate /* 3153446Smrj * Initialize thread/cpu microstate accounting 3160Sstevel@tonic-gate */ 3170Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 3180Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /* 3210Sstevel@tonic-gate * Initialize lists of available and active CPUs. 3220Sstevel@tonic-gate */ 3230Sstevel@tonic-gate cpu_list_init(CPU); 3240Sstevel@tonic-gate 3258906SEric.Saxe@Sun.COM pg_cpu_bootstrap(CPU); 3268906SEric.Saxe@Sun.COM 3273446Smrj /* 3283446Smrj * Now that we have taken over the GDT, IDT and have initialized 3293446Smrj * active CPU list it's time to inform kmdb if present. 3303446Smrj */ 3313446Smrj if (boothowto & RB_DEBUG) 3323446Smrj kdi_idt_sync(); 3333446Smrj 3343446Smrj /* 33510574SSherry.Moore@Sun.COM * Explicitly set console to text mode (0x3) if this is a boot 33610574SSherry.Moore@Sun.COM * post Fast Reboot, and the console is set to CONS_SCREEN_TEXT. 33710574SSherry.Moore@Sun.COM */ 33810574SSherry.Moore@Sun.COM if (post_fastreboot && console == CONS_SCREEN_TEXT) 33910574SSherry.Moore@Sun.COM set_console_mode(0x3); 34010574SSherry.Moore@Sun.COM 34110574SSherry.Moore@Sun.COM /* 3423446Smrj * If requested (boot -d) drop into kmdb. 3433446Smrj * 3443446Smrj * This must be done after cpu_list_init() on the 64-bit kernel 3453446Smrj * since taking a trap requires that we re-compute gsbase based 3463446Smrj * on the cpu list. 3473446Smrj */ 3483446Smrj if (boothowto & RB_DEBUGENTER) 3493446Smrj kmdb_enter(); 3503446Smrj 351414Skchow cpu_vm_data_init(CPU); 352414Skchow 3530Sstevel@tonic-gate rp->r_fp = 0; /* terminate kernel stack traces! */ 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate prom_init("kernel", (void *)NULL); 3560Sstevel@tonic-gate 3579053Sjonathan.chew@sun.com if (bootprop_getval("boot-ncpus", &prop_value) != 0) 3583446Smrj boot_ncpus = NCPU; 3599053Sjonathan.chew@sun.com else { 3609053Sjonathan.chew@sun.com boot_ncpus = (int)prop_value; 3619053Sjonathan.chew@sun.com if (boot_ncpus <= 0 || boot_ncpus > NCPU) 3629053Sjonathan.chew@sun.com boot_ncpus = NCPU; 3639053Sjonathan.chew@sun.com } 3642006Sandrei 3652006Sandrei max_ncpus = boot_max_ncpus = boot_ncpus; 3662006Sandrei 3676445Sjjc /* 3686445Sjjc * Initialize the lgrp framework 3696445Sjjc */ 370*10710Sjonathan.chew@sun.com lgrp_init(LGRP_INIT_STAGE1); 3716445Sjjc 3720Sstevel@tonic-gate if (boothowto & RB_HALT) { 3730Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 3740Sstevel@tonic-gate prom_enter_mon(); 3750Sstevel@tonic-gate } 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 3780Sstevel@tonic-gate 3794581Ssherrym /* 3804581Ssherrym * Fill out cpu_ucode_info. Update microcode if necessary. 3814581Ssherrym */ 3824581Ssherrym ucode_check(CPU); 3834581Ssherrym 3840Sstevel@tonic-gate if (workaround_errata(CPU) != 0) 3850Sstevel@tonic-gate panic("critical workaround(s) missing for boot cpu"); 3860Sstevel@tonic-gate } 3875648Ssetje 3885648Ssetje 3895648Ssetje void 3905648Ssetje mach_modpath(char *path, const char *filename) 3915648Ssetje { 3925648Ssetje /* 3935648Ssetje * Construct the directory path from the filename. 3945648Ssetje */ 3955648Ssetje 3965648Ssetje int len; 3975648Ssetje char *p; 3985648Ssetje const char isastr[] = "/amd64"; 3995648Ssetje size_t isalen = strlen(isastr); 4005648Ssetje 4015648Ssetje if ((p = strrchr(filename, '/')) == NULL) 4025648Ssetje return; 4035648Ssetje 4045648Ssetje while (p > filename && *(p - 1) == '/') 4055648Ssetje p--; /* remove trailing '/' characters */ 4065648Ssetje if (p == filename) 4075648Ssetje p++; /* so "/" -is- the modpath in this case */ 4085648Ssetje 4095648Ssetje /* 4105648Ssetje * Remove optional isa-dependent directory name - the module 4115648Ssetje * subsystem will put this back again (!) 4125648Ssetje */ 4135648Ssetje len = p - filename; 4145648Ssetje if (len > isalen && 4155648Ssetje strncmp(&filename[len - isalen], isastr, isalen) == 0) 4165648Ssetje p -= isalen; 4175648Ssetje 4185648Ssetje /* 4195648Ssetje * "/platform/mumblefrotz" + " " + MOD_DEFPATH 4205648Ssetje */ 4215648Ssetje len += (p - filename) + 1 + strlen(MOD_DEFPATH) + 1; 4225648Ssetje (void) strncpy(path, filename, p - filename); 4235648Ssetje } 424