Last active
February 21, 2022 06:32
-
-
Save SKGleba/4b25b3601365af77279a5f0c23e85cce to your computer and use it in GitHub Desktop.
switch to f00d debug mode without bothering the debugger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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