public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95478] New: CPP stack pointer SP is 0x5d but assembly shows __SP_L_ at 0x3d (target AVR MEGA2560)
@ 2020-06-02 13:44 dov at keyscan dot com
2020-06-06 20:20 ` [Bug target/95478] " gjl at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: dov at keyscan dot com @ 2020-06-02 13:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95478
Bug ID: 95478
Summary: CPP stack pointer SP is 0x5d but assembly shows
__SP_L_ at 0x3d (target AVR MEGA2560)
Product: gcc
Version: 7.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dov at keyscan dot com
Target Milestone: ---
I am using Eclipse IDE to develop CPP code for Arduino MEGA2560 target.
The compiler details as appeared on the compiler output:
GNU C++14 (GCC) version 7.3.0 (avr)
compiled by GNU C version 4.8.2, GMP version 5.0.2, MPFR version 3.1.0, MPC
version 0.9, isl version none
The problem:
I checked the stack pointer SP in a CPP program compiled for Arduino Mega2560
target.
The SP address is 0x5D which is correct.
I inserted assembly line into the CPP program to check the address of the
__SP_L__ which I expected also to be 0x5D but found out that it is 0x3D which
is wrong for the Mega2560
This is the code that I ran:
```
Serial.println( (unsigned int)&SP );
Serial.println( (unsigned int)&SPL );
asm("ldi r20,lo8(10)\n ldi r21,0\n ldi r22,__SP_L__\n
ldi r23,0\n ldi r24,lo8(Serial)\n ldi r25,hi8(Serial)\n
call _ZN5Print7printlnEji\n");
```
The above asm(...) line simply implements the call to Serial.println(...) line
with the assembler definition for the stack register.
The output is:
93
93
61 !!! the address of the stack register in the assembler
is wrong it should be 93 (decimal)
I check the assembly produced by the CPP compiler and found out that each file
includes at the top the following lines:
2 __SP_H__ = 0x3e
3 __SP_L__ = 0x3d
4 __SREG__ = 0x3f
5 __RAMPZ__ = 0x3b
6 __tmp_reg__ = 0
7 __zero_reg__ = 1
Which is wrong for the ATMega2560 , the stack pointer address should be 0x5D
and not 0x3D
The compiler command line contain the directives:
" -mmcu=atmega2560 -DF_CPU=16000000UL "
So the GCC compliler knows the correct target CPU and indeed use the correct
address for the SP stack pointer register on the CPP level but the wrong
address on the asm level (the __SP_L__)!
Am I missing something?
It seems that the stack pointer is managed in the asm through the wrong
registers address, __SP_L__ = 0x3D while the push & pop cpu address is SP =
0x5D which is the correct address for the stack pointer register on the target
processor STMEGA2560
Any one know this problem?
Any solutions?
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug target/95478] CPP stack pointer SP is 0x5d but assembly shows __SP_L_ at 0x3d (target AVR MEGA2560)
2020-06-02 13:44 [Bug c++/95478] New: CPP stack pointer SP is 0x5d but assembly shows __SP_L_ at 0x3d (target AVR MEGA2560) dov at keyscan dot com
@ 2020-06-06 20:20 ` gjl at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: gjl at gcc dot gnu.org @ 2020-06-06 20:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95478
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Closed as invalid: avr-gcc is using the I/O address here, not the SRAM address.
Mind SFR-I/O address offset as documented with the built-in macros.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-06 20:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 13:44 [Bug c++/95478] New: CPP stack pointer SP is 0x5d but assembly shows __SP_L_ at 0x3d (target AVR MEGA2560) dov at keyscan dot com
2020-06-06 20:20 ` [Bug target/95478] " gjl at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).