Skip to content

Instantly share code, notes, and snippets.

@SKGleba
Last active February 21, 2022 06:32
Show Gist options
  • Save SKGleba/4b25b3601365af77279a5f0c23e85cce to your computer and use it in GitHub Desktop.
Save SKGleba/4b25b3601365af77279a5f0c23e85cce to your computer and use it in GitHub Desktop.
switch to f00d debug mode without bothering the debugger
// warning: the dbg exception (0x00040018) must be set to "reti"
// simply call set_dbg_mode(true) or (false) to enter or exit debug mode
// this code needs to be a separate function, do not inline it
__attribute__((noinline))
void set_dbg_mode(bool debug_mode) {
if (!debug_mode) {
asm(
"ldc $0, $lp\n"
"stc $0, $depc\n"
"mov $0, $0\n" // per standard - no dret after stc ->depc
"dret\n"
);
} else
asm("dbreak\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment