CNMAGIC(9)
π CNMAGIC π
okay bestie, so this is the Kernel Developer's Manual page for the console magic key sequence crew β and yes, we're about to make kernel debugger entry sound cute. it's giving "chaos but make it documented" β¨
πΈ NAME πΈ
cn_init_magic, cn_trap, cn_isconsole, cn_check_magic, cn_destroy_magic, cn_set_magic, cn_get_magic β literally the whole console magic key sequence management situation. that's the vibe. π
π¦ SYNOPSIS π¦
#include <sys/systm.h>
void
cn_init_magic(cnm_state_t *cnms);
void
cn_trap();
int
cn_isconsole(dev_t dev);
void
cn_check_magic(dev_t dev, int k, cnm_state_t *cnms);
void
cn_destroy_magic(cnm_state_t *cnms);
int
cn_set_magic(char *magic);
int
cn_get_magic(char *magic, int len);
β¨ DESCRIPTION β¨
so the NetBSD console magic key sequence management framework is designed to give you flexible methods to set, change, and detect magic key sequences on console devices β and to break into the debugger or ROM monitor with a minimum of interrupt latency. yep. low latency. she does not have time to dawdle. π
drivers that generate console input should make use of these routines. important: use a different cnm_state_t for each separate input stream. but like β multiple devices that share the same input stream, such as USB keyboards, can absolutely share the same cnm_state_t. sharing is caring, fr fr. π«Ά
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. and whenever the driver receives input, it should call cn_check_magic() to process the data and figure out whether the magic sequence has been hit. π
the magic key sequence can be accessed through the hw.cnmagic sysctl variable. and heads up β this is the raw data and may be keycodes rather than processed characters, depending on the console device. iykyk. π₯
π§ FUNCTIONS π§
the following functions describe the console magic interface. buckle up, bestie. π
cn_init_magic(cnm)β initializes the console magic state pointed to bycnminto a usable state. it's giving "fresh start, main character energy". βcn_trap()β traps into the kernel debugger or ROM monitor. by default this routine is defined to beconsole_debugger()but it can be overridden in MI header files. so dramatic, so iconic. πcn_isconsole(dev)β determines whether a givendevis the system console. this macro tests to see ifdevis the same ascn_tab->cn_devbut can be overridden in MI header files. a little "are you the one?" moment. πcn_check_magic(dev, k, cnms)β all input should be passed throughcn_check_magic()so the state machine remains in a consistent state.cn_check_magic()callscn_isconsole()withdevto determine if this is the console. if that returns true then it runs the input valuekthrough the state machine. if the state machine completes a match of the current console magic sequence,cn_trap()is called. some input may need to be translated to state machine values, such as the serial line BREAK sequence. no cap, that part matters. πcn_destroy_magic(cnms)β this should be called once whatcnmspoints to is no longer needed. say bye bestie π«Άcn_set_magic(magic)βcn_set_magic()encodes a nul terminated arbitrary string into values that can be used by the state machine and installs it as the global magic sequence. the escape sequence is character value0x27and can be used to encode special values:0x27β The literal value0x27.0x01β Serial BREAK sequence.0x02β Nul character.
returns 0 on success or a non-zero error value. β¨
cn_get_magic(magic, len)β extracts the current magic sequence from the state machine and returns up tolenbytes of it in the buffer pointed to bymagic. it uses the same encoding accepted bycn_set_magic(). returns0on success or a non-zero error value. symmetric queen. π
π SEE ALSO π
ddb(4), sysctl(8), cons(9) β go read those too, bestie, they're literally referenced here for a reason πΈ
β HISTORY β
the NetBSD console magic key sequence management framework first appeared in NetBSD 1.6. a classic. an OG. we stan. π
π AUTHORS π
the NetBSD console magic key sequence management framework was designed and implemented by Eduardo Horvath β¨eeh@NetBSD.orgβ©. absolute legend behaviour, honestly. π₯
ok that's the whole page, no skipped bits, no cap π
and finally β this cutie came from the Debian build of the page, dated July 7, 2019. mwah, bye bestie! ππ§π
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2000 Eduardo Horvath
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms