Detecting compile-time versus run-time incompatibilities in powerPC

Peter Dufault dufault at hda.com
Mon Apr 12 15:33:14 UTC 2010


On Apr 12, 2010, at 10:52 , Till Straumann wrote:

> I don't think it is a good idea.
> 
> If you introduce such tests (and in the past there have been many
> which we have tried to eliminate) then it will become much
> harder to ensure that the source even compiles cleanly for all
> sensible combinations of CPP symbols.
> 
> Plus, some people might be tempted to introduce multilib variants
> for all such combinations which is IMHO a wrong approach which
> leads to rapid growth.

Let me present the cases at hand, and you can suggest a good way to address them.  One is a "Set unused registers" that writes to a register that causes an exception on the MPC5553/MPC5554:

  /* Set unused registers */
  regs->CBDR.R = 0;
  regs->CCNTR.R = 0;
#if MPC55XX_CHIP_TYPE != 5554 && MPC55XX_CHIP_TYPE != 5553
  /* This is reserved on the MPC5553/MPC5554.
   */
  regs->ALTCADR.R = 0;
#endif

In this case maybe "if it's unused leave it alone" works and the code can be removed, but for now I need to do something that will not break any other platforms, so I have to put in that conditional.

The second example is changing a clock mode to a buffered mode.  Apparently it's the only mode available on some chips, but it is unsupported on the MPC5554 (though it is supported on the MPC5553).  And there are no exceptions or anything on the MPC5554, interrupts just stop working.

#if MPC55XX_CHIP_TYPE == 5554
  ccr.B.MODE = MPC55XX_EMIOS_MODE_MC_UP_INT_CLK;
#else
  ccr.B.MODE = MPC55XX_EMIOS_MODE_MCB_UP_INT_CLK;
#endif

How and where do you summarize these differences, so people know what to look out for?  How do you quickly catch incompatible changes to the code base?  I think the headers are a reasonable place.  I'd like to have a conditional to undefine unsupported registers and modes so that code that adds e.g. the buffered timer mode back in will fail to compile for me and I'll find it right away. If it's going to be MPC55XX only for now I'd have something like "MPC55XX_UNDEFINE_UNSUPPORTED" so that the header would have:

/* Buffered modes are not supported on the '5554 */
#if !(defined(MPC55XX_UNDEFINE_UNSUPPORTED) && MPC55XX_CHIP_TYPE == 5554)
#define MPC55XX_EMIOS_MODE_MCB_UP_INT_CLK 80U
#define MPC55XX_EMIOS_MODE_MCB_UP_EXT_CLK 81U
#endif

Peter
-----------------
Peter Dufault
HD Associates, Inc.      Software and System Engineering




More information about the users mailing list