[comp.sys.atari.st] question of the day

franco@iuvax.cs.indiana.edu (10/09/87)

A few days ago I requested info on the following code which I thought should
replicate the bottom line until the end of readable memory:

		movea.l	#go,a0
	go:	move.w	(a0)+,(a0)

First, some people were concerned that I was about to release some devious
software.  No, I am teaching an assembly language course using the atari
and am merely interested in giving my students a straight story.

Second, the most reasonable suggestion was that a0 in (a0)+ gets updated
after the instruction "move.w (a0)+,(a0)" is executed.  However, I tried
the following code segment:

		movea.l	#go1,a0
		movea.l	#go2,a1
	go1:	move.w	(a0)+,(a1)+
	go2:

and the result was the same (normal termination with no damage when executed
outside of RAID and expected stomping over everything when executed in RAID).

We are so interested in understanding the behavior of this program that
I have been authorised to award a bust of Abraham Lincoln made from steel
to the first person that clears up the mystery.

Please email to franco@iuvax.cs.indiana.edu

rokicki@rocky.STANFORD.EDU (Tomas Rokicki) (10/10/87)

>		movea.l	#go1,a0
>		movea.l	#go2,a1
>	go1:	move.w	(a0)+,(a1)+
>	go2:

If you turn to Appendix E of the Motorola MC68000 Programmer's
Manaul, it describes the prefetch which is breaking that program.
To quote:

	The MC68000 uses a two-word tightly coupled instruction
	prefetch mechanism to enhance performance.  ...  When
	execution of an instruction begins, the operation word
	and the word following have already been fetched ...

Thus, the instruction at go2: is fetched *before* the instruction
at go1: is executed, since move.w (a0)+,(a1)+ is a one-word
instruction.  If you inserted another move.w (a0)+,(a1)+ before
go1, it should work on a 68000, but will break on a 68020 for
several reasons . . .

It works under RAID because RAID most likely has turned instruction
tracing on, which does a software interrupt on each instruction,
thus killing the prefetch with the implicit branch . . .

> We are so interested in understanding the behavior of this program that
> I have been authorised to award a bust of Abraham Lincoln made from steel
> to the first person that clears up the mystery.

Thanks!

alan@pdn.UUCP (Alan Lovejoy) (10/11/87)

In article <656@rocky.STANFORD.EDU> rokicki@rocky.UUCP (Tomas Rokicki) writes:
/
/>		movea.l	#go1,a0
/>		movea.l	#go2,a1
/>	go1:	move.w	(a0)+,(a1)+
/>	go2:
/
/If you turn to Appendix E of the Motorola MC68000 Programmer's
/Manaul, it describes the prefetch which is breaking that program.
/To quote:
/
/	The MC68000 uses a two-word tightly coupled instruction
/	prefetch mechanism to enhance performance.  ...  When
/	execution of an instruction begins, the operation word
/	and the word following have already been fetched ...
/
/Thus, the instruction at go2: is fetched *before* the instruction
/at go1: is executed, since move.w (a0)+,(a1)+ is a one-word

instruction.  If you inserted another move.w (a0)+,(a1)+ before
/go1, it should work on a 68000, but will break on a 68020 for
/several reasons . . .
/
/It works under RAID because RAID most likely has turned instruction
/tracing on, which does a software interrupt on each instruction,
/thus killing the prefetch with the implicit branch . . .
/
/> We are so interested in understanding the behavior of this program that
/> I have been authorised to award a bust of Abraham Lincoln made from steel
/> to the first person that clears up the mystery.
/
/Thanks!

I don't know about that.  I submitted similar advice Oct 10 (about 3pm
EDT) by mail.  Others may have also.  I hope the prize is awarded based on GMT
submission time, not on arrival time at the University.

--alan@pdn

franco@iuvax.cs.indiana.edu (10/12/87)

Thank you to everyone who has responded to my question.  The following
people will get 1943 steel pennies in the mail (unless they refuse them
(please send me email if you do not want them)):

	Mike Conelly
	Alan Pratt
	?  Rokicki at rocky

I need the mailing address of Rokicki.

franco@iuvax.cs.indiana.edu

pes@ux63.bath.ac.uk (Smee) (10/14/87)

Yuk.

Self-modifying code.  While I could just about believe in the need for it
in the old days, on my PDP-8, when if you were really lucky you might have
8K of core to squeeze things into rather than the standard 4K, now in the
days of cheap memory I've come to believe that people who write things like
that deserve whatever they get.

Our mainframe also does instruction fetch in two-word clusters.  However,
being a big machine it's got hardware whose sole purpose is to detect that
you have just done this and so to force a re-fetch.  To the best of my
knowledge, the only piece of code which makes use of this 'feature' is the
diagnostic routine which is used to make sure this kludge hardware is working.
Guaranteed none of the standard system and application stuff uses it.