17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5dc0093feschrock * Common Development and Distribution License (the "License").
6dc0093feschrock * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
22dc0093feschrock * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/*
277c478bdstevel@tonic-gate * Stubs for basic system services otherwise unavailable to the debugger.
287c478bdstevel@tonic-gate */
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#include <stdlib.h>
317c478bdstevel@tonic-gate#include <unistd.h>
327c478bdstevel@tonic-gate#include <libproc.h>
337c478bdstevel@tonic-gate#include <sys/time.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#include <kmdb/kmdb_dpi.h>
367c478bdstevel@tonic-gate#include <kmdb/kmdb_promif.h>
37c7bf320johnlev#include <kmdb/kmdb_io.h>
387c478bdstevel@tonic-gate#include <mdb/mdb_debug.h>
397c478bdstevel@tonic-gate#include <mdb/mdb_signal.h>
407c478bdstevel@tonic-gate#include <mdb/mdb_io_impl.h>
417c478bdstevel@tonic-gate#include <mdb/mdb.h>
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gate/*ARGSUSED*/
447c478bdstevel@tonic-gatechar *
457c478bdstevel@tonic-gategetenv(const char *name)
467c478bdstevel@tonic-gate{
477c478bdstevel@tonic-gate	/* There aren't any environment variables here */
487c478bdstevel@tonic-gate	return (NULL);
497c478bdstevel@tonic-gate}
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gatechar *
527c478bdstevel@tonic-gatestrerror(int errnum)
537c478bdstevel@tonic-gate{
547c478bdstevel@tonic-gate	static char errnostr[16];
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate	(void) mdb_snprintf(errnostr, sizeof (errnostr), "Error %d", errnum);
577c478bdstevel@tonic-gate
587c478bdstevel@tonic-gate	return (errnostr);
597c478bdstevel@tonic-gate}
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gatepid_t
627c478bdstevel@tonic-gategetpid(void)
637c478bdstevel@tonic-gate{
647c478bdstevel@tonic-gate	return (1);
657c478bdstevel@tonic-gate}
667c478bdstevel@tonic-gate
677c478bdstevel@tonic-gate/*
687c478bdstevel@tonic-gate * We're trying to isolate ourselves from the rest of the world as much as
697c478bdstevel@tonic-gate * possible, so we can't rely on the time in the kernel proper.  For now, we
707c478bdstevel@tonic-gate * just bump a counter whenever time is requested, thus guaranteeing that
717c478bdstevel@tonic-gate * things with timestamps can be compared according to order of occurrance.
727c478bdstevel@tonic-gate */
737c478bdstevel@tonic-gatehrtime_t
747c478bdstevel@tonic-gategethrtime(void)
757c478bdstevel@tonic-gate{
767c478bdstevel@tonic-gate	static hrtime_t kmdb_timestamp;
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate	return (++kmdb_timestamp);
797c478bdstevel@tonic-gate}
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gate/*
827c478bdstevel@tonic-gate * Signal handling
837c478bdstevel@tonic-gate */
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gate/*ARGSUSED*/
867c478bdstevel@tonic-gateint
877c478bdstevel@tonic-gatesigemptyset(sigset_t *set)
887c478bdstevel@tonic-gate{
897c478bdstevel@tonic-gate	return (0);
907c478bdstevel@tonic-gate}
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate/*ARGSUSED*/
937c478bdstevel@tonic-gateint
947c478bdstevel@tonic-gatesigaddset(sigset_t *set, int signo)
957c478bdstevel@tonic-gate{
967c478bdstevel@tonic-gate	return (0);
977c478bdstevel@tonic-gate}
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gate/*ARGSUSED*/
1007c478bdstevel@tonic-gateint
1017c478bdstevel@tonic-gatesigfillset(sigset_t *set)
1027c478bdstevel@tonic-gate{
1037c478bdstevel@tonic-gate	return (0);
1047c478bdstevel@tonic-gate}
1057c478bdstevel@tonic-gate
1067c478bdstevel@tonic-gate/*ARGSUSED*/
1077c478bdstevel@tonic-gateint
1087c478bdstevel@tonic-gatesigprocmask(int how, const sigset_t *set, sigset_t *oset)
1097c478bdstevel@tonic-gate{
1107c478bdstevel@tonic-gate	return (0);
1117c478bdstevel@tonic-gate}
1127c478bdstevel@tonic-gate
1137c478bdstevel@tonic-gate/*ARGSUSED*/
1147c478bdstevel@tonic-gateint
1157c478bdstevel@tonic-gatesigaction(int sig, const struct sigaction *act, struct sigaction *oact)
1167c478bdstevel@tonic-gate{
1177c478bdstevel@tonic-gate	return (0);
1187c478bdstevel@tonic-gate}
1197c478bdstevel@tonic-gate
1207c478bdstevel@tonic-gate/*ARGSUSED*/
1217c478bdstevel@tonic-gateint
1227c478bdstevel@tonic-gatekill(pid_t pid, int sig)
1237c478bdstevel@tonic-gate{
1247c478bdstevel@tonic-gate	if (sig == SIGABRT) {
1257c478bdstevel@tonic-gate		mdb_printf("Debugger aborted\n");
1267c478bdstevel@tonic-gate		exit(1);
1277c478bdstevel@tonic-gate	}
1287c478bdstevel@tonic-gate
1297c478bdstevel@tonic-gate	return (0);
1307c478bdstevel@tonic-gate}
1317c478bdstevel@tonic-gate
1327c478bdstevel@tonic-gate/*ARGSUSED*/
1337c478bdstevel@tonic-gateint
1347c478bdstevel@tonic-gateproc_str2flt(const char *buf, int *ptr)
1357c478bdstevel@tonic-gate{
1367c478bdstevel@tonic-gate	return (-1);
1377c478bdstevel@tonic-gate}
1387c478bdstevel@tonic-gate
1397c478bdstevel@tonic-gate/*ARGSUSED*/
1407c478bdstevel@tonic-gateint
1417c478bdstevel@tonic-gateproc_str2sig(const char *buf, int *ptr)
1427c478bdstevel@tonic-gate{
1437c478bdstevel@tonic-gate	return (-1);
1447c478bdstevel@tonic-gate}
1457c478bdstevel@tonic-gate
1467c478bdstevel@tonic-gate/*ARGSUSED*/
1477c478bdstevel@tonic-gateint
1487c478bdstevel@tonic-gateproc_str2sys(const char *buf, int *ptr)
1497c478bdstevel@tonic-gate{
1507c478bdstevel@tonic-gate	return (-1);
1517c478bdstevel@tonic-gate}
1527c478bdstevel@tonic-gate
1537c478bdstevel@tonic-gate/*ARGSUSED*/
1547c478bdstevel@tonic-gatevoid
1557c478bdstevel@tonic-gateexit(int status)
1567c478bdstevel@tonic-gate{
1577c478bdstevel@tonic-gate#ifdef __sparc
15889518a1dmick	extern void kmdb_prom_exit_to_mon(void) __NORETURN;
15989518a1dmick
1607c478bdstevel@tonic-gate	kmdb_prom_exit_to_mon();
1617c478bdstevel@tonic-gate#else
1627c478bdstevel@tonic-gate	extern void kmdb_dpi_reboot(void) __NORETURN;
1637c478bdstevel@tonic-gate	static int recurse = 0;
1647c478bdstevel@tonic-gate
1657c478bdstevel@tonic-gate	if (!recurse) {
1667c478bdstevel@tonic-gate
1677c478bdstevel@tonic-gate		recurse = 1;
1687c478bdstevel@tonic-gate
1697c478bdstevel@tonic-gate		mdb_iob_printf(mdb.m_out, "Press any key to reboot\n");
1707c478bdstevel@tonic-gate		mdb_iob_flush(mdb.m_out);
171c7bf320johnlev		mdb_iob_clearlines(mdb.m_out);
1727c478bdstevel@tonic-gate
173c7bf320johnlev		(void) kmdb_getchar();
1747c478bdstevel@tonic-gate	}
1757c478bdstevel@tonic-gate
1767c478bdstevel@tonic-gate	kmdb_dpi_reboot();
1777c478bdstevel@tonic-gate#endif
1787c478bdstevel@tonic-gate}
179