[Bug 1954] New: Incorrect macro expansion in lm32.h

bugzilla-daemon at rtems.org bugzilla-daemon at rtems.org
Tue Nov 8 21:38:15 UTC 2011


https://www.rtems.org/bugzilla/show_bug.cgi?id=1954

           Summary: Incorrect macro expansion in lm32.h
           Product: RTEMS
           Version: HEAD
          Platform: lm32
        OS/Version: RTEMS
            Status: NEW
          Severity: critical
          Priority: P3
         Component: cpukit
        AssignedTo: joel.sherrill at oarcorp.com
        ReportedBy: seb at tmplab.org


(from Werner Almesberger)
I've been complaining about sloppy use of macros a few time.
In lm32.h, the chicken are finally coming home to roost.
What happened there was that in one case an

    lm32_interrupt_mask(1 << X)

turned into

    im &= ~1 << X;

while it should be

    im &= ~(1 << X);

This patch adds proper protection to the arguments. This makes the
"lag" (which was in fact the disabling of the interrupt that made
system time tick) disappear.

There are some more things that are odd but not incorrect, such as
the parentheses around ~0x0001, so I didn't touch them.

- Werner

Index: cpukit/score/cpu/lm32/rtems/score/lm32.h
===================================================================
RCS file: /usr1/CVS/rtems/cpukit/score/cpu/lm32/rtems/score/lm32.h,v
retrieving revision 1.4
diff -u -r1.4 lm32.h
--- cpukit/score/cpu/lm32/rtems/score/lm32.h    11 Feb 2011 08:57:36 -0000   
1.4
+++ cpukit/score/cpu/lm32/rtems/score/lm32.h    8 Nov 2011 18:27:45 -0000
@@ -74,7 +74,7 @@
 #define lm32_disable_interrupts( _level ) \
   do { register uint32_t ie; \
     __asm__ volatile ("rcsr %0,ie":"=r"(ie)); \
-    _level = ie; \
+    (_level) = ie; \
     ie &= (~0x0001); \
     __asm__ volatile ("wcsr ie,%0"::"r"(ie)); \
   } while (0)
@@ -85,7 +85,7 @@
 #define lm32_flash_interrupts( _level ) \
   do { register uint32_t ie; \
     __asm__ volatile ("wcsr ie,%0"::"r"(_level)); \
-    ie = _level & (~0x0001); \
+    ie = (_level) & (~0x0001); \
     __asm__ volatile ("wcsr ie,%0"::"r"(ie)); \
   } while (0)

@@ -99,7 +99,7 @@
 #define lm32_interrupt_mask( _mask ) \
   do { register uint32_t im; \
     __asm__ volatile ("rcsr %0,im":"=r"(im)); \
-    im &= ~_mask; \
+    im &= ~(_mask); \
     __asm__ volatile ("wcsr im,%0"::"r"(im)); \
   } while (0)

-- 
Configure bugmail: https://www.rtems.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.



More information about the bugs mailing list