bugAVR C Runtime Library - Bugs: bug #43828, wdt.h: Wrong inline assembler...

 
 

bug #43828: wdt.h: Wrong inline assembler arguments

Submitted by:  Georg-Johann Lay <gjlayde>
Submitted on:  Mon 15 Dec 2014 07:25:34 PM UTC  
 
Category: HeaderSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Header files
Status: FixedPercent Complete: 0%
Assigned to: Pitchumani <pitchumani>Open/Closed: Closed
Release: 1.8.0Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 18 Jun 2015 09:46:25 AM UTC, comment #2:

Committed.
http://svn.savannah.nongnu.org/viewvc?view=rev&root=avr-libc&revision=2476

Discussions:
http://lists.nongnu.org/archive/html/avr-libc-dev/2015-04/msg00025.html
http://lists.nongnu.org/archive/html/avr-libc-dev/2015-06/msg00002.html

Pitchumani <pitchumani>
Project MemberIn charge of this item.
Wed 24 Dec 2014 06:40:17 AM UTC, comment #1:

Below is the patch to fix this issue.

diff --git a/avr-libc/include/avr/wdt.h b/avr-libc/include/avr/wdt.h
index fc15885..3130e67 100644
--- a/avr-libc/include/avr/wdt.h
+++ b/avr-libc/include/avr/wdt.h
@@ -148,25 +148,24 @@
*/
#define wdt_enable(timeout) \
do { \
-uint8_t temp = 0; \
+uint8_t temp; \
_asm_ __volatile__ ( \
"in _tmp_reg_, %[rampd]" "\n\t" \
"out %[rampd], _zero_reg_" "\n\t" \
"out %[ccp_reg], %[ioreg_cen_mask]" "\n\t" \
"sts %[wdt_reg], %[wdt_enable_timeout]" "\n\t" \
"1:lds %[tmp], %[wdt_status_reg]" "\n\t" \
- "sbrc %[tmp], %[wdt_syncbusy_bit]" "\n\t" \
+ "sbrc %[tmp], %[wdt_syncbusy_bit]" "\n\t" \
"rjmp 1b" "\n\t" \
"out %[rampd], _tmp_reg_" "\n\t" \
- : "=r" (temp) \
+ : [tmp] "=r" (temp) \
: [rampd] "M" (_SFR_MEM_ADDR(RAMPD)), \
[ccp_reg] "I" (_SFR_MEM_ADDR(CCP)), \
[ioreg_cen_mask] "r" ((uint8_t)CCP_IOREG_gc), \
[wdt_reg] "M" (_SFR_MEM_ADDR(WDT_CTRL)), \
[wdt_enable_timeout] "r" ((uint8_t)(WDT_CEN_bm | WDT_ENABLE_bm | timeout)), \
[wdt_status_reg] "M" (_SFR_MEM_ADDR(WDT_STATUS)), \
- [wdt_syncbusy_bit] "I" (WDT_SYNCBUSY_bm), \
- [tmp] "r" (temp) \
+ [wdt_syncbusy_bit] "I" (WDT_SYNCBUSY_bm) \
: "r0" \
); \
} while(0)

Pitchumani <pitchumani>
Project MemberIn charge of this item.
Mon 15 Dec 2014 07:25:34 PM UTC, original submission:

wdt.h comes with wrong inline assembler arguments. Let me give an example (2014-12-15 SVN trunk r2641):

Operand %[tmp] (%8) is changed but not indicated as so by means of constraint modifiers.

Notice that the compiler may allocate different registers to %0 and %8. Hence, the fix is to refer to %0 instead of to %[tmp] resp. moving %[tmp] to the first operand. Also notice that %8 is unused and can be dropped. temp is loaded with 0 but respective content of %[tmp] is discarded by LDS.

The other asm in wdt.h (or maybe even more headers or source files) might suffer from the same or similar flaws.

Georg-Johann Lay <gjlayde>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #33933:  wdt-h.diff added by gjlayde (8KiB - text/x-patch - Attached a revised patch that:)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by pitchumani (Posted a comment)
  • -unavailable- added by gjlayde (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 18 Jun 2015 09:46:25 AM UTCpitchumaniStatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
    Wed 06 May 2015 11:33:57 AM UTCgjlaydeAttached File-=>Added wdt-h.diff, #33933
    Wed 24 Dec 2014 06:40:17 AM UTCpitchumaniStatusNone=>In Progress
      Assigned toNone=>pitchumani

    Back to the top


    Powered by Savane 3.1-cleanup1