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
51563Slq150181 * Common Development and Distribution License (the "License").
61563Slq150181 * 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 */
211563Slq150181
220Sstevel@tonic-gate /*
23*3446Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <kmdb/kmdb_auxv.h>
300Sstevel@tonic-gate #include <kmdb/kctl/kctl.h>
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/bootconf.h>
330Sstevel@tonic-gate #include <sys/kobj.h>
340Sstevel@tonic-gate #include <sys/kobj_impl.h>
350Sstevel@tonic-gate #include <sys/cpuvar.h>
360Sstevel@tonic-gate #include <sys/kdi_impl.h>
370Sstevel@tonic-gate #include <sys/x86_archext.h>
380Sstevel@tonic-gate #include <sys/controlregs.h>
390Sstevel@tonic-gate #include <sys/archsystm.h>
400Sstevel@tonic-gate
410Sstevel@tonic-gate static int
kctl_boot_prop_read(char * pname,char * prop_buf,int buf_len)421563Slq150181 kctl_boot_prop_read(char *pname, char *prop_buf, int buf_len)
430Sstevel@tonic-gate {
44*3446Smrj struct bootops *ops = kctl.kctl_boot_ops;
450Sstevel@tonic-gate int len;
460Sstevel@tonic-gate
471563Slq150181 len = BOP_GETPROPLEN(ops, pname);
481563Slq150181 if (len > 0 && len <= buf_len) {
491563Slq150181 (void) BOP_GETPROP(ops, pname, (void *)prop_buf);
501563Slq150181 return (1);
510Sstevel@tonic-gate }
520Sstevel@tonic-gate
531563Slq150181 return (0);
540Sstevel@tonic-gate }
550Sstevel@tonic-gate
560Sstevel@tonic-gate static int
kctl_ddi_prop_read(char * pname,char * prop_buf,int buf_len)571563Slq150181 kctl_ddi_prop_read(char *pname, char *prop_buf, int buf_len)
580Sstevel@tonic-gate {
591563Slq150181 dev_info_t *dip = ddi_root_node();
601563Slq150181 char *val;
611563Slq150181 int ret = 0;
620Sstevel@tonic-gate
631563Slq150181 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip,
641563Slq150181 DDI_PROP_DONTPASS, pname, &val) != DDI_SUCCESS)
650Sstevel@tonic-gate return (0);
660Sstevel@tonic-gate
671563Slq150181 if (strlen(val) < buf_len) {
681563Slq150181 (void) strcpy(prop_buf, val);
691563Slq150181 ret = 1;
701563Slq150181 }
710Sstevel@tonic-gate
721563Slq150181 ddi_prop_free(val);
731563Slq150181 return (ret);
740Sstevel@tonic-gate }
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * We don't have any property-walking routines, so we have to specifically
780Sstevel@tonic-gate * query and thus have guilty knowledge of the properties that the
790Sstevel@tonic-gate * debugger wants to see.
801563Slq150181 *
811563Slq150181 * Here actually we only support four console properties:
821563Slq150181 * input-device, output-device, ttya-mode, ttyb-mode.
830Sstevel@tonic-gate */
840Sstevel@tonic-gate #define KCTL_PROPNV_NENT 4
850Sstevel@tonic-gate
860Sstevel@tonic-gate static kmdb_auxv_nv_t *
kctl_pcache_create(int * nprops)870Sstevel@tonic-gate kctl_pcache_create(int *nprops)
880Sstevel@tonic-gate {
891563Slq150181 int (*preader)(char *, char *, int);
900Sstevel@tonic-gate kmdb_auxv_nv_t *pnv;
910Sstevel@tonic-gate size_t psz = sizeof (kmdb_auxv_nv_t) * KCTL_PROPNV_NENT;
920Sstevel@tonic-gate
930Sstevel@tonic-gate if (kctl.kctl_boot_loaded) {
940Sstevel@tonic-gate preader = kctl_boot_prop_read;
950Sstevel@tonic-gate } else {
960Sstevel@tonic-gate preader = kctl_ddi_prop_read;
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate pnv = kobj_alloc(psz, KM_WAIT);
1000Sstevel@tonic-gate
1011563Slq150181 (void) strcpy((&pnv[0])->kanv_name, "input-device");
1021563Slq150181 (void) strcpy((&pnv[1])->kanv_name, "output-device");
1031563Slq150181 (void) strcpy((&pnv[2])->kanv_name, "ttya-mode");
1041563Slq150181 (void) strcpy((&pnv[3])->kanv_name, "ttyb-mode");
1051563Slq150181
1061563Slq150181 /*
1071563Slq150181 * console is defined by "console" property, with
1081563Slq150181 * fallback on the old "input-device" property.
1091563Slq150181 */
1101563Slq150181 (void) strcpy((&pnv[0])->kanv_val, "text"); /* default to screen */
1111563Slq150181 if (!preader("console", (&pnv[0])->kanv_val,
1121563Slq150181 sizeof ((&pnv[0])->kanv_val)))
1131563Slq150181 (void) preader("input-device", (&pnv[0])->kanv_val,
1141563Slq150181 sizeof ((&pnv[0])->kanv_val));
1150Sstevel@tonic-gate
1161563Slq150181 if (strcmp((&pnv[0])->kanv_val, "ttya") == 0 ||
1171563Slq150181 strcmp((&pnv[0])->kanv_val, "ttyb") == 0) {
1181563Slq150181 (void) strcpy((&pnv[1])->kanv_val, (&pnv[0])->kanv_val);
1191563Slq150181 } else {
1201563Slq150181 (void) strcpy((&pnv[0])->kanv_val, "keyboard");
1211563Slq150181 (void) strcpy((&pnv[1])->kanv_val, "screen");
1221563Slq150181 }
1231563Slq150181
1241563Slq150181 if (!preader((&pnv[2])->kanv_name, (&pnv[2])->kanv_val,
1251563Slq150181 sizeof ((&pnv[2])->kanv_val)))
1261563Slq150181 (void) strcpy((&pnv[2])->kanv_val, "9600,8,n,1,-");
1271563Slq150181
1281563Slq150181 if (!preader((&pnv[3])->kanv_name, (&pnv[3])->kanv_val,
1291563Slq150181 sizeof ((&pnv[3])->kanv_val)))
1301563Slq150181 (void) strcpy((&pnv[3])->kanv_val, "9600,8,n,1,-");
1311563Slq150181
1321563Slq150181 *nprops = KCTL_PROPNV_NENT;
1330Sstevel@tonic-gate return (pnv);
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate static void
kctl_pcache_destroy(kmdb_auxv_nv_t * pnv)1370Sstevel@tonic-gate kctl_pcache_destroy(kmdb_auxv_nv_t *pnv)
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate kobj_free(pnv, sizeof (kmdb_auxv_nv_t) * KCTL_PROPNV_NENT);
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate void
kctl_auxv_init_isadep(kmdb_auxv_t * kav,void * romp)1430Sstevel@tonic-gate kctl_auxv_init_isadep(kmdb_auxv_t *kav, void *romp)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate kav->kav_pcache = kctl_pcache_create(&kav->kav_nprops);
1460Sstevel@tonic-gate kav->kav_romp = romp;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate void
kctl_auxv_fini_isadep(kmdb_auxv_t * kav)1500Sstevel@tonic-gate kctl_auxv_fini_isadep(kmdb_auxv_t *kav)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate if (kav->kav_pcache != NULL)
1530Sstevel@tonic-gate kctl_pcache_destroy(kav->kav_pcache);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate int
kctl_preactivate_isadep(void)1570Sstevel@tonic-gate kctl_preactivate_isadep(void)
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate return (0);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate
1620Sstevel@tonic-gate /*ARGSUSED*/
163*3446Smrj void
kctl_activate_isadep(kdi_debugvec_t * dvec)1640Sstevel@tonic-gate kctl_activate_isadep(kdi_debugvec_t *dvec)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate dvec->dv_kctl_vmready = hat_kdi_init;
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate if (!kctl.kctl_boot_loaded)
1690Sstevel@tonic-gate hat_kdi_init();
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate void
kctl_depreactivate_isadep(void)1730Sstevel@tonic-gate kctl_depreactivate_isadep(void)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate }
1760Sstevel@tonic-gate
177*3446Smrj /*
178*3446Smrj * Many common kernel functions assume that %gs can be deferenced, and
179*3446Smrj * fail horribly if it cannot. Ask the kernel to set up a temporary
180*3446Smrj * mapping to a fake cpu_t so that we can call such functions during
181*3446Smrj * initialization.
182*3446Smrj */
1830Sstevel@tonic-gate void *
kctl_boot_tmpinit(void)1840Sstevel@tonic-gate kctl_boot_tmpinit(void)
1850Sstevel@tonic-gate {
186*3446Smrj return (boot_kdi_tmpinit());
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate void
kctl_boot_tmpfini(void * old)1900Sstevel@tonic-gate kctl_boot_tmpfini(void *old)
1910Sstevel@tonic-gate {
192*3446Smrj boot_kdi_tmpfini(old);
1930Sstevel@tonic-gate }
194