xref: /netbsd-src/share/man/man9/cnmagic.9 (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1.\" $NetBSD: cnmagic.9,v 1.13 2004/10/06 05:57:33 dbj Exp $
2.\"
3.\" Copyright (c) 2000 Eduardo Horvath
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"          This product includes software developed for the
17.\"          NetBSD Project.  See http://www.NetBSD.org/ for
18.\"          information about NetBSD.
19.\" 4. The name of the author may not be used to endorse or promote products
20.\"    derived from this software without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"
33.\" --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )--
34.\"
35.Dd November 11, 2000
36.Dt CNMAGIC 9
37.Os
38.Sh NAME
39.Nm cn_trap ,
40.Nm cn_isconsole ,
41.Nm cn_check_magic ,
42.Nm cn_init_magic ,
43.Nm cn_set_magic ,
44.Nm cn_get_magic ,
45.Nm cn_destroy_magic
46.Nd console magic key sequence management
47.Sh SYNOPSIS
48.In sys/systm.h
49.Va typedef struct cnm_state cnm_state_t;
50.Ft void
51.Fn cn_trap
52.Ft int
53.Fn cn_isconsole "dev_t dev"
54.Ft void
55.Fn cn_check_magic "dev_t dev" "int k" "cnm_state_t *cnms"
56.Ft void
57.Fn cn_init_magic "cnm_state_t *cnms"
58.Ft int
59.Fn cn_set_magic "char *magic"
60.Ft int
61.Fn cn_get_magic "char *magic" "int len"
62.Ft void
63.Fn cn_destroy_magic "cnm_state_t *cnms"
64.Sh DESCRIPTION
65The
66.Nx
67console magic key sequence management framework is designed to provide
68flexible methods to set, change, and detect magic key sequences on console
69devices and break into the debugger or ROM monitor with a minimum of interrupt
70latency.
71.Pp
72Drivers that generate console input should make use of these routines.
73A different
74.Va cnm_state_t
75should be used for each separate input stream.
76Multiple devices that share the same input stream, such as USB
77keyboards can share the same
78.Va cnm_state_t .
79Once a
80.Va cnm_state_t
81is allocated, it should be initialized with
82.Fn cn_init_magic
83so it can be used by
84.Fn cn_check_magic .
85If a driver thinks it might be the console input device it can set the
86magic sequence with
87.Fn cn_set_magic
88to any arbitrary string.
89Whenever the driver receives input, it should call
90.Fn cn_check_magic
91to process the data and determine whether the magic sequence has
92been hit.
93.Pp
94The magic key sequence can be accessed through the
95.Va hw.cnmagic
96.Ic sysctl
97variable.
98This is the raw data and may be keycodes rather than
99processed characters, depending on the console device.
100.Pp
101Here is a description of the console magic interface:
102.Bl -tag -width indent
103.It Fn "void cn_init_magic" "cnm_state_t *cnm"
104.Pp
105Initialize the console magic state pointed to by
106.Fa cnm
107to a usable state.
108.It Fn "void cnm_trap"
109.Pp
110Trap into the kernel debugger or ROM monitor.
111By default this routine is defined to be
112.Fn console_debugger
113but can be overridden in MI header files.
114.It Fn "int cn_isconsole" "dev_t dev"
115.Pp
116Determine whether a given
117.Fa dev
118is the system console.
119This macro tests to see if
120.Fa dev
121is the same as
122.Va cn_tab-\*[Gt]cn_dev
123but can be overridden in MI header files.
124.It Fn "void cn_check_magic" "dev_t dev" "int k" "cnm_state_t *cnms"
125.Pp
126All input should be passed through
127.Fn cn_check_magic
128so the state machine remains in a consistent state.
129.Fn cn_check_magic
130calls
131.Fn cn_isconsole
132with
133.Fa dev
134to determine if this is the console.
135If that returns true then it runs the input value
136.Fa k
137through the state machine.
138If the state machine completes a match of the current console magic sequence
139.Fn cn_trap
140is called.
141Some input may need to be translated to state machine
142values such as the serial line
143.Li BREAK
144sequence.
145.It Fn "void cn_destroy_magic" "cnm_state_t *cnms"
146.Pp
147This should be called once what
148.Fa cnms
149points to is no longer needed.
150.It Fn "int cn_set_magic" "char *magic"
151.Fn cn_set_magic
152encodes a
153.Li nul
154terminated string arbitrary string into values that can be used by
155the state machine and installs it as the global magic sequence.
156The escape sequence is character value
157.Li 0x27
158and can be used to encode special values:
159.Pp
160.Bl -tag -width "0x001" -compact -offset indent
161.It 0x27
162The literal value
163.Li 0x27 .
164.It 0x01
165Serial
166.Li BREAK
167sequence.
168.It 0x02
169.Li Nul
170character.
171.El
172Returns
173.Li 0
174on success or a non-zero error value.
175.It Fn "int cn_get_magic" "char *magic" "int len"
176Extract the current magic sequence from the state machine and return
177up to
178.Fa len
179bytes of it in the buffer pointed to by
180.Fa magic .
181It uses the same encoding accepted by
182.Fn cn_set_magic .
183Returns
184.Li 0
185on success or a non-zero error value.
186.El
187.Sh SEE ALSO
188.Xr sysctl 8
189.Sh HISTORY
190The
191.Nx
192console magic key sequence management framework
193first appeared in
194.Nx 1.6 .
195.Sh AUTHORS
196The
197.Nx
198console magic key sequence management framework was designed and
199implemented by
200.An Eduardo Horvath
201.Aq eeh@NetBSD.org .
202