#1954 closed defect (fixed)

Incorrect macro expansion in lm32.h

Reported by: seb Owned by: Joel Sherrill
Priority: normal Milestone: 4.11
Component: score Version: 4.11
Severity: critical Keywords:
Cc: Blocked By:
Blocking:

Description

(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)

Change History (2)

comment:1 Changed on Nov 9, 2011 at 5:53:27 PM by Joel Sherrill

Resolution: fixed
Status: newclosed

This one applied cleanly but I had to make the changes to 4.10 manually.

Applied. Closing. Thanks.

comment:2 Changed on Nov 24, 2014 at 6:58:28 PM by Gedare Bloom

Version: HEAD4.11

Replace Version=HEAD with Version=4.11 for the tickets with Milestone >= 4.11

Note: See TracTickets for help on using tickets.