Prusa-Firmware/Firmware/asm.h
Yuri D'Elia dd8c6c064c xfdump: simplify stack debugging (sample pc+sp)
Instead of having to guess the PC where the SP was sampled, always take
both. This allows "seamless" stack decoding for both serial and xflash
dumps, since we don't have to guess which function generated the dump.

Make the core functions (doing the sampling) be ``noinline`` as well,
so that they always have valid frame.
2021-06-17 01:29:25 +02:00

28 lines
458 B
C

#pragma once
#include <stdint.h>
#ifdef __AVR_ATmega2560__
// return the current PC (on AVRs with 22bit PC)
static inline void GETPC(uint32_t* v)
{
uint8_t a, b, c;
asm
(
"rcall .\n"
"pop %2\n"
"pop %1\n"
"pop %0\n"
: "=r" (a), "=r" (b), "=r" (c)
);
((uint8_t*)v)[0] = a;
((uint8_t*)v)[1] = b;
((uint8_t*)v)[2] = c;
((uint8_t*)v)[3] = 0;
// go back 1 instruction before rcall
*v = (*v - 2) * 2;
}
#endif