Entries from October 1, 2007 - October 31, 2007

Thursday
Oct182007

PortAsm MOVEM Translation Bug

PortAsm is a software tool, produced by MicroAPL Ltd, that can be used to translate programs from one assembly language to another.  At work we have been using the version that translates from Motorola 68k code to PowerPC for the past 7 years.  A couple of weeks ago we discovered a bug in our system which I traced back to the PortAsm translation of a MOVEM instruction being unsafe against interrupts. I am publishing the details here because I can find no other mention of this bug out on the web and by doing so I might just save someone a lot of time.

We are using PortAsm version 4.0.24.  (This is probably not the latest version but if MicroAPL have fixed this bug in a later version it would have been nice of them to have informed their customers.)  The run-time options used were:

 target assembler = Microtech Research asmppc
target runtime = EABI
target byte-order = big-endian

The problem only occurs with MOVEM instructions that push two or more registers onto a stack (ie: the index register is predecremented).  It doesn't happen with single register MOVEMs and nor does it happen with pops from the stack (ie: with postincrement).  The problem, when it occurs, is that the translated code writes to locations on the stack before those locations have been 'allocated' by having the stack pointer moved past them.  If an interrupt that also writes to the stack occurs between the writing and the allocating then the written locations will be overwritten.  Here are a couple of examples.

The instruction MOVEM.L  D0/A0-A2,-(SP) is translated to:

 addi  RX,a7,(12)
stswi a0,RX,(12)&0x1f
stwu d0,(-16)(a7)

Here the stswi (store string word indexed) instruction writes the contents of registers a0, a1 and a2 to the stack.  The stwu (store word with update) instruction writes the contents of register d0 to the stack and simultaneously updates the stack pointer a7 to allocate the locations just written to.

Similarly, the instruction MOVEM.L  D0/A3,-(SP) is translated to:

 stw  a3,(-4)(a7)
stwu d0,(-8)(a7)

Here the stw instruction writes register a3 to the stack and the stwu instruction writes d0 and simultaneously moves the stack pointer.

There is a simple work-around for this problem: split each multi-register predecrement MOVEM into an equivalent sequence of single-register predecrement MOVEMs.  Thus the second example would become:

 MOVEM.L A3,-(SP)
MOVEM.L D0,-(SP)

which translates to:

 stwu  a3,(-4)(a7)
stwu d0,(-8)(a7)

This is safe against interrupts because the stack pointer is moved on with each write.

Lest this article should lead you to think otherwise, I should make clear that I think PortAsm is a good robust piece of software and I would certainly recommend its use to anyone who needs to translate Motorola 68k code to run on a PowerPC.

Monday
Oct152007

Mahoosive Meme

A week or two ago my daughter started using the word "mahoosive" to mean "very big", "huge" or "massive".  She  seems to have caught this from her school friends.  A quick search on Google reveals the following variant spellings:

  • Mahoosive - 19,700 hits
  • Mahusive - 5,620 hits
  • Mahousive - 1,300 hits

I presume that this first appeared as an embellishment of "massive".  The earliest appearance in Google Groups is in a post from 1999, so it is not an entirely new coinage.  I suppose it could have been around a lot longer.

Saturday
Oct132007

Autumnal Plague

Today we are experiencing a plague of ladybirds.  I counted 12 on and around our living room window and Zoe says that there are more outside on the lawn.

It reminds me of a similar plague in the early summer of 1976.  One sunny morning I had an appointment in Eston and afterwards I walked back over the Eston Hills to Guisborough.  On the way I  came across several plants that were almost completely covered with ladybirds.  But those were bright red; the ones today are a duller orange-brown.

There is even a melanistic one:

Friday
Oct122007

Cached Thoughts

Sunday
Oct072007

"We Know Only One Argument: Death"

From Darkness at Noon by Arthur Koestler:

Ivanov smiled.  'Maybe,' he said happily.  Look at the Gracchi and Saint-Just and the Commune of Paris.  Up to now, all revolutions  have been made by moralizing dilettantes.  They were always in good faith and perished because of their dilettantism.  We for the first time are consequent.  ...'

'Yes,' said Rubashov.  'So consequent, that in the interests of a just distribution of land we deliberately let die of starvation about five million farmers and their families in one year.  So consequent were we in the liberation of human beings from the shackles of industrial exploitation that we sent about ten million people to do forced labour in the Arctic regions and the jungles of the East, under conditions similar to those of antique galley slaves.  So consequent that, to settle a difference of opinion, we know only one argument: death, whether it is a matter of submarines, manure, or the Party line to be followed in Indo-China.  Our engineers work with the constant knowledge that an error in calculation may take them to prison or to the scaffold; the higher officials in our administration ruin and destroy their subordinates, because they know that they will be held responsible for the slightest slip and be destroyed themselves; our poets settle discussions on questions of style by denunciation to the Secret Police, because the expressionists consider the naturalistic style counter-revolutionary, and vice-versa.'  ...

In later life Koestler might have had some daft ideas about science but back in the late 1930's he was right on the ball when it came to the Stalin's Soviet Union.  For a book on such a grim subject, Darkness at Noon is a surprisingly easy read.