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 51253Slq150181 * Common Development and Distribution License (the "License"). 61253Slq150181 * 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 */ 211253Slq150181 220Sstevel@tonic-gate /* 239160SSherry.Moore@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <sys/types.h> 280Sstevel@tonic-gate #include <sys/t_lock.h> 290Sstevel@tonic-gate #include <sys/param.h> 303939Ssethg #include <sys/segments.h> 310Sstevel@tonic-gate #include <sys/sysmacros.h> 320Sstevel@tonic-gate #include <sys/signal.h> 330Sstevel@tonic-gate #include <sys/systm.h> 340Sstevel@tonic-gate #include <sys/user.h> 350Sstevel@tonic-gate #include <sys/mman.h> 360Sstevel@tonic-gate #include <sys/vm.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <sys/disp.h> 390Sstevel@tonic-gate #include <sys/class.h> 400Sstevel@tonic-gate 410Sstevel@tonic-gate #include <sys/proc.h> 420Sstevel@tonic-gate #include <sys/buf.h> 430Sstevel@tonic-gate #include <sys/kmem.h> 440Sstevel@tonic-gate 450Sstevel@tonic-gate #include <sys/reboot.h> 460Sstevel@tonic-gate #include <sys/uadmin.h> 470Sstevel@tonic-gate #include <sys/callb.h> 480Sstevel@tonic-gate 490Sstevel@tonic-gate #include <sys/cred.h> 500Sstevel@tonic-gate #include <sys/vnode.h> 510Sstevel@tonic-gate #include <sys/file.h> 520Sstevel@tonic-gate 530Sstevel@tonic-gate #include <sys/procfs.h> 540Sstevel@tonic-gate #include <sys/acct.h> 550Sstevel@tonic-gate 560Sstevel@tonic-gate #include <sys/vfs.h> 570Sstevel@tonic-gate #include <sys/dnlc.h> 580Sstevel@tonic-gate #include <sys/var.h> 590Sstevel@tonic-gate #include <sys/cmn_err.h> 600Sstevel@tonic-gate #include <sys/utsname.h> 610Sstevel@tonic-gate #include <sys/debug.h> 620Sstevel@tonic-gate 630Sstevel@tonic-gate #include <sys/dumphdr.h> 640Sstevel@tonic-gate #include <sys/bootconf.h> 650Sstevel@tonic-gate #include <sys/varargs.h> 660Sstevel@tonic-gate #include <sys/promif.h> 670Sstevel@tonic-gate #include <sys/modctl.h> 680Sstevel@tonic-gate 690Sstevel@tonic-gate #include <sys/consdev.h> 700Sstevel@tonic-gate #include <sys/frame.h> 710Sstevel@tonic-gate 720Sstevel@tonic-gate #include <sys/sunddi.h> 730Sstevel@tonic-gate #include <sys/ddidmareq.h> 740Sstevel@tonic-gate #include <sys/psw.h> 750Sstevel@tonic-gate #include <sys/regset.h> 760Sstevel@tonic-gate #include <sys/privregs.h> 770Sstevel@tonic-gate #include <sys/clock.h> 780Sstevel@tonic-gate #include <sys/tss.h> 790Sstevel@tonic-gate #include <sys/cpu.h> 800Sstevel@tonic-gate #include <sys/stack.h> 810Sstevel@tonic-gate #include <sys/trap.h> 820Sstevel@tonic-gate #include <sys/pic.h> 830Sstevel@tonic-gate #include <vm/hat.h> 840Sstevel@tonic-gate #include <vm/anon.h> 850Sstevel@tonic-gate #include <vm/as.h> 860Sstevel@tonic-gate #include <vm/page.h> 870Sstevel@tonic-gate #include <vm/seg.h> 880Sstevel@tonic-gate #include <vm/seg_kmem.h> 890Sstevel@tonic-gate #include <vm/seg_map.h> 900Sstevel@tonic-gate #include <vm/seg_vn.h> 910Sstevel@tonic-gate #include <vm/seg_kp.h> 920Sstevel@tonic-gate #include <vm/hat_i86.h> 930Sstevel@tonic-gate #include <sys/swap.h> 940Sstevel@tonic-gate #include <sys/thread.h> 950Sstevel@tonic-gate #include <sys/sysconf.h> 960Sstevel@tonic-gate #include <sys/vm_machparam.h> 970Sstevel@tonic-gate #include <sys/archsystm.h> 980Sstevel@tonic-gate #include <sys/machsystm.h> 990Sstevel@tonic-gate #include <sys/machlock.h> 1000Sstevel@tonic-gate #include <sys/x_call.h> 1010Sstevel@tonic-gate #include <sys/instance.h> 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate #include <sys/time.h> 1040Sstevel@tonic-gate #include <sys/smp_impldefs.h> 1050Sstevel@tonic-gate #include <sys/psm_types.h> 1060Sstevel@tonic-gate #include <sys/atomic.h> 1070Sstevel@tonic-gate #include <sys/panic.h> 1080Sstevel@tonic-gate #include <sys/cpuvar.h> 1090Sstevel@tonic-gate #include <sys/dtrace.h> 1100Sstevel@tonic-gate #include <sys/bl.h> 1110Sstevel@tonic-gate #include <sys/nvpair.h> 1120Sstevel@tonic-gate #include <sys/x86_archext.h> 1130Sstevel@tonic-gate #include <sys/pool_pset.h> 1140Sstevel@tonic-gate #include <sys/autoconf.h> 1153446Smrj #include <sys/mem.h> 1163446Smrj #include <sys/dumphdr.h> 1173446Smrj #include <sys/compress.h> 1187532SSean.Ye@Sun.COM #include <sys/cpu_module.h> 1195084Sjohnlev #if defined(__xpv) 1205084Sjohnlev #include <sys/hypervisor.h> 1215084Sjohnlev #include <sys/xpv_panic.h> 1225084Sjohnlev #endif 1230Sstevel@tonic-gate 1247656SSherry.Moore@Sun.COM #include <sys/fastboot.h> 1257656SSherry.Moore@Sun.COM #include <sys/machelf.h> 1267656SSherry.Moore@Sun.COM #include <sys/kobj.h> 1277656SSherry.Moore@Sun.COM #include <sys/multiboot.h> 1287656SSherry.Moore@Sun.COM 1290Sstevel@tonic-gate #ifdef TRAPTRACE 1300Sstevel@tonic-gate #include <sys/traptrace.h> 1310Sstevel@tonic-gate #endif /* TRAPTRACE */ 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate extern void audit_enterprom(int); 1340Sstevel@tonic-gate extern void audit_exitprom(int); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1376681Sjohnlev * Occassionally the kernel knows better whether to power-off or reboot. 1386681Sjohnlev */ 1396681Sjohnlev int force_shutdown_method = AD_UNKNOWN; 1406681Sjohnlev 1416681Sjohnlev /* 1420Sstevel@tonic-gate * The panicbuf array is used to record messages and state: 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate char panicbuf[PANICBUFSIZE]; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 1470Sstevel@tonic-gate * maxphys - used during physio 1480Sstevel@tonic-gate * klustsize - used for klustering by swapfs and specfs 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate int maxphys = 56 * 1024; /* XXX See vm_subr.c - max b_count in physio */ 1510Sstevel@tonic-gate int klustsize = 56 * 1024; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate caddr_t p0_va; /* Virtual address for accessing physical page 0 */ 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * defined here, though unused on x86, 1570Sstevel@tonic-gate * to make kstat_fr.c happy. 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate int vac; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate void debug_enter(char *); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate extern void pm_cfb_check_and_powerup(void); 1640Sstevel@tonic-gate extern void pm_cfb_rele(void); 1650Sstevel@tonic-gate 1667656SSherry.Moore@Sun.COM extern fastboot_info_t newkernel; 1677656SSherry.Moore@Sun.COM 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * Machine dependent code to reboot. 1700Sstevel@tonic-gate * "mdep" is interpreted as a character pointer; if non-null, it is a pointer 1710Sstevel@tonic-gate * to a string to be used as the argument string when rebooting. 172136Sachartre * 173136Sachartre * "invoke_cb" is a boolean. It is set to true when mdboot() can safely 174136Sachartre * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when 175136Sachartre * we are in a normal shutdown sequence (interrupts are not blocked, the 176136Sachartre * system is not panic'ing or being suspended). 1770Sstevel@tonic-gate */ 1780Sstevel@tonic-gate /*ARGSUSED*/ 1790Sstevel@tonic-gate void 180136Sachartre mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb) 1810Sstevel@tonic-gate { 1827656SSherry.Moore@Sun.COM processorid_t bootcpuid = 0; 1837863SSherry.Moore@Sun.COM static int is_first_quiesce = 1; 1847863SSherry.Moore@Sun.COM static int is_first_reset = 1; 1857863SSherry.Moore@Sun.COM int reset_status = 0; 1869160SSherry.Moore@Sun.COM static char fallback_str[] = "Falling back to regular reboot.\n"; 1877656SSherry.Moore@Sun.COM 1887656SSherry.Moore@Sun.COM if (fcn == AD_FASTREBOOT && !newkernel.fi_valid) 1897656SSherry.Moore@Sun.COM fcn = AD_BOOT; 1907656SSherry.Moore@Sun.COM 1910Sstevel@tonic-gate if (!panicstr) { 1920Sstevel@tonic-gate kpreempt_disable(); 1937656SSherry.Moore@Sun.COM if (fcn == AD_FASTREBOOT) { 1947656SSherry.Moore@Sun.COM mutex_enter(&cpu_lock); 1957656SSherry.Moore@Sun.COM if (CPU_ACTIVE(cpu_get(bootcpuid))) { 1967656SSherry.Moore@Sun.COM affinity_set(bootcpuid); 1977656SSherry.Moore@Sun.COM } 1987656SSherry.Moore@Sun.COM mutex_exit(&cpu_lock); 1997656SSherry.Moore@Sun.COM } else { 2007656SSherry.Moore@Sun.COM affinity_set(CPU_CURRENT); 2017656SSherry.Moore@Sun.COM } 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate 2046681Sjohnlev if (force_shutdown_method != AD_UNKNOWN) 2056681Sjohnlev fcn = force_shutdown_method; 2066681Sjohnlev 2070Sstevel@tonic-gate /* 2085630Sjbeck * XXX - rconsvp is set to NULL to ensure that output messages 2095630Sjbeck * are sent to the underlying "hardware" device using the 2105630Sjbeck * monitor's printf routine since we are in the process of 2115630Sjbeck * either rebooting or halting the machine. 2125630Sjbeck */ 2135630Sjbeck rconsvp = NULL; 2145630Sjbeck 2155630Sjbeck /* 2160Sstevel@tonic-gate * Print the reboot message now, before pausing other cpus. 2170Sstevel@tonic-gate * There is a race condition in the printing support that 2180Sstevel@tonic-gate * can deadlock multiprocessor machines. 2190Sstevel@tonic-gate */ 2200Sstevel@tonic-gate if (!(fcn == AD_HALT || fcn == AD_POWEROFF)) 2210Sstevel@tonic-gate prom_printf("rebooting...\n"); 2220Sstevel@tonic-gate 2235084Sjohnlev if (IN_XPV_PANIC()) 2245084Sjohnlev reset(); 2255084Sjohnlev 2260Sstevel@tonic-gate /* 2270Sstevel@tonic-gate * We can't bring up the console from above lock level, so do it now 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate pm_cfb_check_and_powerup(); 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate /* make sure there are no more changes to the device tree */ 2320Sstevel@tonic-gate devtree_freeze(); 2330Sstevel@tonic-gate 234136Sachartre if (invoke_cb) 235136Sachartre (void) callb_execute_class(CB_CL_MDBOOT, NULL); 236136Sachartre 2373253Smec /* 2383253Smec * Clear any unresolved UEs from memory. 2393253Smec */ 2403253Smec page_retire_mdboot(); 241917Selowe 2425084Sjohnlev #if defined(__xpv) 2435084Sjohnlev /* 2445084Sjohnlev * XXPV Should probably think some more about how we deal 2455084Sjohnlev * with panicing before it's really safe to panic. 2465084Sjohnlev * On hypervisors, we reboot very quickly.. Perhaps panic 2475084Sjohnlev * should only attempt to recover by rebooting if, 2485084Sjohnlev * say, we were able to mount the root filesystem, 2495084Sjohnlev * or if we successfully launched init(1m). 2505084Sjohnlev */ 2515084Sjohnlev if (panicstr && proc_init == NULL) 2525084Sjohnlev (void) HYPERVISOR_shutdown(SHUTDOWN_poweroff); 2535084Sjohnlev #endif 2540Sstevel@tonic-gate /* 2550Sstevel@tonic-gate * stop other cpus and raise our priority. since there is only 2560Sstevel@tonic-gate * one active cpu after this, and our priority will be too high 2570Sstevel@tonic-gate * for us to be preempted, we're essentially single threaded 2580Sstevel@tonic-gate * from here on out. 2590Sstevel@tonic-gate */ 2600Sstevel@tonic-gate (void) spl6(); 2610Sstevel@tonic-gate if (!panicstr) { 2620Sstevel@tonic-gate mutex_enter(&cpu_lock); 2630Sstevel@tonic-gate pause_cpus(NULL); 2640Sstevel@tonic-gate mutex_exit(&cpu_lock); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate /* 2689160SSherry.Moore@Sun.COM * If the system is panicking, the preloaded kernel is valid, 2699160SSherry.Moore@Sun.COM * and fastreboot_onpanic has been set, choose Fast Reboot. 2709160SSherry.Moore@Sun.COM */ 2719160SSherry.Moore@Sun.COM if (fcn == AD_BOOT && panicstr && newkernel.fi_valid && 2729160SSherry.Moore@Sun.COM fastreboot_onpanic) 2739160SSherry.Moore@Sun.COM fcn = AD_FASTREBOOT; 2749160SSherry.Moore@Sun.COM 2759160SSherry.Moore@Sun.COM /* 2767656SSherry.Moore@Sun.COM * Try to quiesce devices. 2770Sstevel@tonic-gate */ 2787863SSherry.Moore@Sun.COM if (is_first_quiesce) { 2797863SSherry.Moore@Sun.COM /* 2807863SSherry.Moore@Sun.COM * Clear is_first_quiesce before calling quiesce_devices() 2817863SSherry.Moore@Sun.COM * so that if quiesce_devices() causes panics, it will not 2827863SSherry.Moore@Sun.COM * be invoked again. 2837863SSherry.Moore@Sun.COM */ 2847863SSherry.Moore@Sun.COM is_first_quiesce = 0; 2857656SSherry.Moore@Sun.COM 2867656SSherry.Moore@Sun.COM quiesce_active = 1; 2877656SSherry.Moore@Sun.COM quiesce_devices(ddi_root_node(), &reset_status); 2887783SSherry.Moore@Sun.COM if (reset_status == -1) { 2897783SSherry.Moore@Sun.COM if (fcn == AD_FASTREBOOT && !force_fastreboot) { 2907783SSherry.Moore@Sun.COM prom_printf("Driver(s) not capable of fast " 2919160SSherry.Moore@Sun.COM "reboot.\n"); 2929160SSherry.Moore@Sun.COM prom_printf(fallback_str); 2937783SSherry.Moore@Sun.COM fastreboot_capable = 0; 2949160SSherry.Moore@Sun.COM fcn = AD_BOOT; 2957783SSherry.Moore@Sun.COM } else if (fcn != AD_FASTREBOOT) 2967783SSherry.Moore@Sun.COM fastreboot_capable = 0; 2977656SSherry.Moore@Sun.COM } 2987656SSherry.Moore@Sun.COM quiesce_active = 0; 2997656SSherry.Moore@Sun.COM } 3007656SSherry.Moore@Sun.COM 3017656SSherry.Moore@Sun.COM /* 3027863SSherry.Moore@Sun.COM * Try to reset devices. reset_leaves() should only be called 3037863SSherry.Moore@Sun.COM * a) when there are no other threads that could be accessing devices, 3047863SSherry.Moore@Sun.COM * and 3057863SSherry.Moore@Sun.COM * b) on a system that's not capable of fast reboot (fastreboot_capable 3067863SSherry.Moore@Sun.COM * being 0), or on a system where quiesce_devices() failed to 3077863SSherry.Moore@Sun.COM * complete (quiesce_active being 1). 3087656SSherry.Moore@Sun.COM */ 3097863SSherry.Moore@Sun.COM if (is_first_reset && (!fastreboot_capable || quiesce_active)) { 3107863SSherry.Moore@Sun.COM /* 3117863SSherry.Moore@Sun.COM * Clear is_first_reset before calling reset_devices() 3127863SSherry.Moore@Sun.COM * so that if reset_devices() causes panics, it will not 3137863SSherry.Moore@Sun.COM * be invoked again. 3147863SSherry.Moore@Sun.COM */ 3157863SSherry.Moore@Sun.COM is_first_reset = 0; 3167656SSherry.Moore@Sun.COM reset_leaves(); 3177863SSherry.Moore@Sun.COM } 3180Sstevel@tonic-gate 3199160SSherry.Moore@Sun.COM /* Verify newkernel checksum */ 3209160SSherry.Moore@Sun.COM if (fastreboot_capable && fcn == AD_FASTREBOOT && 3219160SSherry.Moore@Sun.COM fastboot_cksum_verify(&newkernel) != 0) { 3229160SSherry.Moore@Sun.COM fastreboot_capable = 0; 3239160SSherry.Moore@Sun.COM prom_printf("Fast reboot: checksum failed for the new " 3249160SSherry.Moore@Sun.COM "kernel.\n"); 3259160SSherry.Moore@Sun.COM prom_printf(fallback_str); 3269160SSherry.Moore@Sun.COM } 3279160SSherry.Moore@Sun.COM 3280Sstevel@tonic-gate (void) spl8(); 3290Sstevel@tonic-gate 3309160SSherry.Moore@Sun.COM if (fastreboot_capable && fcn == AD_FASTREBOOT) { 3319160SSherry.Moore@Sun.COM /* 3329160SSherry.Moore@Sun.COM * psm_shutdown is called within fast_reboot() 3339160SSherry.Moore@Sun.COM */ 3347656SSherry.Moore@Sun.COM fast_reboot(); 3359160SSherry.Moore@Sun.COM } else { 3369160SSherry.Moore@Sun.COM (*psm_shutdownf)(cmd, fcn); 3379160SSherry.Moore@Sun.COM 3389160SSherry.Moore@Sun.COM if (fcn == AD_HALT || fcn == AD_POWEROFF) 3399160SSherry.Moore@Sun.COM halt((char *)NULL); 3409160SSherry.Moore@Sun.COM else 3419160SSherry.Moore@Sun.COM prom_reboot(""); 3429160SSherry.Moore@Sun.COM } 3430Sstevel@tonic-gate /*NOTREACHED*/ 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* mdpreboot - may be called prior to mdboot while root fs still mounted */ 3470Sstevel@tonic-gate /*ARGSUSED*/ 3480Sstevel@tonic-gate void 3490Sstevel@tonic-gate mdpreboot(int cmd, int fcn, char *mdep) 3500Sstevel@tonic-gate { 3517656SSherry.Moore@Sun.COM if (fcn == AD_FASTREBOOT && !fastreboot_capable) { 3527656SSherry.Moore@Sun.COM fcn = AD_BOOT; 3537656SSherry.Moore@Sun.COM #ifdef __xpv 3549160SSherry.Moore@Sun.COM cmn_err(CE_WARN, "Fast reboot is not supported on xVM"); 3557656SSherry.Moore@Sun.COM #else 3569160SSherry.Moore@Sun.COM cmn_err(CE_WARN, 3579160SSherry.Moore@Sun.COM "Fast reboot is not supported on this platform"); 3587656SSherry.Moore@Sun.COM #endif 3597656SSherry.Moore@Sun.COM } 3607656SSherry.Moore@Sun.COM 3617656SSherry.Moore@Sun.COM if (fcn == AD_FASTREBOOT) { 3629160SSherry.Moore@Sun.COM fastboot_load_kernel(mdep); 3637656SSherry.Moore@Sun.COM if (!newkernel.fi_valid) 3647656SSherry.Moore@Sun.COM fcn = AD_BOOT; 3657656SSherry.Moore@Sun.COM } 3667656SSherry.Moore@Sun.COM 3670Sstevel@tonic-gate (*psm_preshutdownf)(cmd, fcn); 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 370*9489SJoe.Bonasera@sun.com static void 371*9489SJoe.Bonasera@sun.com stop_other_cpus(void) 3720Sstevel@tonic-gate { 373*9489SJoe.Bonasera@sun.com ulong_t s = clear_int_flag(); /* fast way to keep CPU from changing */ 3740Sstevel@tonic-gate cpuset_t xcset; 3750Sstevel@tonic-gate 376*9489SJoe.Bonasera@sun.com CPUSET_ALL_BUT(xcset, CPU->cpu_id); 377*9489SJoe.Bonasera@sun.com xc_priority(0, 0, 0, CPUSET2BV(xcset), (xc_func_t)mach_cpu_halt); 378*9489SJoe.Bonasera@sun.com restore_int_flag(s); 3790Sstevel@tonic-gate } 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate /* 3820Sstevel@tonic-gate * Machine dependent abort sequence handling 3830Sstevel@tonic-gate */ 3840Sstevel@tonic-gate void 3850Sstevel@tonic-gate abort_sequence_enter(char *msg) 3860Sstevel@tonic-gate { 3870Sstevel@tonic-gate if (abort_enable == 0) { 3880Sstevel@tonic-gate if (audit_active) 3890Sstevel@tonic-gate audit_enterprom(0); 3900Sstevel@tonic-gate return; 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate if (audit_active) 3930Sstevel@tonic-gate audit_enterprom(1); 3940Sstevel@tonic-gate debug_enter(msg); 3950Sstevel@tonic-gate if (audit_active) 3960Sstevel@tonic-gate audit_exitprom(1); 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * Enter debugger. Called when the user types ctrl-alt-d or whenever 4010Sstevel@tonic-gate * code wants to enter the debugger and possibly resume later. 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate void 4040Sstevel@tonic-gate debug_enter( 4050Sstevel@tonic-gate char *msg) /* message to print, possibly NULL */ 4060Sstevel@tonic-gate { 4070Sstevel@tonic-gate if (dtrace_debugger_init != NULL) 4080Sstevel@tonic-gate (*dtrace_debugger_init)(); 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate if (msg) 4110Sstevel@tonic-gate prom_printf("%s\n", msg); 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate if (boothowto & RB_DEBUG) 4143446Smrj kmdb_enter(); 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate if (dtrace_debugger_fini != NULL) 4170Sstevel@tonic-gate (*dtrace_debugger_fini)(); 4180Sstevel@tonic-gate } 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate void 4210Sstevel@tonic-gate reset(void) 4220Sstevel@tonic-gate { 4235084Sjohnlev #if !defined(__xpv) 4240Sstevel@tonic-gate ushort_t *bios_memchk; 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate /* 4270Sstevel@tonic-gate * Can't use psm_map_phys before the hat is initialized. 4280Sstevel@tonic-gate */ 4290Sstevel@tonic-gate if (khat_running) { 4300Sstevel@tonic-gate bios_memchk = (ushort_t *)psm_map_phys(0x472, 4310Sstevel@tonic-gate sizeof (ushort_t), PROT_READ | PROT_WRITE); 4320Sstevel@tonic-gate if (bios_memchk) 4330Sstevel@tonic-gate *bios_memchk = 0x1234; /* bios memory check disable */ 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4362866Sszhou if (ddi_prop_exists(DDI_DEV_T_ANY, ddi_root_node(), 0, "efi-systab")) 4372866Sszhou efi_reset(); 4380Sstevel@tonic-gate pc_reset(); 4395084Sjohnlev #else 4405084Sjohnlev if (IN_XPV_PANIC()) 4415084Sjohnlev pc_reset(); 4425084Sjohnlev (void) HYPERVISOR_shutdown(SHUTDOWN_reboot); 4435084Sjohnlev panic("HYPERVISOR_shutdown() failed"); 4445084Sjohnlev #endif 4450Sstevel@tonic-gate /*NOTREACHED*/ 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate /* 4490Sstevel@tonic-gate * Halt the machine and return to the monitor 4500Sstevel@tonic-gate */ 4510Sstevel@tonic-gate void 4520Sstevel@tonic-gate halt(char *s) 4530Sstevel@tonic-gate { 4540Sstevel@tonic-gate stop_other_cpus(); /* send stop signal to other CPUs */ 4550Sstevel@tonic-gate if (s) 4560Sstevel@tonic-gate prom_printf("(%s) \n", s); 4570Sstevel@tonic-gate prom_exit_to_mon(); 4580Sstevel@tonic-gate /*NOTREACHED*/ 4590Sstevel@tonic-gate } 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate /* 4620Sstevel@tonic-gate * Initiate interrupt redistribution. 4630Sstevel@tonic-gate */ 4640Sstevel@tonic-gate void 4650Sstevel@tonic-gate i_ddi_intr_redist_all_cpus() 4660Sstevel@tonic-gate { 4670Sstevel@tonic-gate } 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate /* 4700Sstevel@tonic-gate * XXX These probably ought to live somewhere else 4710Sstevel@tonic-gate * XXX They are called from mem.c 4720Sstevel@tonic-gate */ 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate /* 4750Sstevel@tonic-gate * Convert page frame number to an OBMEM page frame number 4760Sstevel@tonic-gate * (i.e. put in the type bits -- zero for this implementation) 4770Sstevel@tonic-gate */ 4780Sstevel@tonic-gate pfn_t 4790Sstevel@tonic-gate impl_obmem_pfnum(pfn_t pf) 4800Sstevel@tonic-gate { 4810Sstevel@tonic-gate return (pf); 4820Sstevel@tonic-gate } 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate #ifdef NM_DEBUG 4850Sstevel@tonic-gate int nmi_test = 0; /* checked in intentry.s during clock int */ 4860Sstevel@tonic-gate int nmtest = -1; 4870Sstevel@tonic-gate nmfunc1(arg, rp) 4880Sstevel@tonic-gate int arg; 4890Sstevel@tonic-gate struct regs *rp; 4900Sstevel@tonic-gate { 4910Sstevel@tonic-gate printf("nmi called with arg = %x, regs = %x\n", arg, rp); 4920Sstevel@tonic-gate nmtest += 50; 4930Sstevel@tonic-gate if (arg == nmtest) { 4940Sstevel@tonic-gate printf("ip = %x\n", rp->r_pc); 4950Sstevel@tonic-gate return (1); 4960Sstevel@tonic-gate } 4970Sstevel@tonic-gate return (0); 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate #endif 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate #include <sys/bootsvcs.h> 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate /* Hacked up initialization for initial kernel check out is HERE. */ 5050Sstevel@tonic-gate /* The basic steps are: */ 5060Sstevel@tonic-gate /* kernel bootfuncs definition/initialization for KADB */ 5070Sstevel@tonic-gate /* kadb bootfuncs pointer initialization */ 5080Sstevel@tonic-gate /* putchar/getchar (interrupts disabled) */ 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate /* kadb bootfuncs pointer initialization */ 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate int 5130Sstevel@tonic-gate sysp_getchar() 5140Sstevel@tonic-gate { 5150Sstevel@tonic-gate int i; 5163446Smrj ulong_t s; 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate if (cons_polledio == NULL) { 5190Sstevel@tonic-gate /* Uh oh */ 5200Sstevel@tonic-gate prom_printf("getchar called with no console\n"); 5210Sstevel@tonic-gate for (;;) 5220Sstevel@tonic-gate /* LOOP FOREVER */; 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate s = clear_int_flag(); 5260Sstevel@tonic-gate i = cons_polledio->cons_polledio_getchar( 5275084Sjohnlev cons_polledio->cons_polledio_argument); 5280Sstevel@tonic-gate restore_int_flag(s); 5290Sstevel@tonic-gate return (i); 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate void 5330Sstevel@tonic-gate sysp_putchar(int c) 5340Sstevel@tonic-gate { 5353446Smrj ulong_t s; 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate /* 5380Sstevel@tonic-gate * We have no alternative but to drop the output on the floor. 5390Sstevel@tonic-gate */ 5401253Slq150181 if (cons_polledio == NULL || 5411253Slq150181 cons_polledio->cons_polledio_putchar == NULL) 5420Sstevel@tonic-gate return; 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate s = clear_int_flag(); 5450Sstevel@tonic-gate cons_polledio->cons_polledio_putchar( 5465084Sjohnlev cons_polledio->cons_polledio_argument, c); 5470Sstevel@tonic-gate restore_int_flag(s); 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate int 5510Sstevel@tonic-gate sysp_ischar() 5520Sstevel@tonic-gate { 5530Sstevel@tonic-gate int i; 5543446Smrj ulong_t s; 5550Sstevel@tonic-gate 5561253Slq150181 if (cons_polledio == NULL || 5571253Slq150181 cons_polledio->cons_polledio_ischar == NULL) 5580Sstevel@tonic-gate return (0); 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate s = clear_int_flag(); 5610Sstevel@tonic-gate i = cons_polledio->cons_polledio_ischar( 5625084Sjohnlev cons_polledio->cons_polledio_argument); 5630Sstevel@tonic-gate restore_int_flag(s); 5640Sstevel@tonic-gate return (i); 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate int 5680Sstevel@tonic-gate goany(void) 5690Sstevel@tonic-gate { 5700Sstevel@tonic-gate prom_printf("Type any key to continue "); 5710Sstevel@tonic-gate (void) prom_getchar(); 5720Sstevel@tonic-gate prom_printf("\n"); 5730Sstevel@tonic-gate return (1); 5740Sstevel@tonic-gate } 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate static struct boot_syscalls kern_sysp = { 5770Sstevel@tonic-gate sysp_getchar, /* unchar (*getchar)(); 7 */ 5780Sstevel@tonic-gate sysp_putchar, /* int (*putchar)(); 8 */ 5790Sstevel@tonic-gate sysp_ischar, /* int (*ischar)(); 9 */ 5800Sstevel@tonic-gate }; 5810Sstevel@tonic-gate 5825084Sjohnlev #if defined(__xpv) 5835084Sjohnlev int using_kern_polledio; 5845084Sjohnlev #endif 5855084Sjohnlev 5860Sstevel@tonic-gate void 5870Sstevel@tonic-gate kadb_uses_kernel() 5880Sstevel@tonic-gate { 5890Sstevel@tonic-gate /* 5900Sstevel@tonic-gate * This routine is now totally misnamed, since it does not in fact 5910Sstevel@tonic-gate * control kadb's I/O; it only controls the kernel's prom_* I/O. 5920Sstevel@tonic-gate */ 5930Sstevel@tonic-gate sysp = &kern_sysp; 5945084Sjohnlev #if defined(__xpv) 5955084Sjohnlev using_kern_polledio = 1; 5965084Sjohnlev #endif 5970Sstevel@tonic-gate } 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate /* 6000Sstevel@tonic-gate * the interface to the outside world 6010Sstevel@tonic-gate */ 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate /* 6040Sstevel@tonic-gate * poll_port -- wait for a register to achieve a 6050Sstevel@tonic-gate * specific state. Arguments are a mask of bits we care about, 6060Sstevel@tonic-gate * and two sub-masks. To return normally, all the bits in the 6070Sstevel@tonic-gate * first sub-mask must be ON, all the bits in the second sub- 6080Sstevel@tonic-gate * mask must be OFF. If about seconds pass without the register 6090Sstevel@tonic-gate * achieving the desired bit configuration, we return 1, else 6100Sstevel@tonic-gate * 0. 6110Sstevel@tonic-gate */ 6120Sstevel@tonic-gate int 6130Sstevel@tonic-gate poll_port(ushort_t port, ushort_t mask, ushort_t onbits, ushort_t offbits) 6140Sstevel@tonic-gate { 6150Sstevel@tonic-gate int i; 6160Sstevel@tonic-gate ushort_t maskval; 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate for (i = 500000; i; i--) { 6190Sstevel@tonic-gate maskval = inb(port) & mask; 6200Sstevel@tonic-gate if (((maskval & onbits) == onbits) && 6215084Sjohnlev ((maskval & offbits) == 0)) 6220Sstevel@tonic-gate return (0); 6230Sstevel@tonic-gate drv_usecwait(10); 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate return (1); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate /* 6290Sstevel@tonic-gate * set_idle_cpu is called from idle() when a CPU becomes idle. 6300Sstevel@tonic-gate */ 6310Sstevel@tonic-gate /*LINTED: static unused */ 6320Sstevel@tonic-gate static uint_t last_idle_cpu; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /*ARGSUSED*/ 6350Sstevel@tonic-gate void 6360Sstevel@tonic-gate set_idle_cpu(int cpun) 6370Sstevel@tonic-gate { 6380Sstevel@tonic-gate last_idle_cpu = cpun; 6390Sstevel@tonic-gate (*psm_set_idle_cpuf)(cpun); 6400Sstevel@tonic-gate } 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate /* 6430Sstevel@tonic-gate * unset_idle_cpu is called from idle() when a CPU is no longer idle. 6440Sstevel@tonic-gate */ 6450Sstevel@tonic-gate /*ARGSUSED*/ 6460Sstevel@tonic-gate void 6470Sstevel@tonic-gate unset_idle_cpu(int cpun) 6480Sstevel@tonic-gate { 6490Sstevel@tonic-gate (*psm_unset_idle_cpuf)(cpun); 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate /* 6530Sstevel@tonic-gate * This routine is almost correct now, but not quite. It still needs the 6540Sstevel@tonic-gate * equivalent concept of "hres_last_tick", just like on the sparc side. 6550Sstevel@tonic-gate * The idea is to take a snapshot of the hi-res timer while doing the 6560Sstevel@tonic-gate * hrestime_adj updates under hres_lock in locore, so that the small 6570Sstevel@tonic-gate * interval between interrupt assertion and interrupt processing is 6580Sstevel@tonic-gate * accounted for correctly. Once we have this, the code below should 6590Sstevel@tonic-gate * be modified to subtract off hres_last_tick rather than hrtime_base. 6600Sstevel@tonic-gate * 6610Sstevel@tonic-gate * I'd have done this myself, but I don't have source to all of the 6620Sstevel@tonic-gate * vendor-specific hi-res timer routines (grrr...). The generic hook I 6630Sstevel@tonic-gate * need is something like "gethrtime_unlocked()", which would be just like 6640Sstevel@tonic-gate * gethrtime() but would assume that you're already holding CLOCK_LOCK(). 6650Sstevel@tonic-gate * This is what the GET_HRTIME() macro is for on sparc (although it also 6660Sstevel@tonic-gate * serves the function of making time available without a function call 6670Sstevel@tonic-gate * so you don't take a register window overflow while traps are disabled). 6680Sstevel@tonic-gate */ 6690Sstevel@tonic-gate void 6700Sstevel@tonic-gate pc_gethrestime(timestruc_t *tp) 6710Sstevel@tonic-gate { 6720Sstevel@tonic-gate int lock_prev; 6730Sstevel@tonic-gate timestruc_t now; 6740Sstevel@tonic-gate int nslt; /* nsec since last tick */ 6750Sstevel@tonic-gate int adj; /* amount of adjustment to apply */ 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate loop: 6780Sstevel@tonic-gate lock_prev = hres_lock; 6790Sstevel@tonic-gate now = hrestime; 6800Sstevel@tonic-gate nslt = (int)(gethrtime() - hres_last_tick); 6810Sstevel@tonic-gate if (nslt < 0) { 6820Sstevel@tonic-gate /* 6830Sstevel@tonic-gate * nslt < 0 means a tick came between sampling 6840Sstevel@tonic-gate * gethrtime() and hres_last_tick; restart the loop 6850Sstevel@tonic-gate */ 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate goto loop; 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate now.tv_nsec += nslt; 6900Sstevel@tonic-gate if (hrestime_adj != 0) { 6910Sstevel@tonic-gate if (hrestime_adj > 0) { 6920Sstevel@tonic-gate adj = (nslt >> ADJ_SHIFT); 6930Sstevel@tonic-gate if (adj > hrestime_adj) 6940Sstevel@tonic-gate adj = (int)hrestime_adj; 6950Sstevel@tonic-gate } else { 6960Sstevel@tonic-gate adj = -(nslt >> ADJ_SHIFT); 6970Sstevel@tonic-gate if (adj < hrestime_adj) 6980Sstevel@tonic-gate adj = (int)hrestime_adj; 6990Sstevel@tonic-gate } 7000Sstevel@tonic-gate now.tv_nsec += adj; 7010Sstevel@tonic-gate } 7020Sstevel@tonic-gate while ((unsigned long)now.tv_nsec >= NANOSEC) { 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate /* 7050Sstevel@tonic-gate * We might have a large adjustment or have been in the 7060Sstevel@tonic-gate * debugger for a long time; take care of (at most) four 7070Sstevel@tonic-gate * of those missed seconds (tv_nsec is 32 bits, so 7080Sstevel@tonic-gate * anything >4s will be wrapping around). However, 7090Sstevel@tonic-gate * anything more than 2 seconds out of sync will trigger 7100Sstevel@tonic-gate * timedelta from clock() to go correct the time anyway, 7110Sstevel@tonic-gate * so do what we can, and let the big crowbar do the 7120Sstevel@tonic-gate * rest. A similar correction while loop exists inside 7130Sstevel@tonic-gate * hres_tick(); in all cases we'd like tv_nsec to 7140Sstevel@tonic-gate * satisfy 0 <= tv_nsec < NANOSEC to avoid confusing 7150Sstevel@tonic-gate * user processes, but if tv_sec's a little behind for a 7160Sstevel@tonic-gate * little while, that's OK; time still monotonically 7170Sstevel@tonic-gate * increases. 7180Sstevel@tonic-gate */ 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate now.tv_nsec -= NANOSEC; 7210Sstevel@tonic-gate now.tv_sec++; 7220Sstevel@tonic-gate } 7230Sstevel@tonic-gate if ((hres_lock & ~1) != lock_prev) 7240Sstevel@tonic-gate goto loop; 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate *tp = now; 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate void 7300Sstevel@tonic-gate gethrestime_lasttick(timespec_t *tp) 7310Sstevel@tonic-gate { 7320Sstevel@tonic-gate int s; 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate s = hr_clock_lock(); 7350Sstevel@tonic-gate *tp = hrestime; 7360Sstevel@tonic-gate hr_clock_unlock(s); 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate time_t 7400Sstevel@tonic-gate gethrestime_sec(void) 7410Sstevel@tonic-gate { 7420Sstevel@tonic-gate timestruc_t now; 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate gethrestime(&now); 7450Sstevel@tonic-gate return (now.tv_sec); 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate /* 7490Sstevel@tonic-gate * Initialize a kernel thread's stack 7500Sstevel@tonic-gate */ 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate caddr_t 7530Sstevel@tonic-gate thread_stk_init(caddr_t stk) 7540Sstevel@tonic-gate { 7550Sstevel@tonic-gate ASSERT(((uintptr_t)stk & (STACK_ALIGN - 1)) == 0); 7560Sstevel@tonic-gate return (stk - SA(MINFRAME)); 7570Sstevel@tonic-gate } 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate /* 7600Sstevel@tonic-gate * Initialize lwp's kernel stack. 7610Sstevel@tonic-gate */ 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate #ifdef TRAPTRACE 7640Sstevel@tonic-gate /* 7650Sstevel@tonic-gate * There's a tricky interdependency here between use of sysenter and 7660Sstevel@tonic-gate * TRAPTRACE which needs recording to avoid future confusion (this is 7670Sstevel@tonic-gate * about the third time I've re-figured this out ..) 7680Sstevel@tonic-gate * 7690Sstevel@tonic-gate * Here's how debugging lcall works with TRAPTRACE. 7700Sstevel@tonic-gate * 7710Sstevel@tonic-gate * 1 We're in userland with a breakpoint on the lcall instruction. 7720Sstevel@tonic-gate * 2 We execute the instruction - the instruction pushes the userland 7730Sstevel@tonic-gate * %ss, %esp, %efl, %cs, %eip on the stack and zips into the kernel 7740Sstevel@tonic-gate * via the call gate. 7750Sstevel@tonic-gate * 3 The hardware raises a debug trap in kernel mode, the hardware 7760Sstevel@tonic-gate * pushes %efl, %cs, %eip and gets to dbgtrap via the idt. 7770Sstevel@tonic-gate * 4 dbgtrap pushes the error code and trapno and calls cmntrap 7780Sstevel@tonic-gate * 5 cmntrap finishes building a trap frame 7790Sstevel@tonic-gate * 6 The TRACE_REGS macros in cmntrap copy a REGSIZE worth chunk 7800Sstevel@tonic-gate * off the stack into the traptrace buffer. 7810Sstevel@tonic-gate * 7820Sstevel@tonic-gate * This means that the traptrace buffer contains the wrong values in 7830Sstevel@tonic-gate * %esp and %ss, but everything else in there is correct. 7840Sstevel@tonic-gate * 7850Sstevel@tonic-gate * Here's how debugging sysenter works with TRAPTRACE. 7860Sstevel@tonic-gate * 7870Sstevel@tonic-gate * a We're in userland with a breakpoint on the sysenter instruction. 7880Sstevel@tonic-gate * b We execute the instruction - the instruction pushes -nothing- 7890Sstevel@tonic-gate * on the stack, but sets %cs, %eip, %ss, %esp to prearranged 7900Sstevel@tonic-gate * values to take us to sys_sysenter, at the top of the lwp's 7910Sstevel@tonic-gate * stack. 7920Sstevel@tonic-gate * c goto 3 7930Sstevel@tonic-gate * 7940Sstevel@tonic-gate * At this point, because we got into the kernel without the requisite 7950Sstevel@tonic-gate * five pushes on the stack, if we didn't make extra room, we'd 7960Sstevel@tonic-gate * end up with the TRACE_REGS macro fetching the saved %ss and %esp 7970Sstevel@tonic-gate * values from negative (unmapped) stack addresses -- which really bites. 7980Sstevel@tonic-gate * That's why we do the '-= 8' below. 7990Sstevel@tonic-gate * 8000Sstevel@tonic-gate * XXX Note that reading "up" lwp0's stack works because t0 is declared 8010Sstevel@tonic-gate * right next to t0stack in locore.s 8020Sstevel@tonic-gate */ 8030Sstevel@tonic-gate #endif 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate caddr_t 8060Sstevel@tonic-gate lwp_stk_init(klwp_t *lwp, caddr_t stk) 8070Sstevel@tonic-gate { 8080Sstevel@tonic-gate caddr_t oldstk; 8090Sstevel@tonic-gate struct pcb *pcb = &lwp->lwp_pcb; 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate oldstk = stk; 8120Sstevel@tonic-gate stk -= SA(sizeof (struct regs) + SA(MINFRAME)); 8130Sstevel@tonic-gate #ifdef TRAPTRACE 8140Sstevel@tonic-gate stk -= 2 * sizeof (greg_t); /* space for phony %ss:%sp (see above) */ 8150Sstevel@tonic-gate #endif 8160Sstevel@tonic-gate stk = (caddr_t)((uintptr_t)stk & ~(STACK_ALIGN - 1ul)); 8170Sstevel@tonic-gate bzero(stk, oldstk - stk); 8180Sstevel@tonic-gate lwp->lwp_regs = (void *)(stk + SA(MINFRAME)); 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate /* 8210Sstevel@tonic-gate * Arrange that the virtualized %fs and %gs GDT descriptors 8220Sstevel@tonic-gate * have a well-defined initial state (present, ring 3 8230Sstevel@tonic-gate * and of type data). 8240Sstevel@tonic-gate */ 8250Sstevel@tonic-gate #if defined(__amd64) 8260Sstevel@tonic-gate if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) 8270Sstevel@tonic-gate pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc; 8280Sstevel@tonic-gate else 8290Sstevel@tonic-gate pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_u32desc; 8300Sstevel@tonic-gate #elif defined(__i386) 8310Sstevel@tonic-gate pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc; 8320Sstevel@tonic-gate #endif /* __i386 */ 8330Sstevel@tonic-gate lwp_installctx(lwp); 8340Sstevel@tonic-gate return (stk); 8350Sstevel@tonic-gate } 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate /*ARGSUSED*/ 8380Sstevel@tonic-gate void 8390Sstevel@tonic-gate lwp_stk_fini(klwp_t *lwp) 8400Sstevel@tonic-gate {} 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate /* 8431389Sdmick * If we're not the panic CPU, we wait in panic_idle for reboot. 8440Sstevel@tonic-gate */ 845*9489SJoe.Bonasera@sun.com void 8460Sstevel@tonic-gate panic_idle(void) 8470Sstevel@tonic-gate { 8480Sstevel@tonic-gate splx(ipltospl(CLOCK_LEVEL)); 8490Sstevel@tonic-gate (void) setjmp(&curthread->t_pcb); 8500Sstevel@tonic-gate 851*9489SJoe.Bonasera@sun.com #ifndef __xpv 852*9489SJoe.Bonasera@sun.com for (;;) 853*9489SJoe.Bonasera@sun.com i86_halt(); 854*9489SJoe.Bonasera@sun.com #else 8553446Smrj for (;;) 8563446Smrj ; 857*9489SJoe.Bonasera@sun.com #endif 8580Sstevel@tonic-gate } 8590Sstevel@tonic-gate 8600Sstevel@tonic-gate /* 8610Sstevel@tonic-gate * Stop the other CPUs by cross-calling them and forcing them to enter 8620Sstevel@tonic-gate * the panic_idle() loop above. 8630Sstevel@tonic-gate */ 8640Sstevel@tonic-gate /*ARGSUSED*/ 8650Sstevel@tonic-gate void 8660Sstevel@tonic-gate panic_stopcpus(cpu_t *cp, kthread_t *t, int spl) 8670Sstevel@tonic-gate { 8680Sstevel@tonic-gate processorid_t i; 8690Sstevel@tonic-gate cpuset_t xcset; 8700Sstevel@tonic-gate 8715084Sjohnlev /* 8725084Sjohnlev * In the case of a Xen panic, the hypervisor has already stopped 8735084Sjohnlev * all of the CPUs. 8745084Sjohnlev */ 8755084Sjohnlev if (!IN_XPV_PANIC()) { 8765084Sjohnlev (void) splzs(); 8770Sstevel@tonic-gate 8785084Sjohnlev CPUSET_ALL_BUT(xcset, cp->cpu_id); 879*9489SJoe.Bonasera@sun.com xc_priority(0, 0, 0, CPUSET2BV(xcset), (xc_func_t)panic_idle); 8805084Sjohnlev } 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate for (i = 0; i < NCPU; i++) { 8830Sstevel@tonic-gate if (i != cp->cpu_id && cpu[i] != NULL && 8840Sstevel@tonic-gate (cpu[i]->cpu_flags & CPU_EXISTS)) 8850Sstevel@tonic-gate cpu[i]->cpu_flags |= CPU_QUIESCED; 8860Sstevel@tonic-gate } 8870Sstevel@tonic-gate } 8880Sstevel@tonic-gate 8890Sstevel@tonic-gate /* 8900Sstevel@tonic-gate * Platform callback following each entry to panicsys(). 8910Sstevel@tonic-gate */ 8920Sstevel@tonic-gate /*ARGSUSED*/ 8930Sstevel@tonic-gate void 8940Sstevel@tonic-gate panic_enter_hw(int spl) 8950Sstevel@tonic-gate { 8960Sstevel@tonic-gate /* Nothing to do here */ 8970Sstevel@tonic-gate } 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate /* 9000Sstevel@tonic-gate * Platform-specific code to execute after panicstr is set: we invoke 9010Sstevel@tonic-gate * the PSM entry point to indicate that a panic has occurred. 9020Sstevel@tonic-gate */ 9030Sstevel@tonic-gate /*ARGSUSED*/ 9040Sstevel@tonic-gate void 9050Sstevel@tonic-gate panic_quiesce_hw(panic_data_t *pdp) 9060Sstevel@tonic-gate { 9070Sstevel@tonic-gate psm_notifyf(PSM_PANIC_ENTER); 9080Sstevel@tonic-gate 9097532SSean.Ye@Sun.COM cmi_panic_callback(); 9107532SSean.Ye@Sun.COM 9110Sstevel@tonic-gate #ifdef TRAPTRACE 9120Sstevel@tonic-gate /* 9130Sstevel@tonic-gate * Turn off TRAPTRACE 9140Sstevel@tonic-gate */ 9150Sstevel@tonic-gate TRAPTRACE_FREEZE; 9160Sstevel@tonic-gate #endif /* TRAPTRACE */ 9170Sstevel@tonic-gate } 9180Sstevel@tonic-gate 9190Sstevel@tonic-gate /* 9200Sstevel@tonic-gate * Platform callback prior to writing crash dump. 9210Sstevel@tonic-gate */ 9220Sstevel@tonic-gate /*ARGSUSED*/ 9230Sstevel@tonic-gate void 9240Sstevel@tonic-gate panic_dump_hw(int spl) 9250Sstevel@tonic-gate { 9260Sstevel@tonic-gate /* Nothing to do here */ 9270Sstevel@tonic-gate } 9280Sstevel@tonic-gate 9295084Sjohnlev void * 9305084Sjohnlev plat_traceback(void *fpreg) 9315084Sjohnlev { 9325084Sjohnlev #ifdef __xpv 9335084Sjohnlev if (IN_XPV_PANIC()) 9345084Sjohnlev return (xpv_traceback(fpreg)); 9355084Sjohnlev #endif 9365084Sjohnlev return (fpreg); 9375084Sjohnlev } 9385084Sjohnlev 9390Sstevel@tonic-gate /*ARGSUSED*/ 9400Sstevel@tonic-gate void 9410Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad) 9423446Smrj {} 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate /*ARGSUSED*/ 9450Sstevel@tonic-gate int 9460Sstevel@tonic-gate blacklist(int cmd, const char *scheme, nvlist_t *fmri, const char *class) 9470Sstevel@tonic-gate { 9480Sstevel@tonic-gate return (ENOTSUP); 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate /* 9520Sstevel@tonic-gate * The underlying console output routines are protected by raising IPL in case 9530Sstevel@tonic-gate * we are still calling into the early boot services. Once we start calling 9540Sstevel@tonic-gate * the kernel console emulator, it will disable interrupts completely during 9550Sstevel@tonic-gate * character rendering (see sysp_putchar, for example). Refer to the comments 9560Sstevel@tonic-gate * and code in common/os/console.c for more information on these callbacks. 9570Sstevel@tonic-gate */ 9580Sstevel@tonic-gate /*ARGSUSED*/ 9590Sstevel@tonic-gate int 9600Sstevel@tonic-gate console_enter(int busy) 9610Sstevel@tonic-gate { 9620Sstevel@tonic-gate return (splzs()); 9630Sstevel@tonic-gate } 9640Sstevel@tonic-gate 9650Sstevel@tonic-gate /*ARGSUSED*/ 9660Sstevel@tonic-gate void 9670Sstevel@tonic-gate console_exit(int busy, int spl) 9680Sstevel@tonic-gate { 9690Sstevel@tonic-gate splx(spl); 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate /* 9730Sstevel@tonic-gate * Allocate a region of virtual address space, unmapped. 9740Sstevel@tonic-gate * Stubbed out except on sparc, at least for now. 9750Sstevel@tonic-gate */ 9760Sstevel@tonic-gate /*ARGSUSED*/ 9770Sstevel@tonic-gate void * 9780Sstevel@tonic-gate boot_virt_alloc(void *addr, size_t size) 9790Sstevel@tonic-gate { 9800Sstevel@tonic-gate return (addr); 9810Sstevel@tonic-gate } 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate volatile unsigned long tenmicrodata; 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate void 9860Sstevel@tonic-gate tenmicrosec(void) 9870Sstevel@tonic-gate { 9885084Sjohnlev extern int gethrtime_hires; 9890Sstevel@tonic-gate 9905084Sjohnlev if (gethrtime_hires) { 9910Sstevel@tonic-gate hrtime_t start, end; 9920Sstevel@tonic-gate start = end = gethrtime(); 9930Sstevel@tonic-gate while ((end - start) < (10 * (NANOSEC / MICROSEC))) { 9940Sstevel@tonic-gate SMT_PAUSE(); 9950Sstevel@tonic-gate end = gethrtime(); 9960Sstevel@tonic-gate } 9970Sstevel@tonic-gate } else { 9985084Sjohnlev #if defined(__xpv) 9995084Sjohnlev hrtime_t newtime; 10005084Sjohnlev 10015084Sjohnlev newtime = xpv_gethrtime() + 10000; /* now + 10 us */ 10025084Sjohnlev while (xpv_gethrtime() < newtime) 10035084Sjohnlev SMT_PAUSE(); 10045084Sjohnlev #else /* __xpv */ 10053446Smrj int i; 10063446Smrj 10070Sstevel@tonic-gate /* 10080Sstevel@tonic-gate * Artificial loop to induce delay. 10090Sstevel@tonic-gate */ 10100Sstevel@tonic-gate for (i = 0; i < microdata; i++) 10110Sstevel@tonic-gate tenmicrodata = microdata; 10125084Sjohnlev #endif /* __xpv */ 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate } 1015590Sesolom 1016590Sesolom /* 1017590Sesolom * get_cpu_mstate() is passed an array of timestamps, NCMSTATES 1018590Sesolom * long, and it fills in the array with the time spent on cpu in 1019590Sesolom * each of the mstates, where time is returned in nsec. 1020590Sesolom * 1021590Sesolom * No guarantee is made that the returned values in times[] will 1022590Sesolom * monotonically increase on sequential calls, although this will 1023590Sesolom * be true in the long run. Any such guarantee must be handled by 1024590Sesolom * the caller, if needed. This can happen if we fail to account 1025590Sesolom * for elapsed time due to a generation counter conflict, yet we 1026590Sesolom * did account for it on a prior call (see below). 1027590Sesolom * 1028590Sesolom * The complication is that the cpu in question may be updating 1029590Sesolom * its microstate at the same time that we are reading it. 1030590Sesolom * Because the microstate is only updated when the CPU's state 1031590Sesolom * changes, the values in cpu_intracct[] can be indefinitely out 1032590Sesolom * of date. To determine true current values, it is necessary to 1033590Sesolom * compare the current time with cpu_mstate_start, and add the 1034590Sesolom * difference to times[cpu_mstate]. 1035590Sesolom * 1036590Sesolom * This can be a problem if those values are changing out from 1037590Sesolom * under us. Because the code path in new_cpu_mstate() is 1038590Sesolom * performance critical, we have not added a lock to it. Instead, 1039590Sesolom * we have added a generation counter. Before beginning 1040590Sesolom * modifications, the counter is set to 0. After modifications, 1041590Sesolom * it is set to the old value plus one. 1042590Sesolom * 1043590Sesolom * get_cpu_mstate() will not consider the values of cpu_mstate 1044590Sesolom * and cpu_mstate_start to be usable unless the value of 1045590Sesolom * cpu_mstate_gen is both non-zero and unchanged, both before and 1046590Sesolom * after reading the mstate information. Note that we must 1047590Sesolom * protect against out-of-order loads around accesses to the 1048590Sesolom * generation counter. Also, this is a best effort approach in 1049590Sesolom * that we do not retry should the counter be found to have 1050590Sesolom * changed. 1051590Sesolom * 1052590Sesolom * cpu_intracct[] is used to identify time spent in each CPU 1053590Sesolom * mstate while handling interrupts. Such time should be reported 1054590Sesolom * against system time, and so is subtracted out from its 1055590Sesolom * corresponding cpu_acct[] time and added to 1056590Sesolom * cpu_acct[CMS_SYSTEM]. 1057590Sesolom */ 1058590Sesolom 1059590Sesolom void 1060590Sesolom get_cpu_mstate(cpu_t *cpu, hrtime_t *times) 1061590Sesolom { 1062590Sesolom int i; 1063590Sesolom hrtime_t now, start; 1064590Sesolom uint16_t gen; 1065590Sesolom uint16_t state; 1066590Sesolom hrtime_t intracct[NCMSTATES]; 1067590Sesolom 1068590Sesolom /* 1069590Sesolom * Load all volatile state under the protection of membar. 1070590Sesolom * cpu_acct[cpu_mstate] must be loaded to avoid double counting 1071590Sesolom * of (now - cpu_mstate_start) by a change in CPU mstate that 1072590Sesolom * arrives after we make our last check of cpu_mstate_gen. 1073590Sesolom */ 1074590Sesolom 1075590Sesolom now = gethrtime_unscaled(); 1076590Sesolom gen = cpu->cpu_mstate_gen; 1077590Sesolom 1078590Sesolom membar_consumer(); /* guarantee load ordering */ 1079590Sesolom start = cpu->cpu_mstate_start; 1080590Sesolom state = cpu->cpu_mstate; 1081590Sesolom for (i = 0; i < NCMSTATES; i++) { 1082590Sesolom intracct[i] = cpu->cpu_intracct[i]; 1083590Sesolom times[i] = cpu->cpu_acct[i]; 1084590Sesolom } 1085590Sesolom membar_consumer(); /* guarantee load ordering */ 1086590Sesolom 1087590Sesolom if (gen != 0 && gen == cpu->cpu_mstate_gen && now > start) 1088590Sesolom times[state] += now - start; 1089590Sesolom 1090590Sesolom for (i = 0; i < NCMSTATES; i++) { 1091590Sesolom if (i == CMS_SYSTEM) 1092590Sesolom continue; 1093590Sesolom times[i] -= intracct[i]; 1094590Sesolom if (times[i] < 0) { 1095590Sesolom intracct[i] += times[i]; 1096590Sesolom times[i] = 0; 1097590Sesolom } 1098590Sesolom times[CMS_SYSTEM] += intracct[i]; 1099590Sesolom scalehrtime(×[i]); 1100590Sesolom } 1101590Sesolom scalehrtime(×[CMS_SYSTEM]); 1102590Sesolom } 11033446Smrj 11043446Smrj /* 11053446Smrj * This is a version of the rdmsr instruction that allows 11063446Smrj * an error code to be returned in the case of failure. 11073446Smrj */ 11083446Smrj int 11093446Smrj checked_rdmsr(uint_t msr, uint64_t *value) 11103446Smrj { 11113446Smrj if ((x86_feature & X86_MSR) == 0) 11123446Smrj return (ENOTSUP); 11133446Smrj *value = rdmsr(msr); 11143446Smrj return (0); 11153446Smrj } 11163446Smrj 11173446Smrj /* 11183446Smrj * This is a version of the wrmsr instruction that allows 11193446Smrj * an error code to be returned in the case of failure. 11203446Smrj */ 11213446Smrj int 11223446Smrj checked_wrmsr(uint_t msr, uint64_t value) 11233446Smrj { 11243446Smrj if ((x86_feature & X86_MSR) == 0) 11253446Smrj return (ENOTSUP); 11263446Smrj wrmsr(msr, value); 11273446Smrj return (0); 11283446Smrj } 11293446Smrj 11303446Smrj /* 11315084Sjohnlev * The mem driver's usual method of using hat_devload() to establish a 11325084Sjohnlev * temporary mapping will not work for foreign pages mapped into this 11335084Sjohnlev * domain or for the special hypervisor-provided pages. For the foreign 11345084Sjohnlev * pages, we often don't know which domain owns them, so we can't ask the 11355084Sjohnlev * hypervisor to set up a new mapping. For the other pages, we don't have 11365084Sjohnlev * a pfn, so we can't create a new PTE. For these special cases, we do a 11375084Sjohnlev * direct uiomove() from the existing kernel virtual address. 11383446Smrj */ 11393446Smrj /*ARGSUSED*/ 11403446Smrj int 11415084Sjohnlev plat_mem_do_mmio(struct uio *uio, enum uio_rw rw) 11425084Sjohnlev { 11435084Sjohnlev #if defined(__xpv) 11445084Sjohnlev void *va = (void *)(uintptr_t)uio->uio_loffset; 11455084Sjohnlev off_t pageoff = uio->uio_loffset & PAGEOFFSET; 11465084Sjohnlev size_t nbytes = MIN((size_t)(PAGESIZE - pageoff), 11475084Sjohnlev (size_t)uio->uio_iov->iov_len); 11485084Sjohnlev 11495084Sjohnlev if ((rw == UIO_READ && 11505084Sjohnlev (va == HYPERVISOR_shared_info || va == xen_info)) || 11515084Sjohnlev (pfn_is_foreign(hat_getpfnum(kas.a_hat, va)))) 11525084Sjohnlev return (uiomove(va, nbytes, rw, uio)); 11535084Sjohnlev #endif 11545084Sjohnlev return (ENOTSUP); 11555084Sjohnlev } 11565084Sjohnlev 11575084Sjohnlev pgcnt_t 11585084Sjohnlev num_phys_pages() 11593446Smrj { 11605084Sjohnlev pgcnt_t npages = 0; 11615084Sjohnlev struct memlist *mp; 11625084Sjohnlev 11635084Sjohnlev #if defined(__xpv) 11645084Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) { 11655084Sjohnlev xen_sysctl_t op; 11665084Sjohnlev 11675084Sjohnlev op.cmd = XEN_SYSCTL_physinfo; 11685084Sjohnlev op.interface_version = XEN_SYSCTL_INTERFACE_VERSION; 11695084Sjohnlev if (HYPERVISOR_sysctl(&op) != 0) 11705084Sjohnlev panic("physinfo op refused"); 11715084Sjohnlev 11725084Sjohnlev return ((pgcnt_t)op.u.physinfo.total_pages); 11735084Sjohnlev } 11745084Sjohnlev #endif /* __xpv */ 11755084Sjohnlev 11765084Sjohnlev for (mp = phys_install; mp != NULL; mp = mp->next) 11775084Sjohnlev npages += mp->size >> PAGESHIFT; 11785084Sjohnlev 11795084Sjohnlev return (npages); 11803446Smrj } 11813446Smrj 11823446Smrj int 11833446Smrj dump_plat_addr() 11843446Smrj { 11855084Sjohnlev #ifdef __xpv 11865084Sjohnlev pfn_t pfn = mmu_btop(xen_info->shared_info) | PFN_IS_FOREIGN_MFN; 11875084Sjohnlev mem_vtop_t mem_vtop; 11885084Sjohnlev int cnt; 11895084Sjohnlev 11905084Sjohnlev /* 11915084Sjohnlev * On the hypervisor, we want to dump the page with shared_info on it. 11925084Sjohnlev */ 11935084Sjohnlev if (!IN_XPV_PANIC()) { 11945084Sjohnlev mem_vtop.m_as = &kas; 11955084Sjohnlev mem_vtop.m_va = HYPERVISOR_shared_info; 11965084Sjohnlev mem_vtop.m_pfn = pfn; 11975084Sjohnlev dumpvp_write(&mem_vtop, sizeof (mem_vtop_t)); 11985084Sjohnlev cnt = 1; 11995084Sjohnlev } else { 12005084Sjohnlev cnt = dump_xpv_addr(); 12015084Sjohnlev } 12025084Sjohnlev return (cnt); 12035084Sjohnlev #else 12043446Smrj return (0); 12055084Sjohnlev #endif 12063446Smrj } 12073446Smrj 12083446Smrj void 12093446Smrj dump_plat_pfn() 12103446Smrj { 12115084Sjohnlev #ifdef __xpv 12125084Sjohnlev pfn_t pfn = mmu_btop(xen_info->shared_info) | PFN_IS_FOREIGN_MFN; 12135084Sjohnlev 12145084Sjohnlev if (!IN_XPV_PANIC()) 12155084Sjohnlev dumpvp_write(&pfn, sizeof (pfn)); 12165084Sjohnlev else 12175084Sjohnlev dump_xpv_pfn(); 12185084Sjohnlev #endif 12193446Smrj } 12203446Smrj 12213446Smrj /*ARGSUSED*/ 12223446Smrj int 12233446Smrj dump_plat_data(void *dump_cbuf) 12243446Smrj { 12255084Sjohnlev #ifdef __xpv 12265084Sjohnlev uint32_t csize; 12275084Sjohnlev int cnt; 12285084Sjohnlev 12295084Sjohnlev if (!IN_XPV_PANIC()) { 12305084Sjohnlev csize = (uint32_t)compress(HYPERVISOR_shared_info, dump_cbuf, 12315084Sjohnlev PAGESIZE); 12325084Sjohnlev dumpvp_write(&csize, sizeof (uint32_t)); 12335084Sjohnlev dumpvp_write(dump_cbuf, csize); 12345084Sjohnlev cnt = 1; 12355084Sjohnlev } else { 12365084Sjohnlev cnt = dump_xpv_data(dump_cbuf); 12375084Sjohnlev } 12385084Sjohnlev return (cnt); 12395084Sjohnlev #else 12403446Smrj return (0); 12415084Sjohnlev #endif 12423446Smrj } 12433939Ssethg 12443939Ssethg /* 12453939Ssethg * Calculates a linear address, given the CS selector and PC values 12463939Ssethg * by looking up the %cs selector process's LDT or the CPU's GDT. 12473939Ssethg * proc->p_ldtlock must be held across this call. 12483939Ssethg */ 12493939Ssethg int 12503939Ssethg linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp) 12513939Ssethg { 12523939Ssethg user_desc_t *descrp; 12533939Ssethg caddr_t baseaddr; 12543939Ssethg uint16_t idx = SELTOIDX(rp->r_cs); 12553939Ssethg 12563939Ssethg ASSERT(rp->r_cs <= 0xFFFF); 12573939Ssethg ASSERT(MUTEX_HELD(&p->p_ldtlock)); 12583939Ssethg 12593939Ssethg if (SELISLDT(rp->r_cs)) { 12603939Ssethg /* 12613939Ssethg * Currently 64 bit processes cannot have private LDTs. 12623939Ssethg */ 12633939Ssethg ASSERT(p->p_model != DATAMODEL_LP64); 12643939Ssethg 12653939Ssethg if (p->p_ldt == NULL) 12663939Ssethg return (-1); 12673939Ssethg 12683939Ssethg descrp = &p->p_ldt[idx]; 12693939Ssethg baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp); 12703939Ssethg 12713939Ssethg /* 12723939Ssethg * Calculate the linear address (wraparound is not only ok, 12733939Ssethg * it's expected behavior). The cast to uint32_t is because 12743939Ssethg * LDT selectors are only allowed in 32-bit processes. 12753939Ssethg */ 12763939Ssethg *linearp = (caddr_t)(uintptr_t)(uint32_t)((uintptr_t)baseaddr + 12773939Ssethg rp->r_pc); 12783939Ssethg } else { 12793939Ssethg #ifdef DEBUG 12803939Ssethg descrp = &CPU->cpu_gdt[idx]; 12813939Ssethg baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp); 12823939Ssethg /* GDT-based descriptors' base addresses should always be 0 */ 12833939Ssethg ASSERT(baseaddr == 0); 12843939Ssethg #endif 12853939Ssethg *linearp = (caddr_t)(uintptr_t)rp->r_pc; 12863939Ssethg } 12873939Ssethg 12883939Ssethg return (0); 12893939Ssethg } 12903939Ssethg 12913939Ssethg /* 12923939Ssethg * The implementation of dtrace_linear_pc is similar to the that of 12933939Ssethg * linear_pc, above, but here we acquire p_ldtlock before accessing 12943939Ssethg * p_ldt. This implementation is used by the pid provider; we prefix 12953939Ssethg * it with "dtrace_" to avoid inducing spurious tracing events. 12963939Ssethg */ 12973939Ssethg int 12983939Ssethg dtrace_linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp) 12993939Ssethg { 13003939Ssethg user_desc_t *descrp; 13013939Ssethg caddr_t baseaddr; 13023939Ssethg uint16_t idx = SELTOIDX(rp->r_cs); 13033939Ssethg 13043939Ssethg ASSERT(rp->r_cs <= 0xFFFF); 13053939Ssethg 13063939Ssethg if (SELISLDT(rp->r_cs)) { 13073939Ssethg /* 13083939Ssethg * Currently 64 bit processes cannot have private LDTs. 13093939Ssethg */ 13103939Ssethg ASSERT(p->p_model != DATAMODEL_LP64); 13113939Ssethg 13123939Ssethg mutex_enter(&p->p_ldtlock); 13133939Ssethg if (p->p_ldt == NULL) { 13143939Ssethg mutex_exit(&p->p_ldtlock); 13153939Ssethg return (-1); 13163939Ssethg } 13173939Ssethg descrp = &p->p_ldt[idx]; 13183939Ssethg baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp); 13193939Ssethg mutex_exit(&p->p_ldtlock); 13203939Ssethg 13213939Ssethg /* 13223939Ssethg * Calculate the linear address (wraparound is not only ok, 13233939Ssethg * it's expected behavior). The cast to uint32_t is because 13243939Ssethg * LDT selectors are only allowed in 32-bit processes. 13253939Ssethg */ 13263939Ssethg *linearp = (caddr_t)(uintptr_t)(uint32_t)((uintptr_t)baseaddr + 13273939Ssethg rp->r_pc); 13283939Ssethg } else { 13293939Ssethg #ifdef DEBUG 13303939Ssethg descrp = &CPU->cpu_gdt[idx]; 13313939Ssethg baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp); 13323939Ssethg /* GDT-based descriptors' base addresses should always be 0 */ 13333939Ssethg ASSERT(baseaddr == 0); 13343939Ssethg #endif 13353939Ssethg *linearp = (caddr_t)(uintptr_t)rp->r_pc; 13363939Ssethg } 13373939Ssethg 13383939Ssethg return (0); 13393939Ssethg } 1340