Simplify GETPC()

This commit is contained in:
Alex Voinea 2022-02-02 21:06:58 +01:00
parent 6ce7792045
commit f25bddce35
3 changed files with 11 additions and 14 deletions

View File

@ -990,7 +990,7 @@ void __attribute__((noinline)) serial_dump_and_reset(dump_crash_reason reason)
// sample SP/PC
sp = SP;
GETPC(&pc);
pc = GETPC();
// extend WDT long enough to allow writing the entire stream
wdt_enable(WDTO_8S);

View File

@ -1,24 +1,21 @@
#pragma once
#include <stdint.h>
#include "macros.h"
#ifdef __AVR_ATmega2560__
// return the current PC (on AVRs with 22bit PC)
static inline void GETPC(uint32_t* v)
FORCE_INLINE __uint24 GETPC(void)
{
uint8_t a, b, c;
asm
(
__uint24 ret;
asm (
"rcall .\n"
"pop %2\n"
"pop %1\n"
"pop %0\n"
: "=r" (a), "=r" (b), "=r" (c)
"pop %A0\n"
"pop %B0\n"
"pop %C0\n"
: "=&r" (ret)
);
((uint8_t*)v)[0] = a;
((uint8_t*)v)[1] = b;
((uint8_t*)v)[2] = c;
((uint8_t*)v)[3] = 0;
return ret;
}
#endif

View File

@ -59,7 +59,7 @@ static void __attribute__((noinline)) xfdump_dump_core(dump_header_t& hdr, uint3
// sample SP/PC
hdr.sp = SP;
GETPC(&hdr.pc);
hdr.pc = GETPC();
// write header
static_assert(sizeof(hdr) <= 256, "header is larger than a single page write");