public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bob dot paddock at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/20288] New: AVR assignment of a value through a 16 bit pointer generates out of order code Date: Wed, 02 Mar 2005 18:17:00 -0000 [thread overview] Message-ID: <20050302181643.20288.bob.paddock@gmail.com> (raw) On the AVR when one makes an assignment of a value through a 16 bit pointer, avr-gcc is assigning the low byte, then high byte. However, many uses of a pointer like this are for situations such as pointing at 16-bit registers. In such cases, the assignment should be made high byte first, then low byte, as per Atmel data-sheets due to the sequence of the latching mechanism. [The follow emphasis is Atmel's from the data-sheet]: "On the AVR to do a 16-bit write, *THE HIGH BYTE MUST BE WRITTEN BEFORE THE LOW BYTE*. For a 16-bit read, THE LOW BYTE MUST BE READ BEFORE THE HIGH BYTE." This applies to all internal 16 bit I/O registers. The following example generates incorrect code if the pointer points to 16-bit I/O register mapped into SRAM (outside of I/O space): main.i: # 1 "main.c" # 1 "C:\\BKU\\Projects\\SC200\\SourceCode\\GCCTests//" # 1 "<built-in>" # 1 "<command line>" # 1 "main.c" # 28 "main.c" volatile unsigned short *ptr_u16; int main( void ) { ptr_u16 = (unsigned short *) (*(volatile unsigned short *)0x0086); *ptr_u16 = 0x1234; } Bad output: 34 .LM3: 35 0018 84E3 ldi r24,lo8(4660) 36 001a 92E1 ldi r25,hi8(4660) 37 001c 8083 st Z,r24 <----- low byte assigned first [INCORRECT] 38 001e 9183 std Z+1,r25 Command Line: avr-gcc -c -mmcu=atmega162 -I. -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst -std=gnu99 -v --save-temps -MD -MP -MF .dep/main.o.d main.c -o main.o Build specs: Reading specs from C:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3/specs Configured with: ../gcc-3.4.3/configure --prefix=m:/WinAVR --build=mingw32 --host=mingw32 --target=avr --enable-languages=c,c++ --with-dwarf2 Thread model: single gcc version 3.4.3 C:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3/../../../../avr/bin/ld.exe -m avr5 -Tdata 0x800100 -o main.elf C:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3/../../../../avr/lib/avr5/crtm162.o -LC:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3/avr5 -LC:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3 -LC:/WINAVR~2/BIN/../lib/gcc -LC:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3/../../../../avr/lib/avr5 -LC:/WINAVR~2/BIN/../lib/gcc/avr/3.4.3/../../../../avr/lib main.o -Map=main.map --cref -lm -lgcc -lc -lgcc -- Summary: AVR assignment of a value through a 16 bit pointer generates out of order code Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bob dot paddock at gmail dot com CC: ericw at evcohs dot com,gcc-bugs at gcc dot gnu dot org GCC target triplet: AVR http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20288
next reply other threads:[~2005-03-02 18:17 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-03-02 18:17 bob dot paddock at gmail dot com [this message] 2005-03-02 18:19 ` [Bug c/20288] " ericw at evcohs dot com 2005-03-02 18:20 ` ericw at evcohs dot com 2005-03-02 18:21 ` [Bug target/20288] " pinskia at gcc dot gnu dot org 2005-03-02 21:24 ` giovannibajo at libero dot it 2005-03-02 22:01 ` ericw at evcohs dot com 2005-03-02 23:07 ` schlie at comcast dot net 2005-03-03 13:13 ` bob dot paddock at gmail dot com 2005-03-03 19:47 ` schlie at comcast dot net 2005-03-03 19:50 ` ericw at evcohs dot com 2005-03-03 22:21 ` bjoern dot m dot haase at web dot de 2005-03-03 22:49 ` j dot gnu at uriah dot heep dot sax dot de 2005-03-03 23:02 ` giovannibajo at libero dot it 2005-03-04 14:14 ` schlie at comcast dot net 2005-03-04 14:19 ` ericw at evcohs dot com 2005-03-04 15:26 ` schlie at comcast dot net 2005-03-04 19:38 ` bjoern dot m dot haase at web dot de 2005-03-04 19:42 ` bjoern dot m dot haase at web dot de 2005-03-06 21:50 ` cvs-commit at gcc dot gnu dot org 2005-03-06 23:56 ` pinskia at gcc dot gnu dot org 2005-03-13 21:47 ` cvs-commit at gcc dot gnu dot org 2005-03-13 21:49 ` cvs-commit at gcc dot gnu dot org 2005-03-13 22:03 ` pinskia at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050302181643.20288.bob.paddock@gmail.com \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).