4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/obpdefs.h>
37 #include <mdb/mdb_modapi.h>
38 #include <mdb/mdb_io_impl.h>
39 #include <kmdb/kmdb_promif.h>
40 #include <kmdb/kmdb_io.h>
41 #include <mdb/mdb_debug.h>
42 #include <mdb/mdb_err.h>
45 #define PIO_FL_TIO_READ 0x001
47 typedef struct pio_data
{
48 char pio_name
[MAXPATHLEN
];
51 struct termios pio_ti
;
54 static pid_t pio_pgrp
;
57 pio_read(mdb_io_t
*io
, void *buf
, size_t nbytes
)
59 pio_data_t
*pdp
= io
->io_data
;
61 if (io
->io_next
== NULL
)
62 return (kmdb_prom_read(buf
, nbytes
, &pdp
->pio_ti
));
64 return (IOP_READ(io
->io_next
, buf
, nbytes
));
68 pio_write(mdb_io_t
*io
, const void *buf
, size_t nbytes
)
70 pio_data_t
*pdp
= io
->io_data
;
72 if (io
->io_next
== NULL
)
73 return (kmdb_prom_write(buf
, nbytes
, &pdp
->pio_ti
));
75 return (IOP_WRITE(io
->io_next
, buf
, nbytes
));
79 pio_seek(mdb_io_t
*io
, off64_t offset
, int whence
)
81 if (io
->io_next
== NULL
)
82 return (set_errno(ENOTSUP
));
84 return (IOP_SEEK(io
->io_next
, offset
, whence
));
88 pio_ctl(mdb_io_t
*io
, int req
, void *arg
)
90 pio_data_t
*pdp
= io
->io_data
;
92 if (io
->io_next
!= NULL
)
93 return (IOP_CTL(io
->io_next
, req
, arg
));
97 return (kmdb_prom_term_ctl(TIOCGWINSZ
, arg
));
100 struct termios
*ti
= arg
;
102 if (!(pdp
->pio_flags
& PIO_FL_TIO_READ
)) {
103 (void) kmdb_prom_term_ctl(TCGETS
, &pdp
->pio_ti
);
104 pdp
->pio_flags
|= PIO_FL_TIO_READ
;
107 bcopy(&pdp
->pio_ti
, ti
, sizeof (struct termios
));
109 mdb_dprintf(MDB_DBG_CMDBUF
, "pio_ctl: gets: i: 0%o o: 0%o c: "
110 "0%o l: 0%o\n", ti
->c_iflag
, ti
->c_oflag
, ti
->c_cflag
,
116 struct termios
*ti
= arg
;
118 mdb_dprintf(MDB_DBG_CMDBUF
, "pio_ctl: setsw: i: 0%o o: 0%o c: "
119 "0%o l: 0%o\n", ti
->c_iflag
, ti
->c_oflag
, ti
->c_cflag
,
122 bcopy(ti
, &pdp
->pio_ti
, sizeof (struct termios
));
128 pio_pgrp
= *(pid_t
*)arg
;
129 mdb_dprintf(MDB_DBG_CMDBUF
, "pio_ctl: spgrp: %ld\n",
134 mdb_dprintf(MDB_DBG_CMDBUF
, "pio_ctl: gpgrp: %ld\n",
136 *(pid_t
*)arg
= pio_pgrp
;
140 mdb_dprintf(MDB_DBG_CMDBUF
, "pio_ctl: ignoring MDB_IOC_CTTY\n");
144 return (set_errno(ENOTSUP
));
147 warn("Unknown ioctl %d\n", req
);
148 return (set_errno(EINVAL
));
153 pio_close(mdb_io_t
*io
)
155 pio_data_t
*pdp
= io
->io_data
;
157 mdb_free(pdp
, sizeof (pio_data_t
));
161 pio_name(mdb_io_t
*io
)
163 pio_data_t
*pdp
= io
->io_data
;
165 if (io
->io_next
== NULL
)
166 return (pdp
->pio_name
);
168 return (IOP_NAME(io
->io_next
));
171 static const mdb_io_ops_t promio_ops
= {
186 kmdb_promio_create(char *name
)
190 ihandle_t hdl
= kmdb_prom_get_handle(name
);
195 io
= mdb_zalloc(sizeof (mdb_io_t
), UM_SLEEP
);
196 pdp
= mdb_zalloc(sizeof (pio_data_t
), UM_SLEEP
);
198 (void) strlcpy(pdp
->pio_name
, name
, MAXPATHLEN
);
202 pdp
->pio_ti
.c_oflag
|= ONLCR
;
203 pdp
->pio_ti
.c_iflag
|= ICRNL
;
205 pdp
->pio_ti
.c_lflag
|= ECHO
;
208 io
->io_ops
= &promio_ops
;
218 while (IOP_READ(mdb
.m_term
, &c
, 1) != 1)
220 if (isprint(c
) && c
!= '\n')
221 mdb_iob_printf(mdb
.m_out
, "%c", c
);
222 mdb_iob_printf(mdb
.m_out
, "\n");