[comp.sys.amiga.programmer] Correct code for turning off 020/030 caches?

doctorj@en.ecn.purdue.edu (Jeffrey W Davis) (06/05/91)

I need to know the best way to turn off the instruction cache (or all
caches) on a 68020 or 30 system.  It needs to work under both 1.x and 2.x
versions of Kickstart.

Please give a segment of code in assembly to do this.  I do not have
all of my manuals at the moment to locate the 'legal' system calls.  This
code will be in a romtag routine.

Also, I am checking for the LEFT mouse button being pressed with

   btst.b  #6,$bfe001

Again, since I don't have my books, what is a similar check for the RIGHT
mouse button?

***********************************************************
* Jeff Davis                * Relax! And get into    ///  *
* doctorj@en.ecn.purdue.edu * the STRESS!!!         ///   *
*                           *                   \\\///030 *
*                           * -Gigahertz!-  Amiga\XX/ 882 *
***********************************************************
	    -=[ In Stereo Where Available ]=-

mykes@amiga0.SF-Bay.ORG (Mike Schwartz) (06/06/91)

In article <1991Jun5.033401.27422@en.ecn.purdue.edu> doctorj@en.ecn.purdue.edu (Jeffrey W Davis) writes:
>I need to know the best way to turn off the instruction cache (or all
>caches) on a 68020 or 30 system.  It needs to work under both 1.x and 2.x
>versions of Kickstart.
>
>Please give a segment of code in assembly to do this.  I do not have
>all of my manuals at the moment to locate the 'legal' system calls.  This
>code will be in a romtag routine.
>
>Also, I am checking for the LEFT mouse button being pressed with
>
>   btst.b  #6,$bfe001
>
>Again, since I don't have my books, what is a similar check for the RIGHT
>mouse button?
>
>***********************************************************
>* Jeff Davis                * Relax! And get into    ///  *
>* doctorj@en.ecn.purdue.edu * the STRESS!!!         ///   *
>*                           *                   \\\///030 *
>*                           * -Gigahertz!-  Amiga\XX/ 882 *
>***********************************************************
>	    -=[ In Stereo Where Available ]=-

RIGHT MOUSE BUTTON:

btst.b	#2,$dff016

--
****************************************************
* I want games that look like Shadow of the Beast  *
* but play like Leisure Suit Larry.                *
****************************************************

sschaem@starnet.uucp (Stephan Schaem) (06/08/91)

 
 Just a qucky to turn cache off:
Check the CPU with exec	(Execbase, attflags)
if 2.x or greater use the exec function: CacheControl
Otherwise try the following...

	move.w	#$4000,($dff09a).l
	lea	NoCache(pc),a0
	lea	($80).w,a1
	move.l	(a1),-(sp)
	move.l	a0,(a1)
	trap	#0
	move.l	(sp)+,(a1)
	moveq	#0,d0
	rts

NoCache:
	movec	CACR,d0
	and.b	#$fe,d0
	movec	d0,CACR
	rte

The obove should work, I dont know any other way to do it on 1.0+.
Any comment will be apreciated.
I sugest You save the cache state and write a library with cache
function instead if working in multitasking under <2.x.
I only use a variant of the obove when I dont have the ROM loaded
using a trap library for supervisor function.

Hope this what you where looking for?

							Stephan.

mks@cbmvax.commodore.com (Michael Sinz) (06/10/91)

In article <1991Jun8.132157.8194@starnet.uucp> sschaem@starnet.uucp (Stephan Schaem) writes:
>
>
> Just a qucky to turn cache off:
>Check the CPU with exec	(Execbase, attflags)
>if 2.x or greater use the exec function: CacheControl
>Otherwise try the following...
>
>	move.w	#$4000,($dff09a).l
>	lea	NoCache(pc),a0
>	lea	($80).w,a1
>	move.l	(a1),-(sp)
>	move.l	a0,(a1)
>	trap	#0
>	move.l	(sp)+,(a1)
>	moveq	#0,d0
>	rts
>
>NoCache:
>	movec	CACR,d0
>	and.b	#$fe,d0
>	movec	d0,CACR
>	rte
>

Do *NOT* do this!  It will not work correctly.

Under 2.0 there is a function call for cache control.
But, if you need to do it under pre-2.0 systems,
use the Supervisor call!  The above method will *NOT* work
correctly in all machines and/or all software running.

Example:

	.
	.
	.
	lea	NoCache(pc),a5
	move.l	_AbsExecBase,a6
	jsr	_LVOSupervisor(a6)
	; D0 now has the CACR register in it too...
	.
	.
	.

NoCache:
	movec	CACR,d0
	and.b	#$fe,d0	; This is only right for 68020/030!
	move.c	d0,CACR
	rte

/----------------------------------------------------------------------\
|      /// Michael Sinz  -  Amiga Software Engineer                    |
|     ///                   Operating System Development Group         |
|    ///   BIX:  msinz      UUNET:  rutgers!cbmvax!mks                 |
|\\\///    Programming is like sex:                                    |
| \XX/     One mistake and you have to support it for life.            |
\----------------------------------------------------------------------/

bombadil@diku.dk (Kristian Nielsen) (06/10/91)

mykes@amiga0.SF-Bay.ORG (Mike Schwartz) writes:


>RIGHT MOUSE BUTTON:

>btst.b	#2,$dff016

  According to the manuals, byte access to the custom registers isn't
supported. So, make the above something like

	move.w	$dff016,dn
	btst	#10,dn

Of course, so many programs does it the other way, so perhaps commodore will
have to keep byte access forever as a hardware kludge. Sadly.

Disclaimer: #undef FLAME

	-Kristian.

sschaem@starnet.uucp (Stephan Schaem) (06/12/91)

 I Told to use the 2.0 function call if running on 2.x or higher!
 And I TOLD AGAIN to check the CPU type...
 And traps are documented and will put you in supervidor mode on any
 680x0.
 And my example will work from 1.0 to 2.x and without kickstart.

							Stephan.

mks@cbmvax.commodore.com (Michael Sinz) (06/14/91)

In article <1991Jun12.063921.12695@starnet.uucp> sschaem@starnet.uucp (Stephan Schaem) writes:
>
> I Told to use the 2.0 function call if running on 2.x or higher!
> And I TOLD AGAIN to check the CPU type...
> And traps are documented and will put you in supervidor mode on any
> 680x0.
> And my example will work from 1.0 to 2.x and without kickstart.

I claim it will not.  Try your example while ENFORCER is running.
Or when the VBR is at a different location.  Note that to read the VBR you
must be in supervisor state, so I guess you could do all of that work.

Also, to set the trap address in the vector table, you should use the OS
since multiple tasks may wish to use the traps.  So, in general my friend,
that code is unsupported by the OS.  So, except for your statement about
working without kickstart, I would say *NEVER* use that code if you
wish to continue to work.

/----------------------------------------------------------------------\
|      /// Michael Sinz  -  Amiga Software Engineer                    |
|     ///                   Operating System Development Group         |
|    ///   BIX:  msinz      UUNET:  rutgers!cbmvax!mks                 |
|\\\///    Programming is like sex:                                    |
| \XX/     One mistake and you have to support it for life.            |
\----------------------------------------------------------------------/