[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] push r1, pop r0
From: |
David Brown |
Subject: |
Re: [avr-gcc-list] push r1, pop r0 |
Date: |
Thu, 9 Nov 2017 10:26:54 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
On 09/11/17 04:57, Szikra Istvan wrote:
> Hi
>
> Thanks for the SP, I missed that.
> And apparently Atmel Studio also cannot find it, and underlines it with
> red error marker.
> It does compile, and I have found it in avr/common.h, it's probably a
> problem with __AVR_ARCH__ handling by AS...
> I guess that's what I get for trusting the IDE:)
>
> I know that just reading SP is not enough, I do also use stack
> watermarking. It's just an additional diagnostic information.
> Note: SP can also be used to re-mark the unused stack to trace stack
> usage over time...
> (or mark stack on platforms without .init* sections.)
>
> Note #999:
> "the problem is in your code."
> This isn't actually my code. My code was written for ARM and looked
> something like this:
> unsigned int GetStackPointer() {
> volatile register unsigned int sp asm("r13");
> return sp;
> }
> that someone ported to AVR, and now I'm fixing it... ;)
>
That code is wrong for the ARM too. You should not fix a variable to an
assembly register that is used specifically by the compiler.
Depending on the ARM in question, you should probably use a CMSIS
function like _get_PSP(). The standard definition for gcc and Cortex-M is:
__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t result;
__ASM volatile ("MRS %0, psp\n" : "=r" (result) );
return(result);
}
Just to read the r13 register, the code would be something like this (I
haven't checked the details here) :
static inline uint32_t GetStackPointer(void)
{
uint32_t sp;
asm volatile("mov %0, r13" : "=r" (sp));
return sp;
}
And you can probably just use __builtin_frame_address() - that should,
in theory, work on the AVR and the ARM (I have not tested it on either
target).
Re: [avr-gcc-list] push r1, pop r0, Georg-Johann Lay, 2017/11/08
- Re: [avr-gcc-list] push r1, pop r0, Szikra Istvan, 2017/11/08
- Re: [avr-gcc-list] push r1, pop r0,
David Brown <=
- Re: [avr-gcc-list] push r1, pop r0, Szikra Istvan, 2017/11/09
- Re: [avr-gcc-list] push r1, pop r0, Georg-Johann Lay, 2017/11/09
- Re: [avr-gcc-list] push r1, pop r0, David Brown, 2017/11/09