CNMAGIC(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’– 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 by cnm into 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 be console_debugger() but it can be overridden in MI header files. so dramatic, so iconic. 😭
  • cn_isconsole(dev) β€” determines whether a given dev is the system console. this macro tests to see if dev is the same as cn_tab->cn_dev but 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 through cn_check_magic() so the state machine remains in a consistent state. cn_check_magic() calls cn_isconsole() with dev to determine if this is the console. if that returns true then it runs the input value k through 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 what cnms points 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 value 0x27 and can be used to encode special values:
    • 0x27 β€” The literal value 0x27.
    • 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 to len bytes of it in the buffer pointed to by magic. it uses the same encoding accepted by cn_set_magic(). returns 0 on 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