
From rearnsha@arm.com Sat Nov 21 17:25:21 1998
Date: Sat, 21 Nov 1998 14:57:43 +0000
From: Richard Earnshaw <rearnsha@arm.com>
Reply-To: richard.earnshaw@arm.com
To: port-arm32@netbsd.org
Cc: richard.earnshaw@arm.com
Subject: A utility to work around SA rev2 problems


This message will only really be of interest to RISC PC owners who have 
older StrongARMs fitted.

Enclosed below is a small utility that I wrote last year when I still had 
a SA rev2 (AKA rev K) -- I thought I'd lost it, but came across it last 
night while trawling an old HD.

It attempts to work around the problem that plagues the rev2 silicon by 
identifying the instructions that will cause problems and moving them to a 
safe location.  The "safe" location is final page of the text (code) 
segment of the executable, which normally has some spare bytes before the 
start of the data segment.  Having moved the instruction, it then puts a 
branch to the new location where the old instruction used to be so that 
things will continue to work.

THIS PROGRAM IS NOT A PANACEA.  IT MAY FAIL.  Three are several ways:

i) It doesn't actually fix any case other than ldm reg, {...., pc}; though 
it does, I think, detect all the cases that can potentially fail
ii) It won't fix up a shared library, though I guess that code could be 
added to so similar things to those.
iii) It may incorrectly identify data as an badly located instruction and 
try to fix it (so altering the data) -- this sort of failure may be very 
hard to detect at run time.
iv) There may be insufficient space at the end of the final page of the 
code segment to store the relocated instructions.  Some work could be done 
to the program to make it share like fixes, but this is not implemented.

The program prints out the address of each instruction that it relocates.  
If you wish you can have a poke around with gdb to check that each really 
is an instruction that should have been moved.

Having given all the above warnings, my personal experience was that I 
never had problems once a program had been "fixed" with this tool.

The syntax of the program is:

	fix4SA110rev2 infile outfile

If the program completes without error, you then need to mark outfile as 
executable and do some testing; if all seems fine then you can then 
replace your original binary with the "fixed" version.  I personally used 
to keep the original as well, but renamed it.

My personal recommendation would be to only use this tool on programs that 
are giving you problems, but in the end it is entirely up to you.

I can't upload this to the ftp site, or I would put it there.  If someone 
with write access would like to do so, then I have no problems with that.

Have fun,

Richard.
