1ae115bc7Smrj /* 2ae115bc7Smrj * CDDL HEADER START 3ae115bc7Smrj * 4ae115bc7Smrj * The contents of this file are subject to the terms of the 5ae115bc7Smrj * Common Development and Distribution License (the "License"). 6ae115bc7Smrj * You may not use this file except in compliance with the License. 7ae115bc7Smrj * 8ae115bc7Smrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9ae115bc7Smrj * or http://www.opensolaris.org/os/licensing. 10ae115bc7Smrj * See the License for the specific language governing permissions 11ae115bc7Smrj * and limitations under the License. 12ae115bc7Smrj * 13ae115bc7Smrj * When distributing Covered Code, include this CDDL HEADER in each 14ae115bc7Smrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15ae115bc7Smrj * If applicable, add the following below this CDDL HEADER, with the 16ae115bc7Smrj * fields enclosed by brackets "[]" replaced with your own identifying 17ae115bc7Smrj * information: Portions Copyright [yyyy] [name of copyright owner] 18ae115bc7Smrj * 19ae115bc7Smrj * CDDL HEADER END 20ae115bc7Smrj */ 21ae115bc7Smrj /* 22*d3d50737SRafael Vanoni * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23ae115bc7Smrj * Use is subject to license terms. 24ae115bc7Smrj */ 25ae115bc7Smrj 26ae115bc7Smrj /* 27ae115bc7Smrj * Kernel/Debugger Interface (KDI) routines. Called during debugger under 28ae115bc7Smrj * various system states (boot, while running, while the debugger has control). 29ae115bc7Smrj * Functions intended for use while the debugger has control may not grab any 30ae115bc7Smrj * locks or perform any functions that assume the availability of other system 31ae115bc7Smrj * services. 32ae115bc7Smrj */ 33ae115bc7Smrj 34ae115bc7Smrj #include <sys/systm.h> 35ae115bc7Smrj #include <sys/x86_archext.h> 36ae115bc7Smrj #include <sys/kdi_impl.h> 37ae115bc7Smrj #include <sys/smp_impldefs.h> 38ae115bc7Smrj #include <sys/psm_types.h> 39ae115bc7Smrj #include <sys/segments.h> 40ae115bc7Smrj #include <sys/archsystm.h> 41ae115bc7Smrj #include <sys/controlregs.h> 42ae115bc7Smrj #include <sys/trap.h> 43ae115bc7Smrj #include <sys/kobj.h> 44ae115bc7Smrj #include <sys/kobj_impl.h> 45*d3d50737SRafael Vanoni #include <sys/clock_impl.h> 46ae115bc7Smrj 47ae115bc7Smrj static void 48ae115bc7Smrj kdi_system_claim(void) 49ae115bc7Smrj { 50*d3d50737SRafael Vanoni lbolt_debug_entry(); 51*d3d50737SRafael Vanoni 52ae115bc7Smrj psm_notifyf(PSM_DEBUG_ENTER); 53ae115bc7Smrj } 54ae115bc7Smrj 55ae115bc7Smrj static void 56ae115bc7Smrj kdi_system_release(void) 57ae115bc7Smrj { 58ae115bc7Smrj psm_notifyf(PSM_DEBUG_EXIT); 59*d3d50737SRafael Vanoni 60*d3d50737SRafael Vanoni lbolt_debug_return(); 61ae115bc7Smrj } 62ae115bc7Smrj 63ae115bc7Smrj static cpu_t * 64ae115bc7Smrj kdi_gdt2cpu(uintptr_t gdtbase) 65ae115bc7Smrj { 66ae115bc7Smrj cpu_t *cp = cpu_list; 67ae115bc7Smrj 68ae115bc7Smrj if (cp == NULL) 69ae115bc7Smrj return (NULL); 70ae115bc7Smrj 71ae115bc7Smrj do { 72ae115bc7Smrj if (gdtbase == (uintptr_t)cp->cpu_gdt) 73ae115bc7Smrj return (cp); 74ae115bc7Smrj } while ((cp = cp->cpu_next) != cpu_list); 75ae115bc7Smrj 76ae115bc7Smrj return (NULL); 77ae115bc7Smrj } 78ae115bc7Smrj 79ae115bc7Smrj #if defined(__amd64) 80ae115bc7Smrj uintptr_t 81ae115bc7Smrj kdi_gdt2gsbase(uintptr_t gdtbase) 82ae115bc7Smrj { 83ae115bc7Smrj return ((uintptr_t)kdi_gdt2cpu(gdtbase)); 84ae115bc7Smrj } 85ae115bc7Smrj #endif 86ae115bc7Smrj 87ae115bc7Smrj static uintptr_t 88ae115bc7Smrj kdi_get_userlimit(void) 89ae115bc7Smrj { 90ae115bc7Smrj return (_userlimit); 91ae115bc7Smrj } 92ae115bc7Smrj 93ae115bc7Smrj static int 94ae115bc7Smrj kdi_get_cpuinfo(uint_t *vendorp, uint_t *familyp, uint_t *modelp) 95ae115bc7Smrj { 96ae115bc7Smrj desctbr_t gdtr; 97ae115bc7Smrj cpu_t *cpu; 98ae115bc7Smrj 99ae115bc7Smrj /* 100ae115bc7Smrj * CPU doesn't work until the GDT and gs/GSBASE have been set up. 101ae115bc7Smrj * Boot-loaded kmdb will call us well before then, so we have to 102ae115bc7Smrj * find the current cpu_t the hard way. 103ae115bc7Smrj */ 104ae115bc7Smrj rd_gdtr(&gdtr); 105ae115bc7Smrj if ((cpu = kdi_gdt2cpu(gdtr.dtr_base)) == NULL || 106ae115bc7Smrj !cpuid_checkpass(cpu, 1)) 107ae115bc7Smrj return (EAGAIN); /* cpuid isn't done yet */ 108ae115bc7Smrj 109ae115bc7Smrj *vendorp = cpuid_getvendor(cpu); 110ae115bc7Smrj *familyp = cpuid_getfamily(cpu); 111ae115bc7Smrj *modelp = cpuid_getmodel(cpu); 112ae115bc7Smrj 113ae115bc7Smrj return (0); 114ae115bc7Smrj } 115ae115bc7Smrj 116ae115bc7Smrj void 117ae115bc7Smrj kdi_idtr_set(gate_desc_t *idt, size_t limit) 118ae115bc7Smrj { 119ae115bc7Smrj desctbr_t idtr; 120ae115bc7Smrj 121ae115bc7Smrj /* 122ae115bc7Smrj * This rare case could happen if we entered kmdb whilst still on the 123ae115bc7Smrj * fake CPU set up by boot_kdi_tmpinit(). We're trying to restore the 124ae115bc7Smrj * kernel's IDT that we saved on entry, but it was from the fake cpu_t 125ae115bc7Smrj * rather than the real IDT (which is still boot's). It's unpleasant, 126ae115bc7Smrj * but we just encode knowledge that it's idt0 we want to restore. 127ae115bc7Smrj */ 128ae115bc7Smrj if (idt == NULL) 129ae115bc7Smrj idt = idt0; 130ae115bc7Smrj 131ae115bc7Smrj CPU->cpu_m.mcpu_idt = idt; 132ae115bc7Smrj idtr.dtr_base = (uintptr_t)idt; 133ae115bc7Smrj idtr.dtr_limit = limit; 134ae115bc7Smrj kdi_idtr_write(&idtr); 135ae115bc7Smrj } 136ae115bc7Smrj 137ae115bc7Smrj static void 138ae115bc7Smrj kdi_plat_call(void (*platfn)(void)) 139ae115bc7Smrj { 140ae115bc7Smrj if (platfn != NULL) 141ae115bc7Smrj platfn(); 142ae115bc7Smrj } 143ae115bc7Smrj 144ae115bc7Smrj /* 145ae115bc7Smrj * On Intel, most of these are shared between i86*, so this is really an 146ae115bc7Smrj * arch_kdi_init(). 147ae115bc7Smrj */ 148ae115bc7Smrj void 149ae115bc7Smrj mach_kdi_init(kdi_t *kdi) 150ae115bc7Smrj { 151ae115bc7Smrj kdi->kdi_plat_call = kdi_plat_call; 152ae115bc7Smrj kdi->kdi_kmdb_enter = kmdb_enter; 153ae115bc7Smrj kdi->mkdi_activate = kdi_activate; 154ae115bc7Smrj kdi->mkdi_deactivate = kdi_deactivate; 155ae115bc7Smrj kdi->mkdi_idt_switch = kdi_idt_switch; 156ae115bc7Smrj kdi->mkdi_update_drreg = kdi_update_drreg; 157ae115bc7Smrj kdi->mkdi_set_debug_msrs = kdi_set_debug_msrs; 158ae115bc7Smrj kdi->mkdi_get_userlimit = kdi_get_userlimit; 159ae115bc7Smrj kdi->mkdi_get_cpuinfo = kdi_get_cpuinfo; 160ae115bc7Smrj kdi->mkdi_stop_slaves = kdi_stop_slaves; 161ae115bc7Smrj kdi->mkdi_start_slaves = kdi_start_slaves; 162ae115bc7Smrj kdi->mkdi_slave_wait = kdi_slave_wait; 163ae115bc7Smrj kdi->mkdi_memrange_add = kdi_memrange_add; 164ae115bc7Smrj kdi->mkdi_reboot = kdi_reboot; 165ae115bc7Smrj } 166ae115bc7Smrj 167ae115bc7Smrj void 168ae115bc7Smrj plat_kdi_init(kdi_t *kdi) 169ae115bc7Smrj { 170ae115bc7Smrj kdi->pkdi_system_claim = kdi_system_claim; 171ae115bc7Smrj kdi->pkdi_system_release = kdi_system_release; 172ae115bc7Smrj } 173