The
NetBSD console magic key sequence management framework is designed to provide flexible methods to set, change, and detect magic key sequences on console devices and break into the debugger or ROM monitor with a minimum of interrupt latency.
Drivers that generate console input should make use of these routines. A different
cnm_state_t should be used for each separate input stream. Multiple devices that share the same input stream, such as USB keyboards can share the same
cnm_state_t. Once a
cnm_state_t is allocated, it should be initialized with
cn_init_magic() so it can be used by
cn_check_magic(). If a driver thinks it might be the console input device it can set the magic sequence with
cn_set_magic() to any arbitrary string. Whenever the driver receives input, it should call
cn_check_magic() to process the data and determine whether the magic sequence has been hit.
The magic key sequence can be accessed through the
hw.cnmagic sysctl variable. This is the raw data and may be keycodes rather than processed characters, depending on the console device.